
It was noticed, that the erase command (mtd erase spi-nand0) aborts upon the first bad block. With this change, bad blocks are now skipped and the erase operation will continue.
Signed-off-by: Stefan Roese sr@denx.de Cc: Miquel Raynal miquel.raynal@bootlin.com Cc: Boris Brezillon boris.brezillon@bootlin.com Cc: Jagan Teki jagan@openedev.com --- v3: - Handle bad-block skipping completely in cmd/mtd. as suggested by Boris - Add message upon bad-block detection
v2: - Use an U-Boot "mtd" command specific option to skip the bad block upon erase so that other MTD users are not affected by this change
cmd/mtd.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/cmd/mtd.c b/cmd/mtd.c index 221b12500f..9f552e7c4a 100644 --- a/cmd/mtd.c +++ b/cmd/mtd.c @@ -360,7 +360,21 @@ static int do_mtd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) erase_op.len = len; erase_op.scrub = scrub;
- ret = mtd_erase(mtd, &erase_op); + while (erase_op.len) { + ret = mtd_erase(mtd, &erase_op); + + /* Abort if its not an bad block error */ + if (ret != -EIO) + break; + + printf("Skipping bad block at 0x%08llx\n", + erase_op.fail_addr); + + /* Skip bad block and continue behind it */ + erase_op.len -= erase_op.fail_addr - erase_op.addr; + erase_op.len -= mtd->erasesize; + erase_op.addr = erase_op.fail_addr + mtd->erasesize; + } } else { return CMD_RET_USAGE; }