blob: ccf420a13279de51d215c487d11ae169bd12a3db [file] [log] [blame]
wdenk38635852002-08-27 05:55:31 +00001/*
2 * (C) Copyright 2000
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24/*
25 * Memory Functions
26 *
27 * Copied from FADS ROM, Dan Malek (dmalek@jlc.net)
28 */
29
30#include <common.h>
31#include <command.h>
wdenk381669a2003-06-16 23:50:08 +000032#ifdef CONFIG_HAS_DATAFLASH
33#include <dataflash.h>
34#endif
Sergei Poselenov474dbb82008-04-09 16:09:41 +020035#include <watchdog.h>
wdenk38635852002-08-27 05:55:31 +000036
Robin Getz93d6cb02009-07-27 00:07:59 -040037#include <u-boot/md5.h>
38#include <sha1.h>
39
wdenk38635852002-08-27 05:55:31 +000040#ifdef CMD_MEM_DEBUG
41#define PRINTF(fmt,args...) printf (fmt ,##args)
42#else
43#define PRINTF(fmt,args...)
44#endif
45
Wolfgang Denk6262d0212010-06-28 22:00:46 +020046static int mod_mem(cmd_tbl_t *, int, int, int, char * const []);
wdenk38635852002-08-27 05:55:31 +000047
48/* Display values from last command.
49 * Memory modify remembered values are different from display memory.
50 */
Mike Frysinger1a4af8c2010-12-22 09:40:29 -050051static uint dp_last_addr, dp_last_size;
52static uint dp_last_length = 0x40;
53static uint mm_last_addr, mm_last_size;
wdenk38635852002-08-27 05:55:31 +000054
55static ulong base_address = 0;
56
57/* Memory Display
58 *
59 * Syntax:
60 * md{.b, .w, .l} {addr} {len}
61 */
62#define DISP_LINE_LEN 16
Wolfgang Denk6262d0212010-06-28 22:00:46 +020063int do_mem_md ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +000064{
wdenk874ac262003-07-24 23:38:38 +000065 ulong addr, length;
Grant Likely02a00782007-02-20 09:05:00 +010066#if defined(CONFIG_HAS_DATAFLASH)
67 ulong nbytes, linebytes;
68#endif
wdenk874ac262003-07-24 23:38:38 +000069 int size;
wdenk38635852002-08-27 05:55:31 +000070 int rc = 0;
71
72 /* We use the last specified parameters, unless new ones are
73 * entered.
74 */
75 addr = dp_last_addr;
76 size = dp_last_size;
77 length = dp_last_length;
78
Wolfgang Denk3b683112010-07-17 01:06:04 +020079 if (argc < 2)
80 return cmd_usage(cmdtp);
wdenk38635852002-08-27 05:55:31 +000081
82 if ((flag & CMD_FLAG_REPEAT) == 0) {
83 /* New command specified. Check for a size specification.
84 * Defaults to long if no or incorrect specification.
85 */
wdenk874ac262003-07-24 23:38:38 +000086 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
87 return 1;
wdenk38635852002-08-27 05:55:31 +000088
89 /* Address is specified since argc > 1
90 */
91 addr = simple_strtoul(argv[1], NULL, 16);
92 addr += base_address;
93
94 /* If another parameter, it is the length to display.
95 * Length is the number of objects, not number of bytes.
96 */
97 if (argc > 2)
98 length = simple_strtoul(argv[2], NULL, 16);
99 }
100
Grant Likely02a00782007-02-20 09:05:00 +0100101#if defined(CONFIG_HAS_DATAFLASH)
wdenk38635852002-08-27 05:55:31 +0000102 /* Print the lines.
103 *
104 * We buffer all read data, so we can make sure data is read only
105 * once, and all accesses are with the specified bus width.
106 */
107 nbytes = length * size;
108 do {
109 char linebuf[DISP_LINE_LEN];
Grant Likely02a00782007-02-20 09:05:00 +0100110 void* p;
wdenk38635852002-08-27 05:55:31 +0000111 linebytes = (nbytes>DISP_LINE_LEN)?DISP_LINE_LEN:nbytes;
wdenk381669a2003-06-16 23:50:08 +0000112
Grant Likely02a00782007-02-20 09:05:00 +0100113 rc = read_dataflash(addr, (linebytes/size)*size, linebuf);
114 p = (rc == DATAFLASH_OK) ? linebuf : (void*)addr;
115 print_buffer(addr, p, size, linebytes/size, DISP_LINE_LEN/size);
wdenk57b2d802003-06-27 21:31:46 +0000116
wdenk38635852002-08-27 05:55:31 +0000117 nbytes -= linebytes;
Grant Likely02a00782007-02-20 09:05:00 +0100118 addr += linebytes;
wdenk38635852002-08-27 05:55:31 +0000119 if (ctrlc()) {
120 rc = 1;
121 break;
122 }
123 } while (nbytes > 0);
Grant Likely02a00782007-02-20 09:05:00 +0100124#else
Mike Frysingere578d682008-02-04 19:26:56 -0500125
126# if defined(CONFIG_BLACKFIN)
127 /* See if we're trying to display L1 inst */
128 if (addr_bfin_on_chip_mem(addr)) {
129 char linebuf[DISP_LINE_LEN];
130 ulong linebytes, nbytes = length * size;
131 do {
132 linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes;
133 memcpy(linebuf, (void *)addr, linebytes);
134 print_buffer(addr, linebuf, size, linebytes/size, DISP_LINE_LEN/size);
135
136 nbytes -= linebytes;
137 addr += linebytes;
138 if (ctrlc()) {
139 rc = 1;
140 break;
141 }
142 } while (nbytes > 0);
143 } else
144# endif
145
146 {
147 /* Print the lines. */
148 print_buffer(addr, (void*)addr, size, length, DISP_LINE_LEN/size);
149 addr += size*length;
150 }
Grant Likely02a00782007-02-20 09:05:00 +0100151#endif
wdenk38635852002-08-27 05:55:31 +0000152
153 dp_last_addr = addr;
154 dp_last_length = length;
155 dp_last_size = size;
156 return (rc);
157}
158
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200159int do_mem_mm ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000160{
161 return mod_mem (cmdtp, 1, flag, argc, argv);
162}
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200163int do_mem_nm ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000164{
165 return mod_mem (cmdtp, 0, flag, argc, argv);
166}
167
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200168int do_mem_mw ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000169{
wdenk874ac262003-07-24 23:38:38 +0000170 ulong addr, writeval, count;
171 int size;
wdenk38635852002-08-27 05:55:31 +0000172
Wolfgang Denk3b683112010-07-17 01:06:04 +0200173 if ((argc < 3) || (argc > 4))
174 return cmd_usage(cmdtp);
wdenk38635852002-08-27 05:55:31 +0000175
176 /* Check for size specification.
177 */
wdenk874ac262003-07-24 23:38:38 +0000178 if ((size = cmd_get_data_size(argv[0], 4)) < 1)
179 return 1;
wdenk38635852002-08-27 05:55:31 +0000180
181 /* Address is specified since argc > 1
182 */
183 addr = simple_strtoul(argv[1], NULL, 16);
184 addr += base_address;
185
186 /* Get the value to write.
187 */
188 writeval = simple_strtoul(argv[2], NULL, 16);
189
190 /* Count ? */
191 if (argc == 4) {
192 count = simple_strtoul(argv[3], NULL, 16);
193 } else {
194 count = 1;
195 }
196
197 while (count-- > 0) {
198 if (size == 4)
199 *((ulong *)addr) = (ulong )writeval;
200 else if (size == 2)
201 *((ushort *)addr) = (ushort)writeval;
202 else
203 *((u_char *)addr) = (u_char)writeval;
204 addr += size;
205 }
206 return 0;
207}
208
stroesefb5e0ac2004-12-16 17:42:39 +0000209#ifdef CONFIG_MX_CYCLIC
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200210int do_mem_mdc ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stroesefb5e0ac2004-12-16 17:42:39 +0000211{
212 int i;
213 ulong count;
214
Wolfgang Denk3b683112010-07-17 01:06:04 +0200215 if (argc < 4)
216 return cmd_usage(cmdtp);
stroesefb5e0ac2004-12-16 17:42:39 +0000217
218 count = simple_strtoul(argv[3], NULL, 10);
219
220 for (;;) {
221 do_mem_md (NULL, 0, 3, argv);
222
223 /* delay for <count> ms... */
224 for (i=0; i<count; i++)
225 udelay (1000);
226
227 /* check for ctrl-c to abort... */
228 if (ctrlc()) {
229 puts("Abort\n");
230 return 0;
231 }
232 }
233
234 return 0;
235}
236
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200237int do_mem_mwc ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stroesefb5e0ac2004-12-16 17:42:39 +0000238{
239 int i;
240 ulong count;
241
Wolfgang Denk3b683112010-07-17 01:06:04 +0200242 if (argc < 4)
243 return cmd_usage(cmdtp);
stroesefb5e0ac2004-12-16 17:42:39 +0000244
245 count = simple_strtoul(argv[3], NULL, 10);
246
247 for (;;) {
248 do_mem_mw (NULL, 0, 3, argv);
249
250 /* delay for <count> ms... */
251 for (i=0; i<count; i++)
252 udelay (1000);
253
254 /* check for ctrl-c to abort... */
255 if (ctrlc()) {
256 puts("Abort\n");
257 return 0;
258 }
259 }
260
261 return 0;
262}
263#endif /* CONFIG_MX_CYCLIC */
264
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200265int do_mem_cmp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000266{
wdenk874ac262003-07-24 23:38:38 +0000267 ulong addr1, addr2, count, ngood;
268 int size;
wdenk38635852002-08-27 05:55:31 +0000269 int rcode = 0;
270
Wolfgang Denk3b683112010-07-17 01:06:04 +0200271 if (argc != 4)
272 return cmd_usage(cmdtp);
wdenk38635852002-08-27 05:55:31 +0000273
274 /* Check for size specification.
275 */
wdenk874ac262003-07-24 23:38:38 +0000276 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
277 return 1;
wdenk38635852002-08-27 05:55:31 +0000278
279 addr1 = simple_strtoul(argv[1], NULL, 16);
280 addr1 += base_address;
281
282 addr2 = simple_strtoul(argv[2], NULL, 16);
283 addr2 += base_address;
284
285 count = simple_strtoul(argv[3], NULL, 16);
286
wdenk381669a2003-06-16 23:50:08 +0000287#ifdef CONFIG_HAS_DATAFLASH
288 if (addr_dataflash(addr1) | addr_dataflash(addr2)){
wdenk42c05472004-03-23 22:14:11 +0000289 puts ("Comparison with DataFlash space not supported.\n\r");
wdenk381669a2003-06-16 23:50:08 +0000290 return 0;
291 }
292#endif
293
Mike Frysingere578d682008-02-04 19:26:56 -0500294#ifdef CONFIG_BLACKFIN
295 if (addr_bfin_on_chip_mem(addr1) || addr_bfin_on_chip_mem(addr2)) {
296 puts ("Comparison with L1 instruction memory not supported.\n\r");
297 return 0;
298 }
299#endif
300
wdenk38635852002-08-27 05:55:31 +0000301 ngood = 0;
302
303 while (count-- > 0) {
304 if (size == 4) {
305 ulong word1 = *(ulong *)addr1;
306 ulong word2 = *(ulong *)addr2;
307 if (word1 != word2) {
308 printf("word at 0x%08lx (0x%08lx) "
309 "!= word at 0x%08lx (0x%08lx)\n",
310 addr1, word1, addr2, word2);
311 rcode = 1;
312 break;
313 }
314 }
315 else if (size == 2) {
316 ushort hword1 = *(ushort *)addr1;
317 ushort hword2 = *(ushort *)addr2;
318 if (hword1 != hword2) {
319 printf("halfword at 0x%08lx (0x%04x) "
320 "!= halfword at 0x%08lx (0x%04x)\n",
321 addr1, hword1, addr2, hword2);
322 rcode = 1;
323 break;
324 }
325 }
326 else {
327 u_char byte1 = *(u_char *)addr1;
328 u_char byte2 = *(u_char *)addr2;
329 if (byte1 != byte2) {
330 printf("byte at 0x%08lx (0x%02x) "
331 "!= byte at 0x%08lx (0x%02x)\n",
332 addr1, byte1, addr2, byte2);
333 rcode = 1;
334 break;
335 }
336 }
337 ngood++;
338 addr1 += size;
339 addr2 += size;
Stefan Roesed4ef82b2010-09-13 11:10:34 +0200340
341 /* reset watchdog from time to time */
342 if ((count % (64 << 10)) == 0)
343 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000344 }
345
346 printf("Total of %ld %s%s were the same\n",
347 ngood, size == 4 ? "word" : size == 2 ? "halfword" : "byte",
348 ngood == 1 ? "" : "s");
349 return rcode;
350}
351
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200352int do_mem_cp ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000353{
wdenk874ac262003-07-24 23:38:38 +0000354 ulong addr, dest, count;
355 int size;
wdenk38635852002-08-27 05:55:31 +0000356
Wolfgang Denk3b683112010-07-17 01:06:04 +0200357 if (argc != 4)
358 return cmd_usage(cmdtp);
wdenk38635852002-08-27 05:55:31 +0000359
360 /* Check for size specification.
361 */
wdenk874ac262003-07-24 23:38:38 +0000362 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
363 return 1;
wdenk38635852002-08-27 05:55:31 +0000364
365 addr = simple_strtoul(argv[1], NULL, 16);
366 addr += base_address;
367
368 dest = simple_strtoul(argv[2], NULL, 16);
369 dest += base_address;
370
371 count = simple_strtoul(argv[3], NULL, 16);
372
373 if (count == 0) {
374 puts ("Zero length ???\n");
375 return 1;
376 }
377
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200378#ifndef CONFIG_SYS_NO_FLASH
wdenk38635852002-08-27 05:55:31 +0000379 /* check if we are copying to Flash */
wdenk381669a2003-06-16 23:50:08 +0000380 if ( (addr2info(dest) != NULL)
381#ifdef CONFIG_HAS_DATAFLASH
Kim B. Heino1eb0fd52008-03-03 10:39:13 +0200382 && (!addr_dataflash(dest))
wdenk381669a2003-06-16 23:50:08 +0000383#endif
384 ) {
wdenk38635852002-08-27 05:55:31 +0000385 int rc;
386
wdenk42c05472004-03-23 22:14:11 +0000387 puts ("Copy to Flash... ");
wdenk38635852002-08-27 05:55:31 +0000388
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200389 rc = flash_write ((char *)addr, dest, count*size);
wdenk38635852002-08-27 05:55:31 +0000390 if (rc != 0) {
391 flash_perror (rc);
392 return (1);
393 }
394 puts ("done\n");
395 return 0;
396 }
397#endif
398
wdenk381669a2003-06-16 23:50:08 +0000399#ifdef CONFIG_HAS_DATAFLASH
400 /* Check if we are copying from RAM or Flash to DataFlash */
401 if (addr_dataflash(dest) && !addr_dataflash(addr)){
402 int rc;
403
wdenk42c05472004-03-23 22:14:11 +0000404 puts ("Copy to DataFlash... ");
wdenk381669a2003-06-16 23:50:08 +0000405
406 rc = write_dataflash (dest, addr, count*size);
407
408 if (rc != 1) {
409 dataflash_perror (rc);
410 return (1);
411 }
412 puts ("done\n");
413 return 0;
414 }
wdenk57b2d802003-06-27 21:31:46 +0000415
wdenk381669a2003-06-16 23:50:08 +0000416 /* Check if we are copying from DataFlash to RAM */
Stelian Popa63d2eb2008-03-26 22:52:35 +0100417 if (addr_dataflash(addr) && !addr_dataflash(dest)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200418#ifndef CONFIG_SYS_NO_FLASH
Stelian Popa63d2eb2008-03-26 22:52:35 +0100419 && (addr2info(dest) == NULL)
420#endif
421 ){
wdenk86765902003-12-06 23:55:10 +0000422 int rc;
423 rc = read_dataflash(addr, count * size, (char *) dest);
424 if (rc != 1) {
wdenk1ebf41e2004-01-02 14:00:00 +0000425 dataflash_perror (rc);
426 return (1);
427 }
wdenk381669a2003-06-16 23:50:08 +0000428 return 0;
429 }
430
431 if (addr_dataflash(addr) && addr_dataflash(dest)){
wdenk42c05472004-03-23 22:14:11 +0000432 puts ("Unsupported combination of source/destination.\n\r");
wdenk381669a2003-06-16 23:50:08 +0000433 return 1;
434 }
wdenk7a428cc2003-06-15 22:40:42 +0000435#endif
436
Mike Frysingere578d682008-02-04 19:26:56 -0500437#ifdef CONFIG_BLACKFIN
438 /* See if we're copying to/from L1 inst */
439 if (addr_bfin_on_chip_mem(dest) || addr_bfin_on_chip_mem(addr)) {
440 memcpy((void *)dest, (void *)addr, count * size);
441 return 0;
442 }
443#endif
444
wdenk38635852002-08-27 05:55:31 +0000445 while (count-- > 0) {
446 if (size == 4)
447 *((ulong *)dest) = *((ulong *)addr);
448 else if (size == 2)
449 *((ushort *)dest) = *((ushort *)addr);
450 else
451 *((u_char *)dest) = *((u_char *)addr);
452 addr += size;
453 dest += size;
Stefan Roesed4ef82b2010-09-13 11:10:34 +0200454
455 /* reset watchdog from time to time */
456 if ((count % (64 << 10)) == 0)
457 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000458 }
459 return 0;
460}
461
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200462int do_mem_base (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000463{
464 if (argc > 1) {
465 /* Set new base address.
466 */
467 base_address = simple_strtoul(argv[1], NULL, 16);
468 }
469 /* Print the current base address.
470 */
471 printf("Base Address: 0x%08lx\n", base_address);
472 return 0;
473}
474
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200475int do_mem_loop (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000476{
wdenk874ac262003-07-24 23:38:38 +0000477 ulong addr, length, i, junk;
478 int size;
wdenk38635852002-08-27 05:55:31 +0000479 volatile uint *longp;
480 volatile ushort *shortp;
481 volatile u_char *cp;
482
Wolfgang Denk3b683112010-07-17 01:06:04 +0200483 if (argc < 3)
484 return cmd_usage(cmdtp);
wdenk38635852002-08-27 05:55:31 +0000485
486 /* Check for a size spefication.
487 * Defaults to long if no or incorrect specification.
488 */
wdenk874ac262003-07-24 23:38:38 +0000489 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
490 return 1;
wdenk38635852002-08-27 05:55:31 +0000491
492 /* Address is always specified.
493 */
494 addr = simple_strtoul(argv[1], NULL, 16);
495
496 /* Length is the number of objects, not number of bytes.
497 */
498 length = simple_strtoul(argv[2], NULL, 16);
499
500 /* We want to optimize the loops to run as fast as possible.
501 * If we have only one object, just run infinite loops.
502 */
503 if (length == 1) {
504 if (size == 4) {
505 longp = (uint *)addr;
506 for (;;)
507 i = *longp;
508 }
509 if (size == 2) {
510 shortp = (ushort *)addr;
511 for (;;)
512 i = *shortp;
513 }
514 cp = (u_char *)addr;
515 for (;;)
516 i = *cp;
517 }
518
519 if (size == 4) {
520 for (;;) {
521 longp = (uint *)addr;
522 i = length;
523 while (i-- > 0)
524 junk = *longp++;
525 }
526 }
527 if (size == 2) {
528 for (;;) {
529 shortp = (ushort *)addr;
530 i = length;
531 while (i-- > 0)
532 junk = *shortp++;
533 }
534 }
535 for (;;) {
536 cp = (u_char *)addr;
537 i = length;
538 while (i-- > 0)
539 junk = *cp++;
540 }
541}
542
wdenk64519362004-07-11 17:40:54 +0000543#ifdef CONFIG_LOOPW
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200544int do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk64519362004-07-11 17:40:54 +0000545{
546 ulong addr, length, i, data;
547 int size;
548 volatile uint *longp;
549 volatile ushort *shortp;
550 volatile u_char *cp;
wdenk7dd13292004-07-11 20:04:51 +0000551
Wolfgang Denk3b683112010-07-17 01:06:04 +0200552 if (argc < 4)
553 return cmd_usage(cmdtp);
wdenk64519362004-07-11 17:40:54 +0000554
555 /* Check for a size spefication.
556 * Defaults to long if no or incorrect specification.
557 */
558 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
559 return 1;
560
561 /* Address is always specified.
562 */
563 addr = simple_strtoul(argv[1], NULL, 16);
564
565 /* Length is the number of objects, not number of bytes.
566 */
567 length = simple_strtoul(argv[2], NULL, 16);
568
569 /* data to write */
570 data = simple_strtoul(argv[3], NULL, 16);
wdenk7dd13292004-07-11 20:04:51 +0000571
wdenk64519362004-07-11 17:40:54 +0000572 /* We want to optimize the loops to run as fast as possible.
573 * If we have only one object, just run infinite loops.
574 */
575 if (length == 1) {
576 if (size == 4) {
577 longp = (uint *)addr;
578 for (;;)
579 *longp = data;
580 }
581 if (size == 2) {
582 shortp = (ushort *)addr;
583 for (;;)
584 *shortp = data;
585 }
586 cp = (u_char *)addr;
587 for (;;)
588 *cp = data;
589 }
590
591 if (size == 4) {
592 for (;;) {
593 longp = (uint *)addr;
594 i = length;
595 while (i-- > 0)
596 *longp++ = data;
597 }
598 }
599 if (size == 2) {
600 for (;;) {
601 shortp = (ushort *)addr;
602 i = length;
603 while (i-- > 0)
604 *shortp++ = data;
605 }
606 }
607 for (;;) {
608 cp = (u_char *)addr;
609 i = length;
610 while (i-- > 0)
611 *cp++ = data;
612 }
613}
614#endif /* CONFIG_LOOPW */
615
wdenk38635852002-08-27 05:55:31 +0000616/*
617 * Perform a memory test. A more complete alternative test can be
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200618 * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
wdenk38635852002-08-27 05:55:31 +0000619 * interrupted by ctrl-c or by a failure of one of the sub-tests.
620 */
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200621int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000622{
623 vu_long *addr, *start, *end;
624 ulong val;
625 ulong readback;
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400626 ulong errs = 0;
Dirk Eibachb2659892008-12-16 14:51:56 +0100627 int iterations = 1;
628 int iteration_limit;
wdenk38635852002-08-27 05:55:31 +0000629
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200630#if defined(CONFIG_SYS_ALT_MEMTEST)
Guennadi Liakhovetskid4e3fb42008-02-08 21:25:58 +0100631 vu_long len;
wdenk38635852002-08-27 05:55:31 +0000632 vu_long offset;
633 vu_long test_offset;
634 vu_long pattern;
635 vu_long temp;
636 vu_long anti_pattern;
637 vu_long num_words;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200638#if defined(CONFIG_SYS_MEMTEST_SCRATCH)
639 vu_long *dummy = (vu_long*)CONFIG_SYS_MEMTEST_SCRATCH;
wdenk5958f4a2003-09-18 09:21:33 +0000640#else
Wolfgang Denkf0e38c12006-07-21 11:37:40 +0200641 vu_long *dummy = 0; /* yes, this is address 0x0, not NULL */
wdenk5958f4a2003-09-18 09:21:33 +0000642#endif
wdenk38635852002-08-27 05:55:31 +0000643 int j;
wdenk38635852002-08-27 05:55:31 +0000644
645 static const ulong bitpattern[] = {
646 0x00000001, /* single bit */
647 0x00000003, /* two adjacent bits */
648 0x00000007, /* three adjacent bits */
649 0x0000000F, /* four adjacent bits */
650 0x00000005, /* two non-adjacent bits */
651 0x00000015, /* three non-adjacent bits */
652 0x00000055, /* four non-adjacent bits */
653 0xaaaaaaaa, /* alternating 1/0 */
654 };
655#else
656 ulong incr;
657 ulong pattern;
wdenk38635852002-08-27 05:55:31 +0000658#endif
659
Dirk Eibachb2659892008-12-16 14:51:56 +0100660 if (argc > 1)
wdenk38635852002-08-27 05:55:31 +0000661 start = (ulong *)simple_strtoul(argv[1], NULL, 16);
Dirk Eibachb2659892008-12-16 14:51:56 +0100662 else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200663 start = (ulong *)CONFIG_SYS_MEMTEST_START;
wdenk38635852002-08-27 05:55:31 +0000664
Dirk Eibachb2659892008-12-16 14:51:56 +0100665 if (argc > 2)
wdenk38635852002-08-27 05:55:31 +0000666 end = (ulong *)simple_strtoul(argv[2], NULL, 16);
Dirk Eibachb2659892008-12-16 14:51:56 +0100667 else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200668 end = (ulong *)(CONFIG_SYS_MEMTEST_END);
wdenk38635852002-08-27 05:55:31 +0000669
Dirk Eibachb2659892008-12-16 14:51:56 +0100670 if (argc > 3)
wdenk38635852002-08-27 05:55:31 +0000671 pattern = (ulong)simple_strtoul(argv[3], NULL, 16);
Dirk Eibachb2659892008-12-16 14:51:56 +0100672 else
wdenk38635852002-08-27 05:55:31 +0000673 pattern = 0;
Dirk Eibachb2659892008-12-16 14:51:56 +0100674
675 if (argc > 4)
676 iteration_limit = (ulong)simple_strtoul(argv[4], NULL, 16);
677 else
678 iteration_limit = 0;
wdenk38635852002-08-27 05:55:31 +0000679
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200680#if defined(CONFIG_SYS_ALT_MEMTEST)
wdenk38635852002-08-27 05:55:31 +0000681 printf ("Testing %08x ... %08x:\n", (uint)start, (uint)end);
682 PRINTF("%s:%d: start 0x%p end 0x%p\n",
683 __FUNCTION__, __LINE__, start, end);
684
685 for (;;) {
686 if (ctrlc()) {
687 putc ('\n');
688 return 1;
689 }
690
Dirk Eibachb2659892008-12-16 14:51:56 +0100691
692 if (iteration_limit && iterations > iteration_limit) {
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400693 printf("Tested %d iteration(s) with %lu errors.\n",
694 iterations-1, errs);
695 return errs != 0;
Dirk Eibachb2659892008-12-16 14:51:56 +0100696 }
697
wdenk38635852002-08-27 05:55:31 +0000698 printf("Iteration: %6d\r", iterations);
Dirk Eibachb2659892008-12-16 14:51:56 +0100699 PRINTF("\n");
wdenk38635852002-08-27 05:55:31 +0000700 iterations++;
701
702 /*
703 * Data line test: write a pattern to the first
704 * location, write the 1's complement to a 'parking'
705 * address (changes the state of the data bus so a
706 * floating bus doen't give a false OK), and then
707 * read the value back. Note that we read it back
708 * into a variable because the next time we read it,
709 * it might be right (been there, tough to explain to
710 * the quality guys why it prints a failure when the
711 * "is" and "should be" are obviously the same in the
712 * error message).
713 *
714 * Rather than exhaustively testing, we test some
715 * patterns by shifting '1' bits through a field of
716 * '0's and '0' bits through a field of '1's (i.e.
717 * pattern and ~pattern).
718 */
719 addr = start;
720 for (j = 0; j < sizeof(bitpattern)/sizeof(bitpattern[0]); j++) {
721 val = bitpattern[j];
722 for(; val != 0; val <<= 1) {
723 *addr = val;
724 *dummy = ~val; /* clear the test data off of the bus */
725 readback = *addr;
726 if(readback != val) {
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400727 printf ("FAILURE (data line): "
wdenk38635852002-08-27 05:55:31 +0000728 "expected %08lx, actual %08lx\n",
729 val, readback);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400730 errs++;
731 if (ctrlc()) {
732 putc ('\n');
733 return 1;
734 }
wdenk38635852002-08-27 05:55:31 +0000735 }
736 *addr = ~val;
737 *dummy = val;
738 readback = *addr;
739 if(readback != ~val) {
740 printf ("FAILURE (data line): "
741 "Is %08lx, should be %08lx\n",
wdenk391b5742004-10-10 23:27:33 +0000742 readback, ~val);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400743 errs++;
744 if (ctrlc()) {
745 putc ('\n');
746 return 1;
747 }
wdenk38635852002-08-27 05:55:31 +0000748 }
749 }
750 }
751
752 /*
753 * Based on code whose Original Author and Copyright
754 * information follows: Copyright (c) 1998 by Michael
755 * Barr. This software is placed into the public
756 * domain and may be used for any purpose. However,
757 * this notice must not be changed or removed and no
758 * warranty is either expressed or implied by its
759 * publication or distribution.
760 */
761
762 /*
763 * Address line test
764 *
765 * Description: Test the address bus wiring in a
766 * memory region by performing a walking
767 * 1's test on the relevant bits of the
768 * address and checking for aliasing.
769 * This test will find single-bit
770 * address failures such as stuck -high,
771 * stuck-low, and shorted pins. The base
772 * address and size of the region are
773 * selected by the caller.
774 *
775 * Notes: For best results, the selected base
776 * address should have enough LSB 0's to
777 * guarantee single address bit changes.
778 * For example, to test a 64-Kbyte
779 * region, select a base address on a
780 * 64-Kbyte boundary. Also, select the
781 * region size as a power-of-two if at
782 * all possible.
783 *
784 * Returns: 0 if the test succeeds, 1 if the test fails.
wdenk38635852002-08-27 05:55:31 +0000785 */
Guennadi Liakhovetskid4e3fb42008-02-08 21:25:58 +0100786 len = ((ulong)end - (ulong)start)/sizeof(vu_long);
wdenk38635852002-08-27 05:55:31 +0000787 pattern = (vu_long) 0xaaaaaaaa;
788 anti_pattern = (vu_long) 0x55555555;
789
Guennadi Liakhovetskid4e3fb42008-02-08 21:25:58 +0100790 PRINTF("%s:%d: length = 0x%.8lx\n",
wdenk38635852002-08-27 05:55:31 +0000791 __FUNCTION__, __LINE__,
Guennadi Liakhovetskid4e3fb42008-02-08 21:25:58 +0100792 len);
wdenk38635852002-08-27 05:55:31 +0000793 /*
794 * Write the default pattern at each of the
795 * power-of-two offsets.
796 */
Guennadi Liakhovetskid4e3fb42008-02-08 21:25:58 +0100797 for (offset = 1; offset < len; offset <<= 1) {
wdenk38635852002-08-27 05:55:31 +0000798 start[offset] = pattern;
799 }
800
801 /*
802 * Check for address bits stuck high.
803 */
804 test_offset = 0;
805 start[test_offset] = anti_pattern;
806
Guennadi Liakhovetskid4e3fb42008-02-08 21:25:58 +0100807 for (offset = 1; offset < len; offset <<= 1) {
wdenk38635852002-08-27 05:55:31 +0000808 temp = start[offset];
809 if (temp != pattern) {
810 printf ("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
811 " expected 0x%.8lx, actual 0x%.8lx\n",
812 (ulong)&start[offset], pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400813 errs++;
814 if (ctrlc()) {
815 putc ('\n');
816 return 1;
817 }
wdenk38635852002-08-27 05:55:31 +0000818 }
819 }
820 start[test_offset] = pattern;
Sergei Poselenov474dbb82008-04-09 16:09:41 +0200821 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000822
823 /*
824 * Check for addr bits stuck low or shorted.
825 */
Guennadi Liakhovetskid4e3fb42008-02-08 21:25:58 +0100826 for (test_offset = 1; test_offset < len; test_offset <<= 1) {
wdenk38635852002-08-27 05:55:31 +0000827 start[test_offset] = anti_pattern;
828
Guennadi Liakhovetskid4e3fb42008-02-08 21:25:58 +0100829 for (offset = 1; offset < len; offset <<= 1) {
wdenk38635852002-08-27 05:55:31 +0000830 temp = start[offset];
831 if ((temp != pattern) && (offset != test_offset)) {
832 printf ("\nFAILURE: Address bit stuck low or shorted @"
833 " 0x%.8lx: expected 0x%.8lx, actual 0x%.8lx\n",
834 (ulong)&start[offset], pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400835 errs++;
836 if (ctrlc()) {
837 putc ('\n');
838 return 1;
839 }
wdenk38635852002-08-27 05:55:31 +0000840 }
841 }
842 start[test_offset] = pattern;
843 }
844
845 /*
846 * Description: Test the integrity of a physical
847 * memory device by performing an
848 * increment/decrement test over the
849 * entire region. In the process every
850 * storage bit in the device is tested
851 * as a zero and a one. The base address
852 * and the size of the region are
853 * selected by the caller.
854 *
855 * Returns: 0 if the test succeeds, 1 if the test fails.
856 */
857 num_words = ((ulong)end - (ulong)start)/sizeof(vu_long) + 1;
858
859 /*
860 * Fill memory with a known pattern.
861 */
862 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
Sergei Poselenov474dbb82008-04-09 16:09:41 +0200863 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000864 start[offset] = pattern;
865 }
866
867 /*
868 * Check each location and invert it for the second pass.
869 */
870 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
Sergei Poselenov474dbb82008-04-09 16:09:41 +0200871 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000872 temp = start[offset];
873 if (temp != pattern) {
874 printf ("\nFAILURE (read/write) @ 0x%.8lx:"
875 " expected 0x%.8lx, actual 0x%.8lx)\n",
876 (ulong)&start[offset], pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400877 errs++;
878 if (ctrlc()) {
879 putc ('\n');
880 return 1;
881 }
wdenk38635852002-08-27 05:55:31 +0000882 }
883
884 anti_pattern = ~pattern;
885 start[offset] = anti_pattern;
886 }
887
888 /*
889 * Check each location for the inverted pattern and zero it.
890 */
891 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
Sergei Poselenov474dbb82008-04-09 16:09:41 +0200892 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000893 anti_pattern = ~pattern;
894 temp = start[offset];
895 if (temp != anti_pattern) {
896 printf ("\nFAILURE (read/write): @ 0x%.8lx:"
897 " expected 0x%.8lx, actual 0x%.8lx)\n",
898 (ulong)&start[offset], anti_pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400899 errs++;
900 if (ctrlc()) {
901 putc ('\n');
902 return 1;
903 }
wdenk38635852002-08-27 05:55:31 +0000904 }
905 start[offset] = 0;
906 }
907 }
908
909#else /* The original, quickie test */
910 incr = 1;
911 for (;;) {
912 if (ctrlc()) {
913 putc ('\n');
914 return 1;
915 }
Dirk Eibachb2659892008-12-16 14:51:56 +0100916
917 if (iteration_limit && iterations > iteration_limit) {
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400918 printf("Tested %d iteration(s) with %lu errors.\n",
919 iterations-1, errs);
920 return errs != 0;
Dirk Eibachb2659892008-12-16 14:51:56 +0100921 }
922 ++iterations;
wdenk38635852002-08-27 05:55:31 +0000923
924 printf ("\rPattern %08lX Writing..."
925 "%12s"
926 "\b\b\b\b\b\b\b\b\b\b",
927 pattern, "");
928
929 for (addr=start,val=pattern; addr<end; addr++) {
Sergei Poselenov474dbb82008-04-09 16:09:41 +0200930 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000931 *addr = val;
932 val += incr;
933 }
934
wdenk42c05472004-03-23 22:14:11 +0000935 puts ("Reading...");
wdenk38635852002-08-27 05:55:31 +0000936
937 for (addr=start,val=pattern; addr<end; addr++) {
Sergei Poselenov474dbb82008-04-09 16:09:41 +0200938 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000939 readback = *addr;
940 if (readback != val) {
941 printf ("\nMem error @ 0x%08X: "
942 "found %08lX, expected %08lX\n",
943 (uint)addr, readback, val);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400944 errs++;
945 if (ctrlc()) {
946 putc ('\n');
947 return 1;
948 }
wdenk38635852002-08-27 05:55:31 +0000949 }
950 val += incr;
951 }
952
953 /*
954 * Flip the pattern each time to make lots of zeros and
955 * then, the next time, lots of ones. We decrement
956 * the "negative" patterns and increment the "positive"
957 * patterns to preserve this feature.
958 */
959 if(pattern & 0x80000000) {
960 pattern = -pattern; /* complement & increment */
961 }
962 else {
963 pattern = ~pattern;
964 }
965 incr = -incr;
966 }
wdenk38635852002-08-27 05:55:31 +0000967#endif
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400968 return 0; /* not reached */
wdenk38635852002-08-27 05:55:31 +0000969}
970
971
972/* Modify memory.
973 *
974 * Syntax:
975 * mm{.b, .w, .l} {addr}
976 * nm{.b, .w, .l} {addr}
977 */
978static int
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200979mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000980{
wdenk874ac262003-07-24 23:38:38 +0000981 ulong addr, i;
982 int nbytes, size;
wdenk38635852002-08-27 05:55:31 +0000983 extern char console_buffer[];
984
Wolfgang Denk3b683112010-07-17 01:06:04 +0200985 if (argc != 2)
986 return cmd_usage(cmdtp);
wdenk38635852002-08-27 05:55:31 +0000987
988#ifdef CONFIG_BOOT_RETRY_TIME
989 reset_cmd_timeout(); /* got a good command to get here */
990#endif
991 /* We use the last specified parameters, unless new ones are
992 * entered.
993 */
994 addr = mm_last_addr;
995 size = mm_last_size;
996
997 if ((flag & CMD_FLAG_REPEAT) == 0) {
998 /* New command specified. Check for a size specification.
999 * Defaults to long if no or incorrect specification.
1000 */
wdenk874ac262003-07-24 23:38:38 +00001001 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
1002 return 1;
wdenk38635852002-08-27 05:55:31 +00001003
1004 /* Address is specified since argc > 1
1005 */
1006 addr = simple_strtoul(argv[1], NULL, 16);
1007 addr += base_address;
1008 }
1009
wdenk381669a2003-06-16 23:50:08 +00001010#ifdef CONFIG_HAS_DATAFLASH
1011 if (addr_dataflash(addr)){
wdenk42c05472004-03-23 22:14:11 +00001012 puts ("Can't modify DataFlash in place. Use cp instead.\n\r");
wdenk381669a2003-06-16 23:50:08 +00001013 return 0;
1014 }
1015#endif
1016
Mike Frysingere578d682008-02-04 19:26:56 -05001017#ifdef CONFIG_BLACKFIN
1018 if (addr_bfin_on_chip_mem(addr)) {
1019 puts ("Can't modify L1 instruction in place. Use cp instead.\n\r");
1020 return 0;
1021 }
1022#endif
1023
wdenk38635852002-08-27 05:55:31 +00001024 /* Print the address, followed by value. Then accept input for
1025 * the next value. A non-converted value exits.
1026 */
1027 do {
1028 printf("%08lx:", addr);
1029 if (size == 4)
1030 printf(" %08x", *((uint *)addr));
1031 else if (size == 2)
1032 printf(" %04x", *((ushort *)addr));
1033 else
1034 printf(" %02x", *((u_char *)addr));
1035
1036 nbytes = readline (" ? ");
1037 if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
1038 /* <CR> pressed as only input, don't modify current
1039 * location and move to next. "-" pressed will go back.
1040 */
1041 if (incrflag)
1042 addr += nbytes ? -size : size;
1043 nbytes = 1;
1044#ifdef CONFIG_BOOT_RETRY_TIME
1045 reset_cmd_timeout(); /* good enough to not time out */
1046#endif
1047 }
1048#ifdef CONFIG_BOOT_RETRY_TIME
1049 else if (nbytes == -2) {
1050 break; /* timed out, exit the command */
1051 }
1052#endif
1053 else {
1054 char *endp;
1055 i = simple_strtoul(console_buffer, &endp, 16);
1056 nbytes = endp - console_buffer;
1057 if (nbytes) {
1058#ifdef CONFIG_BOOT_RETRY_TIME
1059 /* good enough to not time out
1060 */
1061 reset_cmd_timeout();
1062#endif
1063 if (size == 4)
1064 *((uint *)addr) = i;
1065 else if (size == 2)
1066 *((ushort *)addr) = i;
1067 else
1068 *((u_char *)addr) = i;
1069 if (incrflag)
1070 addr += size;
1071 }
1072 }
1073 } while (nbytes);
1074
1075 mm_last_addr = addr;
1076 mm_last_size = size;
1077 return 0;
1078}
1079
wdenk6203e402004-04-18 10:13:26 +00001080#ifndef CONFIG_CRC32_VERIFY
1081
Wolfgang Denk6262d0212010-06-28 22:00:46 +02001082int do_mem_crc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +00001083{
wdenk7a428cc2003-06-15 22:40:42 +00001084 ulong addr, length;
1085 ulong crc;
1086 ulong *ptr;
wdenk38635852002-08-27 05:55:31 +00001087
Wolfgang Denk3b683112010-07-17 01:06:04 +02001088 if (argc < 3)
1089 return cmd_usage(cmdtp);
wdenk38635852002-08-27 05:55:31 +00001090
wdenk7a428cc2003-06-15 22:40:42 +00001091 addr = simple_strtoul (argv[1], NULL, 16);
wdenk38635852002-08-27 05:55:31 +00001092 addr += base_address;
1093
wdenk7a428cc2003-06-15 22:40:42 +00001094 length = simple_strtoul (argv[2], NULL, 16);
wdenk38635852002-08-27 05:55:31 +00001095
wdenk7a428cc2003-06-15 22:40:42 +00001096 crc = crc32 (0, (const uchar *) addr, length);
wdenk38635852002-08-27 05:55:31 +00001097
1098 printf ("CRC32 for %08lx ... %08lx ==> %08lx\n",
wdenk7a428cc2003-06-15 22:40:42 +00001099 addr, addr + length - 1, crc);
wdenk38635852002-08-27 05:55:31 +00001100
wdenk7a428cc2003-06-15 22:40:42 +00001101 if (argc > 3) {
1102 ptr = (ulong *) simple_strtoul (argv[3], NULL, 16);
1103 *ptr = crc;
1104 }
wdenk38635852002-08-27 05:55:31 +00001105
1106 return 0;
1107}
1108
wdenk6203e402004-04-18 10:13:26 +00001109#else /* CONFIG_CRC32_VERIFY */
1110
Wolfgang Denk6262d0212010-06-28 22:00:46 +02001111int do_mem_crc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk6203e402004-04-18 10:13:26 +00001112{
1113 ulong addr, length;
1114 ulong crc;
1115 ulong *ptr;
wdenk05939202004-04-18 17:39:38 +00001116 ulong vcrc;
wdenk6203e402004-04-18 10:13:26 +00001117 int verify;
1118 int ac;
Wolfgang Denk6262d0212010-06-28 22:00:46 +02001119 char * const *av;
wdenk6203e402004-04-18 10:13:26 +00001120
1121 if (argc < 3) {
Wolfgang Denk3b683112010-07-17 01:06:04 +02001122usage:
1123 return cmd_usage(cmdtp);
wdenk6203e402004-04-18 10:13:26 +00001124 }
1125
1126 av = argv + 1;
1127 ac = argc - 1;
1128 if (strcmp(*av, "-v") == 0) {
1129 verify = 1;
1130 av++;
1131 ac--;
1132 if (ac < 3)
1133 goto usage;
1134 } else
1135 verify = 0;
1136
1137 addr = simple_strtoul(*av++, NULL, 16);
1138 addr += base_address;
1139 length = simple_strtoul(*av++, NULL, 16);
1140
1141 crc = crc32(0, (const uchar *) addr, length);
1142
1143 if (!verify) {
1144 printf ("CRC32 for %08lx ... %08lx ==> %08lx\n",
1145 addr, addr + length - 1, crc);
1146 if (ac > 2) {
1147 ptr = (ulong *) simple_strtoul (*av++, NULL, 16);
1148 *ptr = crc;
1149 }
1150 } else {
1151 vcrc = simple_strtoul(*av++, NULL, 16);
1152 if (vcrc != crc) {
1153 printf ("CRC32 for %08lx ... %08lx ==> %08lx != %08lx ** ERROR **\n",
1154 addr, addr + length - 1, crc, vcrc);
1155 return 1;
1156 }
1157 }
1158
1159 return 0;
1160
1161}
1162#endif /* CONFIG_CRC32_VERIFY */
1163
Robin Getz93d6cb02009-07-27 00:07:59 -04001164#ifdef CONFIG_CMD_MD5SUM
Wolfgang Denk6262d0212010-06-28 22:00:46 +02001165int do_md5sum(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Robin Getz93d6cb02009-07-27 00:07:59 -04001166{
1167 unsigned long addr, len;
1168 unsigned int i;
1169 u8 output[16];
1170
Wolfgang Denk3b683112010-07-17 01:06:04 +02001171 if (argc < 3)
1172 return cmd_usage(cmdtp);
Robin Getz93d6cb02009-07-27 00:07:59 -04001173
1174 addr = simple_strtoul(argv[1], NULL, 16);
1175 len = simple_strtoul(argv[2], NULL, 16);
1176
1177 md5((unsigned char *) addr, len, output);
1178 printf("md5 for %08lx ... %08lx ==> ", addr, addr + len - 1);
1179 for (i = 0; i < 16; i++)
1180 printf("%02x", output[i]);
1181 printf("\n");
1182
1183 return 0;
1184}
1185#endif
1186
Alexander Holler37ef5392011-01-18 09:48:08 +01001187#ifdef CONFIG_CMD_SHA1SUM
Wolfgang Denk6262d0212010-06-28 22:00:46 +02001188int do_sha1sum(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Robin Getz93d6cb02009-07-27 00:07:59 -04001189{
1190 unsigned long addr, len;
1191 unsigned int i;
1192 u8 output[20];
1193
Wolfgang Denk3b683112010-07-17 01:06:04 +02001194 if (argc < 3)
1195 return cmd_usage(cmdtp);
Robin Getz93d6cb02009-07-27 00:07:59 -04001196
1197 addr = simple_strtoul(argv[1], NULL, 16);
1198 len = simple_strtoul(argv[2], NULL, 16);
1199
1200 sha1_csum((unsigned char *) addr, len, output);
1201 printf("SHA1 for %08lx ... %08lx ==> ", addr, addr + len - 1);
1202 for (i = 0; i < 20; i++)
1203 printf("%02x", output[i]);
1204 printf("\n");
1205
1206 return 0;
1207}
1208#endif
Harald Weltef0db32c2008-07-06 15:56:38 +08001209
1210#ifdef CONFIG_CMD_UNZIP
Wolfgang Denk6262d0212010-06-28 22:00:46 +02001211int do_unzip ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Harald Weltef0db32c2008-07-06 15:56:38 +08001212{
1213 unsigned long src, dst;
1214 unsigned long src_len = ~0UL, dst_len = ~0UL;
Harald Weltef0db32c2008-07-06 15:56:38 +08001215
1216 switch (argc) {
1217 case 4:
1218 dst_len = simple_strtoul(argv[3], NULL, 16);
1219 /* fall through */
1220 case 3:
1221 src = simple_strtoul(argv[1], NULL, 16);
1222 dst = simple_strtoul(argv[2], NULL, 16);
1223 break;
1224 default:
Wolfgang Denk3b683112010-07-17 01:06:04 +02001225 return cmd_usage(cmdtp);
Harald Weltef0db32c2008-07-06 15:56:38 +08001226 }
1227
1228 return !!gunzip((void *) dst, dst_len, (void *) src, &src_len);
1229}
1230#endif /* CONFIG_CMD_UNZIP */
1231
1232
wdenk57b2d802003-06-27 21:31:46 +00001233/**************************************************/
wdenkf287a242003-07-01 21:06:45 +00001234U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001235 md, 3, 1, do_mem_md,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001236 "memory display",
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001237 "[.b, .w, .l] address [# of objects]"
wdenk57b2d802003-06-27 21:31:46 +00001238);
1239
1240
wdenkf287a242003-07-01 21:06:45 +00001241U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001242 mm, 2, 1, do_mem_mm,
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001243 "memory modify (auto-incrementing address)",
1244 "[.b, .w, .l] address"
wdenk57b2d802003-06-27 21:31:46 +00001245);
1246
1247
wdenkf287a242003-07-01 21:06:45 +00001248U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001249 nm, 2, 1, do_mem_nm,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001250 "memory modify (constant address)",
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001251 "[.b, .w, .l] address"
wdenk57b2d802003-06-27 21:31:46 +00001252);
1253
wdenkf287a242003-07-01 21:06:45 +00001254U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001255 mw, 4, 1, do_mem_mw,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001256 "memory write (fill)",
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001257 "[.b, .w, .l] address value [count]"
wdenk57b2d802003-06-27 21:31:46 +00001258);
1259
wdenkf287a242003-07-01 21:06:45 +00001260U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001261 cp, 4, 1, do_mem_cp,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001262 "memory copy",
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001263 "[.b, .w, .l] source target count"
wdenk57b2d802003-06-27 21:31:46 +00001264);
1265
wdenkf287a242003-07-01 21:06:45 +00001266U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001267 cmp, 4, 1, do_mem_cmp,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001268 "memory compare",
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001269 "[.b, .w, .l] addr1 addr2 count"
wdenk57b2d802003-06-27 21:31:46 +00001270);
1271
wdenk6203e402004-04-18 10:13:26 +00001272#ifndef CONFIG_CRC32_VERIFY
1273
wdenkf287a242003-07-01 21:06:45 +00001274U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001275 crc32, 4, 1, do_mem_crc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001276 "checksum calculation",
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001277 "address count [addr]\n - compute CRC32 checksum [save at addr]"
wdenk57b2d802003-06-27 21:31:46 +00001278);
1279
wdenk6203e402004-04-18 10:13:26 +00001280#else /* CONFIG_CRC32_VERIFY */
1281
1282U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001283 crc32, 5, 1, do_mem_crc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001284 "checksum calculation",
wdenk6203e402004-04-18 10:13:26 +00001285 "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001286 "-v address count crc\n - verify crc of memory area"
wdenk6203e402004-04-18 10:13:26 +00001287);
1288
1289#endif /* CONFIG_CRC32_VERIFY */
1290
wdenkf287a242003-07-01 21:06:45 +00001291U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001292 base, 2, 1, do_mem_base,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001293 "print or set address offset",
wdenk57b2d802003-06-27 21:31:46 +00001294 "\n - print address offset for memory commands\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001295 "base off\n - set address offset for memory commands to 'off'"
wdenk57b2d802003-06-27 21:31:46 +00001296);
1297
wdenkf287a242003-07-01 21:06:45 +00001298U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001299 loop, 3, 1, do_mem_loop,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001300 "infinite loop on address range",
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001301 "[.b, .w, .l] address number_of_objects"
wdenk57b2d802003-06-27 21:31:46 +00001302);
wdenk64519362004-07-11 17:40:54 +00001303
1304#ifdef CONFIG_LOOPW
1305U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001306 loopw, 4, 1, do_mem_loopw,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001307 "infinite write loop on address range",
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001308 "[.b, .w, .l] address number_of_objects data_to_write"
wdenk64519362004-07-11 17:40:54 +00001309);
1310#endif /* CONFIG_LOOPW */
wdenk57b2d802003-06-27 21:31:46 +00001311
wdenkf287a242003-07-01 21:06:45 +00001312U_BOOT_CMD(
Dirk Eibachb2659892008-12-16 14:51:56 +01001313 mtest, 5, 1, do_mem_mtest,
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001314 "simple RAM read/write test",
1315 "[start [end [pattern [iterations]]]]"
wdenk57b2d802003-06-27 21:31:46 +00001316);
stroesefb5e0ac2004-12-16 17:42:39 +00001317
1318#ifdef CONFIG_MX_CYCLIC
1319U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001320 mdc, 4, 1, do_mem_mdc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001321 "memory display cyclic",
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001322 "[.b, .w, .l] address count delay(ms)"
stroesefb5e0ac2004-12-16 17:42:39 +00001323);
1324
1325U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001326 mwc, 4, 1, do_mem_mwc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001327 "memory write cyclic",
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001328 "[.b, .w, .l] address value delay(ms)"
stroesefb5e0ac2004-12-16 17:42:39 +00001329);
1330#endif /* CONFIG_MX_CYCLIC */
wdenk57b2d802003-06-27 21:31:46 +00001331
Robin Getz93d6cb02009-07-27 00:07:59 -04001332#ifdef CONFIG_CMD_MD5SUM
1333U_BOOT_CMD(
1334 md5sum, 3, 1, do_md5sum,
1335 "compute MD5 message digest",
1336 "address count"
1337);
1338#endif
1339
1340#ifdef CONFIG_CMD_SHA1SUM
1341U_BOOT_CMD(
1342 sha1sum, 3, 1, do_sha1sum,
1343 "compute SHA1 message digest",
1344 "address count"
1345);
Alexander Holler37ef5392011-01-18 09:48:08 +01001346#endif /* CONFIG_CMD_SHA1SUM */
Robin Getz93d6cb02009-07-27 00:07:59 -04001347
Harald Weltef0db32c2008-07-06 15:56:38 +08001348#ifdef CONFIG_CMD_UNZIP
1349U_BOOT_CMD(
1350 unzip, 4, 1, do_unzip,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001351 "unzip a memory region",
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001352 "srcaddr dstaddr [dstsize]"
Harald Weltef0db32c2008-07-06 15:56:38 +08001353);
1354#endif /* CONFIG_CMD_UNZIP */