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)
14 #include <bootretry.h>
18 #include <display_options.h>
19 #ifdef CONFIG_MTD_NOR_FLASH
28 #include <asm/global_data.h>
30 #include <linux/bitops.h>
31 #include <linux/compiler.h>
32 #include <linux/ctype.h>
33 #include <linux/delay.h>
35 DECLARE_GLOBAL_DATA_PTR;
37 /* Create a compile-time value */
38 #if MEM_SUPPORT_64BIT_DATA
44 static int mod_mem(struct cmd_tbl *, int, int, int, char * const []);
46 /* Display values from last command.
47 * Memory modify remembered values are different from display memory.
49 static ulong dp_last_addr, dp_last_size;
50 static ulong dp_last_length = 0x40;
51 static ulong mm_last_addr, mm_last_size;
53 static ulong base_address = 0;
54 #ifdef CONFIG_CMD_MEM_SEARCH
55 static ulong dp_last_ms_length;
56 static u8 search_buf[64];
57 static uint search_len;
63 * md{.b, .w, .l, .q} {addr} {len}
65 #define DISP_LINE_LEN 16
66 static int do_mem_md(struct cmd_tbl *cmdtp, int flag, int argc,
69 ulong addr, length, bytes;
74 /* We use the last specified parameters, unless new ones are
79 length = dp_last_length;
84 if ((flag & CMD_FLAG_REPEAT) == 0) {
85 /* New command specified. Check for a size specification.
86 * Defaults to long if no or incorrect specification.
88 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
91 /* Address is specified since argc > 1
93 addr = hextoul(argv[1], NULL);
96 /* If another parameter, it is the length to display.
97 * Length is the number of objects, not number of bytes.
100 length = hextoul(argv[2], NULL);
103 bytes = size * length;
104 buf = map_sysmem(addr, bytes);
106 /* Print the lines. */
107 print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
112 dp_last_length = length;
117 static int do_mem_mm(struct cmd_tbl *cmdtp, int flag, int argc,
120 return mod_mem (cmdtp, 1, flag, argc, argv);
123 static int do_mem_nm(struct cmd_tbl *cmdtp, int flag, int argc,
126 return mod_mem (cmdtp, 0, flag, argc, argv);
129 static int do_mem_mw(struct cmd_tbl *cmdtp, int flag, int argc,
132 ulong writeval; /* 64-bit if MEM_SUPPORT_64BIT_DATA */
138 if ((argc < 3) || (argc > 4))
139 return CMD_RET_USAGE;
141 /* Check for size specification.
143 if ((size = cmd_get_data_size(argv[0], 4)) < 1)
146 /* Address is specified since argc > 1
148 addr = hextoul(argv[1], NULL);
149 addr += base_address;
151 /* Get the value to write.
153 if (MEM_SUPPORT_64BIT_DATA)
154 writeval = simple_strtoull(argv[2], NULL, 16);
156 writeval = hextoul(argv[2], NULL);
160 count = hextoul(argv[3], NULL);
165 bytes = size * count;
166 start = map_sysmem(addr, bytes);
168 while (count-- > 0) {
170 *((u32 *)buf) = (u32)writeval;
171 else if (MEM_SUPPORT_64BIT_DATA && size == 8)
172 *((ulong *)buf) = writeval;
174 *((u16 *)buf) = (u16)writeval;
176 *((u8 *)buf) = (u8)writeval;
183 #ifdef CONFIG_CMD_MX_CYCLIC
184 static int do_mem_mdc(struct cmd_tbl *cmdtp, int flag, int argc,
191 return CMD_RET_USAGE;
193 count = dectoul(argv[3], NULL);
196 do_mem_md (NULL, 0, 3, argv);
198 /* delay for <count> ms... */
199 for (i=0; i<count; i++)
202 /* check for ctrl-c to abort... */
212 static int do_mem_mwc(struct cmd_tbl *cmdtp, int flag, int argc,
219 return CMD_RET_USAGE;
221 count = dectoul(argv[3], NULL);
224 do_mem_mw (NULL, 0, 3, argv);
226 /* delay for <count> ms... */
227 for (i=0; i<count; i++)
230 /* check for ctrl-c to abort... */
239 #endif /* CONFIG_CMD_MX_CYCLIC */
241 static int do_mem_cmp(struct cmd_tbl *cmdtp, int flag, int argc,
244 ulong addr1, addr2, count, ngood, bytes;
248 const void *buf1, *buf2, *base;
249 ulong word1, word2; /* 64-bit if MEM_SUPPORT_64BIT_DATA */
252 return CMD_RET_USAGE;
254 /* Check for size specification.
256 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
258 type = size == 8 ? "double word" :
260 size == 2 ? "halfword" : "byte";
262 addr1 = hextoul(argv[1], NULL);
263 addr1 += base_address;
265 addr2 = hextoul(argv[2], NULL);
266 addr2 += base_address;
268 count = hextoul(argv[3], NULL);
270 bytes = size * count;
271 base = buf1 = map_sysmem(addr1, bytes);
272 buf2 = map_sysmem(addr2, bytes);
273 for (ngood = 0; ngood < count; ++ngood) {
275 word1 = *(u32 *)buf1;
276 word2 = *(u32 *)buf2;
277 } else if (MEM_SUPPORT_64BIT_DATA && size == 8) {
278 word1 = *(ulong *)buf1;
279 word2 = *(ulong *)buf2;
280 } else if (size == 2) {
281 word1 = *(u16 *)buf1;
282 word2 = *(u16 *)buf2;
287 if (word1 != word2) {
288 ulong offset = buf1 - base;
289 printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n",
290 type, (ulong)(addr1 + offset), size, word1,
291 type, (ulong)(addr2 + offset), size, word2);
299 /* reset watchdog from time to time */
300 if ((ngood % (64 << 10)) == 0)
306 printf("Total of %ld %s(s) were the same\n", ngood, type);
310 static int do_mem_cp(struct cmd_tbl *cmdtp, int flag, int argc,
313 ulong addr, dest, count;
318 return CMD_RET_USAGE;
320 /* Check for size specification.
322 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
325 addr = hextoul(argv[1], NULL);
326 addr += base_address;
328 dest = hextoul(argv[2], NULL);
329 dest += base_address;
331 count = hextoul(argv[3], NULL);
334 puts ("Zero length ???\n");
338 src = map_sysmem(addr, count * size);
339 dst = map_sysmem(dest, count * size);
341 #ifdef CONFIG_MTD_NOR_FLASH
342 /* check if we are copying to Flash */
343 if (addr2info((ulong)dst)) {
346 puts ("Copy to Flash... ");
348 rc = flash_write((char *)src, (ulong)dst, count * size);
362 memmove(dst, src, count * size);
369 #ifdef CONFIG_CMD_MEM_SEARCH
370 static int do_mem_search(struct cmd_tbl *cmdtp, int flag, int argc,
373 ulong addr, length, bytes, offset;
376 ulong last_pos; /* Offset of last match in 'size' units*/
377 ulong last_addr; /* Address of last displayed line */
384 /* We use the last specified parameters, unless new ones are entered */
387 length = dp_last_ms_length;
390 return CMD_RET_USAGE;
392 if (!(flag & CMD_FLAG_REPEAT)) {
394 * Check for a size specification.
395 * Defaults to long if no or incorrect specification.
397 size = cmd_get_data_size(argv[0], 4);
398 if (size < 0 && size != CMD_DATA_SIZE_STR)
403 while (argc && *argv[0] == '-') {
408 else if (ch == 'l' && isxdigit(argv[0][2]))
409 limit = hextoul(argv[0] + 2, NULL);
411 return CMD_RET_USAGE;
416 /* Address is specified since argc > 1 */
417 addr = hextoul(argv[0], NULL);
418 addr += base_address;
420 /* Length is the number of objects, not number of bytes */
421 length = hextoul(argv[1], NULL);
423 /* Read the bytes to search for */
424 end = search_buf + sizeof(search_buf);
425 for (i = 2, ptr = search_buf; i < argc && ptr < end; i++) {
426 if (MEM_SUPPORT_64BIT_DATA && size == 8) {
427 u64 val = simple_strtoull(argv[i], NULL, 16);
430 } else if (size == -2) { /* string */
431 int len = min(strlen(argv[i]),
432 (size_t)(end - ptr));
434 memcpy(ptr, argv[i], len);
438 u32 val = hextoul(argv[i], NULL);
454 search_len = ptr - search_buf;
460 bytes = size * length;
461 buf = map_sysmem(addr, bytes);
466 offset < bytes && offset <= bytes - search_len && count < limit;
468 void *ptr = buf + offset;
470 if (!memcmp(ptr, search_buf, search_len)) {
471 uint align = (addr + offset) & 0xf;
472 ulong match = addr + offset;
474 if (!count || (last_addr & ~0xf) != (match & ~0xf)) {
478 print_buffer(match - align, ptr - align,
480 ALIGN(search_len + align,
484 last_pos = offset / size;
490 printf("%d match%s", count, count == 1 ? "" : "es");
492 printf(" (repeat command to check for more)");
495 env_set_hex("memmatches", count);
496 env_set_hex("memaddr", last_addr);
497 env_set_hex("mempos", last_pos);
501 used_len = offset / size;
502 dp_last_addr = addr + used_len;
504 dp_last_ms_length = length < used_len ? 0 : length - used_len;
506 return count ? 0 : CMD_RET_FAILURE;
510 static int do_mem_base(struct cmd_tbl *cmdtp, int flag, int argc,
514 /* Set new base address.
516 base_address = hextoul(argv[1], NULL);
518 /* Print the current base address.
520 printf("Base Address: 0x%08lx\n", base_address);
524 static int do_mem_loop(struct cmd_tbl *cmdtp, int flag, int argc,
527 ulong addr, length, i, bytes;
529 volatile ulong *llp; /* 64-bit if MEM_SUPPORT_64BIT_DATA */
531 volatile u16 *shortp;
536 return CMD_RET_USAGE;
539 * Check for a size specification.
540 * Defaults to long if no or incorrect specification.
542 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
545 /* Address is always specified.
547 addr = hextoul(argv[1], NULL);
549 /* Length is the number of objects, not number of bytes.
551 length = hextoul(argv[2], NULL);
553 bytes = size * length;
554 buf = map_sysmem(addr, bytes);
556 /* We want to optimize the loops to run as fast as possible.
557 * If we have only one object, just run infinite loops.
560 if (MEM_SUPPORT_64BIT_DATA && size == 8) {
580 if (MEM_SUPPORT_64BIT_DATA && size == 8) {
616 static int do_mem_loopw(struct cmd_tbl *cmdtp, int flag, int argc,
619 ulong addr, length, i, bytes;
621 volatile ulong *llp; /* 64-bit if MEM_SUPPORT_64BIT_DATA */
622 ulong data; /* 64-bit if MEM_SUPPORT_64BIT_DATA */
624 volatile u16 *shortp;
629 return CMD_RET_USAGE;
632 * Check for a size specification.
633 * Defaults to long if no or incorrect specification.
635 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
638 /* Address is always specified.
640 addr = hextoul(argv[1], NULL);
642 /* Length is the number of objects, not number of bytes.
644 length = hextoul(argv[2], NULL);
647 if (MEM_SUPPORT_64BIT_DATA)
648 data = simple_strtoull(argv[3], NULL, 16);
650 data = hextoul(argv[3], NULL);
652 bytes = size * length;
653 buf = map_sysmem(addr, bytes);
655 /* We want to optimize the loops to run as fast as possible.
656 * If we have only one object, just run infinite loops.
659 if (MEM_SUPPORT_64BIT_DATA && size == 8) {
679 if (MEM_SUPPORT_64BIT_DATA && size == 8) {
710 #endif /* CONFIG_LOOPW */
712 #ifdef CONFIG_CMD_MEMTEST
713 static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr,
724 vu_long anti_pattern;
726 static const ulong bitpattern[] = {
727 0x00000001, /* single bit */
728 0x00000003, /* two adjacent bits */
729 0x00000007, /* three adjacent bits */
730 0x0000000F, /* four adjacent bits */
731 0x00000005, /* two non-adjacent bits */
732 0x00000015, /* three non-adjacent bits */
733 0x00000055, /* four non-adjacent bits */
734 0xaaaaaaaa, /* alternating 1/0 */
737 num_words = (end_addr - start_addr) / sizeof(vu_long);
740 * Data line test: write a pattern to the first
741 * location, write the 1's complement to a 'parking'
742 * address (changes the state of the data bus so a
743 * floating bus doesn't give a false OK), and then
744 * read the value back. Note that we read it back
745 * into a variable because the next time we read it,
746 * it might be right (been there, tough to explain to
747 * the quality guys why it prints a failure when the
748 * "is" and "should be" are obviously the same in the
751 * Rather than exhaustively testing, we test some
752 * patterns by shifting '1' bits through a field of
753 * '0's and '0' bits through a field of '1's (i.e.
754 * pattern and ~pattern).
757 for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) {
759 for (; val != 0; val <<= 1) {
761 *dummy = ~val; /* clear the test data off the bus */
763 if (readback != val) {
764 printf("FAILURE (data line): "
765 "expected %08lx, actual %08lx\n",
774 if (readback != ~val) {
775 printf("FAILURE (data line): "
776 "Is %08lx, should be %08lx\n",
786 * Based on code whose Original Author and Copyright
787 * information follows: Copyright (c) 1998 by Michael
788 * Barr. This software is placed into the public
789 * domain and may be used for any purpose. However,
790 * this notice must not be changed or removed and no
791 * warranty is either expressed or implied by its
792 * publication or distribution.
798 * Description: Test the address bus wiring in a
799 * memory region by performing a walking
800 * 1's test on the relevant bits of the
801 * address and checking for aliasing.
802 * This test will find single-bit
803 * address failures such as stuck-high,
804 * stuck-low, and shorted pins. The base
805 * address and size of the region are
806 * selected by the caller.
808 * Notes: For best results, the selected base
809 * address should have enough LSB 0's to
810 * guarantee single address bit changes.
811 * For example, to test a 64-Kbyte
812 * region, select a base address on a
813 * 64-Kbyte boundary. Also, select the
814 * region size as a power-of-two if at
817 * Returns: 0 if the test succeeds, 1 if the test fails.
819 pattern = (vu_long)0xaaaaaaaaaaaaaaaa;
820 anti_pattern = (vu_long)0x5555555555555555;
822 debug("%s:%d: length = 0x%.8lx\n", __func__, __LINE__, num_words);
824 * Write the default pattern at each of the
825 * power-of-two offsets.
827 for (offset = 1; offset < num_words; offset <<= 1)
828 addr[offset] = pattern;
831 * Check for address bits stuck high.
834 addr[test_offset] = anti_pattern;
836 for (offset = 1; offset < num_words; offset <<= 1) {
838 if (temp != pattern) {
839 printf("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
840 " expected 0x%.8lx, actual 0x%.8lx\n",
841 start_addr + offset*sizeof(vu_long),
848 addr[test_offset] = pattern;
852 * Check for addr bits stuck low or shorted.
854 for (test_offset = 1; test_offset < num_words; test_offset <<= 1) {
855 addr[test_offset] = anti_pattern;
857 for (offset = 1; offset < num_words; offset <<= 1) {
859 if ((temp != pattern) && (offset != test_offset)) {
860 printf("\nFAILURE: Address bit stuck low or"
861 " shorted @ 0x%.8lx: expected 0x%.8lx,"
863 start_addr + offset*sizeof(vu_long),
870 addr[test_offset] = pattern;
874 * Description: Test the integrity of a physical
875 * memory device by performing an
876 * increment/decrement test over the
877 * entire region. In the process every
878 * storage bit in the device is tested
879 * as a zero and a one. The base address
880 * and the size of the region are
881 * selected by the caller.
883 * Returns: 0 if the test succeeds, 1 if the test fails.
888 * Fill memory with a known pattern.
890 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
892 addr[offset] = pattern;
896 * Check each location and invert it for the second pass.
898 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
901 if (temp != pattern) {
902 printf("\nFAILURE (read/write) @ 0x%.8lx:"
903 " expected 0x%.8lx, actual 0x%.8lx)\n",
904 start_addr + offset*sizeof(vu_long),
911 anti_pattern = ~pattern;
912 addr[offset] = anti_pattern;
916 * Check each location for the inverted pattern and zero it.
918 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
920 anti_pattern = ~pattern;
922 if (temp != anti_pattern) {
923 printf("\nFAILURE (read/write): @ 0x%.8lx:"
924 " expected 0x%.8lx, actual 0x%.8lx)\n",
925 start_addr + offset*sizeof(vu_long),
937 static int compare_regions(volatile unsigned long *bufa,
938 volatile unsigned long *bufb, size_t count)
940 volatile unsigned long *p1 = bufa;
941 volatile unsigned long *p2 = bufb;
945 for (i = 0; i < count; i++, p1++, p2++) {
947 printf("FAILURE: 0x%08lx != 0x%08lx (delta=0x%08lx -> bit %ld) at offset 0x%08lx\n",
948 (unsigned long)*p1, (unsigned long)*p2,
949 *p1 ^ *p2, __ffs(*p1 ^ *p2),
950 (unsigned long)(i * sizeof(unsigned long)));
958 static ulong test_bitflip_comparison(volatile unsigned long *bufa,
959 volatile unsigned long *bufb, size_t count)
961 volatile unsigned long *p1 = bufa;
962 volatile unsigned long *p2 = bufb;
969 max = sizeof(unsigned long) * 8;
970 for (k = 0; k < max; k++) {
972 for (j = 0; j < 8; j++) {
975 p1 = (volatile unsigned long *)bufa;
976 p2 = (volatile unsigned long *)bufb;
977 for (i = 0; i < count; i++)
978 *p1++ = *p2++ = (i % 2) == 0 ? q : ~q;
980 errs += compare_regions(bufa, bufb, count);
990 static ulong mem_test_bitflip(vu_long *buf, ulong start, ulong end)
993 * Split the specified range into two halves.
994 * Note that mtest range is inclusive of start,end.
995 * Bitflip test instead uses a count (of 32-bit words).
997 ulong half_size = (end - start + 1) / 2 / sizeof(unsigned long);
999 return test_bitflip_comparison(buf, buf + half_size, half_size);
1002 static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr,
1003 vu_long pattern, int iteration)
1009 ulong val, readback;
1010 const int plen = 2 * sizeof(ulong);
1012 /* Alternate the pattern */
1014 if (iteration & 1) {
1017 * Flip the pattern each time to make lots of zeros and
1018 * then, the next time, lots of ones. We decrement
1019 * the "negative" patterns and increment the "positive"
1020 * patterns to preserve this feature.
1022 if (pattern > (ulong)LONG_MAX)
1023 pattern = -pattern; /* complement & increment */
1027 length = (end_addr - start_addr) / sizeof(ulong);
1029 printf("\rPattern %0*lX Writing..."
1031 "\b\b\b\b\b\b\b\b\b\b",
1034 for (addr = buf, val = pattern; addr < end; addr++) {
1042 for (addr = buf, val = pattern; addr < end; addr++) {
1045 if (readback != val) {
1046 ulong offset = addr - buf;
1048 printf("\nMem error @ 0x%0*lX: found %0*lX, expected %0*lX\n",
1049 plen, start_addr + offset * sizeof(vu_long),
1050 plen, readback, plen, val);
1062 * Perform a memory test. A more complete alternative test can be
1063 * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
1064 * interrupted by ctrl-c or by a failure of one of the sub-tests.
1066 static int do_mem_mtest(struct cmd_tbl *cmdtp, int flag, int argc,
1070 vu_long scratch_space;
1071 vu_long *buf, *dummy = &scratch_space;
1072 ulong iteration_limit = 0;
1074 ulong errs = 0; /* number of errors, or -1 if interrupted */
1078 start = CONFIG_SYS_MEMTEST_START;
1079 end = CONFIG_SYS_MEMTEST_END;
1082 if (strict_strtoul(argv[1], 16, &start) < 0)
1083 return CMD_RET_USAGE;
1086 if (strict_strtoul(argv[2], 16, &end) < 0)
1087 return CMD_RET_USAGE;
1090 if (strict_strtoul(argv[3], 16, &pattern) < 0)
1091 return CMD_RET_USAGE;
1094 if (strict_strtoul(argv[4], 16, &iteration_limit) < 0)
1095 return CMD_RET_USAGE;
1098 printf("Refusing to do empty test\n");
1102 printf("Testing %08lx ... %08lx:\n", start, end);
1103 debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__,
1106 buf = map_sysmem(start, end - start);
1108 !iteration_limit || iteration < iteration_limit;
1115 printf("Iteration: %6d\r", iteration + 1);
1117 if (IS_ENABLED(CONFIG_SYS_ALT_MEMTEST)) {
1118 errs = mem_test_alt(buf, start, end, dummy);
1121 if (IS_ENABLED(CONFIG_SYS_ALT_MEMTEST_BITFLIP)) {
1123 errs = mem_test_bitflip(buf, start, end);
1126 errs = mem_test_quick(buf, start, end, pattern,
1134 unmap_sysmem((void *)buf);
1136 printf("\nTested %d iteration(s) with %lu errors.\n", iteration, count);
1140 #endif /* CONFIG_CMD_MEMTEST */
1145 * mm{.b, .w, .l, .q} {addr}
1148 mod_mem(struct cmd_tbl *cmdtp, int incrflag, int flag, int argc,
1152 ulong i; /* 64-bit if MEM_SUPPORT_64BIT_DATA */
1157 return CMD_RET_USAGE;
1159 bootretry_reset_cmd_timeout(); /* got a good command to get here */
1160 /* We use the last specified parameters, unless new ones are
1163 addr = mm_last_addr;
1164 size = mm_last_size;
1166 if ((flag & CMD_FLAG_REPEAT) == 0) {
1167 /* New command specified. Check for a size specification.
1168 * Defaults to long if no or incorrect specification.
1170 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
1173 /* Address is specified since argc > 1
1175 addr = hextoul(argv[1], NULL);
1176 addr += base_address;
1179 /* Print the address, followed by value. Then accept input for
1180 * the next value. A non-converted value exits.
1183 ptr = map_sysmem(addr, size);
1184 printf("%08lx:", addr);
1186 printf(" %08x", *((u32 *)ptr));
1187 else if (MEM_SUPPORT_64BIT_DATA && size == 8)
1188 printf(" %0lx", *((ulong *)ptr));
1190 printf(" %04x", *((u16 *)ptr));
1192 printf(" %02x", *((u8 *)ptr));
1194 nbytes = cli_readline(" ? ");
1195 if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
1196 /* <CR> pressed as only input, don't modify current
1197 * location and move to next. "-" pressed will go back.
1200 addr += nbytes ? -size : size;
1202 /* good enough to not time out */
1203 bootretry_reset_cmd_timeout();
1205 #ifdef CONFIG_BOOT_RETRY_TIME
1206 else if (nbytes == -2) {
1207 break; /* timed out, exit the command */
1212 if (MEM_SUPPORT_64BIT_DATA)
1213 i = simple_strtoull(console_buffer, &endp, 16);
1215 i = hextoul(console_buffer, &endp);
1216 nbytes = endp - console_buffer;
1218 /* good enough to not time out
1220 bootretry_reset_cmd_timeout();
1223 else if (MEM_SUPPORT_64BIT_DATA && size == 8)
1224 *((ulong *)ptr) = i;
1237 mm_last_addr = addr;
1238 mm_last_size = size;
1242 #ifdef CONFIG_CMD_CRC32
1244 static int do_mem_crc(struct cmd_tbl *cmdtp, int flag, int argc,
1252 return CMD_RET_USAGE;
1256 #ifdef CONFIG_CRC32_VERIFY
1257 if (strcmp(*av, "-v") == 0) {
1258 flags |= HASH_FLAG_VERIFY | HASH_FLAG_ENV;
1264 return hash_command("crc32", flags, cmdtp, flag, ac, av);
1269 #ifdef CONFIG_CMD_RANDOM
1270 static int do_random(struct cmd_tbl *cmdtp, int flag, int argc,
1273 unsigned long addr, len;
1274 unsigned long seed; // NOT INITIALIZED ON PURPOSE
1275 unsigned int *buf, *start;
1276 unsigned char *buf8;
1279 if (argc < 3 || argc > 4)
1280 return CMD_RET_USAGE;
1282 len = hextoul(argv[2], NULL);
1283 addr = hextoul(argv[1], NULL);
1286 seed = hextoul(argv[3], NULL);
1288 printf("The seed cannot be 0. Using 0xDEADBEEF.\n");
1292 seed = get_timer(0) ^ rand();
1296 start = map_sysmem(addr, len);
1298 for (i = 0; i < (len / 4); i++)
1301 buf8 = (unsigned char *)buf;
1302 for (i = 0; i < (len % 4); i++)
1303 *buf8++ = rand() & 0xFF;
1305 unmap_sysmem(start);
1306 printf("%lu bytes filled with random data\n", len);
1308 return CMD_RET_SUCCESS;
1312 /**************************************************/
1314 md, 3, 1, do_mem_md,
1316 "[.b, .w, .l" HELP_Q "] address [# of objects]"
1320 mm, 2, 1, do_mem_mm,
1321 "memory modify (auto-incrementing address)",
1322 "[.b, .w, .l" HELP_Q "] address"
1326 nm, 2, 1, do_mem_nm,
1327 "memory modify (constant address)",
1328 "[.b, .w, .l" HELP_Q "] address"
1332 mw, 4, 1, do_mem_mw,
1333 "memory write (fill)",
1334 "[.b, .w, .l" HELP_Q "] address value [count]"
1338 cp, 4, 1, do_mem_cp,
1340 "[.b, .w, .l" HELP_Q "] source target count"
1344 cmp, 4, 1, do_mem_cmp,
1346 "[.b, .w, .l" HELP_Q "] addr1 addr2 count"
1349 #ifdef CONFIG_CMD_MEM_SEARCH
1350 /**************************************************/
1352 ms, 255, 1, do_mem_search,
1354 "[.b, .w, .l" HELP_Q ", .s] [-q | -<n>] address #-of-objects <value>..."
1355 " -q = quiet, -l<val> = match limit"
1359 #ifdef CONFIG_CMD_CRC32
1361 #ifndef CONFIG_CRC32_VERIFY
1364 crc32, 4, 1, do_mem_crc,
1365 "checksum calculation",
1366 "address count [addr]\n - compute CRC32 checksum [save at addr]"
1369 #else /* CONFIG_CRC32_VERIFY */
1372 crc32, 5, 1, do_mem_crc,
1373 "checksum calculation",
1374 "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
1375 "-v address count crc\n - verify crc of memory area"
1378 #endif /* CONFIG_CRC32_VERIFY */
1382 #ifdef CONFIG_CMD_MEMINFO
1383 static int do_mem_info(struct cmd_tbl *cmdtp, int flag, int argc,
1387 print_size(gd->ram_size, "\n");
1394 base, 2, 1, do_mem_base,
1395 "print or set address offset",
1396 "\n - print address offset for memory commands\n"
1397 "base off\n - set address offset for memory commands to 'off'"
1401 loop, 3, 1, do_mem_loop,
1402 "infinite loop on address range",
1403 "[.b, .w, .l" HELP_Q "] address number_of_objects"
1408 loopw, 4, 1, do_mem_loopw,
1409 "infinite write loop on address range",
1410 "[.b, .w, .l" HELP_Q "] address number_of_objects data_to_write"
1412 #endif /* CONFIG_LOOPW */
1414 #ifdef CONFIG_CMD_MEMTEST
1416 mtest, 5, 1, do_mem_mtest,
1417 "simple RAM read/write test",
1418 "[start [end [pattern [iterations]]]]"
1420 #endif /* CONFIG_CMD_MEMTEST */
1422 #ifdef CONFIG_CMD_MX_CYCLIC
1424 mdc, 4, 1, do_mem_mdc,
1425 "memory display cyclic",
1426 "[.b, .w, .l" HELP_Q "] address count delay(ms)"
1430 mwc, 4, 1, do_mem_mwc,
1431 "memory write cyclic",
1432 "[.b, .w, .l" HELP_Q "] address value delay(ms)"
1434 #endif /* CONFIG_CMD_MX_CYCLIC */
1436 #ifdef CONFIG_CMD_MEMINFO
1438 meminfo, 3, 1, do_mem_info,
1439 "display memory information",
1444 #ifdef CONFIG_CMD_RANDOM
1446 random, 4, 0, do_random,
1447 "fill memory with random pattern",
1448 "<addr> <len> [<seed>]\n"
1449 " - Fill 'len' bytes of memory starting at 'addr' with random data\n"