1 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
2 Date: Sat, 2 Jan 2016 01:04:52 +0100
3 Subject: [PATCH] mtd: bcm47xxpart: check for bad blocks when calculating
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
12 --- a/drivers/mtd/parsers/parser_trx.c
13 +++ b/drivers/mtd/parsers/parser_trx.c
14 @@ -29,6 +29,33 @@ struct trx_header {
19 + * Calculate real end offset (address) for a given amount of data. It checks
20 + * all blocks skipping bad ones.
22 +static size_t parser_trx_real_offset(struct mtd_info *mtd, size_t bytes)
24 + size_t real_offset = 0;
26 + if (mtd_block_isbad(mtd, real_offset))
27 + pr_warn("Base offset shouldn't be at bad block");
29 + while (bytes >= mtd->erasesize) {
30 + bytes -= mtd->erasesize;
31 + real_offset += mtd->erasesize;
32 + while (mtd_block_isbad(mtd, real_offset)) {
33 + real_offset += mtd->erasesize;
35 + if (real_offset >= mtd->size)
36 + return real_offset - mtd->erasesize;
40 + real_offset += bytes;
45 static const char *parser_trx_data_part_name(struct mtd_info *master,
48 @@ -83,21 +110,21 @@ static int parser_trx_parse(struct mtd_i
50 part = &parts[curr_part++];
51 part->name = "loader";
52 - part->offset = trx.offset[i];
53 + part->offset = parser_trx_real_offset(mtd, trx.offset[i]);
58 part = &parts[curr_part++];
60 - part->offset = trx.offset[i];
61 + part->offset = parser_trx_real_offset(mtd, trx.offset[i]);
66 part = &parts[curr_part++];
67 part->name = parser_trx_data_part_name(mtd, trx.offset[i]);
68 - part->offset = trx.offset[i];
69 + part->offset = parser_trx_real_offset(mtd, trx.offset[i]);