From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stefan Roese Date: Tue, 7 Aug 2018 14:16:53 +0200 Subject: [U-Boot] [PATCH 2/4 v2] cmd: mtd: Don't abort erase operation when a bad block is detected In-Reply-To: <20180807121655.22346-1-sr@denx.de> References: <20180807121655.22346-1-sr@denx.de> Message-ID: <20180807121655.22346-2-sr@denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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 Cc: Miquel Raynal Cc: Boris Brezillon Cc: Jagan Teki --- 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