mtd/drivers/mtd/nand nand_base.c,1.108,1.109 nand_bbt.c,1.19,1.20

dbrown at infradead.org dbrown at infradead.org
Thu Jun 24 08:39:38 EDT 2004


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

Modified Files:
	nand_base.c nand_bbt.c 
Log Message:
Add ability to use a larger (virtual) eraseblock size for BBT tables.


Index: nand_base.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/nand/nand_base.c,v
retrieving revision 1.108
retrieving revision 1.109
diff -u -r1.108 -r1.109
--- nand_base.c	22 Jun 2004 15:04:40 -0000	1.108
+++ nand_base.c	24 Jun 2004 12:39:35 -0000	1.109
@@ -432,7 +432,7 @@
 	int block;
 	
 	/* Get block number */
-	block = ((int) ofs) >> this->erase_shift;
+	block = ((int) ofs) >> this->bbt_erase_shift;
 	this->bbt[block >> 2] |= 0x01 << ((block & 0x03) << 1);
 
 	/* Do we have a flash based bad block table ? */
@@ -1035,7 +1035,7 @@
 	u_char ecc_code[32];
         int eccmode, eccsteps;
 	int	*oob_config, datidx;
-	int	blockcheck = (mtd->erasesize >> this->page_shift) - 1;
+	int	blockcheck = (1 << (this->phys_erase_shift - this->page_shift)) - 1;
 	int	eccbytes = 3;
 	int	compareecc = 1;
 	int	oobreadlen;
@@ -1306,7 +1306,7 @@
 {
 	int i, col, page, chipnr;
 	struct nand_chip *this = mtd->priv;
-	int	blockcheck = (mtd->erasesize >> this->page_shift) - 1;
+	int	blockcheck = (1 << (this->phys_erase_shift - this->page_shift)) - 1;
 
 	DEBUG (MTD_DEBUG_LEVEL3, "nand_read_oob: from = 0x%08x, len = %i\n", (unsigned int) from, (int) len);
 
@@ -1402,7 +1402,7 @@
 	int sndcmd = 1;
 	int cnt = 0;
 	int pagesize = mtd->oobblock + mtd->oobsize;
-	int blockcheck = (mtd->erasesize >> this->page_shift) - 1;
+	int	blockcheck = (1 << (this->phys_erase_shift - this->page_shift)) - 1;
 
 	/* Do not allow reads past end of device */
 	if ((from + len) > mtd->size) {
@@ -1481,7 +1481,7 @@
 	/* Check, if the buffer must be filled with ff again */
 	if (this->oobdirty) {	
 		memset (this->oob_buf, 0xff, 
-			mtd->oobsize << (this->erase_shift - this->page_shift));
+			mtd->oobsize << (this->phys_erase_shift - this->page_shift));
 		this->oobdirty = 0;
 	}	
 	
@@ -1542,7 +1542,7 @@
 	int autoplace = 0, numpages, totalpages;
 	struct nand_chip *this = mtd->priv;
 	u_char *oobbuf, *bufstart;
-	int ppblock = mtd->erasesize >> this->page_shift;
+	int	ppblock = (1 << (this->phys_erase_shift - this->page_shift));
 
 	DEBUG (MTD_DEBUG_LEVEL3, "nand_write_ecc: to = 0x%08x, len = %i\n", (unsigned int) to, (int) len);
 
@@ -1809,7 +1809,7 @@
 	int i, page, len, total_len, ret = -EIO, written = 0, chipnr;
 	int oob, numpages, autoplace = 0, startpage;
 	struct nand_chip *this = mtd->priv;
-	int ppblock = mtd->erasesize >> this->page_shift;
+	int	ppblock = (1 << (this->phys_erase_shift - this->page_shift));
 	u_char *oobbuf, *bufstart;
 
 	/* Preset written len for early exit */
@@ -2019,13 +2019,13 @@
 	       "nand_erase: start = 0x%08x, len = %i\n", (unsigned int) instr->addr, (unsigned int) instr->len);
 
 	/* Start address must align on block boundary */
