mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 4/4] mtd: nand: bb: fix erasing bb devices with bad blocks
Date: Thu,  5 Feb 2015 11:09:58 +0100	[thread overview]
Message-ID: <1423130998-21853-4-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1423130998-21853-1-git-send-email-s.hauer@pengutronix.de>

mtd_erase does not skip bad blocks, we must skip them in nand_bb_erase
instead.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mtd/nand/nand-bb.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/nand/nand-bb.c b/drivers/mtd/nand/nand-bb.c
index e38517d..853c617 100644
--- a/drivers/mtd/nand/nand-bb.c
+++ b/drivers/mtd/nand/nand-bb.c
@@ -159,16 +159,34 @@ static int nand_bb_erase(struct cdev *cdev, size_t count, loff_t offset)
 {
 	struct nand_bb *bb = cdev->priv;
 	struct erase_info erase = {};
+	int ret;
 
 	if (offset != 0) {
 		printf("can only erase from beginning of device\n");
 		return -EINVAL;
 	}
 
-	erase.addr = 0;
-	erase.len = bb->mtd->size;
+	while (count) {
+		if (offset + bb->mtd->erasesize >= bb->mtd->size)
+			return 0;
+
+		if (mtd_block_isbad(bb->mtd, offset)) {
+			offset += bb->mtd->erasesize;
+			continue;
+		}
 
-	return mtd_erase(bb->mtd, &erase);
+		erase.addr = offset;
+		erase.len = bb->mtd->erasesize;
+
+		ret = mtd_erase(bb->mtd, &erase);
+		if (ret)
+			return ret;
+
+		offset += bb->mtd->erasesize;
+		count -= bb->mtd->erasesize;
+	}
+
+	return 0;
 }
 #endif
 
-- 
2.1.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

      parent reply	other threads:[~2015-02-05 10:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-05 10:09 [PATCH 1/4] mtd: nand: omap: Fix OMAP_ECC_BCH8_CODE_HW ecc mode Sascha Hauer
2015-02-05 10:09 ` [PATCH 2/4] mtd: Fix allowing to erase bad blocks on partitions Sascha Hauer
2015-02-05 10:09 ` [PATCH 3/4] mtd: nand-bb: Fix accesses beyond device Sascha Hauer
2015-02-05 10:09 ` Sascha Hauer [this message]

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=1423130998-21853-4-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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