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