1 // SPDX-License-Identifier: GPL-2.0+
15 #include <bootretry.h>
19 #ifdef CONFIG_MTD_NOR_FLASH
27 #include <asm/global_data.h>
29 #include <linux/bitops.h>
30 #include <linux/compiler.h>
31 #include <linux/ctype.h>
32 #include <linux/delay.h>
34 DECLARE_GLOBAL_DATA_PTR;
36 /* Create a compile-time value */
37 #ifdef MEM_SUPPORT_64BIT_DATA
38 #define SUPPORT_64BIT_DATA 1
41 #define SUPPORT_64BIT_DATA 0
45 static int mod_mem(struct cmd_tbl *, int, int, int, char * const []);
47 /* Display values from last command.
48 * Memory modify remembered values are different from display memory.
50 static ulong dp_last_addr, dp_last_size;
51 static ulong dp_last_length = 0x40;
52 static ulong mm_last_addr, mm_last_size;
54 static ulong base_address = 0;
55 #ifdef CONFIG_CMD_MEM_SEARCH
56 static ulong dp_last_ms_length;
57 static u8 search_buf[64];
58 static uint search_len;
64 * md{.b, .w, .l, .q} {addr} {len}
66 #define DISP_LINE_LEN 16
67 static int do_mem_md(struct cmd_tbl *cmdtp, int flag, int argc,
70 ulong addr, length, bytes;
75 /* We use the last specified parameters, unless new ones are
80 length = dp_last_length;
85 if ((flag & CMD_FLAG_REPEAT) == 0) {
86 /* New command specified. Check for a size specification.
87 * Defaults to long if no or incorrect specification.
89 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
92 /* Address is specified since argc > 1
94 addr = hextoul(argv[1], NULL);
97 /* If another parameter, it is the length to display.
98 * Length is the number of objects, not number of bytes.
101 length = hextoul(argv[2], NULL);
104 bytes = size * length;
105 buf = map_sysmem(addr, bytes);
107 /* Print the lines. */
108 print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
113 dp_last_length = length;
118 static int do_mem_mm(struct cmd_tbl *cmdtp, int flag, int argc,
121 return mod_mem (cmdtp, 1, flag, argc, argv);
124 static int do_mem_nm(struct cmd_tbl *cmdtp, int flag, int argc,
127 return mod_mem (cmdtp, 0, flag, argc, argv);
130 static int do_mem_mw(struct cmd_tbl *cmdtp, int flag, int argc,
133 ulong writeval; /* 64-bit if SUPPORT_64BIT_DATA */
139 if ((argc < 3) || (argc > 4))
140 return CMD_RET_USAGE;
142 /* Check for size specification.
144 if ((size = cmd_get_data_size(argv[0], 4)) < 1)
147 /* Address is specified since argc > 1
149 addr = hextoul(argv[1], NULL);
150 addr += base_address;
152 /* Get the value to write.
154 if (SUPPORT_64BIT_DATA)
155 writeval = simple_strtoull(argv[2], NULL, 16);
157 writeval = hextoul(argv[2], NULL);
161 count = hextoul(argv[3], NULL);
166 bytes = size * count;
167 start = map_sysmem(addr, bytes);
169 while (count-- > 0) {
171 *((u32 *)buf) = (u32)writeval;
172 else if (SUPPORT_64BIT_DATA && size == 8)
173 *((ulong *)buf) = writeval;
175 *((u16 *)buf) = (u16)writeval;
177 *((u8 *)buf) = (u8)writeval;
184 #ifdef CONFIG_CMD_MX_CYCLIC
185 static int do_mem_mdc(struct cmd_tbl *cmdtp, int flag, int argc,
192 return CMD_RET_USAGE;
194 count = dectoul(argv[3], NULL);
197 do_mem_md (NULL, 0, 3, argv);
199 /* delay for <count> ms... */
200 for (i=0; i<count; i++)
203 /* check for ctrl-c to abort... */
213 static int do_mem_mwc(struct cmd_tbl *cmdtp, int flag, int argc,
220 return CMD_RET_USAGE;
222 count = dectoul(argv[3], NULL);
225 do_mem_mw (NULL, 0, 3, argv);
227 /* delay for <count> ms... */
228 for (i=0; i<count; i++)
231 /* check for ctrl-c to abort... */
240 #endif /* CONFIG_CMD_MX_CYCLIC */
242 static int do_mem_cmp(struct cmd_tbl *cmdtp, int flag, int argc,
245 ulong addr1, addr2, count, ngood, bytes;
249 const void *buf1, *buf2, *base;
250 ulong word1, word2; /* 64-bit if SUPPORT_64BIT_DATA */
253 return CMD_RET_USAGE;
255 /* Check for size specification.
257 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
259 type = size == 8 ? "double word" :
261 size == 2 ? "halfword" : "byte";
263 addr1 = hextoul(argv[1], NULL);
264 addr1 += base_address;
266 addr2 = hextoul(argv[2], NULL);
267 addr2 += base_address;
269 count = hextoul(argv[3], NULL);
271 bytes = size * count;
272 base = buf1 = map_sysmem(addr1, bytes);
273 buf2 = map_sysmem(addr2, bytes);
274 for (ngood = 0; ngood < count; ++ngood) {
276 word1 = *(u32 *)buf1;
277 word2 = *(u32 *)buf2;
278 } else if (SUPPORT_64BIT_DATA && size == 8) {
279 word1 = *(ulong *)buf1;
280 word2 = *(ulong *)buf2;
281 } else if (size == 2) {
282 word1 = *(u16 *)buf1;
283 word2 = *(u16 *)buf2;
288 if (word1 != word2) {
289 ulong offset = buf1 - base;
290 printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n",
291 type, (ulong)(addr1 + offset), size, word1,
292 type, (ulong)(addr2 + offset), size, word2);
300 /* reset watchdog from time to time */
301 if ((ngood % (64 << 10)) == 0)
307 printf("Total of %ld %s(s) were the same\n", ngood, type);
311 static int do_mem_cp(struct cmd_tbl *cmdtp, int flag, int argc,
314 ulong addr, dest, count;
319 return CMD_RET_USAGE;
321 /* Check for size specification.
323 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
326 addr = hextoul(argv[1], NULL);
327 addr += base_address;
329 dest = hextoul(argv[2], NULL);
330 dest += base_address;
332 count = hextoul(argv[3], NULL);
335 puts ("Zero length ???\n");
339 src = map_sysmem(addr, count * size);
340 dst = map_sysmem(dest, count * size);
342 #ifdef CONFIG_MTD_NOR_FLASH
343 /* check if we are copying to Flash */
344 if (addr2info((ulong)dst)) {
347 puts ("Copy to Flash... ");
349 rc = flash_write((char *)src, (ulong)dst, count * size);
363 memcpy(dst, src, count * size);
370 #ifdef CONFIG_CMD_MEM_SEARCH
371 static int do_mem_search(struct cmd_tbl *cmdtp, int flag, int argc,
374 ulong addr, length, bytes, offset;
377 ulong last_pos; /* Offset of last match in 'size' units*/
378 ulong last_addr; /* Address of last displayed line */
385 /* We use the last specified parameters, unless new ones are entered */
388 length = dp_last_ms_length;
391 return CMD_RET_USAGE;
393 if (!(flag & CMD_FLAG_REPEAT)) {
395 * Check for a size specification.
396 * Defaults to long if no or incorrect specification.
398 size = cmd_get_data_size(argv[0], 4);
399 if (size < 0 && size != CMD_DATA_SIZE_STR)
404 while (argc && *argv[0] == '-') {
409 else if (ch == 'l' && isxdigit(argv[0][2]))
410 limit = hextoul(argv[0] + 2, NULL);
412 return CMD_RET_USAGE;
417 /* Address is specified since argc > 1 */
418 addr = hextoul(argv[0], NULL);
419 addr += base_address;
421 /* Length is the number of objects, not number of bytes */
422 length = hextoul(argv[1], NULL);
424 /* Read the bytes to search for */
425 end = search_buf + sizeof(search_buf);
426 for (i = 2, ptr = search_buf; i < argc && ptr < end; i++) {
427 if (MEM_SUPPORT_64BIT_DATA && size == 8) {
428 u64 val = simple_strtoull(argv[i], NULL, 16);
431 } else if (size == -2) { /* string */
432 int len = min(strlen(argv[i]),
433 (size_t)(end - ptr));
435 memcpy(ptr, argv[i], len);
439 u32 val = hextoul(argv[i], NULL);
455 search_len = ptr - search_buf;
461 bytes = size * length;
462 buf = map_sysmem(addr, bytes);
467 offset < bytes && offset <= bytes - search_len && count < limit;
469 void *ptr = buf + offset;
471 if (!memcmp(ptr, search_buf, search_len)) {
472 uint align = (addr + offset) & 0xf;
473 ulong match = addr + offset;
475 if (!count || (last_addr & ~0xf) != (match & ~0xf)) {
479 print_buffer(match - align, ptr - align,
481 ALIGN(search_len + align,
485 last_pos = offset / size;
491 printf("%d match%s", count, count == 1 ? "" : "es");
493 printf(" (repeat command to check for more)");
496 env_set_hex("memmatches", count);
497 env_set_hex("memaddr", last_addr);
498 env_set_hex("mempos", last_pos);
502 used_len = offset / size;
503 dp_last_addr = addr + used_len;
505 dp_last_ms_length = length < used_len ? 0 : length - used_len;
507 return count ? 0 : CMD_RET_FAILURE;
511 static int do_mem_base(struct cmd_tbl *cmdtp, int flag, int argc,
515 /* Set new base address.
517 base_address = hextoul(argv[1], NULL);
519 /* Print the current base address.
521 printf("Base Address: 0x%08lx\n", base_address);
525 static int do_mem_loop(struct cmd_tbl *cmdtp, int flag, int argc,
528 ulong addr, length, i, bytes;
530 volatile ulong *llp; /* 64-bit if SUPPORT_64BIT_DATA */
532 volatile u16 *shortp;
537 return CMD_RET_USAGE;
540 * Check for a size specification.
541 * Defaults to long if no or incorrect specification.
543 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
546 /* Address is always specified.
548 addr = hextoul(argv[1], NULL);
550 /* Length is the number of objects, not number of bytes.
552 length = hextoul(argv[2], NULL);
554 bytes = size * length;
555 buf = map_sysmem(addr, bytes);
557 /* We want to optimize the loops to run as fast as possible.
558 * If we have only one object, just run infinite loops.
561 if (SUPPORT_64BIT_DATA && size == 8) {
581 if (SUPPORT_64BIT_DATA && size == 8) {
617 static int do_mem_loopw(struct cmd_tbl *cmdtp, int flag, int argc,
620 ulong addr, length, i, bytes;
622 volatile ulong *llp; /* 64-bit if SUPPORT_64BIT_DATA */
623 ulong data; /* 64-bit if SUPPORT_64BIT_DATA */
625 volatile u16 *shortp;
630 return CMD_RET_USAGE;
633 * Check for a size specification.
634 * Defaults to long if no or incorrect specification.
636 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
639 /* Address is always specified.
641 addr = hextoul(argv[1], NULL);
643 /* Length is the number of objects, not number of bytes.
645 length = hextoul(argv[2], NULL);
648 if (SUPPORT_64BIT_DATA)
649 data = simple_strtoull(argv[3], NULL, 16);
651 data = hextoul(argv[3], NULL);
653 bytes = size * length;
654 buf = map_sysmem(addr, bytes);
656 /* We want to optimize the loops to run as fast as possible.
657 * If we have only one object, just run infinite loops.
660 if (SUPPORT_64BIT_DATA && size == 8) {
680 if (SUPPORT_64BIT_DATA && size == 8) {
711 #endif /* CONFIG_LOOPW */
713 #ifdef CONFIG_CMD_MEMTEST
714 static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr,
725 vu_long anti_pattern;
727 static const ulong bitpattern[] = {
728 0x00000001, /* single bit */
729 0x00000003, /* two adjacent bits */
730 0x00000007, /* three adjacent bits */
731 0x0000000F, /* four adjacent bits */
732 0x00000005, /* two non-adjacent bits */
733 0x00000015, /* three non-adjacent bits */
734 0x00000055, /* four non-adjacent bits */
735 0xaaaaaaaa, /* alternating 1/0 */
738 num_words = (end_addr - start_addr) / sizeof(vu_long);
741 * Data line test: write a pattern to the first
742 * location, write the 1's complement to a 'parking'
743 * address (changes the state of the data bus so a
744 * floating bus doesn't give a false OK), and then
745 * read the value back. Note that we read it back
746 * into a variable because the next time we read it,
747 * it might be right (been there, tough to explain to
748 * the quality guys why it prints a failure when the
749 * "is" and "should be" are obviously the same in the
752 * Rather than exhaustively testing, we test some
753 * patterns by shifting '1' bits through a field of
754 * '0's and '0' bits through a field of '1's (i.e.
755 * pattern and ~pattern).
758 for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) {
760 for (; val != 0; val <<= 1) {
762 *dummy = ~val; /* clear the test data off the bus */
764 if (readback != val) {
765 printf("FAILURE (data line): "
766 "expected %08lx, actual %08lx\n",
775 if (readback != ~val) {
776 printf("FAILURE (data line): "
777 "Is %08lx, should be %08lx\n",
787 * Based on code whose Original Author and Copyright
788 * information follows: Copyright (c) 1998 by Michael
789 * Barr. This software is placed into the public
790 * domain and may be used for any purpose. However,
791 * this notice must not be changed or removed and no
792 * warranty is either expressed or implied by its
793 * publication or distribution.
799 * Description: Test the address bus wiring in a
800 * memory region by performing a walking
801 * 1's test on the relevant bits of the
802 * address and checking for aliasing.
803 * This test will find single-bit
804 * address failures such as stuck-high,
805 * stuck-low, and shorted pins. The base
806 * address and size of the region are
807 * selected by the caller.
809 * Notes: For best results, the selected base
810 * address should have enough LSB 0's to
811 * guarantee single address bit changes.
812 * For example, to test a 64-Kbyte
813 * region, select a base address on a
814 * 64-Kbyte boundary. Also, select the
815 * region size as a power-of-two if at
818 * Returns: 0 if the test succeeds, 1 if the test fails.
820 pattern = (vu_long) 0xaaaaaaaa;
821 anti_pattern = (vu_long) 0x55555555;
823 debug("%s:%d: length = 0x%.8lx\n", __func__, __LINE__, num_words);
825 * Write the default pattern at each of the
826 * power-of-two offsets.
828 for (offset = 1; offset < num_words; offset <<= 1)
829 addr[offset] = pattern;
832 * Check for address bits stuck high.
835 addr[test_offset] = anti_pattern;
837 for (offset = 1; offset < num_words; offset <<= 1) {
839 if (temp != pattern) {
840 printf("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
841 " expected 0x%.8lx, actual 0x%.8lx\n",
842 start_addr + offset*sizeof(vu_long),
849 addr[test_offset] = pattern;
853 * Check for addr bits stuck low or shorted.
855 for (test_offset = 1; test_offset < num_words; test_offset <<= 1) {
856 addr[test_offset] = anti_pattern;
858 for (offset = 1; offset < num_words; offset <<= 1) {
860 if ((temp != pattern) && (offset != test_offset)) {
861 printf("\nFAILURE: Address bit stuck low or"
862 " shorted @ 0x%.8lx: expected 0x%.8lx,"
864 start_addr + offset*sizeof(vu_long),
871 addr[test_offset] = pattern;
875 * Description: Test the integrity of a physical
876 * memory device by performing an
877 * increment/decrement test over the
878 * entire region. In the process every
879 * storage bit in the device is tested
880 * as a zero and a one. The base address
881 * and the size of the region are
882 * selected by the caller.
884 * Returns: 0 if the test succeeds, 1 if the test fails.
889 * Fill memory with a known pattern.
891 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
893 addr[offset] = pattern;
897 * Check each location and invert it for the second pass.
899 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
902 if (temp != pattern) {
903 printf("\nFAILURE (read/write) @ 0x%.8lx:"
904 " expected 0x%.8lx, actual 0x%.8lx)\n",
905 start_addr + offset*sizeof(vu_long),
912 anti_pattern = ~pattern;
913 addr[offset] = anti_pattern;
917 * Check each location for the inverted pattern and zero it.
919 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
921 anti_pattern = ~pattern;
923 if (temp != anti_pattern) {
924 printf("\nFAILURE (read/write): @ 0x%.8lx:"
925 " expected 0x%.8lx, actual 0x%.8lx)\n",
926 start_addr + offset*sizeof(vu_long),
938 static int compare_regions(volatile unsigned long *bufa,
939 volatile unsigned long *bufb, size_t count)
941 volatile unsigned long *p1 = bufa;
942 volatile unsigned long *p2 = bufb;
946 for (i = 0; i < count; i++, p1++, p2++) {
948 printf("FAILURE: 0x%08lx != 0x%08lx (delta=0x%08lx -> bit %ld) at offset 0x%08lx\n",
949 (unsigned long)*p1, (unsigned long)*p2,
950 *p1 ^ *p2, __ffs(*p1 ^ *p2),
951 (unsigned long)(i * sizeof(unsigned long)));
959 static ulong test_bitflip_comparison(volatile unsigned long *bufa,
960 volatile unsigned long *bufb, size_t count)
962 volatile unsigned long *p1 = bufa;
963 volatile unsigned long *p2 = bufb;
970 max = sizeof(unsigned long) * 8;
971 for (k = 0; k < max; k++) {
972 q = 0x00000001L << k;
973 for (j = 0; j < 8; j++) {
976 p1 = (volatile unsigned long *)bufa;
977 p2 = (volatile unsigned long *)bufb;
978 for (i = 0; i < count; i++)
979 *p1++ = *p2++ = (i % 2) == 0 ? q : ~q;
981 errs += compare_regions(bufa, bufb, count);
991 static ulong mem_test_bitflip(vu_long *buf, ulong start, ulong end)
994 * Split the specified range into two halves.
995 * Note that mtest range is inclusive of start,end.
996 * Bitflip test instead uses a count (of 32-bit words).
998 ulong half_size = (end - start + 1) / 2 / sizeof(unsigned long);
1000 return test_bitflip_comparison(buf, buf + half_size, half_size);
1003 static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr,
1004 vu_long pattern, int iteration)
1010 ulong val, readback;
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 & 0x80000000)
1023 pattern = -pattern; /* complement & increment */
1027 length = (end_addr - start_addr) / sizeof(ulong);
1029 printf("\rPattern %08lX 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%08X: "
1049 "found %08lX, expected %08lX\n",
1050 (uint)(uintptr_t)(start_addr + offset*sizeof(vu_long)),
1063 * Perform a memory test. A more complete alternative test can be
1064 * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
1065 * interrupted by ctrl-c or by a failure of one of the sub-tests.
1067 static int do_mem_mtest(struct cmd_tbl *cmdtp, int flag, int argc,
1071 vu_long scratch_space;
1072 vu_long *buf, *dummy = &scratch_space;
1073 ulong iteration_limit = 0;
1075 ulong errs = 0; /* number of errors, or -1 if interrupted */
1079 start = CONFIG_SYS_MEMTEST_START;
1080 end = CONFIG_SYS_MEMTEST_END;
1083 if (strict_strtoul(argv[1], 16, &start) < 0)
1084 return CMD_RET_USAGE;
1087 if (strict_strtoul(argv[2], 16, &end) < 0)
1088 return CMD_RET_USAGE;
1091 if (strict_strtoul(argv[3], 16, &pattern) < 0)
1092 return CMD_RET_USAGE;
1095 if (strict_strtoul(argv[4], 16, &iteration_limit) < 0)
1096 return CMD_RET_USAGE;
1099 printf("Refusing to do empty test\n");
1103 printf("Testing %08lx ... %08lx:\n", start, end);
1104 debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__,
1107 buf = map_sysmem(start, end - start);
1109 !iteration_limit || iteration < iteration_limit;
1116 printf("Iteration: %6d\r", iteration + 1);
1118 if (IS_ENABLED(CONFIG_SYS_ALT_MEMTEST)) {
1119 errs = mem_test_alt(buf, start, end, dummy);
1122 if (IS_ENABLED(CONFIG_SYS_ALT_MEMTEST_BITFLIP)) {
1124 errs = mem_test_bitflip(buf, start, end);
1127 errs = mem_test_quick(buf, start, end, pattern,
1135 unmap_sysmem((void *)buf);
1138 /* Memory test was aborted - write a newline to finish off */
1141 printf("Tested %d iteration(s) with %lu errors.\n", iteration, count);
1145 #endif /* CONFIG_CMD_MEMTEST */
1150 * mm{.b, .w, .l, .q} {addr}
1153 mod_mem(struct cmd_tbl *cmdtp, int incrflag, int flag, int argc,
1157 ulong i; /* 64-bit if SUPPORT_64BIT_DATA */
1162 return CMD_RET_USAGE;
1164 bootretry_reset_cmd_timeout(); /* got a good command to get here */
1165 /* We use the last specified parameters, unless new ones are
1168 addr = mm_last_addr;
1169 size = mm_last_size;
1171 if ((flag & CMD_FLAG_REPEAT) == 0) {
1172 /* New command specified. Check for a size specification.
1173 * Defaults to long if no or incorrect specification.
1175 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
1178 /* Address is specified since argc > 1
1180 addr = hextoul(argv[1], NULL);
1181 addr += base_address;
1184 /* Print the address, followed by value. Then accept input for
1185 * the next value. A non-converted value exits.
1188 ptr = map_sysmem(addr, size);
1189 printf("%08lx:", addr);
1191 printf(" %08x", *((u32 *)ptr));
1192 else if (SUPPORT_64BIT_DATA && size == 8)
1193 printf(" %0lx", *((ulong *)ptr));
1195 printf(" %04x", *((u16 *)ptr));
1197 printf(" %02x", *((u8 *)ptr));
1199 nbytes = cli_readline(" ? ");
1200 if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
1201 /* <CR> pressed as only input, don't modify current
1202 * location and move to next. "-" pressed will go back.
1205 addr += nbytes ? -size : size;
1207 /* good enough to not time out */
1208 bootretry_reset_cmd_timeout();
1210 #ifdef CONFIG_BOOT_RETRY_TIME
1211 else if (nbytes == -2) {
1212 break; /* timed out, exit the command */
1217 if (SUPPORT_64BIT_DATA)
1218 i = simple_strtoull(console_buffer, &endp, 16);
1220 i = hextoul(console_buffer, &endp);
1221 nbytes = endp - console_buffer;
1223 /* good enough to not time out
1225 bootretry_reset_cmd_timeout();
1228 else if (SUPPORT_64BIT_DATA && size == 8)
1229 *((ulong *)ptr) = i;
1242 mm_last_addr = addr;
1243 mm_last_size = size;
1247 #ifdef CONFIG_CMD_CRC32
1249 static int do_mem_crc(struct cmd_tbl *cmdtp, int flag, int argc,
1257 return CMD_RET_USAGE;
1261 #ifdef CONFIG_CRC32_VERIFY
1262 if (strcmp(*av, "-v") == 0) {
1263 flags |= HASH_FLAG_VERIFY | HASH_FLAG_ENV;
1269 return hash_command("crc32", flags, cmdtp, flag, ac, av);
1274 #ifdef CONFIG_CMD_RANDOM
1275 static int do_random(struct cmd_tbl *cmdtp, int flag, int argc,
1278 unsigned long addr, len;
1279 unsigned long seed; // NOT INITIALIZED ON PURPOSE
1280 unsigned int *buf, *start;
1281 unsigned char *buf8;
1284 if (argc < 3 || argc > 4)
1285 return CMD_RET_USAGE;
1287 len = hextoul(argv[2], NULL);
1288 addr = hextoul(argv[1], NULL);
1291 seed = hextoul(argv[3], NULL);
1293 printf("The seed cannot be 0. Using 0xDEADBEEF.\n");
1297 seed = get_timer(0) ^ rand();
1301 start = map_sysmem(addr, len);
1303 for (i = 0; i < (len / 4); i++)
1306 buf8 = (unsigned char *)buf;
1307 for (i = 0; i < (len % 4); i++)
1308 *buf8++ = rand() & 0xFF;
1310 unmap_sysmem(start);
1311 printf("%lu bytes filled with random data\n", len);
1313 return CMD_RET_SUCCESS;
1317 /**************************************************/
1319 md, 3, 1, do_mem_md,
1321 "[.b, .w, .l" HELP_Q "] address [# of objects]"
1326 mm, 2, 1, do_mem_mm,
1327 "memory modify (auto-incrementing address)",
1328 "[.b, .w, .l" HELP_Q "] address"
1333 nm, 2, 1, do_mem_nm,
1334 "memory modify (constant address)",
1335 "[.b, .w, .l" HELP_Q "] address"
1339 mw, 4, 1, do_mem_mw,
1340 "memory write (fill)",
1341 "[.b, .w, .l" HELP_Q "] address value [count]"
1345 cp, 4, 1, do_mem_cp,
1347 "[.b, .w, .l" HELP_Q "] source target count"
1351 cmp, 4, 1, do_mem_cmp,
1353 "[.b, .w, .l" HELP_Q "] addr1 addr2 count"
1356 #ifdef CONFIG_CMD_MEM_SEARCH
1357 /**************************************************/
1359 ms, 255, 1, do_mem_search,
1361 "[.b, .w, .l" HELP_Q ", .s] [-q | -<n>] address #-of-objects <value>..."
1362 " -q = quiet, -l<val> = match limit"
1366 #ifdef CONFIG_CMD_CRC32
1368 #ifndef CONFIG_CRC32_VERIFY
1371 crc32, 4, 1, do_mem_crc,
1372 "checksum calculation",
1373 "address count [addr]\n - compute CRC32 checksum [save at addr]"
1376 #else /* CONFIG_CRC32_VERIFY */
1379 crc32, 5, 1, do_mem_crc,
1380 "checksum calculation",
1381 "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
1382 "-v address count crc\n - verify crc of memory area"
1385 #endif /* CONFIG_CRC32_VERIFY */
1389 #ifdef CONFIG_CMD_MEMINFO
1390 static int do_mem_info(struct cmd_tbl *cmdtp, int flag, int argc,
1394 print_size(gd->ram_size, "\n");
1401 base, 2, 1, do_mem_base,
1402 "print or set address offset",
1403 "\n - print address offset for memory commands\n"
1404 "base off\n - set address offset for memory commands to 'off'"
1408 loop, 3, 1, do_mem_loop,
1409 "infinite loop on address range",
1410 "[.b, .w, .l" HELP_Q "] address number_of_objects"
1415 loopw, 4, 1, do_mem_loopw,
1416 "infinite write loop on address range",
1417 "[.b, .w, .l" HELP_Q "] address number_of_objects data_to_write"
1419 #endif /* CONFIG_LOOPW */
1421 #ifdef CONFIG_CMD_MEMTEST
1423 mtest, 5, 1, do_mem_mtest,
1424 "simple RAM read/write test",
1425 "[start [end [pattern [iterations]]]]"
1427 #endif /* CONFIG_CMD_MEMTEST */
1429 #ifdef CONFIG_CMD_MX_CYCLIC
1431 mdc, 4, 1, do_mem_mdc,
1432 "memory display cyclic",
1433 "[.b, .w, .l" HELP_Q "] address count delay(ms)"
1437 mwc, 4, 1, do_mem_mwc,
1438 "memory write cyclic",
1439 "[.b, .w, .l" HELP_Q "] address value delay(ms)"
1441 #endif /* CONFIG_CMD_MX_CYCLIC */
1443 #ifdef CONFIG_CMD_MEMINFO
1445 meminfo, 3, 1, do_mem_info,
1446 "display memory information",
1451 #ifdef CONFIG_CMD_RANDOM
1453 random, 4, 0, do_random,
1454 "fill memory with random pattern",
1455 "<addr> <len> [<seed>]\n"
1456 " - Fill 'len' bytes of memory starting at 'addr' with random data\n"