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>
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 #ifndef CONFIG_SYS_MEMTEST_SCRATCH
34 #define CONFIG_SYS_MEMTEST_SCRATCH 0
37 /* Create a compile-time value */
38 #ifdef MEM_SUPPORT_64BIT_DATA
39 #define SUPPORT_64BIT_DATA 1
42 #define SUPPORT_64BIT_DATA 0
46 static int mod_mem(struct cmd_tbl *, int, int, int, char * const []);
48 /* Display values from last command.
49 * Memory modify remembered values are different from display memory.
51 static ulong dp_last_addr, dp_last_size;
52 static ulong dp_last_length = 0x40;
53 static ulong mm_last_addr, mm_last_size;
55 static ulong base_address = 0;
56 #ifdef CONFIG_CMD_MEM_SEARCH
57 static ulong dp_last_ms_length;
58 static u8 search_buf[64];
59 static uint search_len;
65 * md{.b, .w, .l, .q} {addr} {len}
67 #define DISP_LINE_LEN 16
68 static int do_mem_md(struct cmd_tbl *cmdtp, int flag, int argc,
71 ulong addr, length, bytes;
76 /* We use the last specified parameters, unless new ones are
81 length = dp_last_length;
86 if ((flag & CMD_FLAG_REPEAT) == 0) {
87 /* New command specified. Check for a size specification.
88 * Defaults to long if no or incorrect specification.
90 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
93 /* Address is specified since argc > 1
95 addr = simple_strtoul(argv[1], NULL, 16);
98 /* If another parameter, it is the length to display.
99 * Length is the number of objects, not number of bytes.
102 length = simple_strtoul(argv[2], NULL, 16);
105 bytes = size * length;
106 buf = map_sysmem(addr, bytes);
108 /* Print the lines. */
109 print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
114 dp_last_length = length;
119 static int do_mem_mm(struct cmd_tbl *cmdtp, int flag, int argc,
122 return mod_mem (cmdtp, 1, flag, argc, argv);
125 static int do_mem_nm(struct cmd_tbl *cmdtp, int flag, int argc,
128 return mod_mem (cmdtp, 0, flag, argc, argv);
131 static int do_mem_mw(struct cmd_tbl *cmdtp, int flag, int argc,
134 ulong writeval; /* 64-bit if SUPPORT_64BIT_DATA */
140 if ((argc < 3) || (argc > 4))
141 return CMD_RET_USAGE;
143 /* Check for size specification.
145 if ((size = cmd_get_data_size(argv[0], 4)) < 1)
148 /* Address is specified since argc > 1
150 addr = simple_strtoul(argv[1], NULL, 16);
151 addr += base_address;
153 /* Get the value to write.
155 if (SUPPORT_64BIT_DATA)
156 writeval = simple_strtoull(argv[2], NULL, 16);
158 writeval = simple_strtoul(argv[2], NULL, 16);
162 count = simple_strtoul(argv[3], NULL, 16);
167 bytes = size * count;
168 start = map_sysmem(addr, bytes);
170 while (count-- > 0) {
172 *((u32 *)buf) = (u32)writeval;
173 else if (SUPPORT_64BIT_DATA && size == 8)
174 *((ulong *)buf) = writeval;
176 *((u16 *)buf) = (u16)writeval;
178 *((u8 *)buf) = (u8)writeval;
185 #ifdef CONFIG_CMD_MX_CYCLIC
186 static int do_mem_mdc(struct cmd_tbl *cmdtp, int flag, int argc,
193 return CMD_RET_USAGE;
195 count = simple_strtoul(argv[3], NULL, 10);
198 do_mem_md (NULL, 0, 3, argv);
200 /* delay for <count> ms... */
201 for (i=0; i<count; i++)
204 /* check for ctrl-c to abort... */
214 static int do_mem_mwc(struct cmd_tbl *cmdtp, int flag, int argc,
221 return CMD_RET_USAGE;
223 count = simple_strtoul(argv[3], NULL, 10);
226 do_mem_mw (NULL, 0, 3, argv);
228 /* delay for <count> ms... */
229 for (i=0; i<count; i++)
232 /* check for ctrl-c to abort... */
241 #endif /* CONFIG_CMD_MX_CYCLIC */
243 static int do_mem_cmp(struct cmd_tbl *cmdtp, int flag, int argc,
246 ulong addr1, addr2, count, ngood, bytes;
250 const void *buf1, *buf2, *base;
251 ulong word1, word2; /* 64-bit if SUPPORT_64BIT_DATA */
254 return CMD_RET_USAGE;
256 /* Check for size specification.
258 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
260 type = size == 8 ? "double word" :
262 size == 2 ? "halfword" : "byte";
264 addr1 = simple_strtoul(argv[1], NULL, 16);
265 addr1 += base_address;
267 addr2 = simple_strtoul(argv[2], NULL, 16);
268 addr2 += base_address;
270 count = simple_strtoul(argv[3], NULL, 16);
272 bytes = size * count;
273 base = buf1 = map_sysmem(addr1, bytes);
274 buf2 = map_sysmem(addr2, bytes);
275 for (ngood = 0; ngood < count; ++ngood) {
277 word1 = *(u32 *)buf1;
278 word2 = *(u32 *)buf2;
279 } else if (SUPPORT_64BIT_DATA && size == 8) {
280 word1 = *(ulong *)buf1;
281 word2 = *(ulong *)buf2;
282 } else if (size == 2) {
283 word1 = *(u16 *)buf1;
284 word2 = *(u16 *)buf2;
289 if (word1 != word2) {
290 ulong offset = buf1 - base;
291 printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n",
292 type, (ulong)(addr1 + offset), size, word1,
293 type, (ulong)(addr2 + offset), size, word2);
301 /* reset watchdog from time to time */
302 if ((ngood % (64 << 10)) == 0)
308 printf("Total of %ld %s(s) were the same\n", ngood, type);
312 static int do_mem_cp(struct cmd_tbl *cmdtp, int flag, int argc,
315 ulong addr, dest, count;
320 return CMD_RET_USAGE;
322 /* Check for size specification.
324 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
327 addr = simple_strtoul(argv[1], NULL, 16);
328 addr += base_address;
330 dest = simple_strtoul(argv[2], NULL, 16);
331 dest += base_address;
333 count = simple_strtoul(argv[3], NULL, 16);
336 puts ("Zero length ???\n");
340 src = map_sysmem(addr, count * size);
341 dst = map_sysmem(dest, count * size);
343 #ifdef CONFIG_MTD_NOR_FLASH
344 /* check if we are copying to Flash */
345 if (addr2info((ulong)dst)) {
348 puts ("Copy to Flash... ");
350 rc = flash_write((char *)src, (ulong)dst, count * size);
364 memcpy(dst, src, count * size);
371 #ifdef CONFIG_CMD_MEM_SEARCH
372 static int do_mem_search(struct cmd_tbl *cmdtp, int flag, int argc,
375 ulong addr, length, bytes, offset;
378 ulong last_pos; /* Offset of last match in 'size' units*/
379 ulong last_addr; /* Address of last displayed line */
386 /* We use the last specified parameters, unless new ones are entered */
389 length = dp_last_ms_length;
392 return CMD_RET_USAGE;
394 if (!(flag & CMD_FLAG_REPEAT)) {
396 * Check for a size specification.
397 * Defaults to long if no or incorrect specification.
399 size = cmd_get_data_size(argv[0], 4);
400 if (size < 0 && size != -2 /* string */)
405 while (argc && *argv[0] == '-') {
410 else if (ch == 'l' && isxdigit(argv[0][2]))
411 limit = simple_strtoul(argv[0] + 2, NULL, 16);
413 return CMD_RET_USAGE;
418 /* Address is specified since argc > 1 */
419 addr = simple_strtoul(argv[0], NULL, 16);
420 addr += base_address;
422 /* Length is the number of objects, not number of bytes */
423 length = simple_strtoul(argv[1], NULL, 16);
425 /* Read the bytes to search for */
426 end = search_buf + sizeof(search_buf);
427 for (i = 2, ptr = search_buf; i < argc && ptr < end; i++) {
428 if (MEM_SUPPORT_64BIT_DATA && size == 8) {
429 u64 val = simple_strtoull(argv[i], NULL, 16);
432 } else if (size == -2) { /* string */
433 int len = min(strlen(argv[i]),
434 (size_t)(end - ptr));
436 memcpy(ptr, argv[i], len);
440 u32 val = simple_strtoul(argv[i], NULL, 16);
456 search_len = ptr - search_buf;
462 bytes = size * length;
463 buf = map_sysmem(addr, bytes);
468 offset < bytes && offset <= bytes - search_len && count < limit;
470 void *ptr = buf + offset;
472 if (!memcmp(ptr, search_buf, search_len)) {
473 uint align = (addr + offset) & 0xf;
474 ulong match = addr + offset;
476 if (!count || (last_addr & ~0xf) != (match & ~0xf)) {
480 print_buffer(match - align, ptr - align,
482 ALIGN(search_len + align,
486 last_pos = offset / size;
492 printf("%d match%s", count, count == 1 ? "" : "es");
494 printf(" (repeat command to check for more)");
497 env_set_hex("memmatches", count);
498 env_set_hex("memaddr", last_addr);
499 env_set_hex("mempos", last_pos);
503 used_len = offset / size;
504 dp_last_addr = addr + used_len;
506 dp_last_ms_length = length < used_len ? 0 : length - used_len;
508 return count ? 0 : CMD_RET_FAILURE;
512 static int do_mem_base(struct cmd_tbl *cmdtp, int flag, int argc,
516 /* Set new base address.
518 base_address = simple_strtoul(argv[1], NULL, 16);
520 /* Print the current base address.
522 printf("Base Address: 0x%08lx\n", base_address);
526 static int do_mem_loop(struct cmd_tbl *cmdtp, int flag, int argc,
529 ulong addr, length, i, bytes;
531 volatile ulong *llp; /* 64-bit if SUPPORT_64BIT_DATA */
533 volatile u16 *shortp;
538 return CMD_RET_USAGE;
541 * Check for a size specification.
542 * Defaults to long if no or incorrect specification.
544 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
547 /* Address is always specified.
549 addr = simple_strtoul(argv[1], NULL, 16);
551 /* Length is the number of objects, not number of bytes.
553 length = simple_strtoul(argv[2], NULL, 16);
555 bytes = size * length;
556 buf = map_sysmem(addr, bytes);
558 /* We want to optimize the loops to run as fast as possible.
559 * If we have only one object, just run infinite loops.
562 if (SUPPORT_64BIT_DATA && size == 8) {
582 if (SUPPORT_64BIT_DATA && size == 8) {
618 static int do_mem_loopw(struct cmd_tbl *cmdtp, int flag, int argc,
621 ulong addr, length, i, bytes;
623 volatile ulong *llp; /* 64-bit if SUPPORT_64BIT_DATA */
624 ulong data; /* 64-bit if SUPPORT_64BIT_DATA */
626 volatile u16 *shortp;
631 return CMD_RET_USAGE;
634 * Check for a size specification.
635 * Defaults to long if no or incorrect specification.
637 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
640 /* Address is always specified.
642 addr = simple_strtoul(argv[1], NULL, 16);
644 /* Length is the number of objects, not number of bytes.
646 length = simple_strtoul(argv[2], NULL, 16);
649 if (SUPPORT_64BIT_DATA)
650 data = simple_strtoull(argv[3], NULL, 16);
652 data = simple_strtoul(argv[3], NULL, 16);
654 bytes = size * length;
655 buf = map_sysmem(addr, bytes);
657 /* We want to optimize the loops to run as fast as possible.
658 * If we have only one object, just run infinite loops.
661 if (SUPPORT_64BIT_DATA && size == 8) {
681 if (SUPPORT_64BIT_DATA && size == 8) {
712 #endif /* CONFIG_LOOPW */
714 #ifdef CONFIG_CMD_MEMTEST
715 static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr,
726 vu_long anti_pattern;
728 static const ulong bitpattern[] = {
729 0x00000001, /* single bit */
730 0x00000003, /* two adjacent bits */
731 0x00000007, /* three adjacent bits */
732 0x0000000F, /* four adjacent bits */
733 0x00000005, /* two non-adjacent bits */
734 0x00000015, /* three non-adjacent bits */
735 0x00000055, /* four non-adjacent bits */
736 0xaaaaaaaa, /* alternating 1/0 */
739 num_words = (end_addr - start_addr) / sizeof(vu_long);
742 * Data line test: write a pattern to the first
743 * location, write the 1's complement to a 'parking'
744 * address (changes the state of the data bus so a
745 * floating bus doesn't give a false OK), and then
746 * read the value back. Note that we read it back
747 * into a variable because the next time we read it,
748 * it might be right (been there, tough to explain to
749 * the quality guys why it prints a failure when the
750 * "is" and "should be" are obviously the same in the
753 * Rather than exhaustively testing, we test some
754 * patterns by shifting '1' bits through a field of
755 * '0's and '0' bits through a field of '1's (i.e.
756 * pattern and ~pattern).
759 for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) {
761 for (; val != 0; val <<= 1) {
763 *dummy = ~val; /* clear the test data off the bus */
765 if (readback != val) {
766 printf("FAILURE (data line): "
767 "expected %08lx, actual %08lx\n",
776 if (readback != ~val) {
777 printf("FAILURE (data line): "
778 "Is %08lx, should be %08lx\n",
788 * Based on code whose Original Author and Copyright
789 * information follows: Copyright (c) 1998 by Michael
790 * Barr. This software is placed into the public
791 * domain and may be used for any purpose. However,
792 * this notice must not be changed or removed and no
793 * warranty is either expressed or implied by its
794 * publication or distribution.
800 * Description: Test the address bus wiring in a
801 * memory region by performing a walking
802 * 1's test on the relevant bits of the
803 * address and checking for aliasing.
804 * This test will find single-bit
805 * address failures such as stuck-high,
806 * stuck-low, and shorted pins. The base
807 * address and size of the region are
808 * selected by the caller.
810 * Notes: For best results, the selected base
811 * address should have enough LSB 0's to
812 * guarantee single address bit changes.
813 * For example, to test a 64-Kbyte
814 * region, select a base address on a
815 * 64-Kbyte boundary. Also, select the
816 * region size as a power-of-two if at
819 * Returns: 0 if the test succeeds, 1 if the test fails.
821 pattern = (vu_long) 0xaaaaaaaa;
822 anti_pattern = (vu_long) 0x55555555;
824 debug("%s:%d: length = 0x%.8lx\n", __func__, __LINE__, num_words);
826 * Write the default pattern at each of the
827 * power-of-two offsets.
829 for (offset = 1; offset < num_words; offset <<= 1)
830 addr[offset] = pattern;
833 * Check for address bits stuck high.
836 addr[test_offset] = anti_pattern;
838 for (offset = 1; offset < num_words; offset <<= 1) {
840 if (temp != pattern) {
841 printf("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
842 " expected 0x%.8lx, actual 0x%.8lx\n",
843 start_addr + offset*sizeof(vu_long),
850 addr[test_offset] = pattern;
854 * Check for addr bits stuck low or shorted.
856 for (test_offset = 1; test_offset < num_words; test_offset <<= 1) {
857 addr[test_offset] = anti_pattern;
859 for (offset = 1; offset < num_words; offset <<= 1) {
861 if ((temp != pattern) && (offset != test_offset)) {
862 printf("\nFAILURE: Address bit stuck low or"
863 " shorted @ 0x%.8lx: expected 0x%.8lx,"
865 start_addr + offset*sizeof(vu_long),
872 addr[test_offset] = pattern;
876 * Description: Test the integrity of a physical
877 * memory device by performing an
878 * increment/decrement test over the
879 * entire region. In the process every
880 * storage bit in the device is tested
881 * as a zero and a one. The base address
882 * and the size of the region are
883 * selected by the caller.
885 * Returns: 0 if the test succeeds, 1 if the test fails.
890 * Fill memory with a known pattern.
892 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
894 addr[offset] = pattern;
898 * Check each location and invert it for the second pass.
900 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
903 if (temp != pattern) {
904 printf("\nFAILURE (read/write) @ 0x%.8lx:"
905 " expected 0x%.8lx, actual 0x%.8lx)\n",
906 start_addr + offset*sizeof(vu_long),
913 anti_pattern = ~pattern;
914 addr[offset] = anti_pattern;
918 * Check each location for the inverted pattern and zero it.
920 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
922 anti_pattern = ~pattern;
924 if (temp != anti_pattern) {
925 printf("\nFAILURE (read/write): @ 0x%.8lx:"
926 " expected 0x%.8lx, actual 0x%.8lx)\n",
927 start_addr + offset*sizeof(vu_long),
939 static int compare_regions(volatile unsigned long *bufa,
940 volatile unsigned long *bufb, size_t count)
942 volatile unsigned long *p1 = bufa;
943 volatile unsigned long *p2 = bufb;
947 for (i = 0; i < count; i++, p1++, p2++) {
949 printf("FAILURE: 0x%08lx != 0x%08lx (delta=0x%08lx -> bit %ld) at offset 0x%08lx\n",
950 (unsigned long)*p1, (unsigned long)*p2,
951 *p1 ^ *p2, __ffs(*p1 ^ *p2),
952 (unsigned long)(i * sizeof(unsigned long)));
960 static ulong test_bitflip_comparison(volatile unsigned long *bufa,
961 volatile unsigned long *bufb, size_t count)
963 volatile unsigned long *p1 = bufa;
964 volatile unsigned long *p2 = bufb;
971 max = sizeof(unsigned long) * 8;
972 for (k = 0; k < max; k++) {
973 q = 0x00000001L << k;
974 for (j = 0; j < 8; j++) {
977 p1 = (volatile unsigned long *)bufa;
978 p2 = (volatile unsigned long *)bufb;
979 for (i = 0; i < count; i++)
980 *p1++ = *p2++ = (i % 2) == 0 ? q : ~q;
982 errs += compare_regions(bufa, bufb, count);
992 static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr,
993 vu_long pattern, int iteration)
1001 /* Alternate the pattern */
1003 if (iteration & 1) {
1006 * Flip the pattern each time to make lots of zeros and
1007 * then, the next time, lots of ones. We decrement
1008 * the "negative" patterns and increment the "positive"
1009 * patterns to preserve this feature.
1011 if (pattern & 0x80000000)
1012 pattern = -pattern; /* complement & increment */
1016 length = (end_addr - start_addr) / sizeof(ulong);
1018 printf("\rPattern %08lX Writing..."
1020 "\b\b\b\b\b\b\b\b\b\b",
1023 for (addr = buf, val = pattern; addr < end; addr++) {
1031 for (addr = buf, val = pattern; addr < end; addr++) {
1034 if (readback != val) {
1035 ulong offset = addr - buf;
1037 printf("\nMem error @ 0x%08X: "
1038 "found %08lX, expected %08lX\n",
1039 (uint)(uintptr_t)(start_addr + offset*sizeof(vu_long)),
1052 * Perform a memory test. A more complete alternative test can be
1053 * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
1054 * interrupted by ctrl-c or by a failure of one of the sub-tests.
1056 static int do_mem_mtest(struct cmd_tbl *cmdtp, int flag, int argc,
1060 vu_long scratch_space;
1061 vu_long *buf, *dummy = &scratch_space;
1062 ulong iteration_limit = 0;
1064 ulong errs = 0; /* number of errors, or -1 if interrupted */
1068 start = CONFIG_SYS_MEMTEST_START;
1069 end = CONFIG_SYS_MEMTEST_END;
1072 if (strict_strtoul(argv[1], 16, &start) < 0)
1073 return CMD_RET_USAGE;
1076 if (strict_strtoul(argv[2], 16, &end) < 0)
1077 return CMD_RET_USAGE;
1080 if (strict_strtoul(argv[3], 16, &pattern) < 0)
1081 return CMD_RET_USAGE;
1084 if (strict_strtoul(argv[4], 16, &iteration_limit) < 0)
1085 return CMD_RET_USAGE;
1088 printf("Refusing to do empty test\n");
1092 printf("Testing %08lx ... %08lx:\n", start, end);
1093 debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__,
1096 buf = map_sysmem(start, end - start);
1098 !iteration_limit || iteration < iteration_limit;
1105 printf("Iteration: %6d\r", iteration + 1);
1107 if (IS_ENABLED(CONFIG_SYS_ALT_MEMTEST)) {
1108 errs = mem_test_alt(buf, start, end, dummy);
1112 errs = test_bitflip_comparison(buf,
1113 buf + (end - start) / 2,
1115 sizeof(unsigned long));
1117 errs = mem_test_quick(buf, start, end, pattern,
1125 unmap_sysmem((void *)buf);
1128 /* Memory test was aborted - write a newline to finish off */
1131 printf("Tested %d iteration(s) with %lu errors.\n", iteration, count);
1135 #endif /* CONFIG_CMD_MEMTEST */
1140 * mm{.b, .w, .l, .q} {addr}
1143 mod_mem(struct cmd_tbl *cmdtp, int incrflag, int flag, int argc,
1147 ulong i; /* 64-bit if SUPPORT_64BIT_DATA */
1152 return CMD_RET_USAGE;
1154 bootretry_reset_cmd_timeout(); /* got a good command to get here */
1155 /* We use the last specified parameters, unless new ones are
1158 addr = mm_last_addr;
1159 size = mm_last_size;
1161 if ((flag & CMD_FLAG_REPEAT) == 0) {
1162 /* New command specified. Check for a size specification.
1163 * Defaults to long if no or incorrect specification.
1165 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
1168 /* Address is specified since argc > 1
1170 addr = simple_strtoul(argv[1], NULL, 16);
1171 addr += base_address;
1174 /* Print the address, followed by value. Then accept input for
1175 * the next value. A non-converted value exits.
1178 ptr = map_sysmem(addr, size);
1179 printf("%08lx:", addr);
1181 printf(" %08x", *((u32 *)ptr));
1182 else if (SUPPORT_64BIT_DATA && size == 8)
1183 printf(" %0lx", *((ulong *)ptr));
1185 printf(" %04x", *((u16 *)ptr));
1187 printf(" %02x", *((u8 *)ptr));
1189 nbytes = cli_readline(" ? ");
1190 if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
1191 /* <CR> pressed as only input, don't modify current
1192 * location and move to next. "-" pressed will go back.
1195 addr += nbytes ? -size : size;
1197 /* good enough to not time out */
1198 bootretry_reset_cmd_timeout();
1200 #ifdef CONFIG_BOOT_RETRY_TIME
1201 else if (nbytes == -2) {
1202 break; /* timed out, exit the command */
1207 if (SUPPORT_64BIT_DATA)
1208 i = simple_strtoull(console_buffer, &endp, 16);
1210 i = simple_strtoul(console_buffer, &endp, 16);
1211 nbytes = endp - console_buffer;
1213 /* good enough to not time out
1215 bootretry_reset_cmd_timeout();
1218 else if (SUPPORT_64BIT_DATA && size == 8)
1219 *((ulong *)ptr) = i;
1232 mm_last_addr = addr;
1233 mm_last_size = size;
1237 #ifdef CONFIG_CMD_CRC32
1239 static int do_mem_crc(struct cmd_tbl *cmdtp, int flag, int argc,
1247 return CMD_RET_USAGE;
1251 #ifdef CONFIG_CRC32_VERIFY
1252 if (strcmp(*av, "-v") == 0) {
1253 flags |= HASH_FLAG_VERIFY | HASH_FLAG_ENV;
1259 return hash_command("crc32", flags, cmdtp, flag, ac, av);
1264 #ifdef CONFIG_CMD_RANDOM
1265 static int do_random(struct cmd_tbl *cmdtp, int flag, int argc,
1268 unsigned long addr, len;
1269 unsigned long seed; // NOT INITIALIZED ON PURPOSE
1270 unsigned int *buf, *start;
1271 unsigned char *buf8;
1274 if (argc < 3 || argc > 4)
1275 return CMD_RET_USAGE;
1277 len = simple_strtoul(argv[2], NULL, 16);
1278 addr = simple_strtoul(argv[1], NULL, 16);
1281 seed = simple_strtoul(argv[3], NULL, 16);
1283 printf("The seed cannot be 0. Using 0xDEADBEEF.\n");
1287 seed = get_timer(0) ^ rand();
1291 start = map_sysmem(addr, len);
1293 for (i = 0; i < (len / 4); i++)
1296 buf8 = (unsigned char *)buf;
1297 for (i = 0; i < (len % 4); i++)
1298 *buf8++ = rand() & 0xFF;
1300 unmap_sysmem(start);
1301 printf("%lu bytes filled with random data\n", len);
1303 return CMD_RET_SUCCESS;
1307 /**************************************************/
1309 md, 3, 1, do_mem_md,
1311 "[.b, .w, .l" HELP_Q "] address [# of objects]"
1316 mm, 2, 1, do_mem_mm,
1317 "memory modify (auto-incrementing address)",
1318 "[.b, .w, .l" HELP_Q "] address"
1323 nm, 2, 1, do_mem_nm,
1324 "memory modify (constant address)",
1325 "[.b, .w, .l" HELP_Q "] address"
1329 mw, 4, 1, do_mem_mw,
1330 "memory write (fill)",
1331 "[.b, .w, .l" HELP_Q "] address value [count]"
1335 cp, 4, 1, do_mem_cp,
1337 "[.b, .w, .l" HELP_Q "] source target count"
1341 cmp, 4, 1, do_mem_cmp,
1343 "[.b, .w, .l" HELP_Q "] addr1 addr2 count"
1346 #ifdef CONFIG_CMD_MEM_SEARCH
1347 /**************************************************/
1349 ms, 255, 1, do_mem_search,
1351 "[.b, .w, .l" HELP_Q ", .s] [-q | -<n>] address #-of-objects <value>..."
1352 " -q = quiet, -l<val> = match limit"
1356 #ifdef CONFIG_CMD_CRC32
1358 #ifndef CONFIG_CRC32_VERIFY
1361 crc32, 4, 1, do_mem_crc,
1362 "checksum calculation",
1363 "address count [addr]\n - compute CRC32 checksum [save at addr]"
1366 #else /* CONFIG_CRC32_VERIFY */
1369 crc32, 5, 1, do_mem_crc,
1370 "checksum calculation",
1371 "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
1372 "-v address count crc\n - verify crc of memory area"
1375 #endif /* CONFIG_CRC32_VERIFY */
1379 #ifdef CONFIG_CMD_MEMINFO
1380 static int do_mem_info(struct cmd_tbl *cmdtp, int flag, int argc,
1384 print_size(gd->ram_size, "\n");
1391 base, 2, 1, do_mem_base,
1392 "print or set address offset",
1393 "\n - print address offset for memory commands\n"
1394 "base off\n - set address offset for memory commands to 'off'"
1398 loop, 3, 1, do_mem_loop,
1399 "infinite loop on address range",
1400 "[.b, .w, .l" HELP_Q "] address number_of_objects"
1405 loopw, 4, 1, do_mem_loopw,
1406 "infinite write loop on address range",
1407 "[.b, .w, .l" HELP_Q "] address number_of_objects data_to_write"
1409 #endif /* CONFIG_LOOPW */
1411 #ifdef CONFIG_CMD_MEMTEST
1413 mtest, 5, 1, do_mem_mtest,
1414 "simple RAM read/write test",
1415 "[start [end [pattern [iterations]]]]"
1417 #endif /* CONFIG_CMD_MEMTEST */
1419 #ifdef CONFIG_CMD_MX_CYCLIC
1421 mdc, 4, 1, do_mem_mdc,
1422 "memory display cyclic",
1423 "[.b, .w, .l" HELP_Q "] address count delay(ms)"
1427 mwc, 4, 1, do_mem_mwc,
1428 "memory write cyclic",
1429 "[.b, .w, .l" HELP_Q "] address value delay(ms)"
1431 #endif /* CONFIG_CMD_MX_CYCLIC */
1433 #ifdef CONFIG_CMD_MEMINFO
1435 meminfo, 3, 1, do_mem_info,
1436 "display memory information",
1441 #ifdef CONFIG_CMD_RANDOM
1443 random, 4, 0, do_random,
1444 "fill memory with random pattern",
1445 "<addr> <len> [<seed>]\n"
1446 " - Fill 'len' bytes of memory starting at 'addr' with random data\n"