|
@@ -48,7 +48,7 @@
|
|
*
|
|
*
|
|
* Following assumptions are made:
|
|
* Following assumptions are made:
|
|
* - bbts start at a page boundary, if autolocated on a block boundary
|
|
* - bbts start at a page boundary, if autolocated on a block boundary
|
|
- * - the space neccecary for a bbt in FLASH does not exceed a block boundary
|
|
|
|
|
|
+ * - the space necessary for a bbt in FLASH does not exceed a block boundary
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
|
|
|
|
@@ -75,7 +75,7 @@
|
|
* pattern area contain 0xff
|
|
* pattern area contain 0xff
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
-static int check_pattern (uint8_t *buf, int len, int paglen, struct nand_bbt_descr *td)
|
|
|
|
|
|
+static int check_pattern(uint8_t *buf, int len, int paglen, struct nand_bbt_descr *td)
|
|
{
|
|
{
|
|
int i, end = 0;
|
|
int i, end = 0;
|
|
uint8_t *p = buf;
|
|
uint8_t *p = buf;
|
|
@@ -116,7 +116,7 @@ static int check_pattern (uint8_t *buf, int len, int paglen, struct nand_bbt_des
|
|
* no optional empty check
|
|
* no optional empty check
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
-static int check_short_pattern (uint8_t *buf, struct nand_bbt_descr *td)
|
|
|
|
|
|
+static int check_short_pattern(uint8_t *buf, struct nand_bbt_descr *td)
|
|
{
|
|
{
|
|
int i;
|
|
int i;
|
|
uint8_t *p = buf;
|
|
uint8_t *p = buf;
|
|
@@ -142,8 +142,8 @@ static int check_short_pattern (uint8_t *buf, struct nand_bbt_descr *td)
|
|
* Read the bad block table starting from page.
|
|
* Read the bad block table starting from page.
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
-static int read_bbt (struct mtd_info *mtd, uint8_t *buf, int page, int num,
|
|
|
|
- int bits, int offs, int reserved_block_code)
|
|
|
|
|
|
+static int read_bbt(struct mtd_info *mtd, uint8_t *buf, int page, int num,
|
|
|
|
+ int bits, int offs, int reserved_block_code)
|
|
{
|
|
{
|
|
int res, i, j, act = 0;
|
|
int res, i, j, act = 0;
|
|
struct nand_chip *this = mtd->priv;
|
|
struct nand_chip *this = mtd->priv;
|
|
@@ -152,17 +152,17 @@ static int read_bbt (struct mtd_info *mtd, uint8_t *buf, int page, int num,
|
|
uint8_t msk = (uint8_t) ((1 << bits) - 1);
|
|
uint8_t msk = (uint8_t) ((1 << bits) - 1);
|
|
|
|
|
|
totlen = (num * bits) >> 3;
|
|
totlen = (num * bits) >> 3;
|
|
- from = ((loff_t)page) << this->page_shift;
|
|
|
|
|
|
+ from = ((loff_t) page) << this->page_shift;
|
|
|
|
|
|
while (totlen) {
|
|
while (totlen) {
|
|
- len = min (totlen, (size_t) (1 << this->bbt_erase_shift));
|
|
|
|
- res = mtd->read_ecc (mtd, from, len, &retlen, buf, NULL, this->autooob);
|
|
|
|
|
|
+ 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 (res < 0) {
|
|
if (retlen != len) {
|
|
if (retlen != len) {
|
|
- printk (KERN_INFO "nand_bbt: Error reading bad block table\n");
|
|
|
|
|
|
+ printk(KERN_INFO "nand_bbt: Error reading bad block table\n");
|
|
return res;
|
|
return res;
|
|
}
|
|
}
|
|
- printk (KERN_WARNING "nand_bbt: ECC error while reading bad block table\n");
|
|
|
|
|
|
+ printk(KERN_WARNING "nand_bbt: ECC error while reading bad block table\n");
|
|
}
|
|
}
|
|
|
|
|
|
/* Analyse data */
|
|
/* Analyse data */
|
|
@@ -172,17 +172,16 @@ static int read_bbt (struct mtd_info *mtd, uint8_t *buf, int page, int num,
|
|
uint8_t tmp = (dat >> j) & msk;
|
|
uint8_t tmp = (dat >> j) & msk;
|
|
if (tmp == msk)
|
|
if (tmp == msk)
|
|
continue;
|
|
continue;
|
|
- 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->bbt_erase_shift);
|
|
|
|
|
|
+ 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->bbt_erase_shift);
|
|
this->bbt[offs + (act >> 3)] |= 0x2 << (act & 0x06);
|
|
this->bbt[offs + (act >> 3)] |= 0x2 << (act & 0x06);
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
/* Leave it for now, if its matured we can move this
|
|
/* Leave it for now, if its matured we can move this
|
|
* message to MTD_DEBUG_LEVEL0 */
|
|
* message to MTD_DEBUG_LEVEL0 */
|
|
- printk (KERN_DEBUG "nand_read_bbt: Bad block at 0x%08x\n",
|
|
|
|
- ((offs << 2) + (act >> 1)) << this->bbt_erase_shift);
|
|
|
|
|
|
+ printk(KERN_DEBUG "nand_read_bbt: Bad block at 0x%08x\n",
|
|
|
|
+ ((offs << 2) + (act >> 1)) << this->bbt_erase_shift);
|
|
/* Factory marked bad or worn out ? */
|
|
/* Factory marked bad or worn out ? */
|
|
if (tmp == 0)
|
|
if (tmp == 0)
|
|
this->bbt[offs + (act >> 3)] |= 0x3 << (act & 0x06);
|
|
this->bbt[offs + (act >> 3)] |= 0x3 << (act & 0x06);
|
|
@@ -207,7 +206,7 @@ static int read_bbt (struct mtd_info *mtd, uint8_t *buf, int page, int num,
|
|
* Read the bad block table for all chips starting at a given page
|
|
* Read the bad block table for all chips starting at a given page
|
|
* We assume that the bbt bits are in consecutive order.
|
|
* We assume that the bbt bits are in consecutive order.
|
|
*/
|
|
*/
|
|
-static int read_abs_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td, int chip)
|
|
|
|
|
|
+static int read_abs_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td, int chip)
|
|
{
|
|
{
|
|
struct nand_chip *this = mtd->priv;
|
|
struct nand_chip *this = mtd->priv;
|
|
int res = 0, i;
|
|
int res = 0, i;
|
|
@@ -242,23 +241,22 @@ static int read_abs_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_des
|
|
* We assume that the bbt bits are in consecutive order.
|
|
* We assume that the bbt bits are in consecutive order.
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
-static int read_abs_bbts (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td,
|
|
|
|
- struct nand_bbt_descr *md)
|
|
|
|
|
|
+static int read_abs_bbts(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td, struct nand_bbt_descr *md)
|
|
{
|
|
{
|
|
struct nand_chip *this = mtd->priv;
|
|
struct nand_chip *this = mtd->priv;
|
|
|
|
|
|
/* Read the primary version, if available */
|
|
/* Read the primary version, if available */
|
|
if (td->options & NAND_BBT_VERSION) {
|
|
if (td->options & NAND_BBT_VERSION) {
|
|
- nand_read_raw (mtd, buf, td->pages[0] << this->page_shift, mtd->oobblock, mtd->oobsize);
|
|
|
|
|
|
+ nand_read_raw(mtd, buf, td->pages[0] << this->page_shift, mtd->oobblock, mtd->oobsize);
|
|
td->version[0] = buf[mtd->oobblock + td->veroffs];
|
|
td->version[0] = buf[mtd->oobblock + td->veroffs];
|
|
- printk (KERN_DEBUG "Bad block table at page %d, version 0x%02X\n", td->pages[0], td->version[0]);
|
|
|
|
|
|
+ printk(KERN_DEBUG "Bad block table at page %d, version 0x%02X\n", td->pages[0], td->version[0]);
|
|
}
|
|
}
|
|
|
|
|
|
/* Read the mirror version, if available */
|
|
/* Read the mirror version, if available */
|
|
if (md && (md->options & NAND_BBT_VERSION)) {
|
|
if (md && (md->options & NAND_BBT_VERSION)) {
|
|
- nand_read_raw (mtd, buf, md->pages[0] << this->page_shift, mtd->oobblock, mtd->oobsize);
|
|
|
|
|
|
+ nand_read_raw(mtd, buf, md->pages[0] << this->page_shift, mtd->oobblock, mtd->oobsize);
|
|
md->version[0] = buf[mtd->oobblock + md->veroffs];
|
|
md->version[0] = buf[mtd->oobblock + md->veroffs];
|
|
- printk (KERN_DEBUG "Bad block table at page %d, version 0x%02X\n", md->pages[0], md->version[0]);
|
|
|
|
|
|
+ printk(KERN_DEBUG "Bad block table at page %d, version 0x%02X\n", md->pages[0], md->version[0]);
|
|
}
|
|
}
|
|
|
|
|
|
return 1;
|
|
return 1;
|
|
@@ -275,7 +273,7 @@ static int read_abs_bbts (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_de
|
|
* Create a bad block table by scanning the device
|
|
* Create a bad block table by scanning the device
|
|
* for the given good/bad block identify pattern
|
|
* for the given good/bad block identify pattern
|
|
*/
|
|
*/
|
|
-static int create_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *bd, int chip)
|
|
|
|
|
|
+static int create_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *bd, int chip)
|
|
{
|
|
{
|
|
struct nand_chip *this = mtd->priv;
|
|
struct nand_chip *this = mtd->priv;
|
|
int i, j, numblocks, len, scanlen;
|
|
int i, j, numblocks, len, scanlen;
|
|
@@ -283,7 +281,7 @@ static int create_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
|
|
loff_t from;
|
|
loff_t from;
|
|
size_t readlen, ooblen;
|
|
size_t readlen, ooblen;
|
|
|
|
|
|
- printk (KERN_INFO "Scanning device for bad blocks\n");
|
|
|
|
|
|
+ printk(KERN_INFO "Scanning device for bad blocks\n");
|
|
|
|
|
|
if (bd->options & NAND_BBT_SCANALLPAGES)
|
|
if (bd->options & NAND_BBT_SCANALLPAGES)
|
|
len = 1 << (this->bbt_erase_shift - this->page_shift);
|
|
len = 1 << (this->bbt_erase_shift - this->page_shift);
|
|
@@ -300,7 +298,7 @@ static int create_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
|
|
readlen = bd->len;
|
|
readlen = bd->len;
|
|
} else {
|
|
} else {
|
|
/* Full page content should be read */
|
|
/* Full page content should be read */
|
|
- scanlen = mtd->oobblock + mtd->oobsize;
|
|
|
|
|
|
+ scanlen = mtd->oobblock + mtd->oobsize;
|
|
readlen = len * mtd->oobblock;
|
|
readlen = len * mtd->oobblock;
|
|
ooblen = len * mtd->oobsize;
|
|
ooblen = len * mtd->oobsize;
|
|
}
|
|
}
|
|
@@ -313,8 +311,8 @@ static int create_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
|
|
from = 0;
|
|
from = 0;
|
|
} else {
|
|
} else {
|
|
if (chip >= this->numchips) {
|
|
if (chip >= this->numchips) {
|
|
- printk (KERN_WARNING "create_bbt(): chipnr (%d) > available chips (%d)\n",
|
|
|
|
- chip + 1, this->numchips);
|
|
|
|
|
|
+ printk(KERN_WARNING "create_bbt(): chipnr (%d) > available chips (%d)\n",
|
|
|
|
+ chip + 1, this->numchips);
|
|
return -EINVAL;
|
|
return -EINVAL;
|
|
}
|
|
}
|
|
numblocks = this->chipsize >> (this->bbt_erase_shift - 1);
|
|
numblocks = this->chipsize >> (this->bbt_erase_shift - 1);
|
|
@@ -327,7 +325,7 @@ static int create_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
|
|
int ret;
|
|
int ret;
|
|
|
|
|
|
if (bd->options & NAND_BBT_SCANEMPTY)
|
|
if (bd->options & NAND_BBT_SCANEMPTY)
|
|
- if ((ret = nand_read_raw (mtd, buf, from, readlen, ooblen)))
|
|
|
|
|
|
+ if ((ret = nand_read_raw(mtd, buf, from, readlen, ooblen)))
|
|
return ret;
|
|
return ret;
|
|
|
|
|
|
for (j = 0; j < len; j++) {
|
|
for (j = 0; j < len; j++) {
|
|
@@ -336,22 +334,21 @@ static int create_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
|
|
|
|
|
|
/* Read the full oob until read_oob is fixed to
|
|
/* Read the full oob until read_oob is fixed to
|
|
* handle single byte reads for 16 bit buswidth */
|
|
* handle single byte reads for 16 bit buswidth */
|
|
- ret = mtd->read_oob(mtd, from + j * mtd->oobblock,
|
|
|
|
- mtd->oobsize, &retlen, buf);
|
|
|
|
|
|
+ ret = mtd->read_oob(mtd, from + j * mtd->oobblock, mtd->oobsize, &retlen, buf);
|
|
if (ret)
|
|
if (ret)
|
|
return ret;
|
|
return ret;
|
|
|
|
|
|
- if (check_short_pattern (buf, bd)) {
|
|
|
|
|
|
+ if (check_short_pattern(buf, bd)) {
|
|
this->bbt[i >> 3] |= 0x03 << (i & 0x6);
|
|
this->bbt[i >> 3] |= 0x03 << (i & 0x6);
|
|
- printk (KERN_WARNING "Bad eraseblock %d at 0x%08x\n",
|
|
|
|
- i >> 1, (unsigned int) from);
|
|
|
|
|
|
+ printk(KERN_WARNING "Bad eraseblock %d at 0x%08x\n",
|
|
|
|
+ i >> 1, (unsigned int)from);
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- if (check_pattern (&buf[j * scanlen], scanlen, mtd->oobblock, bd)) {
|
|
|
|
|
|
+ if (check_pattern(&buf[j * scanlen], scanlen, mtd->oobblock, bd)) {
|
|
this->bbt[i >> 3] |= 0x03 << (i & 0x6);
|
|
this->bbt[i >> 3] |= 0x03 << (i & 0x6);
|
|
- printk (KERN_WARNING "Bad eraseblock %d at 0x%08x\n",
|
|
|
|
- i >> 1, (unsigned int) from);
|
|
|
|
|
|
+ printk(KERN_WARNING "Bad eraseblock %d at 0x%08x\n",
|
|
|
|
+ i >> 1, (unsigned int)from);
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -374,12 +371,12 @@ static int create_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
|
|
* block.
|
|
* block.
|
|
* If the option NAND_BBT_PERCHIP is given, each chip is searched
|
|
* If the option NAND_BBT_PERCHIP is given, each chip is searched
|
|
* for a bbt, which contains the bad block information of this chip.
|
|
* for a bbt, which contains the bad block information of this chip.
|
|
- * This is neccecary to provide support for certain DOC devices.
|
|
|
|
|
|
+ * This is necessary to provide support for certain DOC devices.
|
|
*
|
|
*
|
|
* The bbt ident pattern resides in the oob area of the first page
|
|
* The bbt ident pattern resides in the oob area of the first page
|
|
* in a block.
|
|
* in a block.
|
|
*/
|
|
*/
|
|
-static int search_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td)
|
|
|
|
|
|
+static int search_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td)
|
|
{
|
|
{
|
|
struct nand_chip *this = mtd->priv;
|
|
struct nand_chip *this = mtd->priv;
|
|
int i, chips;
|
|
int i, chips;
|
|
@@ -389,7 +386,7 @@ static int search_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
|
|
|
|
|
|
/* Search direction top -> down ? */
|
|
/* Search direction top -> down ? */
|
|
if (td->options & NAND_BBT_LASTBLOCK) {
|
|
if (td->options & NAND_BBT_LASTBLOCK) {
|
|
- startblock = (mtd->size >> this->bbt_erase_shift) -1;
|
|
|
|
|
|
+ startblock = (mtd->size >> this->bbt_erase_shift) - 1;
|
|
dir = -1;
|
|
dir = -1;
|
|
} else {
|
|
} else {
|
|
startblock = 0;
|
|
startblock = 0;
|
|
@@ -417,7 +414,7 @@ static int search_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
|
|
for (block = 0; block < td->maxblocks; block++) {
|
|
for (block = 0; block < td->maxblocks; block++) {
|
|
int actblock = startblock + dir * block;
|
|
int actblock = startblock + dir * block;
|
|
/* Read first page */
|
|
/* Read first page */
|
|
- nand_read_raw (mtd, buf, actblock << this->bbt_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)) {
|
|
if (!check_pattern(buf, scanlen, mtd->oobblock, td)) {
|
|
td->pages[i] = actblock << (this->bbt_erase_shift - this->page_shift);
|
|
td->pages[i] = actblock << (this->bbt_erase_shift - this->page_shift);
|
|
if (td->options & NAND_BBT_VERSION) {
|
|
if (td->options & NAND_BBT_VERSION) {
|
|
@@ -431,9 +428,10 @@ static int search_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
|
|
/* Check, if we found a bbt for each requested chip */
|
|
/* Check, if we found a bbt for each requested chip */
|
|
for (i = 0; i < chips; i++) {
|
|
for (i = 0; i < chips; i++) {
|
|
if (td->pages[i] == -1)
|
|
if (td->pages[i] == -1)
|
|
- printk (KERN_WARNING "Bad block table not found for chip %d\n", i);
|
|
|
|
|
|
+ printk(KERN_WARNING "Bad block table not found for chip %d\n", i);
|
|
else
|
|
else
|
|
- printk (KERN_DEBUG "Bad block table found at page %d, version 0x%02X\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;
|
|
return 0;
|
|
}
|
|
}
|
|
@@ -447,21 +445,19 @@ static int search_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
|
|
*
|
|
*
|
|
* Search and read the bad block table(s)
|
|
* Search and read the bad block table(s)
|
|
*/
|
|
*/
|
|
-static int search_read_bbts (struct mtd_info *mtd, uint8_t *buf,
|
|
|
|
- struct nand_bbt_descr *td, struct nand_bbt_descr *md)
|
|
|
|
|
|
+static int search_read_bbts(struct mtd_info *mtd, uint8_t * buf, struct nand_bbt_descr *td, struct nand_bbt_descr *md)
|
|
{
|
|
{
|
|
/* Search the primary table */
|
|
/* Search the primary table */
|
|
- search_bbt (mtd, buf, td);
|
|
|
|
|
|
+ search_bbt(mtd, buf, td);
|
|
|
|
|
|
/* Search the mirror table */
|
|
/* Search the mirror table */
|
|
if (md)
|
|
if (md)
|
|
- search_bbt (mtd, buf, md);
|
|
|
|
|
|
+ search_bbt(mtd, buf, md);
|
|
|
|
|
|
/* Force result check */
|
|
/* Force result check */
|
|
return 1;
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* write_bbt - [GENERIC] (Re)write the bad block table
|
|
* write_bbt - [GENERIC] (Re)write the bad block table
|
|
*
|
|
*
|
|
@@ -474,8 +470,8 @@ static int search_read_bbts (struct mtd_info *mtd, uint8_t *buf,
|
|
* (Re)write the bad block table
|
|
* (Re)write the bad block table
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
-static int write_bbt (struct mtd_info *mtd, uint8_t *buf,
|
|
|
|
- struct nand_bbt_descr *td, struct nand_bbt_descr *md, int chipsel)
|
|
|
|
|
|
+static int write_bbt(struct mtd_info *mtd, uint8_t *buf,
|
|
|
|
+ struct nand_bbt_descr *td, struct nand_bbt_descr *md, int chipsel)
|
|
{
|
|
{
|
|
struct nand_chip *this = mtd->priv;
|
|
struct nand_chip *this = mtd->priv;
|
|
struct nand_oobinfo oobinfo;
|
|
struct nand_oobinfo oobinfo;
|
|
@@ -492,7 +488,7 @@ static int write_bbt (struct mtd_info *mtd, uint8_t *buf,
|
|
rcode = 0xff;
|
|
rcode = 0xff;
|
|
/* Write bad block table per chip rather than per device ? */
|
|
/* Write bad block table per chip rather than per device ? */
|
|
if (td->options & NAND_BBT_PERCHIP) {
|
|
if (td->options & NAND_BBT_PERCHIP) {
|
|
- numblocks = (int) (this->chipsize >> this->bbt_erase_shift);
|
|
|
|
|
|
+ numblocks = (int)(this->chipsize >> this->bbt_erase_shift);
|
|
/* Full device write or specific chip ? */
|
|
/* Full device write or specific chip ? */
|
|
if (chipsel == -1) {
|
|
if (chipsel == -1) {
|
|
nrchips = this->numchips;
|
|
nrchips = this->numchips;
|
|
@@ -501,7 +497,7 @@ static int write_bbt (struct mtd_info *mtd, uint8_t *buf,
|
|
chip = chipsel;
|
|
chip = chipsel;
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- numblocks = (int) (mtd->size >> this->bbt_erase_shift);
|
|
|
|
|
|
+ numblocks = (int)(mtd->size >> this->bbt_erase_shift);
|
|
nrchips = 1;
|
|
nrchips = 1;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -540,9 +536,9 @@ static int write_bbt (struct mtd_info *mtd, uint8_t *buf,
|
|
if (!md || md->pages[chip] != page)
|
|
if (!md || md->pages[chip] != page)
|
|
goto write;
|
|
goto write;
|
|
}
|
|
}
|
|
- printk (KERN_ERR "No space left to write bad block table\n");
|
|
|
|
|
|
+ printk(KERN_ERR "No space left to write bad block table\n");
|
|
return -ENOSPC;
|
|
return -ENOSPC;
|
|
-write:
|
|
|
|
|
|
+ write:
|
|
|
|
|
|
/* Set up shift count and masks for the flash table */
|
|
/* Set up shift count and masks for the flash table */
|
|
bits = td->options & NAND_BBT_NRBITS_MSK;
|
|
bits = td->options & NAND_BBT_NRBITS_MSK;
|
|
@@ -558,7 +554,7 @@ write:
|
|
|
|
|
|
to = ((loff_t) page) << this->page_shift;
|
|
to = ((loff_t) page) << this->page_shift;
|
|
|
|
|
|
- memcpy (&oobinfo, this->autooob, sizeof(oobinfo));
|
|
|
|
|
|
+ memcpy(&oobinfo, this->autooob, sizeof(oobinfo));
|
|
oobinfo.useecc = MTD_NANDECC_PLACEONLY;
|
|
oobinfo.useecc = MTD_NANDECC_PLACEONLY;
|
|
|
|
|
|
/* Must we save the block contents ? */
|
|
/* Must we save the block contents ? */
|
|
@@ -566,22 +562,23 @@ write:
|
|
/* Make it block aligned */
|
|
/* Make it block aligned */
|
|
to &= ~((loff_t) ((1 << this->bbt_erase_shift) - 1));
|
|
to &= ~((loff_t) ((1 << this->bbt_erase_shift) - 1));
|
|
len = 1 << this->bbt_erase_shift;
|
|
len = 1 << this->bbt_erase_shift;
|
|
- res = mtd->read_ecc (mtd, to, len, &retlen, buf, &buf[len], &oobinfo);
|
|
|
|
|
|
+ res = mtd->read_ecc(mtd, to, len, &retlen, buf, &buf[len], &oobinfo);
|
|
if (res < 0) {
|
|
if (res < 0) {
|
|
if (retlen != len) {
|
|
if (retlen != len) {
|
|
- printk (KERN_INFO "nand_bbt: Error reading block for writing the bad block table\n");
|
|
|
|
|
|
+ printk(KERN_INFO
|
|
|
|
+ "nand_bbt: Error reading block for writing the bad block table\n");
|
|
return res;
|
|
return res;
|
|
}
|
|
}
|
|
- printk (KERN_WARNING "nand_bbt: ECC error while reading block for writing bad block table\n");
|
|
|
|
|
|
+ printk(KERN_WARNING "nand_bbt: ECC error while reading block for writing bad block table\n");
|
|
}
|
|
}
|
|
/* Calc the byte offset in the buffer */
|
|
/* Calc the byte offset in the buffer */
|
|
pageoffs = page - (int)(to >> this->page_shift);
|
|
pageoffs = page - (int)(to >> this->page_shift);
|
|
offs = pageoffs << this->page_shift;
|
|
offs = pageoffs << this->page_shift;
|
|
/* Preset the bbt area with 0xff */
|
|
/* Preset the bbt area with 0xff */
|
|
- memset (&buf[offs], 0xff, (size_t)(numblocks >> sft));
|
|
|
|
|
|
+ memset(&buf[offs], 0xff, (size_t) (numblocks >> sft));
|
|
/* Preset the bbt's oob area with 0xff */
|
|
/* Preset the bbt's oob area with 0xff */
|
|
- memset (&buf[len + pageoffs * mtd->oobsize], 0xff,
|
|
|
|
- ((len >> this->page_shift) - pageoffs) * mtd->oobsize);
|
|
|
|
|
|
+ memset(&buf[len + pageoffs * mtd->oobsize], 0xff,
|
|
|
|
+ ((len >> this->page_shift) - pageoffs) * mtd->oobsize);
|
|
if (td->options & NAND_BBT_VERSION) {
|
|
if (td->options & NAND_BBT_VERSION) {
|
|
buf[len + (pageoffs * mtd->oobsize) + td->veroffs] = td->version[chip];
|
|
buf[len + (pageoffs * mtd->oobsize) + td->veroffs] = td->version[chip];
|
|
}
|
|
}
|
|
@@ -589,22 +586,22 @@ write:
|
|
/* Calc length */
|
|
/* Calc length */
|
|
len = (size_t) (numblocks >> sft);
|
|
len = (size_t) (numblocks >> sft);
|
|
/* Make it page aligned ! */
|
|
/* Make it page aligned ! */
|
|
- len = (len + (mtd->oobblock-1)) & ~(mtd->oobblock-1);
|
|
|
|
|
|
+ len = (len + (mtd->oobblock - 1)) & ~(mtd->oobblock - 1);
|
|
/* Preset the buffer with 0xff */
|
|
/* Preset the buffer with 0xff */
|
|
- memset (buf, 0xff, len + (len >> this->page_shift) * mtd->oobsize);
|
|
|
|
|
|
+ memset(buf, 0xff, len + (len >> this->page_shift) * mtd->oobsize);
|
|
offs = 0;
|
|
offs = 0;
|
|
/* Pattern is located in oob area of first page */
|
|
/* Pattern is located in oob area of first page */
|
|
- memcpy (&buf[len + td->offs], td->pattern, td->len);
|
|
|
|
|
|
+ memcpy(&buf[len + td->offs], td->pattern, td->len);
|
|
if (td->options & NAND_BBT_VERSION) {
|
|
if (td->options & NAND_BBT_VERSION) {
|
|
buf[len + td->veroffs] = td->version[chip];
|
|
buf[len + td->veroffs] = td->version[chip];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/* walk through the memory table */
|
|
/* walk through the memory table */
|
|
- for (i = 0; i < numblocks; ) {
|
|
|
|
|
|
+ for (i = 0; i < numblocks;) {
|
|
uint8_t dat;
|
|
uint8_t dat;
|
|
dat = this->bbt[bbtoffs + (i >> 2)];
|
|
dat = this->bbt[bbtoffs + (i >> 2)];
|
|
- for (j = 0; j < 4; j++ , i++) {
|
|
|
|
|
|
+ for (j = 0; j < 4; j++, i++) {
|
|
int sftcnt = (i << (3 - sft)) & sftmsk;
|
|
int sftcnt = (i << (3 - sft)) & sftmsk;
|
|
/* Do not store the reserved bbt blocks ! */
|
|
/* Do not store the reserved bbt blocks ! */
|
|
buf[offs + (i >> sft)] &= ~(msk[dat & 0x03] << sftcnt);
|
|
buf[offs + (i >> sft)] &= ~(msk[dat & 0x03] << sftcnt);
|
|
@@ -612,23 +609,23 @@ write:
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- memset (&einfo, 0, sizeof (einfo));
|
|
|
|
|
|
+ memset(&einfo, 0, sizeof(einfo));
|
|
einfo.mtd = mtd;
|
|
einfo.mtd = mtd;
|
|
- einfo.addr = (unsigned long) to;
|
|
|
|
|
|
+ einfo.addr = (unsigned long)to;
|
|
einfo.len = 1 << this->bbt_erase_shift;
|
|
einfo.len = 1 << this->bbt_erase_shift;
|
|
- res = nand_erase_nand (mtd, &einfo, 1);
|
|
|
|
|
|
+ res = nand_erase_nand(mtd, &einfo, 1);
|
|
if (res < 0) {
|
|
if (res < 0) {
|
|
- printk (KERN_WARNING "nand_bbt: Error during block erase: %d\n", res);
|
|
|
|
|
|
+ printk(KERN_WARNING "nand_bbt: Error during block erase: %d\n", res);
|
|
return res;
|
|
return res;
|
|
}
|
|
}
|
|
|
|
|
|
- res = mtd->write_ecc (mtd, to, len, &retlen, buf, &buf[len], &oobinfo);
|
|
|
|
|
|
+ res = mtd->write_ecc(mtd, to, len, &retlen, buf, &buf[len], &oobinfo);
|
|
if (res < 0) {
|
|
if (res < 0) {
|
|
- printk (KERN_WARNING "nand_bbt: Error while writing bad block table %d\n", res);
|
|
|
|
|
|
+ printk(KERN_WARNING "nand_bbt: Error while writing bad block table %d\n", res);
|
|
return res;
|
|
return res;
|
|
}
|
|
}
|
|
- printk (KERN_DEBUG "Bad block table written to 0x%08x, version 0x%02X\n",
|
|
|
|
- (unsigned int) to, td->version[chip]);
|
|
|
|
|
|
+ printk(KERN_DEBUG "Bad block table written to 0x%08x, version 0x%02X\n",
|
|
|
|
+ (unsigned int)to, td->version[chip]);
|
|
|
|
|
|
/* Mark it as used */
|
|
/* Mark it as used */
|
|
td->pages[chip] = page;
|
|
td->pages[chip] = page;
|
|
@@ -644,27 +641,27 @@ write:
|
|
* The function creates a memory based bbt by scanning the device
|
|
* The function creates a memory based bbt by scanning the device
|
|
* for manufacturer / software marked good / bad blocks
|
|
* for manufacturer / software marked good / bad blocks
|
|
*/
|
|
*/
|
|
-static inline int nand_memory_bbt (struct mtd_info *mtd, struct nand_bbt_descr *bd)
|
|
|
|
|
|
+static inline int nand_memory_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd)
|
|
{
|
|
{
|
|
struct nand_chip *this = mtd->priv;
|
|
struct nand_chip *this = mtd->priv;
|
|
|
|
|
|
bd->options &= ~NAND_BBT_SCANEMPTY;
|
|
bd->options &= ~NAND_BBT_SCANEMPTY;
|
|
- return create_bbt (mtd, this->data_buf, bd, -1);
|
|
|
|
|
|
+ return create_bbt(mtd, this->data_buf, bd, -1);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * check_create - [GENERIC] create and write bbt(s) if neccecary
|
|
|
|
|
|
+ * check_create - [GENERIC] create and write bbt(s) if necessary
|
|
* @mtd: MTD device structure
|
|
* @mtd: MTD device structure
|
|
* @buf: temporary buffer
|
|
* @buf: temporary buffer
|
|
* @bd: descriptor for the good/bad block search pattern
|
|
* @bd: descriptor for the good/bad block search pattern
|
|
*
|
|
*
|
|
* The function checks the results of the previous call to read_bbt
|
|
* The function checks the results of the previous call to read_bbt
|
|
- * and creates / updates the bbt(s) if neccecary
|
|
|
|
- * Creation is neccecary if no bbt was found for the chip/device
|
|
|
|
- * Update is neccecary if one of the tables is missing or the
|
|
|
|
|
|
+ * and creates / updates the bbt(s) if necessary
|
|
|
|
+ * Creation is necessary if no bbt was found for the chip/device
|
|
|
|
+ * Update is necessary if one of the tables is missing or the
|
|
* version nr. of one table is less than the other
|
|
* version nr. of one table is less than the other
|
|
*/
|
|
*/
|
|
-static int check_create (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *bd)
|
|
|
|
|
|
+static int check_create(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *bd)
|
|
{
|
|
{
|
|
int i, chips, writeops, chipsel, res;
|
|
int i, chips, writeops, chipsel, res;
|
|
struct nand_chip *this = mtd->priv;
|
|
struct nand_chip *this = mtd->priv;
|
|
@@ -732,35 +729,35 @@ static int check_create (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_des
|
|
rd = td;
|
|
rd = td;
|
|
goto writecheck;
|
|
goto writecheck;
|
|
}
|
|
}
|
|
-create:
|
|
|
|
|
|
+ create:
|
|
/* Create the bad block table by scanning the device ? */
|
|
/* Create the bad block table by scanning the device ? */
|
|
if (!(td->options & NAND_BBT_CREATE))
|
|
if (!(td->options & NAND_BBT_CREATE))
|
|
continue;
|
|
continue;
|
|
|
|
|
|
/* Create the table in memory by scanning the chip(s) */
|
|
/* Create the table in memory by scanning the chip(s) */
|
|
- create_bbt (mtd, buf, bd, chipsel);
|
|
|
|
|
|
+ create_bbt(mtd, buf, bd, chipsel);
|
|
|
|
|
|
td->version[i] = 1;
|
|
td->version[i] = 1;
|
|
if (md)
|
|
if (md)
|
|
md->version[i] = 1;
|
|
md->version[i] = 1;
|
|
-writecheck:
|
|
|
|
|
|
+ writecheck:
|
|
/* read back first ? */
|
|
/* read back first ? */
|
|
if (rd)
|
|
if (rd)
|
|
- read_abs_bbt (mtd, buf, rd, chipsel);
|
|
|
|
|
|
+ read_abs_bbt(mtd, buf, rd, chipsel);
|
|
/* If they weren't versioned, read both. */
|
|
/* If they weren't versioned, read both. */
|
|
if (rd2)
|
|
if (rd2)
|
|
- read_abs_bbt (mtd, buf, rd2, chipsel);
|
|
|
|
|
|
+ read_abs_bbt(mtd, buf, rd2, chipsel);
|
|
|
|
|
|
/* Write the bad block table to the device ? */
|
|
/* Write the bad block table to the device ? */
|
|
if ((writeops & 0x01) && (td->options & NAND_BBT_WRITE)) {
|
|
if ((writeops & 0x01) && (td->options & NAND_BBT_WRITE)) {
|
|
- res = write_bbt (mtd, buf, td, md, chipsel);
|
|
|
|
|
|
+ res = write_bbt(mtd, buf, td, md, chipsel);
|
|
if (res < 0)
|
|
if (res < 0)
|
|
return res;
|
|
return res;
|
|
}
|
|
}
|
|
|
|
|
|
/* Write the mirror bad block table to the device ? */
|
|
/* Write the mirror bad block table to the device ? */
|
|
if ((writeops & 0x02) && md && (md->options & NAND_BBT_WRITE)) {
|
|
if ((writeops & 0x02) && md && (md->options & NAND_BBT_WRITE)) {
|
|
- res = write_bbt (mtd, buf, md, td, chipsel);
|
|
|
|
|
|
+ res = write_bbt(mtd, buf, md, td, chipsel);
|
|
if (res < 0)
|
|
if (res < 0)
|
|
return res;
|
|
return res;
|
|
}
|
|
}
|
|
@@ -777,7 +774,7 @@ writecheck:
|
|
* accidental erasures / writes. The regions are identified by
|
|
* accidental erasures / writes. The regions are identified by
|
|
* the mark 0x02.
|
|
* the mark 0x02.
|
|
*/
|
|
*/
|
|
-static void mark_bbt_region (struct mtd_info *mtd, struct nand_bbt_descr *td)
|
|
|
|
|
|
+static void mark_bbt_region(struct mtd_info *mtd, struct nand_bbt_descr *td)
|
|
{
|
|
{
|
|
struct nand_chip *this = mtd->priv;
|
|
struct nand_chip *this = mtd->priv;
|
|
int i, j, chips, block, nrblocks, update;
|
|
int i, j, chips, block, nrblocks, update;
|
|
@@ -795,7 +792,8 @@ static void mark_bbt_region (struct mtd_info *mtd, struct nand_bbt_descr *td)
|
|
for (i = 0; i < chips; i++) {
|
|
for (i = 0; i < chips; i++) {
|
|
if ((td->options & NAND_BBT_ABSPAGE) ||
|
|
if ((td->options & NAND_BBT_ABSPAGE) ||
|
|
!(td->options & NAND_BBT_WRITE)) {
|
|
!(td->options & NAND_BBT_WRITE)) {
|
|
- if (td->pages[i] == -1) continue;
|
|
|
|
|
|
+ if (td->pages[i] == -1)
|
|
|
|
+ continue;
|
|
block = td->pages[i] >> (this->bbt_erase_shift - this->page_shift);
|
|
block = td->pages[i] >> (this->bbt_erase_shift - this->page_shift);
|
|
block <<= 1;
|
|
block <<= 1;
|
|
oldval = this->bbt[(block >> 3)];
|
|
oldval = this->bbt[(block >> 3)];
|
|
@@ -815,7 +813,8 @@ static void mark_bbt_region (struct mtd_info *mtd, struct nand_bbt_descr *td)
|
|
oldval = this->bbt[(block >> 3)];
|
|
oldval = this->bbt[(block >> 3)];
|
|
newval = oldval | (0x2 << (block & 0x06));
|
|
newval = oldval | (0x2 << (block & 0x06));
|
|
this->bbt[(block >> 3)] = newval;
|
|
this->bbt[(block >> 3)] = newval;
|
|
- if (oldval != newval) update = 1;
|
|
|
|
|
|
+ if (oldval != newval)
|
|
|
|
+ update = 1;
|
|
block += 2;
|
|
block += 2;
|
|
}
|
|
}
|
|
/* If we want reserved blocks to be recorded to flash, and some
|
|
/* If we want reserved blocks to be recorded to flash, and some
|
|
@@ -840,7 +839,7 @@ static void mark_bbt_region (struct mtd_info *mtd, struct nand_bbt_descr *td)
|
|
* by calling the nand_free_bbt function.
|
|
* by calling the nand_free_bbt function.
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
-int nand_scan_bbt (struct mtd_info *mtd, struct nand_bbt_descr *bd)
|
|
|
|
|
|
+int nand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd)
|
|
{
|
|
{
|
|
struct nand_chip *this = mtd->priv;
|
|
struct nand_chip *this = mtd->priv;
|
|
int len, res = 0;
|
|
int len, res = 0;
|
|
@@ -850,21 +849,21 @@ int nand_scan_bbt (struct mtd_info *mtd, struct nand_bbt_descr *bd)
|
|
|
|
|
|
len = mtd->size >> (this->bbt_erase_shift + 2);
|
|
len = mtd->size >> (this->bbt_erase_shift + 2);
|
|
/* Allocate memory (2bit per block) */
|
|
/* Allocate memory (2bit per block) */
|
|
- this->bbt = kmalloc (len, GFP_KERNEL);
|
|
|
|
|
|
+ this->bbt = kmalloc(len, GFP_KERNEL);
|
|
if (!this->bbt) {
|
|
if (!this->bbt) {
|
|
- printk (KERN_ERR "nand_scan_bbt: Out of memory\n");
|
|
|
|
|
|
+ printk(KERN_ERR "nand_scan_bbt: Out of memory\n");
|
|
return -ENOMEM;
|
|
return -ENOMEM;
|
|
}
|
|
}
|
|
/* Clear the memory bad block table */
|
|
/* Clear the memory bad block table */
|
|
- memset (this->bbt, 0x00, len);
|
|
|
|
|
|
+ memset(this->bbt, 0x00, len);
|
|
|
|
|
|
/* If no primary table decriptor is given, scan the device
|
|
/* If no primary table decriptor is given, scan the device
|
|
* to build a memory based bad block table
|
|
* to build a memory based bad block table
|
|
*/
|
|
*/
|
|
if (!td) {
|
|
if (!td) {
|
|
if ((res = nand_memory_bbt(mtd, bd))) {
|
|
if ((res = nand_memory_bbt(mtd, bd))) {
|
|
- printk (KERN_ERR "nand_bbt: Can't scan flash and build the RAM-based BBT\n");
|
|
|
|
- kfree (this->bbt);
|
|
|
|
|
|
+ printk(KERN_ERR "nand_bbt: Can't scan flash and build the RAM-based BBT\n");
|
|
|
|
+ kfree(this->bbt);
|
|
this->bbt = NULL;
|
|
this->bbt = NULL;
|
|
}
|
|
}
|
|
return res;
|
|
return res;
|
|
@@ -875,33 +874,32 @@ int nand_scan_bbt (struct mtd_info *mtd, struct nand_bbt_descr *bd)
|
|
len += (len >> this->page_shift) * mtd->oobsize;
|
|
len += (len >> this->page_shift) * mtd->oobsize;
|
|
buf = vmalloc(len);
|
|
buf = vmalloc(len);
|
|
if (!buf) {
|
|
if (!buf) {
|
|
- printk (KERN_ERR "nand_bbt: Out of memory\n");
|
|
|
|
- kfree (this->bbt);
|
|
|
|
|
|
+ printk(KERN_ERR "nand_bbt: Out of memory\n");
|
|
|
|
+ kfree(this->bbt);
|
|
this->bbt = NULL;
|
|
this->bbt = NULL;
|
|
return -ENOMEM;
|
|
return -ENOMEM;
|
|
}
|
|
}
|
|
|
|
|
|
/* Is the bbt at a given page ? */
|
|
/* Is the bbt at a given page ? */
|
|
if (td->options & NAND_BBT_ABSPAGE) {
|
|
if (td->options & NAND_BBT_ABSPAGE) {
|
|
- res = read_abs_bbts (mtd, buf, td, md);
|
|
|
|
|
|
+ res = read_abs_bbts(mtd, buf, td, md);
|
|
} else {
|
|
} else {
|
|
/* Search the bad block table using a pattern in oob */
|
|
/* Search the bad block table using a pattern in oob */
|
|
- res = search_read_bbts (mtd, buf, td, md);
|
|
|
|
|
|
+ res = search_read_bbts(mtd, buf, td, md);
|
|
}
|
|
}
|
|
|
|
|
|
if (res)
|
|
if (res)
|
|
- res = check_create (mtd, buf, bd);
|
|
|
|
|
|
+ res = check_create(mtd, buf, bd);
|
|
|
|
|
|
/* Prevent the bbt regions from erasing / writing */
|
|
/* Prevent the bbt regions from erasing / writing */
|
|
- mark_bbt_region (mtd, td);
|
|
|
|
|
|
+ mark_bbt_region(mtd, td);
|
|
if (md)
|
|
if (md)
|
|
- mark_bbt_region (mtd, md);
|
|
|
|
|
|
+ mark_bbt_region(mtd, md);
|
|
|
|
|
|
- vfree (buf);
|
|
|
|
|
|
+ vfree(buf);
|
|
return res;
|
|
return res;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* nand_update_bbt - [NAND Interface] update bad block table(s)
|
|
* nand_update_bbt - [NAND Interface] update bad block table(s)
|
|
* @mtd: MTD device structure
|
|
* @mtd: MTD device structure
|
|
@@ -909,7 +907,7 @@ int nand_scan_bbt (struct mtd_info *mtd, struct nand_bbt_descr *bd)
|
|
*
|
|
*
|
|
* The function updates the bad block table(s)
|
|
* The function updates the bad block table(s)
|
|
*/
|
|
*/
|
|
-int nand_update_bbt (struct mtd_info *mtd, loff_t offs)
|
|
|
|
|
|
+int nand_update_bbt(struct mtd_info *mtd, loff_t offs)
|
|
{
|
|
{
|
|
struct nand_chip *this = mtd->priv;
|
|
struct nand_chip *this = mtd->priv;
|
|
int len, res = 0, writeops = 0;
|
|
int len, res = 0, writeops = 0;
|
|
@@ -925,9 +923,9 @@ int nand_update_bbt (struct mtd_info *mtd, loff_t offs)
|
|
/* Allocate a temporary buffer for one eraseblock incl. oob */
|
|
/* Allocate a temporary buffer for one eraseblock incl. oob */
|
|
len = (1 << this->bbt_erase_shift);
|
|
len = (1 << this->bbt_erase_shift);
|
|
len += (len >> this->page_shift) * mtd->oobsize;
|
|
len += (len >> this->page_shift) * mtd->oobsize;
|
|
- buf = kmalloc (len, GFP_KERNEL);
|
|
|
|
|
|
+ buf = kmalloc(len, GFP_KERNEL);
|
|
if (!buf) {
|
|
if (!buf) {
|
|
- printk (KERN_ERR "nand_update_bbt: Out of memory\n");
|
|
|
|
|
|
+ printk(KERN_ERR "nand_update_bbt: Out of memory\n");
|
|
return -ENOMEM;
|
|
return -ENOMEM;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -935,7 +933,7 @@ int nand_update_bbt (struct mtd_info *mtd, loff_t offs)
|
|
|
|
|
|
/* Do we have a bbt per chip ? */
|
|
/* Do we have a bbt per chip ? */
|
|
if (td->options & NAND_BBT_PERCHIP) {
|
|
if (td->options & NAND_BBT_PERCHIP) {
|
|
- chip = (int) (offs >> this->chip_shift);
|
|
|
|
|
|
+ chip = (int)(offs >> this->chip_shift);
|
|
chipsel = chip;
|
|
chipsel = chip;
|
|
} else {
|
|
} else {
|
|
chip = 0;
|
|
chip = 0;
|
|
@@ -948,17 +946,17 @@ int nand_update_bbt (struct mtd_info *mtd, loff_t offs)
|
|
|
|
|
|
/* Write the bad block table to the device ? */
|
|
/* Write the bad block table to the device ? */
|
|
if ((writeops & 0x01) && (td->options & NAND_BBT_WRITE)) {
|
|
if ((writeops & 0x01) && (td->options & NAND_BBT_WRITE)) {
|
|
- res = write_bbt (mtd, buf, td, md, chipsel);
|
|
|
|
|
|
+ res = write_bbt(mtd, buf, td, md, chipsel);
|
|
if (res < 0)
|
|
if (res < 0)
|
|
goto out;
|
|
goto out;
|
|
}
|
|
}
|
|
/* Write the mirror bad block table to the device ? */
|
|
/* Write the mirror bad block table to the device ? */
|
|
if ((writeops & 0x02) && md && (md->options & NAND_BBT_WRITE)) {
|
|
if ((writeops & 0x02) && md && (md->options & NAND_BBT_WRITE)) {
|
|
- res = write_bbt (mtd, buf, md, td, chipsel);
|
|
|
|
|
|
+ res = write_bbt(mtd, buf, md, td, chipsel);
|
|
}
|
|
}
|
|
|
|
|
|
-out:
|
|
|
|
- kfree (buf);
|
|
|
|
|
|
+ out:
|
|
|
|
+ kfree(buf);
|
|
return res;
|
|
return res;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1036,7 +1034,7 @@ static struct nand_bbt_descr bbt_mirror_descr = {
|
|
* support for the device and calls the nand_scan_bbt function
|
|
* support for the device and calls the nand_scan_bbt function
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
-int nand_default_bbt (struct mtd_info *mtd)
|
|
|
|
|
|
+int nand_default_bbt(struct mtd_info *mtd)
|
|
{
|
|
{
|
|
struct nand_chip *this = mtd->priv;
|
|
struct nand_chip *this = mtd->priv;
|
|
|
|
|
|
@@ -1046,7 +1044,7 @@ int nand_default_bbt (struct mtd_info *mtd)
|
|
* of the good / bad information, so we _must_ store
|
|
* of the good / bad information, so we _must_ store
|
|
* this information in a good / bad table during
|
|
* this information in a good / bad table during
|
|
* startup
|
|
* startup
|
|
- */
|
|
|
|
|
|
+ */
|
|
if (this->options & NAND_IS_AND) {
|
|
if (this->options & NAND_IS_AND) {
|
|
/* Use the default pattern descriptors */
|
|
/* Use the default pattern descriptors */
|
|
if (!this->bbt_td) {
|
|
if (!this->bbt_td) {
|
|
@@ -1054,10 +1052,9 @@ int nand_default_bbt (struct mtd_info *mtd)
|
|
this->bbt_md = &bbt_mirror_descr;
|
|
this->bbt_md = &bbt_mirror_descr;
|
|
}
|
|
}
|
|
this->options |= NAND_USE_FLASH_BBT;
|
|
this->options |= NAND_USE_FLASH_BBT;
|
|
- return nand_scan_bbt (mtd, &agand_flashbased);
|
|
|
|
|
|
+ return nand_scan_bbt(mtd, &agand_flashbased);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/* Is a flash based bad block table requested ? */
|
|
/* Is a flash based bad block table requested ? */
|
|
if (this->options & NAND_USE_FLASH_BBT) {
|
|
if (this->options & NAND_USE_FLASH_BBT) {
|
|
/* Use the default pattern descriptors */
|
|
/* Use the default pattern descriptors */
|
|
@@ -1066,18 +1063,17 @@ int nand_default_bbt (struct mtd_info *mtd)
|
|
this->bbt_md = &bbt_mirror_descr;
|
|
this->bbt_md = &bbt_mirror_descr;
|
|
}
|
|
}
|
|
if (!this->badblock_pattern) {
|
|
if (!this->badblock_pattern) {
|
|
- this->badblock_pattern = (mtd->oobblock > 512) ?
|
|
|
|
- &largepage_flashbased : &smallpage_flashbased;
|
|
|
|
|
|
+ this->badblock_pattern = (mtd->oobblock > 512) ? &largepage_flashbased : &smallpage_flashbased;
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
this->bbt_td = NULL;
|
|
this->bbt_td = NULL;
|
|
this->bbt_md = NULL;
|
|
this->bbt_md = NULL;
|
|
if (!this->badblock_pattern) {
|
|
if (!this->badblock_pattern) {
|
|
this->badblock_pattern = (mtd->oobblock > 512) ?
|
|
this->badblock_pattern = (mtd->oobblock > 512) ?
|
|
- &largepage_memorybased : &smallpage_memorybased;
|
|
|
|
|
|
+ &largepage_memorybased : &smallpage_memorybased;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- return nand_scan_bbt (mtd, this->badblock_pattern);
|
|
|
|
|
|
+ return nand_scan_bbt(mtd, this->badblock_pattern);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -1087,26 +1083,29 @@ int nand_default_bbt (struct mtd_info *mtd)
|
|
* @allowbbt: allow access to bad block table region
|
|
* @allowbbt: allow access to bad block table region
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
-int nand_isbad_bbt (struct mtd_info *mtd, loff_t offs, int allowbbt)
|
|
|
|
|
|
+int nand_isbad_bbt(struct mtd_info *mtd, loff_t offs, int allowbbt)
|
|
{
|
|
{
|
|
struct nand_chip *this = mtd->priv;
|
|
struct nand_chip *this = mtd->priv;
|
|
int block;
|
|
int block;
|
|
- uint8_t res;
|
|
|
|
|
|
+ uint8_t res;
|
|
|
|
|
|
/* Get block number * 2 */
|
|
/* Get block number * 2 */
|
|
- block = (int) (offs >> (this->bbt_erase_shift - 1));
|
|
|
|
|
|
+ block = (int)(offs >> (this->bbt_erase_shift - 1));
|
|
res = (this->bbt[block >> 3] >> (block & 0x06)) & 0x03;
|
|
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",
|
|
|
|
- (unsigned int)offs, block >> 1, res);
|
|
|
|
|
|
+ DEBUG(MTD_DEBUG_LEVEL2, "nand_isbad_bbt(): bbt info for offs 0x%08x: (block %d) 0x%02x\n",
|
|
|
|
+ (unsigned int)offs, block >> 1, res);
|
|
|
|
|
|
switch ((int)res) {
|
|
switch ((int)res) {
|
|
- case 0x00: return 0;
|
|
|
|
- case 0x01: return 1;
|
|
|
|
- case 0x02: return allowbbt ? 0 : 1;
|
|
|
|
|
|
+ case 0x00:
|
|
|
|
+ return 0;
|
|
|
|
+ case 0x01:
|
|
|
|
+ return 1;
|
|
|
|
+ case 0x02:
|
|
|
|
+ return allowbbt ? 0 : 1;
|
|
}
|
|
}
|
|
return 1;
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
|
|
-EXPORT_SYMBOL (nand_scan_bbt);
|
|
|
|
-EXPORT_SYMBOL (nand_default_bbt);
|
|
|
|
|
|
+EXPORT_SYMBOL(nand_scan_bbt);
|
|
|
|
+EXPORT_SYMBOL(nand_default_bbt);
|