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

dbrown at infradead.org dbrown at infradead.org
Tue Jun 22 13:26:39 EDT 2004


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

Modified Files:
	nand_bbt.c 
Log Message:
Reduce BBT version code to 1 byte (also handle wraparound properly).  Fix error in reserved page marking.


Index: nand_bbt.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/nand/nand_bbt.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- nand_bbt.c	22 Jun 2004 13:59:32 -0000	1.17
+++ nand_bbt.c	22 Jun 2004 17:26:36 -0000	1.18
@@ -355,8 +355,7 @@
 			if (!check_pattern(buf, scanlen, mtd->oobblock, td)) {
 				td->pages[i] = actblock << (this->erase_shift - this->page_shift);
 				if (td->options & NAND_BBT_VERSION) {
-					int *p = (int *) &buf[mtd->oobblock + td->veroffs];
-					td->version[i] = (int) le32_to_cpu (*p);
+					td->version[i] = *((char *) &buf[mtd->oobblock + td->veroffs]);
 				}
 				break;
 			}
@@ -368,7 +367,7 @@
 		if (td->pages[i] == -1)
 			printk (KERN_WARNING "Bad block table not found for chip %d\n", i);
 		else
-			printk (KERN_DEBUG "Bad block table found at page %d, version %d\n", td->pages[i], td->version[i]);
+			printk (KERN_DEBUG "Bad block table found at page %d, version 0x%02X\n", td->pages[i], td->version[i]);
 	}
 	return 0;	
 }
@@ -421,7 +420,7 @@
 	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) {
 		numblocks = (int) (this->chipsize >> this->erase_shift);
@@ -479,10 +478,10 @@
 		/* Set up shift count and masks for the flash table */
 		bits = td->options & NAND_BBT_NRBITS_MSK;
 		switch (bits) {
-		case 1: sft = 3; sftmsk = 0x07; msk[0] = 0x00; msk[1] = 0x01; msk[2] = td->reserved_block_code; msk[3] = 0x01; break;
-		case 2: sft = 2; sftmsk = 0x06; msk[0] = 0x00; msk[1] = 0x01; msk[2] = td->reserved_block_code; msk[3] = 0x03; break;
-		case 4: sft = 1; sftmsk = 0x04; msk[0] = 0x00; msk[1] = 0x0C; msk[2] = td->reserved_block_code; msk[3] = 0x0f; break;
-		case 8: sft = 0; sftmsk = 0x00; msk[0] = 0x00; msk[1] = 0x0F; msk[2] = td->reserved_block_code; msk[3] = 0xff; break;
+		case 1: sft = 3; sftmsk = 0x07; msk[0] = 0x00; msk[1] = 0x01; msk[2] = ~td->reserved_block_code; msk[3] = 0x01; break;
+		case 2: sft = 2; sftmsk = 0x06; msk[0] = 0x00; msk[1] = 0x01; msk[2] = ~td->reserved_block_code; msk[3] = 0x03; break;
+		case 4: sft = 1; sftmsk = 0x04; msk[0] = 0x00; msk[1] = 0x0C; msk[2] = ~td->reserved_block_code; msk[3] = 0x0f; break;
+		case 8: sft = 0; sftmsk = 0x00; msk[0] = 0x00; msk[1] = 0x0F; msk[2] = ~td->reserved_block_code; msk[3] = 0xff; break;
 		default: return -EINVAL;
 		}
 		
@@ -522,8 +521,7 @@
 			/* Pattern is located in oob area of first page */
 			memcpy (&buf[len + td->offs], td->pattern, td->len);
 			if (td->options & NAND_BBT_VERSION) {
-				int *p = (int *) &buf[len + td->veroffs];
-				*p = (int) cpu_to_le32 (td->version[chip]);
+				*((char *) &buf[len + td->veroffs]) = td->version[chip];
 			}
 		}
 	
@@ -554,7 +552,7 @@
 			printk (KERN_WARNING "nand_bbt: Error while writing bad block table %d\n", res);
 			return res;
 		}
-		printk (KERN_DEBUG "Bad block table written to 0x%08x, version %d\n", 
+		printk (KERN_DEBUG "Bad block table written to 0x%08x, version 0x%02X\n", 
 			(unsigned int) to, td->version[chip]);
 	
 		/* Mark it as used */
@@ -621,12 +619,14 @@
 
 			if (td->pages[i] == -1) {
 				rd = md;				
+				td->version[i] = md->version[i];
 				writeops = 1;
 				goto writecheck;
 			}
 
 			if (md->pages[i] == -1) {
 				rd = td;
+				md->version[i] = td->version[i];
 				writeops = 2;
 				goto writecheck;
 			}
@@ -636,7 +636,7 @@
 				goto writecheck;
 			}	
 
-			if (td->version[i] > md->version[i]) {
+			if ((td->version[i] - md->version[i]) > 0) {
 				rd = td;
 				md->version[i] = td->version[i];
 				writeops = 2;





More information about the linux-mtd-cvs mailing list