[PATCH v3 1/6] mtd: nand: add NAND_NO_WRITE_OOB option

Brian Norris computersforpeace at gmail.com
Mon Jan 9 15:23:27 EST 2012


Some systems cannot use the OOB area for storing any information, not
even bad block markers (for instance, if ECC uses entire spare area).
Thus, we implement an option to prevent ever writing to OOB. This will
be useful for determining whether to record bad blocks by writing to the
flash-based BBT, the bad block's OOB region, or both.

Signed-off-by: Brian Norris <computersforpeace at gmail.com>
---
 drivers/mtd/nand/nand_base.c |    8 ++++++--
 include/linux/mtd/nand.h     |    6 ++++++
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 35b4565..b9dbf0c 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -2187,6 +2187,7 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to,
 	int ret, subpage;
 
 	ops->retlen = 0;
+	ops->oobretlen = 0;
 	if (!writelen)
 		return 0;
 
@@ -2238,7 +2239,7 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to,
 			wbuf = chip->buffers->databuf;
 		}
 
-		if (unlikely(oob)) {
+		if (unlikely(oob) && !(chip->options & NAND_NO_WRITE_OOB)) {
 			size_t len = min(oobwritelen, oobmaxlen);
 			oob = nand_fill_oob(mtd, oob, len, ops);
 			oobwritelen -= len;
@@ -2270,7 +2271,7 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to,
 	}
 
 	ops->retlen = ops->len - writelen;
-	if (unlikely(oob))
+	if (unlikely(oob) && !(chip->options & NAND_NO_WRITE_OOB))
 		ops->oobretlen = ops->ooblen;
 	return ret;
 }
@@ -2372,6 +2373,9 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,
 	pr_debug("%s: to = 0x%08x, len = %i\n",
 			 __func__, (unsigned int)to, (int)ops->ooblen);
 
+	if (chip->options & NAND_NO_WRITE_OOB)
+		return 0;
+
 	if (ops->mode == MTD_OPS_AUTO_OOB)
 		len = chip->ecc.layout->oobavail;
 	else
diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
index 63b5a8b..3547205 100644
--- a/include/linux/mtd/nand.h
+++ b/include/linux/mtd/nand.h
@@ -228,6 +228,12 @@ typedef enum {
 #define NAND_OWN_BUFFERS	0x00020000
 /* Chip may not exist, so silence any errors in scan */
 #define NAND_SCAN_SILENT_NODEV	0x00040000
+/*
+ * Do not write to OOB. Useful, e.g., when ECC takes up entire OOB. Should be
+ * used with flash-based BBT, since the bad block markers will no longer be
+ * reliable.
+ */
+#define NAND_NO_WRITE_OOB	0x00080000
 
 /* Options set by nand scan */
 /* Nand scan has allocated controller struct */
-- 
1.7.5.4




More information about the linux-mtd mailing list