1 // SPDX-License-Identifier: GPL-2.0+
15 #include <bootretry.h>
26 #include <linux/bitops.h>
27 #include <linux/compiler.h>
28 #include <linux/ctype.h>
29 #include <linux/delay.h>
31 DECLARE_GLOBAL_DATA_PTR;
33 /* Create a compile-time value */
34 #ifdef MEM_SUPPORT_64BIT_DATA
35 #define SUPPORT_64BIT_DATA 1
38 #define SUPPORT_64BIT_DATA 0
42 static int mod_mem(struct cmd_tbl *, int, int, int, char * const []);
44 /* Display values from last command.
45 * Memory modify remembered values are different from display memory.
47 static ulong dp_last_addr, dp_last_size;
48 static ulong dp_last_length = 0x40;
49 static ulong mm_last_addr, mm_last_size;
51 static ulong base_address = 0;
52 #ifdef CONFIG_CMD_MEM_SEARCH
53 static ulong dp_last_ms_length;
54 static u8 search_buf[64];
55 static uint search_len;
61 * md{.b, .w, .l, .q} {addr} {len}
63 #define DISP_LINE_LEN 16
64 static int do_mem_md(struct cmd_tbl *cmdtp, int flag, int argc,
67 ulong addr, length, bytes;
72 /* We use the last specified parameters, unless new ones are
77 length = dp_last_length;
82 if ((flag & CMD_FLAG_REPEAT) == 0) {
83 /* New command specified. Check for a size specification.
84 * Defaults to long if no or incorrect specification.
86 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
89 /* Address is specified since argc > 1
91 addr = simple_strtoul(argv[1], NULL, 16);
94 /* If another parameter, it is the length to display.
95 * Length is the number of objects, not number of bytes.
98 length = simple_strtoul(argv[2], NULL, 16);
101 bytes = size * length;
102 buf = map_sysmem(addr, bytes);
104 /* Print the lines. */
105 print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
110 dp_last_length = length;
115 static int do_mem_mm(struct cmd_tbl *cmdtp, int flag, int argc,
118 return mod_mem (cmdtp, 1, flag, argc, argv);
121 static int do_mem_nm(struct cmd_tbl *cmdtp, int flag, int argc,
124 return mod_mem (cmdtp, 0, flag, argc, argv);
127 static int do_mem_mw(struct cmd_tbl *cmdtp, int flag, int argc,
130 ulong writeval; /* 64-bit if SUPPORT_64BIT_DATA */
136 if ((argc < 3) || (argc > 4))
137 return CMD_RET_USAGE;
139 /* Check for size specification.
141 if ((size = cmd_get_data_size(argv[0], 4)) < 1)
144 /* Address is specified since argc > 1
146 addr = simple_strtoul(argv[1], NULL, 16);
147 addr += base_address;
149 /* Get the value to write.
151 if (SUPPORT_64BIT_DATA)
152 writeval = simple_strtoull(argv[2], NULL, 16);
154 writeval = simple_strtoul(argv[2], NULL, 16);
158 count = simple_strtoul(argv[3], NULL, 16);
163 bytes = size * count;
164 start = map_sysmem(addr, bytes);
166 while (count-- > 0) {
168 *((u32 *)buf) = (u32)writeval;
169 else if (SUPPORT_64BIT_DATA && size == 8)
170 *((ulong *)buf) = writeval;
172 *((u16 *)buf) = (u16)writeval;
174 *((u8 *)buf) = (u8)writeval;
181 #ifdef CONFIG_CMD_MX_CYCLIC
182 static int do_mem_mdc(struct cmd_tbl *cmdtp, int flag, int argc,
189 return CMD_RET_USAGE;
191 count = simple_strtoul(argv[3], NULL, 10);
194 do_mem_md (NULL, 0, 3, argv);
196 /* delay for <count> ms... */
197 for (i=0; i<count; i++)
200 /* check for ctrl-c to abort... */
210 static int do_mem_mwc(struct cmd_tbl *cmdtp, int flag, int argc,
217 return CMD_RET_USAGE;
219 count = simple_strtoul(argv[3], NULL, 10);
222 do_mem_mw (NULL, 0, 3, argv);
224 /* delay for <count> ms... */
225 for (i=0; i<count; i++)
228 /* check for ctrl-c to abort... */
237 #endif /* CONFIG_CMD_MX_CYCLIC */
239 static int do_mem_cmp(struct cmd_tbl *cmdtp, int flag, int argc,
242 ulong addr1, addr2, count, ngood, bytes;
246 const void *buf1, *buf2, *base;
247 ulong word1, word2; /* 64-bit if SUPPORT_64BIT_DATA */
250 return CMD_RET_USAGE;
252 /* Check for size specification.
254 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
256 type = size == 8 ? "double word" :
258 size == 2 ? "halfword" : "byte";
260 addr1 = simple_strtoul(argv[1], NULL, 16);
261 addr1 += base_address;
263 addr2 = simple_strtoul(argv[2], NULL, 16);
264 addr2 += base_address;
266 count = simple_strtoul(argv[3], NULL, 16);
268 bytes = size * count;
269 base = buf1 = map_sysmem(addr1, bytes);
270 buf2 = map_sysmem(addr2, bytes);
271 for (ngood = 0; ngood < count; ++ngood) {
273 word1 = *(u32 *)buf1;
274 word2 = *(u32 *)buf2;
275 } else if (SUPPORT_64BIT_DATA && size == 8) {
276 word1 = *(ulong *)buf1;
277 word2 = *(ulong *)buf2;
278 } else if (size == 2) {
279 word1 = *(u16 *)buf1;
280 word2 = *(u16 *)buf2;
285 if (word1 != word2) {
286 ulong offset = buf1 - base;
287 printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n",
288 type, (ulong)(addr1 + offset), size, word1,
289 type, (ulong)(addr2 + offset), size, word2);
297 /* reset watchdog from time to time */
298 if ((ngood % (64 << 10)) == 0)
304 printf("Total of %ld %s(s) were the same\n", ngood, type);
308 static int do_mem_cp(struct cmd_tbl *cmdtp, int flag, int argc,
311 ulong addr, dest, count;
316 return CMD_RET_USAGE;
318 /* Check for size specification.
320 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
323 addr = simple_strtoul(argv[1], NULL, 16);
324 addr += base_address;
326 dest = simple_strtoul(argv[2], NULL, 16);
327 dest += base_address;
329 count = simple_strtoul(argv[3], NULL, 16);
332 puts ("Zero length ???\n");
336 src = map_sysmem(addr, count * size);
337 dst = map_sysmem(dest, count * size);
339 #ifdef CONFIG_MTD_NOR_FLASH
340 /* check if we are copying to Flash */
341 if (addr2info((ulong)dst)) {
344 puts ("Copy to Flash... ");
346 rc = flash_write((char *)src, (ulong)dst, count * size);
360 memcpy(dst, src, count * size);
367 #ifdef CONFIG_CMD_MEM_SEARCH
368 static int do_mem_search(struct cmd_tbl *cmdtp, int flag, int argc,
371 ulong addr, length, bytes, offset;
374 ulong last_pos; /* Offset of last match in 'size' units*/
375 ulong last_addr; /* Address of last displayed line */
382 /* We use the last specified parameters, unless new ones are entered */
385 length = dp_last_ms_length;
388 return CMD_RET_USAGE;
390 if (!(flag & CMD_FLAG_REPEAT)) {
392 * Check for a size specification.
393 * Defaults to long if no or incorrect specification.
395 size = cmd_get_data_size(argv[0], 4);
396 if (size < 0 && size != -2 /* string */)
401 while (argc && *argv[0] == '-') {
406 else if (ch == 'l' && isxdigit(argv[0][2]))
407 limit = simple_strtoul(argv[0] + 2, NULL, 16);
409 return CMD_RET_USAGE;
414 /* Address is specified since argc > 1 */
415 addr = simple_strtoul(argv[0], NULL, 16);
416 addr += base_address;
418 /* Length is the number of objects, not number of bytes */
419 length = simple_strtoul(argv[1], NULL, 16);
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 (MEM_SUPPORT_64BIT_DATA && size == 8) {
425 u64 val = simple_strtoull(argv[i], NULL, 16);
428 } else if (size == -2) { /* string */
429 int len = min(strlen(argv[i]),
430 (size_t)(end - ptr));
432 memcpy(ptr, argv[i], len);
436 u32 val = simple_strtoul(argv[i], NULL, 16);
452 search_len = ptr - search_buf;
458 bytes = size * length;
459 buf = map_sysmem(addr, bytes);
464 offset < bytes && offset <= bytes - search_len && count < limit;
466 void *ptr = buf + offset;
468 if (!memcmp(ptr, search_buf, search_len)) {
469 uint align = (addr + offset) & 0xf;
470 ulong match = addr + offset;
472 if (!count || (last_addr & ~0xf) != (match & ~0xf)) {
476 print_buffer(match - align, ptr - align,
478 ALIGN(search_len + align,
482 last_pos = offset / size;
488 printf("%d match%s", count, count == 1 ? "" : "es");
490 printf(" (repeat command to check for more)");
493 env_set_hex("memmatches", count);
494 env_set_hex("memaddr", last_addr);
495 env_set_hex("mempos", last_pos);
499 used_len = offset / size;
500 dp_last_addr = addr + used_len;
502 dp_last_ms_length = length < used_len ? 0 : length - used_len;
504 return count ? 0 : CMD_RET_FAILURE;
508 static int do_mem_base(struct cmd_tbl *cmdtp, int flag, int argc,
512 /* Set new base address.
514 base_address = simple_strtoul(argv[1], NULL, 16);
516 /* Print the current base address.
518 printf("Base Address: 0x%08lx\n", base_address);
522 static int do_mem_loop(struct cmd_tbl *cmdtp, int flag, int argc,
525 ulong addr, length, i, bytes;
527 volatile ulong *llp; /* 64-bit if SUPPORT_64BIT_DATA */
529 volatile u16 *shortp;
534 return CMD_RET_USAGE;
537 * Check for a size specification.
538 * Defaults to long if no or incorrect specification.
540 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
543 /* Address is always specified.
545 addr = simple_strtoul(argv[1], NULL, 16);
547 /* Length is the number of objects, not number of bytes.
549 length = simple_strtoul(argv[2], NULL, 16);
551 bytes = size * length;
552 buf = map_sysmem(addr, bytes);
554 /* We want to optimize the loops to run as fast as possible.
555 * If we have only one object, just run infinite loops.
558 if (SUPPORT_64BIT_DATA && size == 8) {
578 if (SUPPORT_64BIT_DATA && size == 8) {
614 static int do_mem_loopw(struct cmd_tbl *cmdtp, int flag, int argc,
617 ulong addr, length, i, bytes;
619 volatile ulong *llp; /* 64-bit if SUPPORT_64BIT_DATA */
620 ulong data; /* 64-bit if SUPPORT_64BIT_DATA */
622 volatile u16 *shortp;
627 return CMD_RET_USAGE;
630 * Check for a size specification.
631 * Defaults to long if no or incorrect specification.
633 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
636 /* Address is always specified.
638 addr = simple_strtoul(argv[1], NULL, 16);
640 /* Length is the number of objects, not number of bytes.
642 length = simple_strtoul(argv[2], NULL, 16);
645 if (SUPPORT_64BIT_DATA)
646 data = simple_strtoull(argv[3], NULL, 16);
648 data = simple_strtoul(argv[3], NULL, 16);
650 bytes = size * length;
651 buf = map_sysmem(addr, bytes);
653 /* We want to optimize the loops to run as fast as possible.
654 * If we have only one object, just run infinite loops.
657 if (SUPPORT_64BIT_DATA && size == 8) {
677 if (SUPPORT_64BIT_DATA && size == 8) {
708 #endif /* CONFIG_LOOPW */
710 #ifdef CONFIG_CMD_MEMTEST
711 static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr,
722 vu_long anti_pattern;
724 static const ulong bitpattern[] = {
725 0x00000001, /* single bit */
726 0x00000003, /* two adjacent bits */
727 0x00000007, /* three adjacent bits */
728 0x0000000F, /* four adjacent bits */
729 0x00000005, /* two non-adjacent bits */
730 0x00000015, /* three non-adjacent bits */
731 0x00000055, /* four non-adjacent bits */
732 0xaaaaaaaa, /* alternating 1/0 */
735 num_words = (end_addr - start_addr) / sizeof(vu_long);
738 * Data line test: write a pattern to the first
739 * location, write the 1's complement to a 'parking'
740 * address (changes the state of the data bus so a
741 * floating bus doesn't give a false OK), and then
742 * read the value back. Note that we read it back
743 * into a variable because the next time we read it,
744 * it might be right (been there, tough to explain to
745 * the quality guys why it prints a failure when the
746 * "is" and "should be" are obviously the same in the
749 * Rather than exhaustively testing, we test some
750 * patterns by shifting '1' bits through a field of
751 * '0's and '0' bits through a field of '1's (i.e.
752 * pattern and ~pattern).
755 for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) {
757 for (; val != 0; val <<= 1) {
759 *dummy = ~val; /* clear the test data off the bus */
761 if (readback != val) {
762 printf("FAILURE (data line): "
763 "expected %08lx, actual %08lx\n",
772 if (readback != ~val) {
773 printf("FAILURE (data line): "
774 "Is %08lx, should be %08lx\n",
784 * Based on code whose Original Author and Copyright
785 * information follows: Copyright (c) 1998 by Michael
786 * Barr. This software is placed into the public
787 * domain and may be used for any purpose. However,
788 * this notice must not be changed or removed and no
789 * warranty is either expressed or implied by its
790 * publication or distribution.
796 * Description: Test the address bus wiring in a
797 * memory region by performing a walking
798 * 1's test on the relevant bits of the
799 * address and checking for aliasing.
800 * This test will find single-bit
801 * address failures such as stuck-high,
802 * stuck-low, and shorted pins. The base
803 * address and size of the region are
804 * selected by the caller.
806 * Notes: For best results, the selected base
807 * address should have enough LSB 0's to
808 * guarantee single address bit changes.
809 * For example, to test a 64-Kbyte
810 * region, select a base address on a
811 * 64-Kbyte boundary. Also, select the
812 * region size as a power-of-two if at
815 * Returns: 0 if the test succeeds, 1 if the test fails.
817 pattern = (vu_long) 0xaaaaaaaa;
818 anti_pattern = (vu_long) 0x55555555;
820 debug("%s:%d: length = 0x%.8lx\n", __func__, __LINE__, num_words);
822 * Write the default pattern at each of the
823 * power-of-two offsets.
825 for (offset = 1; offset < num_words; offset <<= 1)
826 addr[offset] = pattern;
829 * Check for address bits stuck high.
832 addr[test_offset] = anti_pattern;
834 for (offset = 1; offset < num_words; offset <<= 1) {
836 if (temp != pattern) {
837 printf("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
838 " expected 0x%.8lx, actual 0x%.8lx\n",
839 start_addr + offset*sizeof(vu_long),
846 addr[test_offset] = pattern;
850 * Check for addr bits stuck low or shorted.
852 for (test_offset = 1; test_offset < num_words; test_offset <<= 1) {
853 addr[test_offset] = anti_pattern;
855 for (offset = 1; offset < num_words; offset <<= 1) {
857 if ((temp != pattern) && (offset != test_offset)) {
858 printf("\nFAILURE: Address bit stuck low or"
859 " shorted @ 0x%.8lx: expected 0x%.8lx,"
861 start_addr + offset*sizeof(vu_long),
868 addr[test_offset] = pattern;
872 * Description: Test the integrity of a physical
873 * memory device by performing an
874 * increment/decrement test over the
875 * entire region. In the process every
876 * storage bit in the device is tested
877 * as a zero and a one. The base address
878 * and the size of the region are
879 * selected by the caller.
881 * Returns: 0 if the test succeeds, 1 if the test fails.
886 * Fill memory with a known pattern.
888 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
890 addr[offset] = pattern;
894 * Check each location and invert it for the second pass.
896 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
899 if (temp != pattern) {
900 printf("\nFAILURE (read/write) @ 0x%.8lx:"
901 " expected 0x%.8lx, actual 0x%.8lx)\n",
902 start_addr + offset*sizeof(vu_long),
909 anti_pattern = ~pattern;
910 addr[offset] = anti_pattern;
914 * Check each location for the inverted pattern and zero it.
916 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
918 anti_pattern = ~pattern;
920 if (temp != anti_pattern) {
921 printf("\nFAILURE (read/write): @ 0x%.8lx:"
922 " expected 0x%.8lx, actual 0x%.8lx)\n",
923 start_addr + offset*sizeof(vu_long),
935 static int compare_regions(volatile unsigned long *bufa,
936 volatile unsigned long *bufb, size_t count)
938 volatile unsigned long *p1 = bufa;
939 volatile unsigned long *p2 = bufb;
943 for (i = 0; i < count; i++, p1++, p2++) {
945 printf("FAILURE: 0x%08lx != 0x%08lx (delta=0x%08lx -> bit %ld) at offset 0x%08lx\n",
946 (unsigned long)*p1, (unsigned long)*p2,
947 *p1 ^ *p2, __ffs(*p1 ^ *p2),
948 (unsigned long)(i * sizeof(unsigned long)));
956 static ulong test_bitflip_comparison(volatile unsigned long *bufa,
957 volatile unsigned long *bufb, size_t count)
959 volatile unsigned long *p1 = bufa;
960 volatile unsigned long *p2 = bufb;
967 max = sizeof(unsigned long) * 8;
968 for (k = 0; k < max; k++) {
969 q = 0x00000001L << k;
970 for (j = 0; j < 8; j++) {
973 p1 = (volatile unsigned long *)bufa;
974 p2 = (volatile unsigned long *)bufb;
975 for (i = 0; i < count; i++)
976 *p1++ = *p2++ = (i % 2) == 0 ? q : ~q;
978 errs += compare_regions(bufa, bufb, count);
988 static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr,
989 vu_long pattern, int iteration)
997 /* Alternate the pattern */
1002 * Flip the pattern each time to make lots of zeros and
1003 * then, the next time, lots of ones. We decrement
1004 * the "negative" patterns and increment the "positive"
1005 * patterns to preserve this feature.
1007 if (pattern & 0x80000000)
1008 pattern = -pattern; /* complement & increment */
1012 length = (end_addr - start_addr) / sizeof(ulong);
1014 printf("\rPattern %08lX Writing..."
1016 "\b\b\b\b\b\b\b\b\b\b",
1019 for (addr = buf, val = pattern; addr < end; addr++) {
1027 for (addr = buf, val = pattern; addr < end; addr++) {
1030 if (readback != val) {
1031 ulong offset = addr - buf;
1033 printf("\nMem error @ 0x%08X: "
1034 "found %08lX, expected %08lX\n",
1035 (uint)(uintptr_t)(start_addr + offset*sizeof(vu_long)),
1048 * Perform a memory test. A more complete alternative test can be
1049 * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
1050 * interrupted by ctrl-c or by a failure of one of the sub-tests.
1052 static int do_mem_mtest(struct cmd_tbl *cmdtp, int flag, int argc,
1056 vu_long scratch_space;
1057 vu_long *buf, *dummy = &scratch_space;
1058 ulong iteration_limit = 0;
1060 ulong errs = 0; /* number of errors, or -1 if interrupted */
1064 start = CONFIG_SYS_MEMTEST_START;
1065 end = CONFIG_SYS_MEMTEST_END;
1068 if (strict_strtoul(argv[1], 16, &start) < 0)
1069 return CMD_RET_USAGE;
1072 if (strict_strtoul(argv[2], 16, &end) < 0)
1073 return CMD_RET_USAGE;
1076 if (strict_strtoul(argv[3], 16, &pattern) < 0)
1077 return CMD_RET_USAGE;
1080 if (strict_strtoul(argv[4], 16, &iteration_limit) < 0)
1081 return CMD_RET_USAGE;
1084 printf("Refusing to do empty test\n");
1088 printf("Testing %08lx ... %08lx:\n", start, end);
1089 debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__,
1092 buf = map_sysmem(start, end - start);
1094 !iteration_limit || iteration < iteration_limit;
1101 printf("Iteration: %6d\r", iteration + 1);
1103 if (IS_ENABLED(CONFIG_SYS_ALT_MEMTEST)) {
1104 errs = mem_test_alt(buf, start, end, dummy);
1108 errs = test_bitflip_comparison(buf,
1109 buf + (end - start) / 2,
1111 sizeof(unsigned long));
1113 errs = mem_test_quick(buf, start, end, pattern,
1121 unmap_sysmem((void *)buf);
1124 /* Memory test was aborted - write a newline to finish off */
1127 printf("Tested %d iteration(s) with %lu errors.\n", iteration, count);
1131 #endif /* CONFIG_CMD_MEMTEST */
1136 * mm{.b, .w, .l, .q} {addr}
1139 mod_mem(struct cmd_tbl *cmdtp, int incrflag, int flag, int argc,
1143 ulong i; /* 64-bit if SUPPORT_64BIT_DATA */
1148 return CMD_RET_USAGE;
1150 bootretry_reset_cmd_timeout(); /* got a good command to get here */
1151 /* We use the last specified parameters, unless new ones are
1154 addr = mm_last_addr;
1155 size = mm_last_size;
1157 if ((flag & CMD_FLAG_REPEAT) == 0) {
1158 /* New command specified. Check for a size specification.
1159 * Defaults to long if no or incorrect specification.
1161 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
1164 /* Address is specified since argc > 1
1166 addr = simple_strtoul(argv[1], NULL, 16);
1167 addr += base_address;
1170 /* Print the address, followed by value. Then accept input for
1171 * the next value. A non-converted value exits.
1174 ptr = map_sysmem(addr, size);
1175 printf("%08lx:", addr);
1177 printf(" %08x", *((u32 *)ptr));
1178 else if (SUPPORT_64BIT_DATA && size == 8)
1179 printf(" %0lx", *((ulong *)ptr));
1181 printf(" %04x", *((u16 *)ptr));
1183 printf(" %02x", *((u8 *)ptr));
1185 nbytes = cli_readline(" ? ");
1186 if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
1187 /* <CR> pressed as only input, don't modify current
1188 * location and move to next. "-" pressed will go back.
1191 addr += nbytes ? -size : size;
1193 /* good enough to not time out */
1194 bootretry_reset_cmd_timeout();
1196 #ifdef CONFIG_BOOT_RETRY_TIME
1197 else if (nbytes == -2) {
1198 break; /* timed out, exit the command */
1203 if (SUPPORT_64BIT_DATA)
1204 i = simple_strtoull(console_buffer, &endp, 16);
1206 i = simple_strtoul(console_buffer, &endp, 16);
1207 nbytes = endp - console_buffer;
1209 /* good enough to not time out
1211 bootretry_reset_cmd_timeout();
1214 else if (SUPPORT_64BIT_DATA && size == 8)
1215 *((ulong *)ptr) = i;
1228 mm_last_addr = addr;
1229 mm_last_size = size;
1233 #ifdef CONFIG_CMD_CRC32
1235 static int do_mem_crc(struct cmd_tbl *cmdtp, int flag, int argc,
1243 return CMD_RET_USAGE;
1247 #ifdef CONFIG_CRC32_VERIFY
1248 if (strcmp(*av, "-v") == 0) {
1249 flags |= HASH_FLAG_VERIFY | HASH_FLAG_ENV;
1255 return hash_command("crc32", flags, cmdtp, flag, ac, av);
1260 #ifdef CONFIG_CMD_RANDOM
1261 static int do_random(struct cmd_tbl *cmdtp, int flag, int argc,
1264 unsigned long addr, len;
1265 unsigned long seed; // NOT INITIALIZED ON PURPOSE
1266 unsigned int *buf, *start;
1267 unsigned char *buf8;
1270 if (argc < 3 || argc > 4)
1271 return CMD_RET_USAGE;
1273 len = simple_strtoul(argv[2], NULL, 16);
1274 addr = simple_strtoul(argv[1], NULL, 16);
1277 seed = simple_strtoul(argv[3], NULL, 16);
1279 printf("The seed cannot be 0. Using 0xDEADBEEF.\n");
1283 seed = get_timer(0) ^ rand();
1287 start = map_sysmem(addr, len);
1289 for (i = 0; i < (len / 4); i++)
1292 buf8 = (unsigned char *)buf;
1293 for (i = 0; i < (len % 4); i++)
1294 *buf8++ = rand() & 0xFF;
1296 unmap_sysmem(start);
1297 printf("%lu bytes filled with random data\n", len);
1299 return CMD_RET_SUCCESS;
1303 /**************************************************/
1305 md, 3, 1, do_mem_md,
1307 "[.b, .w, .l" HELP_Q "] address [# of objects]"
1312 mm, 2, 1, do_mem_mm,
1313 "memory modify (auto-incrementing address)",
1314 "[.b, .w, .l" HELP_Q "] address"
1319 nm, 2, 1, do_mem_nm,
1320 "memory modify (constant address)",
1321 "[.b, .w, .l" HELP_Q "] address"
1325 mw, 4, 1, do_mem_mw,
1326 "memory write (fill)",
1327 "[.b, .w, .l" HELP_Q "] address value [count]"
1331 cp, 4, 1, do_mem_cp,
1333 "[.b, .w, .l" HELP_Q "] source target count"
1337 cmp, 4, 1, do_mem_cmp,
1339 "[.b, .w, .l" HELP_Q "] addr1 addr2 count"
1342 #ifdef CONFIG_CMD_MEM_SEARCH
1343 /**************************************************/
1345 ms, 255, 1, do_mem_search,
1347 "[.b, .w, .l" HELP_Q ", .s] [-q | -<n>] address #-of-objects <value>..."
1348 " -q = quiet, -l<val> = match limit"
1352 #ifdef CONFIG_CMD_CRC32
1354 #ifndef CONFIG_CRC32_VERIFY
1357 crc32, 4, 1, do_mem_crc,
1358 "checksum calculation",
1359 "address count [addr]\n - compute CRC32 checksum [save at addr]"
1362 #else /* CONFIG_CRC32_VERIFY */
1365 crc32, 5, 1, do_mem_crc,
1366 "checksum calculation",
1367 "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
1368 "-v address count crc\n - verify crc of memory area"
1371 #endif /* CONFIG_CRC32_VERIFY */
1375 #ifdef CONFIG_CMD_MEMINFO
1376 static int do_mem_info(struct cmd_tbl *cmdtp, int flag, int argc,
1380 print_size(gd->ram_size, "\n");
1387 base, 2, 1, do_mem_base,
1388 "print or set address offset",
1389 "\n - print address offset for memory commands\n"
1390 "base off\n - set address offset for memory commands to 'off'"
1394 loop, 3, 1, do_mem_loop,
1395 "infinite loop on address range",
1396 "[.b, .w, .l" HELP_Q "] address number_of_objects"
1401 loopw, 4, 1, do_mem_loopw,
1402 "infinite write loop on address range",
1403 "[.b, .w, .l" HELP_Q "] address number_of_objects data_to_write"
1405 #endif /* CONFIG_LOOPW */
1407 #ifdef CONFIG_CMD_MEMTEST
1409 mtest, 5, 1, do_mem_mtest,
1410 "simple RAM read/write test",
1411 "[start [end [pattern [iterations]]]]"
1413 #endif /* CONFIG_CMD_MEMTEST */
1415 #ifdef CONFIG_CMD_MX_CYCLIC
1417 mdc, 4, 1, do_mem_mdc,
1418 "memory display cyclic",
1419 "[.b, .w, .l" HELP_Q "] address count delay(ms)"
1423 mwc, 4, 1, do_mem_mwc,
1424 "memory write cyclic",
1425 "[.b, .w, .l" HELP_Q "] address value delay(ms)"
1427 #endif /* CONFIG_CMD_MX_CYCLIC */
1429 #ifdef CONFIG_CMD_MEMINFO
1431 meminfo, 3, 1, do_mem_info,
1432 "display memory information",
1437 #ifdef CONFIG_CMD_RANDOM
1439 random, 4, 0, do_random,
1440 "fill memory with random pattern",
1441 "<addr> <len> [<seed>]\n"
1442 " - Fill 'len' bytes of memory starting at 'addr' with random data\n"