On 09/03/2020 10:15, Tudor.Ambarus@xxxxxxxxxxxxx wrote:
From: Tudor Ambarus <tudor.ambarus@xxxxxxxxxxxxx>
When an Erase or Program error occurs on a spansion/cypress or a
micron flash, the WEL bit remains set to one and should be cleared
with a WRDI command in order to protect against inadvertent writes
that can possible corrupt the contents of the memory.
Winbond, macronix, gd, etc., do not support the E_ERR and P_ERR bits in the
Status Register and always clear the WEL bit regardless of the outcome
of the erase or page program operation (ex w25q40bw, MX25L25635E).
Issue a WRDI command when erase or page program errors occur.
Reported-by: John Garry <john.garry@xxxxxxxxxx>
Previously I would get this unlock complaint:
root@ubuntu:/home/john# flash_lock -l /dev/mtd0
root@ubuntu:/home/john# sudo mtd_debug erase /dev/mtd0 0xf80000 4096
[ 167.458647] spi-nor spi-PRP0001:00: Erase operation failed.
[ 167.464248] spi-nor spi-PRP0001:00: Attempted to modify a protected
sector.
MEMERASE: Input/output error
root@ubuntu:/home/john# flash_lock -u /dev/mtd0
flash_lock: error!: could not unlock device: /dev/mtd0
error 5 (Input/output error)
Now, no such issue. Thanks
Tested-by: John Garry <john.garry@xxxxxxxxxx>
Signed-off-by: Tudor Ambarus <tudor.ambarus@xxxxxxxxxxxxx>
---
drivers/mtd/spi-nor/spi-nor.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index caf0c109cca0..4376d8ad5834 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -819,6 +819,17 @@ static int spi_nor_sr_ready(struct spi_nor *nor)
dev_err(nor->dev, "Programming Error occurred\n");
spi_nor_clear_sr(nor);
+
+ /*
+ * WEL bit remains set to one when an erase or page program
+ * error occurs. Issue a Write Disable command to protect
+ * against inadvertent writes that can possibly corrupt the
+ * contents of the memory.
+ */
+ ret = spi_nor_write_disable(nor);
+ if (ret)
+ return ret;
+
return -EIO;
}
@@ -875,6 +886,17 @@ static int spi_nor_fsr_ready(struct spi_nor *nor)
"Attempted to modify a protected sector.\n");
spi_nor_clear_fsr(nor);
+
+ /*
+ * WEL bit remains set to one when an erase or page program
+ * error occurs. Issue a Write Disable command to protect
+ * against inadvertent writes that can possibly corrupt the
+ * contents of the memory.
+ */
+ ret = spi_nor_write_disable(nor);
+ if (ret)
+ return ret;
+
return -EIO;
}
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/