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> |
| 32 | #include <cmd_mem.h> |
| 33 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 34 | #if (CONFIG_COMMANDS & (CFG_CMD_MEMORY | CFG_CMD_PCI | CFG_CMD_I2C\ |
| 35 | | CMD_CMD_PORTIO)) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 36 | int cmd_get_data_size(char* arg, int default_size) |
| 37 | { |
| 38 | /* Check for a size specification .b, .w or .l. |
| 39 | */ |
| 40 | int len = strlen(arg); |
| 41 | if (len > 2 && arg[len-2] == '.') { |
| 42 | switch(arg[len-1]) { |
| 43 | case 'b': |
| 44 | return 1; |
| 45 | case 'w': |
| 46 | return 2; |
| 47 | case 'l': |
| 48 | return 4; |
| 49 | } |
| 50 | } |
| 51 | return default_size; |
| 52 | } |
| 53 | #endif |
| 54 | |
| 55 | #if (CONFIG_COMMANDS & CFG_CMD_MEMORY) |
| 56 | |
| 57 | #ifdef CMD_MEM_DEBUG |
| 58 | #define PRINTF(fmt,args...) printf (fmt ,##args) |
| 59 | #else |
| 60 | #define PRINTF(fmt,args...) |
| 61 | #endif |
| 62 | |
| 63 | static int mod_mem(cmd_tbl_t *, int, int, int, char *[]); |
| 64 | |
| 65 | /* Display values from last command. |
| 66 | * Memory modify remembered values are different from display memory. |
| 67 | */ |
| 68 | uint dp_last_addr, dp_last_size; |
| 69 | uint dp_last_length = 0x40; |
| 70 | uint mm_last_addr, mm_last_size; |
| 71 | |
| 72 | static ulong base_address = 0; |
| 73 | |
| 74 | /* Memory Display |
| 75 | * |
| 76 | * Syntax: |
| 77 | * md{.b, .w, .l} {addr} {len} |
| 78 | */ |
| 79 | #define DISP_LINE_LEN 16 |
| 80 | int do_mem_md ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 81 | { |
| 82 | ulong addr, size, length; |
| 83 | ulong i, nbytes, linebytes; |
| 84 | u_char *cp; |
| 85 | int rc = 0; |
| 86 | |
| 87 | /* We use the last specified parameters, unless new ones are |
| 88 | * entered. |
| 89 | */ |
| 90 | addr = dp_last_addr; |
| 91 | size = dp_last_size; |
| 92 | length = dp_last_length; |
| 93 | |
| 94 | if (argc < 2) { |
| 95 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 96 | return 1; |
| 97 | } |
| 98 | |
| 99 | if ((flag & CMD_FLAG_REPEAT) == 0) { |
| 100 | /* New command specified. Check for a size specification. |
| 101 | * Defaults to long if no or incorrect specification. |
| 102 | */ |
| 103 | size = cmd_get_data_size(argv[0], 4); |
| 104 | |
| 105 | /* Address is specified since argc > 1 |
| 106 | */ |
| 107 | addr = simple_strtoul(argv[1], NULL, 16); |
| 108 | addr += base_address; |
| 109 | |
| 110 | /* If another parameter, it is the length to display. |
| 111 | * Length is the number of objects, not number of bytes. |
| 112 | */ |
| 113 | if (argc > 2) |
| 114 | length = simple_strtoul(argv[2], NULL, 16); |
| 115 | } |
| 116 | |
| 117 | /* Print the lines. |
| 118 | * |
| 119 | * We buffer all read data, so we can make sure data is read only |
| 120 | * once, and all accesses are with the specified bus width. |
| 121 | */ |
| 122 | nbytes = length * size; |
| 123 | do { |
| 124 | char linebuf[DISP_LINE_LEN]; |
| 125 | uint *uip = (uint *)linebuf; |
| 126 | ushort *usp = (ushort *)linebuf; |
| 127 | u_char *ucp = (u_char *)linebuf; |
| 128 | |
| 129 | printf("%08lx:", addr); |
| 130 | linebytes = (nbytes>DISP_LINE_LEN)?DISP_LINE_LEN:nbytes; |
| 131 | for (i=0; i<linebytes; i+= size) { |
| 132 | if (size == 4) { |
| 133 | printf(" %08x", (*uip++ = *((uint *)addr))); |
| 134 | } else if (size == 2) { |
| 135 | printf(" %04x", (*usp++ = *((ushort *)addr))); |
| 136 | } else { |
| 137 | printf(" %02x", (*ucp++ = *((u_char *)addr))); |
| 138 | } |
| 139 | addr += size; |
| 140 | } |
| 141 | printf(" "); |
| 142 | cp = linebuf; |
| 143 | for (i=0; i<linebytes; i++) { |
| 144 | if ((*cp < 0x20) || (*cp > 0x7e)) |
| 145 | printf("."); |
| 146 | else |
| 147 | printf("%c", *cp); |
| 148 | cp++; |
| 149 | } |
| 150 | printf("\n"); |
| 151 | nbytes -= linebytes; |
| 152 | if (ctrlc()) { |
| 153 | rc = 1; |
| 154 | break; |
| 155 | } |
| 156 | } while (nbytes > 0); |
| 157 | |
| 158 | dp_last_addr = addr; |
| 159 | dp_last_length = length; |
| 160 | dp_last_size = size; |
| 161 | return (rc); |
| 162 | } |
| 163 | |
| 164 | int do_mem_mm ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 165 | { |
| 166 | return mod_mem (cmdtp, 1, flag, argc, argv); |
| 167 | } |
| 168 | int do_mem_nm ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 169 | { |
| 170 | return mod_mem (cmdtp, 0, flag, argc, argv); |
| 171 | } |
| 172 | |
| 173 | int do_mem_mw ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 174 | { |
| 175 | ulong addr, size, writeval, count; |
| 176 | |
| 177 | if ((argc < 3) || (argc > 4)) { |
| 178 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 179 | return 1; |
| 180 | } |
| 181 | |
| 182 | /* Check for size specification. |
| 183 | */ |
| 184 | size = cmd_get_data_size(argv[0], 4); |
| 185 | |
| 186 | /* Address is specified since argc > 1 |
| 187 | */ |
| 188 | addr = simple_strtoul(argv[1], NULL, 16); |
| 189 | addr += base_address; |
| 190 | |
| 191 | /* Get the value to write. |
| 192 | */ |
| 193 | writeval = simple_strtoul(argv[2], NULL, 16); |
| 194 | |
| 195 | /* Count ? */ |
| 196 | if (argc == 4) { |
| 197 | count = simple_strtoul(argv[3], NULL, 16); |
| 198 | } else { |
| 199 | count = 1; |
| 200 | } |
| 201 | |
| 202 | while (count-- > 0) { |
| 203 | if (size == 4) |
| 204 | *((ulong *)addr) = (ulong )writeval; |
| 205 | else if (size == 2) |
| 206 | *((ushort *)addr) = (ushort)writeval; |
| 207 | else |
| 208 | *((u_char *)addr) = (u_char)writeval; |
| 209 | addr += size; |
| 210 | } |
| 211 | return 0; |
| 212 | } |
| 213 | |
| 214 | int do_mem_cmp (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 215 | { |
| 216 | ulong size, addr1, addr2, count, ngood; |
| 217 | int rcode = 0; |
| 218 | |
| 219 | if (argc != 4) { |
| 220 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 221 | return 1; |
| 222 | } |
| 223 | |
| 224 | /* Check for size specification. |
| 225 | */ |
| 226 | size = cmd_get_data_size(argv[0], 4); |
| 227 | |
| 228 | addr1 = simple_strtoul(argv[1], NULL, 16); |
| 229 | addr1 += base_address; |
| 230 | |
| 231 | addr2 = simple_strtoul(argv[2], NULL, 16); |
| 232 | addr2 += base_address; |
| 233 | |
| 234 | count = simple_strtoul(argv[3], NULL, 16); |
| 235 | |
| 236 | ngood = 0; |
| 237 | |
| 238 | while (count-- > 0) { |
| 239 | if (size == 4) { |
| 240 | ulong word1 = *(ulong *)addr1; |
| 241 | ulong word2 = *(ulong *)addr2; |
| 242 | if (word1 != word2) { |
| 243 | printf("word at 0x%08lx (0x%08lx) " |
| 244 | "!= word at 0x%08lx (0x%08lx)\n", |
| 245 | addr1, word1, addr2, word2); |
| 246 | rcode = 1; |
| 247 | break; |
| 248 | } |
| 249 | } |
| 250 | else if (size == 2) { |
| 251 | ushort hword1 = *(ushort *)addr1; |
| 252 | ushort hword2 = *(ushort *)addr2; |
| 253 | if (hword1 != hword2) { |
| 254 | printf("halfword at 0x%08lx (0x%04x) " |
| 255 | "!= halfword at 0x%08lx (0x%04x)\n", |
| 256 | addr1, hword1, addr2, hword2); |
| 257 | rcode = 1; |
| 258 | break; |
| 259 | } |
| 260 | } |
| 261 | else { |
| 262 | u_char byte1 = *(u_char *)addr1; |
| 263 | u_char byte2 = *(u_char *)addr2; |
| 264 | if (byte1 != byte2) { |
| 265 | printf("byte at 0x%08lx (0x%02x) " |
| 266 | "!= byte at 0x%08lx (0x%02x)\n", |
| 267 | addr1, byte1, addr2, byte2); |
| 268 | rcode = 1; |
| 269 | break; |
| 270 | } |
| 271 | } |
| 272 | ngood++; |
| 273 | addr1 += size; |
| 274 | addr2 += size; |
| 275 | } |
| 276 | |
| 277 | printf("Total of %ld %s%s were the same\n", |
| 278 | ngood, size == 4 ? "word" : size == 2 ? "halfword" : "byte", |
| 279 | ngood == 1 ? "" : "s"); |
| 280 | return rcode; |
| 281 | } |
| 282 | |
| 283 | int do_mem_cp ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 284 | { |
| 285 | ulong addr, size, dest, count; |
| 286 | |
| 287 | if (argc != 4) { |
| 288 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 289 | return 1; |
| 290 | } |
| 291 | |
| 292 | /* Check for size specification. |
| 293 | */ |
| 294 | size = cmd_get_data_size(argv[0], 4); |
| 295 | |
| 296 | addr = simple_strtoul(argv[1], NULL, 16); |
| 297 | addr += base_address; |
| 298 | |
| 299 | dest = simple_strtoul(argv[2], NULL, 16); |
| 300 | dest += base_address; |
| 301 | |
| 302 | count = simple_strtoul(argv[3], NULL, 16); |
| 303 | |
| 304 | if (count == 0) { |
| 305 | puts ("Zero length ???\n"); |
| 306 | return 1; |
| 307 | } |
| 308 | |
| 309 | #ifndef CFG_NO_FLASH |
| 310 | /* check if we are copying to Flash */ |
| 311 | if (addr2info(dest) != NULL) { |
| 312 | int rc; |
| 313 | |
| 314 | printf ("Copy to Flash... "); |
| 315 | |
| 316 | rc = flash_write ((uchar *)addr, dest, count*size); |
| 317 | if (rc != 0) { |
| 318 | flash_perror (rc); |
| 319 | return (1); |
| 320 | } |
| 321 | puts ("done\n"); |
| 322 | return 0; |
| 323 | } |
| 324 | #endif |
| 325 | |
| 326 | while (count-- > 0) { |
| 327 | if (size == 4) |
| 328 | *((ulong *)dest) = *((ulong *)addr); |
| 329 | else if (size == 2) |
| 330 | *((ushort *)dest) = *((ushort *)addr); |
| 331 | else |
| 332 | *((u_char *)dest) = *((u_char *)addr); |
| 333 | addr += size; |
| 334 | dest += size; |
| 335 | } |
| 336 | return 0; |
| 337 | } |
| 338 | |
| 339 | int do_mem_base (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 340 | { |
| 341 | if (argc > 1) { |
| 342 | /* Set new base address. |
| 343 | */ |
| 344 | base_address = simple_strtoul(argv[1], NULL, 16); |
| 345 | } |
| 346 | /* Print the current base address. |
| 347 | */ |
| 348 | printf("Base Address: 0x%08lx\n", base_address); |
| 349 | return 0; |
| 350 | } |
| 351 | |
| 352 | int do_mem_loop (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 353 | { |
| 354 | ulong addr, size, length, i, junk; |
| 355 | volatile uint *longp; |
| 356 | volatile ushort *shortp; |
| 357 | volatile u_char *cp; |
| 358 | |
| 359 | if (argc < 3) { |
| 360 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 361 | return 1; |
| 362 | } |
| 363 | |
| 364 | /* Check for a size spefication. |
| 365 | * Defaults to long if no or incorrect specification. |
| 366 | */ |
| 367 | size = cmd_get_data_size(argv[0], 4); |
| 368 | |
| 369 | /* Address is always specified. |
| 370 | */ |
| 371 | addr = simple_strtoul(argv[1], NULL, 16); |
| 372 | |
| 373 | /* Length is the number of objects, not number of bytes. |
| 374 | */ |
| 375 | length = simple_strtoul(argv[2], NULL, 16); |
| 376 | |
| 377 | /* We want to optimize the loops to run as fast as possible. |
| 378 | * If we have only one object, just run infinite loops. |
| 379 | */ |
| 380 | if (length == 1) { |
| 381 | if (size == 4) { |
| 382 | longp = (uint *)addr; |
| 383 | for (;;) |
| 384 | i = *longp; |
| 385 | } |
| 386 | if (size == 2) { |
| 387 | shortp = (ushort *)addr; |
| 388 | for (;;) |
| 389 | i = *shortp; |
| 390 | } |
| 391 | cp = (u_char *)addr; |
| 392 | for (;;) |
| 393 | i = *cp; |
| 394 | } |
| 395 | |
| 396 | if (size == 4) { |
| 397 | for (;;) { |
| 398 | longp = (uint *)addr; |
| 399 | i = length; |
| 400 | while (i-- > 0) |
| 401 | junk = *longp++; |
| 402 | } |
| 403 | } |
| 404 | if (size == 2) { |
| 405 | for (;;) { |
| 406 | shortp = (ushort *)addr; |
| 407 | i = length; |
| 408 | while (i-- > 0) |
| 409 | junk = *shortp++; |
| 410 | } |
| 411 | } |
| 412 | for (;;) { |
| 413 | cp = (u_char *)addr; |
| 414 | i = length; |
| 415 | while (i-- > 0) |
| 416 | junk = *cp++; |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | /* |
| 421 | * Perform a memory test. A more complete alternative test can be |
| 422 | * configured using CFG_ALT_MEMTEST. The complete test loops until |
| 423 | * interrupted by ctrl-c or by a failure of one of the sub-tests. |
| 424 | */ |
| 425 | int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 426 | { |
| 427 | vu_long *addr, *start, *end; |
| 428 | ulong val; |
| 429 | ulong readback; |
| 430 | |
| 431 | #if defined(CFG_ALT_MEMTEST) |
| 432 | vu_long addr_mask; |
| 433 | vu_long offset; |
| 434 | vu_long test_offset; |
| 435 | vu_long pattern; |
| 436 | vu_long temp; |
| 437 | vu_long anti_pattern; |
| 438 | vu_long num_words; |
| 439 | vu_long *dummy = NULL; |
| 440 | int j; |
| 441 | int iterations = 1; |
| 442 | |
| 443 | static const ulong bitpattern[] = { |
| 444 | 0x00000001, /* single bit */ |
| 445 | 0x00000003, /* two adjacent bits */ |
| 446 | 0x00000007, /* three adjacent bits */ |
| 447 | 0x0000000F, /* four adjacent bits */ |
| 448 | 0x00000005, /* two non-adjacent bits */ |
| 449 | 0x00000015, /* three non-adjacent bits */ |
| 450 | 0x00000055, /* four non-adjacent bits */ |
| 451 | 0xaaaaaaaa, /* alternating 1/0 */ |
| 452 | }; |
| 453 | #else |
| 454 | ulong incr; |
| 455 | ulong pattern; |
| 456 | int rcode = 0; |
| 457 | #endif |
| 458 | |
| 459 | if (argc > 1) { |
| 460 | start = (ulong *)simple_strtoul(argv[1], NULL, 16); |
| 461 | } else { |
| 462 | start = (ulong *)CFG_MEMTEST_START; |
| 463 | } |
| 464 | |
| 465 | if (argc > 2) { |
| 466 | end = (ulong *)simple_strtoul(argv[2], NULL, 16); |
| 467 | } else { |
| 468 | end = (ulong *)(CFG_MEMTEST_END); |
| 469 | } |
| 470 | |
| 471 | if (argc > 3) { |
| 472 | pattern = (ulong)simple_strtoul(argv[3], NULL, 16); |
| 473 | } else { |
| 474 | pattern = 0; |
| 475 | } |
| 476 | |
| 477 | #if defined(CFG_ALT_MEMTEST) |
| 478 | printf ("Testing %08x ... %08x:\n", (uint)start, (uint)end); |
| 479 | PRINTF("%s:%d: start 0x%p end 0x%p\n", |
| 480 | __FUNCTION__, __LINE__, start, end); |
| 481 | |
| 482 | for (;;) { |
| 483 | if (ctrlc()) { |
| 484 | putc ('\n'); |
| 485 | return 1; |
| 486 | } |
| 487 | |
| 488 | printf("Iteration: %6d\r", iterations); |
| 489 | PRINTF("Iteration: %6d\n", iterations); |
| 490 | iterations++; |
| 491 | |
| 492 | /* |
| 493 | * Data line test: write a pattern to the first |
| 494 | * location, write the 1's complement to a 'parking' |
| 495 | * address (changes the state of the data bus so a |
| 496 | * floating bus doen't give a false OK), and then |
| 497 | * read the value back. Note that we read it back |
| 498 | * into a variable because the next time we read it, |
| 499 | * it might be right (been there, tough to explain to |
| 500 | * the quality guys why it prints a failure when the |
| 501 | * "is" and "should be" are obviously the same in the |
| 502 | * error message). |
| 503 | * |
| 504 | * Rather than exhaustively testing, we test some |
| 505 | * patterns by shifting '1' bits through a field of |
| 506 | * '0's and '0' bits through a field of '1's (i.e. |
| 507 | * pattern and ~pattern). |
| 508 | */ |
| 509 | addr = start; |
| 510 | for (j = 0; j < sizeof(bitpattern)/sizeof(bitpattern[0]); j++) { |
| 511 | val = bitpattern[j]; |
| 512 | for(; val != 0; val <<= 1) { |
| 513 | *addr = val; |
| 514 | *dummy = ~val; /* clear the test data off of the bus */ |
| 515 | readback = *addr; |
| 516 | if(readback != val) { |
| 517 | printf ("FAILURE (data line): " |
| 518 | "expected %08lx, actual %08lx\n", |
| 519 | val, readback); |
| 520 | } |
| 521 | *addr = ~val; |
| 522 | *dummy = val; |
| 523 | readback = *addr; |
| 524 | if(readback != ~val) { |
| 525 | printf ("FAILURE (data line): " |
| 526 | "Is %08lx, should be %08lx\n", |
| 527 | val, readback); |
| 528 | } |
| 529 | } |
| 530 | } |
| 531 | |
| 532 | /* |
| 533 | * Based on code whose Original Author and Copyright |
| 534 | * information follows: Copyright (c) 1998 by Michael |
| 535 | * Barr. This software is placed into the public |
| 536 | * domain and may be used for any purpose. However, |
| 537 | * this notice must not be changed or removed and no |
| 538 | * warranty is either expressed or implied by its |
| 539 | * publication or distribution. |
| 540 | */ |
| 541 | |
| 542 | /* |
| 543 | * Address line test |
| 544 | * |
| 545 | * Description: Test the address bus wiring in a |
| 546 | * memory region by performing a walking |
| 547 | * 1's test on the relevant bits of the |
| 548 | * address and checking for aliasing. |
| 549 | * This test will find single-bit |
| 550 | * address failures such as stuck -high, |
| 551 | * stuck-low, and shorted pins. The base |
| 552 | * address and size of the region are |
| 553 | * selected by the caller. |
| 554 | * |
| 555 | * Notes: For best results, the selected base |
| 556 | * address should have enough LSB 0's to |
| 557 | * guarantee single address bit changes. |
| 558 | * For example, to test a 64-Kbyte |
| 559 | * region, select a base address on a |
| 560 | * 64-Kbyte boundary. Also, select the |
| 561 | * region size as a power-of-two if at |
| 562 | * all possible. |
| 563 | * |
| 564 | * Returns: 0 if the test succeeds, 1 if the test fails. |
| 565 | * |
| 566 | * ## NOTE ## Be sure to specify start and end |
| 567 | * addresses such that addr_mask has |
| 568 | * lots of bits set. For example an |
| 569 | * address range of 01000000 02000000 is |
| 570 | * bad while a range of 01000000 |
| 571 | * 01ffffff is perfect. |
| 572 | */ |
| 573 | addr_mask = ((ulong)end - (ulong)start)/sizeof(vu_long); |
| 574 | pattern = (vu_long) 0xaaaaaaaa; |
| 575 | anti_pattern = (vu_long) 0x55555555; |
| 576 | |
| 577 | PRINTF("%s:%d: addr mask = 0x%.8lx\n", |
| 578 | __FUNCTION__, __LINE__, |
| 579 | addr_mask); |
| 580 | /* |
| 581 | * Write the default pattern at each of the |
| 582 | * power-of-two offsets. |
| 583 | */ |
| 584 | for (offset = 1; (offset & addr_mask) != 0; offset <<= 1) { |
| 585 | start[offset] = pattern; |
| 586 | } |
| 587 | |
| 588 | /* |
| 589 | * Check for address bits stuck high. |
| 590 | */ |
| 591 | test_offset = 0; |
| 592 | start[test_offset] = anti_pattern; |
| 593 | |
| 594 | for (offset = 1; (offset & addr_mask) != 0; offset <<= 1) { |
| 595 | temp = start[offset]; |
| 596 | if (temp != pattern) { |
| 597 | printf ("\nFAILURE: Address bit stuck high @ 0x%.8lx:" |
| 598 | " expected 0x%.8lx, actual 0x%.8lx\n", |
| 599 | (ulong)&start[offset], pattern, temp); |
| 600 | return 1; |
| 601 | } |
| 602 | } |
| 603 | start[test_offset] = pattern; |
| 604 | |
| 605 | /* |
| 606 | * Check for addr bits stuck low or shorted. |
| 607 | */ |
| 608 | for (test_offset = 1; (test_offset & addr_mask) != 0; test_offset <<= 1) { |
| 609 | start[test_offset] = anti_pattern; |
| 610 | |
| 611 | for (offset = 1; (offset & addr_mask) != 0; offset <<= 1) { |
| 612 | temp = start[offset]; |
| 613 | if ((temp != pattern) && (offset != test_offset)) { |
| 614 | printf ("\nFAILURE: Address bit stuck low or shorted @" |
| 615 | " 0x%.8lx: expected 0x%.8lx, actual 0x%.8lx\n", |
| 616 | (ulong)&start[offset], pattern, temp); |
| 617 | return 1; |
| 618 | } |
| 619 | } |
| 620 | start[test_offset] = pattern; |
| 621 | } |
| 622 | |
| 623 | /* |
| 624 | * Description: Test the integrity of a physical |
| 625 | * memory device by performing an |
| 626 | * increment/decrement test over the |
| 627 | * entire region. In the process every |
| 628 | * storage bit in the device is tested |
| 629 | * as a zero and a one. The base address |
| 630 | * and the size of the region are |
| 631 | * selected by the caller. |
| 632 | * |
| 633 | * Returns: 0 if the test succeeds, 1 if the test fails. |
| 634 | */ |
| 635 | num_words = ((ulong)end - (ulong)start)/sizeof(vu_long) + 1; |
| 636 | |
| 637 | /* |
| 638 | * Fill memory with a known pattern. |
| 639 | */ |
| 640 | for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) { |
| 641 | start[offset] = pattern; |
| 642 | } |
| 643 | |
| 644 | /* |
| 645 | * Check each location and invert it for the second pass. |
| 646 | */ |
| 647 | for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) { |
| 648 | temp = start[offset]; |
| 649 | if (temp != pattern) { |
| 650 | printf ("\nFAILURE (read/write) @ 0x%.8lx:" |
| 651 | " expected 0x%.8lx, actual 0x%.8lx)\n", |
| 652 | (ulong)&start[offset], pattern, temp); |
| 653 | return 1; |
| 654 | } |
| 655 | |
| 656 | anti_pattern = ~pattern; |
| 657 | start[offset] = anti_pattern; |
| 658 | } |
| 659 | |
| 660 | /* |
| 661 | * Check each location for the inverted pattern and zero it. |
| 662 | */ |
| 663 | for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) { |
| 664 | anti_pattern = ~pattern; |
| 665 | temp = start[offset]; |
| 666 | if (temp != anti_pattern) { |
| 667 | printf ("\nFAILURE (read/write): @ 0x%.8lx:" |
| 668 | " expected 0x%.8lx, actual 0x%.8lx)\n", |
| 669 | (ulong)&start[offset], anti_pattern, temp); |
| 670 | return 1; |
| 671 | } |
| 672 | start[offset] = 0; |
| 673 | } |
| 674 | } |
| 675 | |
| 676 | #else /* The original, quickie test */ |
| 677 | incr = 1; |
| 678 | for (;;) { |
| 679 | if (ctrlc()) { |
| 680 | putc ('\n'); |
| 681 | return 1; |
| 682 | } |
| 683 | |
| 684 | printf ("\rPattern %08lX Writing..." |
| 685 | "%12s" |
| 686 | "\b\b\b\b\b\b\b\b\b\b", |
| 687 | pattern, ""); |
| 688 | |
| 689 | for (addr=start,val=pattern; addr<end; addr++) { |
| 690 | *addr = val; |
| 691 | val += incr; |
| 692 | } |
| 693 | |
| 694 | printf("Reading..."); |
| 695 | |
| 696 | for (addr=start,val=pattern; addr<end; addr++) { |
| 697 | readback = *addr; |
| 698 | if (readback != val) { |
| 699 | printf ("\nMem error @ 0x%08X: " |
| 700 | "found %08lX, expected %08lX\n", |
| 701 | (uint)addr, readback, val); |
| 702 | rcode = 1; |
| 703 | } |
| 704 | val += incr; |
| 705 | } |
| 706 | |
| 707 | /* |
| 708 | * Flip the pattern each time to make lots of zeros and |
| 709 | * then, the next time, lots of ones. We decrement |
| 710 | * the "negative" patterns and increment the "positive" |
| 711 | * patterns to preserve this feature. |
| 712 | */ |
| 713 | if(pattern & 0x80000000) { |
| 714 | pattern = -pattern; /* complement & increment */ |
| 715 | } |
| 716 | else { |
| 717 | pattern = ~pattern; |
| 718 | } |
| 719 | incr = -incr; |
| 720 | } |
| 721 | return rcode; |
| 722 | #endif |
| 723 | } |
| 724 | |
| 725 | |
| 726 | /* Modify memory. |
| 727 | * |
| 728 | * Syntax: |
| 729 | * mm{.b, .w, .l} {addr} |
| 730 | * nm{.b, .w, .l} {addr} |
| 731 | */ |
| 732 | static int |
| 733 | mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char *argv[]) |
| 734 | { |
| 735 | ulong addr, size, i; |
| 736 | int nbytes; |
| 737 | extern char console_buffer[]; |
| 738 | |
| 739 | if (argc != 2) { |
| 740 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 741 | return 1; |
| 742 | } |
| 743 | |
| 744 | #ifdef CONFIG_BOOT_RETRY_TIME |
| 745 | reset_cmd_timeout(); /* got a good command to get here */ |
| 746 | #endif |
| 747 | /* We use the last specified parameters, unless new ones are |
| 748 | * entered. |
| 749 | */ |
| 750 | addr = mm_last_addr; |
| 751 | size = mm_last_size; |
| 752 | |
| 753 | if ((flag & CMD_FLAG_REPEAT) == 0) { |
| 754 | /* New command specified. Check for a size specification. |
| 755 | * Defaults to long if no or incorrect specification. |
| 756 | */ |
| 757 | size = cmd_get_data_size(argv[0], 4); |
| 758 | |
| 759 | /* Address is specified since argc > 1 |
| 760 | */ |
| 761 | addr = simple_strtoul(argv[1], NULL, 16); |
| 762 | addr += base_address; |
| 763 | } |
| 764 | |
| 765 | /* Print the address, followed by value. Then accept input for |
| 766 | * the next value. A non-converted value exits. |
| 767 | */ |
| 768 | do { |
| 769 | printf("%08lx:", addr); |
| 770 | if (size == 4) |
| 771 | printf(" %08x", *((uint *)addr)); |
| 772 | else if (size == 2) |
| 773 | printf(" %04x", *((ushort *)addr)); |
| 774 | else |
| 775 | printf(" %02x", *((u_char *)addr)); |
| 776 | |
| 777 | nbytes = readline (" ? "); |
| 778 | if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) { |
| 779 | /* <CR> pressed as only input, don't modify current |
| 780 | * location and move to next. "-" pressed will go back. |
| 781 | */ |
| 782 | if (incrflag) |
| 783 | addr += nbytes ? -size : size; |
| 784 | nbytes = 1; |
| 785 | #ifdef CONFIG_BOOT_RETRY_TIME |
| 786 | reset_cmd_timeout(); /* good enough to not time out */ |
| 787 | #endif |
| 788 | } |
| 789 | #ifdef CONFIG_BOOT_RETRY_TIME |
| 790 | else if (nbytes == -2) { |
| 791 | break; /* timed out, exit the command */ |
| 792 | } |
| 793 | #endif |
| 794 | else { |
| 795 | char *endp; |
| 796 | i = simple_strtoul(console_buffer, &endp, 16); |
| 797 | nbytes = endp - console_buffer; |
| 798 | if (nbytes) { |
| 799 | #ifdef CONFIG_BOOT_RETRY_TIME |
| 800 | /* good enough to not time out |
| 801 | */ |
| 802 | reset_cmd_timeout(); |
| 803 | #endif |
| 804 | if (size == 4) |
| 805 | *((uint *)addr) = i; |
| 806 | else if (size == 2) |
| 807 | *((ushort *)addr) = i; |
| 808 | else |
| 809 | *((u_char *)addr) = i; |
| 810 | if (incrflag) |
| 811 | addr += size; |
| 812 | } |
| 813 | } |
| 814 | } while (nbytes); |
| 815 | |
| 816 | mm_last_addr = addr; |
| 817 | mm_last_size = size; |
| 818 | return 0; |
| 819 | } |
| 820 | |
| 821 | int do_mem_crc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 822 | { |
| 823 | ulong addr, length; |
| 824 | ulong crc; |
| 825 | ulong *ptr; |
| 826 | |
| 827 | if (argc < 3) { |
| 828 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 829 | return 1; |
| 830 | } |
| 831 | |
| 832 | addr = simple_strtoul(argv[1], NULL, 16); |
| 833 | addr += base_address; |
| 834 | |
| 835 | length = simple_strtoul(argv[2], NULL, 16); |
| 836 | |
| 837 | crc = crc32 (0, (const uchar *)addr, length); |
| 838 | |
| 839 | printf ("CRC32 for %08lx ... %08lx ==> %08lx\n", |
| 840 | addr, addr + length -1, crc); |
| 841 | |
| 842 | if (argc > 3) |
| 843 | { |
| 844 | ptr = (ulong *)simple_strtoul(argv[3], NULL, 16); |
| 845 | *ptr = crc; |
| 846 | } |
| 847 | |
| 848 | return 0; |
| 849 | } |
| 850 | |
| 851 | #endif /* CFG_CMD_MEMORY */ |