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)
16 #include <bootretry.h>
20 #ifdef CONFIG_HAS_DATAFLASH
21 #include <dataflash.h>
28 #include <linux/compiler.h>
30 DECLARE_GLOBAL_DATA_PTR
;
32 #ifndef CONFIG_SYS_MEMTEST_SCRATCH
33 #define CONFIG_SYS_MEMTEST_SCRATCH 0
36 static int mod_mem(cmd_tbl_t
*, int, int, int, char * const []);
38 /* Display values from last command.
39 * Memory modify remembered values are different from display memory.
41 static ulong dp_last_addr
, dp_last_size
;
42 static ulong dp_last_length
= 0x40;
43 static ulong mm_last_addr
, mm_last_size
;
45 static ulong base_address
= 0;
50 * md{.b, .w, .l, .q} {addr} {len}
52 #define DISP_LINE_LEN 16
53 static int do_mem_md(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
56 #if defined(CONFIG_HAS_DATAFLASH)
57 ulong nbytes
, linebytes
;
62 /* We use the last specified parameters, unless new ones are
67 length
= dp_last_length
;
72 if ((flag
& CMD_FLAG_REPEAT
) == 0) {
73 /* New command specified. Check for a size specification.
74 * Defaults to long if no or incorrect specification.
76 if ((size
= cmd_get_data_size(argv
[0], 4)) < 0)
79 /* Address is specified since argc > 1
81 addr
= simple_strtoul(argv
[1], NULL
, 16);
84 /* If another parameter, it is the length to display.
85 * Length is the number of objects, not number of bytes.
88 length
= simple_strtoul(argv
[2], NULL
, 16);
91 #if defined(CONFIG_HAS_DATAFLASH)
94 * We buffer all read data, so we can make sure data is read only
95 * once, and all accesses are with the specified bus width.
97 nbytes
= length
* size
;
99 char linebuf
[DISP_LINE_LEN
];
101 linebytes
= (nbytes
>DISP_LINE_LEN
)?DISP_LINE_LEN
:nbytes
;
103 rc
= read_dataflash(addr
, (linebytes
/size
)*size
, linebuf
);
104 p
= (rc
== DATAFLASH_OK
) ? linebuf
: (void*)addr
;
105 print_buffer(addr
, p
, size
, linebytes
/size
, DISP_LINE_LEN
/size
);
113 } while (nbytes
> 0);
116 # if defined(CONFIG_BLACKFIN)
117 /* See if we're trying to display L1 inst */
118 if (addr_bfin_on_chip_mem(addr
)) {
119 char linebuf
[DISP_LINE_LEN
];
120 ulong linebytes
, nbytes
= length
* size
;
122 linebytes
= (nbytes
> DISP_LINE_LEN
) ? DISP_LINE_LEN
: nbytes
;
123 memcpy(linebuf
, (void *)addr
, linebytes
);
124 print_buffer(addr
, linebuf
, size
, linebytes
/size
, DISP_LINE_LEN
/size
);
132 } while (nbytes
> 0);
137 ulong bytes
= size
* length
;
138 const void *buf
= map_sysmem(addr
, bytes
);
140 /* Print the lines. */
141 print_buffer(addr
, buf
, size
, length
, DISP_LINE_LEN
/ size
);
148 dp_last_length
= length
;
153 static int do_mem_mm(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
155 return mod_mem (cmdtp
, 1, flag
, argc
, argv
);
157 static int do_mem_nm(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
159 return mod_mem (cmdtp
, 0, flag
, argc
, argv
);
162 static int do_mem_mw(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
164 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
174 if ((argc
< 3) || (argc
> 4))
175 return CMD_RET_USAGE
;
177 /* Check for size specification.
179 if ((size
= cmd_get_data_size(argv
[0], 4)) < 1)
182 /* Address is specified since argc > 1
184 addr
= simple_strtoul(argv
[1], NULL
, 16);
185 addr
+= base_address
;
187 /* Get the value to write.
189 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
190 writeval
= simple_strtoull(argv
[2], NULL
, 16);
192 writeval
= simple_strtoul(argv
[2], NULL
, 16);
197 count
= simple_strtoul(argv
[3], NULL
, 16);
202 bytes
= size
* count
;
203 start
= map_sysmem(addr
, bytes
);
205 while (count
-- > 0) {
207 *((u32
*)buf
) = (u32
)writeval
;
208 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
210 *((u64
*)buf
) = (u64
)writeval
;
213 *((u16
*)buf
) = (u16
)writeval
;
215 *((u8
*)buf
) = (u8
)writeval
;
222 #ifdef CONFIG_MX_CYCLIC
223 static int do_mem_mdc(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
229 return CMD_RET_USAGE
;
231 count
= simple_strtoul(argv
[3], NULL
, 10);
234 do_mem_md (NULL
, 0, 3, argv
);
236 /* delay for <count> ms... */
237 for (i
=0; i
<count
; i
++)
240 /* check for ctrl-c to abort... */
250 static int do_mem_mwc(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
256 return CMD_RET_USAGE
;
258 count
= simple_strtoul(argv
[3], NULL
, 10);
261 do_mem_mw (NULL
, 0, 3, argv
);
263 /* delay for <count> ms... */
264 for (i
=0; i
<count
; i
++)
267 /* check for ctrl-c to abort... */
276 #endif /* CONFIG_MX_CYCLIC */
278 static int do_mem_cmp(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
280 ulong addr1
, addr2
, count
, ngood
, bytes
;
284 const void *buf1
, *buf2
, *base
;
285 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
292 return CMD_RET_USAGE
;
294 /* Check for size specification.
296 if ((size
= cmd_get_data_size(argv
[0], 4)) < 0)
298 type
= size
== 8 ? "double word" :
300 size
== 2 ? "halfword" : "byte";
302 addr1
= simple_strtoul(argv
[1], NULL
, 16);
303 addr1
+= base_address
;
305 addr2
= simple_strtoul(argv
[2], NULL
, 16);
306 addr2
+= base_address
;
308 count
= simple_strtoul(argv
[3], NULL
, 16);
310 #ifdef CONFIG_HAS_DATAFLASH
311 if (addr_dataflash(addr1
) | addr_dataflash(addr2
)){
312 puts ("Comparison with DataFlash space not supported.\n\r");
317 #ifdef CONFIG_BLACKFIN
318 if (addr_bfin_on_chip_mem(addr1
) || addr_bfin_on_chip_mem(addr2
)) {
319 puts ("Comparison with L1 instruction memory not supported.\n\r");
324 bytes
= size
* count
;
325 base
= buf1
= map_sysmem(addr1
, bytes
);
326 buf2
= map_sysmem(addr2
, bytes
);
327 for (ngood
= 0; ngood
< count
; ++ngood
) {
329 word1
= *(u32
*)buf1
;
330 word2
= *(u32
*)buf2
;
331 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
332 } else if (size
== 8) {
333 word1
= *(u64
*)buf1
;
334 word2
= *(u64
*)buf2
;
336 } else if (size
== 2) {
337 word1
= *(u16
*)buf1
;
338 word2
= *(u16
*)buf2
;
343 if (word1
!= word2
) {
344 ulong offset
= buf1
- base
;
345 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
346 printf("%s at 0x%p (%#0*"PRIx64
") != %s at 0x%p (%#0*"
348 type
, (void *)(addr1
+ offset
), size
, word1
,
349 type
, (void *)(addr2
+ offset
), size
, word2
);
351 printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n",
352 type
, (ulong
)(addr1
+ offset
), size
, word1
,
353 type
, (ulong
)(addr2
+ offset
), size
, word2
);
362 /* reset watchdog from time to time */
363 if ((ngood
% (64 << 10)) == 0)
369 printf("Total of %ld %s(s) were the same\n", ngood
, type
);
373 static int do_mem_cp(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
375 ulong addr
, dest
, count
, bytes
;
381 return CMD_RET_USAGE
;
383 /* Check for size specification.
385 if ((size
= cmd_get_data_size(argv
[0], 4)) < 0)
388 addr
= simple_strtoul(argv
[1], NULL
, 16);
389 addr
+= base_address
;
391 dest
= simple_strtoul(argv
[2], NULL
, 16);
392 dest
+= base_address
;
394 count
= simple_strtoul(argv
[3], NULL
, 16);
397 puts ("Zero length ???\n");
401 #ifndef CONFIG_SYS_NO_FLASH
402 /* check if we are copying to Flash */
403 if ( (addr2info(dest
) != NULL
)
404 #ifdef CONFIG_HAS_DATAFLASH
405 && (!addr_dataflash(dest
))
410 puts ("Copy to Flash... ");
412 rc
= flash_write ((char *)addr
, dest
, count
*size
);
422 #ifdef CONFIG_HAS_DATAFLASH
423 /* Check if we are copying from RAM or Flash to DataFlash */
424 if (addr_dataflash(dest
) && !addr_dataflash(addr
)){
427 puts ("Copy to DataFlash... ");
429 rc
= write_dataflash (dest
, addr
, count
*size
);
432 dataflash_perror (rc
);
439 /* Check if we are copying from DataFlash to RAM */
440 if (addr_dataflash(addr
) && !addr_dataflash(dest
)
441 #ifndef CONFIG_SYS_NO_FLASH
442 && (addr2info(dest
) == NULL
)
446 rc
= read_dataflash(addr
, count
* size
, (char *) dest
);
448 dataflash_perror (rc
);
454 if (addr_dataflash(addr
) && addr_dataflash(dest
)){
455 puts ("Unsupported combination of source/destination.\n\r");
460 #ifdef CONFIG_BLACKFIN
461 /* See if we're copying to/from L1 inst */
462 if (addr_bfin_on_chip_mem(dest
) || addr_bfin_on_chip_mem(addr
)) {
463 memcpy((void *)dest
, (void *)addr
, count
* size
);
468 bytes
= size
* count
;
469 buf
= map_sysmem(dest
, bytes
);
470 src
= map_sysmem(addr
, bytes
);
471 while (count
-- > 0) {
473 *((u32
*)buf
) = *((u32
*)src
);
474 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
476 *((u64
*)buf
) = *((u64
*)src
);
479 *((u16
*)buf
) = *((u16
*)src
);
481 *((u8
*)buf
) = *((u8
*)src
);
485 /* reset watchdog from time to time */
486 if ((count
% (64 << 10)) == 0)
495 static int do_mem_base(cmd_tbl_t
*cmdtp
, int flag
, int argc
,
499 /* Set new base address.
501 base_address
= simple_strtoul(argv
[1], NULL
, 16);
503 /* Print the current base address.
505 printf("Base Address: 0x%08lx\n", base_address
);
509 static int do_mem_loop(cmd_tbl_t
*cmdtp
, int flag
, int argc
,
512 ulong addr
, length
, i
, bytes
;
514 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
518 volatile u16
*shortp
;
523 return CMD_RET_USAGE
;
526 * Check for a size specification.
527 * Defaults to long if no or incorrect specification.
529 if ((size
= cmd_get_data_size(argv
[0], 4)) < 0)
532 /* Address is always specified.
534 addr
= simple_strtoul(argv
[1], NULL
, 16);
536 /* Length is the number of objects, not number of bytes.
538 length
= simple_strtoul(argv
[2], NULL
, 16);
540 bytes
= size
* length
;
541 buf
= map_sysmem(addr
, bytes
);
543 /* We want to optimize the loops to run as fast as possible.
544 * If we have only one object, just run infinite loops.
547 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
569 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
607 static int do_mem_loopw(cmd_tbl_t
*cmdtp
, int flag
, int argc
,
610 ulong addr
, length
, i
, bytes
;
612 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
619 volatile u16
*shortp
;
624 return CMD_RET_USAGE
;
627 * Check for a size specification.
628 * Defaults to long if no or incorrect specification.
630 if ((size
= cmd_get_data_size(argv
[0], 4)) < 0)
633 /* Address is always specified.
635 addr
= simple_strtoul(argv
[1], NULL
, 16);
637 /* Length is the number of objects, not number of bytes.
639 length
= simple_strtoul(argv
[2], NULL
, 16);
642 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
643 data
= simple_strtoull(argv
[3], NULL
, 16);
645 data
= simple_strtoul(argv
[3], NULL
, 16);
648 bytes
= size
* length
;
649 buf
= map_sysmem(addr
, bytes
);
651 /* We want to optimize the loops to run as fast as possible.
652 * If we have only one object, just run infinite loops.
655 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
677 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
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
) 0xaaaaaaaa;
820 anti_pattern
= (vu_long
) 0x55555555;
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 ulong
mem_test_quick(vu_long
*buf
, ulong start_addr
, ulong end_addr
,
938 vu_long pattern
, int iteration
)
946 /* Alternate the pattern */
951 * Flip the pattern each time to make lots of zeros and
952 * then, the next time, lots of ones. We decrement
953 * the "negative" patterns and increment the "positive"
954 * patterns to preserve this feature.
956 if (pattern
& 0x80000000)
957 pattern
= -pattern
; /* complement & increment */
961 length
= (end_addr
- start_addr
) / sizeof(ulong
);
963 printf("\rPattern %08lX Writing..."
965 "\b\b\b\b\b\b\b\b\b\b",
968 for (addr
= buf
, val
= pattern
; addr
< end
; addr
++) {
976 for (addr
= buf
, val
= pattern
; addr
< end
; addr
++) {
979 if (readback
!= val
) {
980 ulong offset
= addr
- buf
;
982 printf("\nMem error @ 0x%08X: "
983 "found %08lX, expected %08lX\n",
984 (uint
)(uintptr_t)(start_addr
+ offset
*sizeof(vu_long
)),
997 * Perform a memory test. A more complete alternative test can be
998 * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
999 * interrupted by ctrl-c or by a failure of one of the sub-tests.
1001 static int do_mem_mtest(cmd_tbl_t
*cmdtp
, int flag
, int argc
,
1002 char * const argv
[])
1005 vu_long
*buf
, *dummy
;
1006 ulong iteration_limit
= 0;
1008 ulong errs
= 0; /* number of errors, or -1 if interrupted */
1011 #if defined(CONFIG_SYS_ALT_MEMTEST)
1012 const int alt_test
= 1;
1014 const int alt_test
= 0;
1017 start
= CONFIG_SYS_MEMTEST_START
;
1018 end
= CONFIG_SYS_MEMTEST_END
;
1021 if (strict_strtoul(argv
[1], 16, &start
) < 0)
1022 return CMD_RET_USAGE
;
1025 if (strict_strtoul(argv
[2], 16, &end
) < 0)
1026 return CMD_RET_USAGE
;
1029 if (strict_strtoul(argv
[3], 16, &pattern
) < 0)
1030 return CMD_RET_USAGE
;
1033 if (strict_strtoul(argv
[4], 16, &iteration_limit
) < 0)
1034 return CMD_RET_USAGE
;
1037 printf("Refusing to do empty test\n");
1041 printf("Testing %08lx ... %08lx:\n", start
, end
);
1042 debug("%s:%d: start %#08lx end %#08lx\n", __func__
, __LINE__
,
1045 buf
= map_sysmem(start
, end
- start
);
1046 dummy
= map_sysmem(CONFIG_SYS_MEMTEST_SCRATCH
, sizeof(vu_long
));
1048 !iteration_limit
|| iteration
< iteration_limit
;
1055 printf("Iteration: %6d\r", iteration
+ 1);
1058 errs
= mem_test_alt(buf
, start
, end
, dummy
);
1060 errs
= mem_test_quick(buf
, start
, end
, pattern
,
1068 * Work-around for eldk-4.2 which gives this warning if we try to
1069 * case in the unmap_sysmem() call:
1070 * warning: initialization discards qualifiers from pointer target type
1073 void *vbuf
= (void *)buf
;
1074 void *vdummy
= (void *)dummy
;
1077 unmap_sysmem(vdummy
);
1081 /* Memory test was aborted - write a newline to finish off */
1085 printf("Tested %d iteration(s) with %lu errors.\n",
1092 #endif /* CONFIG_CMD_MEMTEST */
1097 * mm{.b, .w, .l, .q} {addr}
1098 * nm{.b, .w, .l, .q} {addr}
1101 mod_mem(cmd_tbl_t
*cmdtp
, int incrflag
, int flag
, int argc
, char * const argv
[])
1104 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1113 return CMD_RET_USAGE
;
1115 bootretry_reset_cmd_timeout(); /* got a good command to get here */
1116 /* We use the last specified parameters, unless new ones are
1119 addr
= mm_last_addr
;
1120 size
= mm_last_size
;
1122 if ((flag
& CMD_FLAG_REPEAT
) == 0) {
1123 /* New command specified. Check for a size specification.
1124 * Defaults to long if no or incorrect specification.
1126 if ((size
= cmd_get_data_size(argv
[0], 4)) < 0)
1129 /* Address is specified since argc > 1
1131 addr
= simple_strtoul(argv
[1], NULL
, 16);
1132 addr
+= base_address
;
1135 #ifdef CONFIG_HAS_DATAFLASH
1136 if (addr_dataflash(addr
)){
1137 puts ("Can't modify DataFlash in place. Use cp instead.\n\r");
1142 #ifdef CONFIG_BLACKFIN
1143 if (addr_bfin_on_chip_mem(addr
)) {
1144 puts ("Can't modify L1 instruction in place. Use cp instead.\n\r");
1149 /* Print the address, followed by value. Then accept input for
1150 * the next value. A non-converted value exits.
1153 ptr
= map_sysmem(addr
, size
);
1154 printf("%08lx:", addr
);
1156 printf(" %08x", *((u32
*)ptr
));
1157 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1159 printf(" %016" PRIx64
, *((u64
*)ptr
));
1162 printf(" %04x", *((u16
*)ptr
));
1164 printf(" %02x", *((u8
*)ptr
));
1166 nbytes
= cli_readline(" ? ");
1167 if (nbytes
== 0 || (nbytes
== 1 && console_buffer
[0] == '-')) {
1168 /* <CR> pressed as only input, don't modify current
1169 * location and move to next. "-" pressed will go back.
1172 addr
+= nbytes
? -size
: size
;
1174 /* good enough to not time out */
1175 bootretry_reset_cmd_timeout();
1177 #ifdef CONFIG_BOOT_RETRY_TIME
1178 else if (nbytes
== -2) {
1179 break; /* timed out, exit the command */
1184 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1185 i
= simple_strtoull(console_buffer
, &endp
, 16);
1187 i
= simple_strtoul(console_buffer
, &endp
, 16);
1189 nbytes
= endp
- console_buffer
;
1191 /* good enough to not time out
1193 bootretry_reset_cmd_timeout();
1196 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1212 mm_last_addr
= addr
;
1213 mm_last_size
= size
;
1217 #ifdef CONFIG_CMD_CRC32
1219 static int do_mem_crc(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
1226 return CMD_RET_USAGE
;
1230 #ifdef CONFIG_HASH_VERIFY
1231 if (strcmp(*av
, "-v") == 0) {
1232 flags
|= HASH_FLAG_VERIFY
| HASH_FLAG_ENV
;
1238 return hash_command("crc32", flags
, cmdtp
, flag
, ac
, av
);
1243 /**************************************************/
1245 md
, 3, 1, do_mem_md
,
1247 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1248 "[.b, .w, .l, .q] address [# of objects]"
1250 "[.b, .w, .l] address [# of objects]"
1256 mm
, 2, 1, do_mem_mm
,
1257 "memory modify (auto-incrementing address)",
1258 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1259 "[.b, .w, .l, .q] address"
1261 "[.b, .w, .l] address"
1267 nm
, 2, 1, do_mem_nm
,
1268 "memory modify (constant address)",
1269 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1270 "[.b, .w, .l, .q] address"
1272 "[.b, .w, .l] address"
1277 mw
, 4, 1, do_mem_mw
,
1278 "memory write (fill)",
1279 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1280 "[.b, .w, .l, .q] address value [count]"
1282 "[.b, .w, .l] address value [count]"
1287 cp
, 4, 1, do_mem_cp
,
1289 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1290 "[.b, .w, .l, .q] source target count"
1292 "[.b, .w, .l] source target count"
1297 cmp
, 4, 1, do_mem_cmp
,
1299 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1300 "[.b, .w, .l, .q] addr1 addr2 count"
1302 "[.b, .w, .l] addr1 addr2 count"
1306 #ifdef CONFIG_CMD_CRC32
1308 #ifndef CONFIG_HASH_VERIFY
1311 crc32
, 4, 1, do_mem_crc
,
1312 "checksum calculation",
1313 "address count [addr]\n - compute CRC32 checksum [save at addr]"
1316 #else /* CONFIG_HASH_VERIFY */
1319 crc32
, 5, 1, do_mem_crc
,
1320 "checksum calculation",
1321 "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
1322 "-v address count crc\n - verify crc of memory area"
1325 #endif /* CONFIG_HASH_VERIFY */
1329 #ifdef CONFIG_CMD_MEMINFO
1330 __weak
void board_show_dram(phys_size_t size
)
1333 print_size(size
, "\n");
1336 static int do_mem_info(cmd_tbl_t
*cmdtp
, int flag
, int argc
,
1337 char * const argv
[])
1339 board_show_dram(gd
->ram_size
);
1346 base
, 2, 1, do_mem_base
,
1347 "print or set address offset",
1348 "\n - print address offset for memory commands\n"
1349 "base off\n - set address offset for memory commands to 'off'"
1353 loop
, 3, 1, do_mem_loop
,
1354 "infinite loop on address range",
1355 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1356 "[.b, .w, .l, .q] address number_of_objects"
1358 "[.b, .w, .l] address number_of_objects"
1364 loopw
, 4, 1, do_mem_loopw
,
1365 "infinite write loop on address range",
1366 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1367 "[.b, .w, .l, .q] address number_of_objects data_to_write"
1369 "[.b, .w, .l] address number_of_objects data_to_write"
1372 #endif /* CONFIG_LOOPW */
1374 #ifdef CONFIG_CMD_MEMTEST
1376 mtest
, 5, 1, do_mem_mtest
,
1377 "simple RAM read/write test",
1378 "[start [end [pattern [iterations]]]]"
1380 #endif /* CONFIG_CMD_MEMTEST */
1382 #ifdef CONFIG_MX_CYCLIC
1384 mdc
, 4, 1, do_mem_mdc
,
1385 "memory display cyclic",
1386 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1387 "[.b, .w, .l, .q] address count delay(ms)"
1389 "[.b, .w, .l] address count delay(ms)"
1394 mwc
, 4, 1, do_mem_mwc
,
1395 "memory write cyclic",
1396 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
1397 "[.b, .w, .l, .q] address value delay(ms)"
1399 "[.b, .w, .l] address value delay(ms)"
1402 #endif /* CONFIG_MX_CYCLIC */
1404 #ifdef CONFIG_CMD_MEMINFO
1406 meminfo
, 3, 1, do_mem_info
,
1407 "display memory information",