-	if (instr->addr & (mtd->erasesize - 1)) {
+	if (instr->addr & ((1 << this->phys_erase_shift) - 1)) {
 		DEBUG (MTD_DEBUG_LEVEL0, "nand_erase: Unaligned address\n");
 		return -EINVAL;
 	}
 
 	/* Length must align on block boundary */
-	if (instr->len & (mtd->erasesize - 1)) {
+	if (instr->len & ((1 << this->phys_erase_shift) - 1)) {
 		DEBUG (MTD_DEBUG_LEVEL0, "nand_erase: Length not block aligned\n");
 		return -EINVAL;
 	}
@@ -2044,7 +2044,7 @@
 	chipnr = (int) (instr->addr >> this->chip_shift);
 
 	/* Calculate pages in each block */
-	pages_per_block = 1 << (this->erase_shift - this->page_shift);
+	pages_per_block = 1 << (this->phys_erase_shift - this->page_shift);
 
 	/* Select the NAND device */
 	this->select_chip(mtd, chipnr);
@@ -2087,7 +2087,7 @@
 		}
 		
 		/* Increment page address and decrement length */
-		len -= mtd->erasesize;
+		len -= (1 << this->phys_erase_shift);
 		page += pages_per_block;
 
 		/* Check, if we cross a chip boundary */
@@ -2310,7 +2310,7 @@
 		
 		/* Calculate the address shift from the page size */	
 		this->page_shift = ffs(mtd->oobblock) - 1;
-		this->erase_shift = ffs(mtd->erasesize) - 1;
+		this->bbt_erase_shift = this->phys_erase_shift = ffs(mtd->erasesize) - 1;
 		this->chip_shift = ffs(this->chipsize) - 1;
 
 		/* Set the bad block position */
@@ -2372,7 +2372,7 @@
 	/* Allocate buffers, if neccecary */
 	if (!this->oob_buf) {
 		size_t len;
-		len = mtd->oobsize << (this->erase_shift - this->page_shift);
+		len = mtd->oobsize << (this->phys_erase_shift - this->page_shift);
 		this->oob_buf = kmalloc (len, GFP_KERNEL);
 		if (!this->oob_buf) {
 			printk (KERN_ERR "nand_scan(): Cannot allocate oob_buf\n");
@@ -2400,7 +2400,7 @@
 	/* Convert chipsize to number of pages per chip -1. */
 	this->pagemask = (this->chipsize >> this->page_shift) - 1;
 	/* Preset the internal oob buffer */
-	memset(this->oob_buf, 0xff, mtd->oobsize << (this->erase_shift - this->page_shift));
+	memset(this->oob_buf, 0xff, mtd->oobsize << (this->phys_erase_shift - this->page_shift));
 
 	/* If no default placement scheme is given, select an
 	 * appropriate one */

Index: nand_bbt.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/nand/nand_bbt.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- nand_bbt.c	22 Jun 2004 18:22:21 -0000	1.19
+++ nand_bbt.c	24 Jun 2004 12:39:35 -0000	1.20
@@ -131,7 +131,7 @@
 	from = ((loff_t)page) << this->page_shift;
 	
 	while (totlen) {
-		len = min (totlen, (size_t) (1 << this->erase_shift));
+		len = min (totlen, (size_t) (1 << this->bbt_erase_shift));
 		res = mtd->read_ecc (mtd, from, len, &retlen, buf, NULL, this->autooob);
 		if (res < 0) {
 			if (retlen != len) {
@@ -151,14 +151,14 @@
 				if (reserved_block_code &&
 				    (tmp == reserved_block_code)) {
 					printk (KERN_DEBUG "nand_read_bbt: Reserved block at 0x%08x\n",
-						((offs << 2) + (act >> 1)) << this->erase_shift);
+						((offs << 2) + (act >> 1)) << this->bbt_erase_shift);
 					this->bbt[offs + (act >> 3)] |= 0x2 << (act & 0x06);
 					continue;
 				}
 				/* Leave it for now, if its matured we can move this
 				 * message to MTD_DEBUG_LEVEL0 */
 				printk (KERN_DEBUG "nand_read_bbt: Bad block at 0x%08x\n",
-					((offs << 2) + (act >> 1)) << this->erase_shift);
+					((offs << 2) + (act >> 1)) << this->bbt_erase_shift);
 				/* Factory marked bad or worn out ? */	
 				if (tmp == 0)
 					this->bbt[offs + (act >> 3)] |= 0x3 << (act & 0x06);
@@ -194,13 +194,13 @@
 		int offs = 0;
 		for (i = 0; i < this->numchips; i++) {
 			if (chip == -1 || chip == i)
-				res = read_bbt (mtd, buf, td->pages[i], this->chipsize >> this->erase_shift, bits, offs, td->reserved_block_code);
+				res = read_bbt (mtd, buf, td->pages[i], this->chipsize >> this->bbt_erase_shift, bits, offs, td->reserved_block_code);
 			if (res)
 				return res;
-			offs += this->chipsize >> (this->erase_shift + 2);
+			offs += this->chipsize >> (this->bbt_erase_shift + 2);
 		}
 	} else {
-		res = read_bbt (mtd, buf, td->pages[0], mtd->size >> this->erase_shift, bits, 0, td->reserved_block_code);
+		res = read_bbt (mtd, buf, td->pages[0], mtd->size >> this->bbt_erase_shift, bits, 0, td->reserved_block_code);
 		if (res)
 			return res;
 	}
@@ -256,7 +256,7 @@
 	printk (KERN_INFO "Scanning device for bad blocks\n");
 
 	if (bd->options & NAND_BBT_SCANALLPAGES)
-		len = 1 << (this->erase_shift - this->page_shift);
+		len = 1 << (this->bbt_erase_shift - this->page_shift);
 	else {
 		if (bd->options & NAND_BBT_SCAN2NDPAGE)
 			len = 1;
@@ -270,7 +270,7 @@
 	if (chip == -1) {
 		/* Note that numblocks is 2 * (real numblocks) here, see i+=2 below as it
 		 * makes shifting and masking less painful */
-		numblocks = mtd->size >> (this->erase_shift - 1);
+		numblocks = mtd->size >> (this->bbt_erase_shift - 1);
 		startblock = 0;
 		from = 0;
 	} else {
@@ -279,10 +279,10 @@
 				chip + 1, this->numchips);
 			return;	
 		}
-		numblocks = this->chipsize >> (this->erase_shift - 1);
+		numblocks = this->chipsize >> (this->bbt_erase_shift - 1);
 		startblock = chip * numblocks;
 		numblocks += startblock;
-		from = startblock << (this->erase_shift - 1);
+		from = startblock << (this->bbt_erase_shift - 1);
 	}
 	
 	for (i = startblock; i < numblocks;) {
@@ -296,7 +296,7 @@
 			}
 		}
 		i += 2;
-		from += (1 << this->erase_shift);
+		from += (1 << this->bbt_erase_shift);
 	}
 }
 
