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