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>
11 drivers/mtd/bcm47xxpart.c | 50 +++++++++++++++++++++++++++++++++++++----------
12 1 file changed, 40 insertions(+), 10 deletions(-)
14 --- a/drivers/mtd/bcm47xxpart.c
15 +++ b/drivers/mtd/bcm47xxpart.c
16 @@ -62,6 +62,34 @@ static void bcm47xxpart_add_part(struct
17 part->mask_flags = mask_flags;
21 + * Calculate real end offset (address) for a given amount of data. It checks
22 + * all blocks skipping bad ones.
24 +static size_t bcm47xxpart_real_offset(struct mtd_info *master, size_t offset,
27 + size_t real_offset = offset;
29 + if (mtd_block_isbad(master, real_offset))
30 + pr_warn("Base offset shouldn't be at bad block");
32 + while (bytes >= master->erasesize) {
33 + bytes -= master->erasesize;
34 + real_offset += master->erasesize;
35 + while (mtd_block_isbad(master, real_offset)) {
36 + real_offset += master->erasesize;
38 + if (real_offset >= master->size)
39 + return real_offset - master->erasesize;
43 + real_offset += bytes;
48 static const char *bcm47xxpart_trx_data_part_name(struct mtd_info *master,
51 @@ -91,6 +119,7 @@ static int bcm47xxpart_parse_trx(struct
53 struct trx_header header;
59 @@ -110,21 +139,25 @@ static int bcm47xxpart_parse_trx(struct
61 /* We have LZMA loader if offset[2] points to sth */
62 if (header.offset[2]) {
63 - bcm47xxpart_add_part(&parts[curr_part++], "loader",
64 - trx->offset + header.offset[i], 0);
65 + offset = bcm47xxpart_real_offset(master, trx->offset,
67 + bcm47xxpart_add_part(&parts[curr_part++], "loader", offset, 0);
71 if (header.offset[i]) {
72 - bcm47xxpart_add_part(&parts[curr_part++], "linux",
73 - trx->offset + header.offset[i], 0);
74 + offset = bcm47xxpart_real_offset(master, trx->offset,
76 + bcm47xxpart_add_part(&parts[curr_part++], "linux", offset, 0);
80 if (header.offset[i]) {
81 - size_t offset = trx->offset + header.offset[i];
82 - const char *name = bcm47xxpart_trx_data_part_name(master,
86 + offset = bcm47xxpart_real_offset(master, trx->offset,
88 + name = bcm47xxpart_trx_data_part_name(master, offset);
90 bcm47xxpart_add_part(&parts[curr_part++], name, offset, 0);