public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Stefan Roese <sr@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 2/4 v2] cmd: mtd: Don't abort erase operation when a bad block is detected
Date: Tue,  7 Aug 2018 14:16:53 +0200	[thread overview]
Message-ID: <20180807121655.22346-2-sr@denx.de> (raw)
In-Reply-To: <20180807121655.22346-1-sr@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 <sr@denx.de>
Cc: Miquel Raynal <miquel.raynal@bootlin.com>
Cc: Boris Brezillon <boris.brezillon@bootlin.com>
Cc: Jagan Teki <jagan@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

  reply	other threads:[~2018-08-07 12:16 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-07 12:16 [U-Boot] [PATCH 1/4 v2] spi: spi-mem: Use 2 SPI messages instead of a single full-duplex one Stefan Roese
2018-08-07 12:16 ` Stefan Roese [this message]
2018-08-07 13:05   ` [U-Boot] [PATCH 2/4 v2] cmd: mtd: Don't abort erase operation when a bad block is detected Boris Brezillon
2018-08-07 12:16 ` [U-Boot] [PATCH 3/4 v2] cmd: mtd: Don't use with negative return codes for shell commands Stefan Roese
2018-08-07 13:29   ` Boris Brezillon
2018-08-07 12:16 ` [U-Boot] [PATCH 4/4 v2] cmd: mtd: Add info text to mtd erase subcommand Stefan Roese
2018-08-07 13:32   ` Boris Brezillon
2018-08-07 13:38     ` Stefan Roese
2018-08-07 13:28 ` [U-Boot] [PATCH 1/4 v2] spi: spi-mem: Use 2 SPI messages instead of a single full-duplex one Boris Brezillon
2018-08-08  8:56   ` Miquel Raynal
2018-08-09  5:24     ` Stefan Roese
2018-08-09  8:13       ` Miquel Raynal
2018-08-09  9:10         ` Stefan Roese
2018-08-09 14:50           ` Miquel Raynal
2018-08-09 14:53             ` Stefan Roese
2018-08-08  9:58   ` Miquel Raynal
2018-08-09  5:25     ` Stefan Roese

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180807121655.22346-2-sr@denx.de \
    --to=sr@denx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox