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