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