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