aboutsummaryrefslogtreecommitdiff
path: root/cmd/sf.c
diff options
context:
space:
mode:
authorJan Kiszka <jan.kiszka@siemens.com>2022-03-02 15:01:56 +0100
committerJagan Teki <jagan@edgeble.ai>2022-07-18 19:15:19 +0530
commitf3a56dda880af44dac87b1a60c44ebb7c079c329 (patch)
treecdca10d76dd60120660d89410aeafa7efda139f0 /cmd/sf.c
parent513c6071ce73d026bb87a4db009e4bfc28e93df3 (diff)
downloadu-boot-f3a56dda880af44dac87b1a60c44ebb7c079c329.zip
u-boot-f3a56dda880af44dac87b1a60c44ebb7c079c329.tar.gz
u-boot-f3a56dda880af44dac87b1a60c44ebb7c079c329.tar.bz2
sf: Query write-protection status before operating the flash
Do not suggest successful operation if a flash area to be changed is actually locked, thus will not execute the request. Rather report an error and bail out. That's way more user-friendly than asking them to manually check for this case. Derived from original patch by Chao Zeng. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Acked-by: Jagan Teki <jagan@amarulasolutions.com>
Diffstat (limited to 'cmd/sf.c')
-rw-r--r--cmd/sf.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/cmd/sf.c b/cmd/sf.c
index 8713736..cd50b38 100644
--- a/cmd/sf.c
+++ b/cmd/sf.c
@@ -294,6 +294,12 @@ static int do_spi_flash_read_write(int argc, char *const argv[])
return 1;
}
+ if (strncmp(argv[0], "read", 4) != 0 && flash->flash_is_unlocked &&
+ !flash->flash_is_unlocked(flash, offset, len)) {
+ printf("ERROR: flash area is locked\n");
+ return 1;
+ }
+
buf = map_physmem(addr, len, MAP_WRBACK);
if (!buf && addr) {
puts("Failed to map physical memory\n");
@@ -350,6 +356,12 @@ static int do_spi_flash_erase(int argc, char *const argv[])
return 1;
}
+ if (flash->flash_is_unlocked &&
+ !flash->flash_is_unlocked(flash, offset, len)) {
+ printf("ERROR: flash area is locked\n");
+ return 1;
+ }
+
ret = spi_flash_erase(flash, offset, size);
printf("SF: %zu bytes @ %#x Erased: ", (size_t)size, (u32)offset);
if (ret)