wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * Memory Functions |
| 10 | * |
| 11 | * Copied from FADS ROM, Dan Malek (dmalek@jlc.net) |
| 12 | */ |
| 13 | |
| 14 | #include <common.h> |
Simon Glass | 24b852a | 2015-11-08 23:47:45 -0700 | [diff] [blame] | 15 | #include <console.h> |
Simon Glass | 0098e17 | 2014-04-10 20:01:30 -0600 | [diff] [blame] | 16 | #include <bootretry.h> |
Simon Glass | 18d6653 | 2014-04-10 20:01:25 -0600 | [diff] [blame] | 17 | #include <cli.h> |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 18 | #include <command.h> |
Simon Glass | 24b852a | 2015-11-08 23:47:45 -0700 | [diff] [blame] | 19 | #include <console.h> |
Simon Glass | d20a40d | 2013-02-24 20:30:22 +0000 | [diff] [blame] | 20 | #include <hash.h> |
Simon Glass | e48f374 | 2014-11-11 12:47:07 -0700 | [diff] [blame] | 21 | #include <inttypes.h> |
Joe Hershberger | 0eb25b6 | 2015-03-22 17:08:59 -0500 | [diff] [blame] | 22 | #include <mapmem.h> |
Sergei Poselenov | a6e6fc6 | 2008-04-09 16:09:41 +0200 | [diff] [blame] | 23 | #include <watchdog.h> |
Simon Glass | 0628ab8 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 24 | #include <asm/io.h> |
Simon Glass | 15a33e4 | 2012-11-30 13:01:20 +0000 | [diff] [blame] | 25 | #include <linux/compiler.h> |
| 26 | |
| 27 | DECLARE_GLOBAL_DATA_PTR; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 28 | |
Simon Glass | 8e169cc | 2013-02-24 17:33:29 +0000 | [diff] [blame] | 29 | #ifndef CONFIG_SYS_MEMTEST_SCRATCH |
| 30 | #define CONFIG_SYS_MEMTEST_SCRATCH 0 |
| 31 | #endif |
| 32 | |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 33 | static int mod_mem(cmd_tbl_t *, int, int, int, char * const []); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 34 | |
| 35 | /* Display values from last command. |
| 36 | * Memory modify remembered values are different from display memory. |
| 37 | */ |
Scott Wood | 581508b | 2015-03-19 09:43:12 -0700 | [diff] [blame] | 38 | static ulong dp_last_addr, dp_last_size; |
| 39 | static ulong dp_last_length = 0x40; |
| 40 | static ulong mm_last_addr, mm_last_size; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 41 | |
| 42 | static ulong base_address = 0; |
| 43 | |
| 44 | /* Memory Display |
| 45 | * |
| 46 | * Syntax: |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 47 | * md{.b, .w, .l, .q} {addr} {len} |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 48 | */ |
| 49 | #define DISP_LINE_LEN 16 |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 50 | static int do_mem_md(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 51 | { |
Tuomas Tynkkynen | c68c03f | 2017-10-10 21:59:42 +0300 | [diff] [blame] | 52 | ulong addr, length, bytes; |
| 53 | const void *buf; |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 54 | int size; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 55 | int rc = 0; |
| 56 | |
| 57 | /* We use the last specified parameters, unless new ones are |
| 58 | * entered. |
| 59 | */ |
| 60 | addr = dp_last_addr; |
| 61 | size = dp_last_size; |
| 62 | length = dp_last_length; |
| 63 | |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 64 | if (argc < 2) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 65 | return CMD_RET_USAGE; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 66 | |
| 67 | if ((flag & CMD_FLAG_REPEAT) == 0) { |
| 68 | /* New command specified. Check for a size specification. |
| 69 | * Defaults to long if no or incorrect specification. |
| 70 | */ |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 71 | if ((size = cmd_get_data_size(argv[0], 4)) < 0) |
| 72 | return 1; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 73 | |
| 74 | /* Address is specified since argc > 1 |
| 75 | */ |
| 76 | addr = simple_strtoul(argv[1], NULL, 16); |
| 77 | addr += base_address; |
| 78 | |
| 79 | /* If another parameter, it is the length to display. |
| 80 | * Length is the number of objects, not number of bytes. |
| 81 | */ |
| 82 | if (argc > 2) |
| 83 | length = simple_strtoul(argv[2], NULL, 16); |
| 84 | } |
| 85 | |
Tuomas Tynkkynen | c68c03f | 2017-10-10 21:59:42 +0300 | [diff] [blame] | 86 | bytes = size * length; |
| 87 | buf = map_sysmem(addr, bytes); |
wdenk | 2abbe07 | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 88 | |
Tuomas Tynkkynen | c68c03f | 2017-10-10 21:59:42 +0300 | [diff] [blame] | 89 | /* Print the lines. */ |
| 90 | print_buffer(addr, buf, size, length, DISP_LINE_LEN / size); |
| 91 | addr += bytes; |
| 92 | unmap_sysmem(buf); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 93 | |
| 94 | dp_last_addr = addr; |
| 95 | dp_last_length = length; |
| 96 | dp_last_size = size; |
| 97 | return (rc); |
| 98 | } |
| 99 | |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 100 | static int do_mem_mm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 101 | { |
| 102 | return mod_mem (cmdtp, 1, flag, argc, argv); |
| 103 | } |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 104 | static int do_mem_nm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 105 | { |
| 106 | return mod_mem (cmdtp, 0, flag, argc, argv); |
| 107 | } |
| 108 | |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 109 | static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 110 | { |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 111 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 112 | u64 writeval; |
| 113 | #else |
| 114 | ulong writeval; |
| 115 | #endif |
| 116 | ulong addr, count; |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 117 | int size; |
Simon Glass | cc5e196 | 2015-03-05 12:25:18 -0700 | [diff] [blame] | 118 | void *buf, *start; |
Simon Glass | 0628ab8 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 119 | ulong bytes; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 120 | |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 121 | if ((argc < 3) || (argc > 4)) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 122 | return CMD_RET_USAGE; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 123 | |
| 124 | /* Check for size specification. |
| 125 | */ |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 126 | if ((size = cmd_get_data_size(argv[0], 4)) < 1) |
| 127 | return 1; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 128 | |
| 129 | /* Address is specified since argc > 1 |
| 130 | */ |
| 131 | addr = simple_strtoul(argv[1], NULL, 16); |
| 132 | addr += base_address; |
| 133 | |
| 134 | /* Get the value to write. |
| 135 | */ |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 136 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 137 | writeval = simple_strtoull(argv[2], NULL, 16); |
| 138 | #else |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 139 | writeval = simple_strtoul(argv[2], NULL, 16); |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 140 | #endif |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 141 | |
| 142 | /* Count ? */ |
| 143 | if (argc == 4) { |
| 144 | count = simple_strtoul(argv[3], NULL, 16); |
| 145 | } else { |
| 146 | count = 1; |
| 147 | } |
| 148 | |
Simon Glass | 0628ab8 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 149 | bytes = size * count; |
Simon Glass | cc5e196 | 2015-03-05 12:25:18 -0700 | [diff] [blame] | 150 | start = map_sysmem(addr, bytes); |
| 151 | buf = start; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 152 | while (count-- > 0) { |
| 153 | if (size == 4) |
York Sun | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 154 | *((u32 *)buf) = (u32)writeval; |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 155 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 156 | else if (size == 8) |
| 157 | *((u64 *)buf) = (u64)writeval; |
| 158 | #endif |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 159 | else if (size == 2) |
York Sun | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 160 | *((u16 *)buf) = (u16)writeval; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 161 | else |
York Sun | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 162 | *((u8 *)buf) = (u8)writeval; |
Simon Glass | 0628ab8 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 163 | buf += size; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 164 | } |
Simon Glass | cc5e196 | 2015-03-05 12:25:18 -0700 | [diff] [blame] | 165 | unmap_sysmem(start); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 166 | return 0; |
| 167 | } |
| 168 | |
stroese | 4aaf29b | 2004-12-16 17:42:39 +0000 | [diff] [blame] | 169 | #ifdef CONFIG_MX_CYCLIC |
Masahiro Yamada | 5a8608e | 2014-09-04 00:38:26 +0900 | [diff] [blame] | 170 | static int do_mem_mdc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
stroese | 4aaf29b | 2004-12-16 17:42:39 +0000 | [diff] [blame] | 171 | { |
| 172 | int i; |
| 173 | ulong count; |
| 174 | |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 175 | if (argc < 4) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 176 | return CMD_RET_USAGE; |
stroese | 4aaf29b | 2004-12-16 17:42:39 +0000 | [diff] [blame] | 177 | |
| 178 | count = simple_strtoul(argv[3], NULL, 10); |
| 179 | |
| 180 | for (;;) { |
| 181 | do_mem_md (NULL, 0, 3, argv); |
| 182 | |
| 183 | /* delay for <count> ms... */ |
| 184 | for (i=0; i<count; i++) |
| 185 | udelay (1000); |
| 186 | |
| 187 | /* check for ctrl-c to abort... */ |
| 188 | if (ctrlc()) { |
| 189 | puts("Abort\n"); |
| 190 | return 0; |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | return 0; |
| 195 | } |
| 196 | |
Masahiro Yamada | 5a8608e | 2014-09-04 00:38:26 +0900 | [diff] [blame] | 197 | static int do_mem_mwc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
stroese | 4aaf29b | 2004-12-16 17:42:39 +0000 | [diff] [blame] | 198 | { |
| 199 | int i; |
| 200 | ulong count; |
| 201 | |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 202 | if (argc < 4) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 203 | return CMD_RET_USAGE; |
stroese | 4aaf29b | 2004-12-16 17:42:39 +0000 | [diff] [blame] | 204 | |
| 205 | count = simple_strtoul(argv[3], NULL, 10); |
| 206 | |
| 207 | for (;;) { |
| 208 | do_mem_mw (NULL, 0, 3, argv); |
| 209 | |
| 210 | /* delay for <count> ms... */ |
| 211 | for (i=0; i<count; i++) |
| 212 | udelay (1000); |
| 213 | |
| 214 | /* check for ctrl-c to abort... */ |
| 215 | if (ctrlc()) { |
| 216 | puts("Abort\n"); |
| 217 | return 0; |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | return 0; |
| 222 | } |
| 223 | #endif /* CONFIG_MX_CYCLIC */ |
| 224 | |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 225 | static int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 226 | { |
Simon Glass | 0628ab8 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 227 | ulong addr1, addr2, count, ngood, bytes; |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 228 | int size; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 229 | int rcode = 0; |
Mike Frysinger | 054ea17 | 2012-01-20 09:07:21 +0000 | [diff] [blame] | 230 | const char *type; |
Simon Glass | 0628ab8 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 231 | const void *buf1, *buf2, *base; |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 232 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 233 | u64 word1, word2; |
| 234 | #else |
| 235 | ulong word1, word2; |
| 236 | #endif |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 237 | |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 238 | if (argc != 4) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 239 | return CMD_RET_USAGE; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 240 | |
| 241 | /* Check for size specification. |
| 242 | */ |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 243 | if ((size = cmd_get_data_size(argv[0], 4)) < 0) |
| 244 | return 1; |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 245 | type = size == 8 ? "double word" : |
| 246 | size == 4 ? "word" : |
| 247 | size == 2 ? "halfword" : "byte"; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 248 | |
| 249 | addr1 = simple_strtoul(argv[1], NULL, 16); |
| 250 | addr1 += base_address; |
| 251 | |
| 252 | addr2 = simple_strtoul(argv[2], NULL, 16); |
| 253 | addr2 += base_address; |
| 254 | |
| 255 | count = simple_strtoul(argv[3], NULL, 16); |
| 256 | |
Simon Glass | 0628ab8 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 257 | bytes = size * count; |
| 258 | base = buf1 = map_sysmem(addr1, bytes); |
| 259 | buf2 = map_sysmem(addr2, bytes); |
Mike Frysinger | feb12a1 | 2012-01-20 09:07:22 +0000 | [diff] [blame] | 260 | for (ngood = 0; ngood < count; ++ngood) { |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 261 | if (size == 4) { |
York Sun | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 262 | word1 = *(u32 *)buf1; |
| 263 | word2 = *(u32 *)buf2; |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 264 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 265 | } else if (size == 8) { |
| 266 | word1 = *(u64 *)buf1; |
| 267 | word2 = *(u64 *)buf2; |
| 268 | #endif |
Mike Frysinger | 054ea17 | 2012-01-20 09:07:21 +0000 | [diff] [blame] | 269 | } else if (size == 2) { |
York Sun | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 270 | word1 = *(u16 *)buf1; |
| 271 | word2 = *(u16 *)buf2; |
Mike Frysinger | 054ea17 | 2012-01-20 09:07:21 +0000 | [diff] [blame] | 272 | } else { |
York Sun | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 273 | word1 = *(u8 *)buf1; |
| 274 | word2 = *(u8 *)buf2; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 275 | } |
Mike Frysinger | 054ea17 | 2012-01-20 09:07:21 +0000 | [diff] [blame] | 276 | if (word1 != word2) { |
Simon Glass | 0628ab8 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 277 | ulong offset = buf1 - base; |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 278 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
Simon Glass | e48f374 | 2014-11-11 12:47:07 -0700 | [diff] [blame] | 279 | printf("%s at 0x%p (%#0*"PRIx64") != %s at 0x%p (%#0*" |
| 280 | PRIx64 ")\n", |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 281 | type, (void *)(addr1 + offset), size, word1, |
| 282 | type, (void *)(addr2 + offset), size, word2); |
| 283 | #else |
Mike Frysinger | 054ea17 | 2012-01-20 09:07:21 +0000 | [diff] [blame] | 284 | printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n", |
Simon Glass | 0628ab8 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 285 | type, (ulong)(addr1 + offset), size, word1, |
| 286 | type, (ulong)(addr2 + offset), size, word2); |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 287 | #endif |
Mike Frysinger | 054ea17 | 2012-01-20 09:07:21 +0000 | [diff] [blame] | 288 | rcode = 1; |
| 289 | break; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 290 | } |
Mike Frysinger | 054ea17 | 2012-01-20 09:07:21 +0000 | [diff] [blame] | 291 | |
Simon Glass | 0628ab8 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 292 | buf1 += size; |
| 293 | buf2 += size; |
Stefan Roese | eaadb44 | 2010-09-13 11:10:34 +0200 | [diff] [blame] | 294 | |
| 295 | /* reset watchdog from time to time */ |
Mike Frysinger | feb12a1 | 2012-01-20 09:07:22 +0000 | [diff] [blame] | 296 | if ((ngood % (64 << 10)) == 0) |
Stefan Roese | eaadb44 | 2010-09-13 11:10:34 +0200 | [diff] [blame] | 297 | WATCHDOG_RESET(); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 298 | } |
Simon Glass | 0628ab8 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 299 | unmap_sysmem(buf1); |
| 300 | unmap_sysmem(buf2); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 301 | |
Mike Frysinger | 054ea17 | 2012-01-20 09:07:21 +0000 | [diff] [blame] | 302 | printf("Total of %ld %s(s) were the same\n", ngood, type); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 303 | return rcode; |
| 304 | } |
| 305 | |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 306 | static int do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 307 | { |
Fabio Estevam | c253842 | 2016-12-15 16:00:13 -0200 | [diff] [blame] | 308 | ulong addr, dest, count; |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 309 | int size; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 310 | |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 311 | if (argc != 4) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 312 | return CMD_RET_USAGE; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 313 | |
| 314 | /* Check for size specification. |
| 315 | */ |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 316 | if ((size = cmd_get_data_size(argv[0], 4)) < 0) |
| 317 | return 1; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 318 | |
| 319 | addr = simple_strtoul(argv[1], NULL, 16); |
| 320 | addr += base_address; |
| 321 | |
| 322 | dest = simple_strtoul(argv[2], NULL, 16); |
| 323 | dest += base_address; |
| 324 | |
| 325 | count = simple_strtoul(argv[3], NULL, 16); |
| 326 | |
| 327 | if (count == 0) { |
| 328 | puts ("Zero length ???\n"); |
| 329 | return 1; |
| 330 | } |
| 331 | |
Masahiro Yamada | e856bdc | 2017-02-11 22:43:54 +0900 | [diff] [blame] | 332 | #ifdef CONFIG_MTD_NOR_FLASH |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 333 | /* check if we are copying to Flash */ |
Tuomas Tynkkynen | c68c03f | 2017-10-10 21:59:42 +0300 | [diff] [blame] | 334 | if (addr2info(dest) != NULL) { |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 335 | int rc; |
| 336 | |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 337 | puts ("Copy to Flash... "); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 338 | |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 339 | rc = flash_write ((char *)addr, dest, count*size); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 340 | if (rc != 0) { |
| 341 | flash_perror (rc); |
| 342 | return (1); |
| 343 | } |
| 344 | puts ("done\n"); |
| 345 | return 0; |
| 346 | } |
| 347 | #endif |
| 348 | |
Fabio Estevam | c253842 | 2016-12-15 16:00:13 -0200 | [diff] [blame] | 349 | memcpy((void *)dest, (void *)addr, count * size); |
Masahiro Yamada | a3a4749 | 2014-10-23 17:46:24 +0900 | [diff] [blame] | 350 | |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 351 | return 0; |
| 352 | } |
| 353 | |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 354 | static int do_mem_base(cmd_tbl_t *cmdtp, int flag, int argc, |
| 355 | char * const argv[]) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 356 | { |
| 357 | if (argc > 1) { |
| 358 | /* Set new base address. |
| 359 | */ |
| 360 | base_address = simple_strtoul(argv[1], NULL, 16); |
| 361 | } |
| 362 | /* Print the current base address. |
| 363 | */ |
| 364 | printf("Base Address: 0x%08lx\n", base_address); |
| 365 | return 0; |
| 366 | } |
| 367 | |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 368 | static int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc, |
| 369 | char * const argv[]) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 370 | { |
Simon Glass | 0628ab8 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 371 | ulong addr, length, i, bytes; |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 372 | int size; |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 373 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 374 | volatile u64 *llp; |
| 375 | #endif |
York Sun | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 376 | volatile u32 *longp; |
| 377 | volatile u16 *shortp; |
| 378 | volatile u8 *cp; |
Simon Glass | 0628ab8 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 379 | const void *buf; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 380 | |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 381 | if (argc < 3) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 382 | return CMD_RET_USAGE; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 383 | |
Robert P. J. Day | 85de63e | 2013-02-03 02:29:54 +0000 | [diff] [blame] | 384 | /* |
| 385 | * Check for a size specification. |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 386 | * Defaults to long if no or incorrect specification. |
| 387 | */ |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 388 | if ((size = cmd_get_data_size(argv[0], 4)) < 0) |
| 389 | return 1; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 390 | |
| 391 | /* Address is always specified. |
| 392 | */ |
| 393 | addr = simple_strtoul(argv[1], NULL, 16); |
| 394 | |
| 395 | /* Length is the number of objects, not number of bytes. |
| 396 | */ |
| 397 | length = simple_strtoul(argv[2], NULL, 16); |
| 398 | |
Simon Glass | 0628ab8 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 399 | bytes = size * length; |
| 400 | buf = map_sysmem(addr, bytes); |
| 401 | |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 402 | /* We want to optimize the loops to run as fast as possible. |
| 403 | * If we have only one object, just run infinite loops. |
| 404 | */ |
| 405 | if (length == 1) { |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 406 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 407 | if (size == 8) { |
| 408 | llp = (u64 *)buf; |
| 409 | for (;;) |
| 410 | i = *llp; |
| 411 | } |
| 412 | #endif |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 413 | if (size == 4) { |
York Sun | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 414 | longp = (u32 *)buf; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 415 | for (;;) |
| 416 | i = *longp; |
| 417 | } |
| 418 | if (size == 2) { |
York Sun | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 419 | shortp = (u16 *)buf; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 420 | for (;;) |
| 421 | i = *shortp; |
| 422 | } |
York Sun | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 423 | cp = (u8 *)buf; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 424 | for (;;) |
| 425 | i = *cp; |
| 426 | } |
| 427 | |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 428 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 429 | if (size == 8) { |
| 430 | for (;;) { |
| 431 | llp = (u64 *)buf; |
| 432 | i = length; |
| 433 | while (i-- > 0) |
| 434 | *llp++; |
| 435 | } |
| 436 | } |
| 437 | #endif |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 438 | if (size == 4) { |
| 439 | for (;;) { |
York Sun | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 440 | longp = (u32 *)buf; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 441 | i = length; |
| 442 | while (i-- > 0) |
Marek Vasut | f3b3c3d | 2011-09-26 02:26:06 +0200 | [diff] [blame] | 443 | *longp++; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 444 | } |
| 445 | } |
| 446 | if (size == 2) { |
| 447 | for (;;) { |
York Sun | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 448 | shortp = (u16 *)buf; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 449 | i = length; |
| 450 | while (i-- > 0) |
Marek Vasut | f3b3c3d | 2011-09-26 02:26:06 +0200 | [diff] [blame] | 451 | *shortp++; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 452 | } |
| 453 | } |
| 454 | for (;;) { |
York Sun | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 455 | cp = (u8 *)buf; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 456 | i = length; |
| 457 | while (i-- > 0) |
Marek Vasut | f3b3c3d | 2011-09-26 02:26:06 +0200 | [diff] [blame] | 458 | *cp++; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 459 | } |
Simon Glass | 0628ab8 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 460 | unmap_sysmem(buf); |
Simon Glass | 92765f42 | 2013-06-11 11:14:35 -0700 | [diff] [blame] | 461 | |
| 462 | return 0; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 463 | } |
| 464 | |
wdenk | 56523f1 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 465 | #ifdef CONFIG_LOOPW |
Masahiro Yamada | 5a8608e | 2014-09-04 00:38:26 +0900 | [diff] [blame] | 466 | static int do_mem_loopw(cmd_tbl_t *cmdtp, int flag, int argc, |
| 467 | char * const argv[]) |
wdenk | 56523f1 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 468 | { |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 469 | ulong addr, length, i, bytes; |
wdenk | 56523f1 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 470 | int size; |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 471 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 472 | volatile u64 *llp; |
| 473 | u64 data; |
| 474 | #else |
| 475 | ulong data; |
| 476 | #endif |
York Sun | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 477 | volatile u32 *longp; |
| 478 | volatile u16 *shortp; |
| 479 | volatile u8 *cp; |
Simon Glass | 0628ab8 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 480 | void *buf; |
wdenk | 8105092 | 2004-07-11 20:04:51 +0000 | [diff] [blame] | 481 | |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 482 | if (argc < 4) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 483 | return CMD_RET_USAGE; |
wdenk | 56523f1 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 484 | |
Robert P. J. Day | 85de63e | 2013-02-03 02:29:54 +0000 | [diff] [blame] | 485 | /* |
| 486 | * Check for a size specification. |
wdenk | 56523f1 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 487 | * Defaults to long if no or incorrect specification. |
| 488 | */ |
| 489 | if ((size = cmd_get_data_size(argv[0], 4)) < 0) |
| 490 | return 1; |
| 491 | |
| 492 | /* Address is always specified. |
| 493 | */ |
| 494 | addr = simple_strtoul(argv[1], NULL, 16); |
| 495 | |
| 496 | /* Length is the number of objects, not number of bytes. |
| 497 | */ |
| 498 | length = simple_strtoul(argv[2], NULL, 16); |
| 499 | |
| 500 | /* data to write */ |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 501 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 502 | data = simple_strtoull(argv[3], NULL, 16); |
| 503 | #else |
wdenk | 56523f1 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 504 | data = simple_strtoul(argv[3], NULL, 16); |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 505 | #endif |
wdenk | 8105092 | 2004-07-11 20:04:51 +0000 | [diff] [blame] | 506 | |
Simon Glass | 0628ab8 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 507 | bytes = size * length; |
| 508 | buf = map_sysmem(addr, bytes); |
| 509 | |
wdenk | 56523f1 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 510 | /* We want to optimize the loops to run as fast as possible. |
| 511 | * If we have only one object, just run infinite loops. |
| 512 | */ |
| 513 | if (length == 1) { |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 514 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 515 | if (size == 8) { |
| 516 | llp = (u64 *)buf; |
| 517 | for (;;) |
| 518 | *llp = data; |
| 519 | } |
| 520 | #endif |
wdenk | 56523f1 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 521 | if (size == 4) { |
York Sun | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 522 | longp = (u32 *)buf; |
wdenk | 56523f1 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 523 | for (;;) |
| 524 | *longp = data; |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 525 | } |
wdenk | 56523f1 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 526 | if (size == 2) { |
York Sun | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 527 | shortp = (u16 *)buf; |
wdenk | 56523f1 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 528 | for (;;) |
| 529 | *shortp = data; |
| 530 | } |
York Sun | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 531 | cp = (u8 *)buf; |
wdenk | 56523f1 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 532 | for (;;) |
| 533 | *cp = data; |
| 534 | } |
| 535 | |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 536 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 537 | if (size == 8) { |
| 538 | for (;;) { |
| 539 | llp = (u64 *)buf; |
| 540 | i = length; |
| 541 | while (i-- > 0) |
| 542 | *llp++ = data; |
| 543 | } |
| 544 | } |
| 545 | #endif |
wdenk | 56523f1 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 546 | if (size == 4) { |
| 547 | for (;;) { |
York Sun | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 548 | longp = (u32 *)buf; |
wdenk | 56523f1 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 549 | i = length; |
| 550 | while (i-- > 0) |
| 551 | *longp++ = data; |
| 552 | } |
| 553 | } |
| 554 | if (size == 2) { |
| 555 | for (;;) { |
York Sun | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 556 | shortp = (u16 *)buf; |
wdenk | 56523f1 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 557 | i = length; |
| 558 | while (i-- > 0) |
| 559 | *shortp++ = data; |
| 560 | } |
| 561 | } |
| 562 | for (;;) { |
York Sun | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 563 | cp = (u8 *)buf; |
wdenk | 56523f1 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 564 | i = length; |
| 565 | while (i-- > 0) |
| 566 | *cp++ = data; |
| 567 | } |
| 568 | } |
| 569 | #endif /* CONFIG_LOOPW */ |
| 570 | |
Tom Rini | 68149e9 | 2013-03-12 10:07:19 -0400 | [diff] [blame] | 571 | #ifdef CONFIG_CMD_MEMTEST |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 572 | static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr, |
| 573 | vu_long *dummy) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 574 | { |
Simon Glass | c9638f5 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 575 | vu_long *addr; |
Simon Glass | c9638f5 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 576 | ulong errs = 0; |
| 577 | ulong val, readback; |
| 578 | int j; |
Simon Glass | c9638f5 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 579 | vu_long offset; |
| 580 | vu_long test_offset; |
| 581 | vu_long pattern; |
| 582 | vu_long temp; |
| 583 | vu_long anti_pattern; |
| 584 | vu_long num_words; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 585 | static const ulong bitpattern[] = { |
| 586 | 0x00000001, /* single bit */ |
| 587 | 0x00000003, /* two adjacent bits */ |
| 588 | 0x00000007, /* three adjacent bits */ |
| 589 | 0x0000000F, /* four adjacent bits */ |
| 590 | 0x00000005, /* two non-adjacent bits */ |
| 591 | 0x00000015, /* three non-adjacent bits */ |
| 592 | 0x00000055, /* four non-adjacent bits */ |
| 593 | 0xaaaaaaaa, /* alternating 1/0 */ |
| 594 | }; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 595 | |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 596 | num_words = (end_addr - start_addr) / sizeof(vu_long); |
Simon Glass | 8c86bbe | 2013-02-24 17:33:20 +0000 | [diff] [blame] | 597 | |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 598 | /* |
| 599 | * Data line test: write a pattern to the first |
| 600 | * location, write the 1's complement to a 'parking' |
| 601 | * address (changes the state of the data bus so a |
| 602 | * floating bus doesn't give a false OK), and then |
| 603 | * read the value back. Note that we read it back |
| 604 | * into a variable because the next time we read it, |
| 605 | * it might be right (been there, tough to explain to |
| 606 | * the quality guys why it prints a failure when the |
| 607 | * "is" and "should be" are obviously the same in the |
| 608 | * error message). |
| 609 | * |
| 610 | * Rather than exhaustively testing, we test some |
| 611 | * patterns by shifting '1' bits through a field of |
| 612 | * '0's and '0' bits through a field of '1's (i.e. |
| 613 | * pattern and ~pattern). |
| 614 | */ |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 615 | addr = buf; |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 616 | for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) { |
| 617 | val = bitpattern[j]; |
| 618 | for (; val != 0; val <<= 1) { |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 619 | *addr = val; |
Simon Glass | c9638f5 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 620 | *dummy = ~val; /* clear the test data off the bus */ |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 621 | readback = *addr; |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 622 | if (readback != val) { |
Simon Glass | c9638f5 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 623 | printf("FAILURE (data line): " |
| 624 | "expected %08lx, actual %08lx\n", |
| 625 | val, readback); |
| 626 | errs++; |
Simon Glass | c44d438 | 2013-02-24 17:33:19 +0000 | [diff] [blame] | 627 | if (ctrlc()) |
Simon Glass | 51209b1 | 2013-02-24 17:33:17 +0000 | [diff] [blame] | 628 | return -1; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 629 | } |
| 630 | *addr = ~val; |
| 631 | *dummy = val; |
| 632 | readback = *addr; |
Simon Glass | c9638f5 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 633 | if (readback != ~val) { |
| 634 | printf("FAILURE (data line): " |
| 635 | "Is %08lx, should be %08lx\n", |
| 636 | readback, ~val); |
| 637 | errs++; |
Simon Glass | c44d438 | 2013-02-24 17:33:19 +0000 | [diff] [blame] | 638 | if (ctrlc()) |
Simon Glass | 51209b1 | 2013-02-24 17:33:17 +0000 | [diff] [blame] | 639 | return -1; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 640 | } |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 641 | } |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 642 | } |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 643 | |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 644 | /* |
| 645 | * Based on code whose Original Author and Copyright |
| 646 | * information follows: Copyright (c) 1998 by Michael |
| 647 | * Barr. This software is placed into the public |
| 648 | * domain and may be used for any purpose. However, |
| 649 | * this notice must not be changed or removed and no |
| 650 | * warranty is either expressed or implied by its |
| 651 | * publication or distribution. |
| 652 | */ |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 653 | |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 654 | /* |
| 655 | * Address line test |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 656 | |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 657 | * Description: Test the address bus wiring in a |
| 658 | * memory region by performing a walking |
| 659 | * 1's test on the relevant bits of the |
| 660 | * address and checking for aliasing. |
| 661 | * This test will find single-bit |
| 662 | * address failures such as stuck-high, |
| 663 | * stuck-low, and shorted pins. The base |
| 664 | * address and size of the region are |
| 665 | * selected by the caller. |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 666 | |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 667 | * Notes: For best results, the selected base |
| 668 | * address should have enough LSB 0's to |
| 669 | * guarantee single address bit changes. |
| 670 | * For example, to test a 64-Kbyte |
| 671 | * region, select a base address on a |
| 672 | * 64-Kbyte boundary. Also, select the |
| 673 | * region size as a power-of-two if at |
| 674 | * all possible. |
| 675 | * |
| 676 | * Returns: 0 if the test succeeds, 1 if the test fails. |
| 677 | */ |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 678 | pattern = (vu_long) 0xaaaaaaaa; |
| 679 | anti_pattern = (vu_long) 0x55555555; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 680 | |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 681 | debug("%s:%d: length = 0x%.8lx\n", __func__, __LINE__, num_words); |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 682 | /* |
| 683 | * Write the default pattern at each of the |
| 684 | * power-of-two offsets. |
| 685 | */ |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 686 | for (offset = 1; offset < num_words; offset <<= 1) |
| 687 | addr[offset] = pattern; |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 688 | |
| 689 | /* |
| 690 | * Check for address bits stuck high. |
| 691 | */ |
| 692 | test_offset = 0; |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 693 | addr[test_offset] = anti_pattern; |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 694 | |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 695 | for (offset = 1; offset < num_words; offset <<= 1) { |
| 696 | temp = addr[offset]; |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 697 | if (temp != pattern) { |
Simon Glass | c9638f5 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 698 | printf("\nFAILURE: Address bit stuck high @ 0x%.8lx:" |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 699 | " expected 0x%.8lx, actual 0x%.8lx\n", |
David Feng | 102c051 | 2014-02-12 16:10:08 +0800 | [diff] [blame] | 700 | start_addr + offset*sizeof(vu_long), |
| 701 | pattern, temp); |
Paul Gortmaker | 87b22b7 | 2009-10-02 18:18:33 -0400 | [diff] [blame] | 702 | errs++; |
Simon Glass | c44d438 | 2013-02-24 17:33:19 +0000 | [diff] [blame] | 703 | if (ctrlc()) |
Simon Glass | 51209b1 | 2013-02-24 17:33:17 +0000 | [diff] [blame] | 704 | return -1; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 705 | } |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 706 | } |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 707 | addr[test_offset] = pattern; |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 708 | WATCHDOG_RESET(); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 709 | |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 710 | /* |
| 711 | * Check for addr bits stuck low or shorted. |
| 712 | */ |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 713 | for (test_offset = 1; test_offset < num_words; test_offset <<= 1) { |
| 714 | addr[test_offset] = anti_pattern; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 715 | |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 716 | for (offset = 1; offset < num_words; offset <<= 1) { |
| 717 | temp = addr[offset]; |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 718 | if ((temp != pattern) && (offset != test_offset)) { |
| 719 | printf("\nFAILURE: Address bit stuck low or" |
| 720 | " shorted @ 0x%.8lx: expected 0x%.8lx," |
| 721 | " actual 0x%.8lx\n", |
David Feng | 102c051 | 2014-02-12 16:10:08 +0800 | [diff] [blame] | 722 | start_addr + offset*sizeof(vu_long), |
| 723 | pattern, temp); |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 724 | errs++; |
Simon Glass | c44d438 | 2013-02-24 17:33:19 +0000 | [diff] [blame] | 725 | if (ctrlc()) |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 726 | return -1; |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 727 | } |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 728 | } |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 729 | addr[test_offset] = pattern; |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 730 | } |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 731 | |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 732 | /* |
| 733 | * Description: Test the integrity of a physical |
| 734 | * memory device by performing an |
| 735 | * increment/decrement test over the |
| 736 | * entire region. In the process every |
| 737 | * storage bit in the device is tested |
| 738 | * as a zero and a one. The base address |
| 739 | * and the size of the region are |
| 740 | * selected by the caller. |
| 741 | * |
| 742 | * Returns: 0 if the test succeeds, 1 if the test fails. |
| 743 | */ |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 744 | num_words++; |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 745 | |
| 746 | /* |
| 747 | * Fill memory with a known pattern. |
| 748 | */ |
| 749 | for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) { |
| 750 | WATCHDOG_RESET(); |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 751 | addr[offset] = pattern; |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | /* |
| 755 | * Check each location and invert it for the second pass. |
| 756 | */ |
| 757 | for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) { |
| 758 | WATCHDOG_RESET(); |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 759 | temp = addr[offset]; |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 760 | if (temp != pattern) { |
Simon Glass | c9638f5 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 761 | printf("\nFAILURE (read/write) @ 0x%.8lx:" |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 762 | " expected 0x%.8lx, actual 0x%.8lx)\n", |
David Feng | 102c051 | 2014-02-12 16:10:08 +0800 | [diff] [blame] | 763 | start_addr + offset*sizeof(vu_long), |
| 764 | pattern, temp); |
Paul Gortmaker | 87b22b7 | 2009-10-02 18:18:33 -0400 | [diff] [blame] | 765 | errs++; |
Simon Glass | c44d438 | 2013-02-24 17:33:19 +0000 | [diff] [blame] | 766 | if (ctrlc()) |
Simon Glass | 51209b1 | 2013-02-24 17:33:17 +0000 | [diff] [blame] | 767 | return -1; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 768 | } |
| 769 | |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 770 | anti_pattern = ~pattern; |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 771 | addr[offset] = anti_pattern; |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | /* |
| 775 | * Check each location for the inverted pattern and zero it. |
| 776 | */ |
| 777 | for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) { |
| 778 | WATCHDOG_RESET(); |
| 779 | anti_pattern = ~pattern; |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 780 | temp = addr[offset]; |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 781 | if (temp != anti_pattern) { |
Simon Glass | c9638f5 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 782 | printf("\nFAILURE (read/write): @ 0x%.8lx:" |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 783 | " expected 0x%.8lx, actual 0x%.8lx)\n", |
David Feng | 102c051 | 2014-02-12 16:10:08 +0800 | [diff] [blame] | 784 | start_addr + offset*sizeof(vu_long), |
| 785 | anti_pattern, temp); |
Paul Gortmaker | 87b22b7 | 2009-10-02 18:18:33 -0400 | [diff] [blame] | 786 | errs++; |
Simon Glass | c44d438 | 2013-02-24 17:33:19 +0000 | [diff] [blame] | 787 | if (ctrlc()) |
Simon Glass | 51209b1 | 2013-02-24 17:33:17 +0000 | [diff] [blame] | 788 | return -1; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 789 | } |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 790 | addr[offset] = 0; |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 791 | } |
Simon Glass | 51209b1 | 2013-02-24 17:33:17 +0000 | [diff] [blame] | 792 | |
Rasmus Villemoes | fea6730 | 2016-01-07 11:36:04 +0100 | [diff] [blame] | 793 | return errs; |
Simon Glass | c9638f5 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 794 | } |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 795 | |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 796 | static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr, |
| 797 | vu_long pattern, int iteration) |
Simon Glass | c9638f5 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 798 | { |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 799 | vu_long *end; |
Simon Glass | c9638f5 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 800 | vu_long *addr; |
Simon Glass | c9638f5 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 801 | ulong errs = 0; |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 802 | ulong incr, length; |
Simon Glass | c9638f5 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 803 | ulong val, readback; |
| 804 | |
Simon Glass | 51209b1 | 2013-02-24 17:33:17 +0000 | [diff] [blame] | 805 | /* Alternate the pattern */ |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 806 | incr = 1; |
Simon Glass | 51209b1 | 2013-02-24 17:33:17 +0000 | [diff] [blame] | 807 | if (iteration & 1) { |
| 808 | incr = -incr; |
| 809 | /* |
| 810 | * Flip the pattern each time to make lots of zeros and |
| 811 | * then, the next time, lots of ones. We decrement |
| 812 | * the "negative" patterns and increment the "positive" |
| 813 | * patterns to preserve this feature. |
| 814 | */ |
| 815 | if (pattern & 0x80000000) |
| 816 | pattern = -pattern; /* complement & increment */ |
| 817 | else |
| 818 | pattern = ~pattern; |
| 819 | } |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 820 | length = (end_addr - start_addr) / sizeof(ulong); |
| 821 | end = buf + length; |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 822 | printf("\rPattern %08lX Writing..." |
| 823 | "%12s" |
| 824 | "\b\b\b\b\b\b\b\b\b\b", |
| 825 | pattern, ""); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 826 | |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 827 | for (addr = buf, val = pattern; addr < end; addr++) { |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 828 | WATCHDOG_RESET(); |
| 829 | *addr = val; |
| 830 | val += incr; |
| 831 | } |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 832 | |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 833 | puts("Reading..."); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 834 | |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 835 | for (addr = buf, val = pattern; addr < end; addr++) { |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 836 | WATCHDOG_RESET(); |
| 837 | readback = *addr; |
| 838 | if (readback != val) { |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 839 | ulong offset = addr - buf; |
| 840 | |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 841 | printf("\nMem error @ 0x%08X: " |
| 842 | "found %08lX, expected %08lX\n", |
David Feng | 102c051 | 2014-02-12 16:10:08 +0800 | [diff] [blame] | 843 | (uint)(uintptr_t)(start_addr + offset*sizeof(vu_long)), |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 844 | readback, val); |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 845 | errs++; |
Simon Glass | c44d438 | 2013-02-24 17:33:19 +0000 | [diff] [blame] | 846 | if (ctrlc()) |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 847 | return -1; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 848 | } |
Simon Glass | 7ecbd4d | 2013-02-24 17:33:18 +0000 | [diff] [blame] | 849 | val += incr; |
| 850 | } |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 851 | |
Rasmus Villemoes | fea6730 | 2016-01-07 11:36:04 +0100 | [diff] [blame] | 852 | return errs; |
Simon Glass | c9638f5 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | /* |
| 856 | * Perform a memory test. A more complete alternative test can be |
| 857 | * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until |
| 858 | * interrupted by ctrl-c or by a failure of one of the sub-tests. |
| 859 | */ |
| 860 | static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, |
| 861 | char * const argv[]) |
| 862 | { |
Simon Glass | 8c86bbe | 2013-02-24 17:33:20 +0000 | [diff] [blame] | 863 | ulong start, end; |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 864 | vu_long *buf, *dummy; |
Tom Rini | adcc570 | 2015-04-07 09:38:54 -0400 | [diff] [blame] | 865 | ulong iteration_limit = 0; |
Simon Glass | c9638f5 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 866 | int ret; |
Simon Glass | 51209b1 | 2013-02-24 17:33:17 +0000 | [diff] [blame] | 867 | ulong errs = 0; /* number of errors, or -1 if interrupted */ |
Pavel Machek | e37f1eb | 2015-04-01 13:50:41 +0200 | [diff] [blame] | 868 | ulong pattern = 0; |
Simon Glass | 51209b1 | 2013-02-24 17:33:17 +0000 | [diff] [blame] | 869 | int iteration; |
Simon Glass | c9638f5 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 870 | #if defined(CONFIG_SYS_ALT_MEMTEST) |
| 871 | const int alt_test = 1; |
| 872 | #else |
| 873 | const int alt_test = 0; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 874 | #endif |
Simon Glass | c9638f5 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 875 | |
Pavel Machek | e37f1eb | 2015-04-01 13:50:41 +0200 | [diff] [blame] | 876 | start = CONFIG_SYS_MEMTEST_START; |
| 877 | end = CONFIG_SYS_MEMTEST_END; |
| 878 | |
Simon Glass | c9638f5 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 879 | if (argc > 1) |
Pavel Machek | e37f1eb | 2015-04-01 13:50:41 +0200 | [diff] [blame] | 880 | if (strict_strtoul(argv[1], 16, &start) < 0) |
| 881 | return CMD_RET_USAGE; |
Simon Glass | c9638f5 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 882 | |
| 883 | if (argc > 2) |
Pavel Machek | e37f1eb | 2015-04-01 13:50:41 +0200 | [diff] [blame] | 884 | if (strict_strtoul(argv[2], 16, &end) < 0) |
| 885 | return CMD_RET_USAGE; |
Simon Glass | c9638f5 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 886 | |
| 887 | if (argc > 3) |
Pavel Machek | e37f1eb | 2015-04-01 13:50:41 +0200 | [diff] [blame] | 888 | if (strict_strtoul(argv[3], 16, &pattern) < 0) |
| 889 | return CMD_RET_USAGE; |
Simon Glass | c9638f5 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 890 | |
| 891 | if (argc > 4) |
Pavel Machek | e37f1eb | 2015-04-01 13:50:41 +0200 | [diff] [blame] | 892 | if (strict_strtoul(argv[4], 16, &iteration_limit) < 0) |
| 893 | return CMD_RET_USAGE; |
| 894 | |
| 895 | if (end < start) { |
| 896 | printf("Refusing to do empty test\n"); |
| 897 | return -1; |
| 898 | } |
Simon Glass | c9638f5 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 899 | |
Michal Simek | dfe461d | 2016-02-24 08:36:02 +0100 | [diff] [blame] | 900 | printf("Testing %08lx ... %08lx:\n", start, end); |
Simon Glass | 8c86bbe | 2013-02-24 17:33:20 +0000 | [diff] [blame] | 901 | debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__, |
| 902 | start, end); |
Simon Glass | 51209b1 | 2013-02-24 17:33:17 +0000 | [diff] [blame] | 903 | |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 904 | buf = map_sysmem(start, end - start); |
| 905 | dummy = map_sysmem(CONFIG_SYS_MEMTEST_SCRATCH, sizeof(vu_long)); |
Simon Glass | 51209b1 | 2013-02-24 17:33:17 +0000 | [diff] [blame] | 906 | for (iteration = 0; |
| 907 | !iteration_limit || iteration < iteration_limit; |
| 908 | iteration++) { |
| 909 | if (ctrlc()) { |
Simon Glass | 51209b1 | 2013-02-24 17:33:17 +0000 | [diff] [blame] | 910 | errs = -1UL; |
| 911 | break; |
| 912 | } |
| 913 | |
| 914 | printf("Iteration: %6d\r", iteration + 1); |
| 915 | debug("\n"); |
Simon Glass | 5512d5b | 2013-02-28 17:47:14 +0000 | [diff] [blame] | 916 | if (alt_test) { |
| 917 | errs = mem_test_alt(buf, start, end, dummy); |
| 918 | } else { |
| 919 | errs = mem_test_quick(buf, start, end, pattern, |
| 920 | iteration); |
| 921 | } |
| 922 | if (errs == -1UL) |
| 923 | break; |
| 924 | } |
| 925 | |
| 926 | /* |
| 927 | * Work-around for eldk-4.2 which gives this warning if we try to |
| 928 | * case in the unmap_sysmem() call: |
| 929 | * warning: initialization discards qualifiers from pointer target type |
| 930 | */ |
| 931 | { |
| 932 | void *vbuf = (void *)buf; |
| 933 | void *vdummy = (void *)dummy; |
| 934 | |
| 935 | unmap_sysmem(vbuf); |
| 936 | unmap_sysmem(vdummy); |
Simon Glass | 51209b1 | 2013-02-24 17:33:17 +0000 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | if (errs == -1UL) { |
Simon Glass | c44d438 | 2013-02-24 17:33:19 +0000 | [diff] [blame] | 940 | /* Memory test was aborted - write a newline to finish off */ |
| 941 | putc('\n'); |
Simon Glass | 51209b1 | 2013-02-24 17:33:17 +0000 | [diff] [blame] | 942 | ret = 1; |
| 943 | } else { |
| 944 | printf("Tested %d iteration(s) with %lu errors.\n", |
| 945 | iteration, errs); |
| 946 | ret = errs != 0; |
| 947 | } |
Simon Glass | c9638f5 | 2013-02-24 17:33:16 +0000 | [diff] [blame] | 948 | |
Pavel Machek | e37f1eb | 2015-04-01 13:50:41 +0200 | [diff] [blame] | 949 | return ret; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 950 | } |
Wolfgang Denk | a268170 | 2013-03-08 10:51:32 +0000 | [diff] [blame] | 951 | #endif /* CONFIG_CMD_MEMTEST */ |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 952 | |
| 953 | /* Modify memory. |
| 954 | * |
| 955 | * Syntax: |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 956 | * mm{.b, .w, .l, .q} {addr} |
| 957 | * nm{.b, .w, .l, .q} {addr} |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 958 | */ |
| 959 | static int |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 960 | mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[]) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 961 | { |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 962 | ulong addr; |
| 963 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 964 | u64 i; |
| 965 | #else |
| 966 | ulong i; |
| 967 | #endif |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 968 | int nbytes, size; |
Simon Glass | 0628ab8 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 969 | void *ptr = NULL; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 970 | |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 971 | if (argc != 2) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 972 | return CMD_RET_USAGE; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 973 | |
Simon Glass | b26440f | 2014-04-10 20:01:31 -0600 | [diff] [blame] | 974 | bootretry_reset_cmd_timeout(); /* got a good command to get here */ |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 975 | /* We use the last specified parameters, unless new ones are |
| 976 | * entered. |
| 977 | */ |
| 978 | addr = mm_last_addr; |
| 979 | size = mm_last_size; |
| 980 | |
| 981 | if ((flag & CMD_FLAG_REPEAT) == 0) { |
| 982 | /* New command specified. Check for a size specification. |
| 983 | * Defaults to long if no or incorrect specification. |
| 984 | */ |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 985 | if ((size = cmd_get_data_size(argv[0], 4)) < 0) |
| 986 | return 1; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 987 | |
| 988 | /* Address is specified since argc > 1 |
| 989 | */ |
| 990 | addr = simple_strtoul(argv[1], NULL, 16); |
| 991 | addr += base_address; |
| 992 | } |
| 993 | |
| 994 | /* Print the address, followed by value. Then accept input for |
| 995 | * the next value. A non-converted value exits. |
| 996 | */ |
| 997 | do { |
Simon Glass | 0628ab8 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 998 | ptr = map_sysmem(addr, size); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 999 | printf("%08lx:", addr); |
| 1000 | if (size == 4) |
York Sun | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 1001 | printf(" %08x", *((u32 *)ptr)); |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1002 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 1003 | else if (size == 8) |
Simon Glass | e48f374 | 2014-11-11 12:47:07 -0700 | [diff] [blame] | 1004 | printf(" %016" PRIx64, *((u64 *)ptr)); |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1005 | #endif |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1006 | else if (size == 2) |
York Sun | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 1007 | printf(" %04x", *((u16 *)ptr)); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1008 | else |
York Sun | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 1009 | printf(" %02x", *((u8 *)ptr)); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1010 | |
Simon Glass | e1bf824 | 2014-04-10 20:01:27 -0600 | [diff] [blame] | 1011 | nbytes = cli_readline(" ? "); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1012 | if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) { |
| 1013 | /* <CR> pressed as only input, don't modify current |
| 1014 | * location and move to next. "-" pressed will go back. |
| 1015 | */ |
| 1016 | if (incrflag) |
| 1017 | addr += nbytes ? -size : size; |
| 1018 | nbytes = 1; |
Simon Glass | b26440f | 2014-04-10 20:01:31 -0600 | [diff] [blame] | 1019 | /* good enough to not time out */ |
| 1020 | bootretry_reset_cmd_timeout(); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1021 | } |
| 1022 | #ifdef CONFIG_BOOT_RETRY_TIME |
| 1023 | else if (nbytes == -2) { |
| 1024 | break; /* timed out, exit the command */ |
| 1025 | } |
| 1026 | #endif |
| 1027 | else { |
| 1028 | char *endp; |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1029 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 1030 | i = simple_strtoull(console_buffer, &endp, 16); |
| 1031 | #else |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1032 | i = simple_strtoul(console_buffer, &endp, 16); |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1033 | #endif |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1034 | nbytes = endp - console_buffer; |
| 1035 | if (nbytes) { |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1036 | /* good enough to not time out |
| 1037 | */ |
Simon Glass | b26440f | 2014-04-10 20:01:31 -0600 | [diff] [blame] | 1038 | bootretry_reset_cmd_timeout(); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1039 | if (size == 4) |
York Sun | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 1040 | *((u32 *)ptr) = i; |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1041 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 1042 | else if (size == 8) |
| 1043 | *((u64 *)ptr) = i; |
| 1044 | #endif |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1045 | else if (size == 2) |
York Sun | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 1046 | *((u16 *)ptr) = i; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1047 | else |
York Sun | 76698b4 | 2014-02-12 15:55:35 -0800 | [diff] [blame] | 1048 | *((u8 *)ptr) = i; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1049 | if (incrflag) |
| 1050 | addr += size; |
| 1051 | } |
| 1052 | } |
| 1053 | } while (nbytes); |
Simon Glass | 0628ab8 | 2013-02-24 17:33:15 +0000 | [diff] [blame] | 1054 | if (ptr) |
| 1055 | unmap_sysmem(ptr); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1056 | |
| 1057 | mm_last_addr = addr; |
| 1058 | mm_last_size = size; |
| 1059 | return 0; |
| 1060 | } |
| 1061 | |
Mike Frysinger | 710b993 | 2010-12-21 14:19:51 -0500 | [diff] [blame] | 1062 | #ifdef CONFIG_CMD_CRC32 |
| 1063 | |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 1064 | static int do_mem_crc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1065 | { |
Simon Glass | d20a40d | 2013-02-24 20:30:22 +0000 | [diff] [blame] | 1066 | int flags = 0; |
| 1067 | int ac; |
| 1068 | char * const *av; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1069 | |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 1070 | if (argc < 3) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 1071 | return CMD_RET_USAGE; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1072 | |
wdenk | c26e454 | 2004-04-18 10:13:26 +0000 | [diff] [blame] | 1073 | av = argv + 1; |
| 1074 | ac = argc - 1; |
Daniel Thompson | 221a949 | 2017-05-19 17:26:58 +0100 | [diff] [blame] | 1075 | #ifdef CONFIG_CRC32_VERIFY |
wdenk | c26e454 | 2004-04-18 10:13:26 +0000 | [diff] [blame] | 1076 | if (strcmp(*av, "-v") == 0) { |
Joe Hershberger | a69bdba | 2015-05-05 12:23:53 -0500 | [diff] [blame] | 1077 | flags |= HASH_FLAG_VERIFY | HASH_FLAG_ENV; |
wdenk | c26e454 | 2004-04-18 10:13:26 +0000 | [diff] [blame] | 1078 | av++; |
| 1079 | ac--; |
wdenk | c26e454 | 2004-04-18 10:13:26 +0000 | [diff] [blame] | 1080 | } |
Simon Glass | d20a40d | 2013-02-24 20:30:22 +0000 | [diff] [blame] | 1081 | #endif |
wdenk | c26e454 | 2004-04-18 10:13:26 +0000 | [diff] [blame] | 1082 | |
Simon Glass | d20a40d | 2013-02-24 20:30:22 +0000 | [diff] [blame] | 1083 | return hash_command("crc32", flags, cmdtp, flag, ac, av); |
wdenk | c26e454 | 2004-04-18 10:13:26 +0000 | [diff] [blame] | 1084 | } |
wdenk | c26e454 | 2004-04-18 10:13:26 +0000 | [diff] [blame] | 1085 | |
Mike Frysinger | 710b993 | 2010-12-21 14:19:51 -0500 | [diff] [blame] | 1086 | #endif |
| 1087 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1088 | /**************************************************/ |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1089 | U_BOOT_CMD( |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1090 | md, 3, 1, do_mem_md, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1091 | "memory display", |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1092 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 1093 | "[.b, .w, .l, .q] address [# of objects]" |
| 1094 | #else |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1095 | "[.b, .w, .l] address [# of objects]" |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1096 | #endif |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1097 | ); |
| 1098 | |
| 1099 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1100 | U_BOOT_CMD( |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1101 | mm, 2, 1, do_mem_mm, |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1102 | "memory modify (auto-incrementing address)", |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1103 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 1104 | "[.b, .w, .l, .q] address" |
| 1105 | #else |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1106 | "[.b, .w, .l] address" |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1107 | #endif |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1108 | ); |
| 1109 | |
| 1110 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1111 | U_BOOT_CMD( |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1112 | nm, 2, 1, do_mem_nm, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1113 | "memory modify (constant address)", |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1114 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 1115 | "[.b, .w, .l, .q] address" |
| 1116 | #else |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1117 | "[.b, .w, .l] address" |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1118 | #endif |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1119 | ); |
| 1120 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1121 | U_BOOT_CMD( |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1122 | mw, 4, 1, do_mem_mw, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1123 | "memory write (fill)", |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1124 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 1125 | "[.b, .w, .l, .q] address value [count]" |
| 1126 | #else |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1127 | "[.b, .w, .l] address value [count]" |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1128 | #endif |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1129 | ); |
| 1130 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1131 | U_BOOT_CMD( |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1132 | cp, 4, 1, do_mem_cp, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1133 | "memory copy", |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1134 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 1135 | "[.b, .w, .l, .q] source target count" |
| 1136 | #else |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1137 | "[.b, .w, .l] source target count" |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1138 | #endif |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1139 | ); |
| 1140 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1141 | U_BOOT_CMD( |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1142 | cmp, 4, 1, do_mem_cmp, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1143 | "memory compare", |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1144 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 1145 | "[.b, .w, .l, .q] addr1 addr2 count" |
| 1146 | #else |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1147 | "[.b, .w, .l] addr1 addr2 count" |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1148 | #endif |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1149 | ); |
| 1150 | |
Mike Frysinger | 710b993 | 2010-12-21 14:19:51 -0500 | [diff] [blame] | 1151 | #ifdef CONFIG_CMD_CRC32 |
| 1152 | |
Daniel Thompson | 221a949 | 2017-05-19 17:26:58 +0100 | [diff] [blame] | 1153 | #ifndef CONFIG_CRC32_VERIFY |
wdenk | c26e454 | 2004-04-18 10:13:26 +0000 | [diff] [blame] | 1154 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1155 | U_BOOT_CMD( |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1156 | crc32, 4, 1, do_mem_crc, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1157 | "checksum calculation", |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1158 | "address count [addr]\n - compute CRC32 checksum [save at addr]" |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1159 | ); |
| 1160 | |
Daniel Thompson | 221a949 | 2017-05-19 17:26:58 +0100 | [diff] [blame] | 1161 | #else /* CONFIG_CRC32_VERIFY */ |
wdenk | c26e454 | 2004-04-18 10:13:26 +0000 | [diff] [blame] | 1162 | |
| 1163 | U_BOOT_CMD( |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1164 | crc32, 5, 1, do_mem_crc, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1165 | "checksum calculation", |
wdenk | c26e454 | 2004-04-18 10:13:26 +0000 | [diff] [blame] | 1166 | "address count [addr]\n - compute CRC32 checksum [save at addr]\n" |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1167 | "-v address count crc\n - verify crc of memory area" |
wdenk | c26e454 | 2004-04-18 10:13:26 +0000 | [diff] [blame] | 1168 | ); |
| 1169 | |
Daniel Thompson | 221a949 | 2017-05-19 17:26:58 +0100 | [diff] [blame] | 1170 | #endif /* CONFIG_CRC32_VERIFY */ |
wdenk | c26e454 | 2004-04-18 10:13:26 +0000 | [diff] [blame] | 1171 | |
Mike Frysinger | 710b993 | 2010-12-21 14:19:51 -0500 | [diff] [blame] | 1172 | #endif |
| 1173 | |
Simon Glass | 15a33e4 | 2012-11-30 13:01:20 +0000 | [diff] [blame] | 1174 | #ifdef CONFIG_CMD_MEMINFO |
Andrew Bradford | ea11b40 | 2015-05-22 08:30:14 -0400 | [diff] [blame] | 1175 | __weak void board_show_dram(phys_size_t size) |
Simon Glass | 15a33e4 | 2012-11-30 13:01:20 +0000 | [diff] [blame] | 1176 | { |
| 1177 | puts("DRAM: "); |
| 1178 | print_size(size, "\n"); |
| 1179 | } |
| 1180 | |
| 1181 | static int do_mem_info(cmd_tbl_t *cmdtp, int flag, int argc, |
| 1182 | char * const argv[]) |
| 1183 | { |
| 1184 | board_show_dram(gd->ram_size); |
| 1185 | |
| 1186 | return 0; |
| 1187 | } |
| 1188 | #endif |
| 1189 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1190 | U_BOOT_CMD( |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1191 | base, 2, 1, do_mem_base, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1192 | "print or set address offset", |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1193 | "\n - print address offset for memory commands\n" |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1194 | "base off\n - set address offset for memory commands to 'off'" |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1195 | ); |
| 1196 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1197 | U_BOOT_CMD( |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1198 | loop, 3, 1, do_mem_loop, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1199 | "infinite loop on address range", |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1200 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 1201 | "[.b, .w, .l, .q] address number_of_objects" |
| 1202 | #else |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1203 | "[.b, .w, .l] address number_of_objects" |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1204 | #endif |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1205 | ); |
| 1206 | |
wdenk | 56523f1 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 1207 | #ifdef CONFIG_LOOPW |
| 1208 | U_BOOT_CMD( |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1209 | loopw, 4, 1, do_mem_loopw, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1210 | "infinite write loop on address range", |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1211 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 1212 | "[.b, .w, .l, .q] address number_of_objects data_to_write" |
| 1213 | #else |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1214 | "[.b, .w, .l] address number_of_objects data_to_write" |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1215 | #endif |
wdenk | 56523f1 | 2004-07-11 17:40:54 +0000 | [diff] [blame] | 1216 | ); |
| 1217 | #endif /* CONFIG_LOOPW */ |
| 1218 | |
Wolfgang Denk | a268170 | 2013-03-08 10:51:32 +0000 | [diff] [blame] | 1219 | #ifdef CONFIG_CMD_MEMTEST |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1220 | U_BOOT_CMD( |
Dirk Eibach | b6fc6fd | 2008-12-16 14:51:56 +0100 | [diff] [blame] | 1221 | mtest, 5, 1, do_mem_mtest, |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1222 | "simple RAM read/write test", |
| 1223 | "[start [end [pattern [iterations]]]]" |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1224 | ); |
Wolfgang Denk | a268170 | 2013-03-08 10:51:32 +0000 | [diff] [blame] | 1225 | #endif /* CONFIG_CMD_MEMTEST */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1226 | |
stroese | 4aaf29b | 2004-12-16 17:42:39 +0000 | [diff] [blame] | 1227 | #ifdef CONFIG_MX_CYCLIC |
| 1228 | U_BOOT_CMD( |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1229 | mdc, 4, 1, do_mem_mdc, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1230 | "memory display cyclic", |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1231 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 1232 | "[.b, .w, .l, .q] address count delay(ms)" |
| 1233 | #else |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1234 | "[.b, .w, .l] address count delay(ms)" |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1235 | #endif |
stroese | 4aaf29b | 2004-12-16 17:42:39 +0000 | [diff] [blame] | 1236 | ); |
| 1237 | |
| 1238 | U_BOOT_CMD( |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1239 | mwc, 4, 1, do_mem_mwc, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1240 | "memory write cyclic", |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1241 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
| 1242 | "[.b, .w, .l, .q] address value delay(ms)" |
| 1243 | #else |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1244 | "[.b, .w, .l] address value delay(ms)" |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 1245 | #endif |
stroese | 4aaf29b | 2004-12-16 17:42:39 +0000 | [diff] [blame] | 1246 | ); |
| 1247 | #endif /* CONFIG_MX_CYCLIC */ |
Simon Glass | 15a33e4 | 2012-11-30 13:01:20 +0000 | [diff] [blame] | 1248 | |
| 1249 | #ifdef CONFIG_CMD_MEMINFO |
| 1250 | U_BOOT_CMD( |
| 1251 | meminfo, 3, 1, do_mem_info, |
| 1252 | "display memory information", |
| 1253 | "" |
| 1254 | ); |
| 1255 | #endif |