]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/cmd_sf.c
zynq: Add UART0, UART1 configs support
[karo-tx-uboot.git] / common / cmd_sf.c
index 4af0f0af26bcfa3afbc63708fb019a89cc99d274..3994b0651c53a8331e49d0093670507ea2f8d8bb 100644 (file)
@@ -2,7 +2,8 @@
  * Command for accessing SPI flash.
  *
  * Copyright (C) 2008 Atmel Corporation
- * Licensed under the GPL-2 or later.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
@@ -152,8 +153,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 +166,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;
 }