cmd: sf: align erase and write on erase block boundary

Align erase and write on erase block boundary in line with how read was
aligned in commit 622b5d3561 ("cmd: sf: Handle unaligned 'update' start
offset").

Fixes: 622b5d3561 ("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
This commit is contained in:
Viorel Suman
2025-09-19 15:01:56 +08:00
committed by Tom Rini
parent 3b278dd9e6
commit 865f665422

View File

@@ -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) {