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