From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-gx0-f177.google.com ([209.85.161.177]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1RkLmD-0004G9-Es for linux-mtd@lists.infradead.org; Mon, 09 Jan 2012 20:25:06 +0000 Received: by ggnp4 with SMTP id p4so1889968ggn.36 for ; Mon, 09 Jan 2012 12:25:04 -0800 (PST) From: Brian Norris To: Subject: [PATCH v3 2/6] mtd: nand: write bad block marker by default even with BBT Date: Mon, 9 Jan 2012 12:23:28 -0800 Message-Id: <1326140612-26323-3-git-send-email-computersforpeace@gmail.com> In-Reply-To: <1326140612-26323-1-git-send-email-computersforpeace@gmail.com> References: <1326140612-26323-1-git-send-email-computersforpeace@gmail.com> Cc: Dan Carpenter , Kulikov Vasiliy , Sebastian Andrzej Siewior , Nicolas Ferre , Dominik Brodowski , Peter Wippich , Gabor Juhos , Guillaume LECERF , Jonas Gorski , Jamie Iles , Ivan Djelic , Robert Jarzmik , David Woodhouse , Maxim Levitsky , Dmitry Eremin-Solenikov , Kevin Cernekee , Barry Song <21cnbao@gmail.com>, Jim Quinlan , Andres Salomon , Axel Lin , Anatolij Gustschin , Mike Frysinger , Arnd Bergmann , Lei Wen , Sascha Hauer , Artem Bityutskiy , Florian Fainelli , Artem Bityutskiy , Adrian Hunter , Matthieu CASTET , Kyungmin Park , Shmulik Ladkani , Wolfram Sang , Chuanxiao Dong , Joe Perches , Brian Norris , Roman Tereshonkov List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Currently, the flash-based BBT implementation writes bad block data only to its flash-based table and not to the OOB marker area. Then, as new bad blocks are marked over time, the OOB markers become out of date and the flash-based table becomes the only source of current bad block information. This can be a problem when, for example: * 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 In an attempt to keep the bad block markers in sync with the flash-based BBT, this patch changes the default so that we write bad block markers to the proper OOB area on each block in addition to flash-based BBT. Theoretically, the bad block table and the OOB markers can still get out of sync if the system experiences a power cut between writing the BBT to flash and writing the OOB marker to a newly-marked bad block. However, this is a relatively unlikely event, as new bad blocks shouldn't appear frequently. Note that this is a change from the previous default flash-based BBT behavior. To restore old behavior (and to generally prevent writing to OOB area), use the NAND_NO_WRITE_OOB options (in combination with NAND_BBT_USE_FLASH and NAND_BBT_NO_OOB). Signed-off-by: Brian Norris --- drivers/mtd/nand/nand_base.c | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index b9dbf0c..ead2a12 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -392,7 +392,10 @@ 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; + + BUG_ON((chip->options & NAND_NO_WRITE_OOB) && + !(chip->bbt_options & NAND_BBT_USE_FLASH)); if (chip->bbt_options & NAND_BBT_SCANLASTPAGE) ofs += mtd->erasesize - mtd->writesize; @@ -405,7 +408,9 @@ 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 */ + if (!(chip->options & NAND_NO_WRITE_OOB)) { struct mtd_oob_ops ops; nand_get_device(chip, mtd, FL_WRITING); -- 1.7.5.4