]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
mtd: spinand: enable erasing of bad mtd blocks
authorMikhail Kshevetskiy <mikhail.kshevetskiy@oktetlabs.ru>
Mon, 22 Jun 2020 13:16:34 +0000 (16:16 +0300)
committerJagan Teki <jagan@amarulasolutions.com>
Fri, 18 Dec 2020 10:46:36 +0000 (16:16 +0530)
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 <mikhail.kshevetskiy@oktetlabs.ru>
drivers/mtd/nand/core.c

index 6fbd24ba7495b2d99301eead36968df1cbcde287..219efdc8959a365b5ff423fa33cb45f20e926231 100644 (file)
@@ -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);