If load of existing BBT fails (first run), scan device for factory-set BBMs (Bad-Block Markers) and create a new flash-resident.
Signed-off-by: Lee Jones <[email protected]> --- drivers/mtd/nand/stm_nand_bch.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/mtd/nand/stm_nand_bch.c b/drivers/mtd/nand/stm_nand_bch.c index 2df452b..a06dca8 100644 --- a/drivers/mtd/nand/stm_nand_bch.c +++ b/drivers/mtd/nand/stm_nand_bch.c @@ -1235,6 +1235,30 @@ static int bch_load_bbt(struct nandi_controller *nandi, return 0; } +static int bch_scan_bbt(struct mtd_info *mtd) +{ + struct nand_chip *chip = mtd->priv; + struct nandi_controller *nandi = chip->priv; + struct nandi_bbt_info *bbt_info = &nandi->info.bbt_info; + int err; + /* Load Flash-resident BBT */ + err = bch_load_bbt(nandi, bbt_info); + if (err) { + dev_warn(nandi->dev, + "failed to find BBTs:" + " scanning device for bad-block markers\n"); + + /* Scan, build, and write BBT */ + nandi_scan_build_bbt(nandi, bbt_info); + err = bch_update_bbts(nandi, bbt_info, NAND_IBBT_UPDATE_BOTH, + bbt_info->bbt_vers[0] + 1); + if (err) + return err; + } + + return 0; +} + /* * Initialisation */ @@ -1318,6 +1342,8 @@ static void nandi_set_mtd_defaults(struct nandi_controller *nandi, chip->ecc.read_page = bch_read; chip->write_page = bch_write; + + chip->scan_bbt = bch_scan_bbt; } /* -- 1.8.3.2 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/

