public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: "Mario J. Rugiero" <mrugiero@gmail.com>
To: linux-mtd@lists.infradead.org
Cc: "Mario J. Rugiero" <mrugiero@gmail.com>
Subject: [PATCH v2] mtd: nand: add option to erase NAND blocks even if detected as bad.
Date: Fri, 12 May 2017 02:52:46 -0300	[thread overview]
Message-ID: <20170512055246.10936-1-mrugiero@gmail.com> (raw)
In-Reply-To: <20170512053957.10426-1-mrugiero@gmail.com>

Some chips used under a custom vendor driver can get their blocks
incorrectly detected as bad blocks, out of incompatibilities
between such drivers and MTD drivers.
When there are too many misdetected bad blocks, the device becomes
unusable because a bad block table can't be allocated, aside from
all the legitimately good blocks which become unusable under these
conditions.
This adds a build option to workaround the issue by enabling the
user to free up space regardless of what the driver thinks about
the blocks.

Example usage: recovering NAND chips on sunxi devices, as explained
here: http://linux-sunxi.org/Mainline_NAND_Howto#Known_issues

Signed-off-by: Mario J. Rugiero <mrugiero@gmail.com>

v2: Fix a typo in the build option description.

---
 drivers/mtd/nand/Kconfig     | 9 +++++++++
 drivers/mtd/nand/nand_base.c | 2 ++
 2 files changed, 11 insertions(+)

diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
index c3029528063b..e0a32a34b6bf 100644
--- a/drivers/mtd/nand/Kconfig
+++ b/drivers/mtd/nand/Kconfig
@@ -36,6 +36,15 @@ config MTD_NAND_ECC_BCH
 	  ECC codes. They are used with NAND devices requiring more than 1 bit
 	  of error correction.
 
+config MTD_NAND_ERASE_BADBLOCKS
+	bool "Enable erasing of bad blocks (DANGEROUS)"
+	default n
+	help
+	  This enables support for attempting to erase bad blocks.
+	  It is needed to workaround too many badblocks issue on chips used
+	  under custom, incompatible vendor drivers.
+	  Say N if unsure.
+
 config MTD_SM_COMMON
 	tristate
 	default n
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index d474378ed810..0216dfc67976 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -3206,6 +3206,7 @@ int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr,
 	instr->state = MTD_ERASING;
 
 	while (len) {
+		#ifndef CONFIG_MTD_NAND_ERASE_BADBLOCKS
 		/* Check if we have a bad block, we do not erase bad blocks! */
 		if (nand_block_checkbad(mtd, ((loff_t) page) <<
 					chip->page_shift, allowbbt)) {
@@ -3214,6 +3215,7 @@ int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr,
 			instr->state = MTD_ERASE_FAILED;
 			goto erase_exit;
 		}
+		#endif
 
 		/*
 		 * Invalidate the page cache, if we erase the block which
-- 
2.13.0

  reply	other threads:[~2017-05-12  5:53 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-12  5:39 [PATCH] mtd: nand: add option to erase NAND blocks even if detected as bad Mario J. Rugiero
2017-05-12  5:52 ` Mario J. Rugiero [this message]
2017-05-12  7:39 ` [PATCH v3] " Mario J. Rugiero
2017-05-15  8:21   ` Boris Brezillon
2017-05-15  9:23     ` Richard Weinberger
2017-05-15  9:41       ` Boris Brezillon
2017-05-15 10:10         ` Richard Weinberger
2017-05-15 11:05           ` Boris Brezillon
2017-05-15 13:16             ` Mario Rugiero
2017-05-15 13:20               ` Boris Brezillon
2017-05-12  8:12 ` [PATCH] " Richard Weinberger
2017-05-12  8:16   ` Mario Rugiero
2017-05-12  8:24     ` Boris Brezillon
2017-05-12  8:33       ` Richard Weinberger
2017-05-12  8:44         ` Boris Brezillon
2017-05-12  8:45           ` Richard Weinberger
2017-05-12  8:34       ` Mario Rugiero
2017-05-12  8:45         ` Boris Brezillon
     [not found]           ` <CAKKQwLQueea6G4B-cng9QdpjtRWyBWHw1Mq9ai3DVp31xswANg@mail.gmail.com>
2017-05-12  9:02             ` Boris Brezillon
2017-05-12  9:15               ` Mario Rugiero
2017-05-12  9:16                 ` Mario Rugiero
2017-05-12  9:32                   ` Boris Brezillon
2017-05-12  9:19                 ` Richard Weinberger
2017-05-12  9:26                   ` Mario Rugiero
2017-05-12  9:34                     ` Boris Brezillon
2017-05-12 10:06                       ` Mario Rugiero
2017-05-12 10:19                         ` Boris Brezillon
2017-05-12 10:23                           ` Mario Rugiero
2017-05-12 10:34                             ` Mario Rugiero
2017-05-13  9:17                             ` Richard Weinberger
2017-05-15  2:54                               ` Mario Rugiero

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=20170512055246.10936-1-mrugiero@gmail.com \
    --to=mrugiero@gmail.com \
    --cc=linux-mtd@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