2017-01-27 13:32:10 +00:00
|
|
|
From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
|
2016-12-25 19:11:34 +00:00
|
|
|
Subject: [PATCH] mtd: bcm47xxpart: check for bad blocks when calculating offsets
|
2017-01-27 13:32:10 +00:00
|
|
|
|
|
|
|
Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
|
|
|
|
---
|
|
|
|
|
2017-06-23 08:58:16 +00:00
|
|
|
--- a/drivers/mtd/parsers/parser_trx.c
|
|
|
|
+++ b/drivers/mtd/parsers/parser_trx.c
|
|
|
|
@@ -29,6 +29,33 @@ struct trx_header {
|
|
|
|
uint32_t offset[3];
|
|
|
|
} __packed;
|
2017-01-27 13:32:10 +00:00
|
|
|
|
|
|
|
+/*
|
|
|
|
+ * Calculate real end offset (address) for a given amount of data. It checks
|
|
|
|
+ * all blocks skipping bad ones.
|
|
|
|
+ */
|
2017-06-23 08:58:16 +00:00
|
|
|
+static size_t parser_trx_real_offset(struct mtd_info *mtd, size_t bytes)
|
2017-01-27 13:32:10 +00:00
|
|
|
+{
|
2017-06-23 08:58:16 +00:00
|
|
|
+ size_t real_offset = 0;
|
2017-01-27 13:32:10 +00:00
|
|
|
+
|
2017-06-23 08:58:16 +00:00
|
|
|
+ if (mtd_block_isbad(mtd, real_offset))
|
2017-01-27 13:32:10 +00:00
|
|
|
+ pr_warn("Base offset shouldn't be at bad block");
|
|
|
|
+
|
2017-06-23 08:58:16 +00:00
|
|
|
+ while (bytes >= mtd->erasesize) {
|
|
|
|
+ bytes -= mtd->erasesize;
|
|
|
|
+ real_offset += mtd->erasesize;
|
|
|
|
+ while (mtd_block_isbad(mtd, real_offset)) {
|
|
|
|
+ real_offset += mtd->erasesize;
|
2017-01-27 13:32:10 +00:00
|
|
|
+
|
2017-06-23 08:58:16 +00:00
|
|
|
+ if (real_offset >= mtd->size)
|
|
|
|
+ return real_offset - mtd->erasesize;
|
2017-01-27 13:32:10 +00:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ real_offset += bytes;
|
|
|
|
+
|
|
|
|
+ return real_offset;
|
|
|
|
+}
|
|
|
|
+
|
2017-06-23 08:58:16 +00:00
|
|
|
static const char *parser_trx_data_part_name(struct mtd_info *master,
|
|
|
|
size_t offset)
|
2017-01-27 13:32:10 +00:00
|
|
|
{
|
2017-06-23 08:58:16 +00:00
|
|
|
@@ -83,21 +110,21 @@ static int parser_trx_parse(struct mtd_i
|
|
|
|
if (trx.offset[2]) {
|
|
|
|
part = &parts[curr_part++];
|
|
|
|
part->name = "loader";
|
|
|
|
- part->offset = trx.offset[i];
|
|
|
|
+ part->offset = parser_trx_real_offset(mtd, trx.offset[i]);
|
2017-01-27 13:32:10 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2017-06-23 08:58:16 +00:00
|
|
|
if (trx.offset[i]) {
|
|
|
|
part = &parts[curr_part++];
|
|
|
|
part->name = "linux";
|
|
|
|
- part->offset = trx.offset[i];
|
|
|
|
+ part->offset = parser_trx_real_offset(mtd, trx.offset[i]);
|
2017-01-27 13:32:10 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2017-06-23 08:58:16 +00:00
|
|
|
if (trx.offset[i]) {
|
|
|
|
part = &parts[curr_part++];
|
|
|
|
part->name = parser_trx_data_part_name(mtd, trx.offset[i]);
|
|
|
|
- part->offset = trx.offset[i];
|
|
|
|
+ part->offset = parser_trx_real_offset(mtd, trx.offset[i]);
|
2017-01-27 13:32:10 +00:00
|
|
|
i++;
|
2017-06-23 08:58:16 +00:00
|
|
|
}
|
|
|
|
|