summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorTom Rini <trini@ti.com>2013-09-16 20:02:50 -0400
committerTom Rini <trini@ti.com>2013-09-16 20:02:50 -0400
commitbc23d96b75fb9c494390c8af02c473c4f11f7719 (patch)
tree1f20b373eaf8c0d56b6d7d4feb7f285fd988f2c1 /common
parent6856254fc05d67f874d08a534724c842f93a605f (diff)
parentb95f958d7d06b3cd117647b29b288cf168aa2ee9 (diff)
downloadtalos-obmc-uboot-bc23d96b75fb9c494390c8af02c473c4f11f7719.tar.gz
talos-obmc-uboot-bc23d96b75fb9c494390c8af02c473c4f11f7719.zip
Merge branch 'master' of git://git.denx.de/u-boot-spi
Diffstat (limited to 'common')
-rw-r--r--common/cmd_sf.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/common/cmd_sf.c b/common/cmd_sf.c
index 4af0f0af26..3f60979ae7 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;
}
OpenPOWER on IntegriCloud