Skip to content

Commit bd9c9fe

Browse files
sriedmuellermiquelraynal
authored andcommitted
mtd: rawnand: bbt: Skip bad blocks when searching for the BBT in NAND
The blocks containing the bad block table can become bad as well. So make sure to skip any blocks that are marked bad when searching for the bad block table. Otherwise in very rare cases where two BBT blocks wear out it might happen that an obsolete BBT is used instead of a newer available version. Signed-off-by: Stefan Riedmueller <s.riedmueller@phytec.de> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Link: https://lore.kernel.org/linux-mtd/20210325102337.481172-1-s.riedmueller@phytec.de
1 parent 25fefc8 commit bd9c9fe

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

drivers/mtd/nand/raw/nand_bbt.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ static int search_bbt(struct nand_chip *this, uint8_t *buf,
525525
{
526526
u64 targetsize = nanddev_target_size(&this->base);
527527
struct mtd_info *mtd = nand_to_mtd(this);
528+
struct nand_bbt_descr *bd = this->badblock_pattern;
528529
int i, chips;
529530
int startblock, block, dir;
530531
int scanlen = mtd->writesize + mtd->oobsize;
@@ -560,6 +561,10 @@ static int search_bbt(struct nand_chip *this, uint8_t *buf,
560561
int actblock = startblock + dir * block;
561562
loff_t offs = (loff_t)actblock << this->bbt_erase_shift;
562563

564+
/* Check if block is marked bad */
565+
if (scan_block_fast(this, bd, offs, buf))
566+
continue;
567+
563568
/* Read first page */
564569
scan_read(this, buf, offs, mtd->writesize, td);
565570
if (!check_pattern(buf, scanlen, mtd->writesize, td)) {

0 commit comments

Comments
 (0)