3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
11 * Copied from FADS ROM, Dan Malek (dmalek@jlc.net)
15 #include <bootretry.h>
18 #ifdef CONFIG_HAS_DATAFLASH
19 #include <dataflash.h>
25 #include <linux/compiler.h>
27 DECLARE_GLOBAL_DATA_PTR
;
29 #ifndef CONFIG_SYS_MEMTEST_SCRATCH
30 #define CONFIG_SYS_MEMTEST_SCRATCH 0
33 static int mod_mem(cmd_tbl_t
*, int, int, int, char * const []);
35 /* Display values from last command.
36 * Memory modify remembered values are different from display memory.
38 static uint dp_last_addr
, dp_last_size
;
39 static uint dp_last_length
= 0x40;
40 static uint mm_last_addr
, mm_last_size
;
42 static ulong base_address
= 0;
47 * md{.b, .w, .l, .q} {addr} {len}
49 #define DISP_LINE_LEN 16
50 static int do_mem_md(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
53 #if defined(CONFIG_HAS_DATAFLASH)
54 ulong nbytes
, linebytes
;
59 /* We use the last specified parameters, unless new ones are
64 length
= dp_last_length
;
69 if ((flag
& CMD_FLAG_REPEAT
) == 0) {
70 /* New command specified. Check for a size specification.
71 * Defaults to long if no or incorrect specification.
73 if ((size
= cmd_get_data_size(argv
[0], 4)) < 0)
76 /* Address is specified since argc > 1
78 addr
= simple_strtoul(argv
[1], NULL
, 16);
81 /* If another parameter, it is the length to display.
82 * Length is the number of objects, not number of bytes.
85 length
= simple_strtoul(argv
[2], NULL
, 16);
88 #if defined(CONFIG_HAS_DATAFLASH)
91 * We buffer all read data, so we can make sure data is read only
92 * once, and all accesses are with the specified bus width.
94 nbytes
= length
* size
;
96 char linebuf
[DISP_LINE_LEN
];
98 linebytes
= (nbytes
>DISP_LINE_LEN
)?DISP_LINE_LEN
:nbytes
;
100 rc
= read_dataflash(addr
, (linebytes
/size
)*size
, linebuf
);
101 p
= (rc
== DATAFLASH_OK
) ? linebuf
: (void*)addr
;
102 print_buffer(addr
, p
, size
, linebytes
/size
, DISP_LINE_LEN
/size
);
110 } while (nbytes
> 0);
113 # if defined(CONFIG_BLACKFIN)
114 /* See if we're trying to display L1 inst */
115 if (addr_bfin_on_chip_mem(addr
)) {
116 char linebuf
[DISP_LINE_LEN
];
117 ulong linebytes
, nbytes
= length
* size
;
119 linebytes
= (nbytes
> DISP_LINE_LEN
) ? DISP_LINE_LEN
: nbytes
;
120 memcpy(linebuf
, (void *)addr
, linebytes
);
121 print_buffer(addr
, linebuf
, size
, linebytes
/size
, DISP_LINE_LEN
/size
);
129 } while (nbytes
> 0);
134 ulong bytes
= size
* length
;
135 const void *buf
= map_sysmem(addr
, bytes
);
137 /* Print the lines. */
138 print_buffer(addr
, buf
, size
, length
, DISP_LINE_LEN
/ size
);
145 dp_last_length
= length
;
150 static int do_mem_mm(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
152 return mod_mem (cmdtp
, 1, flag
, argc
, argv
);
154 static int do_mem_nm(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
156 return mod_mem (cmdtp
, 0, flag
, argc
, argv
);
159 static int do_mem_mw(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
161 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
171 if ((argc
< 3) || (argc
> 4))
172 return CMD_RET_USAGE
;
174 /* Check for size specification.
176 if ((size
= cmd_get_data_size(argv
[0], 4)) < 1)
179 /* Address is specified since argc > 1
181 addr
= simple_strtoul(argv
[1], NULL
, 16);
182 addr
+= base_address
;
184 /* Get the value to write.
186 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
187 writeval
= simple_strtoull(argv
[2], NULL
, 16);
189 writeval
= simple_strtoul(argv
[2], NULL
, 16);
194 count
= simple_strtoul(argv
[3], NULL
, 16);
199 bytes
= size
* count
;
200 buf
= map_sysmem(addr
, bytes
);
201 while (count
-- > 0) {
203 *((u32
*)buf
) = (u32
)writeval
;
204 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
206 *((u64
*)buf
) = (u64
)writeval
;
209 *((u16
*)buf
) = (u16
)writeval
;
211 *((u8
*)buf
) = (u8
)writeval
;
218 #ifdef CONFIG_MX_CYCLIC
219 static int do_mem_mdc(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
225 return CMD_RET_USAGE
;
227 count
= simple_strtoul(argv
[3], NULL
, 10);
230 do_mem_md (NULL
, 0, 3, argv
);
232 /* delay for <count> ms... */
233 for (i
=0; i
<count
; i
++)
236 /* check for ctrl-c to abort... */
246 static int do_mem_mwc(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
252 return CMD_RET_USAGE
;
254 count
= simple_strtoul(argv
[3], NULL
, 10);
257 do_mem_mw (NULL
, 0, 3, argv
);
259 /* delay for <count> ms... */
260 for (i
=0; i
<count
; i
++)
263 /* check for ctrl-c to abort... */
272 #endif /* CONFIG_MX_CYCLIC */
274 static int do_mem_cmp(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
276 ulong addr1
, addr2
, count
, ngood
, bytes
;
280 const void *buf1
, *buf2
, *base
;
281 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
288 return CMD_RET_USAGE
;
290 /* Check for size specification.
292 if ((size
= cmd_get_data_size(argv
[0], 4)) < 0)
294 type
= size
== 8 ? "double word" :
296 size
== 2 ? "halfword" : "byte";
298 addr1
= simple_strtoul(argv
[1], NULL
, 16);
299 addr1
+= base_address
;
301 addr2
= simple_strtoul(argv
[2], NULL
, 16);
302 addr2
+= base_address
;
304 count
= simple_strtoul(argv
[3], NULL
, 16);
306 #ifdef CONFIG_HAS_DATAFLASH
307 if (addr_dataflash(addr1
) | addr_dataflash(addr2
)){
308 puts ("Comparison with DataFlash space not supported.\n\r");
313 #ifdef CONFIG_BLACKFIN
314 if (addr_bfin_on_chip_mem(addr1
) || addr_bfin_on_chip_mem(addr2
)) {
315 puts ("Comparison with L1 instruction memory not supported.\n\r");
320 bytes
= size
* count
;
321 base
= buf1
= map_sysmem(addr1
, bytes
);
322 buf2
= map_sysmem(addr2
, bytes
);
323 for (ngood
= 0; ngood
< count
; ++ngood
) {
325 word1
= *(u32
*)buf1
;
326 word2
= *(u32
*)buf2
;
327 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
328 } else if (size
== 8) {
329 word1
= *(u64
*)buf1
;
330 word2
= *(u64
*)buf2
;
332 } else if (size
== 2) {
333 word1
= *(u16
*)buf1
;
334 word2
= *(u16
*)buf2
;
339 if (word1
!= word2
) {
340 ulong offset
= buf1
- base
;
341 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
342 printf("%s at 0x%p (%#0*"PRIx64
") != %s at 0x%p (%#0*"
344 type
, (void *)(addr1
+ offset
), size
, word1
,
345 type
, (void *)(addr2
+ offset
), size
, word2
);
347 printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n",
348 type
, (ulong
)(addr1
+ offset
), size
, word1
,
349 type
, (ulong
)(addr2
+ offset
), size
, word2
);
358 /* reset watchdog from time to time */
359 if ((ngood
% (64 << 10)) == 0)
365 printf("Total of %ld %s(s) were the same\n", ngood
, type
);
369 static int do_mem_cp(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
371 ulong addr
, dest
, count
, bytes
;
377 return CMD_RET_USAGE
;
379 /* Check for size specification.
381 if ((size
= cmd_get_data_size(argv
[0], 4)) < 0)
384 addr
= simple_strtoul(argv
[1], NULL
, 16);
385 addr
+= base_address
;
387 dest
= simple_strtoul(argv
[2], NULL
, 16);
388 dest
+= base_address
;
390 count
= simple_strtoul(argv
[3], NULL
, 16);
393 puts ("Zero length ???\n");
397 #ifndef CONFIG_SYS_NO_FLASH
398 /* check if we are copying to Flash */
399 if ( (addr2info(dest
) != NULL
)
400 #ifdef CONFIG_HAS_DATAFLASH
401 && (!addr_dataflash(dest
))
406 puts ("Copy to Flash... ");
408 rc
= flash_write ((char *)addr
, dest
, count
*size
);
418 #ifdef CONFIG_HAS_DATAFLASH
419 /* Check if we are copying from RAM or Flash to DataFlash */
420 if (addr_dataflash(dest
) && !addr_dataflash(addr
)){
423 puts ("Copy to DataFlash... ");
425 rc
= write_dataflash (dest
, addr
, count
*size
);
428 dataflash_perror (rc
);
435 /* Check if we are copying from DataFlash to RAM */
436 if (addr_dataflash(addr
) && !addr_dataflash(dest
)
437 #ifndef CONFIG_SYS_NO_FLASH
438 && (addr2info(dest
) == NULL
)
442 rc
= read_dataflash(addr
, count
* size
, (char *) dest
);
444 dataflash_perror (rc
);
450 if (addr_dataflash(addr
) && addr_dataflash(dest
)){
451 puts ("Unsupported combination of source/destination.\n\r");
456 #ifdef CONFIG_BLACKFIN
457 /* See if we're copying to/from L1 inst */
458 if (addr_bfin_on_chip_mem(dest
) || addr_bfin_on_chip_mem(addr
)) {
459 memcpy((void *)dest
, (void *)addr
, count
* size
);
464 bytes
= size
* count
;
465 buf
= map_sysmem(dest
, bytes
);
466 src
= map_sysmem(addr
, bytes
);
467 while (count
-- > 0) {
469 *((u32
*)buf
) = *((u32
*)src
);
470 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
472 *((u64
*)buf
) = *((u64
*)src
);
475 *((u16
*)buf
) = *((u16
*)src
);
477 *((u8
*)buf
) = *((u8
*)src
);
481 /* reset watchdog from time to time */
482 if ((count
% (64 << 10)) == 0)
491 static int do_mem_base(cmd_tbl_t
*cmdtp
, int flag
, int argc
,
495 /* Set new base address.
497 base_address
= simple_strtoul(argv
[1], NULL
, 16);
499 /* Print the current base address.
501 printf("Base Address: 0x%08lx\n", base_address
);
505 static int do_mem_loop(cmd_tbl_t
*cmdtp
, int flag
, int argc
,
508 ulong addr
, length
, i
, bytes
;
510 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
514 volatile u16
*shortp
;
519 return CMD_RET_USAGE
;
522 * Check for a size specification.
523 * Defaults to long if no or incorrect specification.
525 if ((size
= cmd_get_data_size(argv
[0], 4)) < 0)
528 /* Address is always specified.
530 addr
= simple_strtoul(argv
[1], NULL
, 16);
532 /* Length is the number of objects, not number of bytes.
534 length
= simple_strtoul(argv
[2], NULL
, 16);
536 bytes
= size
* length
;
537 buf
= map_sysmem(addr
, bytes
);
539 /* We want to optimize the loops to run as fast as possible.
540 * If we have only one object, just run infinite loops.
543 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
565 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
603 static int do_mem_loopw(cmd_tbl_t
*cmdtp
, int flag
, int argc
,
606 ulong addr
, length
, i
, bytes
;
608 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
615 volatile u16
*shortp
;
620 return CMD_RET_USAGE
;
623 * Check for a size specification.
624 * Defaults to long if no or incorrect specification.
626 if ((size
= cmd_get_data_size(argv
[0], 4)) < 0)
629 /* Address is always specified.
631 addr
= simple_strtoul(argv
[1], NULL
, 16);
633 /* Length is the number of objects, not number of bytes.
635 length
= simple_strtoul(argv
[2], NULL
, 16);
638 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
639 data
= simple_strtoull(argv
[3], NULL
, 16);
641 data
= simple_strtoul(argv
[3], NULL
, 16);
644 bytes
= size
* length
;
645 buf
= map_sysmem(addr
, bytes
);
647 /* We want to optimize the loops to run as fast as possible.
648 * If we have only one object, just run infinite loops.
651 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
673 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
706 #endif /* CONFIG_LOOPW */
708 #ifdef CONFIG_CMD_MEMTEST
709 static ulong
mem_test_alt(vu_long
*buf
, ulong start_addr
, ulong end_addr
,
720 vu_long anti_pattern
;
722 static const ulong bitpattern
[] = {
723 0x00000001, /* single bit */
724 0x00000003, /* two adjacent bits */
725 0x00000007, /* three adjacent bits */
726 0x0000000F, /* four adjacent bits */
727 0x00000005, /* two non-adjacent bits */
728 0x00000015, /* three non-adjacent bits */
729 0x00000055, /* four non-adjacent bits */
730 0xaaaaaaaa, /* alternating 1/0 */
733 num_words
= (end_addr
- start_addr
) / sizeof(vu_long
);
736 * Data line test: write a pattern to the first
737 * location, write the 1's complement to a 'parking'
738 * address (changes the state of the data bus so a
739 * floating bus doesn't give a false OK), and then
740 * read the value back. Note that we read it back
741 * into a variable because the next time we read it,
742 * it might be right (been there, tough to explain to
743 * the quality guys why it prints a failure when the
744 * "is" and "should be" are obviously the same in the
747 * Rather than exhaustively testing, we test some
748 * patterns by shifting '1' bits through a field of
749 * '0's and '0' bits through a field of '1's (i.e.
750 * pattern and ~pattern).
753 for (j
= 0; j
< sizeof(bitpattern
) / sizeof(bitpattern
[0]); j
++) {
755 for (; val
!= 0; val
<<= 1) {
757 *dummy
= ~val
; /* clear the test data off the bus */
759 if (readback
!= val
) {
760 printf("FAILURE (data line): "
761 "expected %08lx, actual %08lx\n",
770 if (readback
!= ~val
) {
771 printf("FAILURE (data line): "
772 "Is %08lx, should be %08lx\n",
782 * Based on code whose Original Author and Copyright
783 * information follows: Copyright (c) 1998 by Michael
784 * Barr. This software is placed into the public
785 * domain and may be used for any purpose. However,
786 * this notice must not be changed or removed and no
787 * warranty is either expressed or implied by its
788 * publication or distribution.
794 * Description: Test the address bus wiring in a
795 * memory region by performing a walking
796 * 1's test on the relevant bits of the
797 * address and checking for aliasing.
798 * This test will find single-bit
799 * address failures such as stuck-high,
800 * stuck-low, and shorted pins. The base
801 * address and size of the region are
802 * selected by the caller.
804 * Notes: For best results, the selected base
805 * address should have enough LSB 0's to
806 * guarantee single address bit changes.
807 * For example, to test a 64-Kbyte
808 * region, select a base address on a
809 * 64-Kbyte boundary. Also, select the
810 * region size as a power-of-two if at
813 * Returns: 0 if the test succeeds, 1 if the test fails.
815 pattern
= (vu_long
) 0xaaaaaaaa;
816 anti_pattern
= (vu_long
) 0x55555555;
818 debug("%s:%d: length = 0x%.8lx\n", __func__
, __LINE__
, num_words
);
820 * Write the default pattern at each of the
821 * power-of-two offsets.
823 for (offset
= 1; offset
< num_words
; offset
<<= 1)
824 addr
[offset
] = pattern
;
827 * Check for address bits stuck high.
830 addr
[test_offset
] = anti_pattern
;
832 for (offset
= 1; offset
< num_words
; offset
<<= 1) {
834 if (temp
!= pattern
) {
835 printf("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
836 " expected 0x%.8lx, actual 0x%.8lx\n",
837 start_addr
+ offset
*sizeof(vu_long
),
844 addr
[test_offset
] = pattern
;
848 * Check for addr bits stuck low or shorted.
850 for (test_offset
= 1; test_offset
< num_words
; test_offset
<<= 1) {
851 addr
[test_offset
] = anti_pattern
;
853 for (offset
= 1; offset
< num_words
; offset
<<= 1) {
855 if ((temp
!= pattern
) && (offset
!= test_offset
)) {
856 printf("\nFAILURE: Address bit stuck low or"
857 " shorted @ 0x%.8lx: expected 0x%.8lx,"
859 start_addr
+ offset
*sizeof(vu_long
),
866 addr
[test_offset
] = pattern
;
870 * Description: Test the integrity of a physical
871 * memory device by performing an
872 * increment/decrement test over the
873 * entire region. In the process every
874 * storage bit in the device is tested
875 * as a zero and a one. The base address
876 * and the size of the region are
877 * selected by the caller.
879 * Returns: 0 if the test succeeds, 1 if the test fails.
884 * Fill memory with a known pattern.
886 for (pattern
= 1, offset
= 0; offset
< num_words
; pattern
++, offset
++) {
888 addr
[offset
] = pattern
;
892 * Check each location and invert it for the second pass.
894 for (pattern
= 1, offset
= 0; offset
< num_words
; pattern
++, offset
++) {
897 if (temp
!= pattern
) {
898 printf("\nFAILURE (read/write) @ 0x%.8lx:"
899 " expected 0x%.8lx, actual 0x%.8lx)\n",
900 start_addr
+ offset
*sizeof(vu_long
),
907 anti_pattern
= ~pattern
;
908 addr
[offset
] = anti_pattern
;
912 * Check each location for the inverted pattern and zero it.
914 for (pattern
= 1, offset
= 0; offset
< num_words
; pattern
++, offset
++) {
916 anti_pattern
= ~pattern
;
918 if (temp
!= anti_pattern
) {
919 printf("\nFAILURE (read/write): @ 0x%.8lx:"
920 " expected 0x%.8lx, actual 0x%.8lx)\n",
921 start_addr
+ offset
*sizeof(vu_long
),
933 static ulong
mem_test_quick(vu_long
*buf
, ulong start_addr
, ulong end_addr
,
934 vu_long pattern
, int iteration
)
942 /* Alternate the pattern */
947 * Flip the pattern each time to make lots of zeros and
948 * then, the next time, lots of ones. We decrement
949 * the "negative" patterns and increment the "positive"
950 * patterns to preserve this feature.
952 if (pattern
& 0x80000000)
953 pattern
= -pattern
; /* complement & increment */
957 length
= (end_addr
- start_addr
) / sizeof(ulong
);
959 printf("\rPattern %08lX Writing..."
961 "\b\b\b\b\b\b\b\b\b\b",
964 for (addr
= buf
, val
= pattern
; addr
< end
; addr
++) {
972 for (addr
= buf
, val
= pattern
; addr
< end
; addr
++) {
975 if (readback
!= val
) {
976 ulong offset
= addr
- buf
;
978 printf("\nMem error @ 0x%08X: "
979 "found %08lX, expected %08lX\n",
980 (uint
)(uintptr_t)(start_addr
+ offset
*sizeof(vu_long
)),
993 * Perform a memory test. A more complete alternative test can be
994 * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
995 * interrupted by ctrl-c or by a failure of one of the sub-tests.
997 static int do_mem_mtest(cmd_tbl_t
*cmdtp
, int flag
, int argc
,
1001 vu_long
*buf
, *dummy
;
1002 ulong iteration_limit
= 0;
1004 ulong errs
= 0; /* number of errors, or -1 if interrupted */
1007 #if defined(CONFIG_SYS_ALT_MEMTEST)
1008 const int alt_test
= 1;
1010 const int alt_test
= 0;
1013 start
= CONFIG_SYS_MEMTEST_START
;
1014 end
= CONFIG_SYS_MEMTEST_END
;
1017 if (strict_strtoul(argv
[1], 16, &start
) < 0)
1018 return CMD_RET_USAGE
;
1021 if (strict_strtoul(argv
[2], 16, &end
) < 0)
1022 return CMD_RET_USAGE
;
1025 if (strict_strtoul(argv
[3], 16, &pattern
) < 0)
1026 return CMD_RET_USAGE
;
1029 if (strict_strtoul(argv
[4], 16, &iteration_limit
) < 0)
1030 return CMD_RET_USAGE
;
1033 printf("Refusing to do empty test\n");
1037 printf("Testing %08x ... %08x:\n", (uint
)start
, (uint
)end
);
1038 debug("%s:%d: start %#08lx end %#08lx\n", __func__
, __LINE__
,
1041 buf
= map_sysmem(start
, end
- start
);
1042 dummy
= map_sysmem(CONFIG_SYS_MEMTEST_SCRATCH
, sizeof(vu_long
));
1044 !iteration_limit
|| iteration
< iteration_limit
;
1051 printf("Iteration: %6d\r", iteration
+ 1);
1054 errs
= mem_test_alt(buf
, start
, end
, dummy
);
1056 errs
= mem_test_quick(buf
, start
, end
, pattern
,
1064 * Work-around for eldk-4.2 which gives this warning if we try to
1065 * case in the unmap_sysmem() call:
1066 * warning: initialization discards qualifiers from pointer target type
1069 void *vbuf
= (void *)buf
;
1070 void *vdummy
= (void *)dummy
;
1073 unmap_sysmem(vdummy
);
1077 /* Memory test was aborted - write a newline to finish off */
1081 printf("Tested %d iteration(s) with %lu errors.\n",
1088 #endif /* CONFIG_CMD_MEMTEST */
1093 * mm{.b, .w, .l, .q} {addr}
1094 * nm{.b, .w, .l, .q} {addr}
1097 mod_mem(cmd_tbl_t
*cmdtp
, int incrflag
, int flag
, int argc
, char * const argv
[])
1100 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1109 return CMD_RET_USAGE
;
1111 bootretry_reset_cmd_timeout(); /* got a good command to get here */
1112 /* We use the last specified parameters, unless new ones are
1115 addr
= mm_last_addr
;
1116 size
= mm_last_size
;
1118 if ((flag
& CMD_FLAG_REPEAT
) == 0) {
1119 /* New command specified. Check for a size specification.
1120 * Defaults to long if no or incorrect specification.
1122 if ((size
= cmd_get_data_size(argv
[0], 4)) < 0)
1125 /* Address is specified since argc > 1
1127 addr
= simple_strtoul(argv
[1], NULL
, 16);
1128 addr
+= base_address
;
1131 #ifdef CONFIG_HAS_DATAFLASH
1132 if (addr_dataflash(addr
)){
1133 puts ("Can't modify DataFlash in place. Use cp instead.\n\r");
1138 #ifdef CONFIG_BLACKFIN
1139 if (addr_bfin_on_chip_mem(addr
)) {
1140 puts ("Can't modify L1 instruction in place. Use cp instead.\n\r");
1145 /* Print the address, followed by value. Then accept input for
1146 * the next value. A non-converted value exits.
1149 ptr
= map_sysmem(addr
, size
);
1150 printf("%08lx:", addr
);
1152 printf(" %08x", *((u32
*)ptr
));
1153 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1155 printf(" %016" PRIx64
, *((u64
*)ptr
));
1158 printf(" %04x", *((u16
*)ptr
));
1160 printf(" %02x", *((u8
*)ptr
));
1162 nbytes
= cli_readline(" ? ");
1163 if (nbytes
== 0 || (nbytes
== 1 && console_buffer
[0] == '-')) {
1164 /* <CR> pressed as only input, don't modify current
1165 * location and move to next. "-" pressed will go back.
1168 addr
+= nbytes
? -size
: size
;
1170 /* good enough to not time out */
1171 bootretry_reset_cmd_timeout();
1173 #ifdef CONFIG_BOOT_RETRY_TIME
1174 else if (nbytes
== -2) {
1175 break; /* timed out, exit the command */
1180 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1181 i
= simple_strtoull(console_buffer
, &endp
, 16);
1183 i
= simple_strtoul(console_buffer
, &endp
, 16);
1185 nbytes
= endp
- console_buffer
;
1187 /* good enough to not time out
1189 bootretry_reset_cmd_timeout();
1192 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1208 mm_last_addr
= addr
;
1209 mm_last_size
= size
;
1213 #ifdef CONFIG_CMD_CRC32
1215 static int do_mem_crc(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
1222 return CMD_RET_USAGE
;
1226 #ifdef CONFIG_HASH_VERIFY
1227 if (strcmp(*av
, "-v") == 0) {
1228 flags
|= HASH_FLAG_VERIFY
;
1234 return hash_command("crc32", flags
, cmdtp
, flag
, ac
, av
);
1239 /**************************************************/
1241 md
, 3, 1, do_mem_md
,
1243 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1244 "[.b, .w, .l, .q] address [# of objects]"
1246 "[.b, .w, .l] address [# of objects]"
1252 mm
, 2, 1, do_mem_mm
,
1253 "memory modify (auto-incrementing address)",
1254 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1255 "[.b, .w, .l, .q] address"
1257 "[.b, .w, .l] address"
1263 nm
, 2, 1, do_mem_nm
,
1264 "memory modify (constant address)",
1265 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1266 "[.b, .w, .l, .q] address"
1268 "[.b, .w, .l] address"
1273 mw
, 4, 1, do_mem_mw
,
1274 "memory write (fill)",
1275 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1276 "[.b, .w, .l, .q] address value [count]"
1278 "[.b, .w, .l] address value [count]"
1283 cp
, 4, 1, do_mem_cp
,
1285 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1286 "[.b, .w, .l, .q] source target count"
1288 "[.b, .w, .l] source target count"
1293 cmp
, 4, 1, do_mem_cmp
,
1295 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1296 "[.b, .w, .l, .q] addr1 addr2 count"
1298 "[.b, .w, .l] addr1 addr2 count"
1302 #ifdef CONFIG_CMD_CRC32
1304 #ifndef CONFIG_CRC32_VERIFY
1307 crc32
, 4, 1, do_mem_crc
,
1308 "checksum calculation",
1309 "address count [addr]\n - compute CRC32 checksum [save at addr]"
1312 #else /* CONFIG_CRC32_VERIFY */
1315 crc32
, 5, 1, do_mem_crc
,
1316 "checksum calculation",
1317 "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
1318 "-v address count crc\n - verify crc of memory area"
1321 #endif /* CONFIG_CRC32_VERIFY */
1325 #ifdef CONFIG_CMD_MEMINFO
1326 __weak
void board_show_dram(ulong size
)
1329 print_size(size
, "\n");
1332 static int do_mem_info(cmd_tbl_t
*cmdtp
, int flag
, int argc
,
1333 char * const argv
[])
1335 board_show_dram(gd
->ram_size
);
1342 base
, 2, 1, do_mem_base
,
1343 "print or set address offset",
1344 "\n - print address offset for memory commands\n"
1345 "base off\n - set address offset for memory commands to 'off'"
1349 loop
, 3, 1, do_mem_loop
,
1350 "infinite loop on address range",
1351 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1352 "[.b, .w, .l, .q] address number_of_objects"
1354 "[.b, .w, .l] address number_of_objects"
1360 loopw
, 4, 1, do_mem_loopw
,
1361 "infinite write loop on address range",
1362 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1363 "[.b, .w, .l, .q] address number_of_objects data_to_write"
1365 "[.b, .w, .l] address number_of_objects data_to_write"
1368 #endif /* CONFIG_LOOPW */
1370 #ifdef CONFIG_CMD_MEMTEST
1372 mtest
, 5, 1, do_mem_mtest
,
1373 "simple RAM read/write test",
1374 "[start [end [pattern [iterations]]]]"
1376 #endif /* CONFIG_CMD_MEMTEST */
1378 #ifdef CONFIG_MX_CYCLIC
1380 mdc
, 4, 1, do_mem_mdc
,
1381 "memory display cyclic",
1382 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1383 "[.b, .w, .l, .q] address count delay(ms)"
1385 "[.b, .w, .l] address count delay(ms)"
1390 mwc
, 4, 1, do_mem_mwc
,
1391 "memory write cyclic",
1392 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1393 "[.b, .w, .l, .q] address value delay(ms)"
1395 "[.b, .w, .l] address value delay(ms)"
1398 #endif /* CONFIG_MX_CYCLIC */
1400 #ifdef CONFIG_CMD_MEMINFO
1402 meminfo
, 3, 1, do_mem_info
,
1403 "display memory information",