cmd: sf: align erase and write on erase block boundary
authorViorel Suman <viorel.suman@nxp.com>
Fri, 19 Sep 2025 07:01:56 +0000 (15:01 +0800)
committerTom Rini <trini@konsulko.com>
Tue, 14 Oct 2025 14:19:43 +0000 (08:19 -0600)
Align erase and write on erase block boundary in line with how read was
aligned in commit 622b5d35613 ("cmd: sf: Handle unaligned 'update' start
offset").

Fixes: 622b5d35613 ("cmd: sf: Handle unaligned 'update' start offset")
Signed-off-by: Viorel Suman <viorel.suman@nxp.com>
Signed-off-by: Ye Li <ye.li@nxp.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
Tested-by: Marek Vasut <marek.vasut+renesas@mailbox.org> # R-Car V4H
cmd/sf.c

index 08e364e..b5b7f67 100644 (file)
--- a/cmd/sf.c
+++ b/cmd/sf.c
@@ -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) {