mtd/drivers/mtd/nand nand_bbt.c,1.12,1.13

gleixner at infradead.org gleixner at infradead.org
Tue Jun 1 15:43:27 EDT 2004


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

Modified Files:
	nand_bbt.c 
Log Message:
Fix per chip write support. Signed-off-by: Thomas Gleixner <tglx at linutronix.de>

Index: nand_bbt.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/nand/nand_bbt.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- nand_bbt.c	1 Jun 2004 13:11:00 -0000	1.12
+++ nand_bbt.c	1 Jun 2004 19:43:25 -0000	1.13
@@ -404,27 +404,27 @@
 	struct nand_chip *this = mtd->priv;
 	struct nand_oobinfo oobinfo;
 	struct erase_info einfo;
-	int i, j, res, chip;
+	int i, j, res, chip = 0;
 	int bits, startblock, dir, page, offs, numblocks, sft, sftmsk;
 	int nrchips, bbtoffs;
 	uint8_t msk[4];
 	size_t retlen, len = 0;
 	loff_t to;
 	
-	
 	/* Write bad block table per chip rather than per device ? */
-	if (td->options & NAND_BBT_PERCHIP)  
-		nrchips = this->numchips;
-	else
-		nrchips = 1;	
-	
-	/* Full device write or specific chip ? */	
-	if (chipsel == -1) 
-		chip = 0;
-	else {
-		nrchips = chipsel + 1;
-		chip = chipsel;
-	}
+	if (td->options & NAND_BBT_PERCHIP) {
+		numblocks = (int) (this->chipsize >> this->erase_shift);
+		/* Full device write or specific chip ? */	
+		if (chipsel == -1) {
+			nrchips = this->numchips;
+		} else {
+			nrchips = chipsel + 1;
+			chip = chipsel;
+		}
+	} else {
+		numblocks = (int) (mtd->size >> this->erase_shift);
+		nrchips = 1;
+	}	
 	
 	/* Loop through the chips */
 	for (; chip < nrchips; chip++) {
@@ -441,20 +441,22 @@
 		/* Automatic placement of the bad block table */
 		/* Search direction top -> down ? */
 		if (td->options & NAND_BBT_LASTBLOCK) {
-			startblock = ((mtd->size >> this->erase_shift) / nrchips);
-			startblock += chip * startblock - 1;
+			startblock = numblocks * (chip + 1) - 1;
 			dir = -1;
 		} else {
-			startblock = chip * (this->chipsize >> this->erase_shift);
+			startblock = chip * numblocks;
 			dir = 1;
 		}	
 
 		for (i = 0; i < td->maxblocks; i++) {
 			int block = startblock + dir * i;
 			/* Check, if the block is bad */
-			if (this->bbt[block >> 2] & (0x03 << ((block << 1) & 0x6)))
+			switch ((this->bbt[block >> 2] >> (2 * (block & 0x03))) & 0x03) {
+			case 0x01:
+			case 0x03:
 				continue;
-			page  = block << (this->erase_shift - this->page_shift);
+			}
+			page = block << (this->erase_shift - this->page_shift);
 			/* Check, if the block is used by the mirror table */
 			if (!md || md->pages[chip] != page)
 				goto write;
@@ -473,13 +475,7 @@
 		default: return -EINVAL;
 		}
 		
-		if (chip != -1) {
-			numblocks = mtd->size >> this->erase_shift;
-			bbtoffs = 0;
-		} else {	
-			numblocks = this->chipsize >> this->erase_shift;
-			bbtoffs = (numblocks >> 2) * chip;
-		}	
+		bbtoffs = chip * (numblocks >> 2);
 		
 		to = ((loff_t) page) << this->page_shift;
 		
@@ -995,10 +991,10 @@
 	
 	/* Get block number * 2 */
 	block = (int) (offs >> (this->erase_shift - 1));
-	res = this->bbt[block >> 3] & (0x3 << (block & 0x06));
-	res >>= (block & 0x06);
+	res = (this->bbt[block >> 3] >> (block & 0x06)) & 0x03;
 
-	DEBUG (MTD_DEBUG_LEVEL0, "nand_isbad_bbt(): bbt info for offs 0x%08x: 0x%02x ", offs, res);
+	DEBUG (MTD_DEBUG_LEVEL2, "nand_isbad_bbt(): bbt info for offs 0x%08x: (block %d) 0x%02x\n", 
+		(unsigned int)offs, res, block >> 1);
 
 	switch ((int)res) {
 	case 0x00:	return 0;





More information about the linux-mtd-cvs mailing list