blob: 4af0f0af26bcfa3afbc63708fb019a89cc99d274 [file] [log] [blame]
Haavard Skinnemoenb6368462008-05-16 11:10:34 +02001/*
2 * Command for accessing SPI flash.
3 *
4 * Copyright (C) 2008 Atmel Corporation
Mike Frysinger4166ee52009-10-09 17:12:44 -04005 * Licensed under the GPL-2 or later.
Haavard Skinnemoenb6368462008-05-16 11:10:34 +02006 */
Mike Frysinger4166ee52009-10-09 17:12:44 -04007
Haavard Skinnemoenb6368462008-05-16 11:10:34 +02008#include <common.h>
Mingkai Hu381c6e22013-04-07 22:13:32 +00009#include <div64.h>
Simon Glass8d1af942011-08-22 16:03:46 -070010#include <malloc.h>
Haavard Skinnemoenb6368462008-05-16 11:10:34 +020011#include <spi_flash.h>
12
13#include <asm/io.h>
14
15#ifndef CONFIG_SF_DEFAULT_SPEED
16# define CONFIG_SF_DEFAULT_SPEED 1000000
17#endif
18#ifndef CONFIG_SF_DEFAULT_MODE
19# define CONFIG_SF_DEFAULT_MODE SPI_MODE_3
20#endif
Eric Nelsonc1173bd2012-01-31 10:52:07 -070021#ifndef CONFIG_SF_DEFAULT_CS
22# define CONFIG_SF_DEFAULT_CS 0
23#endif
24#ifndef CONFIG_SF_DEFAULT_BUS
25# define CONFIG_SF_DEFAULT_BUS 0
26#endif
Haavard Skinnemoenb6368462008-05-16 11:10:34 +020027
28static struct spi_flash *flash;
29
Richard Retanubun334eb4b2011-02-16 16:39:44 -050030
31/*
32 * This function computes the length argument for the erase command.
33 * The length on which the command is to operate can be given in two forms:
34 * 1. <cmd> offset len - operate on <'offset', 'len')
35 * 2. <cmd> offset +len - operate on <'offset', 'round_up(len)')
36 * If the second form is used and the length doesn't fall on the
37 * sector boundary, than it will be adjusted to the next sector boundary.
38 * If it isn't in the flash, the function will fail (return -1).
39 * Input:
40 * arg: length specification (i.e. both command arguments)
41 * Output:
42 * len: computed length for operation
43 * Return:
44 * 1: success
45 * -1: failure (bad format, bad address).
46 */
47static int sf_parse_len_arg(char *arg, ulong *len)
48{
49 char *ep;
50 char round_up_len; /* indicates if the "+length" form used */
51 ulong len_arg;
52
53 round_up_len = 0;
54 if (*arg == '+') {
55 round_up_len = 1;
56 ++arg;
57 }
58
59 len_arg = simple_strtoul(arg, &ep, 16);
60 if (ep == arg || *ep != '\0')
61 return -1;
62
63 if (round_up_len && flash->sector_size > 0)
Anton Staaf155cfb52011-09-02 13:45:28 +000064 *len = ROUND(len_arg, flash->sector_size);
Richard Retanubun334eb4b2011-02-16 16:39:44 -050065 else
66 *len = len_arg;
67
68 return 1;
69}
70
James Millera683c282012-09-28 14:28:00 +000071/**
72 * This function takes a byte length and a delta unit of time to compute the
73 * approximate bytes per second
74 *
75 * @param len amount of bytes currently processed
76 * @param start_ms start time of processing in ms
77 * @return bytes per second if OK, 0 on error
78 */
79static ulong bytes_per_second(unsigned int len, ulong start_ms)
80{
81 /* less accurate but avoids overflow */
82 if (len >= ((unsigned int) -1) / 1024)
83 return len / (max(get_timer(start_ms) / 1024, 1));
84 else
85 return 1024 * len / max(get_timer(start_ms), 1);
86}
87
Wolfgang Denk54841ab2010-06-28 22:00:46 +020088static int do_spi_flash_probe(int argc, char * const argv[])
Haavard Skinnemoenb6368462008-05-16 11:10:34 +020089{
Eric Nelsonc1173bd2012-01-31 10:52:07 -070090 unsigned int bus = CONFIG_SF_DEFAULT_BUS;
91 unsigned int cs = CONFIG_SF_DEFAULT_CS;
Haavard Skinnemoenb6368462008-05-16 11:10:34 +020092 unsigned int speed = CONFIG_SF_DEFAULT_SPEED;
93 unsigned int mode = CONFIG_SF_DEFAULT_MODE;
94 char *endp;
95 struct spi_flash *new;
96
Eric Nelsonc1173bd2012-01-31 10:52:07 -070097 if (argc >= 2) {
98 cs = simple_strtoul(argv[1], &endp, 0);
99 if (*argv[1] == 0 || (*endp != 0 && *endp != ':'))
Mike Frysinger8a07de02011-04-12 02:21:31 -0400100 return -1;
Eric Nelsonc1173bd2012-01-31 10:52:07 -0700101 if (*endp == ':') {
102 if (endp[1] == 0)
103 return -1;
Haavard Skinnemoenb6368462008-05-16 11:10:34 +0200104
Eric Nelsonc1173bd2012-01-31 10:52:07 -0700105 bus = cs;
106 cs = simple_strtoul(endp + 1, &endp, 0);
107 if (*endp != 0)
108 return -1;
109 }
Haavard Skinnemoenb6368462008-05-16 11:10:34 +0200110 }
111
112 if (argc >= 3) {
113 speed = simple_strtoul(argv[2], &endp, 0);
114 if (*argv[2] == 0 || *endp != 0)
Mike Frysinger8a07de02011-04-12 02:21:31 -0400115 return -1;
Haavard Skinnemoenb6368462008-05-16 11:10:34 +0200116 }
117 if (argc >= 4) {
TsiChung Liew6e8d58d2009-06-30 14:30:19 +0000118 mode = simple_strtoul(argv[3], &endp, 16);
Haavard Skinnemoenb6368462008-05-16 11:10:34 +0200119 if (*argv[3] == 0 || *endp != 0)
Mike Frysinger8a07de02011-04-12 02:21:31 -0400120 return -1;
Haavard Skinnemoenb6368462008-05-16 11:10:34 +0200121 }
122
123 new = spi_flash_probe(bus, cs, speed, mode);
124 if (!new) {
125 printf("Failed to initialize SPI flash at %u:%u\n", bus, cs);
126 return 1;
127 }
128
129 if (flash)
130 spi_flash_free(flash);
131 flash = new;
132
Haavard Skinnemoenb6368462008-05-16 11:10:34 +0200133 return 0;
Haavard Skinnemoenb6368462008-05-16 11:10:34 +0200134}
135
Simon Glass8d1af942011-08-22 16:03:46 -0700136/**
137 * Write a block of data to SPI flash, first checking if it is different from
138 * what is already there.
139 *
140 * If the data being written is the same, then *skipped is incremented by len.
141 *
142 * @param flash flash context pointer
143 * @param offset flash offset to write
144 * @param len number of bytes to write
145 * @param buf buffer to write from
146 * @param cmp_buf read buffer to use to compare data
147 * @param skipped Count of skipped data (incremented by this function)
148 * @return NULL if OK, else a string containing the stage which failed
149 */
150static const char *spi_flash_update_block(struct spi_flash *flash, u32 offset,
151 size_t len, const char *buf, char *cmp_buf, size_t *skipped)
152{
Andreas Bießmanna97f6ef2011-12-15 09:56:53 +0100153 debug("offset=%#x, sector_size=%#x, len=%#zx\n",
Jagannadha Sutradharudu Teki402ba1e2013-07-29 22:12:52 +0530154 offset, flash->sector_size, len);
Simon Glass8d1af942011-08-22 16:03:46 -0700155 if (spi_flash_read(flash, offset, len, cmp_buf))
156 return "read";
157 if (memcmp(cmp_buf, buf, len) == 0) {
Andreas Bießmanna97f6ef2011-12-15 09:56:53 +0100158 debug("Skip region %x size %zx: no change\n",
Jagannadha Sutradharudu Teki402ba1e2013-07-29 22:12:52 +0530159 offset, len);
Simon Glass8d1af942011-08-22 16:03:46 -0700160 *skipped += len;
161 return NULL;
162 }
Gerlando Falauto34888502013-07-03 20:33:57 +0200163 /* Erase the entire sector */
164 if (spi_flash_erase(flash, offset, flash->sector_size))
Simon Glass8d1af942011-08-22 16:03:46 -0700165 return "erase";
166 if (spi_flash_write(flash, offset, len, buf))
167 return "write";
168 return NULL;
169}
170
171/**
172 * Update an area of SPI flash by erasing and writing any blocks which need
173 * to change. Existing blocks with the correct data are left unchanged.
174 *
175 * @param flash flash context pointer
176 * @param offset flash offset to write
177 * @param len number of bytes to write
178 * @param buf buffer to write from
179 * @return 0 if ok, 1 on error
180 */
181static int spi_flash_update(struct spi_flash *flash, u32 offset,
182 size_t len, const char *buf)
183{
184 const char *err_oper = NULL;
185 char *cmp_buf;
186 const char *end = buf + len;
187 size_t todo; /* number of bytes to do in this pass */
Kumar Gala8e8a4bc2011-10-03 04:35:47 +0000188 size_t skipped = 0; /* statistics */
James Millera683c282012-09-28 14:28:00 +0000189 const ulong start_time = get_timer(0);
190 size_t scale = 1;
191 const char *start_buf = buf;
192 ulong delta;
Simon Glass8d1af942011-08-22 16:03:46 -0700193
James Millera683c282012-09-28 14:28:00 +0000194 if (end - buf >= 200)
195 scale = (end - buf) / 100;
Simon Glass8d1af942011-08-22 16:03:46 -0700196 cmp_buf = malloc(flash->sector_size);
197 if (cmp_buf) {
James Millera683c282012-09-28 14:28:00 +0000198 ulong last_update = get_timer(0);
199
Kumar Gala8e8a4bc2011-10-03 04:35:47 +0000200 for (; buf < end && !err_oper; buf += todo, offset += todo) {
Simon Glass8d1af942011-08-22 16:03:46 -0700201 todo = min(end - buf, flash->sector_size);
James Millera683c282012-09-28 14:28:00 +0000202 if (get_timer(last_update) > 100) {
203 printf(" \rUpdating, %zu%% %lu B/s",
Jagannadha Sutradharudu Teki402ba1e2013-07-29 22:12:52 +0530204 100 - (end - buf) / scale,
James Millera683c282012-09-28 14:28:00 +0000205 bytes_per_second(buf - start_buf,
206 start_time));
207 last_update = get_timer(0);
208 }
Simon Glass8d1af942011-08-22 16:03:46 -0700209 err_oper = spi_flash_update_block(flash, offset, todo,
210 buf, cmp_buf, &skipped);
211 }
212 } else {
213 err_oper = "malloc";
214 }
215 free(cmp_buf);
James Millera683c282012-09-28 14:28:00 +0000216 putc('\r');
Simon Glass8d1af942011-08-22 16:03:46 -0700217 if (err_oper) {
218 printf("SPI flash failed in %s step\n", err_oper);
219 return 1;
220 }
James Millera683c282012-09-28 14:28:00 +0000221
222 delta = get_timer(start_time);
223 printf("%zu bytes written, %zu bytes skipped", len - skipped,
Jagannadha Sutradharudu Teki402ba1e2013-07-29 22:12:52 +0530224 skipped);
James Millera683c282012-09-28 14:28:00 +0000225 printf(" in %ld.%lds, speed %ld B/s\n",
Jagannadha Sutradharudu Teki402ba1e2013-07-29 22:12:52 +0530226 delta / 1000, delta % 1000, bytes_per_second(len, start_time));
Kumar Gala8e8a4bc2011-10-03 04:35:47 +0000227
Simon Glass8d1af942011-08-22 16:03:46 -0700228 return 0;
229}
230
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200231static int do_spi_flash_read_write(int argc, char * const argv[])
Haavard Skinnemoenb6368462008-05-16 11:10:34 +0200232{
233 unsigned long addr;
234 unsigned long offset;
235 unsigned long len;
236 void *buf;
237 char *endp;
Jagannadha Sutradharudu Teki60b66142013-05-26 14:52:52 +0530238 int ret = 1;
Haavard Skinnemoenb6368462008-05-16 11:10:34 +0200239
240 if (argc < 4)
Mike Frysinger8a07de02011-04-12 02:21:31 -0400241 return -1;
Haavard Skinnemoenb6368462008-05-16 11:10:34 +0200242
243 addr = simple_strtoul(argv[1], &endp, 16);
244 if (*argv[1] == 0 || *endp != 0)
Mike Frysinger8a07de02011-04-12 02:21:31 -0400245 return -1;
Haavard Skinnemoenb6368462008-05-16 11:10:34 +0200246 offset = simple_strtoul(argv[2], &endp, 16);
247 if (*argv[2] == 0 || *endp != 0)
Mike Frysinger8a07de02011-04-12 02:21:31 -0400248 return -1;
Haavard Skinnemoenb6368462008-05-16 11:10:34 +0200249 len = simple_strtoul(argv[3], &endp, 16);
250 if (*argv[3] == 0 || *endp != 0)
Mike Frysinger8a07de02011-04-12 02:21:31 -0400251 return -1;
Haavard Skinnemoenb6368462008-05-16 11:10:34 +0200252
Gerlando Falauto86493992012-04-03 04:34:13 +0000253 /* Consistency checking */
254 if (offset + len > flash->size) {
255 printf("ERROR: attempting %s past flash size (%#x)\n",
Jagannadha Sutradharudu Teki402ba1e2013-07-29 22:12:52 +0530256 argv[0], flash->size);
Gerlando Falauto86493992012-04-03 04:34:13 +0000257 return 1;
258 }
259
Haavard Skinnemoenb6368462008-05-16 11:10:34 +0200260 buf = map_physmem(addr, len, MAP_WRBACK);
261 if (!buf) {
262 puts("Failed to map physical memory\n");
263 return 1;
264 }
265
Jagannadha Sutradharudu Teki402ba1e2013-07-29 22:12:52 +0530266 if (strcmp(argv[0], "update") == 0) {
Simon Glass8d1af942011-08-22 16:03:46 -0700267 ret = spi_flash_update(flash, offset, len, buf);
Jagannadha Sutradharudu Teki402ba1e2013-07-29 22:12:52 +0530268 } else if (strncmp(argv[0], "read", 4) == 0 ||
Jagannadha Sutradharudu Teki60b66142013-05-26 14:52:52 +0530269 strncmp(argv[0], "write", 5) == 0) {
270 int read;
271
272 read = strncmp(argv[0], "read", 4) == 0;
273 if (read)
274 ret = spi_flash_read(flash, offset, len, buf);
275 else
276 ret = spi_flash_write(flash, offset, len, buf);
277
278 printf("SF: %zu bytes @ %#x %s: %s\n", (size_t)len, (u32)offset,
Jagannadha Sutradharudu Teki402ba1e2013-07-29 22:12:52 +0530279 read ? "Read" : "Written", ret ? "ERROR" : "OK");
Jagannadha Sutradharudu Teki60b66142013-05-26 14:52:52 +0530280 }
Haavard Skinnemoenb6368462008-05-16 11:10:34 +0200281
282 unmap_physmem(buf, len);
283
Jagannadha Sutradharudu Teki60b66142013-05-26 14:52:52 +0530284 return ret == 0 ? 0 : 1;
Haavard Skinnemoenb6368462008-05-16 11:10:34 +0200285}
286
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200287static int do_spi_flash_erase(int argc, char * const argv[])
Haavard Skinnemoenb6368462008-05-16 11:10:34 +0200288{
289 unsigned long offset;
290 unsigned long len;
291 char *endp;
292 int ret;
293
294 if (argc < 3)
Mike Frysinger8a07de02011-04-12 02:21:31 -0400295 return -1;
Haavard Skinnemoenb6368462008-05-16 11:10:34 +0200296
297 offset = simple_strtoul(argv[1], &endp, 16);
298 if (*argv[1] == 0 || *endp != 0)
Mike Frysinger8a07de02011-04-12 02:21:31 -0400299 return -1;
Richard Retanubun334eb4b2011-02-16 16:39:44 -0500300
301 ret = sf_parse_len_arg(argv[2], &len);
302 if (ret != 1)
Mike Frysinger8a07de02011-04-12 02:21:31 -0400303 return -1;
Haavard Skinnemoenb6368462008-05-16 11:10:34 +0200304
Gerlando Falauto86493992012-04-03 04:34:13 +0000305 /* Consistency checking */
306 if (offset + len > flash->size) {
307 printf("ERROR: attempting %s past flash size (%#x)\n",
Jagannadha Sutradharudu Teki402ba1e2013-07-29 22:12:52 +0530308 argv[0], flash->size);
Gerlando Falauto86493992012-04-03 04:34:13 +0000309 return 1;
310 }
311
Haavard Skinnemoenb6368462008-05-16 11:10:34 +0200312 ret = spi_flash_erase(flash, offset, len);
Jagannadha Sutradharudu Teki96bbf552013-05-26 01:35:21 +0530313 printf("SF: %zu bytes @ %#x Erased: %s\n", (size_t)len, (u32)offset,
Jagannadha Sutradharudu Teki402ba1e2013-07-29 22:12:52 +0530314 ret ? "ERROR" : "OK");
Haavard Skinnemoenb6368462008-05-16 11:10:34 +0200315
Jagannadha Sutradharudu Teki96bbf552013-05-26 01:35:21 +0530316 return ret == 0 ? 0 : 1;
Haavard Skinnemoenb6368462008-05-16 11:10:34 +0200317}
318
Simon Glass24007272012-10-08 13:16:02 +0000319#ifdef CONFIG_CMD_SF_TEST
320enum {
321 STAGE_ERASE,
322 STAGE_CHECK,
323 STAGE_WRITE,
324 STAGE_READ,
325
326 STAGE_COUNT,
327};
328
329static char *stage_name[STAGE_COUNT] = {
330 "erase",
331 "check",
332 "write",
333 "read",
334};
335
336struct test_info {
337 int stage;
338 int bytes;
339 unsigned base_ms;
340 unsigned time_ms[STAGE_COUNT];
341};
342
343static void show_time(struct test_info *test, int stage)
344{
345 uint64_t speed; /* KiB/s */
346 int bps; /* Bits per second */
347
348 speed = (long long)test->bytes * 1000;
349 do_div(speed, test->time_ms[stage] * 1024);
350 bps = speed * 8;
351
352 printf("%d %s: %d ticks, %d KiB/s %d.%03d Mbps\n", stage,
353 stage_name[stage], test->time_ms[stage],
354 (int)speed, bps / 1000, bps % 1000);
355}
356
357static void spi_test_next_stage(struct test_info *test)
358{
359 test->time_ms[test->stage] = get_timer(test->base_ms);
360 show_time(test, test->stage);
361 test->base_ms = get_timer(0);
362 test->stage++;
363}
364
365/**
366 * Run a test on the SPI flash
367 *
368 * @param flash SPI flash to use
369 * @param buf Source buffer for data to write
370 * @param len Size of data to read/write
371 * @param offset Offset within flash to check
372 * @param vbuf Verification buffer
373 * @return 0 if ok, -1 on error
374 */
Simon Glass1e7133e2013-03-11 06:08:13 +0000375static int spi_flash_test(struct spi_flash *flash, uint8_t *buf, ulong len,
376 ulong offset, uint8_t *vbuf)
Simon Glass24007272012-10-08 13:16:02 +0000377{
378 struct test_info test;
379 int i;
380
381 printf("SPI flash test:\n");
382 memset(&test, '\0', sizeof(test));
383 test.base_ms = get_timer(0);
384 test.bytes = len;
385 if (spi_flash_erase(flash, offset, len)) {
386 printf("Erase failed\n");
387 return -1;
388 }
389 spi_test_next_stage(&test);
390
391 if (spi_flash_read(flash, offset, len, vbuf)) {
392 printf("Check read failed\n");
393 return -1;
394 }
395 for (i = 0; i < len; i++) {
396 if (vbuf[i] != 0xff) {
397 printf("Check failed at %d\n", i);
398 print_buffer(i, vbuf + i, 1, min(len - i, 0x40), 0);
399 return -1;
400 }
401 }
402 spi_test_next_stage(&test);
403
404 if (spi_flash_write(flash, offset, len, buf)) {
405 printf("Write failed\n");
406 return -1;
407 }
408 memset(vbuf, '\0', len);
409 spi_test_next_stage(&test);
410
411 if (spi_flash_read(flash, offset, len, vbuf)) {
412 printf("Read failed\n");
413 return -1;
414 }
415 spi_test_next_stage(&test);
416
417 for (i = 0; i < len; i++) {
418 if (buf[i] != vbuf[i]) {
419 printf("Verify failed at %d, good data:\n", i);
420 print_buffer(i, buf + i, 1, min(len - i, 0x40), 0);
421 printf("Bad data:\n");
422 print_buffer(i, vbuf + i, 1, min(len - i, 0x40), 0);
423 return -1;
424 }
425 }
426 printf("Test passed\n");
427 for (i = 0; i < STAGE_COUNT; i++)
428 show_time(&test, i);
429
430 return 0;
431}
432
433static int do_spi_flash_test(int argc, char * const argv[])
434{
435 unsigned long offset;
436 unsigned long len;
Simon Glass1e7133e2013-03-11 06:08:13 +0000437 uint8_t *buf = (uint8_t *)CONFIG_SYS_TEXT_BASE;
Simon Glass24007272012-10-08 13:16:02 +0000438 char *endp;
Simon Glass1e7133e2013-03-11 06:08:13 +0000439 uint8_t *vbuf;
Simon Glass24007272012-10-08 13:16:02 +0000440 int ret;
441
442 offset = simple_strtoul(argv[1], &endp, 16);
443 if (*argv[1] == 0 || *endp != 0)
444 return -1;
445 len = simple_strtoul(argv[2], &endp, 16);
446 if (*argv[2] == 0 || *endp != 0)
447 return -1;
448
449 vbuf = malloc(len);
450 if (!vbuf) {
451 printf("Cannot allocate memory\n");
452 return 1;
453 }
454 buf = malloc(len);
455 if (!buf) {
456 free(vbuf);
457 printf("Cannot allocate memory\n");
458 return 1;
459 }
460
461 memcpy(buf, (char *)CONFIG_SYS_TEXT_BASE, len);
462 ret = spi_flash_test(flash, buf, len, offset, vbuf);
463 free(vbuf);
464 free(buf);
465 if (ret) {
466 printf("Test failed\n");
467 return 1;
468 }
469
470 return 0;
471}
472#endif /* CONFIG_CMD_SF_TEST */
473
Jagannadha Sutradharudu Teki402ba1e2013-07-29 22:12:52 +0530474static int do_spi_flash(cmd_tbl_t *cmdtp, int flag, int argc,
475 char * const argv[])
Haavard Skinnemoenb6368462008-05-16 11:10:34 +0200476{
477 const char *cmd;
Mike Frysinger8a07de02011-04-12 02:21:31 -0400478 int ret;
Haavard Skinnemoenb6368462008-05-16 11:10:34 +0200479
480 /* need at least two arguments */
481 if (argc < 2)
482 goto usage;
483
484 cmd = argv[1];
Mike Frysinger8a07de02011-04-12 02:21:31 -0400485 --argc;
486 ++argv;
Haavard Skinnemoenb6368462008-05-16 11:10:34 +0200487
Mike Frysinger8a07de02011-04-12 02:21:31 -0400488 if (strcmp(cmd, "probe") == 0) {
489 ret = do_spi_flash_probe(argc, argv);
490 goto done;
491 }
Haavard Skinnemoenb6368462008-05-16 11:10:34 +0200492
493 /* The remaining commands require a selected device */
494 if (!flash) {
495 puts("No SPI flash selected. Please run `sf probe'\n");
496 return 1;
497 }
498
Simon Glass8d1af942011-08-22 16:03:46 -0700499 if (strcmp(cmd, "read") == 0 || strcmp(cmd, "write") == 0 ||
500 strcmp(cmd, "update") == 0)
Mike Frysinger8a07de02011-04-12 02:21:31 -0400501 ret = do_spi_flash_read_write(argc, argv);
502 else if (strcmp(cmd, "erase") == 0)
503 ret = do_spi_flash_erase(argc, argv);
Simon Glass24007272012-10-08 13:16:02 +0000504#ifdef CONFIG_CMD_SF_TEST
505 else if (!strcmp(cmd, "test"))
506 ret = do_spi_flash_test(argc, argv);
507#endif
Mike Frysinger8a07de02011-04-12 02:21:31 -0400508 else
509 ret = -1;
510
511done:
512 if (ret != -1)
513 return ret;
Haavard Skinnemoenb6368462008-05-16 11:10:34 +0200514
515usage:
Simon Glass4c12eeb2011-12-10 08:44:01 +0000516 return CMD_RET_USAGE;
Haavard Skinnemoenb6368462008-05-16 11:10:34 +0200517}
518
Simon Glass24007272012-10-08 13:16:02 +0000519#ifdef CONFIG_CMD_SF_TEST
520#define SF_TEST_HELP "\nsf test offset len " \
521 "- run a very basic destructive test"
522#else
523#define SF_TEST_HELP
524#endif
525
Haavard Skinnemoenb6368462008-05-16 11:10:34 +0200526U_BOOT_CMD(
527 sf, 5, 1, do_spi_flash,
Peter Tyser2fb26042009-01-27 18:03:12 -0600528 "SPI flash sub-system",
Eric Nelsonc1173bd2012-01-31 10:52:07 -0700529 "probe [[bus:]cs] [hz] [mode] - init flash device on given SPI bus\n"
Haavard Skinnemoenb6368462008-05-16 11:10:34 +0200530 " and chip select\n"
Jagannadha Sutradharudu Teki402ba1e2013-07-29 22:12:52 +0530531 "sf read addr offset len - read `len' bytes starting at\n"
Haavard Skinnemoenb6368462008-05-16 11:10:34 +0200532 " `offset' to memory at `addr'\n"
533 "sf write addr offset len - write `len' bytes from memory\n"
534 " at `addr' to flash at `offset'\n"
Richard Retanubun334eb4b2011-02-16 16:39:44 -0500535 "sf erase offset [+]len - erase `len' bytes from `offset'\n"
Simon Glass8d1af942011-08-22 16:03:46 -0700536 " `+len' round up `len' to block size\n"
537 "sf update addr offset len - erase and write `len' bytes from memory\n"
538 " at `addr' to flash at `offset'"
Simon Glass24007272012-10-08 13:16:02 +0000539 SF_TEST_HELP
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200540);