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