[PATCH 1/2] mtd: spinand: wait for erase completion before writing bad block maker

Mikhail Kshevetskiy
2020-03-10T20:41:22Z

SPI flash will discard any write operation while it is busy with block
erasing. As result bad block marker will not be writed to a flash.
To fix it just wait for completion of erase operation.

The erasing code is almost the same as in spinand_erase(). The only
difference is: we ignore ERASE_FAILED status.

This patch also improve error handling a bit.

Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@oktetlabs.ru>
---
drivers/mtd/nand/spi/core.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index 89f6beefb01c..bb4eac400b0f 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -610,6 +610,7 @@ static int spinand_markbad(struct nand_device *nand, const struct nand_pos *pos)
.oobbuf.out = spinand->oobbuf,
};
int ret;
+ u8 status;

/* Erase block before marking it bad. */
ret = spinand_select_target(spinand, pos->target);
@@ -620,7 +621,14 @@ static int spinand_markbad(struct nand_device *nand, const struct nand_pos *pos)
if (ret)
return ret;

- spinand_erase_op(spinand, pos);
+ ret = spinand_erase_op(spinand, pos);
+ if (ret)
+ return ret;
+
+ /* ignore status as erase may fail for bad blocks */
+ spinand_wait(spinand, &status);
+ if (ret)
+ return ret;

memset(spinand->oobbuf, 0, 2);
return spinand_write_page(spinand, &req);
--
2.25.0