From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stefan Roese Date: Thu, 9 Aug 2018 08:22:47 +0200 Subject: [U-Boot] [PATCH 2/4 v3] cmd: mtd: Don't abort erase operation when a bad block is detected In-Reply-To: <20180809062249.10889-1-sr@denx.de> References: <20180809062249.10889-1-sr@denx.de> Message-ID: <20180809062249.10889-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 --- 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; } -- 2.18.0