u-boot.lists.denx.de archive mirror
 help / color / mirror / Atom feed
* [PATCH] sf: Querying write-protect status before operating the flash
@ 2021-06-22  5:21 chao zeng
  2021-06-29 13:50 ` Jagan Teki
  2021-11-05 17:17 ` Tudor.Ambarus
  0 siblings, 2 replies; 13+ messages in thread
From: chao zeng @ 2021-06-22  5:21 UTC (permalink / raw)
  To: u-boot; +Cc: jagan, vigneshr, Chao Zeng

From: Chao Zeng <chao.zeng@siemens.com>

When operating the write-protection flash,spi_flash_std_write() and
spi_flash_std_erase() would return wrong result.The flash is protected,
but write or erase the flash would show "OK".

Check the flash write protection state if the write-protection has enbale
before operating the flash.

Signed-off-by: Chao Zeng <chao.zeng@siemens.com>
---

 drivers/mtd/spi/sf_probe.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c
index 3befbe91ca..f06e6b88bd 100644
--- a/drivers/mtd/spi/sf_probe.c
+++ b/drivers/mtd/spi/sf_probe.c
@@ -109,6 +109,11 @@ static int spi_flash_std_write(struct udevice *dev, u32 offset, size_t len,
 	struct mtd_info *mtd = &flash->mtd;
 	size_t retlen;
 
+	if (flash->flash_is_locked && flash->flash_is_locked(flash, offset, len)) {
+		debug("SF: Flash is locked\n");
+		return -ENOPROTOOPT;
+	}
+
 	return mtd->_write(mtd, offset, len, &retlen, buf);
 }
 
@@ -127,6 +132,11 @@ static int spi_flash_std_erase(struct udevice *dev, u32 offset, size_t len)
 	instr.addr = offset;
 	instr.len = len;
 
+	if (flash->flash_is_locked && flash->flash_is_locked(flash, offset, len)) {
+		debug("SF: Flash is locked\n");
+		return -ENOPROTOOPT;
+	}
+
 	return mtd->_erase(mtd, &instr);
 }
 
-- 
2.31.1



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

end of thread, other threads:[~2021-11-09  8:14 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-22  5:21 [PATCH] sf: Querying write-protect status before operating the flash chao zeng
2021-06-29 13:50 ` Jagan Teki
2021-09-08  4:55   ` chaochao2021666
2021-09-13  7:48     ` Jan Kiszka
2021-10-04 13:36       ` Jan Kiszka
2021-11-03 12:18         ` Jan Kiszka
2021-11-04 16:06           ` Tom Rini
2021-11-05 17:17 ` Tudor.Ambarus
2021-11-05 18:08   ` Jagan Teki
2021-11-08  9:50     ` [PATCH] sf: Querying write-protect status before operating the Michael Walle
2021-11-08 11:01       ` Tudor.Ambarus
2021-11-09  1:52     ` Re:Re: [PATCH] sf: Querying write-protect status before operating the flash chaochao2021666
2021-11-09  8:14       ` Tudor.Ambarus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).