From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-iy0-f177.google.com ([209.85.210.177]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1RkLmO-0004Da-3x for linux-mtd@lists.infradead.org; Mon, 09 Jan 2012 20:25:16 +0000 Received: by mail-iy0-f177.google.com with SMTP id k27so8400220iad.36 for ; Mon, 09 Jan 2012 12:25:16 -0800 (PST) From: Brian Norris To: Subject: [PATCH v3 3/6] mtd: nand: erase block before marking bad Date: Mon, 9 Jan 2012 12:23:29 -0800 Message-Id: <1326140612-26323-4-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: , Many NAND flash systems (especially those with MLC NAND) cannot be reliably written twice in a row. For instance, when marking a bad block, the block may already have data written to it, and so we should attempt to erase the block before writing a bad block marker to its OOB region. We can ignore erase failures, since the block may be bad such that it cannot be erased properly; we still attempt to write zeros to its spare area. Note that the erase must be performed before the BBT is updated, since otherwise, nand_erase_nand() would not allow us to erase our "bad block." Signed-off-by: Brian Norris --- drivers/mtd/nand/nand_base.c | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-) diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index ead2a12..d5dbe0a 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -397,6 +397,16 @@ static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs) BUG_ON((chip->options & NAND_NO_WRITE_OOB) && !(chip->bbt_options & NAND_BBT_USE_FLASH)); + /* Erase before writing to OOB and before BBT is updated */ + if (!(chip->options & NAND_NO_WRITE_OOB)) { + struct erase_info einfo; + memset(&einfo, 0, sizeof(einfo)); + einfo.mtd = mtd; + einfo.addr = ofs; + einfo.len = 1 << chip->phys_erase_shift; + nand_erase_nand(mtd, &einfo, 0); + } + if (chip->bbt_options & NAND_BBT_SCANLASTPAGE) ofs += mtd->erasesize - mtd->writesize; -- 1.7.5.4