From: Viorel Suman <viorel.su...@nxp.com>

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 <viorel.su...@nxp.com>
Signed-off-by: Ye Li <ye...@nxp.com>
---
 cmd/sf.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/cmd/sf.c b/cmd/sf.c
index 08e364e1914..b5b7f671fb9 100644
--- 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) {
-- 
2.37.1

Reply via email to