This patch introduces support for a custom BBT scan based on code from Marvell's U-Boot: https://github.com/MarvellEmbeddedProcessors/u-boot-marvell
Using a Marvell NAND Flash Controller (NFC), we found this change was needed to initialize a new NAND chip with the nand erase.chip command. Without the change, a timeout would occur when trying to read the OOB area to when constructing the bad-block table. The changes are enabled by defining BBT_CUSTOM_SCAN. Signed-off-by: Joshua Scott <joshua.sc...@alliedtelesis.co.nz> --- drivers/mtd/nand/nand_bbt.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/drivers/mtd/nand/nand_bbt.c b/drivers/mtd/nand/nand_bbt.c index 74c4c9a3c8..545d43dad4 100644 --- a/drivers/mtd/nand/nand_bbt.c +++ b/drivers/mtd/nand/nand_bbt.c @@ -438,6 +438,37 @@ static int scan_block_fast(struct mtd_info *mtd, struct nand_bbt_descr *bd, return 0; } +#ifdef BBT_CUSTOM_SCAN +/* + * Scan a given block in the custom location based on Naked symantics + * BBT_CUSTOM_SCAN_PAGE selects the page within the erase-block to use + * BBT_CUSTOM_SCAN_POSITION selects the byte within the page to check + */ +static int scan_block_custom(struct mtd_info *mtd, struct nand_bbt_descr *bd, + uint64_t offs, uint8_t *buf) +{ + int ret; + struct mtd_oob_ops ops; + + ops.mode = MTD_OPS_RAW; + ops.ooboffs = 0; + ops.ooblen = mtd->oobsize; + ops.oobbuf = (buf + mtd->writesize); + ops.datbuf = buf; + ops.len = mtd->writesize; + + ret = mtd_read_oob(mtd, + (offs + (mtd->writesize * BBT_CUSTOM_SCAN_PAGE)), &ops); + if (ret) + return ret; + + if (buf[BBT_CUSTOM_SCAN_POSITION] != 0xff) + return 1; + + return 0; +} +#endif + /** * create_bbt - [GENERIC] Create a bad block table by scanning the device * @mtd: MTD device structure @@ -488,7 +519,11 @@ static int create_bbt(struct mtd_info *mtd, uint8_t *buf, BUG_ON(bd->options & NAND_BBT_NO_OOB); +#ifdef BBT_CUSTOM_SCAN + ret = scan_block_custom(mtd, bd, from, buf); +#else ret = scan_block_fast(mtd, bd, from, buf, numpages); +#endif if (ret < 0) return ret; -- 2.13.0 _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot