mtd/drivers/mtd/nand nand_bbt.c,1.18,1.19

dbrown at infradead.org dbrown at infradead.org
Tue Jun 22 14:22:24 EDT 2004


Update of /home/cvs/mtd/drivers/mtd/nand
In directory phoenix.infradead.org:/tmp/cvs-serv5583

Modified Files:
	nand_bbt.c 
Log Message:
Update on-flash BBT if additional reserved pages need to be marked.  Fix some comments at top.


Index: nand_bbt.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/nand/nand_bbt.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- nand_bbt.c	22 Jun 2004 17:26:36 -0000	1.18
+++ nand_bbt.c	22 Jun 2004 18:22:21 -0000	1.19
@@ -38,9 +38,13 @@
  * 00b: 	block is factory marked bad
  * 01b, 10b: 	block is marked bad due to wear
  *
- * The memory bad block table uses the same scheme.
+ * The memory bad block table uses the following scheme:
+ * 00b:		block is good
+ * 01b:		block is marked bad due to wear
+ * 10b:		block is reserved (to protect the bbt area)
+ * 11b:		block is factory marked bad
  * 
- * Multichip devices like DOC store the bad block info per floor (chip).
+ * Multichip devices like DOC store the bad block info per floor.
  *
  * Following assumptions are made:
  * - bbts start at a page boundary, if autolocated on a block boundary
@@ -701,7 +705,8 @@
 static void mark_bbt_region (struct mtd_info *mtd, struct nand_bbt_descr *td)
 {
 	struct nand_chip *this = mtd->priv;
-	int i, j, chips, block, nrblocks;
+	int i, j, chips, block, nrblocks, update;
+	uint8_t oldval, newval;
 
 	/* Do we have a bbt per chip ? */
 	if (td->options & NAND_BBT_PERCHIP) {
@@ -718,18 +723,31 @@
 		    	if (td->pages[i] == -1) continue;
 			block = td->pages[i] >> (this->erase_shift - this->page_shift);
 			block <<= 1;		
-			this->bbt[(block >> 3)] |= 0x2 << (block & 0x06);
+			oldval = this->bbt[(block >> 3)];
+			newval = oldval | (0x2 << (block & 0x06));
+			this->bbt[(block >> 3)] = newval;
+			if ((oldval != newval) && td->reserved_block_code)
+				nand_update_bbt(mtd, block << (this->erase_shift - 1));
 			continue;
-		} 
+		}
+		update = 0;
 		if (td->options & NAND_BBT_LASTBLOCK)
 			block = ((i + 1) * nrblocks) - td->maxblocks;
 		else	
 			block = i * nrblocks;
 		block <<= 1;	
 		for (j = 0; j < td->maxblocks; j++) {
-			this->bbt[(block >> 3)] |= 0x2 << (block & 0x06);
+			oldval = this->bbt[(block >> 3)];
+			newval = oldval | (0x2 << (block & 0x06));
+			this->bbt[(block >> 3)] = newval;
+			if (oldval != newval) update = 1;
 			block += 2;
 		}	
+		/* If we want reserved blocks to be recorded to flash, and some
+		   new ones have been marked, then we need to update the stored
+		   bbts.  This should only happen once. */
+		if (update && td->reserved_block_code)
+			nand_update_bbt(mtd, (block - 2) << (this->erase_shift - 1));
 	}
 }
 





More information about the linux-mtd-cvs mailing list