mirror of
https://github.com/AsahiLinux/u-boot
synced 2025-02-17 22:49:02 +00:00
cmd_sf: let "sf update" preserve the final part of the last sector
Since "sf update" erases the last block as a whole, but only rewrites the meaningful initial part of it, the rest would be left erased, potentially erasing meaningful information. So, as a safety measure, have it rewrite the original content. Signed-off-by: Gerlando Falauto <gerlando.falauto@keymile.com> Cc: Valentin Longchamp <valentin.longchamp@keymile.com> Cc: Holger Brunck <holger.brunck@keymile.com> Acked-by: Simon Glass <sjg@chromium.org> Signed-off-by: Jagannadha Sutradharudu Teki <jaganna@xilinx.com>
This commit is contained in:
parent
a928a36ff9
commit
b95f958d7d
1 changed files with 12 additions and 1 deletions
|
@ -152,8 +152,10 @@ static const char *spi_flash_update_block(struct spi_flash *flash, u32 offset,
|
|||
{
|
||||
debug("offset=%#x, sector_size=%#x, len=%#zx\n",
|
||||
offset, flash->sector_size, len);
|
||||
if (spi_flash_read(flash, offset, len, cmp_buf))
|
||||
/* Read the entire sector so to allow for rewriting */
|
||||
if (spi_flash_read(flash, offset, flash->sector_size, cmp_buf))
|
||||
return "read";
|
||||
/* Compare only what is meaningful (len) */
|
||||
if (memcmp(cmp_buf, buf, len) == 0) {
|
||||
debug("Skip region %x size %zx: no change\n",
|
||||
offset, len);
|
||||
|
@ -163,8 +165,17 @@ static const char *spi_flash_update_block(struct spi_flash *flash, u32 offset,
|
|||
/* Erase the entire sector */
|
||||
if (spi_flash_erase(flash, offset, flash->sector_size))
|
||||
return "erase";
|
||||
/* Write the initial part of the block from the source */
|
||||
if (spi_flash_write(flash, offset, len, buf))
|
||||
return "write";
|
||||
/* If it's a partial sector, rewrite the existing part */
|
||||
if (len != flash->sector_size) {
|
||||
/* Rewrite the original data to the end of the sector */
|
||||
if (spi_flash_write(flash, offset + len,
|
||||
flash->sector_size - len, &cmp_buf[len]))
|
||||
return "write";
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue