diff mbox series

sf: Querying write-protect status before operating the flash

Message ID 20210622052126.49853-1-chaochao2021666@163.com
State New
Delegated to: Jagannadha Sutradharudu Teki
Headers show
Series sf: Querying write-protect status before operating the flash | expand

Commit Message

chao zeng June 22, 2021, 5:21 a.m. UTC
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(+)

Comments

Jagan Teki June 29, 2021, 1:50 p.m. UTC | #1
On Tue, Jun 22, 2021 at 10:51 AM chao zeng <chaochao2021666@163.com> wrote:
>
> 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>
> ---

Does it broken on master? if yes can you check in u-boot-spi/next?

Jagan.
diff mbox series

Patch

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);
 }