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