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