From patchwork Wed Dec 7 21:08:20 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 130039 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E151B1007D5 for ; Thu, 8 Dec 2011 08:10:49 +1100 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1RYOjf-00061g-Lz; Wed, 07 Dec 2011 21:09:03 +0000 Received: from mail-qy0-f177.google.com ([209.85.216.177]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1RYOjc-00061P-4Z for linux-mtd@lists.infradead.org; Wed, 07 Dec 2011 21:09:00 +0000 Received: by qcsf1 with SMTP id f1so914519qcs.36 for ; Wed, 07 Dec 2011 13:08:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; bh=BnekRBGB1Zq0vwv/nxFu+8ggHPIJxOz8usshiYqLTN8=; b=bgVwnxz0a5sk0OoyH44A4f8fuxSX2E8TYtDuoJXEd3r9wgO/NVVVDytPLdb8jaA9sV HHcl7OBJkjKBCLNBjXR3YdZoLbQPu/Fj9oVlIaxKDYinlGuAwFPesEyXGuj4Wssoi6uw +C/IAFoqIRlVgWB5BwHEQedXgVpT8Mwvrij8w= Received: by 10.50.207.40 with SMTP id lt8mr576591igc.43.1323292138194; Wed, 07 Dec 2011 13:08:58 -0800 (PST) Received: from localhost.localdomain (5520-maca-inet1-outside.broadcom.com. [216.31.211.11]) by mx.google.com with ESMTPS id j1sm5832733igq.2.2011.12.07.13.08.56 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 07 Dec 2011 13:08:57 -0800 (PST) From: Brian Norris To: Artem Bityutskiy Subject: [PATCH] mtd: nand: write bad block marker even with BBT Date: Wed, 7 Dec 2011 13:08:20 -0800 Message-Id: <1323292100-19280-1-git-send-email-computersforpeace@gmail.com> X-Mailer: git-send-email 1.7.5.4 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.216.177 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (computersforpeace[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -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 Cc: Jim Quinlan , Kevin Cernekee , Brian Norris , linux-mtd@lists.infradead.org, Matthieu CASTET X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.14 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-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Add and option (NAND_BBT_WRITE_BBM) for writing bad block markers to proper OOB area on each block in addition to flash-based BBT. This is useful when: * bootloader cannot read the flash-based BBT format * BBT is corrupted and the flash must be rescanned for bad blocks; we want to remember bad blocks that were marked from Linux Adapted from code by Matthieu CASTET. Cc: Matthieu CASTET Signed-off-by: Brian Norris --- Last year's discussion thread: http://lists.infradead.org/pipermail/linux-mtd/2010-October/032942.html I'll address the criticisms: "add a BUG_ON to catch misuse cases when NAND_WRITE_BB [now named NAND_BBT_WRITE_BBM] is used without NAND_USE_FLASH_BBT - they should go in pair" NAND_BBT_WRITE_BBM has no special effect when used without NAND_BBT_USE_FLASH; it's already the default behavior. So I don't expect it to be an issue. "And also, how about cases when BBT is updated, but OOB did not because of a power cut" Not a very likely case as bad blocks are written infrequently, plus for the situations where we're writing BBM simply because the bootloader doesn't understand our BBT, having 99% of blocks marked properly is better than none. drivers/mtd/nand/nand_base.c | 11 +++++++++-- include/linux/mtd/bbm.h | 9 +++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index 35b4565..6d619f7 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -392,7 +392,7 @@ static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs) { struct nand_chip *chip = mtd->priv; uint8_t buf[2] = { 0, 0 }; - int block, ret, i = 0; + int block, ret = 0, i = 0; if (chip->bbt_options & NAND_BBT_SCANLASTPAGE) ofs += mtd->erasesize - mtd->writesize; @@ -405,7 +405,14 @@ static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs) /* Do we have a flash based bad block table? */ if (chip->bbt_options & NAND_BBT_USE_FLASH) ret = nand_update_bbt(mtd, ofs); - else { + /* + * Write bad block marker to OOB, in one of two cases: + * (1) we don't have flash-based BBT + * (2) we have flash-based BBT but also want to keep markers in OOB in + * each block + */ + if (!(chip->bbt_options & NAND_BBT_USE_FLASH) || + (chip->bbt_options & NAND_BBT_WRITE_BBM)) { struct mtd_oob_ops ops; nand_get_device(chip, mtd, FL_WRITING); diff --git a/include/linux/mtd/bbm.h b/include/linux/mtd/bbm.h index c4eec22..61fcb30 100644 --- a/include/linux/mtd/bbm.h +++ b/include/linux/mtd/bbm.h @@ -112,6 +112,15 @@ struct nand_bbt_descr { #define NAND_BBT_USE_FLASH 0x00020000 /* Do not store flash based bad block table in OOB area; store it in-band */ #define NAND_BBT_NO_OOB 0x00040000 +/* + * Write bad block marker to OOB when marking new bad blocks. This is the + * default behavior without NAND_USE_FLASH_BBT, so this is only useful in + * conjunction with NAND_USE_FLASH_BBT. + * One might need bad blocks marked in each block as well as in BBT when + * bootloader cannot read the flash-based BBT format or when the BBT is + * corrupted and the flash must be rescanned for bad blocks. + */ +#define NAND_BBT_WRITE_BBM 0x00080000 /* * Flag set by nand_create_default_bbt_descr(), marking that the nand_bbt_descr