]> Git Repo - J-u-boot.git/blobdiff - common/cmd_sf.c
mtd, nand: Move common functions from cmd_nand.c to common place
[J-u-boot.git] / common / cmd_sf.c
index 6aabf39302ce5e9000d19777a1622b27d1d52189..ed3e398ccd59fe2ff7a781f7200ac5a773a9b624 100644 (file)
@@ -139,8 +139,6 @@ static int do_spi_flash_probe(int argc, char * const argv[])
                return 1;
        }
 
-       if (flash)
-               spi_flash_free(flash);
        flash = new;
 #endif
 
@@ -164,6 +162,8 @@ static int do_spi_flash_probe(int argc, char * const argv[])
 static const char *spi_flash_update_block(struct spi_flash *flash, u32 offset,
                size_t len, const char *buf, char *cmp_buf, size_t *skipped)
 {
+       char *ptr = (char *)buf;
+
        debug("offset=%#x, sector_size=%#x, len=%#zx\n",
              offset, flash->sector_size, len);
        /* Read the entire sector so to allow for rewriting */
@@ -179,16 +179,14 @@ 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 it's a partial sector, copy the data into the temp-buffer */
        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";
+               memcpy(cmp_buf, buf, len);
+               ptr = cmp_buf;
        }
+       /* Write one complete sector */
+       if (spi_flash_write(flash, offset, flash->sector_size, ptr))
+               return "write";
 
        return NULL;
 }
This page took 0.022899 seconds and 4 git commands to generate.