* [U-Boot] [PATCH v4] cmd_sf: let "sf update" preserve the final part of the last sector
@ 2013-08-27 13:52 Jagannadha Sutradharudu Teki
2013-08-27 14:14 ` Jagan Teki
0 siblings, 1 reply; 2+ messages in thread
From: Jagannadha Sutradharudu Teki @ 2013-08-27 13:52 UTC (permalink / raw)
To: u-boot
From: Gerlando Falauto <gerlando.falauto@keymile.com>
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>
---
Changes for v4:
- Rebase to current tree
- Fix one checkpatch warning
common/cmd_sf.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/common/cmd_sf.c b/common/cmd_sf.c
index 4af0f0a..3f60979 100644
--- a/common/cmd_sf.c
+++ b/common/cmd_sf.c
@@ -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;
}
--
1.8.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [U-Boot] [PATCH v4] cmd_sf: let "sf update" preserve the final part of the last sector
2013-08-27 13:52 [U-Boot] [PATCH v4] cmd_sf: let "sf update" preserve the final part of the last sector Jagannadha Sutradharudu Teki
@ 2013-08-27 14:14 ` Jagan Teki
0 siblings, 0 replies; 2+ messages in thread
From: Jagan Teki @ 2013-08-27 14:14 UTC (permalink / raw)
To: u-boot
On 27-08-2013 19:22, Jagannadha Sutradharudu Teki wrote:
> From: Gerlando Falauto <gerlando.falauto@keymile.com>
>
> 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>
> ---
> Changes for v4:
> - Rebase to current tree
> - Fix one checkpatch warning
>
> common/cmd_sf.c | 13 ++++++++++++-
> 1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/common/cmd_sf.c b/common/cmd_sf.c
> index 4af0f0a..3f60979 100644
> --- a/common/cmd_sf.c
> +++ b/common/cmd_sf.c
> @@ -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;
> }
>
>
Applied to u-boot-spi/master
--
Thanks,
Jagan.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-08-27 14:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-27 13:52 [U-Boot] [PATCH v4] cmd_sf: let "sf update" preserve the final part of the last sector Jagannadha Sutradharudu Teki
2013-08-27 14:14 ` Jagan Teki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox