From patchwork Thu May 16 14:21:42 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Westfahl X-Patchwork-Id: 244337 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:770:15f::2]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E4CAA2C015E for ; Fri, 17 May 2013 00:22:31 +1000 (EST) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ucz4a-0002Yh-1P; Thu, 16 May 2013 14:22:24 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ucz4X-0005Ph-Nb; Thu, 16 May 2013 14:22:21 +0000 Received: from mailserver5.natinst.com ([130.164.80.5] helo=spamkiller05.natinst.com) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ucz4V-0005Oj-IW for linux-mtd@lists.infradead.org; Thu, 16 May 2013 14:22:20 +0000 Received: from mailserv58-us.natinst.com (nb-chan1-1338.natinst.com [130.164.19.134]) by spamkiller05.natinst.com (8.14.5/8.14.5) with ESMTP id r4GELwB8021206 for ; Thu, 16 May 2013 09:21:58 -0500 Received: from scoamf.amer.corp.natinst.com ([130.164.14.198]) by mailserv58-us.natinst.com (Lotus Domino Release 8.5.3FP2 HF169) with ESMTP id 2013051609215814-170116 ; Thu, 16 May 2013 09:21:58 -0500 From: Jeff Westfahl To: linux-mtd@lists.infradead.org Subject: [RESEND v2 PATCH] mtd: nand: nand_bbt: scan for next free bbt block if writing bbt fails Date: Thu, 16 May 2013 09:21:42 -0500 Message-Id: <1368714102-8399-1-git-send-email-jeff.westfahl@ni.com> X-Mailer: git-send-email 1.7.1 X-MIMETrack: Itemize by SMTP Server on MailServ58-US/AUS/H/NIC(Release 8.5.3FP2 HF169|September 14, 2012) at 05/16/2013 09:21:58 AM, Serialize by Router on MailServ58-US/AUS/H/NIC(Release 8.5.3FP2 HF169|September 14, 2012) at 05/16/2013 09:21:58 AM, Serialize complete at 05/16/2013 09:21:58 AM X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.10.8626, 1.0.431, 0.0.0000 definitions=2013-05-16_04:2013-05-16, 2013-05-16, 1970-01-01 signatures=0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130516_102219_713609_8B477550 X-CRM114-Status: GOOD ( 13.32 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Jeff Westfahl X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org If erasing or writing the BBT fails, we should mark the current BBT block as bad and use the BBT descriptor to scan for the next available unused block in the BBT. We should only return a failure if there isn't any space left. Signed-off-by: Jeff Westfahl --- drivers/mtd/nand/nand_bbt.c | 21 +++++++++++++++++---- 1 files changed, 17 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/nand/nand_bbt.c b/drivers/mtd/nand/nand_bbt.c index 2672643..900bda1 100644 --- a/drivers/mtd/nand/nand_bbt.c +++ b/drivers/mtd/nand/nand_bbt.c @@ -697,6 +697,7 @@ static int write_bbt(struct mtd_info *mtd, uint8_t *buf, page = td->pages[chip]; goto write; } + next: /* * Automatic placement of the bad block table. Search direction @@ -831,14 +832,26 @@ static int write_bbt(struct mtd_info *mtd, uint8_t *buf, einfo.addr = to; einfo.len = 1 << this->bbt_erase_shift; res = nand_erase_nand(mtd, &einfo, 1); - if (res < 0) - goto outerr; + if (res < 0) { + /* This block is bad. Mark it as such and see if there's + another available in the BBT area. */ + int block = page >> + (this->bbt_erase_shift - this->page_shift); + this->bbt[block >> 2] |= 0x01 << ((block & 0x03) << 1); + goto next; + } res = scan_write_bbt(mtd, to, len, buf, td->options & NAND_BBT_NO_OOB ? NULL : &buf[len]); - if (res < 0) - goto outerr; + if (res < 0) { + /* This block is bad. Mark it as such and see if there's + another available in the BBT area. */ + int block = page >> + (this->bbt_erase_shift - this->page_shift); + this->bbt[block >> 2] |= 0x01 << ((block & 0x03) << 1); + goto next; + } pr_info("Bad block table written to 0x%012llx, version 0x%02X\n", (unsigned long long)to, td->version[chip]);