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