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 /* Create a compile-time value */
34 #ifdef MEM_SUPPORT_64BIT_DATA
35 #define SUPPORT_64BIT_DATA 1
38 #define SUPPORT_64BIT_DATA 0
42 static int mod_mem(struct cmd_tbl *, int, int, int, char * const []);
44 /* Display values from last command.
45 * Memory modify remembered values are different from display memory.
47 static ulong dp_last_addr, dp_last_size;
48 static ulong dp_last_length = 0x40;
49 static ulong mm_last_addr, mm_last_size;
51 static ulong base_address = 0;
52 #ifdef CONFIG_CMD_MEM_SEARCH
53 static ulong dp_last_ms_length;
54 static u8 search_buf[64];
55 static uint search_len;
61 * md{.b, .w, .l, .q} {addr} {len}
63 #define DISP_LINE_LEN 16
64 static int do_mem_md(struct cmd_tbl *cmdtp, int flag, int argc,
67 ulong addr, length, bytes;
72 /* We use the last specified parameters, unless new ones are
77 length = dp_last_length;
82 if ((flag & CMD_FLAG_REPEAT) == 0) {
83 /* New command specified. Check for a size specification.
84 * Defaults to long if no or incorrect specification.
86 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
89 /* Address is specified since argc > 1
91 addr = simple_strtoul(argv[1], NULL, 16);
94 /* If another parameter, it is the length to display.
95 * Length is the number of objects, not number of bytes.
98 length = simple_strtoul(argv[2], NULL, 16);
101 bytes = size * length;
102 buf = map_sysmem(addr, bytes);
104 /* Print the lines. */
105 print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
110 dp_last_length = length;
115 static int do_mem_mm(struct cmd_tbl *cmdtp, int flag, int argc,
118 return mod_mem (cmdtp, 1, flag, argc, argv);
121 static int do_mem_nm(struct cmd_tbl *cmdtp, int flag, int argc,
124 return mod_mem (cmdtp, 0, flag, argc, argv);
127 static int do_mem_mw(struct cmd_tbl *cmdtp, int flag, int argc,
130 ulong writeval; /* 64-bit if SUPPORT_64BIT_DATA */
136 if ((argc < 3) || (argc > 4))
137 return CMD_RET_USAGE;
139 /* Check for size specification.
141 if ((size = cmd_get_data_size(argv[0], 4)) < 1)
144 /* Address is specified since argc > 1
146 addr = simple_strtoul(argv[1], NULL, 16);
147 addr += base_address;
149 /* Get the value to write.
151 if (SUPPORT_64BIT_DATA)
152 writeval = simple_strtoull(argv[2], NULL, 16);
154 writeval = simple_strtoul(argv[2], NULL, 16);
158 count = simple_strtoul(argv[3], NULL, 16);
163 bytes = size * count;
164 start = map_sysmem(addr, bytes);
166 while (count-- > 0) {
168 *((u32 *)buf) = (u32)writeval;
169 else if (SUPPORT_64BIT_DATA && size == 8)
170 *((ulong *)buf) = writeval;
172 *((u16 *)buf) = (u16)writeval;
174 *((u8 *)buf) = (u8)writeval;
181 #ifdef CONFIG_CMD_MX_CYCLIC
182 static int do_mem_mdc(struct cmd_tbl *cmdtp, int flag, int argc,
189 return CMD_RET_USAGE;
191 count = simple_strtoul(argv[3], NULL, 10);
194 do_mem_md (NULL, 0, 3, argv);
196 /* delay for <count> ms... */
197 for (i=0; i<count; i++)
200 /* check for ctrl-c to abort... */
210 static int do_mem_mwc(struct cmd_tbl *cmdtp, int flag, int argc,
217 return CMD_RET_USAGE;
219 count = simple_strtoul(argv[3], NULL, 10);
222 do_mem_mw (NULL, 0, 3, argv);
224 /* delay for <count> ms... */
225 for (i=0; i<count; i++)
228 /* check for ctrl-c to abort... */
237 #endif /* CONFIG_CMD_MX_CYCLIC */
239 static int do_mem_cmp(struct cmd_tbl *cmdtp, int flag, int argc,
242 ulong addr1, addr2, count, ngood, bytes;
246 const void *buf1, *buf2, *base;
247 ulong word1, word2; /* 64-bit if SUPPORT_64BIT_DATA */
250 return CMD_RET_USAGE;
252 /* Check for size specification.
254 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
256 type = size == 8 ? "double word" :
258 size == 2 ? "halfword" : "byte";
260 addr1 = simple_strtoul(argv[1], NULL, 16);
261 addr1 += base_address;
263 addr2 = simple_strtoul(argv[2], NULL, 16);
264 addr2 += base_address;
266 count = simple_strtoul(argv[3], NULL, 16);
268 bytes = size * count;
269 base = buf1 = map_sysmem(addr1, bytes);
270 buf2 = map_sysmem(addr2, bytes);
271 for (ngood = 0; ngood < count; ++ngood) {
273 word1 = *(u32 *)buf1;
274 word2 = *(u32 *)buf2;
275 } else if (SUPPORT_64BIT_DATA && size == 8) {
276 word1 = *(ulong *)buf1;
277 word2 = *(ulong *)buf2;
278 } else if (size == 2) {
279 word1 = *(u16 *)buf1;
280 word2 = *(u16 *)buf2;
285 if (word1 != word2) {
286 ulong offset = buf1 - base;
287 printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n",
288 type, (ulong)(addr1 + offset), size, word1,
289 type, (ulong)(addr2 + offset), size, word2);
297 /* reset watchdog from time to time */
298 if ((ngood % (64 << 10)) == 0)
304 printf("Total of %ld %s(s) were the same\n", ngood, type);
308 static int do_mem_cp(struct cmd_tbl *cmdtp, int flag, int argc,
311 ulong addr, dest, count;
316 return CMD_RET_USAGE;
318 /* Check for size specification.
320 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
323 addr = simple_strtoul(argv[1], NULL, 16);
324 addr += base_address;
326 dest = simple_strtoul(argv[2], NULL, 16);
327 dest += base_address;
329 count = simple_strtoul(argv[3], NULL, 16);
332 puts ("Zero length ???\n");
336 src = map_sysmem(addr, count * size);
337 dst = map_sysmem(dest, count * size);
339 #ifdef CONFIG_MTD_NOR_FLASH
340 /* check if we are copying to Flash */
341 if (addr2info((ulong)dst)) {
344 puts ("Copy to Flash... ");
346 rc = flash_write((char *)src, (ulong)dst, count * size);
360 memcpy(dst, src, count * size);
367 #ifdef CONFIG_CMD_MEM_SEARCH
368 static int do_mem_search(struct cmd_tbl *cmdtp, int flag, int argc,
371 ulong addr, length, bytes, offset;
374 ulong last_pos; /* Offset of last match in 'size' units*/
375 ulong last_addr; /* Address of last displayed line */
382 /* We use the last specified parameters, unless new ones are entered */
385 length = dp_last_ms_length;
388 return CMD_RET_USAGE;
390 if (!(flag & CMD_FLAG_REPEAT)) {
392 * Check for a size specification.
393 * Defaults to long if no or incorrect specification.
395 size = cmd_get_data_size(argv[0], 4);
396 if (size < 0 && size != -2 /* string */)
401 while (argc && *argv[0] == '-') {
406 else if (ch == 'l' && isxdigit(argv[0][2]))
407 limit = simple_strtoul(argv[0] + 2, NULL, 16);
409 return CMD_RET_USAGE;
414 /* Address is specified since argc > 1 */
415 addr = simple_strtoul(argv[0], NULL, 16);
416 addr += base_address;
418 /* Length is the number of objects, not number of bytes */
419 length = simple_strtoul(argv[1], NULL, 16);
421 /* Read the bytes to search for */
422 end = search_buf + sizeof(search_buf);
423 for (i = 2, ptr = search_buf; i < argc && ptr < end; i++) {
424 if (MEM_SUPPORT_64BIT_DATA && size == 8) {
425 u64 val = simple_strtoull(argv[i], NULL, 16);
428 } else if (size == -2) { /* string */
429 int len = min(strlen(argv[i]),
430 (size_t)(end - ptr));
432 memcpy(ptr, argv[i], len);
436 u32 val = simple_strtoul(argv[i], NULL, 16);
452 search_len = ptr - search_buf;
458 bytes = size * length;
459 buf = map_sysmem(addr, bytes);
464 offset < bytes && offset <= bytes - search_len && count < limit;
466 void *ptr = buf + offset;
468 if (!memcmp(ptr, search_buf, search_len)) {
469 uint align = (addr + offset) & 0xf;
470 ulong match = addr + offset;
472 if (!count || (last_addr & ~0xf) != (match & ~0xf)) {
476 print_buffer(match - align, ptr - align,
478 ALIGN(search_len + align,
482 last_pos = offset / size;
488 printf("%d match%s", count, count == 1 ? "" : "es");
490 printf(" (repeat command to check for more)");
493 env_set_hex("memmatches", count);
494 env_set_hex("memaddr", last_addr);
495 env_set_hex("mempos", last_pos);
499 used_len = offset / size;
500 dp_last_addr = addr + used_len;
502 dp_last_ms_length = length < used_len ? 0 : length - used_len;
504 return count ? 0 : CMD_RET_FAILURE;
508 static int do_mem_base(struct cmd_tbl *cmdtp, int flag, int argc,
512 /* Set new base address.
514 base_address = simple_strtoul(argv[1], NULL, 16);
516 /* Print the current base address.
518 printf("Base Address: 0x%08lx\n", base_address);
522 static int do_mem_loop(struct cmd_tbl *cmdtp, int flag, int argc,
525 ulong addr, length, i, bytes;
527 volatile ulong *llp; /* 64-bit if SUPPORT_64BIT_DATA */
529 volatile u16 *shortp;
534 return CMD_RET_USAGE;
537 * Check for a size specification.
538 * Defaults to long if no or incorrect specification.
540 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
543 /* Address is always specified.
545 addr = simple_strtoul(argv[1], NULL, 16);
547 /* Length is the number of objects, not number of bytes.
549 length = simple_strtoul(argv[2], NULL, 16);
551 bytes = size * length;
552 buf = map_sysmem(addr, bytes);
554 /* We want to optimize the loops to run as fast as possible.
555 * If we have only one object, just run infinite loops.
558 if (SUPPORT_64BIT_DATA && size == 8) {
578 if (SUPPORT_64BIT_DATA && size == 8) {
614 static int do_mem_loopw(struct cmd_tbl *cmdtp, int flag, int argc,
617 ulong addr, length, i, bytes;
619 volatile ulong *llp; /* 64-bit if SUPPORT_64BIT_DATA */
620 ulong data; /* 64-bit if SUPPORT_64BIT_DATA */
622 volatile u16 *shortp;
627 return CMD_RET_USAGE;
630 * Check for a size specification.
631 * Defaults to long if no or incorrect specification.
633 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
636 /* Address is always specified.
638 addr = simple_strtoul(argv[1], NULL, 16);
640 /* Length is the number of objects, not number of bytes.
642 length = simple_strtoul(argv[2], NULL, 16);
645 if (SUPPORT_64BIT_DATA)
646 data = simple_strtoull(argv[3], NULL, 16);
648 data = simple_strtoul(argv[3], NULL, 16);
650 bytes = size * length;
651 buf = map_sysmem(addr, bytes);
653 /* We want to optimize the loops to run as fast as possible.
654 * If we have only one object, just run infinite loops.
657 if (SUPPORT_64BIT_DATA && size == 8) {
677 if (SUPPORT_64BIT_DATA && size == 8) {
708 #endif /* CONFIG_LOOPW */
710 #ifdef CONFIG_CMD_MEMTEST
711 static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr,
722 vu_long anti_pattern;
724 static const ulong bitpattern[] = {
725 0x00000001, /* single bit */
726 0x00000003, /* two adjacent bits */
727 0x00000007, /* three adjacent bits */
728 0x0000000F, /* four adjacent bits */
729 0x00000005, /* two non-adjacent bits */
730 0x00000015, /* three non-adjacent bits */
731 0x00000055, /* four non-adjacent bits */
732 0xaaaaaaaa, /* alternating 1/0 */
735 num_words = (end_addr - start_addr) / sizeof(vu_long);
738 * Data line test: write a pattern to the first
739 * location, write the 1's complement to a 'parking'
740 * address (changes the state of the data bus so a
741 * floating bus doesn't give a false OK), and then
742 * read the value back. Note that we read it back
743 * into a variable because the next time we read it,
744 * it might be right (been there, tough to explain to
745 * the quality guys why it prints a failure when the
746 * "is" and "should be" are obviously the same in the
749 * Rather than exhaustively testing, we test some
750 * patterns by shifting '1' bits through a field of
751 * '0's and '0' bits through a field of '1's (i.e.
752 * pattern and ~pattern).
755 for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) {
757 for (; val != 0; val <<= 1) {
759 *dummy = ~val; /* clear the test data off the bus */
761 if (readback != val) {
762 printf("FAILURE (data line): "
763 "expected %08lx, actual %08lx\n",
772 if (readback != ~val) {
773 printf("FAILURE (data line): "
774 "Is %08lx, should be %08lx\n",
784 * Based on code whose Original Author and Copyright
785 * information follows: Copyright (c) 1998 by Michael
786 * Barr. This software is placed into the public
787 * domain and may be used for any purpose. However,
788 * this notice must not be changed or removed and no
789 * warranty is either expressed or implied by its
790 * publication or distribution.
796 * Description: Test the address bus wiring in a
797 * memory region by performing a walking
798 * 1's test on the relevant bits of the
799 * address and checking for aliasing.
800 * This test will find single-bit
801 * address failures such as stuck-high,
802 * stuck-low, and shorted pins. The base
803 * address and size of the region are
804 * selected by the caller.
806 * Notes: For best results, the selected base
807 * address should have enough LSB 0's to
808 * guarantee single address bit changes.
809 * For example, to test a 64-Kbyte
810 * region, select a base address on a
811 * 64-Kbyte boundary. Also, select the
812 * region size as a power-of-two if at
815 * Returns: 0 if the test succeeds, 1 if the test fails.
817 pattern = (vu_long) 0xaaaaaaaa;
818 anti_pattern = (vu_long) 0x55555555;
820 debug("%s:%d: length = 0x%.8lx\n", __func__, __LINE__, num_words);
822 * Write the default pattern at each of the
823 * power-of-two offsets.
825 for (offset = 1; offset < num_words; offset <<= 1)
826 addr[offset] = pattern;
829 * Check for address bits stuck high.
832 addr[test_offset] = anti_pattern;
834 for (offset = 1; offset < num_words; offset <<= 1) {
836 if (temp != pattern) {
837 printf("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
838 " expected 0x%.8lx, actual 0x%.8lx\n",
839 start_addr + offset*sizeof(vu_long),
846 addr[test_offset] = pattern;
850 * Check for addr bits stuck low or shorted.
852 for (test_offset = 1; test_offset < num_words; test_offset <<= 1) {
853 addr[test_offset] = anti_pattern;
855 for (offset = 1; offset < num_words; offset <<= 1) {
857 if ((temp != pattern) && (offset != test_offset)) {
858 printf("\nFAILURE: Address bit stuck low or"
859 " shorted @ 0x%.8lx: expected 0x%.8lx,"
861 start_addr + offset*sizeof(vu_long),
868 addr[test_offset] = pattern;
872 * Description: Test the integrity of a physical
873 * memory device by performing an
874 * increment/decrement test over the
875 * entire region. In the process every
876 * storage bit in the device is tested
877 * as a zero and a one. The base address
878 * and the size of the region are
879 * selected by the caller.
881 * Returns: 0 if the test succeeds, 1 if the test fails.
886 * Fill memory with a known pattern.
888 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
890 addr[offset] = pattern;
894 * Check each location and invert it for the second pass.
896 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
899 if (temp != pattern) {
900 printf("\nFAILURE (read/write) @ 0x%.8lx:"
901 " expected 0x%.8lx, actual 0x%.8lx)\n",
902 start_addr + offset*sizeof(vu_long),
909 anti_pattern = ~pattern;
910 addr[offset] = anti_pattern;
914 * Check each location for the inverted pattern and zero it.
916 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
918 anti_pattern = ~pattern;
920 if (temp != anti_pattern) {
921 printf("\nFAILURE (read/write): @ 0x%.8lx:"
922 " expected 0x%.8lx, actual 0x%.8lx)\n",
923 start_addr + offset*sizeof(vu_long),
935 static int compare_regions(volatile unsigned long *bufa,
936 volatile unsigned long *bufb, size_t count)
938 volatile unsigned long *p1 = bufa;
939 volatile unsigned long *p2 = bufb;
943 for (i = 0; i < count; i++, p1++, p2++) {
945 printf("FAILURE: 0x%08lx != 0x%08lx (delta=0x%08lx -> bit %ld) at offset 0x%08lx\n",
946 (unsigned long)*p1, (unsigned long)*p2,
947 *p1 ^ *p2, __ffs(*p1 ^ *p2),
948 (unsigned long)(i * sizeof(unsigned long)));
956 static ulong test_bitflip_comparison(volatile unsigned long *bufa,
957 volatile unsigned long *bufb, size_t count)
959 volatile unsigned long *p1 = bufa;
960 volatile unsigned long *p2 = bufb;
967 max = sizeof(unsigned long) * 8;
968 for (k = 0; k < max; k++) {
969 q = 0x00000001L << k;
970 for (j = 0; j < 8; j++) {
973 p1 = (volatile unsigned long *)bufa;
974 p2 = (volatile unsigned long *)bufb;
975 for (i = 0; i < count; i++)
976 *p1++ = *p2++ = (i % 2) == 0 ? q : ~q;
978 errs += compare_regions(bufa, bufb, count);
988 static ulong mem_test_bitflip(vu_long *buf, ulong start, ulong end)
991 * Split the specified range into two halves.
992 * Note that mtest range is inclusive of start,end.
993 * Bitflip test instead uses a count (of 32-bit words).
995 ulong half_size = (end - start + 1) / 2 / sizeof(unsigned long);
997 return test_bitflip_comparison(buf, buf + half_size, half_size);
1000 static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr,
1001 vu_long pattern, int iteration)
1007 ulong val, readback;
1009 /* Alternate the pattern */
1011 if (iteration & 1) {
1014 * Flip the pattern each time to make lots of zeros and
1015 * then, the next time, lots of ones. We decrement
1016 * the "negative" patterns and increment the "positive"
1017 * patterns to preserve this feature.
1019 if (pattern & 0x80000000)
1020 pattern = -pattern; /* complement & increment */
1024 length = (end_addr - start_addr) / sizeof(ulong);
1026 printf("\rPattern %08lX Writing..."
1028 "\b\b\b\b\b\b\b\b\b\b",
1031 for (addr = buf, val = pattern; addr < end; addr++) {
1039 for (addr = buf, val = pattern; addr < end; addr++) {
1042 if (readback != val) {
1043 ulong offset = addr - buf;
1045 printf("\nMem error @ 0x%08X: "
1046 "found %08lX, expected %08lX\n",
1047 (uint)(uintptr_t)(start_addr + offset*sizeof(vu_long)),
1060 * Perform a memory test. A more complete alternative test can be
1061 * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
1062 * interrupted by ctrl-c or by a failure of one of the sub-tests.
1064 static int do_mem_mtest(struct cmd_tbl *cmdtp, int flag, int argc,
1068 vu_long scratch_space;
1069 vu_long *buf, *dummy = &scratch_space;
1070 ulong iteration_limit = 0;
1072 ulong errs = 0; /* number of errors, or -1 if interrupted */
1076 start = CONFIG_SYS_MEMTEST_START;
1077 end = CONFIG_SYS_MEMTEST_END;
1080 if (strict_strtoul(argv[1], 16, &start) < 0)
1081 return CMD_RET_USAGE;
1084 if (strict_strtoul(argv[2], 16, &end) < 0)
1085 return CMD_RET_USAGE;
1088 if (strict_strtoul(argv[3], 16, &pattern) < 0)
1089 return CMD_RET_USAGE;
1092 if (strict_strtoul(argv[4], 16, &iteration_limit) < 0)
1093 return CMD_RET_USAGE;
1096 printf("Refusing to do empty test\n");
1100 printf("Testing %08lx ... %08lx:\n", start, end);
1101 debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__,
1104 buf = map_sysmem(start, end - start);
1106 !iteration_limit || iteration < iteration_limit;
1113 printf("Iteration: %6d\r", iteration + 1);
1115 if (IS_ENABLED(CONFIG_SYS_ALT_MEMTEST)) {
1116 errs = mem_test_alt(buf, start, end, dummy);
1119 if (IS_ENABLED(CONFIG_SYS_ALT_MEMTEST_BITFLIP)) {
1121 errs = mem_test_bitflip(buf, start, end);
1124 errs = mem_test_quick(buf, start, end, pattern,
1132 unmap_sysmem((void *)buf);
1135 /* Memory test was aborted - write a newline to finish off */
1138 printf("Tested %d iteration(s) with %lu errors.\n", iteration, count);
1142 #endif /* CONFIG_CMD_MEMTEST */
1147 * mm{.b, .w, .l, .q} {addr}
1150 mod_mem(struct cmd_tbl *cmdtp, int incrflag, int flag, int argc,
1154 ulong i; /* 64-bit if SUPPORT_64BIT_DATA */
1159 return CMD_RET_USAGE;
1161 bootretry_reset_cmd_timeout(); /* got a good command to get here */
1162 /* We use the last specified parameters, unless new ones are
1165 addr = mm_last_addr;
1166 size = mm_last_size;
1168 if ((flag & CMD_FLAG_REPEAT) == 0) {
1169 /* New command specified. Check for a size specification.
1170 * Defaults to long if no or incorrect specification.
1172 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
1175 /* Address is specified since argc > 1
1177 addr = simple_strtoul(argv[1], NULL, 16);
1178 addr += base_address;
1181 /* Print the address, followed by value. Then accept input for
1182 * the next value. A non-converted value exits.
1185 ptr = map_sysmem(addr, size);
1186 printf("%08lx:", addr);
1188 printf(" %08x", *((u32 *)ptr));
1189 else if (SUPPORT_64BIT_DATA && size == 8)
1190 printf(" %0lx", *((ulong *)ptr));
1192 printf(" %04x", *((u16 *)ptr));
1194 printf(" %02x", *((u8 *)ptr));
1196 nbytes = cli_readline(" ? ");
1197 if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
1198 /* <CR> pressed as only input, don't modify current
1199 * location and move to next. "-" pressed will go back.
1202 addr += nbytes ? -size : size;
1204 /* good enough to not time out */
1205 bootretry_reset_cmd_timeout();
1207 #ifdef CONFIG_BOOT_RETRY_TIME
1208 else if (nbytes == -2) {
1209 break; /* timed out, exit the command */
1214 if (SUPPORT_64BIT_DATA)
1215 i = simple_strtoull(console_buffer, &endp, 16);
1217 i = simple_strtoul(console_buffer, &endp, 16);
1218 nbytes = endp - console_buffer;
1220 /* good enough to not time out
1222 bootretry_reset_cmd_timeout();
1225 else if (SUPPORT_64BIT_DATA && size == 8)
1226 *((ulong *)ptr) = i;
1239 mm_last_addr = addr;
1240 mm_last_size = size;
1244 #ifdef CONFIG_CMD_CRC32
1246 static int do_mem_crc(struct cmd_tbl *cmdtp, int flag, int argc,
1254 return CMD_RET_USAGE;
1258 #ifdef CONFIG_CRC32_VERIFY
1259 if (strcmp(*av, "-v") == 0) {
1260 flags |= HASH_FLAG_VERIFY | HASH_FLAG_ENV;
1266 return hash_command("crc32", flags, cmdtp, flag, ac, av);
1271 #ifdef CONFIG_CMD_RANDOM
1272 static int do_random(struct cmd_tbl *cmdtp, int flag, int argc,
1275 unsigned long addr, len;
1276 unsigned long seed; // NOT INITIALIZED ON PURPOSE
1277 unsigned int *buf, *start;
1278 unsigned char *buf8;
1281 if (argc < 3 || argc > 4)
1282 return CMD_RET_USAGE;
1284 len = simple_strtoul(argv[2], NULL, 16);
1285 addr = simple_strtoul(argv[1], NULL, 16);
1288 seed = simple_strtoul(argv[3], NULL, 16);
1290 printf("The seed cannot be 0. Using 0xDEADBEEF.\n");
1294 seed = get_timer(0) ^ rand();
1298 start = map_sysmem(addr, len);
1300 for (i = 0; i < (len / 4); i++)
1303 buf8 = (unsigned char *)buf;
1304 for (i = 0; i < (len % 4); i++)
1305 *buf8++ = rand() & 0xFF;
1307 unmap_sysmem(start);
1308 printf("%lu bytes filled with random data\n", len);
1310 return CMD_RET_SUCCESS;
1314 /**************************************************/
1316 md, 3, 1, do_mem_md,
1318 "[.b, .w, .l" HELP_Q "] address [# of objects]"
1323 mm, 2, 1, do_mem_mm,
1324 "memory modify (auto-incrementing address)",
1325 "[.b, .w, .l" HELP_Q "] address"
1330 nm, 2, 1, do_mem_nm,
1331 "memory modify (constant address)",
1332 "[.b, .w, .l" HELP_Q "] address"
1336 mw, 4, 1, do_mem_mw,
1337 "memory write (fill)",
1338 "[.b, .w, .l" HELP_Q "] address value [count]"
1342 cp, 4, 1, do_mem_cp,
1344 "[.b, .w, .l" HELP_Q "] source target count"
1348 cmp, 4, 1, do_mem_cmp,
1350 "[.b, .w, .l" HELP_Q "] addr1 addr2 count"
1353 #ifdef CONFIG_CMD_MEM_SEARCH
1354 /**************************************************/
1356 ms, 255, 1, do_mem_search,
1358 "[.b, .w, .l" HELP_Q ", .s] [-q | -<n>] address #-of-objects <value>..."
1359 " -q = quiet, -l<val> = match limit"
1363 #ifdef CONFIG_CMD_CRC32
1365 #ifndef CONFIG_CRC32_VERIFY
1368 crc32, 4, 1, do_mem_crc,
1369 "checksum calculation",
1370 "address count [addr]\n - compute CRC32 checksum [save at addr]"
1373 #else /* CONFIG_CRC32_VERIFY */
1376 crc32, 5, 1, do_mem_crc,
1377 "checksum calculation",
1378 "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
1379 "-v address count crc\n - verify crc of memory area"
1382 #endif /* CONFIG_CRC32_VERIFY */
1386 #ifdef CONFIG_CMD_MEMINFO
1387 static int do_mem_info(struct cmd_tbl *cmdtp, int flag, int argc,
1391 print_size(gd->ram_size, "\n");
1398 base, 2, 1, do_mem_base,
1399 "print or set address offset",
1400 "\n - print address offset for memory commands\n"
1401 "base off\n - set address offset for memory commands to 'off'"
1405 loop, 3, 1, do_mem_loop,
1406 "infinite loop on address range",
1407 "[.b, .w, .l" HELP_Q "] address number_of_objects"
1412 loopw, 4, 1, do_mem_loopw,
1413 "infinite write loop on address range",
1414 "[.b, .w, .l" HELP_Q "] address number_of_objects data_to_write"
1416 #endif /* CONFIG_LOOPW */
1418 #ifdef CONFIG_CMD_MEMTEST
1420 mtest, 5, 1, do_mem_mtest,
1421 "simple RAM read/write test",
1422 "[start [end [pattern [iterations]]]]"
1424 #endif /* CONFIG_CMD_MEMTEST */
1426 #ifdef CONFIG_CMD_MX_CYCLIC
1428 mdc, 4, 1, do_mem_mdc,
1429 "memory display cyclic",
1430 "[.b, .w, .l" HELP_Q "] address count delay(ms)"
1434 mwc, 4, 1, do_mem_mwc,
1435 "memory write cyclic",
1436 "[.b, .w, .l" HELP_Q "] address value delay(ms)"
1438 #endif /* CONFIG_CMD_MX_CYCLIC */
1440 #ifdef CONFIG_CMD_MEMINFO
1442 meminfo, 3, 1, do_mem_info,
1443 "display memory information",
1448 #ifdef CONFIG_CMD_RANDOM
1450 random, 4, 0, do_random,
1451 "fill memory with random pattern",
1452 "<addr> <len> [<seed>]\n"
1453 " - Fill 'len' bytes of memory starting at 'addr' with random data\n"