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 <s...@denx.de>
Cc: Miquel Raynal <miquel.ray...@bootlin.com>
Cc: Boris Brezillon <boris.brezil...@bootlin.com>
Cc: Jagan Teki <ja...@openedev.com>
---
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               | 1 +
 drivers/mtd/nand/core.c | 6 ++++++
 include/linux/mtd/mtd.h | 1 +
 3 files changed, 8 insertions(+)

diff --git a/cmd/mtd.c b/cmd/mtd.c
index 221b12500f..999d686e66 100644
--- a/cmd/mtd.c
+++ b/cmd/mtd.c
@@ -359,6 +359,7 @@ static int do_mtd(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
                erase_op.addr = off;
                erase_op.len = len;
                erase_op.scrub = scrub;
+               erase_op.skipbad = true;
 
                ret = mtd_erase(mtd, &erase_op);
        } else {
diff --git a/drivers/mtd/nand/core.c b/drivers/mtd/nand/core.c
index 0b793695cc..c9d7a646f6 100644
--- a/drivers/mtd/nand/core.c
+++ b/drivers/mtd/nand/core.c
@@ -163,6 +163,12 @@ int nanddev_mtd_erase(struct mtd_info *mtd, struct 
erase_info *einfo)
        while (nanddev_pos_cmp(&pos, &last) <= 0) {
                ret = nanddev_erase(nand, &pos);
                if (ret) {
+                       /* U-Boot special: Allow the users to skip bad blocks */
+                       if ((ret == -EIO) && einfo->skipbad) {
+                               nanddev_pos_next_eraseblock(nand, &pos);
+                               continue;
+                       }
+
                        einfo->fail_addr = nanddev_pos_to_offs(nand, &pos);
 
                        return ret;
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 4ca5d764d7..3a09dbab95 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -53,6 +53,7 @@ struct erase_info {
        u_char state;
        struct erase_info *next;
        int scrub;
+       bool skipbad;
 };
 
 struct mtd_erase_region_info {
-- 
2.18.0

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot

Reply via email to