@@ -327,7 +327,7 @@
 
 	/* Search direction top -> down ? */
 	if (td->options & NAND_BBT_LASTBLOCK) {
-		startblock = (mtd->size >> this->erase_shift) -1;
+		startblock = (mtd->size >> this->bbt_erase_shift) -1;
 		dir = -1;
 	} else {
 		startblock = 0;	
@@ -337,11 +337,11 @@
 	/* Do we have a bbt per chip ? */
 	if (td->options & NAND_BBT_PERCHIP) {
 		chips = this->numchips;
-		bbtblocks = this->chipsize >> this->erase_shift;
+		bbtblocks = this->chipsize >> this->bbt_erase_shift;
 		startblock &= bbtblocks - 1;
 	} else {
 		chips = 1;
-		bbtblocks = mtd->size >> this->erase_shift;
+		bbtblocks = mtd->size >> this->bbt_erase_shift;
 	}
 	
 	/* Number of bits for each erase block in the bbt */
@@ -355,16 +355,16 @@
 		for (block = 0; block < td->maxblocks; block++) {
 			int actblock = startblock + dir * block;
 			/* Read first page */
-			nand_read_raw (mtd, buf, actblock << this->erase_shift, mtd->oobblock, mtd->oobsize); 
+			nand_read_raw (mtd, buf, actblock << this->bbt_erase_shift, mtd->oobblock, mtd->oobsize); 
 			if (!check_pattern(buf, scanlen, mtd->oobblock, td)) {
-				td->pages[i] = actblock << (this->erase_shift - this->page_shift);
+				td->pages[i] = actblock << (this->bbt_erase_shift - this->page_shift);
 				if (td->options & NAND_BBT_VERSION) {
 					td->version[i] = *((char *) &buf[mtd->oobblock + td->veroffs]);
 				}
 				break;
 			}
 		}
-		startblock += this->chipsize >> this->erase_shift;
+		startblock += this->chipsize >> this->bbt_erase_shift;
 	}
 	/* Check, if we found a bbt for each requested chip */
 	for (i = 0; i < chips; i++) {
@@ -427,7 +427,7 @@
 
 	/* Write bad block table per chip rather than per device ? */
 	if (td->options & NAND_BBT_PERCHIP) {
-		numblocks = (int) (this->chipsize >> this->erase_shift);
+		numblocks = (int) (this->chipsize >> this->bbt_erase_shift);
 		/* Full device write or specific chip ? */	
 		if (chipsel == -1) {
 			nrchips = this->numchips;
@@ -436,7 +436,7 @@
 			chip = chipsel;
 		}
 	} else {
-		numblocks = (int) (mtd->size >> this->erase_shift);
+		numblocks = (int) (mtd->size >> this->bbt_erase_shift);
 		nrchips = 1;
 	}	
 	
@@ -470,7 +470,7 @@
 			case 0x03:
 				continue;
 			}
