From patchwork Mon Jun 22 13:16:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Kshevetskiy X-Patchwork-Id: 242755 List-Id: U-Boot discussion From: mikhail.kshevetskiy at oktetlabs.ru (Mikhail Kshevetskiy) Date: Mon, 22 Jun 2020 16:16:34 +0300 Subject: [PATCH 4/4] mtd: spinand: enable erasing of bad mtd blocks In-Reply-To: <20200622131634.2132717-1-mikhail.kshevetskiy@oktetlabs.ru> References: <20200622131634.2132717-1-mikhail.kshevetskiy@oktetlabs.ru> Message-ID: <20200622131634.2132717-4-mikhail.kshevetskiy@oktetlabs.ru> U-Boot is able to erase bad mtd blocks on raw nand devices, but this is not true for spinand flashes. Lets enable this feature for spinand flashes as well. This is extemelly useful for flash testing. Signed-off-by: Mikhail Kshevetskiy --- drivers/mtd/nand/core.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/nand/core.c b/drivers/mtd/nand/core.c index 6fbd24ba74..a39b4c4b30 100644 --- a/drivers/mtd/nand/core.c +++ b/drivers/mtd/nand/core.c @@ -130,10 +130,18 @@ EXPORT_SYMBOL_GPL(nanddev_isreserved); */ int nanddev_erase(struct nand_device *nand, const struct nand_pos *pos) { + unsigned int entry; + if (nanddev_isbad(nand, pos) || nanddev_isreserved(nand, pos)) { pr_warn("attempt to erase a bad/reserved block @%llx\n", nanddev_pos_to_offs(nand, pos)); - return -EIO; + if (nanddev_isreserved(nand, pos)) + return -EIO; + + /* remove bad block from BBT */ + entry = nanddev_bbt_pos_to_entry(nand, pos); + nanddev_bbt_set_block_status(nand, entry, + NAND_BBT_BLOCK_STATUS_UNKNOWN); } return nand->ops->erase(nand, pos);