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
|
2018-07-27 19:54:08 +00:00
|
|
|
@@ -30,6 +30,33 @@ struct trx_header {
|
2017-06-23 08:58:16 +00:00
|
|
|
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
|
|
|
{
|
2018-07-27 19:54:08 +00:00
|
|
|
@@ -84,21 +111,21 @@ static int parser_trx_parse(struct mtd_i
|
2017-06-23 08:58:16 +00:00
|
|
|
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++];
|
2018-07-10 12:02:00 +00:00
|
|
|
- part->name = parser_trx_data_part_name(mtd, trx.offset[i]);
|
2017-06-23 08:58:16 +00:00
|
|
|
- part->offset = trx.offset[i];
|
|
|
|
+ part->offset = parser_trx_real_offset(mtd, trx.offset[i]);
|
2018-07-10 12:02:00 +00:00
|
|
|
+ part->name = parser_trx_data_part_name(mtd, part->offset);
|
2017-01-27 13:32:10 +00:00
|
|
|
i++;
|
2017-06-23 08:58:16 +00:00
|
|
|
}
|
|
|
|
|