Skip to contentSkip to conversation

cmd: sf: Fix the flash_is_unlocked api size parameter

PATCH Applied Venkatesh Yadav Abbarapu 3 participants 3 messages Sep 20, 2023 – Sep 21, 2023

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 cmd: sf: Fix the flash_is_unlocked api size parameter

When flash erase is called with size parameter, code is checking if sectors are locked or not. But for checking, the whole device length minus offset is used instead of actual size which should be erased. That's why when only some sectors are locked it is not possible to erase unlocked sectors.

The length is calculated as "length = max_chipsize - offset", flash_is_unlocked() api is getting updated with length which is incorrect. Fix this flash_is_unlocked() api by passing the size parameter.

ZynqMP> sf erase 0 100000
len=0x8000000 which is flash size
size=0x100000

We need to update the size in the flash_is_unlocked() api and not the length.

---
Changes in v2:
- Updated the commit description.

---
 cmd/sf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
cmd/sf.c +1 -1
index 55bef2f769..977ffcb63c 100644
@@ -366,7 +366,7 @@ static int do_spi_flash_erase(int argc, char *const argv[])
 	}
 
 	if (flash->flash_is_unlocked &&
-	    !flash->flash_is_unlocked(flash, offset, len)) {
+	    !flash->flash_is_unlocked(flash, offset, size)) {
 		printf("ERROR: flash area is locked\n");
 		return CMD_RET_FAILURE;
 	}
Signature · 1 line
2.17.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 19 lines · Venkatesh Yadav Abbarapu

When flash erase is called with size parameter, code is checking if sectors are locked or not. But for checking, the whole device length minus offset is used instead of actual size which should be erased. That's why when only some sectors are locked it is not possible to erase unlocked sectors.

The length is calculated as "length = max_chipsize - offset", flash_is_unlocked() api is getting updated with length which is incorrect. Fix this flash_is_unlocked() api by passing the size parameter.

ZynqMP> sf erase 0 100000
len=0x8000000 which is flash size
size=0x100000

We need to update the size in the flash_is_unlocked() api and not the length.

Quoted 7 lines

---
Changes in v2:
- Updated the commit description.

---
 cmd/sf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Applied
#2 lore raw
In reply to Venkatesh Yadav Abbarapu
Quoted 31 lines · Venkatesh Yadav Abbarapu

When flash erase is called with size parameter, code is checking if sectors are locked or not. But for checking, the whole device length minus offset is used instead of actual size which should be erased. That's why when only some sectors are locked it is not possible to erase unlocked sectors.

The length is calculated as "length = max_chipsize - offset", flash_is_unlocked() api is getting updated with length which is incorrect. Fix this flash_is_unlocked() api by passing the size parameter.

ZynqMP> sf erase 0 100000
len=0x8000000 which is flash size
size=0x100000

We need to update the size in the flash_is_unlocked() api and not the length.

---
Changes in v2:
- Updated the commit description.

---
  cmd/sf.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
cmd/sf.c +0 -0
index 55bef2f769..977ffcb63c 100644

cmd/sf.c static int do_spi_flash_erase(int argc, char *const argv[]) · line 372

Quoted 8 lines
cmd/sf.c +1 -1
@@ -366,7 +366,7 @@ static int do_spi_flash_erase(int argc, char *const argv[])
  	}
 
  	if (flash->flash_is_unlocked &&
-	    !flash->flash_is_unlocked(flash, offset, len)) {
+	    !flash->flash_is_unlocked(flash, offset, size)) {
  		printf("ERROR: flash area is locked\n");
  		return CMD_RET_FAILURE;
  	}

Applied.
M