linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Brian Norris <computersforpeace@gmail.com>
To: <linux-mtd@lists.infradead.org>
Cc: Dan Carpenter <error27@gmail.com>,
	Kulikov Vasiliy <segooon@gmail.com>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	Nicolas Ferre <nicolas.ferre@atmel.com>,
	Dominik Brodowski <linux@dominikbrodowski.net>,
	Peter Wippich <pewi@gw-instruments.de>,
	Gabor Juhos <juhosg@openwrt.org>,
	Guillaume LECERF <glecerf@gmail.com>,
	Jonas Gorski <jonas.gorski@gmail.com>,
	Jamie Iles <jamie@jamieiles.com>,
	Ivan Djelic <ivan.djelic@parrot.com>,
	Robert Jarzmik <robert.jarzmik@free.fr>,
	David Woodhouse <David.Woodhouse@intel.com>,
	Maxim Levitsky <maximlevitsky@gmail.com>,
	Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>,
	Kevin Cernekee <cernekee@gmail.com>,
	Barry Song <21cnbao@gmail.com>,
	Jim Quinlan <jim2101024@gmail.com>,
	Andres Salomon <dilinger@queued.net>,
	Axel Lin <axel.lin@gmail.com>, Anatolij Gustschin <agust@denx.de>,
	Mike Frysinger <vapier@gentoo.org>, Arnd Bergmann <arnd@arndb.de>,
	Lei Wen <leiwen@marvell.com>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	Artem Bityutskiy <artem.bityutskiy@intel.com>,
	Florian Fainelli <florian@openwrt.org>,
	Artem Bityutskiy <dedekind1@gmail.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Matthieu CASTET <matthieu.castet@parrot.com>,
	Kyungmin Park <kyungmin.park@samsung.com>,
	Shmulik Ladkani <shmulik.ladkani@gmail.com>,
	Wolfram Sang <w.sang@pengutronix.de>,
	Chuanxiao Dong <chuanxiao.dong@intel.com>,
	Joe Perches <joe@perches.com>,
	Brian Norris <computersforpeace@gmail.com>,
	Roman Tereshonkov <roman.tereshonkov@nokia.com>
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	[thread overview]
Message-ID: <1326140612-26323-3-git-send-email-computersforpeace@gmail.com> (raw)
In-Reply-To: <1326140612-26323-1-git-send-email-computersforpeace@gmail.com>

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 <computersforpeace@gmail.com>
---
 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

  parent reply	other threads:[~2012-01-09 20:25 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-09 20:23 [PATCH v3 0/6] NAND BBM + BBT updates Brian Norris
2012-01-09 20:23 ` [PATCH v3 1/6] mtd: nand: add NAND_NO_WRITE_OOB option Brian Norris
2012-01-09 20:23 ` Brian Norris [this message]
2012-01-09 20:23 ` [PATCH v3 3/6] mtd: nand: erase block before marking bad Brian Norris
2012-01-13 22:42   ` Artem Bityutskiy
2012-01-13 23:07     ` Brian Norris
2012-01-09 20:23 ` [PATCH v3 4/6] mtd: nand: fix SCAN2NDPAGE check for BBM Brian Norris
2012-01-09 20:23 ` [PATCH v3 5/6] mtd: nand: differentiate 1- vs. 2-byte writes when marking bad blocks Brian Norris
2012-01-09 20:23 ` [PATCH v3 6/6] mtd: nand: correct comment on nand_chip badblockbits Brian Norris
2012-01-10  9:44 ` [PATCH v3 0/6] NAND BBM + BBT updates Sebastian Andrzej Siewior
2012-01-10 18:54   ` Brian Norris
2012-01-11 22:28   ` Artem Bityutskiy
2012-01-12  7:58     ` Shmulik Ladkani
2012-01-13 22:12       ` Artem Bityutskiy
2012-01-16 19:35         ` Shmulik Ladkani
2012-01-12  9:09     ` Sebastian Andrzej Siewior
2012-01-13 22:36       ` Artem Bityutskiy
2012-01-16 20:59         ` Woodhouse, David
2012-01-17  8:23           ` Artem Bityutskiy
2012-01-17  8:27             ` Artem Bityutskiy
2012-01-17 11:19         ` Angus CLARK
2012-01-17 13:06           ` Ivan Djelic
2012-01-18 22:18         ` Brian Norris
2012-01-17 10:22     ` Angus CLARK
2012-01-17 13:33       ` Artem Bityutskiy
2012-01-18 22:04       ` Brian Norris
2012-01-19  9:30         ` Angus CLARK
2012-01-19  9:59           ` Ricard Wanderlof

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1326140612-26323-3-git-send-email-computersforpeace@gmail.com \
    --to=computersforpeace@gmail.com \
    --cc=21cnbao@gmail.com \
    --cc=David.Woodhouse@intel.com \
    --cc=adrian.hunter@intel.com \
    --cc=agust@denx.de \
    --cc=arnd@arndb.de \
    --cc=artem.bityutskiy@intel.com \
    --cc=axel.lin@gmail.com \
    --cc=bigeasy@linutronix.de \
    --cc=cernekee@gmail.com \
    --cc=chuanxiao.dong@intel.com \
    --cc=dbaryshkov@gmail.com \
    --cc=dedekind1@gmail.com \
    --cc=dilinger@queued.net \
    --cc=error27@gmail.com \
    --cc=florian@openwrt.org \
    --cc=glecerf@gmail.com \
    --cc=ivan.djelic@parrot.com \
    --cc=jamie@jamieiles.com \
    --cc=jim2101024@gmail.com \
    --cc=joe@perches.com \
    --cc=jonas.gorski@gmail.com \
    --cc=juhosg@openwrt.org \
    --cc=kyungmin.park@samsung.com \
    --cc=leiwen@marvell.com \
    --cc=linux-mtd@lists.infradead.org \
    --cc=linux@dominikbrodowski.net \
    --cc=matthieu.castet@parrot.com \
    --cc=maximlevitsky@gmail.com \
    --cc=nicolas.ferre@atmel.com \
    --cc=pewi@gw-instruments.de \
    --cc=robert.jarzmik@free.fr \
    --cc=roman.tereshonkov@nokia.com \
    --cc=s.hauer@pengutronix.de \
    --cc=segooon@gmail.com \
    --cc=shmulik.ladkani@gmail.com \
    --cc=vapier@gentoo.org \
    --cc=w.sang@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).