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