From patchwork Fri May 12 05:39:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Rugiero X-Patchwork-Id: 761451 X-Patchwork-Delegate: boris.brezillon@free-electrons.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wPJjD0SQSz9s7v for ; Fri, 12 May 2017 15:40:32 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="DhZcP4H9"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="i+s800H0"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=5LMmAGmZ9Q3OxCHRISNRwFynalBu+AVtM2fJZA15950=; b=DhZ cP4H9YznmfBEXw5gXIGEXDhpaANlUF4i7S40/CQKE81rmcgnsmP2hh3zixFLLjpYbmSEJWwo3agvh svMleh+8A7/j8EuB8w0nypnX5RtZS3TE8N6FxLg1HYOs4jkOiMQo/hBxKiP8ST4yih9vXGXVjVXuD CdWvFkAYKM1VpjbVwFwqH9IG/lQthHYO735zGTl7oEM1A/3VfjDPxnf8uXcaY9Qj6a/e3uKiTV3u/ uSJGKKA4siqjwIZIPHsCDBi5XYv9CPLp2KnAStOcY4n5bGmsQrPBwfyS/7uWEQ/qjf94IdLsJHD9D 2QnQF6bPX1D7n/jDlnDwzp8+tXK+PDw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1d93JT-0000vQ-Ut; Fri, 12 May 2017 05:40:27 +0000 Received: from mail-qt0-x243.google.com ([2607:f8b0:400d:c0d::243]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d93JQ-0008Kq-T0 for linux-mtd@lists.infradead.org; Fri, 12 May 2017 05:40:26 +0000 Received: by mail-qt0-x243.google.com with SMTP id a46so5589341qte.0 for ; Thu, 11 May 2017 22:40:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=VNf2Hf6kDflU38wAiZmYMIZ2hGlHZ7nrJVAxkMZHUjk=; b=i+s800H0YEDh+Cj+2eTr89R1a3bd87f4Anisvhl0YyjUdyviGnoUntNPq5wi0Hy52j ZLAz8OJd+vNQazyDgI1BTXWyL1OP2qmb8hy/a0KyxUgLEGROg+XVeXSroL1/nRDWiI+w eWDHLcRdjNk+dSmfZ37hVgvrzp2JeflPJGVdJVeg0SQDLfxBwvuWHkwjC31qQCZtEIjN a5hgfO6SOe+T0T599ZiJjWebCvaScoO3RWTcVEWi6d5RpJd9I5/zpsMRIm1eyQRwZr5F A6a7K8nM8abbMLQHhVhWMZDAQt+tYSu2mvIr5wkprgNLJPUgeu2iwxAMbCL6JuB7HGV1 wB5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=VNf2Hf6kDflU38wAiZmYMIZ2hGlHZ7nrJVAxkMZHUjk=; b=OMbZ8L8Xd/7y1K7+PBSXZ7nJ9D2ntoRxSecTRYwZzIxp3Tyx9ookqthEDdmNqBf55n 0uP6ZTfUfbiEKBQpv0sLE5xcq/ViDkBOzv9RMq7WlWVThO5Eyf+ci3VjGEUDWjY6E22e vM0I1x+LclwLQEduqEeF/mHSX8kA4UTtMt9s9UCLdpTs+LNlL/PImvKWUGSTn6gjya8Z rfO3Bn9bgkeArbmKZbob4Dt0f7IAaqQMx22vVVGtJ+xhMnH/T5mu1jIR+yJt4fDFmLLf kc/K1ERCSdsNUYDuAAXyA6wF/+1xK7x0RCcoQhYQ+3MX735d1x514KMAMwn7AM8hHsP1 ciFA== X-Gm-Message-State: AODbwcBbX8DzNIfDHik56HSBdoeWeBBlm4taQx9Zo7lzTqM7gL7fg3LF 2J6lgapJDhfzwQ== X-Received: by 10.237.34.246 with SMTP id q51mr135979qtc.39.1494567602403; Thu, 11 May 2017 22:40:02 -0700 (PDT) Received: from localhost ([191.85.47.115]) by smtp.gmail.com with ESMTPSA id a45sm1660533qta.39.2017.05.11.22.40.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 11 May 2017 22:40:01 -0700 (PDT) From: "Mario J. Rugiero" To: linux-mtd@lists.infradead.org Subject: [PATCH] mtd: nand: add option to erase NAND blocks even if detected as bad. Date: Fri, 12 May 2017 02:39:57 -0300 Message-Id: <20170512053957.10426-1-mrugiero@gmail.com> X-Mailer: git-send-email 2.13.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170511_224025_061929_CB7B482A X-CRM114-Status: GOOD ( 10.81 ) X-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-2.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2607:f8b0:400d:c0d:0:0:0:243 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (mrugiero[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Mario J. Rugiero" MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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 --- 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..e5b29fab4a60 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