public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH 1/2] mtd: spinand: wait for erase completion before writing bad block maker
@ 2020-03-10 20:32 Mikhail Kshevetskiy
  2020-03-10 20:32 ` [PATCH 2/2] mtd: spinand: fix bad block marker writing Mikhail Kshevetskiy
  2020-03-11 10:13 ` [PATCH 1/2] mtd: spinand: wait for erase completion before writing bad block maker Miquel Raynal
  0 siblings, 2 replies; 3+ messages in thread
From: Mikhail Kshevetskiy @ 2020-03-10 20:32 UTC (permalink / raw)
  To: miquel.raynal, richard; +Cc: linux-mtd, linux-kernel, Mikhail Kshevetskiy

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


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-03-11 10:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-03-10 20:32 [PATCH 1/2] mtd: spinand: wait for erase completion before writing bad block maker Mikhail Kshevetskiy
2020-03-10 20:32 ` [PATCH 2/2] mtd: spinand: fix bad block marker writing Mikhail Kshevetskiy
2020-03-11 10:13 ` [PATCH 1/2] mtd: spinand: wait for erase completion before writing bad block maker Miquel Raynal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox