mirror of https://gitee.com/openkylin/linux.git
mtd: nand: use read_oob() instead of cmdfunc() for bad block check
The nand_default_block_markbad() and scan_block_fast() use high level APIs to get access to the BBM. On the other hand, nand_block_bad (the default implementation of ->block_bad) calls the lower level ->cmdfunc hook. This prevents drivers from using ->ecc.read_oob() even if optimized read operation is implemented. Besides, some NAND controllers may protect the BBM with ECC. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
This commit is contained in:
parent
9fe4b66efb
commit
c120e75e0e
|
@ -354,40 +354,32 @@ static void nand_read_buf16(struct mtd_info *mtd, uint8_t *buf, int len)
|
||||||
*/
|
*/
|
||||||
static int nand_block_bad(struct mtd_info *mtd, loff_t ofs)
|
static int nand_block_bad(struct mtd_info *mtd, loff_t ofs)
|
||||||
{
|
{
|
||||||
int page, res = 0, i = 0;
|
int page, page_end, res;
|
||||||
struct nand_chip *chip = mtd_to_nand(mtd);
|
struct nand_chip *chip = mtd_to_nand(mtd);
|
||||||
u16 bad;
|
u8 bad;
|
||||||
|
|
||||||
if (chip->bbt_options & NAND_BBT_SCANLASTPAGE)
|
if (chip->bbt_options & NAND_BBT_SCANLASTPAGE)
|
||||||
ofs += mtd->erasesize - mtd->writesize;
|
ofs += mtd->erasesize - mtd->writesize;
|
||||||
|
|
||||||
page = (int)(ofs >> chip->page_shift) & chip->pagemask;
|
page = (int)(ofs >> chip->page_shift) & chip->pagemask;
|
||||||
|
page_end = page + (chip->bbt_options & NAND_BBT_SCAN2NDPAGE ? 2 : 1);
|
||||||
|
|
||||||
do {
|
for (; page < page_end; page++) {
|
||||||
if (chip->options & NAND_BUSWIDTH_16) {
|
res = chip->ecc.read_oob(mtd, chip, page);
|
||||||
chip->cmdfunc(mtd, NAND_CMD_READOOB,
|
if (res)
|
||||||
chip->badblockpos & 0xFE, page);
|
return res;
|
||||||
bad = cpu_to_le16(chip->read_word(mtd));
|
|
||||||
if (chip->badblockpos & 0x1)
|
bad = chip->oob_poi[chip->badblockpos];
|
||||||
bad >>= 8;
|
|
||||||
else
|
|
||||||
bad &= 0xFF;
|
|
||||||
} else {
|
|
||||||
chip->cmdfunc(mtd, NAND_CMD_READOOB, chip->badblockpos,
|
|
||||||
page);
|
|
||||||
bad = chip->read_byte(mtd);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (likely(chip->badblockbits == 8))
|
if (likely(chip->badblockbits == 8))
|
||||||
res = bad != 0xFF;
|
res = bad != 0xFF;
|
||||||
else
|
else
|
||||||
res = hweight8(bad) < chip->badblockbits;
|
res = hweight8(bad) < chip->badblockbits;
|
||||||
ofs += mtd->writesize;
|
if (res)
|
||||||
page = (int)(ofs >> chip->page_shift) & chip->pagemask;
|
return res;
|
||||||
i++;
|
}
|
||||||
} while (!res && i < 2 && (chip->bbt_options & NAND_BBT_SCAN2NDPAGE));
|
|
||||||
|
|
||||||
return res;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue