1 // SPDX-License-Identifier: GPL-2.0+
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
10 * Copied from FADS ROM, Dan Malek (dmalek@jlc.net)
15 #include <bootretry.h>
25 #include <asm/global_data.h>
27 #include <linux/bitops.h>
28 #include <linux/compiler.h>
29 #include <linux/ctype.h>
30 #include <linux/delay.h>
32 DECLARE_GLOBAL_DATA_PTR;
34 /* Create a compile-time value */
35 #ifdef MEM_SUPPORT_64BIT_DATA
36 #define SUPPORT_64BIT_DATA 1
39 #define SUPPORT_64BIT_DATA 0
43 static int mod_mem(struct cmd_tbl *, int, int, int, char * const []);
45 /* Display values from last command.
46 * Memory modify remembered values are different from display memory.
48 static ulong dp_last_addr, dp_last_size;
49 static ulong dp_last_length = 0x40;
50 static ulong mm_last_addr, mm_last_size;
52 static ulong base_address = 0;
53 #ifdef CONFIG_CMD_MEM_SEARCH
54 static ulong dp_last_ms_length;
55 static u8 search_buf[64];
56 static uint search_len;
62 * md{.b, .w, .l, .q} {addr} {len}
64 #define DISP_LINE_LEN 16
65 static int do_mem_md(struct cmd_tbl *cmdtp, int flag, int argc,
68 ulong addr, length, bytes;
73 /* We use the last specified parameters, unless new ones are
78 length = dp_last_length;
83 if ((flag & CMD_FLAG_REPEAT) == 0) {
84 /* New command specified. Check for a size specification.
85 * Defaults to long if no or incorrect specification.
87 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
90 /* Address is specified since argc > 1
92 addr = hextoul(argv[1], NULL);
95 /* If another parameter, it is the length to display.
96 * Length is the number of objects, not number of bytes.
99 length = hextoul(argv[2], NULL);
102 bytes = size * length;
103 buf = map_sysmem(addr, bytes);
105 /* Print the lines. */
106 print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
111 dp_last_length = length;
116 static int do_mem_mm(struct cmd_tbl *cmdtp, int flag, int argc,
119 return mod_mem (cmdtp, 1, flag, argc, argv);
122 static int do_mem_nm(struct cmd_tbl *cmdtp, int flag, int argc,
125 return mod_mem (cmdtp, 0, flag, argc, argv);
128 static int do_mem_mw(struct cmd_tbl *cmdtp, int flag, int argc,
131 ulong writeval; /* 64-bit if SUPPORT_64BIT_DATA */
137 if ((argc < 3) || (argc > 4))
138 return CMD_RET_USAGE;
140 /* Check for size specification.
142 if ((size = cmd_get_data_size(argv[0], 4)) < 1)
145 /* Address is specified since argc > 1
147 addr = hextoul(argv[1], NULL);
148 addr += base_address;
150 /* Get the value to write.
152 if (SUPPORT_64BIT_DATA)
153 writeval = simple_strtoull(argv[2], NULL, 16);
155 writeval = hextoul(argv[2], NULL);
159 count = hextoul(argv[3], NULL);
164 bytes = size * count;
165 start = map_sysmem(addr, bytes);
167 while (count-- > 0) {
169 *((u32 *)buf) = (u32)writeval;
170 else if (SUPPORT_64BIT_DATA && size == 8)
171 *((ulong *)buf) = writeval;
173 *((u16 *)buf) = (u16)writeval;
175 *((u8 *)buf) = (u8)writeval;
182 #ifdef CONFIG_CMD_MX_CYCLIC
183 static int do_mem_mdc(struct cmd_tbl *cmdtp, int flag, int argc,
190 return CMD_RET_USAGE;
192 count = dectoul(argv[3], NULL);
195 do_mem_md (NULL, 0, 3, argv);
197 /* delay for <count> ms... */
198 for (i=0; i<count; i++)
201 /* check for ctrl-c to abort... */
211 static int do_mem_mwc(struct cmd_tbl *cmdtp, int flag, int argc,
218 return CMD_RET_USAGE;
220 count = dectoul(argv[3], NULL);
223 do_mem_mw (NULL, 0, 3, argv);
225 /* delay for <count> ms... */
226 for (i=0; i<count; i++)
229 /* check for ctrl-c to abort... */
238 #endif /* CONFIG_CMD_MX_CYCLIC */
240 static int do_mem_cmp(struct cmd_tbl *cmdtp, int flag, int argc,
243 ulong addr1, addr2, count, ngood, bytes;
247 const void *buf1, *buf2, *base;
248 ulong word1, word2; /* 64-bit if SUPPORT_64BIT_DATA */
251 return CMD_RET_USAGE;
253 /* Check for size specification.
255 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
257 type = size == 8 ? "double word" :
259 size == 2 ? "halfword" : "byte";
261 addr1 = hextoul(argv[1], NULL);
262 addr1 += base_address;
264 addr2 = hextoul(argv[2], NULL);
265 addr2 += base_address;
267 count = hextoul(argv[3], NULL);
269 bytes = size * count;
270 base = buf1 = map_sysmem(addr1, bytes);
271 buf2 = map_sysmem(addr2, bytes);
272 for (ngood = 0; ngood < count; ++ngood) {
274 word1 = *(u32 *)buf1;
275 word2 = *(u32 *)buf2;
276 } else if (SUPPORT_64BIT_DATA && size == 8) {
277 word1 = *(ulong *)buf1;
278 word2 = *(ulong *)buf2;
279 } else if (size == 2) {
280 word1 = *(u16 *)buf1;
281 word2 = *(u16 *)buf2;
286 if (word1 != word2) {
287 ulong offset = buf1 - base;
288 printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n",
289 type, (ulong)(addr1 + offset), size, word1,
290 type, (ulong)(addr2 + offset), size, word2);
298 /* reset watchdog from time to time */
299 if ((ngood % (64 << 10)) == 0)
305 printf("Total of %ld %s(s) were the same\n", ngood, type);
309 static int do_mem_cp(struct cmd_tbl *cmdtp, int flag, int argc,
312 ulong addr, dest, count;
317 return CMD_RET_USAGE;
319 /* Check for size specification.
321 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
324 addr = hextoul(argv[1], NULL);
325 addr += base_address;
327 dest = hextoul(argv[2], NULL);
328 dest += base_address;
330 count = hextoul(argv[3], NULL);
333 puts ("Zero length ???\n");
337 src = map_sysmem(addr, count * size);
338 dst = map_sysmem(dest, count * size);
340 #ifdef CONFIG_MTD_NOR_FLASH
341 /* check if we are copying to Flash */
342 if (addr2info((ulong)dst)) {
345 puts ("Copy to Flash... ");
347 rc = flash_write((char *)src, (ulong)dst, count * size);
361 memcpy(dst, src, count * size);
368 #ifdef CONFIG_CMD_MEM_SEARCH
369 static int do_mem_search(struct cmd_tbl *cmdtp, int flag, int argc,
372 ulong addr, length, bytes, offset;
375 ulong last_pos; /* Offset of last match in 'size' units*/
376 ulong last_addr; /* Address of last displayed line */
383 /* We use the last specified parameters, unless new ones are entered */
386 length = dp_last_ms_length;
389 return CMD_RET_USAGE;
391 if (!(flag & CMD_FLAG_REPEAT)) {
393 * Check for a size specification.
394 * Defaults to long if no or incorrect specification.
396 size = cmd_get_data_size(argv[0], 4);
397 if (size < 0 && size != CMD_DATA_SIZE_STR)
402 while (argc && *argv[0] == '-') {
407 else if (ch == 'l' && isxdigit(argv[0][2]))
408 limit = hextoul(argv[0] + 2, NULL);
410 return CMD_RET_USAGE;
415 /* Address is specified since argc > 1 */
416 addr = hextoul(argv[0], NULL);
417 addr += base_address;
419 /* Length is the number of objects, not number of bytes */
420 length = hextoul(argv[1], NULL);
422 /* Read the bytes to search for */
423 end = search_buf + sizeof(search_buf);
424 for (i = 2, ptr = search_buf; i < argc && ptr < end; i++) {
425 if (MEM_SUPPORT_64BIT_DATA && size == 8) {
426 u64 val = simple_strtoull(argv[i], NULL, 16);
429 } else if (size == -2) { /* string */
430 int len = min(strlen(argv[i]),
431 (size_t)(end - ptr));
433 memcpy(ptr, argv[i], len);
437 u32 val = hextoul(argv[i], NULL);
453 search_len = ptr - search_buf;
459 bytes = size * length;
460 buf = map_sysmem(addr, bytes);
465 offset < bytes && offset <= bytes - search_len && count < limit;
467 void *ptr = buf + offset;
469 if (!memcmp(ptr, search_buf, search_len)) {
470 uint align = (addr + offset) & 0xf;
471 ulong match = addr + offset;
473 if (!count || (last_addr & ~0xf) != (match & ~0xf)) {
477 print_buffer(match - align, ptr - align,
479 ALIGN(search_len + align,
483 last_pos = offset / size;
489 printf("%d match%s", count, count == 1 ? "" : "es");
491 printf(" (repeat command to check for more)");
494 env_set_hex("memmatches", count);
495 env_set_hex("memaddr", last_addr);
496 env_set_hex("mempos", last_pos);
500 used_len = offset / size;
501 dp_last_addr = addr + used_len;
503 dp_last_ms_length = length < used_len ? 0 : length - used_len;
505 return count ? 0 : CMD_RET_FAILURE;
509 static int do_mem_base(struct cmd_tbl *cmdtp, int flag, int argc,
513 /* Set new base address.
515 base_address = hextoul(argv[1], NULL);
517 /* Print the current base address.
519 printf("Base Address: 0x%08lx\n", base_address);
523 static int do_mem_loop(struct cmd_tbl *cmdtp, int flag, int argc,
526 ulong addr, length, i, bytes;
528 volatile ulong *llp; /* 64-bit if SUPPORT_64BIT_DATA */
530 volatile u16 *shortp;
535 return CMD_RET_USAGE;
538 * Check for a size specification.
539 * Defaults to long if no or incorrect specification.
541 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
544 /* Address is always specified.
546 addr = hextoul(argv[1], NULL);
548 /* Length is the number of objects, not number of bytes.
550 length = hextoul(argv[2], NULL);
552 bytes = size * length;
553 buf = map_sysmem(addr, bytes);
555 /* We want to optimize the loops to run as fast as possible.
556 * If we have only one object, just run infinite loops.
559 if (SUPPORT_64BIT_DATA && size == 8) {
579 if (SUPPORT_64BIT_DATA && size == 8) {
615 static int do_mem_loopw(struct cmd_tbl *cmdtp, int flag, int argc,
618 ulong addr, length, i, bytes;
620 volatile ulong *llp; /* 64-bit if SUPPORT_64BIT_DATA */
621 ulong data; /* 64-bit if SUPPORT_64BIT_DATA */
623 volatile u16 *shortp;
628 return CMD_RET_USAGE;
631 * Check for a size specification.
632 * Defaults to long if no or incorrect specification.
634 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
637 /* Address is always specified.
639 addr = hextoul(argv[1], NULL);
641 /* Length is the number of objects, not number of bytes.
643 length = hextoul(argv[2], NULL);
646 if (SUPPORT_64BIT_DATA)
647 data = simple_strtoull(argv[3], NULL, 16);
649 data = hextoul(argv[3], NULL);
651 bytes = size * length;
652 buf = map_sysmem(addr, bytes);
654 /* We want to optimize the loops to run as fast as possible.
655 * If we have only one object, just run infinite loops.
658 if (SUPPORT_64BIT_DATA && size == 8) {
678 if (SUPPORT_64BIT_DATA && size == 8) {
709 #endif /* CONFIG_LOOPW */
711 #ifdef CONFIG_CMD_MEMTEST
712 static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr,
723 vu_long anti_pattern;
725 static const ulong bitpattern[] = {
726 0x00000001, /* single bit */
727 0x00000003, /* two adjacent bits */
728 0x00000007, /* three adjacent bits */
729 0x0000000F, /* four adjacent bits */
730 0x00000005, /* two non-adjacent bits */
731 0x00000015, /* three non-adjacent bits */
732 0x00000055, /* four non-adjacent bits */
733 0xaaaaaaaa, /* alternating 1/0 */
736 num_words = (end_addr - start_addr) / sizeof(vu_long);
739 * Data line test: write a pattern to the first
740 * location, write the 1's complement to a 'parking'
741 * address (changes the state of the data bus so a
742 * floating bus doesn't give a false OK), and then
743 * read the value back. Note that we read it back
744 * into a variable because the next time we read it,
745 * it might be right (been there, tough to explain to
746 * the quality guys why it prints a failure when the
747 * "is" and "should be" are obviously the same in the
750 * Rather than exhaustively testing, we test some
751 * patterns by shifting '1' bits through a field of
752 * '0's and '0' bits through a field of '1's (i.e.
753 * pattern and ~pattern).
756 for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) {
758 for (; val != 0; val <<= 1) {
760 *dummy = ~val; /* clear the test data off the bus */
762 if (readback != val) {
763 printf("FAILURE (data line): "
764 "expected %08lx, actual %08lx\n",
773 if (readback != ~val) {
774 printf("FAILURE (data line): "
775 "Is %08lx, should be %08lx\n",
785 * Based on code whose Original Author and Copyright
786 * information follows: Copyright (c) 1998 by Michael
787 * Barr. This software is placed into the public
788 * domain and may be used for any purpose. However,
789 * this notice must not be changed or removed and no
790 * warranty is either expressed or implied by its
791 * publication or distribution.
797 * Description: Test the address bus wiring in a
798 * memory region by performing a walking
799 * 1's test on the relevant bits of the
800 * address and checking for aliasing.
801 * This test will find single-bit
802 * address failures such as stuck-high,
803 * stuck-low, and shorted pins. The base
804 * address and size of the region are
805 * selected by the caller.
807 * Notes: For best results, the selected base
808 * address should have enough LSB 0's to
809 * guarantee single address bit changes.
810 * For example, to test a 64-Kbyte
811 * region, select a base address on a
812 * 64-Kbyte boundary. Also, select the
813 * region size as a power-of-two if at
816 * Returns: 0 if the test succeeds, 1 if the test fails.
818 pattern = (vu_long) 0xaaaaaaaa;
819 anti_pattern = (vu_long) 0x55555555;
821 debug("%s:%d: length = 0x%.8lx\n", __func__, __LINE__, num_words);
823 * Write the default pattern at each of the
824 * power-of-two offsets.
826 for (offset = 1; offset < num_words; offset <<= 1)
827 addr[offset] = pattern;
830 * Check for address bits stuck high.
833 addr[test_offset] = anti_pattern;
835 for (offset = 1; offset < num_words; offset <<= 1) {
837 if (temp != pattern) {
838 printf("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
839 " expected 0x%.8lx, actual 0x%.8lx\n",
840 start_addr + offset*sizeof(vu_long),
847 addr[test_offset] = pattern;
851 * Check for addr bits stuck low or shorted.
853 for (test_offset = 1; test_offset < num_words; test_offset <<= 1) {
854 addr[test_offset] = anti_pattern;
856 for (offset = 1; offset < num_words; offset <<= 1) {
858 if ((temp != pattern) && (offset != test_offset)) {
859 printf("\nFAILURE: Address bit stuck low or"
860 " shorted @ 0x%.8lx: expected 0x%.8lx,"
862 start_addr + offset*sizeof(vu_long),
869 addr[test_offset] = pattern;
873 * Description: Test the integrity of a physical
874 * memory device by performing an
875 * increment/decrement test over the
876 * entire region. In the process every
877 * storage bit in the device is tested
878 * as a zero and a one. The base address
879 * and the size of the region are
880 * selected by the caller.
882 * Returns: 0 if the test succeeds, 1 if the test fails.
887 * Fill memory with a known pattern.
889 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
891 addr[offset] = pattern;
895 * Check each location and invert it for the second pass.
897 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
900 if (temp != pattern) {
901 printf("\nFAILURE (read/write) @ 0x%.8lx:"
902 " expected 0x%.8lx, actual 0x%.8lx)\n",
903 start_addr + offset*sizeof(vu_long),
910 anti_pattern = ~pattern;
911 addr[offset] = anti_pattern;
915 * Check each location for the inverted pattern and zero it.
917 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
919 anti_pattern = ~pattern;
921 if (temp != anti_pattern) {
922 printf("\nFAILURE (read/write): @ 0x%.8lx:"
923 " expected 0x%.8lx, actual 0x%.8lx)\n",
924 start_addr + offset*sizeof(vu_long),
936 static int compare_regions(volatile unsigned long *bufa,
937 volatile unsigned long *bufb, size_t count)
939 volatile unsigned long *p1 = bufa;
940 volatile unsigned long *p2 = bufb;
944 for (i = 0; i < count; i++, p1++, p2++) {
946 printf("FAILURE: 0x%08lx != 0x%08lx (delta=0x%08lx -> bit %ld) at offset 0x%08lx\n",
947 (unsigned long)*p1, (unsigned long)*p2,
948 *p1 ^ *p2, __ffs(*p1 ^ *p2),
949 (unsigned long)(i * sizeof(unsigned long)));
957 static ulong test_bitflip_comparison(volatile unsigned long *bufa,
958 volatile unsigned long *bufb, size_t count)
960 volatile unsigned long *p1 = bufa;
961 volatile unsigned long *p2 = bufb;
968 max = sizeof(unsigned long) * 8;
969 for (k = 0; k < max; k++) {
970 q = 0x00000001L << k;
971 for (j = 0; j < 8; j++) {
974 p1 = (volatile unsigned long *)bufa;
975 p2 = (volatile unsigned long *)bufb;
976 for (i = 0; i < count; i++)
977 *p1++ = *p2++ = (i % 2) == 0 ? q : ~q;
979 errs += compare_regions(bufa, bufb, count);
989 static ulong mem_test_bitflip(vu_long *buf, ulong start, ulong end)
992 * Split the specified range into two halves.
993 * Note that mtest range is inclusive of start,end.
994 * Bitflip test instead uses a count (of 32-bit words).
996 ulong half_size = (end - start + 1) / 2 / sizeof(unsigned long);
998 return test_bitflip_comparison(buf, buf + half_size, half_size);
1001 static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr,
1002 vu_long pattern, int iteration)
1008 ulong val, readback;
1010 /* Alternate the pattern */
1012 if (iteration & 1) {
1015 * Flip the pattern each time to make lots of zeros and
1016 * then, the next time, lots of ones. We decrement
1017 * the "negative" patterns and increment the "positive"
1018 * patterns to preserve this feature.
1020 if (pattern & 0x80000000)
1021 pattern = -pattern; /* complement & increment */
1025 length = (end_addr - start_addr) / sizeof(ulong);
1027 printf("\rPattern %08lX Writing..."
1029 "\b\b\b\b\b\b\b\b\b\b",
1032 for (addr = buf, val = pattern; addr < end; addr++) {
1040 for (addr = buf, val = pattern; addr < end; addr++) {
1043 if (readback != val) {
1044 ulong offset = addr - buf;
1046 printf("\nMem error @ 0x%08X: "
1047 "found %08lX, expected %08lX\n",
1048 (uint)(uintptr_t)(start_addr + offset*sizeof(vu_long)),
1061 * Perform a memory test. A more complete alternative test can be
1062 * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
1063 * interrupted by ctrl-c or by a failure of one of the sub-tests.
1065 static int do_mem_mtest(struct cmd_tbl *cmdtp, int flag, int argc,
1069 vu_long scratch_space;
1070 vu_long *buf, *dummy = &scratch_space;
1071 ulong iteration_limit = 0;
1073 ulong errs = 0; /* number of errors, or -1 if interrupted */
1077 start = CONFIG_SYS_MEMTEST_START;
1078 end = CONFIG_SYS_MEMTEST_END;
1081 if (strict_strtoul(argv[1], 16, &start) < 0)
1082 return CMD_RET_USAGE;
1085 if (strict_strtoul(argv[2], 16, &end) < 0)
1086 return CMD_RET_USAGE;
1089 if (strict_strtoul(argv[3], 16, &pattern) < 0)
1090 return CMD_RET_USAGE;
1093 if (strict_strtoul(argv[4], 16, &iteration_limit) < 0)
1094 return CMD_RET_USAGE;
1097 printf("Refusing to do empty test\n");
1101 printf("Testing %08lx ... %08lx:\n", start, end);
1102 debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__,
1105 buf = map_sysmem(start, end - start);
1107 !iteration_limit || iteration < iteration_limit;
1114 printf("Iteration: %6d\r", iteration + 1);
1116 if (IS_ENABLED(CONFIG_SYS_ALT_MEMTEST)) {
1117 errs = mem_test_alt(buf, start, end, dummy);
1120 if (IS_ENABLED(CONFIG_SYS_ALT_MEMTEST_BITFLIP)) {
1122 errs = mem_test_bitflip(buf, start, end);
1125 errs = mem_test_quick(buf, start, end, pattern,
1133 unmap_sysmem((void *)buf);
1136 /* Memory test was aborted - write a newline to finish off */
1139 printf("Tested %d iteration(s) with %lu errors.\n", iteration, count);
1143 #endif /* CONFIG_CMD_MEMTEST */
1148 * mm{.b, .w, .l, .q} {addr}
1151 mod_mem(struct cmd_tbl *cmdtp, int incrflag, int flag, int argc,
1155 ulong i; /* 64-bit if SUPPORT_64BIT_DATA */
1160 return CMD_RET_USAGE;
1162 bootretry_reset_cmd_timeout(); /* got a good command to get here */
1163 /* We use the last specified parameters, unless new ones are
1166 addr = mm_last_addr;
1167 size = mm_last_size;
1169 if ((flag & CMD_FLAG_REPEAT) == 0) {
1170 /* New command specified. Check for a size specification.
1171 * Defaults to long if no or incorrect specification.
1173 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
1176 /* Address is specified since argc > 1
1178 addr = hextoul(argv[1], NULL);
1179 addr += base_address;
1182 /* Print the address, followed by value. Then accept input for
1183 * the next value. A non-converted value exits.
1186 ptr = map_sysmem(addr, size);
1187 printf("%08lx:", addr);
1189 printf(" %08x", *((u32 *)ptr));
1190 else if (SUPPORT_64BIT_DATA && size == 8)
1191 printf(" %0lx", *((ulong *)ptr));
1193 printf(" %04x", *((u16 *)ptr));
1195 printf(" %02x", *((u8 *)ptr));
1197 nbytes = cli_readline(" ? ");
1198 if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
1199 /* <CR> pressed as only input, don't modify current
1200 * location and move to next. "-" pressed will go back.
1203 addr += nbytes ? -size : size;
1205 /* good enough to not time out */
1206 bootretry_reset_cmd_timeout();
1208 #ifdef CONFIG_BOOT_RETRY_TIME
1209 else if (nbytes == -2) {
1210 break; /* timed out, exit the command */
1215 if (SUPPORT_64BIT_DATA)
1216 i = simple_strtoull(console_buffer, &endp, 16);
1218 i = hextoul(console_buffer, &endp);
1219 nbytes = endp - console_buffer;
1221 /* good enough to not time out
1223 bootretry_reset_cmd_timeout();
1226 else if (SUPPORT_64BIT_DATA && size == 8)
1227 *((ulong *)ptr) = i;
1240 mm_last_addr = addr;
1241 mm_last_size = size;
1245 #ifdef CONFIG_CMD_CRC32
1247 static int do_mem_crc(struct cmd_tbl *cmdtp, int flag, int argc,
1255 return CMD_RET_USAGE;
1259 #ifdef CONFIG_CRC32_VERIFY
1260 if (strcmp(*av, "-v") == 0) {
1261 flags |= HASH_FLAG_VERIFY | HASH_FLAG_ENV;
1267 return hash_command("crc32", flags, cmdtp, flag, ac, av);
1272 #ifdef CONFIG_CMD_RANDOM
1273 static int do_random(struct cmd_tbl *cmdtp, int flag, int argc,
1276 unsigned long addr, len;
1277 unsigned long seed; // NOT INITIALIZED ON PURPOSE
1278 unsigned int *buf, *start;
1279 unsigned char *buf8;
1282 if (argc < 3 || argc > 4)
1283 return CMD_RET_USAGE;
1285 len = hextoul(argv[2], NULL);
1286 addr = hextoul(argv[1], NULL);
1289 seed = hextoul(argv[3], NULL);
1291 printf("The seed cannot be 0. Using 0xDEADBEEF.\n");
1295 seed = get_timer(0) ^ rand();
1299 start = map_sysmem(addr, len);
1301 for (i = 0; i < (len / 4); i++)
1304 buf8 = (unsigned char *)buf;
1305 for (i = 0; i < (len % 4); i++)
1306 *buf8++ = rand() & 0xFF;
1308 unmap_sysmem(start);
1309 printf("%lu bytes filled with random data\n", len);
1311 return CMD_RET_SUCCESS;
1315 /**************************************************/
1317 md, 3, 1, do_mem_md,
1319 "[.b, .w, .l" HELP_Q "] address [# of objects]"
1324 mm, 2, 1, do_mem_mm,
1325 "memory modify (auto-incrementing address)",
1326 "[.b, .w, .l" HELP_Q "] address"
1331 nm, 2, 1, do_mem_nm,
1332 "memory modify (constant address)",
1333 "[.b, .w, .l" HELP_Q "] address"
1337 mw, 4, 1, do_mem_mw,
1338 "memory write (fill)",
1339 "[.b, .w, .l" HELP_Q "] address value [count]"
1343 cp, 4, 1, do_mem_cp,
1345 "[.b, .w, .l" HELP_Q "] source target count"
1349 cmp, 4, 1, do_mem_cmp,
1351 "[.b, .w, .l" HELP_Q "] addr1 addr2 count"
1354 #ifdef CONFIG_CMD_MEM_SEARCH
1355 /**************************************************/
1357 ms, 255, 1, do_mem_search,
1359 "[.b, .w, .l" HELP_Q ", .s] [-q | -<n>] address #-of-objects <value>..."
1360 " -q = quiet, -l<val> = match limit"
1364 #ifdef CONFIG_CMD_CRC32
1366 #ifndef CONFIG_CRC32_VERIFY
1369 crc32, 4, 1, do_mem_crc,
1370 "checksum calculation",
1371 "address count [addr]\n - compute CRC32 checksum [save at addr]"
1374 #else /* CONFIG_CRC32_VERIFY */
1377 crc32, 5, 1, do_mem_crc,
1378 "checksum calculation",
1379 "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
1380 "-v address count crc\n - verify crc of memory area"
1383 #endif /* CONFIG_CRC32_VERIFY */
1387 #ifdef CONFIG_CMD_MEMINFO
1388 static int do_mem_info(struct cmd_tbl *cmdtp, int flag, int argc,
1392 print_size(gd->ram_size, "\n");
1399 base, 2, 1, do_mem_base,
1400 "print or set address offset",
1401 "\n - print address offset for memory commands\n"
1402 "base off\n - set address offset for memory commands to 'off'"
1406 loop, 3, 1, do_mem_loop,
1407 "infinite loop on address range",
1408 "[.b, .w, .l" HELP_Q "] address number_of_objects"
1413 loopw, 4, 1, do_mem_loopw,
1414 "infinite write loop on address range",
1415 "[.b, .w, .l" HELP_Q "] address number_of_objects data_to_write"
1417 #endif /* CONFIG_LOOPW */
1419 #ifdef CONFIG_CMD_MEMTEST
1421 mtest, 5, 1, do_mem_mtest,
1422 "simple RAM read/write test",
1423 "[start [end [pattern [iterations]]]]"
1425 #endif /* CONFIG_CMD_MEMTEST */
1427 #ifdef CONFIG_CMD_MX_CYCLIC
1429 mdc, 4, 1, do_mem_mdc,
1430 "memory display cyclic",
1431 "[.b, .w, .l" HELP_Q "] address count delay(ms)"
1435 mwc, 4, 1, do_mem_mwc,
1436 "memory write cyclic",
1437 "[.b, .w, .l" HELP_Q "] address value delay(ms)"
1439 #endif /* CONFIG_CMD_MX_CYCLIC */
1441 #ifdef CONFIG_CMD_MEMINFO
1443 meminfo, 3, 1, do_mem_info,
1444 "display memory information",
1449 #ifdef CONFIG_CMD_RANDOM
1451 random, 4, 0, do_random,
1452 "fill memory with random pattern",
1453 "<addr> <len> [<seed>]\n"
1454 " - Fill 'len' bytes of memory starting at 'addr' with random data\n"