Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 4484
b: refs/heads/master
c: eeada24
h: refs/heads/master
v: v3
  • Loading branch information
Artem B. Bityuckiy authored and Thomas Gleixner committed May 23, 2005
1 parent 95a8e4b commit 5c62b99
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 15 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 41ce921440bd14d9b69b19fbf47d9278582739fe
refs/heads/master: eeada24da8bd23fcf6acd2729be054ea99b301bb
52 changes: 38 additions & 14 deletions trunk/drivers/mtd/nand/nand_bbt.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Copyright (C) 2004 Thomas Gleixner (tglx@linutronix.de)
*
* $Id: nand_bbt.c,v 1.28 2004/11/13 10:19:09 gleixner Exp $
* $Id: nand_bbt.c,v 1.30 2005/02/11 10:14:12 dedekind Exp $
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
Expand Down Expand Up @@ -252,10 +252,10 @@ 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
* for the given good/bad block identify pattern
*/
static void 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;
int i, j, numblocks, len, scanlen;
int i, j, numblocks, len, scanlen, pagelen;
int startblock;
loff_t from;
size_t readlen, ooblen;
Expand All @@ -270,9 +270,18 @@ static void create_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_desc
else
len = 1;
}
scanlen = mtd->oobblock + mtd->oobsize;
readlen = len * mtd->oobblock;
ooblen = len * mtd->oobsize;

if (bd->options == 0) {
/* Memory-based BBT. We may read only needed bytes from the OOB area to
* test if block is bad, no need to read the whole page content. */
scanlen = ooblen = pagelen = 0;
readlen = bd->len;
} else {
scanlen = mtd->oobblock + mtd->oobsize;
readlen = len * mtd->oobblock;
ooblen = len * mtd->oobsize;
pagelen = mtd->oobblock;
}

if (chip == -1) {
/* Note that numblocks is 2 * (real numblocks) here, see i+=2 below as it
Expand All @@ -284,7 +293,7 @@ static void create_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_desc
if (chip >= this->numchips) {
printk (KERN_WARNING "create_bbt(): chipnr (%d) > available chips (%d)\n",
chip + 1, this->numchips);
return;
return -EINVAL;
}
numblocks = this->chipsize >> (this->bbt_erase_shift - 1);
startblock = chip * numblocks;
Expand All @@ -293,9 +302,18 @@ static void create_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_desc
}

for (i = startblock; i < numblocks;) {
nand_read_raw (mtd, buf, from, readlen, ooblen);
int ret;

if (bd->options == 0) {
size_t retlen;
if ((ret = mtd->read_oob(mtd, from + bd->offs, bd->len, &retlen, &buf[bd->offs])))
return ret;
} else {
if ((ret = nand_read_raw (mtd, buf, from, readlen, ooblen)))
return ret;
}
for (j = 0; j < len; j++) {
if (check_pattern (&buf[j * scanlen], scanlen, mtd->oobblock, bd)) {
if (check_pattern (&buf[j * scanlen], scanlen, pagelen, bd)) {
this->bbt[i >> 3] |= 0x03 << (i & 0x6);
printk (KERN_WARNING "Bad eraseblock %d at 0x%08x\n",
i >> 1, (unsigned int) from);
Expand All @@ -305,6 +323,7 @@ static void create_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_desc
i += 2;
from += (1 << this->bbt_erase_shift);
}
return 0;
}

/**
Expand Down Expand Up @@ -595,8 +614,7 @@ static int nand_memory_bbt (struct mtd_info *mtd, struct nand_bbt_descr *bd)

/* Ensure that we only scan for the pattern and nothing else */
bd->options = 0;
create_bbt (mtd, this->data_buf, bd, -1);
return 0;
return create_bbt (mtd, this->data_buf, bd, -1);
}

/**
Expand Down Expand Up @@ -808,8 +826,14 @@ int nand_scan_bbt (struct mtd_info *mtd, struct nand_bbt_descr *bd)
/* If no primary table decriptor is given, scan the device
* to build a memory based bad block table
*/
if (!td)
return nand_memory_bbt(mtd, bd);
if (!td) {
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);
this->bbt = NULL;
}
return res;
}

/* Allocate a temporary buffer for one eraseblock incl. oob */
len = (1 << this->bbt_erase_shift);
Expand Down Expand Up @@ -1042,7 +1066,7 @@ int nand_isbad_bbt (struct mtd_info *mtd, loff_t offs, int allowbbt)
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, res, block >> 1);
(unsigned int)offs, block >> 1, res);

switch ((int)res) {
case 0x00: return 0;
Expand Down

0 comments on commit 5c62b99

Please sign in to comment.