Commit 2ec1a4059cd0421653b19979a046e9fb7296652f

Authored by Heiko Schocher
Committed by Jagan Teki
1 parent 09c3280754

spi, sf: Use offset and size in sf cmd from mtdpartition

With this patch, it is possible to get the offset and size information
from the mtdpartiton setting in "mtdparts", similiar to the
"nand" commandos.

=> sf
sf - SPI flash sub-system

Usage:
sf probe [[bus:]cs] [hz] [mode] - init flash device on given SPI bus
                                  and chip select
sf read addr offset|partition len       - read `len' bytes starting at
                                          `offset' to memory at `addr'
sf write addr offset|partition len      - write `len' bytes from memory
                                          at `addr' to flash at `offset'
sf erase offset|partition [+]len        - erase `len' bytes from `offset'
                                          `+len' round up `len' to block size
sf update addr offset|partition len     - erase and write `len' bytes from memory
                                          at `addr' to flash at `offset'
=>
for example "env" is defined in mtdparts:

=> sf read 13000000 env
device 0 offset 0xd0000, size 0x10000
SF: 65536 bytes @ 0xd0000 Read: OK

zynq-uboot> mtdparts add nor0 0x10000@0x0 env
zynq-uboot> sf erase env 0x10000
SF: 65536 bytes @ 0x0 Erased: OK

zynq-uboot> sf write 0x100 env
device 0 offset 0x0, size 0x10000
SF: 65536 bytes @ 0x0 Written: OK

zynq-uboot> sf read 0x40000 env
device 0 offset 0x0, size 0x10000
SF: 65536 bytes @ 0x0 Read: OK

Signed-off-by: Heiko Schocher <hs@denx.de>
Tested-by: Jagannadh Teki <jteki@openedev.com>
Reviewed-by: Jagannadh Teki <jteki@openedev.com>

Showing 1 changed file with 29 additions and 25 deletions Side-by-side Diff

... ... @@ -13,6 +13,8 @@
13 13 #include <mapmem.h>
14 14 #include <spi.h>
15 15 #include <spi_flash.h>
  16 +#include <jffs2/jffs2.h>
  17 +#include <linux/mtd/mtd.h>
16 18  
17 19 #include <asm/io.h>
18 20 #include <dm/device-internal.h>
19 21  
20 22  
21 23  
22 24  
... ... @@ -254,24 +256,22 @@
254 256 static int do_spi_flash_read_write(int argc, char * const argv[])
255 257 {
256 258 unsigned long addr;
257   - unsigned long offset;
258   - unsigned long len;
259 259 void *buf;
260 260 char *endp;
261 261 int ret = 1;
  262 + int dev = 0;
  263 + loff_t offset, len, maxsize;
262 264  
263   - if (argc < 4)
  265 + if (argc < 3)
264 266 return -1;
265 267  
266 268 addr = simple_strtoul(argv[1], &endp, 16);
267 269 if (*argv[1] == 0 || *endp != 0)
268 270 return -1;
269   - offset = simple_strtoul(argv[2], &endp, 16);
270   - if (*argv[2] == 0 || *endp != 0)
  271 +
  272 + if (mtd_arg_off_size(argc - 2, &argv[2], &dev, &offset, &len,
  273 + &maxsize, MTD_DEV_TYPE_NOR, flash->size))
271 274 return -1;
272   - len = simple_strtoul(argv[3], &endp, 16);
273   - if (*argv[3] == 0 || *endp != 0)
274   - return -1;
275 275  
276 276 /* Consistency checking */
277 277 if (offset + len > flash->size) {
278 278  
279 279  
280 280  
281 281  
282 282  
... ... @@ -309,31 +309,31 @@
309 309  
310 310 static int do_spi_flash_erase(int argc, char * const argv[])
311 311 {
312   - unsigned long offset;
313   - unsigned long len;
314   - char *endp;
315 312 int ret;
  313 + int dev = 0;
  314 + loff_t offset, len, maxsize;
  315 + ulong size;
316 316  
317 317 if (argc < 3)
318 318 return -1;
319 319  
320   - offset = simple_strtoul(argv[1], &endp, 16);
321   - if (*argv[1] == 0 || *endp != 0)
  320 + if (mtd_arg_off(argv[1], &dev, &offset, &len, &maxsize,
  321 + MTD_DEV_TYPE_NOR, flash->size))
322 322 return -1;
323 323  
324   - ret = sf_parse_len_arg(argv[2], &len);
  324 + ret = sf_parse_len_arg(argv[2], &size);
325 325 if (ret != 1)
326 326 return -1;
327 327  
328 328 /* Consistency checking */
329   - if (offset + len > flash->size) {
  329 + if (offset + size > flash->size) {
330 330 printf("ERROR: attempting %s past flash size (%#x)\n",
331 331 argv[0], flash->size);
332 332 return 1;
333 333 }
334 334  
335   - ret = spi_flash_erase(flash, offset, len);
336   - printf("SF: %zu bytes @ %#x Erased: %s\n", (size_t)len, (u32)offset,
  335 + ret = spi_flash_erase(flash, offset, size);
  336 + printf("SF: %zu bytes @ %#x Erased: %s\n", (size_t)size, (u32)offset,
337 337 ret ? "ERROR" : "OK");
338 338  
339 339 return ret == 0 ? 0 : 1;
... ... @@ -558,14 +558,18 @@
558 558 "SPI flash sub-system",
559 559 "probe [[bus:]cs] [hz] [mode] - init flash device on given SPI bus\n"
560 560 " and chip select\n"
561   - "sf read addr offset len - read `len' bytes starting at\n"
562   - " `offset' to memory at `addr'\n"
563   - "sf write addr offset len - write `len' bytes from memory\n"
564   - " at `addr' to flash at `offset'\n"
565   - "sf erase offset [+]len - erase `len' bytes from `offset'\n"
566   - " `+len' round up `len' to block size\n"
567   - "sf update addr offset len - erase and write `len' bytes from memory\n"
568   - " at `addr' to flash at `offset'"
  561 + "sf read addr offset|partition len - read `len' bytes starting at\n"
  562 + " `offset' or from start of mtd\n"
  563 + " `partition'to memory at `addr'\n"
  564 + "sf write addr offset|partition len - write `len' bytes from memory\n"
  565 + " at `addr' to flash at `offset'\n"
  566 + " or to start of mtd `partition'\n"
  567 + "sf erase offset|partition [+]len - erase `len' bytes from `offset'\n"
  568 + " or from start of mtd `partition'\n"
  569 + " `+len' round up `len' to block size\n"
  570 + "sf update addr offset|partition len - erase and write `len' bytes from memory\n"
  571 + " at `addr' to flash at `offset'\n"
  572 + " or to start of mtd `partition'\n"
569 573 SF_TEST_HELP
570 574 );