]> git.ipfire.org Git - people/ms/u-boot.git/blame - cmd/mem.c
flash: complete CONFIG_SYS_NO_FLASH move with renaming
[people/ms/u-boot.git] / cmd / mem.c
CommitLineData
3863585b
WD
1/*
2 * (C) Copyright 2000
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
1a459660 5 * SPDX-License-Identifier: GPL-2.0+
3863585b
WD
6 */
7
8/*
9 * Memory Functions
10 *
11 * Copied from FADS ROM, Dan Malek (dmalek@jlc.net)
12 */
13
14#include <common.h>
24b852a7 15#include <console.h>
0098e179 16#include <bootretry.h>
18d66533 17#include <cli.h>
3863585b 18#include <command.h>
24b852a7 19#include <console.h>
2abbe075
WD
20#ifdef CONFIG_HAS_DATAFLASH
21#include <dataflash.h>
22#endif
d20a40de 23#include <hash.h>
e48f3741 24#include <inttypes.h>
0eb25b61 25#include <mapmem.h>
a6e6fc61 26#include <watchdog.h>
0628ab8e 27#include <asm/io.h>
15a33e49
SG
28#include <linux/compiler.h>
29
30DECLARE_GLOBAL_DATA_PTR;
3863585b 31
8e169cc9
SG
32#ifndef CONFIG_SYS_MEMTEST_SCRATCH
33#define CONFIG_SYS_MEMTEST_SCRATCH 0
34#endif
35
54841ab5 36static int mod_mem(cmd_tbl_t *, int, int, int, char * const []);
3863585b
WD
37
38/* Display values from last command.
39 * Memory modify remembered values are different from display memory.
40 */
581508bd
SW
41static ulong dp_last_addr, dp_last_size;
42static ulong dp_last_length = 0x40;
43static ulong mm_last_addr, mm_last_size;
3863585b
WD
44
45static ulong base_address = 0;
46
47/* Memory Display
48 *
49 * Syntax:
4d1fd7f1 50 * md{.b, .w, .l, .q} {addr} {len}
3863585b
WD
51 */
52#define DISP_LINE_LEN 16
088f1b19 53static int do_mem_md(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
3863585b 54{
27b207fd 55 ulong addr, length;
c95c4280
GL
56#if defined(CONFIG_HAS_DATAFLASH)
57 ulong nbytes, linebytes;
58#endif
27b207fd 59 int size;
3863585b
WD
60 int rc = 0;
61
62 /* We use the last specified parameters, unless new ones are
63 * entered.
64 */
65 addr = dp_last_addr;
66 size = dp_last_size;
67 length = dp_last_length;
68
47e26b1b 69 if (argc < 2)
4c12eeb8 70 return CMD_RET_USAGE;
3863585b
WD
71
72 if ((flag & CMD_FLAG_REPEAT) == 0) {
73 /* New command specified. Check for a size specification.
74 * Defaults to long if no or incorrect specification.
75 */
27b207fd
WD
76 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
77 return 1;
3863585b
WD
78
79 /* Address is specified since argc > 1
80 */
81 addr = simple_strtoul(argv[1], NULL, 16);
82 addr += base_address;
83
84 /* If another parameter, it is the length to display.
85 * Length is the number of objects, not number of bytes.
86 */
87 if (argc > 2)
88 length = simple_strtoul(argv[2], NULL, 16);
89 }
90
c95c4280 91#if defined(CONFIG_HAS_DATAFLASH)
3863585b
WD
92 /* Print the lines.
93 *
94 * We buffer all read data, so we can make sure data is read only
95 * once, and all accesses are with the specified bus width.
96 */
97 nbytes = length * size;
98 do {
99 char linebuf[DISP_LINE_LEN];
c95c4280 100 void* p;
3863585b 101 linebytes = (nbytes>DISP_LINE_LEN)?DISP_LINE_LEN:nbytes;
2abbe075 102
c95c4280
GL
103 rc = read_dataflash(addr, (linebytes/size)*size, linebuf);
104 p = (rc == DATAFLASH_OK) ? linebuf : (void*)addr;
105 print_buffer(addr, p, size, linebytes/size, DISP_LINE_LEN/size);
106
3863585b 107 nbytes -= linebytes;
c95c4280 108 addr += linebytes;
3863585b
WD
109 if (ctrlc()) {
110 rc = 1;
111 break;
112 }
113 } while (nbytes > 0);
c95c4280 114#else
4c727c77
MF
115
116# if defined(CONFIG_BLACKFIN)
117 /* See if we're trying to display L1 inst */
118 if (addr_bfin_on_chip_mem(addr)) {
119 char linebuf[DISP_LINE_LEN];
120 ulong linebytes, nbytes = length * size;
121 do {
122 linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes;
123 memcpy(linebuf, (void *)addr, linebytes);
124 print_buffer(addr, linebuf, size, linebytes/size, DISP_LINE_LEN/size);
125
126 nbytes -= linebytes;
127 addr += linebytes;
128 if (ctrlc()) {
129 rc = 1;
130 break;
131 }
132 } while (nbytes > 0);
133 } else
134# endif
135
136 {
0628ab8e
SG
137 ulong bytes = size * length;
138 const void *buf = map_sysmem(addr, bytes);
139
4c727c77 140 /* Print the lines. */
0628ab8e
SG
141 print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
142 addr += bytes;
143 unmap_sysmem(buf);
4c727c77 144 }
c95c4280 145#endif
3863585b
WD
146
147 dp_last_addr = addr;
148 dp_last_length = length;
149 dp_last_size = size;
150 return (rc);
151}
152
088f1b19 153static int do_mem_mm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
3863585b
WD
154{
155 return mod_mem (cmdtp, 1, flag, argc, argv);
156}
088f1b19 157static int do_mem_nm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
3863585b
WD
158{
159 return mod_mem (cmdtp, 0, flag, argc, argv);
160}
161
088f1b19 162static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
3863585b 163{
4d1fd7f1
YS
164#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
165 u64 writeval;
166#else
167 ulong writeval;
168#endif
169 ulong addr, count;
27b207fd 170 int size;
cc5e196e 171 void *buf, *start;
0628ab8e 172 ulong bytes;
3863585b 173
47e26b1b 174 if ((argc < 3) || (argc > 4))
4c12eeb8 175 return CMD_RET_USAGE;
3863585b
WD
176
177 /* Check for size specification.
178 */
27b207fd
WD
179 if ((size = cmd_get_data_size(argv[0], 4)) < 1)
180 return 1;
3863585b
WD
181
182 /* Address is specified since argc > 1
183 */
184 addr = simple_strtoul(argv[1], NULL, 16);
185 addr += base_address;
186
187 /* Get the value to write.
188 */
4d1fd7f1
YS
189#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
190 writeval = simple_strtoull(argv[2], NULL, 16);
191#else
3863585b 192 writeval = simple_strtoul(argv[2], NULL, 16);
4d1fd7f1 193#endif
3863585b
WD
194
195 /* Count ? */
196 if (argc == 4) {
197 count = simple_strtoul(argv[3], NULL, 16);
198 } else {
199 count = 1;
200 }
201
0628ab8e 202 bytes = size * count;
cc5e196e
SG
203 start = map_sysmem(addr, bytes);
204 buf = start;
3863585b
WD
205 while (count-- > 0) {
206 if (size == 4)
76698b4e 207 *((u32 *)buf) = (u32)writeval;
4d1fd7f1
YS
208#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
209 else if (size == 8)
210 *((u64 *)buf) = (u64)writeval;
211#endif
3863585b 212 else if (size == 2)
76698b4e 213 *((u16 *)buf) = (u16)writeval;
3863585b 214 else
76698b4e 215 *((u8 *)buf) = (u8)writeval;
0628ab8e 216 buf += size;
3863585b 217 }
cc5e196e 218 unmap_sysmem(start);
3863585b
WD
219 return 0;
220}
221
4aaf29b2 222#ifdef CONFIG_MX_CYCLIC
5a8608e5 223static int do_mem_mdc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
4aaf29b2
SR
224{
225 int i;
226 ulong count;
227
47e26b1b 228 if (argc < 4)
4c12eeb8 229 return CMD_RET_USAGE;
4aaf29b2
SR
230
231 count = simple_strtoul(argv[3], NULL, 10);
232
233 for (;;) {
234 do_mem_md (NULL, 0, 3, argv);
235
236 /* delay for <count> ms... */
237 for (i=0; i<count; i++)
238 udelay (1000);
239
240 /* check for ctrl-c to abort... */
241 if (ctrlc()) {
242 puts("Abort\n");
243 return 0;
244 }
245 }
246
247 return 0;
248}
249
5a8608e5 250static int do_mem_mwc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
4aaf29b2
SR
251{
252 int i;
253 ulong count;
254
47e26b1b 255 if (argc < 4)
4c12eeb8 256 return CMD_RET_USAGE;
4aaf29b2
SR
257
258 count = simple_strtoul(argv[3], NULL, 10);
259
260 for (;;) {
261 do_mem_mw (NULL, 0, 3, argv);
262
263 /* delay for <count> ms... */
264 for (i=0; i<count; i++)
265 udelay (1000);
266
267 /* check for ctrl-c to abort... */
268 if (ctrlc()) {
269 puts("Abort\n");
270 return 0;
271 }
272 }
273
274 return 0;
275}
276#endif /* CONFIG_MX_CYCLIC */
277
088f1b19 278static int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
3863585b 279{
0628ab8e 280 ulong addr1, addr2, count, ngood, bytes;
27b207fd 281 int size;
3863585b 282 int rcode = 0;
054ea170 283 const char *type;
0628ab8e 284 const void *buf1, *buf2, *base;
4d1fd7f1
YS
285#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
286 u64 word1, word2;
287#else
288 ulong word1, word2;
289#endif
3863585b 290
47e26b1b 291 if (argc != 4)
4c12eeb8 292 return CMD_RET_USAGE;
3863585b
WD
293
294 /* Check for size specification.
295 */
27b207fd
WD
296 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
297 return 1;
4d1fd7f1
YS
298 type = size == 8 ? "double word" :
299 size == 4 ? "word" :
300 size == 2 ? "halfword" : "byte";
3863585b
WD
301
302 addr1 = simple_strtoul(argv[1], NULL, 16);
303 addr1 += base_address;
304
305 addr2 = simple_strtoul(argv[2], NULL, 16);
306 addr2 += base_address;
307
308 count = simple_strtoul(argv[3], NULL, 16);
309
2abbe075
WD
310#ifdef CONFIG_HAS_DATAFLASH
311 if (addr_dataflash(addr1) | addr_dataflash(addr2)){
4b9206ed 312 puts ("Comparison with DataFlash space not supported.\n\r");
2abbe075
WD
313 return 0;
314 }
315#endif
316
4c727c77
MF
317#ifdef CONFIG_BLACKFIN
318 if (addr_bfin_on_chip_mem(addr1) || addr_bfin_on_chip_mem(addr2)) {
319 puts ("Comparison with L1 instruction memory not supported.\n\r");
320 return 0;
321 }
322#endif
323
0628ab8e
SG
324 bytes = size * count;
325 base = buf1 = map_sysmem(addr1, bytes);
326 buf2 = map_sysmem(addr2, bytes);
feb12a1f 327 for (ngood = 0; ngood < count; ++ngood) {
3863585b 328 if (size == 4) {
76698b4e
YS
329 word1 = *(u32 *)buf1;
330 word2 = *(u32 *)buf2;
4d1fd7f1
YS
331#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
332 } else if (size == 8) {
333 word1 = *(u64 *)buf1;
334 word2 = *(u64 *)buf2;
335#endif
054ea170 336 } else if (size == 2) {
76698b4e
YS
337 word1 = *(u16 *)buf1;
338 word2 = *(u16 *)buf2;
054ea170 339 } else {
76698b4e
YS
340 word1 = *(u8 *)buf1;
341 word2 = *(u8 *)buf2;
3863585b 342 }
054ea170 343 if (word1 != word2) {
0628ab8e 344 ulong offset = buf1 - base;
4d1fd7f1 345#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
e48f3741
SG
346 printf("%s at 0x%p (%#0*"PRIx64") != %s at 0x%p (%#0*"
347 PRIx64 ")\n",
4d1fd7f1
YS
348 type, (void *)(addr1 + offset), size, word1,
349 type, (void *)(addr2 + offset), size, word2);
350#else
054ea170 351 printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n",
0628ab8e
SG
352 type, (ulong)(addr1 + offset), size, word1,
353 type, (ulong)(addr2 + offset), size, word2);
4d1fd7f1 354#endif
054ea170
MF
355 rcode = 1;
356 break;
3863585b 357 }
054ea170 358
0628ab8e
SG
359 buf1 += size;
360 buf2 += size;
eaadb44e
SR
361
362 /* reset watchdog from time to time */
feb12a1f 363 if ((ngood % (64 << 10)) == 0)
eaadb44e 364 WATCHDOG_RESET();
3863585b 365 }
0628ab8e
SG
366 unmap_sysmem(buf1);
367 unmap_sysmem(buf2);
3863585b 368
054ea170 369 printf("Total of %ld %s(s) were the same\n", ngood, type);
3863585b
WD
370 return rcode;
371}
372
088f1b19 373static int do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
3863585b 374{
c2538421 375 ulong addr, dest, count;
27b207fd 376 int size;
3863585b 377
47e26b1b 378 if (argc != 4)
4c12eeb8 379 return CMD_RET_USAGE;
3863585b
WD
380
381 /* Check for size specification.
382 */
27b207fd
WD
383 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
384 return 1;
3863585b
WD
385
386 addr = simple_strtoul(argv[1], NULL, 16);
387 addr += base_address;
388
389 dest = simple_strtoul(argv[2], NULL, 16);
390 dest += base_address;
391
392 count = simple_strtoul(argv[3], NULL, 16);
393
394 if (count == 0) {
395 puts ("Zero length ???\n");
396 return 1;
397 }
398
e856bdcf 399#ifdef CONFIG_MTD_NOR_FLASH
3863585b 400 /* check if we are copying to Flash */
2abbe075
WD
401 if ( (addr2info(dest) != NULL)
402#ifdef CONFIG_HAS_DATAFLASH
84d0c2f1 403 && (!addr_dataflash(dest))
2abbe075
WD
404#endif
405 ) {
3863585b
WD
406 int rc;
407
4b9206ed 408 puts ("Copy to Flash... ");
3863585b 409
77ddac94 410 rc = flash_write ((char *)addr, dest, count*size);
3863585b
WD
411 if (rc != 0) {
412 flash_perror (rc);
413 return (1);
414 }
415 puts ("done\n");
416 return 0;
417 }
418#endif
419
2abbe075
WD
420#ifdef CONFIG_HAS_DATAFLASH
421 /* Check if we are copying from RAM or Flash to DataFlash */
422 if (addr_dataflash(dest) && !addr_dataflash(addr)){
423 int rc;
424
4b9206ed 425 puts ("Copy to DataFlash... ");
2abbe075
WD
426
427 rc = write_dataflash (dest, addr, count*size);
428
429 if (rc != 1) {
430 dataflash_perror (rc);
431 return (1);
432 }
433 puts ("done\n");
434 return 0;
435 }
8bde7f77 436
2abbe075 437 /* Check if we are copying from DataFlash to RAM */
880cc438 438 if (addr_dataflash(addr) && !addr_dataflash(dest)
e856bdcf 439#ifdef CONFIG_MTD_NOR_FLASH
880cc438
SP
440 && (addr2info(dest) == NULL)
441#endif
442 ){
5779d8d9
WD
443 int rc;
444 rc = read_dataflash(addr, count * size, (char *) dest);
445 if (rc != 1) {
d4ca31c4
WD
446 dataflash_perror (rc);
447 return (1);
448 }
2abbe075
WD
449 return 0;
450 }
451
452 if (addr_dataflash(addr) && addr_dataflash(dest)){
4b9206ed 453 puts ("Unsupported combination of source/destination.\n\r");
2abbe075
WD
454 return 1;
455 }
456#endif
457
4c727c77
MF
458#ifdef CONFIG_BLACKFIN
459 /* See if we're copying to/from L1 inst */
460 if (addr_bfin_on_chip_mem(dest) || addr_bfin_on_chip_mem(addr)) {
461 memcpy((void *)dest, (void *)addr, count * size);
462 return 0;
463 }
464#endif
465
c2538421 466 memcpy((void *)dest, (void *)addr, count * size);
a3a4749d 467
3863585b
WD
468 return 0;
469}
470
088f1b19
KP
471static int do_mem_base(cmd_tbl_t *cmdtp, int flag, int argc,
472 char * const argv[])
3863585b
WD
473{
474 if (argc > 1) {
475 /* Set new base address.
476 */
477 base_address = simple_strtoul(argv[1], NULL, 16);
478 }
479 /* Print the current base address.
480 */
481 printf("Base Address: 0x%08lx\n", base_address);
482 return 0;
483}
484
088f1b19
KP
485static int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc,
486 char * const argv[])
3863585b 487{
0628ab8e 488 ulong addr, length, i, bytes;
27b207fd 489 int size;
4d1fd7f1
YS
490#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
491 volatile u64 *llp;
492#endif
76698b4e
YS
493 volatile u32 *longp;
494 volatile u16 *shortp;
495 volatile u8 *cp;
0628ab8e 496 const void *buf;
3863585b 497
47e26b1b 498 if (argc < 3)
4c12eeb8 499 return CMD_RET_USAGE;
3863585b 500
85de63e2
RD
501 /*
502 * Check for a size specification.
3863585b
WD
503 * Defaults to long if no or incorrect specification.
504 */
27b207fd
WD
505 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
506 return 1;
3863585b
WD
507
508 /* Address is always specified.
509 */
510 addr = simple_strtoul(argv[1], NULL, 16);
511
512 /* Length is the number of objects, not number of bytes.
513 */
514 length = simple_strtoul(argv[2], NULL, 16);
515
0628ab8e
SG
516 bytes = size * length;
517 buf = map_sysmem(addr, bytes);
518
3863585b
WD
519 /* We want to optimize the loops to run as fast as possible.
520 * If we have only one object, just run infinite loops.
521 */
522 if (length == 1) {
4d1fd7f1
YS
523#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
524 if (size == 8) {
525 llp = (u64 *)buf;
526 for (;;)
527 i = *llp;
528 }
529#endif
3863585b 530 if (size == 4) {
76698b4e 531 longp = (u32 *)buf;
3863585b
WD
532 for (;;)
533 i = *longp;
534 }
535 if (size == 2) {
76698b4e 536 shortp = (u16 *)buf;
3863585b
WD
537 for (;;)
538 i = *shortp;
539 }
76698b4e 540 cp = (u8 *)buf;
3863585b
WD
541 for (;;)
542 i = *cp;
543 }
544
4d1fd7f1
YS
545#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
546 if (size == 8) {
547 for (;;) {
548 llp = (u64 *)buf;
549 i = length;
550 while (i-- > 0)
551 *llp++;
552 }
553 }
554#endif
3863585b
WD
555 if (size == 4) {
556 for (;;) {
76698b4e 557 longp = (u32 *)buf;
3863585b
WD
558 i = length;
559 while (i-- > 0)
f3b3c3df 560 *longp++;
3863585b
WD
561 }
562 }
563 if (size == 2) {
564 for (;;) {
76698b4e 565 shortp = (u16 *)buf;
3863585b
WD
566 i = length;
567 while (i-- > 0)
f3b3c3df 568 *shortp++;
3863585b
WD
569 }
570 }
571 for (;;) {
76698b4e 572 cp = (u8 *)buf;
3863585b
WD
573 i = length;
574 while (i-- > 0)
f3b3c3df 575 *cp++;
3863585b 576 }
0628ab8e 577 unmap_sysmem(buf);
92765f42
SG
578
579 return 0;
3863585b
WD
580}
581
56523f12 582#ifdef CONFIG_LOOPW
5a8608e5
MY
583static int do_mem_loopw(cmd_tbl_t *cmdtp, int flag, int argc,
584 char * const argv[])
56523f12 585{
4d1fd7f1 586 ulong addr, length, i, bytes;
56523f12 587 int size;
4d1fd7f1
YS
588#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
589 volatile u64 *llp;
590 u64 data;
591#else
592 ulong data;
593#endif
76698b4e
YS
594 volatile u32 *longp;
595 volatile u16 *shortp;
596 volatile u8 *cp;
0628ab8e 597 void *buf;
81050926 598
47e26b1b 599 if (argc < 4)
4c12eeb8 600 return CMD_RET_USAGE;
56523f12 601
85de63e2
RD
602 /*
603 * Check for a size specification.
56523f12
WD
604 * Defaults to long if no or incorrect specification.
605 */
606 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
607 return 1;
608
609 /* Address is always specified.
610 */
611 addr = simple_strtoul(argv[1], NULL, 16);
612
613 /* Length is the number of objects, not number of bytes.
614 */
615 length = simple_strtoul(argv[2], NULL, 16);
616
617 /* data to write */
4d1fd7f1
YS
618#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
619 data = simple_strtoull(argv[3], NULL, 16);
620#else
56523f12 621 data = simple_strtoul(argv[3], NULL, 16);
4d1fd7f1 622#endif
81050926 623
0628ab8e
SG
624 bytes = size * length;
625 buf = map_sysmem(addr, bytes);
626
56523f12
WD
627 /* We want to optimize the loops to run as fast as possible.
628 * If we have only one object, just run infinite loops.
629 */
630 if (length == 1) {
4d1fd7f1
YS
631#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
632 if (size == 8) {
633 llp = (u64 *)buf;
634 for (;;)
635 *llp = data;
636 }
637#endif
56523f12 638 if (size == 4) {
76698b4e 639 longp = (u32 *)buf;
56523f12
WD
640 for (;;)
641 *longp = data;
4d1fd7f1 642 }
56523f12 643 if (size == 2) {
76698b4e 644 shortp = (u16 *)buf;
56523f12
WD
645 for (;;)
646 *shortp = data;
647 }
76698b4e 648 cp = (u8 *)buf;
56523f12
WD
649 for (;;)
650 *cp = data;
651 }
652
4d1fd7f1
YS
653#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
654 if (size == 8) {
655 for (;;) {
656 llp = (u64 *)buf;
657 i = length;
658 while (i-- > 0)
659 *llp++ = data;
660 }
661 }
662#endif
56523f12
WD
663 if (size == 4) {
664 for (;;) {
76698b4e 665 longp = (u32 *)buf;
56523f12
WD
666 i = length;
667 while (i-- > 0)
668 *longp++ = data;
669 }
670 }
671 if (size == 2) {
672 for (;;) {
76698b4e 673 shortp = (u16 *)buf;
56523f12
WD
674 i = length;
675 while (i-- > 0)
676 *shortp++ = data;
677 }
678 }
679 for (;;) {
76698b4e 680 cp = (u8 *)buf;
56523f12
WD
681 i = length;
682 while (i-- > 0)
683 *cp++ = data;
684 }
685}
686#endif /* CONFIG_LOOPW */
687
68149e94 688#ifdef CONFIG_CMD_MEMTEST
5512d5b0
SG
689static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr,
690 vu_long *dummy)
3863585b 691{
c9638f50 692 vu_long *addr;
c9638f50
SG
693 ulong errs = 0;
694 ulong val, readback;
695 int j;
c9638f50
SG
696 vu_long offset;
697 vu_long test_offset;
698 vu_long pattern;
699 vu_long temp;
700 vu_long anti_pattern;
701 vu_long num_words;
3863585b
WD
702 static const ulong bitpattern[] = {
703 0x00000001, /* single bit */
704 0x00000003, /* two adjacent bits */
705 0x00000007, /* three adjacent bits */
706 0x0000000F, /* four adjacent bits */
707 0x00000005, /* two non-adjacent bits */
708 0x00000015, /* three non-adjacent bits */
709 0x00000055, /* four non-adjacent bits */
710 0xaaaaaaaa, /* alternating 1/0 */
711 };
3863585b 712
5512d5b0 713 num_words = (end_addr - start_addr) / sizeof(vu_long);
8c86bbe0 714
7ecbd4d7
SG
715 /*
716 * Data line test: write a pattern to the first
717 * location, write the 1's complement to a 'parking'
718 * address (changes the state of the data bus so a
719 * floating bus doesn't give a false OK), and then
720 * read the value back. Note that we read it back
721 * into a variable because the next time we read it,
722 * it might be right (been there, tough to explain to
723 * the quality guys why it prints a failure when the
724 * "is" and "should be" are obviously the same in the
725 * error message).
726 *
727 * Rather than exhaustively testing, we test some
728 * patterns by shifting '1' bits through a field of
729 * '0's and '0' bits through a field of '1's (i.e.
730 * pattern and ~pattern).
731 */
5512d5b0 732 addr = buf;
7ecbd4d7
SG
733 for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) {
734 val = bitpattern[j];
735 for (; val != 0; val <<= 1) {
5512d5b0 736 *addr = val;
c9638f50 737 *dummy = ~val; /* clear the test data off the bus */
3863585b 738 readback = *addr;
7ecbd4d7 739 if (readback != val) {
c9638f50
SG
740 printf("FAILURE (data line): "
741 "expected %08lx, actual %08lx\n",
742 val, readback);
743 errs++;
c44d4386 744 if (ctrlc())
51209b1f 745 return -1;
3863585b
WD
746 }
747 *addr = ~val;
748 *dummy = val;
749 readback = *addr;
c9638f50
SG
750 if (readback != ~val) {
751 printf("FAILURE (data line): "
752 "Is %08lx, should be %08lx\n",
753 readback, ~val);
754 errs++;
c44d4386 755 if (ctrlc())
51209b1f 756 return -1;
3863585b 757 }
3863585b 758 }
7ecbd4d7 759 }
3863585b 760
7ecbd4d7
SG
761 /*
762 * Based on code whose Original Author and Copyright
763 * information follows: Copyright (c) 1998 by Michael
764 * Barr. This software is placed into the public
765 * domain and may be used for any purpose. However,
766 * this notice must not be changed or removed and no
767 * warranty is either expressed or implied by its
768 * publication or distribution.
769 */
3863585b 770
7ecbd4d7
SG
771 /*
772 * Address line test
773
774 * Description: Test the address bus wiring in a
775 * memory region by performing a walking
776 * 1's test on the relevant bits of the
777 * address and checking for aliasing.
778 * This test will find single-bit
779 * address failures such as stuck-high,
780 * stuck-low, and shorted pins. The base
781 * address and size of the region are
782 * selected by the caller.
783
784 * Notes: For best results, the selected base
785 * address should have enough LSB 0's to
786 * guarantee single address bit changes.
787 * For example, to test a 64-Kbyte
788 * region, select a base address on a
789 * 64-Kbyte boundary. Also, select the
790 * region size as a power-of-two if at
791 * all possible.
792 *
793 * Returns: 0 if the test succeeds, 1 if the test fails.
794 */
7ecbd4d7
SG
795 pattern = (vu_long) 0xaaaaaaaa;
796 anti_pattern = (vu_long) 0x55555555;
3863585b 797
5512d5b0 798 debug("%s:%d: length = 0x%.8lx\n", __func__, __LINE__, num_words);
7ecbd4d7
SG
799 /*
800 * Write the default pattern at each of the
801 * power-of-two offsets.
802 */
5512d5b0
SG
803 for (offset = 1; offset < num_words; offset <<= 1)
804 addr[offset] = pattern;
3863585b 805
7ecbd4d7
SG
806 /*
807 * Check for address bits stuck high.
808 */
809 test_offset = 0;
5512d5b0 810 addr[test_offset] = anti_pattern;
3863585b 811
5512d5b0
SG
812 for (offset = 1; offset < num_words; offset <<= 1) {
813 temp = addr[offset];
7ecbd4d7 814 if (temp != pattern) {
c9638f50 815 printf("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
3863585b 816 " expected 0x%.8lx, actual 0x%.8lx\n",
102c051f
DF
817 start_addr + offset*sizeof(vu_long),
818 pattern, temp);
87b22b77 819 errs++;
c44d4386 820 if (ctrlc())
7ecbd4d7 821 return -1;
3863585b 822 }
7ecbd4d7 823 }
5512d5b0 824 addr[test_offset] = pattern;
7ecbd4d7 825 WATCHDOG_RESET();
3863585b 826
7ecbd4d7
SG
827 /*
828 * Check for addr bits stuck low or shorted.
829 */
5512d5b0
SG
830 for (test_offset = 1; test_offset < num_words; test_offset <<= 1) {
831 addr[test_offset] = anti_pattern;
3863585b 832
5512d5b0
SG
833 for (offset = 1; offset < num_words; offset <<= 1) {
834 temp = addr[offset];
3863585b 835 if ((temp != pattern) && (offset != test_offset)) {
7ecbd4d7
SG
836 printf("\nFAILURE: Address bit stuck low or"
837 " shorted @ 0x%.8lx: expected 0x%.8lx,"
838 " actual 0x%.8lx\n",
102c051f
DF
839 start_addr + offset*sizeof(vu_long),
840 pattern, temp);
7ecbd4d7 841 errs++;
c44d4386 842 if (ctrlc())
7ecbd4d7 843 return -1;
3863585b 844 }
3863585b 845 }
5512d5b0 846 addr[test_offset] = pattern;
7ecbd4d7 847 }
3863585b 848
7ecbd4d7
SG
849 /*
850 * Description: Test the integrity of a physical
851 * memory device by performing an
852 * increment/decrement test over the
853 * entire region. In the process every
854 * storage bit in the device is tested
855 * as a zero and a one. The base address
856 * and the size of the region are
857 * selected by the caller.
858 *
859 * Returns: 0 if the test succeeds, 1 if the test fails.
860 */
5512d5b0 861 num_words++;
3863585b 862
7ecbd4d7
SG
863 /*
864 * Fill memory with a known pattern.
865 */
866 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
867 WATCHDOG_RESET();
5512d5b0 868 addr[offset] = pattern;
7ecbd4d7 869 }
3863585b 870
7ecbd4d7
SG
871 /*
872 * Check each location and invert it for the second pass.
873 */
874 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
875 WATCHDOG_RESET();
5512d5b0 876 temp = addr[offset];
7ecbd4d7 877 if (temp != pattern) {
c9638f50 878 printf("\nFAILURE (read/write) @ 0x%.8lx:"
3863585b 879 " expected 0x%.8lx, actual 0x%.8lx)\n",
102c051f
DF
880 start_addr + offset*sizeof(vu_long),
881 pattern, temp);
87b22b77 882 errs++;
c44d4386 883 if (ctrlc())
51209b1f 884 return -1;
3863585b
WD
885 }
886
7ecbd4d7 887 anti_pattern = ~pattern;
5512d5b0 888 addr[offset] = anti_pattern;
7ecbd4d7
SG
889 }
890
891 /*
892 * Check each location for the inverted pattern and zero it.
893 */
894 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
895 WATCHDOG_RESET();
896 anti_pattern = ~pattern;
5512d5b0 897 temp = addr[offset];
7ecbd4d7 898 if (temp != anti_pattern) {
c9638f50 899 printf("\nFAILURE (read/write): @ 0x%.8lx:"
3863585b 900 " expected 0x%.8lx, actual 0x%.8lx)\n",
102c051f
DF
901 start_addr + offset*sizeof(vu_long),
902 anti_pattern, temp);
87b22b77 903 errs++;
c44d4386 904 if (ctrlc())
51209b1f 905 return -1;
3863585b 906 }
5512d5b0 907 addr[offset] = 0;
7ecbd4d7 908 }
51209b1f 909
fea6730e 910 return errs;
c9638f50
SG
911}
912
5512d5b0
SG
913static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr,
914 vu_long pattern, int iteration)
c9638f50 915{
5512d5b0 916 vu_long *end;
c9638f50 917 vu_long *addr;
c9638f50 918 ulong errs = 0;
5512d5b0 919 ulong incr, length;
c9638f50 920 ulong val, readback;
3863585b 921
51209b1f 922 /* Alternate the pattern */
3863585b 923 incr = 1;
51209b1f
SG
924 if (iteration & 1) {
925 incr = -incr;
926 /*
927 * Flip the pattern each time to make lots of zeros and
928 * then, the next time, lots of ones. We decrement
929 * the "negative" patterns and increment the "positive"
930 * patterns to preserve this feature.
931 */
932 if (pattern & 0x80000000)
933 pattern = -pattern; /* complement & increment */
934 else
935 pattern = ~pattern;
936 }
5512d5b0
SG
937 length = (end_addr - start_addr) / sizeof(ulong);
938 end = buf + length;
7ecbd4d7
SG
939 printf("\rPattern %08lX Writing..."
940 "%12s"
941 "\b\b\b\b\b\b\b\b\b\b",
942 pattern, "");
3863585b 943
5512d5b0 944 for (addr = buf, val = pattern; addr < end; addr++) {
7ecbd4d7
SG
945 WATCHDOG_RESET();
946 *addr = val;
947 val += incr;
948 }
3863585b 949
7ecbd4d7 950 puts("Reading...");
3863585b 951
5512d5b0 952 for (addr = buf, val = pattern; addr < end; addr++) {
7ecbd4d7
SG
953 WATCHDOG_RESET();
954 readback = *addr;
955 if (readback != val) {
5512d5b0
SG
956 ulong offset = addr - buf;
957
7ecbd4d7
SG
958 printf("\nMem error @ 0x%08X: "
959 "found %08lX, expected %08lX\n",
102c051f 960 (uint)(uintptr_t)(start_addr + offset*sizeof(vu_long)),
5512d5b0 961 readback, val);
7ecbd4d7 962 errs++;
c44d4386 963 if (ctrlc())
7ecbd4d7 964 return -1;
3863585b 965 }
7ecbd4d7
SG
966 val += incr;
967 }
3863585b 968
fea6730e 969 return errs;
c9638f50
SG
970}
971
972/*
973 * Perform a memory test. A more complete alternative test can be
974 * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
975 * interrupted by ctrl-c or by a failure of one of the sub-tests.
976 */
977static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
978 char * const argv[])
979{
8c86bbe0 980 ulong start, end;
5512d5b0 981 vu_long *buf, *dummy;
adcc5705 982 ulong iteration_limit = 0;
c9638f50 983 int ret;
51209b1f 984 ulong errs = 0; /* number of errors, or -1 if interrupted */
e37f1eb4 985 ulong pattern = 0;
51209b1f 986 int iteration;
c9638f50
SG
987#if defined(CONFIG_SYS_ALT_MEMTEST)
988 const int alt_test = 1;
989#else
990 const int alt_test = 0;
3863585b 991#endif
c9638f50 992
e37f1eb4
PM
993 start = CONFIG_SYS_MEMTEST_START;
994 end = CONFIG_SYS_MEMTEST_END;
995
c9638f50 996 if (argc > 1)
e37f1eb4
PM
997 if (strict_strtoul(argv[1], 16, &start) < 0)
998 return CMD_RET_USAGE;
c9638f50
SG
999
1000 if (argc > 2)
e37f1eb4
PM
1001 if (strict_strtoul(argv[2], 16, &end) < 0)
1002 return CMD_RET_USAGE;
c9638f50
SG
1003
1004 if (argc > 3)
e37f1eb4
PM
1005 if (strict_strtoul(argv[3], 16, &pattern) < 0)
1006 return CMD_RET_USAGE;
c9638f50
SG
1007
1008 if (argc > 4)
e37f1eb4
PM
1009 if (strict_strtoul(argv[4], 16, &iteration_limit) < 0)
1010 return CMD_RET_USAGE;
1011
1012 if (end < start) {
1013 printf("Refusing to do empty test\n");
1014 return -1;
1015 }
c9638f50 1016
dfe461d6 1017 printf("Testing %08lx ... %08lx:\n", start, end);
8c86bbe0
SG
1018 debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__,
1019 start, end);
51209b1f 1020
5512d5b0
SG
1021 buf = map_sysmem(start, end - start);
1022 dummy = map_sysmem(CONFIG_SYS_MEMTEST_SCRATCH, sizeof(vu_long));
51209b1f
SG
1023 for (iteration = 0;
1024 !iteration_limit || iteration < iteration_limit;
1025 iteration++) {
1026 if (ctrlc()) {
51209b1f
SG
1027 errs = -1UL;
1028 break;
1029 }
1030
1031 printf("Iteration: %6d\r", iteration + 1);
1032 debug("\n");
5512d5b0
SG
1033 if (alt_test) {
1034 errs = mem_test_alt(buf, start, end, dummy);
1035 } else {
1036 errs = mem_test_quick(buf, start, end, pattern,
1037 iteration);
1038 }
1039 if (errs == -1UL)
1040 break;
1041 }
1042
1043 /*
1044 * Work-around for eldk-4.2 which gives this warning if we try to
1045 * case in the unmap_sysmem() call:
1046 * warning: initialization discards qualifiers from pointer target type
1047 */
1048 {
1049 void *vbuf = (void *)buf;
1050 void *vdummy = (void *)dummy;
1051
1052 unmap_sysmem(vbuf);
1053 unmap_sysmem(vdummy);
51209b1f
SG
1054 }
1055
1056 if (errs == -1UL) {
c44d4386
SG
1057 /* Memory test was aborted - write a newline to finish off */
1058 putc('\n');
51209b1f
SG
1059 ret = 1;
1060 } else {
1061 printf("Tested %d iteration(s) with %lu errors.\n",
1062 iteration, errs);
1063 ret = errs != 0;
1064 }
c9638f50 1065
e37f1eb4 1066 return ret;
3863585b 1067}
a2681707 1068#endif /* CONFIG_CMD_MEMTEST */
3863585b
WD
1069
1070/* Modify memory.
1071 *
1072 * Syntax:
4d1fd7f1
YS
1073 * mm{.b, .w, .l, .q} {addr}
1074 * nm{.b, .w, .l, .q} {addr}
3863585b
WD
1075 */
1076static int
54841ab5 1077mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
3863585b 1078{
4d1fd7f1
YS
1079 ulong addr;
1080#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1081 u64 i;
1082#else
1083 ulong i;
1084#endif
27b207fd 1085 int nbytes, size;
0628ab8e 1086 void *ptr = NULL;
3863585b 1087
47e26b1b 1088 if (argc != 2)
4c12eeb8 1089 return CMD_RET_USAGE;
3863585b 1090
b26440f1 1091 bootretry_reset_cmd_timeout(); /* got a good command to get here */
3863585b
WD
1092 /* We use the last specified parameters, unless new ones are
1093 * entered.
1094 */
1095 addr = mm_last_addr;
1096 size = mm_last_size;
1097
1098 if ((flag & CMD_FLAG_REPEAT) == 0) {
1099 /* New command specified. Check for a size specification.
1100 * Defaults to long if no or incorrect specification.
1101 */
27b207fd
WD
1102 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
1103 return 1;
3863585b
WD
1104
1105 /* Address is specified since argc > 1
1106 */
1107 addr = simple_strtoul(argv[1], NULL, 16);
1108 addr += base_address;
1109 }
1110
2abbe075
WD
1111#ifdef CONFIG_HAS_DATAFLASH
1112 if (addr_dataflash(addr)){
4b9206ed 1113 puts ("Can't modify DataFlash in place. Use cp instead.\n\r");
2abbe075
WD
1114 return 0;
1115 }
1116#endif
1117
4c727c77
MF
1118#ifdef CONFIG_BLACKFIN
1119 if (addr_bfin_on_chip_mem(addr)) {
1120 puts ("Can't modify L1 instruction in place. Use cp instead.\n\r");
1121 return 0;
1122 }
1123#endif
1124
3863585b
WD
1125 /* Print the address, followed by value. Then accept input for
1126 * the next value. A non-converted value exits.
1127 */
1128 do {
0628ab8e 1129 ptr = map_sysmem(addr, size);
3863585b
WD
1130 printf("%08lx:", addr);
1131 if (size == 4)
76698b4e 1132 printf(" %08x", *((u32 *)ptr));
4d1fd7f1
YS
1133#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1134 else if (size == 8)
e48f3741 1135 printf(" %016" PRIx64, *((u64 *)ptr));
4d1fd7f1 1136#endif
3863585b 1137 else if (size == 2)
76698b4e 1138 printf(" %04x", *((u16 *)ptr));
3863585b 1139 else
76698b4e 1140 printf(" %02x", *((u8 *)ptr));
3863585b 1141
e1bf824d 1142 nbytes = cli_readline(" ? ");
3863585b
WD
1143 if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
1144 /* <CR> pressed as only input, don't modify current
1145 * location and move to next. "-" pressed will go back.
1146 */
1147 if (incrflag)
1148 addr += nbytes ? -size : size;
1149 nbytes = 1;
b26440f1
SG
1150 /* good enough to not time out */
1151 bootretry_reset_cmd_timeout();
3863585b
WD
1152 }
1153#ifdef CONFIG_BOOT_RETRY_TIME
1154 else if (nbytes == -2) {
1155 break; /* timed out, exit the command */
1156 }
1157#endif
1158 else {
1159 char *endp;
4d1fd7f1
YS
1160#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1161 i = simple_strtoull(console_buffer, &endp, 16);
1162#else
3863585b 1163 i = simple_strtoul(console_buffer, &endp, 16);
4d1fd7f1 1164#endif
3863585b
WD
1165 nbytes = endp - console_buffer;
1166 if (nbytes) {
3863585b
WD
1167 /* good enough to not time out
1168 */
b26440f1 1169 bootretry_reset_cmd_timeout();
3863585b 1170 if (size == 4)
76698b4e 1171 *((u32 *)ptr) = i;
4d1fd7f1
YS
1172#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1173 else if (size == 8)
1174 *((u64 *)ptr) = i;
1175#endif
3863585b 1176 else if (size == 2)
76698b4e 1177 *((u16 *)ptr) = i;
3863585b 1178 else
76698b4e 1179 *((u8 *)ptr) = i;
3863585b
WD
1180 if (incrflag)
1181 addr += size;
1182 }
1183 }
1184 } while (nbytes);
0628ab8e
SG
1185 if (ptr)
1186 unmap_sysmem(ptr);
3863585b
WD
1187
1188 mm_last_addr = addr;
1189 mm_last_size = size;
1190 return 0;
1191}
1192
710b9938
MF
1193#ifdef CONFIG_CMD_CRC32
1194
088f1b19 1195static int do_mem_crc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
3863585b 1196{
d20a40de 1197 int flags = 0;
c26e454d 1198 int ac;
54841ab5 1199 char * const *av;
c26e454d 1200
d20a40de 1201 if (argc < 3)
4c12eeb8 1202 return CMD_RET_USAGE;
c26e454d
WD
1203
1204 av = argv + 1;
1205 ac = argc - 1;
d20a40de 1206#ifdef CONFIG_HASH_VERIFY
c26e454d 1207 if (strcmp(*av, "-v") == 0) {
a69bdba9 1208 flags |= HASH_FLAG_VERIFY | HASH_FLAG_ENV;
c26e454d
WD
1209 av++;
1210 ac--;
c26e454d 1211 }
d20a40de 1212#endif
c26e454d 1213
d20a40de 1214 return hash_command("crc32", flags, cmdtp, flag, ac, av);
c26e454d 1215}
c26e454d 1216
710b9938
MF
1217#endif
1218
8bde7f77 1219/**************************************************/
0d498393 1220U_BOOT_CMD(
53677ef1 1221 md, 3, 1, do_mem_md,
2fb2604d 1222 "memory display",
4d1fd7f1
YS
1223#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1224 "[.b, .w, .l, .q] address [# of objects]"
1225#else
a89c33db 1226 "[.b, .w, .l] address [# of objects]"
4d1fd7f1 1227#endif
8bde7f77
WD
1228);
1229
1230
0d498393 1231U_BOOT_CMD(
53677ef1 1232 mm, 2, 1, do_mem_mm,
a89c33db 1233 "memory modify (auto-incrementing address)",
4d1fd7f1
YS
1234#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1235 "[.b, .w, .l, .q] address"
1236#else
a89c33db 1237 "[.b, .w, .l] address"
4d1fd7f1 1238#endif
8bde7f77
WD
1239);
1240
1241
0d498393 1242U_BOOT_CMD(
53677ef1 1243 nm, 2, 1, do_mem_nm,
2fb2604d 1244 "memory modify (constant address)",
4d1fd7f1
YS
1245#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1246 "[.b, .w, .l, .q] address"
1247#else
a89c33db 1248 "[.b, .w, .l] address"
4d1fd7f1 1249#endif
8bde7f77
WD
1250);
1251
0d498393 1252U_BOOT_CMD(
53677ef1 1253 mw, 4, 1, do_mem_mw,
2fb2604d 1254 "memory write (fill)",
4d1fd7f1
YS
1255#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1256 "[.b, .w, .l, .q] address value [count]"
1257#else
a89c33db 1258 "[.b, .w, .l] address value [count]"
4d1fd7f1 1259#endif
8bde7f77
WD
1260);
1261
0d498393 1262U_BOOT_CMD(
53677ef1 1263 cp, 4, 1, do_mem_cp,
2fb2604d 1264 "memory copy",
4d1fd7f1
YS
1265#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1266 "[.b, .w, .l, .q] source target count"
1267#else
a89c33db 1268 "[.b, .w, .l] source target count"
4d1fd7f1 1269#endif
8bde7f77
WD
1270);
1271
0d498393 1272U_BOOT_CMD(
53677ef1 1273 cmp, 4, 1, do_mem_cmp,
2fb2604d 1274 "memory compare",
4d1fd7f1
YS
1275#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1276 "[.b, .w, .l, .q] addr1 addr2 count"
1277#else
a89c33db 1278 "[.b, .w, .l] addr1 addr2 count"
4d1fd7f1 1279#endif
8bde7f77
WD
1280);
1281
710b9938
MF
1282#ifdef CONFIG_CMD_CRC32
1283
849337bb 1284#ifndef CONFIG_HASH_VERIFY
c26e454d 1285
0d498393 1286U_BOOT_CMD(
53677ef1 1287 crc32, 4, 1, do_mem_crc,
2fb2604d 1288 "checksum calculation",
a89c33db 1289 "address count [addr]\n - compute CRC32 checksum [save at addr]"
8bde7f77
WD
1290);
1291
849337bb 1292#else /* CONFIG_HASH_VERIFY */
c26e454d
WD
1293
1294U_BOOT_CMD(
53677ef1 1295 crc32, 5, 1, do_mem_crc,
2fb2604d 1296 "checksum calculation",
c26e454d 1297 "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
a89c33db 1298 "-v address count crc\n - verify crc of memory area"
c26e454d
WD
1299);
1300
849337bb 1301#endif /* CONFIG_HASH_VERIFY */
c26e454d 1302
710b9938
MF
1303#endif
1304
15a33e49 1305#ifdef CONFIG_CMD_MEMINFO
ea11b401 1306__weak void board_show_dram(phys_size_t size)
15a33e49
SG
1307{
1308 puts("DRAM: ");
1309 print_size(size, "\n");
1310}
1311
1312static int do_mem_info(cmd_tbl_t *cmdtp, int flag, int argc,
1313 char * const argv[])
1314{
1315 board_show_dram(gd->ram_size);
1316
1317 return 0;
1318}
1319#endif
1320
0d498393 1321U_BOOT_CMD(
53677ef1 1322 base, 2, 1, do_mem_base,
2fb2604d 1323 "print or set address offset",
8bde7f77 1324 "\n - print address offset for memory commands\n"
a89c33db 1325 "base off\n - set address offset for memory commands to 'off'"
8bde7f77
WD
1326);
1327
0d498393 1328U_BOOT_CMD(
53677ef1 1329 loop, 3, 1, do_mem_loop,
2fb2604d 1330 "infinite loop on address range",
4d1fd7f1
YS
1331#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1332 "[.b, .w, .l, .q] address number_of_objects"
1333#else
a89c33db 1334 "[.b, .w, .l] address number_of_objects"
4d1fd7f1 1335#endif
8bde7f77
WD
1336);
1337
56523f12
WD
1338#ifdef CONFIG_LOOPW
1339U_BOOT_CMD(
53677ef1 1340 loopw, 4, 1, do_mem_loopw,
2fb2604d 1341 "infinite write loop on address range",
4d1fd7f1
YS
1342#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1343 "[.b, .w, .l, .q] address number_of_objects data_to_write"
1344#else
a89c33db 1345 "[.b, .w, .l] address number_of_objects data_to_write"
4d1fd7f1 1346#endif
56523f12
WD
1347);
1348#endif /* CONFIG_LOOPW */
1349
a2681707 1350#ifdef CONFIG_CMD_MEMTEST
0d498393 1351U_BOOT_CMD(
b6fc6fd4 1352 mtest, 5, 1, do_mem_mtest,
a89c33db
WD
1353 "simple RAM read/write test",
1354 "[start [end [pattern [iterations]]]]"
8bde7f77 1355);
a2681707 1356#endif /* CONFIG_CMD_MEMTEST */
8bde7f77 1357
4aaf29b2
SR
1358#ifdef CONFIG_MX_CYCLIC
1359U_BOOT_CMD(
53677ef1 1360 mdc, 4, 1, do_mem_mdc,
2fb2604d 1361 "memory display cyclic",
4d1fd7f1
YS
1362#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1363 "[.b, .w, .l, .q] address count delay(ms)"
1364#else
a89c33db 1365 "[.b, .w, .l] address count delay(ms)"
4d1fd7f1 1366#endif
4aaf29b2
SR
1367);
1368
1369U_BOOT_CMD(
53677ef1 1370 mwc, 4, 1, do_mem_mwc,
2fb2604d 1371 "memory write cyclic",
4d1fd7f1
YS
1372#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1373 "[.b, .w, .l, .q] address value delay(ms)"
1374#else
a89c33db 1375 "[.b, .w, .l] address value delay(ms)"
4d1fd7f1 1376#endif
4aaf29b2
SR
1377);
1378#endif /* CONFIG_MX_CYCLIC */
15a33e49
SG
1379
1380#ifdef CONFIG_CMD_MEMINFO
1381U_BOOT_CMD(
1382 meminfo, 3, 1, do_mem_info,
1383 "display memory information",
1384 ""
1385);
1386#endif