For computing proper sector_size the below patch
assigned erase_size which is a proper sector
computation size, so this patch directly used
erasesize instead of assignment.
"sf: Fix to compute proper sector_size"
(sha1: c650ca7b4c160193791dc7a52381c71c6a29e871)

Cc: Simon Glass <s...@chromium.org>
Cc: Bin Meng <bmeng...@gmail.com>
Cc: Mugunthan V N <mugunthan...@ti.com>
Cc: Michal Simek <michal.si...@xilinx.com>
Cc: Siva Durga Prasad Paladugu <siva...@xilinx.com>
Signed-off-by: Jagan Teki <jt...@openedev.com>
---
 cmd/sf.c                    | 20 ++++++++++----------
 drivers/dfu/dfu_sf.c        |  8 ++++----
 drivers/mtd/spi/sf_mtd.c    |  2 +-
 drivers/mtd/spi/spi_flash.c |  3 ---
 4 files changed, 15 insertions(+), 18 deletions(-)

diff --git a/cmd/sf.c b/cmd/sf.c
index 89ab41e..1e0dcb4 100644
--- a/cmd/sf.c
+++ b/cmd/sf.c
@@ -53,8 +53,8 @@ static int sf_parse_len_arg(char *arg, ulong *len)
        if (ep == arg || *ep != '\0')
                return -1;
 
-       if (round_up_len && flash->sector_size > 0)
-               *len = ROUND(len_arg, flash->sector_size);
+       if (round_up_len && flash->erasesize > 0)
+               *len = ROUND(len_arg, flash->erasesize);
        else
                *len = len_arg;
 
@@ -171,10 +171,10 @@ static const char *spi_flash_update_block(struct 
spi_flash *flash, u32 offset,
 {
        char *ptr = (char *)buf;
 
-       debug("offset=%#x, sector_size=%#x, len=%#zx\n",
-             offset, flash->sector_size, len);
+       debug("offset=%#x, erasesize=%#x, len=%#zx\n",
+             offset, flash->erasesize, len);
        /* Read the entire sector so to allow for rewriting */
-       if (spi_flash_read(flash, offset, flash->sector_size, cmp_buf))
+       if (spi_flash_read(flash, offset, flash->erasesize, cmp_buf))
                return "read";
        /* Compare only what is meaningful (len) */
        if (memcmp(cmp_buf, buf, len) == 0) {
@@ -184,15 +184,15 @@ static const char *spi_flash_update_block(struct 
spi_flash *flash, u32 offset,
                return NULL;
        }
        /* Erase the entire sector */
-       if (spi_flash_erase(flash, offset, flash->sector_size))
+       if (spi_flash_erase(flash, offset, flash->erasesize))
                return "erase";
        /* If it's a partial sector, copy the data into the temp-buffer */
-       if (len != flash->sector_size) {
+       if (len != flash->erasesize) {
                memcpy(cmp_buf, buf, len);
                ptr = cmp_buf;
        }
        /* Write one complete sector */
-       if (spi_flash_write(flash, offset, flash->sector_size, ptr))
+       if (spi_flash_write(flash, offset, flash->erasesize, ptr))
                return "write";
 
        return NULL;
@@ -223,12 +223,12 @@ static int spi_flash_update(struct spi_flash *flash, u32 
offset,
 
        if (end - buf >= 200)
                scale = (end - buf) / 100;
-       cmp_buf = memalign(ARCH_DMA_MINALIGN, flash->sector_size);
+       cmp_buf = memalign(ARCH_DMA_MINALIGN, flash->erasesize);
        if (cmp_buf) {
                ulong last_update = get_timer(0);
 
                for (; buf < end && !err_oper; buf += todo, offset += todo) {
-                       todo = min_t(size_t, end - buf, flash->sector_size);
+                       todo = min_t(size_t, end - buf, flash->erasesize);
                        if (get_timer(last_update) > 100) {
                                printf("   \rUpdating, %zu%% %lu B/s",
                                       100 - (end - buf) / scale,
diff --git a/drivers/dfu/dfu_sf.c b/drivers/dfu/dfu_sf.c
index 9702eee..13e7f92 100644
--- a/drivers/dfu/dfu_sf.c
+++ b/drivers/dfu/dfu_sf.c
@@ -25,8 +25,8 @@ static int dfu_read_medium_sf(struct dfu_entity *dfu, u64 
offset, void *buf,
 
 static u64 find_sector(struct dfu_entity *dfu, u64 start, u64 offset)
 {
-       return (lldiv((start + offset), dfu->data.sf.dev->sector_size)) *
-               dfu->data.sf.dev->sector_size;
+       return (lldiv((start + offset), dfu->data.sf.dev->erasesize)) *
+               dfu->data.sf.dev->erasesize;
 }
 
 static int dfu_write_medium_sf(struct dfu_entity *dfu,
@@ -36,7 +36,7 @@ static int dfu_write_medium_sf(struct dfu_entity *dfu,
 
        ret = spi_flash_erase(dfu->data.sf.dev,
                              find_sector(dfu, dfu->data.sf.start, offset),
-                             dfu->data.sf.dev->sector_size);
+                             dfu->data.sf.dev->erasesize);
        if (ret)
                return ret;
 
@@ -123,7 +123,7 @@ int dfu_fill_entity_sf(struct dfu_entity *dfu, char 
*devstr, char *s)
                return -ENODEV;
 
        dfu->dev_type = DFU_DEV_SF;
-       dfu->max_buf_size = dfu->data.sf.dev->sector_size;
+       dfu->max_buf_size = dfu->data.sf.dev->erasesize;
 
        st = strsep(&s, " ");
        if (!strcmp(st, "raw")) {
diff --git a/drivers/mtd/spi/sf_mtd.c b/drivers/mtd/spi/sf_mtd.c
index 0b9cb62..9a8302d 100644
--- a/drivers/mtd/spi/sf_mtd.c
+++ b/drivers/mtd/spi/sf_mtd.c
@@ -93,7 +93,7 @@ int spi_flash_mtd_register(struct spi_flash *flash)
 
        /* Only uniform flash devices for now */
        sf_mtd_info.numeraseregions = 0;
-       sf_mtd_info.erasesize = flash->sector_size;
+       sf_mtd_info.erasesize = flash->erasesize;
 
        return add_mtd_device(&sf_mtd_info);
 }
diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c
index dfadb77..4614c9c 100644
--- a/drivers/mtd/spi/spi_flash.c
+++ b/drivers/mtd/spi/spi_flash.c
@@ -1100,9 +1100,6 @@ int spi_flash_scan(struct spi_flash *flash)
                flash->erasesize = flash->sector_size;
        }
 
-       /* Now erase size becomes valid sector size */
-       flash->sector_size = flash->erasesize;
-
        /* Look for the fastest read cmd */
        cmd = fls(params->e_rd_cmd & spi->mode_rx);
        if (cmd) {
-- 
1.9.1

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to