cmd: sf: align erase and write on erase block boundary
PATCH 1/1 cmd: sf: align erase and write on erase block boundary
From: Viorel Suman <[email protected]>
Align erase and write on erase block boundary in line with how read was aligned in commit 622b5d35613.
--- cmd/sf.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
cmd/sf.c +2 -3
@@ -197,7 +197,7 @@ static const char *spi_flash_update_block(struct spi_flash *flash, u32 offset,return NULL ; }/* Erase the entire sector */ -if (spi_flash_erase (flash, offset, flash->sector_size)) +if (spi_flash_erase (flash, read_offset, flash->sector_size))return "erase" ;/* If it's a partial sector, copy the data into the temp-buffer */ if (len != flash->sector_size) {
@@ -205,7 +205,7 @@ static const char *spi_flash_update_block(struct spi_flash *flash, u32 offset, ptr = cmp_buf; }/* Write one complete sector */ -if (spi_flash_write (flash, offset, flash->sector_size, ptr)) +if (spi_flash_write (flash, read_offset, flash->sector_size, ptr))return "write" ;return NULL ;
@@ -241,7 +241,6 @@ static int spi_flash_update(struct spi_flash *flash, u32 offset,ulong last_update =get_timer (0 );for (; buf < end && !err_oper; buf += todo, offset += todo) { - todo =min_t (size_t, end - buf, flash->sector_size); todo =min_t (size_t, end - buf, flash->sector_size - (offset % flash->sector_size));if (get_timer (last_update) >100 ) {
Signature · 1 line
2.37.1
Quoted 4 lines · Ye Li
From: Viorel Suman <[email protected]>
Align erase and write on erase block boundary in line with how read was aligned in commit
622b5d35613.
What is the issue that is being fixed here ?
What is the reproducer ?
Details please .
Quoted 7 lines · Marek Vasut
Quoted 4 lines · Ye Li
From: Viorel Suman <[email protected]>
Align erase and write on erase block boundary in line with how read was aligned in commit
622b5d35613.What is the issue that is being fixed here ?
Previous commit 622b5d35613 tried to fix issue that offset is not sector size aligned. But it only use the aligned offset read_offset for flash read, not use it for erase and write. So still unaligned offset send to spi_flash_erase and spi_flash_write.> What is the reproducer ?
Quoted 1 line
If the address is neither page or sector aligned, we meet issue with flash update
Best regards,
Ye Li> Details please .
Quoted 6 lines · Ye Li
Quoted 3 lines · Marek Vasut
Quoted 2 lines · Ye Li
From: Viorel Suman <[email protected]>
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Align erase and write on erase block boundary in line with how read was aligned in commit
622b5d35613.What is the issue that is being fixed here ?
Previous commit
622b5d35613tried to fix issue that offset is not sector size aligned. But it only use the aligned offsetread_offsetfor flash read, not use it for erase and write. So still unaligned offset send tospi_flash_eraseandspi_flash_write.> What is the reproducer ?Quoted 1 line
If the address is neither page or sector aligned, we meet issue with flash update
What exact command do I run to trigger the problem, what is the failing result without this patch, what is the passing result with this patch ?
Quoted 7 lines · Marek Vasut
Quoted 6 lines · Ye Li
Quoted 3 lines · Marek Vasut
Quoted 2 lines · Ye Li
From: Viorel Suman <[email protected]>
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Align erase and write on erase block boundary in line with how read was aligned in commit
622b5d35613.What is the issue that is being fixed here ?
Previous commit
622b5d35613tried to fix issue that offset is not sector size aligned. But it only use the aligned offsetread_offsetfor flash read, not use it for erase and write. So still unaligned offset send tospi_flash_eraseandspi_flash_write.> What is the reproducer ?Quoted 1 line
If the address is neither page or sector aligned, we meet issue with flash update
What exact command do I run to trigger the problem, what is the failing result without this patch, what is the passing result with this patch ?
You can use "sf update" command to reproduce the issue. Without the patch:
u-boot=> sf update 0x94000000 0x10 0x20
device 0 offset 0x10, size 0x20
SPI flash failed in erase step
With the patch:
u-boot=> sf update 0x94000000 0x10 0x20
device 0 offset 0x10, size 0x20
32 bytes written, 0 bytes skipped in 0.20s, speed 1424 B/s
Best regards,
Ye Li
On 9/22/25 8:48 AM, Ye Li wrote:
Hello again,
I'm sorry for the horribly late reply.
Quoted 18 lines
Quoted 4 lines
Quoted 4 lines · Marek Vasut
Quoted 3 lines · Ye Li
Quoted 2 lines
From: Viorel Suman <[email protected]>
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Align erase and write on erase block boundary in line with how read was aligned in commit
622b5d35613.What is the issue that is being fixed here ?
Previous commit
622b5d35613tried to fix issue that offset is not sector size aligned. But it only use the aligned offsetread_offsetfor flash read, not use it for erase and write. So still unaligned offset send tospi_flash_eraseandspi_flash_write.> What is the reproducer ?Quoted 1 line
If the address is neither page or sector aligned, we meet issue with flash update
What exact command do I run to trigger the problem, what is the failing result without this patch, what is the passing result with this patch ?
You can use "sf update" command to reproduce the issue. Without the patch:
u-boot=> sf update0x940000000x100x20
device 0 offset0x10, size0x20
SPI flash failed in erase step
Quoted 4 lines
With the patch:
u-boot=> sf update0x940000000x100x20
device 0 offset0x10, size0x20
32 bytes written, 0 bytes skipped in 0.20s, speed 1424 B/s
Thank you for the test case, this helped a lot.
If you want to do a V2, please include the test case in the commit message.
In either case:
Thank you !
Quoted 8 lines · Ye Li
From: Viorel Suman <[email protected]>
Align erase and write on erase block boundary in line with how read was aligned in commit
622b5d35613.Fixes 622b5d35613 ("cmd: sf: Handle unaligned 'update' start offset")Signed-off-by Viorel Suman <[email protected]>Signed-off-by Ye Li <[email protected]>
Quoted 4 lines · Ye Li
Align erase and write on erase block boundary in line with how read was aligned in commit
622b5d35613.
Applied to u-boot/master, thanks!
[1/1] cmd: sf: align erase and write on erase block boundary
commit: 865f6654226b2b933d1971f86eddb8664ca83a3e
Signature · 1 line
Tom