-			page = block << (this->erase_shift - this->page_shift);
+			page = block << (this->bbt_erase_shift - this->page_shift);
 			/* Check, if the block is used by the mirror table */
 			if (!md || md->pages[chip] != page)
 				goto write;
@@ -499,8 +499,8 @@
 		/* Must we save the block contents ? */
 		if (td->options & NAND_BBT_SAVECONTENT) {
 			/* Make it block aligned */
-			to &= ~((loff_t) ((1 << this->erase_shift) - 1));
-			len = 1 << this->erase_shift;
+			to &= ~((loff_t) ((1 << this->bbt_erase_shift) - 1));
+			len = 1 << this->bbt_erase_shift;
 			res = mtd->read_ecc (mtd, to, len, &retlen, buf, &buf[len], &oobinfo);
 			if (res < 0) {
 				if (retlen != len) {
@@ -544,7 +544,7 @@
 		memset (&einfo, 0, sizeof (einfo));
 		einfo.mtd = mtd;
 		einfo.addr = (unsigned long) to;
-		einfo.len = 1 << this->erase_shift;
+		einfo.len = 1 << this->bbt_erase_shift;
 		res = nand_erase_nand (mtd, &einfo, 1);
 		if (res < 0) {
 			printk (KERN_WARNING "nand_bbt: Error during block erase: %d\n", res);
@@ -711,23 +711,23 @@
 	/* Do we have a bbt per chip ? */
 	if (td->options & NAND_BBT_PERCHIP) {
 		chips = this->numchips;
-		nrblocks = (int)(this->chipsize >> this->erase_shift);
+		nrblocks = (int)(this->chipsize >> this->bbt_erase_shift);
 	} else {
 		chips = 1;
-		nrblocks = (int)(mtd->size >> this->erase_shift);
+		nrblocks = (int)(mtd->size >> this->bbt_erase_shift);
 	}	
 	
 	for (i = 0; i < chips; i++) {
 		if ((td->options & NAND_BBT_ABSPAGE) ||
 		    !(td->options & NAND_BBT_WRITE)) {
 		    	if (td->pages[i] == -1) continue;
-			block = td->pages[i] >> (this->erase_shift - this->page_shift);
+			block = td->pages[i] >> (this->bbt_erase_shift - this->page_shift);
 			block <<= 1;		
 			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));
+				nand_update_bbt(mtd, block << (this->bbt_erase_shift - 1));
 			continue;
 		}
 		update = 0;
@@ -747,7 +747,7 @@
 		   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));
+			nand_update_bbt(mtd, (block - 2) << (this->bbt_erase_shift - 1));
 	}
 }
 
@@ -773,7 +773,7 @@
 	struct nand_bbt_descr *td = this->bbt_td;
 	struct nand_bbt_descr *md = this->bbt_md;
 
-	len = mtd->size >> (this->erase_shift + 2);
+	len = mtd->size >> (this->bbt_erase_shift + 2);
 	/* Allocate memory (2bit per block) */
 	this->bbt = (uint8_t *) kmalloc (len, GFP_KERNEL);
 	if (!this->bbt) {
@@ -790,7 +790,7 @@
 		return nand_memory_bbt(mtd, bd);
 
 	/* Allocate a temporary buffer for one eraseblock incl. oob */
-	len = (1 << this->erase_shift);
+	len = (1 << this->bbt_erase_shift);
 	len += (len >> this->page_shift) * mtd->oobsize;
 	buf = kmalloc (len, GFP_KERNEL);
 	if (!buf) {
@@ -840,9 +840,9 @@
 	if (!this->bbt || !td)
 		return -EINVAL;
 
-	len = mtd->size >> (this->erase_shift + 2);
+	len = mtd->size >> (this->bbt_erase_shift + 2);
 	/* Allocate a temporary buffer for one eraseblock incl. oob */
-	len = (1 << this->erase_shift);
+	len = (1 << this->bbt_erase_shift);
 	len += (len >> this->page_shift) * mtd->oobsize;
 	buf = kmalloc (len, GFP_KERNEL);
 	if (!buf) {
@@ -1014,7 +1014,7 @@
 	uint8_t	res;
 	
 	/* Get block number * 2 */
-	block = (int) (offs >> (this->erase_shift - 1));
+	block = (int) (offs >> (this->bbt_erase_shift - 1));
 	res = (this->bbt[block >> 3] >> (block & 0x06)) & 0x03;
 
 	DEBUG (MTD_DEBUG_LEVEL2, "nand_isbad_bbt(): bbt info for offs 0x%08x: (block %d) 0x%02x\n", 





More information about the linux-mtd-cvs mailing list