This patch provides a support to add a write instruction(wr_inst)
argument to 'sf update' command.

User will dynamically use the specific write instruction while
programming the flash using 'sf update' command.
Currently added an existing write instruction called pp(Page Program).

Example:
erase and write 0x2000 length bytes from memory at 0x10000 address to
flash offset at 0x0 using pp write instruction.
u-boot> sf update pp 0x10000 0x0 0x2000

Signed-off-by: Jagannadha Sutradharudu Teki <jagannadh.t...@gmail.com>
---
 common/cmd_sf.c |   37 ++++++++++++++++++++++++++-----------
 1 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/common/cmd_sf.c b/common/cmd_sf.c
index 88b18f8..0f4e440 100644
--- a/common/cmd_sf.c
+++ b/common/cmd_sf.c
@@ -141,6 +141,7 @@ static int do_spi_flash_probe(int argc, char * const argv[])
  * If the data being written is the same, then *skipped is incremented by len.
  *
  * @param flash                flash context pointer
+ * @param wr_inst      write instruction
  * @param offset       flash offset to write
  * @param len          number of bytes to write
  * @param buf          buffer to write from
@@ -148,8 +149,9 @@ static int do_spi_flash_probe(int argc, char * const argv[])
  * @param skipped      Count of skipped data (incremented by this function)
  * @return NULL if OK, else a string containing the stage which failed
  */
-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)
+static const char *spi_flash_update_block(struct spi_flash *flash, u8 wr_inst,
+               u32 offset, size_t len, const char *buf, char *cmp_buf,
+               size_t *skipped)
 {
        debug("offset=%#x, sector_size=%#x, len=%#zx\n",
                offset, flash->sector_size, len);
@@ -163,7 +165,7 @@ static const char *spi_flash_update_block(struct spi_flash 
*flash, u32 offset,
        }
        if (spi_flash_erase(flash, offset, len))
                return "erase";
-       if (spi_flash_write(flash, offset, len, buf))
+       if (spi_flash_write(flash, wr_inst, offset, len, buf))
                return "write";
        return NULL;
 }
@@ -173,12 +175,13 @@ static const char *spi_flash_update_block(struct 
spi_flash *flash, u32 offset,
  * to change. Existing blocks with the correct data are left unchanged.
  *
  * @param flash                flash context pointer
+ * @param wr_inst      write instruction
  * @param offset       flash offset to write
  * @param len          number of bytes to write
  * @param buf          buffer to write from
  * @return 0 if ok, 1 on error
  */
-static int spi_flash_update(struct spi_flash *flash, u32 offset,
+static int spi_flash_update(struct spi_flash *flash, u8 wr_inst, u32 offset,
                size_t len, const char *buf)
 {
        const char *err_oper = NULL;
@@ -206,8 +209,9 @@ static int spi_flash_update(struct spi_flash *flash, u32 
offset,
                                                         start_time));
                                last_update = get_timer(0);
                        }
-                       err_oper = spi_flash_update_block(flash, offset, todo,
-                                       buf, cmp_buf, &skipped);
+                       err_oper = spi_flash_update_block(flash, wr_inst,
+                                       offset, todo, buf, cmp_buf,
+                                       &skipped);
                }
        } else {
                err_oper = "malloc";
@@ -264,9 +268,17 @@ static int do_spi_flash_read_write(int argc, char * const 
argv[])
                return 1;
        }
 
-       if (strcmp(argv[0], "update") == 0)
-               ret = spi_flash_update(flash, offset, len, buf);
-       else if (strcmp(argv[0], "read") == 0) {
+       if (strcmp(argv[0], "update") == 0) {
+               if (strcmp(argv[1], "pp") == 0)
+                       wr_inst = CMD_PAGE_PROGRAM;
+               else {
+                       printf("SF: Unknown %s wr_inst on 'sf update'\n",
+                                       argv[1]);
+                       return 1;
+               }
+
+               ret = spi_flash_update(flash, wr_inst, offset, len, buf);
+       } else if (strcmp(argv[0], "read") == 0) {
                if (strcmp(argv[1], "afr") == 0)
                        rd_inst = CMD_READ_ARRAY_FAST;
                else {
@@ -555,7 +567,10 @@ U_BOOT_CMD(
        "                                 pp (Page Program, 02h)\n"
        "sf erase offset [+]len         - erase `len' bytes from `offset'\n"
        "                                 `+len' round up `len' to block size\n"
-       "sf update addr offset len      - erase and write `len' bytes from 
memory\n"
-       "                                 at `addr' to flash at `offset'"
+       "sf update wr_inst addr offset len\n"
+       "                               - erase and write `len' bytes from 
memory\n"
+       "                                 at `addr' to flash at `offset' 
using\n"
+       "                                 pp `wr_inst' write instruction\n"
+       "                                 pp (Page Program, 02h)"
        SF_TEST_HELP
 );
-- 
1.7.0.4

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

Reply via email to