Commit 1c9f47ab2a2e9b62d08d39bfb9c4adc8f8edc5da

Authored by Tom Rini

Merge branch 'mem' of git://git.denx.de/u-boot-x86

Showing 38 changed files Side-by-side Diff

... ... @@ -3811,6 +3811,15 @@
3811 3811 that is executed before the actual U-Boot. E.g. when
3812 3812 compiling a NAND SPL.
3813 3813  
  3814 +- CONFIG_ARCH_MAP_SYSMEM
  3815 + Generally U-Boot (and in particular the md command) uses
  3816 + effective address. It is therefore not necessary to regard
  3817 + U-Boot address as virtual addresses that need to be translated
  3818 + to physical addresses. However, sandbox requires this, since
  3819 + it maintains its own little RAM buffer which contains all
  3820 + addressable memory. This option causes some memory accesses
  3821 + to be mapped through map_sysmem() / unmap_sysmem().
  3822 +
3814 3823 - CONFIG_USE_ARCH_MEMCPY
3815 3824 CONFIG_USE_ARCH_MEMSET
3816 3825 If these options are used a optimized version of memcpy/memset will
arch/sandbox/config.mk
... ... @@ -18,5 +18,6 @@
18 18 # MA 02111-1307 USA
19 19  
20 20 PLATFORM_CPPFLAGS += -DCONFIG_SANDBOX -D__SANDBOX__ -U_FORTIFY_SOURCE
  21 +PLATFORM_CPPFLAGS += -DCONFIG_ARCH_MAP_SYSMEM
21 22 PLATFORM_LIBS += -lrt
arch/sandbox/cpu/os.c
... ... @@ -44,6 +44,14 @@
44 44 return read(fd, buf, count);
45 45 }
46 46  
  47 +ssize_t os_read_no_block(int fd, void *buf, size_t count)
  48 +{
  49 + const int flags = fcntl(fd, F_GETFL, 0);
  50 +
  51 + fcntl(fd, F_SETFL, flags | O_NONBLOCK);
  52 + return os_read(fd, buf, count);
  53 +}
  54 +
47 55 ssize_t os_write(int fd, const void *buf, size_t count)
48 56 {
49 57 return write(fd, buf, count);
arch/sandbox/cpu/start.c
... ... @@ -122,5 +122,8 @@
122 122 * never return.
123 123 */
124 124 board_init_f(0);
  125 +
  126 + /* NOTREACHED - board_init_f() does not return */
  127 + return 0;
125 128 }
arch/sandbox/include/asm/io.h
... ... @@ -39,4 +39,14 @@
39 39 {
40 40  
41 41 }
  42 +
  43 +/* For sandbox, we want addresses to point into our RAM buffer */
  44 +static inline void *map_sysmem(phys_addr_t paddr, unsigned long len)
  45 +{
  46 + return map_physmem(paddr, len, MAP_WRBACK);
  47 +}
  48 +
  49 +static inline void unmap_sysmem(const void *vaddr)
  50 +{
  51 +}
... ... @@ -452,9 +452,7 @@
452 452  
453 453 /* Don't start if "autostart" is set to "no" */
454 454 if (((s = getenv("autostart")) != NULL) && (strcmp(s, "no") == 0)) {
455   - char buf[32];
456   - sprintf(buf, "%lX", images.os.image_len);
457   - setenv("filesize", buf);
  455 + setenv_hex("filesize", images.os.image_len);
458 456 return 0;
459 457 }
460 458 appl = (int (*)(int, char * const []))(ulong)ntohl(images.ep);
461 459  
... ... @@ -529,17 +527,14 @@
529 527 case BOOTM_STATE_RAMDISK:
530 528 {
531 529 ulong rd_len = images.rd_end - images.rd_start;
532   - char str[17];
533 530  
534 531 ret = boot_ramdisk_high(&images.lmb, images.rd_start,
535 532 rd_len, &images.initrd_start, &images.initrd_end);
536 533 if (ret)
537 534 return ret;
538 535  
539   - sprintf(str, "%lx", images.initrd_start);
540   - setenv("initrd_start", str);
541   - sprintf(str, "%lx", images.initrd_end);
542   - setenv("initrd_end", str);
  536 + setenv_hex("initrd_start", images.initrd_start);
  537 + setenv_hex("initrd_end", images.initrd_end);
543 538 }
544 539 break;
545 540 #endif
... ... @@ -65,7 +65,6 @@
65 65 const struct cbfs_cachenode *file;
66 66 unsigned long offset;
67 67 unsigned long count;
68   - char buf[12];
69 68 long size;
70 69  
71 70 if (argc < 3) {
... ... @@ -95,8 +94,7 @@
95 94  
96 95 printf("\n%ld bytes read\n", size);
97 96  
98   - sprintf(buf, "%lX", size);
99   - setenv("filesize", buf);
  97 + setenv_hex("filesize", size);
100 98  
101 99 return 0;
102 100 }
... ... @@ -146,11 +146,9 @@
146 146 size = cramfs_load ((char *) offset, &part, filename);
147 147  
148 148 if (size > 0) {
149   - char buf[10];
150 149 printf("### CRAMFS load complete: %d bytes loaded to 0x%lx\n",
151 150 size, offset);
152   - sprintf(buf, "%x", size);
153   - setenv("filesize", buf);
  151 + setenv_hex("filesize", size);
154 152 } else {
155 153 printf("### CRAMFS LOAD ERROR<%x> for %s!\n", size, filename);
156 154 }
... ... @@ -40,7 +40,6 @@
40 40 char *name;
41 41 char *ep;
42 42 int size;
43   - char buf [12];
44 43 int drive = CONFIG_SYS_FDC_DRIVE_NUMBER;
45 44  
46 45 /* pre-set load_addr */
... ... @@ -91,8 +90,7 @@
91 90 }
92 91 flush_cache (load_addr, size);
93 92  
94   - sprintf(buf, "%x", size);
95   - setenv("filesize", buf);
  93 + setenv_hex("filesize", size);
96 94  
97 95 printf("Floppy DOS load complete: %d bytes loaded to 0x%lx\n",
98 96 size, load_addr);
... ... @@ -55,12 +55,8 @@
55 55  
56 56 void set_working_fdt_addr(void *addr)
57 57 {
58   - char buf[17];
59   -
60 58 working_fdt = addr;
61   -
62   - sprintf(buf, "%lx", (unsigned long)addr);
63   - setenv("fdtaddr", buf);
  59 + setenv_addr("fdtaddr", addr);
64 60 }
65 61  
66 62 /*
... ... @@ -347,10 +343,7 @@
347 343 }
348 344 if (subcmd[0] == 's') {
349 345 /* get the num nodes at this level */
350   - char buf[11];
351   -
352   - sprintf(buf, "%d", curIndex + 1);
353   - setenv(var, buf);
  346 + setenv_ulong(var, curIndex + 1);
354 347 } else {
355 348 /* node index not found */
356 349 printf("libfdt node not found\n");
... ... @@ -26,22 +26,30 @@
26 26 #include <common.h>
27 27 #include <command.h>
28 28 #include <hash.h>
  29 +#include <linux/ctype.h>
29 30  
30 31 static int do_hash(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
31 32 {
  33 + char *s;
32 34 #ifdef CONFIG_HASH_VERIFY
33   - int verify = 0;
  35 + int flags = HASH_FLAG_ENV;
34 36  
  37 + if (argc < 4)
  38 + return CMD_RET_USAGE;
35 39 if (!strcmp(argv[1], "-v")) {
36   - verify = 1;
  40 + flags |= HASH_FLAG_VERIFY;
37 41 argc--;
38 42 argv++;
39 43 }
  44 +#else
  45 + const int flags = HASH_FLAG_ENV;
40 46 #endif
41 47 /* Move forward to 'algorithm' parameter */
42 48 argc--;
43 49 argv++;
44   - return hash_command(*argv, verify, cmdtp, flag, argc - 1, argv + 1);
  50 + for (s = *argv; *s; s++)
  51 + *s = tolower(*s);
  52 + return hash_command(*argv, flags, cmdtp, flag, argc - 1, argv + 1);
45 53 }
46 54  
47 55 #ifdef CONFIG_HASH_VERIFY
... ... @@ -525,11 +525,9 @@
525 525 }
526 526  
527 527 if (size > 0) {
528   - char buf[10];
529 528 printf("### %s load complete: %d bytes loaded to 0x%lx\n",
530 529 fsname, size, offset);
531   - sprintf(buf, "%x", size);
532   - setenv("filesize", buf);
  530 + setenv_hex("filesize", size);
533 531 } else {
534 532 printf("### %s LOAD ERROR<%x> for %s!\n", fsname, size, filename);
535 533 }
... ... @@ -149,7 +149,6 @@
149 149 int type; /* return code for record type */
150 150 ulong addr; /* load address from S-Record */
151 151 ulong size; /* number of bytes transferred */
152   - char buf[32];
153 152 ulong store_addr;
154 153 ulong start_addr = ~0;
155 154 ulong end_addr = 0;
... ... @@ -198,8 +197,7 @@
198 197 start_addr, end_addr, size, size
199 198 );
200 199 flush_cache(start_addr, size);
201   - sprintf(buf, "%lX", size);
202   - setenv("filesize", buf);
  200 + setenv_hex("filesize", size);
203 201 return (addr);
204 202 case SREC_START:
205 203 break;
... ... @@ -519,7 +517,6 @@
519 517 static ulong load_serial_bin(ulong offset)
520 518 {
521 519 int size, i;
522   - char buf[32];
523 520  
524 521 set_kerm_bin_mode((ulong *) offset);
525 522 size = k_recv();
... ... @@ -539,8 +536,7 @@
539 536 flush_cache(offset, size);
540 537  
541 538 printf("## Total Size = 0x%08x = %d Bytes\n", size, size);
542   - sprintf(buf, "%X", size);
543   - setenv("filesize", buf);
  539 + setenv_hex("filesize", size);
544 540  
545 541 return offset;
546 542 }
... ... @@ -965,7 +961,6 @@
965 961 static ulong load_serial_ymodem(ulong offset)
966 962 {
967 963 int size;
968   - char buf[32];
969 964 int err;
970 965 int res;
971 966 connection_info_t info;
... ... @@ -1012,8 +1007,7 @@
1012 1007 flush_cache(offset, size);
1013 1008  
1014 1009 printf("## Total Size = 0x%08x = %d Bytes\n", size, size);
1015   - sprintf(buf, "%X", size);
1016   - setenv("filesize", buf);
  1010 + setenv_hex("filesize", size);
1017 1011  
1018 1012 return offset;
1019 1013 }
Changes suppressed. Click to show
... ... @@ -32,11 +32,17 @@
32 32 #ifdef CONFIG_HAS_DATAFLASH
33 33 #include <dataflash.h>
34 34 #endif
  35 +#include <hash.h>
35 36 #include <watchdog.h>
  37 +#include <asm/io.h>
36 38 #include <linux/compiler.h>
37 39  
38 40 DECLARE_GLOBAL_DATA_PTR;
39 41  
  42 +#ifndef CONFIG_SYS_MEMTEST_SCRATCH
  43 +#define CONFIG_SYS_MEMTEST_SCRATCH 0
  44 +#endif
  45 +
40 46 static int mod_mem(cmd_tbl_t *, int, int, int, char * const []);
41 47  
42 48 /* Display values from last command.
43 49  
... ... @@ -138,9 +144,13 @@
138 144 # endif
139 145  
140 146 {
  147 + ulong bytes = size * length;
  148 + const void *buf = map_sysmem(addr, bytes);
  149 +
141 150 /* Print the lines. */
142   - print_buffer(addr, (void*)addr, size, length, DISP_LINE_LEN/size);
143   - addr += size*length;
  151 + print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
  152 + addr += bytes;
  153 + unmap_sysmem(buf);
144 154 }
145 155 #endif
146 156  
... ... @@ -163,6 +173,8 @@
163 173 {
164 174 ulong addr, writeval, count;
165 175 int size;
  176 + void *buf;
  177 + ulong bytes;
166 178  
167 179 if ((argc < 3) || (argc > 4))
168 180 return CMD_RET_USAGE;
169 181  
170 182  
171 183  
172 184  
... ... @@ -188,15 +200,18 @@
188 200 count = 1;
189 201 }
190 202  
  203 + bytes = size * count;
  204 + buf = map_sysmem(addr, bytes);
191 205 while (count-- > 0) {
192 206 if (size == 4)
193   - *((ulong *)addr) = (ulong )writeval;
  207 + *((ulong *)buf) = (ulong)writeval;
194 208 else if (size == 2)
195   - *((ushort *)addr) = (ushort)writeval;
  209 + *((ushort *)buf) = (ushort)writeval;
196 210 else
197   - *((u_char *)addr) = (u_char)writeval;
198   - addr += size;
  211 + *((u_char *)buf) = (u_char)writeval;
  212 + buf += size;
199 213 }
  214 + unmap_sysmem(buf);
200 215 return 0;
201 216 }
202 217  
203 218  
... ... @@ -258,10 +273,11 @@
258 273  
259 274 static int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
260 275 {
261   - ulong addr1, addr2, count, ngood;
  276 + ulong addr1, addr2, count, ngood, bytes;
262 277 int size;
263 278 int rcode = 0;
264 279 const char *type;
  280 + const void *buf1, *buf2, *base;
265 281  
266 282 if (argc != 4)
267 283 return CMD_RET_USAGE;
268 284  
269 285  
270 286  
271 287  
272 288  
273 289  
274 290  
... ... @@ -294,33 +310,40 @@
294 310 }
295 311 #endif
296 312  
  313 + bytes = size * count;
  314 + base = buf1 = map_sysmem(addr1, bytes);
  315 + buf2 = map_sysmem(addr2, bytes);
297 316 for (ngood = 0; ngood < count; ++ngood) {
298 317 ulong word1, word2;
299 318 if (size == 4) {
300   - word1 = *(ulong *)addr1;
301   - word2 = *(ulong *)addr2;
  319 + word1 = *(ulong *)buf1;
  320 + word2 = *(ulong *)buf2;
302 321 } else if (size == 2) {
303   - word1 = *(ushort *)addr1;
304   - word2 = *(ushort *)addr2;
  322 + word1 = *(ushort *)buf1;
  323 + word2 = *(ushort *)buf2;
305 324 } else {
306   - word1 = *(u_char *)addr1;
307   - word2 = *(u_char *)addr2;
  325 + word1 = *(u_char *)buf1;
  326 + word2 = *(u_char *)buf2;
308 327 }
309 328 if (word1 != word2) {
  329 + ulong offset = buf1 - base;
  330 +
310 331 printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n",
311   - type, addr1, size, word1,
312   - type, addr2, size, word2);
  332 + type, (ulong)(addr1 + offset), size, word1,
  333 + type, (ulong)(addr2 + offset), size, word2);
313 334 rcode = 1;
314 335 break;
315 336 }
316 337  
317   - addr1 += size;
318   - addr2 += size;
  338 + buf1 += size;
  339 + buf2 += size;
319 340  
320 341 /* reset watchdog from time to time */
321 342 if ((ngood % (64 << 10)) == 0)
322 343 WATCHDOG_RESET();
323 344 }
  345 + unmap_sysmem(buf1);
  346 + unmap_sysmem(buf2);
324 347  
325 348 printf("Total of %ld %s(s) were the same\n", ngood, type);
326 349 return rcode;
327 350  
... ... @@ -328,8 +351,10 @@
328 351  
329 352 static int do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
330 353 {
331   - ulong addr, dest, count;
  354 + ulong addr, dest, count, bytes;
332 355 int size;
  356 + const void *src;
  357 + void *buf;
333 358  
334 359 if (argc != 4)
335 360 return CMD_RET_USAGE;
336 361  
337 362  
338 363  
... ... @@ -419,15 +444,18 @@
419 444 }
420 445 #endif
421 446  
  447 + bytes = size * count;
  448 + buf = map_sysmem(addr, bytes);
  449 + src = map_sysmem(addr, bytes);
422 450 while (count-- > 0) {
423 451 if (size == 4)
424   - *((ulong *)dest) = *((ulong *)addr);
  452 + *((ulong *)buf) = *((ulong *)src);
425 453 else if (size == 2)
426   - *((ushort *)dest) = *((ushort *)addr);
  454 + *((ushort *)buf) = *((ushort *)src);
427 455 else
428   - *((u_char *)dest) = *((u_char *)addr);
429   - addr += size;
430   - dest += size;
  456 + *((u_char *)buf) = *((u_char *)src);
  457 + src += size;
  458 + buf += size;
431 459  
432 460 /* reset watchdog from time to time */
433 461 if ((count % (64 << 10)) == 0)
434 462  
... ... @@ -453,11 +481,12 @@
453 481 static int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc,
454 482 char * const argv[])
455 483 {
456   - ulong addr, length, i;
  484 + ulong addr, length, i, bytes;
457 485 int size;
458 486 volatile uint *longp;
459 487 volatile ushort *shortp;
460 488 volatile u_char *cp;
  489 + const void *buf;
461 490  
462 491 if (argc < 3)
463 492 return CMD_RET_USAGE;
464 493  
465 494  
466 495  
467 496  
... ... @@ -477,28 +506,31 @@
477 506 */
478 507 length = simple_strtoul(argv[2], NULL, 16);
479 508  
  509 + bytes = size * length;
  510 + buf = map_sysmem(addr, bytes);
  511 +
480 512 /* We want to optimize the loops to run as fast as possible.
481 513 * If we have only one object, just run infinite loops.
482 514 */
483 515 if (length == 1) {
484 516 if (size == 4) {
485   - longp = (uint *)addr;
  517 + longp = (uint *)buf;
486 518 for (;;)
487 519 i = *longp;
488 520 }
489 521 if (size == 2) {
490   - shortp = (ushort *)addr;
  522 + shortp = (ushort *)buf;
491 523 for (;;)
492 524 i = *shortp;
493 525 }
494   - cp = (u_char *)addr;
  526 + cp = (u_char *)buf;
495 527 for (;;)
496 528 i = *cp;
497 529 }
498 530  
499 531 if (size == 4) {
500 532 for (;;) {
501   - longp = (uint *)addr;
  533 + longp = (uint *)buf;
502 534 i = length;
503 535 while (i-- > 0)
504 536 *longp++;
505 537  
506 538  
507 539  
508 540  
... ... @@ -506,28 +538,30 @@
506 538 }
507 539 if (size == 2) {
508 540 for (;;) {
509   - shortp = (ushort *)addr;
  541 + shortp = (ushort *)buf;
510 542 i = length;
511 543 while (i-- > 0)
512 544 *shortp++;
513 545 }
514 546 }
515 547 for (;;) {
516   - cp = (u_char *)addr;
  548 + cp = (u_char *)buf;
517 549 i = length;
518 550 while (i-- > 0)
519 551 *cp++;
520 552 }
  553 + unmap_sysmem(buf);
521 554 }
522 555  
523 556 #ifdef CONFIG_LOOPW
524 557 int do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
525 558 {
526   - ulong addr, length, i, data;
  559 + ulong addr, length, i, data, bytes;
527 560 int size;
528 561 volatile uint *longp;
529 562 volatile ushort *shortp;
530 563 volatile u_char *cp;
  564 + void *buf;
531 565  
532 566 if (argc < 4)
533 567 return CMD_RET_USAGE;
534 568  
535 569  
536 570  
537 571  
... ... @@ -550,28 +584,31 @@
550 584 /* data to write */
551 585 data = simple_strtoul(argv[3], NULL, 16);
552 586  
  587 + bytes = size * length;
  588 + buf = map_sysmem(addr, bytes);
  589 +
553 590 /* We want to optimize the loops to run as fast as possible.
554 591 * If we have only one object, just run infinite loops.
555 592 */
556 593 if (length == 1) {
557 594 if (size == 4) {
558   - longp = (uint *)addr;
  595 + longp = (uint *)buf;
559 596 for (;;)
560 597 *longp = data;
561 598 }
562 599 if (size == 2) {
563   - shortp = (ushort *)addr;
  600 + shortp = (ushort *)buf;
564 601 for (;;)
565 602 *shortp = data;
566 603 }
567   - cp = (u_char *)addr;
  604 + cp = (u_char *)buf;
568 605 for (;;)
569 606 *cp = data;
570 607 }
571 608  
572 609 if (size == 4) {
573 610 for (;;) {
574   - longp = (uint *)addr;
  611 + longp = (uint *)buf;
575 612 i = length;
576 613 while (i-- > 0)
577 614 *longp++ = data;
578 615  
... ... @@ -579,14 +616,14 @@
579 616 }
580 617 if (size == 2) {
581 618 for (;;) {
582   - shortp = (ushort *)addr;
  619 + shortp = (ushort *)buf;
583 620 i = length;
584 621 while (i-- > 0)
585 622 *shortp++ = data;
586 623 }
587 624 }
588 625 for (;;) {
589   - cp = (u_char *)addr;
  626 + cp = (u_char *)buf;
590 627 i = length;
591 628 while (i-- > 0)
592 629 *cp++ = data;
593 630  
... ... @@ -594,36 +631,19 @@
594 631 }
595 632 #endif /* CONFIG_LOOPW */
596 633  
597   -/*
598   - * Perform a memory test. A more complete alternative test can be
599   - * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
600   - * interrupted by ctrl-c or by a failure of one of the sub-tests.
601   - */
602   -static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
603   - char * const argv[])
  634 +static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr,
  635 + vu_long *dummy)
604 636 {
605   - vu_long *addr, *start, *end;
606   - ulong val;
607   - ulong readback;
608   - ulong errs = 0;
609   - int iterations = 1;
610   - int iteration_limit;
611   -
612   -#if defined(CONFIG_SYS_ALT_MEMTEST)
613   - vu_long len;
614   - vu_long offset;
615   - vu_long test_offset;
616   - vu_long pattern;
617   - vu_long temp;
618   - vu_long anti_pattern;
619   - vu_long num_words;
620   -#if defined(CONFIG_SYS_MEMTEST_SCRATCH)
621   - vu_long *dummy = (vu_long*)CONFIG_SYS_MEMTEST_SCRATCH;
622   -#else
623   - vu_long *dummy = NULL; /* yes, this is address 0x0, not NULL */
624   -#endif
625   - int j;
626   -
  637 + vu_long *addr;
  638 + ulong errs = 0;
  639 + ulong val, readback;
  640 + int j;
  641 + vu_long offset;
  642 + vu_long test_offset;
  643 + vu_long pattern;
  644 + vu_long temp;
  645 + vu_long anti_pattern;
  646 + vu_long num_words;
627 647 static const ulong bitpattern[] = {
628 648 0x00000001, /* single bit */
629 649 0x00000003, /* two adjacent bits */
630 650  
631 651  
632 652  
633 653  
634 654  
635 655  
636 656  
637 657  
638 658  
639 659  
640 660  
641 661  
642 662  
643 663  
644 664  
645 665  
646 666  
647 667  
648 668  
649 669  
650 670  
651 671  
652 672  
653 673  
654 674  
655 675  
656 676  
657 677  
658 678  
659 679  
660 680  
661 681  
662 682  
663 683  
664 684  
665 685  
666 686  
... ... @@ -634,320 +654,353 @@
634 654 0x00000055, /* four non-adjacent bits */
635 655 0xaaaaaaaa, /* alternating 1/0 */
636 656 };
637   -#else
638   - ulong incr;
639   - ulong pattern;
640   -#endif
641 657  
642   - if (argc > 1)
643   - start = (ulong *)simple_strtoul(argv[1], NULL, 16);
644   - else
645   - start = (ulong *)CONFIG_SYS_MEMTEST_START;
  658 + num_words = (end_addr - start_addr) / sizeof(vu_long);
646 659  
647   - if (argc > 2)
648   - end = (ulong *)simple_strtoul(argv[2], NULL, 16);
649   - else
650   - end = (ulong *)(CONFIG_SYS_MEMTEST_END);
651   -
652   - if (argc > 3)
653   - pattern = (ulong)simple_strtoul(argv[3], NULL, 16);
654   - else
655   - pattern = 0;
656   -
657   - if (argc > 4)
658   - iteration_limit = (ulong)simple_strtoul(argv[4], NULL, 16);
659   - else
660   - iteration_limit = 0;
661   -
662   -#if defined(CONFIG_SYS_ALT_MEMTEST)
663   - printf ("Testing %08x ... %08x:\n", (uint)start, (uint)end);
664   - debug("%s:%d: start 0x%p end 0x%p\n",
665   - __FUNCTION__, __LINE__, start, end);
666   -
667   - for (;;) {
668   - if (ctrlc()) {
669   - putc ('\n');
670   - return 1;
671   - }
672   -
673   -
674   - if (iteration_limit && iterations > iteration_limit) {
675   - printf("Tested %d iteration(s) with %lu errors.\n",
676   - iterations-1, errs);
677   - return errs != 0;
678   - }
679   -
680   - printf("Iteration: %6d\r", iterations);
681   - debug("\n");
682   - iterations++;
683   -
684   - /*
685   - * Data line test: write a pattern to the first
686   - * location, write the 1's complement to a 'parking'
687   - * address (changes the state of the data bus so a
688   - * floating bus doesn't give a false OK), and then
689   - * read the value back. Note that we read it back
690   - * into a variable because the next time we read it,
691   - * it might be right (been there, tough to explain to
692   - * the quality guys why it prints a failure when the
693   - * "is" and "should be" are obviously the same in the
694   - * error message).
695   - *
696   - * Rather than exhaustively testing, we test some
697   - * patterns by shifting '1' bits through a field of
698   - * '0's and '0' bits through a field of '1's (i.e.
699   - * pattern and ~pattern).
700   - */
701   - addr = start;
702   - for (j = 0; j < sizeof(bitpattern)/sizeof(bitpattern[0]); j++) {
703   - val = bitpattern[j];
704   - for(; val != 0; val <<= 1) {
705   - *addr = val;
706   - *dummy = ~val; /* clear the test data off of the bus */
  660 + /*
  661 + * Data line test: write a pattern to the first
  662 + * location, write the 1's complement to a 'parking'
  663 + * address (changes the state of the data bus so a
  664 + * floating bus doesn't give a false OK), and then
  665 + * read the value back. Note that we read it back
  666 + * into a variable because the next time we read it,
  667 + * it might be right (been there, tough to explain to
  668 + * the quality guys why it prints a failure when the
  669 + * "is" and "should be" are obviously the same in the
  670 + * error message).
  671 + *
  672 + * Rather than exhaustively testing, we test some
  673 + * patterns by shifting '1' bits through a field of
  674 + * '0's and '0' bits through a field of '1's (i.e.
  675 + * pattern and ~pattern).
  676 + */
  677 + addr = buf;
  678 + for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) {
  679 + val = bitpattern[j];
  680 + for (; val != 0; val <<= 1) {
  681 + *addr = val;
  682 + *dummy = ~val; /* clear the test data off the bus */
707 683 readback = *addr;
708   - if(readback != val) {
709   - printf ("FAILURE (data line): "
710   - "expected %08lx, actual %08lx\n",
711   - val, readback);
712   - errs++;
713   - if (ctrlc()) {
714   - putc ('\n');
715   - return 1;
716   - }
  684 + if (readback != val) {
  685 + printf("FAILURE (data line): "
  686 + "expected %08lx, actual %08lx\n",
  687 + val, readback);
  688 + errs++;
  689 + if (ctrlc())
  690 + return -1;
717 691 }
718 692 *addr = ~val;
719 693 *dummy = val;
720 694 readback = *addr;
721   - if(readback != ~val) {
722   - printf ("FAILURE (data line): "
723   - "Is %08lx, should be %08lx\n",
724   - readback, ~val);
725   - errs++;
726   - if (ctrlc()) {
727   - putc ('\n');
728   - return 1;
729   - }
  695 + if (readback != ~val) {
  696 + printf("FAILURE (data line): "
  697 + "Is %08lx, should be %08lx\n",
  698 + readback, ~val);
  699 + errs++;
  700 + if (ctrlc())
  701 + return -1;
730 702 }
731   - }
732 703 }
  704 + }
733 705  
734   - /*
735   - * Based on code whose Original Author and Copyright
736   - * information follows: Copyright (c) 1998 by Michael
737   - * Barr. This software is placed into the public
738   - * domain and may be used for any purpose. However,
739   - * this notice must not be changed or removed and no
740   - * warranty is either expressed or implied by its
741   - * publication or distribution.
742   - */
  706 + /*
  707 + * Based on code whose Original Author and Copyright
  708 + * information follows: Copyright (c) 1998 by Michael
  709 + * Barr. This software is placed into the public
  710 + * domain and may be used for any purpose. However,
  711 + * this notice must not be changed or removed and no
  712 + * warranty is either expressed or implied by its
  713 + * publication or distribution.
  714 + */
743 715  
744   - /*
745   - * Address line test
746   - *
747   - * Description: Test the address bus wiring in a
748   - * memory region by performing a walking
749   - * 1's test on the relevant bits of the
750   - * address and checking for aliasing.
751   - * This test will find single-bit
752   - * address failures such as stuck-high,
753   - * stuck-low, and shorted pins. The base
754   - * address and size of the region are
755   - * selected by the caller.
756   - *
757   - * Notes: For best results, the selected base
758   - * address should have enough LSB 0's to
759   - * guarantee single address bit changes.
760   - * For example, to test a 64-Kbyte
761   - * region, select a base address on a
762   - * 64-Kbyte boundary. Also, select the
763   - * region size as a power-of-two if at
764   - * all possible.
765   - *
766   - * Returns: 0 if the test succeeds, 1 if the test fails.
767   - */
768   - len = ((ulong)end - (ulong)start)/sizeof(vu_long);
769   - pattern = (vu_long) 0xaaaaaaaa;
770   - anti_pattern = (vu_long) 0x55555555;
  716 + /*
  717 + * Address line test
771 718  
772   - debug("%s:%d: length = 0x%.8lx\n",
773   - __FUNCTION__, __LINE__,
774   - len);
775   - /*
776   - * Write the default pattern at each of the
777   - * power-of-two offsets.
778   - */
779   - for (offset = 1; offset < len; offset <<= 1) {
780   - start[offset] = pattern;
781   - }
  719 + * Description: Test the address bus wiring in a
  720 + * memory region by performing a walking
  721 + * 1's test on the relevant bits of the
  722 + * address and checking for aliasing.
  723 + * This test will find single-bit
  724 + * address failures such as stuck-high,
  725 + * stuck-low, and shorted pins. The base
  726 + * address and size of the region are
  727 + * selected by the caller.
782 728  
783   - /*
784   - * Check for address bits stuck high.
785   - */
786   - test_offset = 0;
787   - start[test_offset] = anti_pattern;
  729 + * Notes: For best results, the selected base
  730 + * address should have enough LSB 0's to
  731 + * guarantee single address bit changes.
  732 + * For example, to test a 64-Kbyte
  733 + * region, select a base address on a
  734 + * 64-Kbyte boundary. Also, select the
  735 + * region size as a power-of-two if at
  736 + * all possible.
  737 + *
  738 + * Returns: 0 if the test succeeds, 1 if the test fails.
  739 + */
  740 + pattern = (vu_long) 0xaaaaaaaa;
  741 + anti_pattern = (vu_long) 0x55555555;
788 742  
789   - for (offset = 1; offset < len; offset <<= 1) {
790   - temp = start[offset];
791   - if (temp != pattern) {
792   - printf ("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
  743 + debug("%s:%d: length = 0x%.8lx\n", __func__, __LINE__, num_words);
  744 + /*
  745 + * Write the default pattern at each of the
  746 + * power-of-two offsets.
  747 + */
  748 + for (offset = 1; offset < num_words; offset <<= 1)
  749 + addr[offset] = pattern;
  750 +
  751 + /*
  752 + * Check for address bits stuck high.
  753 + */
  754 + test_offset = 0;
  755 + addr[test_offset] = anti_pattern;
  756 +
  757 + for (offset = 1; offset < num_words; offset <<= 1) {
  758 + temp = addr[offset];
  759 + if (temp != pattern) {
  760 + printf("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
793 761 " expected 0x%.8lx, actual 0x%.8lx\n",
794   - (ulong)&start[offset], pattern, temp);
  762 + start_addr + offset, pattern, temp);
795 763 errs++;
796   - if (ctrlc()) {
797   - putc ('\n');
798   - return 1;
799   - }
800   - }
  764 + if (ctrlc())
  765 + return -1;
801 766 }
802   - start[test_offset] = pattern;
803   - WATCHDOG_RESET();
  767 + }
  768 + addr[test_offset] = pattern;
  769 + WATCHDOG_RESET();
804 770  
805   - /*
806   - * Check for addr bits stuck low or shorted.
807   - */
808   - for (test_offset = 1; test_offset < len; test_offset <<= 1) {
809   - start[test_offset] = anti_pattern;
  771 + /*
  772 + * Check for addr bits stuck low or shorted.
  773 + */
  774 + for (test_offset = 1; test_offset < num_words; test_offset <<= 1) {
  775 + addr[test_offset] = anti_pattern;
810 776  
811   - for (offset = 1; offset < len; offset <<= 1) {
812   - temp = start[offset];
  777 + for (offset = 1; offset < num_words; offset <<= 1) {
  778 + temp = addr[offset];
813 779 if ((temp != pattern) && (offset != test_offset)) {
814   - printf ("\nFAILURE: Address bit stuck low or shorted @"
815   - " 0x%.8lx: expected 0x%.8lx, actual 0x%.8lx\n",
816   - (ulong)&start[offset], pattern, temp);
817   - errs++;
818   - if (ctrlc()) {
819   - putc ('\n');
820   - return 1;
821   - }
  780 + printf("\nFAILURE: Address bit stuck low or"
  781 + " shorted @ 0x%.8lx: expected 0x%.8lx,"
  782 + " actual 0x%.8lx\n",
  783 + start_addr + offset, pattern, temp);
  784 + errs++;
  785 + if (ctrlc())
  786 + return -1;
822 787 }
823   - }
824   - start[test_offset] = pattern;
825 788 }
  789 + addr[test_offset] = pattern;
  790 + }
826 791  
827   - /*
828   - * Description: Test the integrity of a physical
829   - * memory device by performing an
830   - * increment/decrement test over the
831   - * entire region. In the process every
832   - * storage bit in the device is tested
833   - * as a zero and a one. The base address
834   - * and the size of the region are
835   - * selected by the caller.
836   - *
837   - * Returns: 0 if the test succeeds, 1 if the test fails.
838   - */
839   - num_words = ((ulong)end - (ulong)start)/sizeof(vu_long) + 1;
  792 + /*
  793 + * Description: Test the integrity of a physical
  794 + * memory device by performing an
  795 + * increment/decrement test over the
  796 + * entire region. In the process every
  797 + * storage bit in the device is tested
  798 + * as a zero and a one. The base address
  799 + * and the size of the region are
  800 + * selected by the caller.
  801 + *
  802 + * Returns: 0 if the test succeeds, 1 if the test fails.
  803 + */
  804 + num_words++;
840 805  
841   - /*
842   - * Fill memory with a known pattern.
843   - */
844   - for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
845   - WATCHDOG_RESET();
846   - start[offset] = pattern;
847   - }
  806 + /*
  807 + * Fill memory with a known pattern.
  808 + */
  809 + for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
  810 + WATCHDOG_RESET();
  811 + addr[offset] = pattern;
  812 + }
848 813  
849   - /*
850   - * Check each location and invert it for the second pass.
851   - */
852   - for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
853   - WATCHDOG_RESET();
854   - temp = start[offset];
855   - if (temp != pattern) {
856   - printf ("\nFAILURE (read/write) @ 0x%.8lx:"
  814 + /*
  815 + * Check each location and invert it for the second pass.
  816 + */
  817 + for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
  818 + WATCHDOG_RESET();
  819 + temp = addr[offset];
  820 + if (temp != pattern) {
  821 + printf("\nFAILURE (read/write) @ 0x%.8lx:"
857 822 " expected 0x%.8lx, actual 0x%.8lx)\n",
858   - (ulong)&start[offset], pattern, temp);
  823 + start_addr + offset, pattern, temp);
859 824 errs++;
860   - if (ctrlc()) {
861   - putc ('\n');
862   - return 1;
863   - }
864   - }
865   -
866   - anti_pattern = ~pattern;
867   - start[offset] = anti_pattern;
  825 + if (ctrlc())
  826 + return -1;
868 827 }
869 828  
870   - /*
871   - * Check each location for the inverted pattern and zero it.
872   - */
873   - for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
874   - WATCHDOG_RESET();
875   - anti_pattern = ~pattern;
876   - temp = start[offset];
877   - if (temp != anti_pattern) {
878   - printf ("\nFAILURE (read/write): @ 0x%.8lx:"
  829 + anti_pattern = ~pattern;
  830 + addr[offset] = anti_pattern;
  831 + }
  832 +
  833 + /*
  834 + * Check each location for the inverted pattern and zero it.
  835 + */
  836 + for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
  837 + WATCHDOG_RESET();
  838 + anti_pattern = ~pattern;
  839 + temp = addr[offset];
  840 + if (temp != anti_pattern) {
  841 + printf("\nFAILURE (read/write): @ 0x%.8lx:"
879 842 " expected 0x%.8lx, actual 0x%.8lx)\n",
880   - (ulong)&start[offset], anti_pattern, temp);
  843 + start_addr + offset, anti_pattern, temp);
881 844 errs++;
882   - if (ctrlc()) {
883   - putc ('\n');
884   - return 1;
885   - }
886   - }
887   - start[offset] = 0;
  845 + if (ctrlc())
  846 + return -1;
888 847 }
  848 + addr[offset] = 0;
889 849 }
890 850  
891   -#else /* The original, quickie test */
892   - incr = 1;
893   - for (;;) {
894   - if (ctrlc()) {
895   - putc ('\n');
896   - return 1;
897   - }
  851 + return 0;
  852 +}
898 853  
899   - if (iteration_limit && iterations > iteration_limit) {
900   - printf("Tested %d iteration(s) with %lu errors.\n",
901   - iterations-1, errs);
902   - return errs != 0;
903   - }
904   - ++iterations;
  854 +static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr,
  855 + vu_long pattern, int iteration)
  856 +{
  857 + vu_long *end;
  858 + vu_long *addr;
  859 + ulong errs = 0;
  860 + ulong incr, length;
  861 + ulong val, readback;
905 862  
906   - printf ("\rPattern %08lX Writing..."
907   - "%12s"
908   - "\b\b\b\b\b\b\b\b\b\b",
909   - pattern, "");
910   -
911   - for (addr=start,val=pattern; addr<end; addr++) {
912   - WATCHDOG_RESET();
913   - *addr = val;
914   - val += incr;
915   - }
916   -
917   - puts ("Reading...");
918   -
919   - for (addr=start,val=pattern; addr<end; addr++) {
920   - WATCHDOG_RESET();
921   - readback = *addr;
922   - if (readback != val) {
923   - printf ("\nMem error @ 0x%08X: "
924   - "found %08lX, expected %08lX\n",
925   - (uint)(uintptr_t)addr, readback, val);
926   - errs++;
927   - if (ctrlc()) {
928   - putc ('\n');
929   - return 1;
930   - }
931   - }
932   - val += incr;
933   - }
934   -
  863 + /* Alternate the pattern */
  864 + incr = 1;
  865 + if (iteration & 1) {
  866 + incr = -incr;
935 867 /*
936 868 * Flip the pattern each time to make lots of zeros and
937 869 * then, the next time, lots of ones. We decrement
938 870 * the "negative" patterns and increment the "positive"
939 871 * patterns to preserve this feature.
940 872 */
941   - if(pattern & 0x80000000) {
  873 + if (pattern & 0x80000000)
942 874 pattern = -pattern; /* complement & increment */
943   - }
944   - else {
  875 + else
945 876 pattern = ~pattern;
  877 + }
  878 + length = (end_addr - start_addr) / sizeof(ulong);
  879 + end = buf + length;
  880 + printf("\rPattern %08lX Writing..."
  881 + "%12s"
  882 + "\b\b\b\b\b\b\b\b\b\b",
  883 + pattern, "");
  884 +
  885 + for (addr = buf, val = pattern; addr < end; addr++) {
  886 + WATCHDOG_RESET();
  887 + *addr = val;
  888 + val += incr;
  889 + }
  890 +
  891 + puts("Reading...");
  892 +
  893 + for (addr = buf, val = pattern; addr < end; addr++) {
  894 + WATCHDOG_RESET();
  895 + readback = *addr;
  896 + if (readback != val) {
  897 + ulong offset = addr - buf;
  898 +
  899 + printf("\nMem error @ 0x%08X: "
  900 + "found %08lX, expected %08lX\n",
  901 + (uint)(uintptr_t)(start_addr + offset),
  902 + readback, val);
  903 + errs++;
  904 + if (ctrlc())
  905 + return -1;
946 906 }
947   - incr = -incr;
  907 + val += incr;
948 908 }
  909 +
  910 + return 0;
  911 +}
  912 +
  913 +/*
  914 + * Perform a memory test. A more complete alternative test can be
  915 + * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
  916 + * interrupted by ctrl-c or by a failure of one of the sub-tests.
  917 + */
  918 +static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
  919 + char * const argv[])
  920 +{
  921 + ulong start, end;
  922 + vu_long *buf, *dummy;
  923 + int iteration_limit;
  924 + int ret;
  925 + ulong errs = 0; /* number of errors, or -1 if interrupted */
  926 + ulong pattern;
  927 + int iteration;
  928 +#if defined(CONFIG_SYS_ALT_MEMTEST)
  929 + const int alt_test = 1;
  930 +#else
  931 + const int alt_test = 0;
949 932 #endif
950   - return 0; /* not reached */
  933 +
  934 + if (argc > 1)
  935 + start = simple_strtoul(argv[1], NULL, 16);
  936 + else
  937 + start = CONFIG_SYS_MEMTEST_START;
  938 +
  939 + if (argc > 2)
  940 + end = simple_strtoul(argv[2], NULL, 16);
  941 + else
  942 + end = CONFIG_SYS_MEMTEST_END;
  943 +
  944 + if (argc > 3)
  945 + pattern = (ulong)simple_strtoul(argv[3], NULL, 16);
  946 + else
  947 + pattern = 0;
  948 +
  949 + if (argc > 4)
  950 + iteration_limit = (ulong)simple_strtoul(argv[4], NULL, 16);
  951 + else
  952 + iteration_limit = 0;
  953 +
  954 + printf("Testing %08x ... %08x:\n", (uint)start, (uint)end);
  955 + debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__,
  956 + start, end);
  957 +
  958 + buf = map_sysmem(start, end - start);
  959 + dummy = map_sysmem(CONFIG_SYS_MEMTEST_SCRATCH, sizeof(vu_long));
  960 + for (iteration = 0;
  961 + !iteration_limit || iteration < iteration_limit;
  962 + iteration++) {
  963 + if (ctrlc()) {
  964 + errs = -1UL;
  965 + break;
  966 + }
  967 +
  968 + printf("Iteration: %6d\r", iteration + 1);
  969 + debug("\n");
  970 + if (alt_test) {
  971 + errs = mem_test_alt(buf, start, end, dummy);
  972 + } else {
  973 + errs = mem_test_quick(buf, start, end, pattern,
  974 + iteration);
  975 + }
  976 + if (errs == -1UL)
  977 + break;
  978 + }
  979 +
  980 + /*
  981 + * Work-around for eldk-4.2 which gives this warning if we try to
  982 + * case in the unmap_sysmem() call:
  983 + * warning: initialization discards qualifiers from pointer target type
  984 + */
  985 + {
  986 + void *vbuf = (void *)buf;
  987 + void *vdummy = (void *)dummy;
  988 +
  989 + unmap_sysmem(vbuf);
  990 + unmap_sysmem(vdummy);
  991 + }
  992 +
  993 + if (errs == -1UL) {
  994 + /* Memory test was aborted - write a newline to finish off */
  995 + putc('\n');
  996 + ret = 1;
  997 + } else {
  998 + printf("Tested %d iteration(s) with %lu errors.\n",
  999 + iteration, errs);
  1000 + ret = errs != 0;
  1001 + }
  1002 +
  1003 + return ret; /* not reached */
951 1004 }
952 1005  
953 1006  
... ... @@ -962,6 +1015,7 @@
962 1015 {
963 1016 ulong addr, i;
964 1017 int nbytes, size;
  1018 + void *ptr = NULL;
965 1019  
966 1020 if (argc != 2)
967 1021 return CMD_RET_USAGE;
968 1022  
969 1023  
970 1024  
... ... @@ -1006,13 +1060,14 @@
1006 1060 * the next value. A non-converted value exits.
1007 1061 */
1008 1062 do {
  1063 + ptr = map_sysmem(addr, size);
1009 1064 printf("%08lx:", addr);
1010 1065 if (size == 4)
1011   - printf(" %08x", *((uint *)addr));
  1066 + printf(" %08x", *((uint *)ptr));
1012 1067 else if (size == 2)
1013   - printf(" %04x", *((ushort *)addr));
  1068 + printf(" %04x", *((ushort *)ptr));
1014 1069 else
1015   - printf(" %02x", *((u_char *)addr));
  1070 + printf(" %02x", *((u_char *)ptr));
1016 1071  
1017 1072 nbytes = readline (" ? ");
1018 1073 if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
1019 1074  
1020 1075  
1021 1076  
... ... @@ -1042,16 +1097,18 @@
1042 1097 reset_cmd_timeout();
1043 1098 #endif
1044 1099 if (size == 4)
1045   - *((uint *)addr) = i;
  1100 + *((uint *)ptr) = i;
1046 1101 else if (size == 2)
1047   - *((ushort *)addr) = i;
  1102 + *((ushort *)ptr) = i;
1048 1103 else
1049   - *((u_char *)addr) = i;
  1104 + *((u_char *)ptr) = i;
1050 1105 if (incrflag)
1051 1106 addr += size;
1052 1107 }
1053 1108 }
1054 1109 } while (nbytes);
  1110 + if (ptr)
  1111 + unmap_sysmem(ptr);
1055 1112  
1056 1113 mm_last_addr = addr;
1057 1114 mm_last_size = size;
1058 1115  
1059 1116  
1060 1117  
1061 1118  
1062 1119  
1063 1120  
1064 1121  
1065 1122  
1066 1123  
... ... @@ -1060,89 +1117,27 @@
1060 1117  
1061 1118 #ifdef CONFIG_CMD_CRC32
1062 1119  
1063   -#ifndef CONFIG_CRC32_VERIFY
1064   -
1065 1120 static int do_mem_crc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1066 1121 {
1067   - ulong addr, length;
1068   - ulong crc;
1069   - ulong *ptr;
1070   -
1071   - if (argc < 3)
1072   - return CMD_RET_USAGE;
1073   -
1074   - addr = simple_strtoul (argv[1], NULL, 16);
1075   - addr += base_address;
1076   -
1077   - length = simple_strtoul (argv[2], NULL, 16);
1078   -
1079   - crc = crc32_wd (0, (const uchar *) addr, length, CHUNKSZ_CRC32);
1080   -
1081   - printf ("CRC32 for %08lx ... %08lx ==> %08lx\n",
1082   - addr, addr + length - 1, crc);
1083   -
1084   - if (argc > 3) {
1085   - ptr = (ulong *) simple_strtoul (argv[3], NULL, 16);
1086   - *ptr = crc;
1087   - }
1088   -
1089   - return 0;
1090   -}
1091   -
1092   -#else /* CONFIG_CRC32_VERIFY */
1093   -
1094   -int do_mem_crc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1095   -{
1096   - ulong addr, length;
1097   - ulong crc;
1098   - ulong *ptr;
1099   - ulong vcrc;
1100   - int verify;
  1122 + int flags = 0;
1101 1123 int ac;
1102 1124 char * const *av;
1103 1125  
1104   - if (argc < 3) {
1105   -usage:
  1126 + if (argc < 3)
1106 1127 return CMD_RET_USAGE;
1107   - }
1108 1128  
1109 1129 av = argv + 1;
1110 1130 ac = argc - 1;
  1131 +#ifdef CONFIG_HASH_VERIFY
1111 1132 if (strcmp(*av, "-v") == 0) {
1112   - verify = 1;
  1133 + flags |= HASH_FLAG_VERIFY;
1113 1134 av++;
1114 1135 ac--;
1115   - if (ac < 3)
1116   - goto usage;
1117   - } else
1118   - verify = 0;
1119   -
1120   - addr = simple_strtoul(*av++, NULL, 16);
1121   - addr += base_address;
1122   - length = simple_strtoul(*av++, NULL, 16);
1123   -
1124   - crc = crc32_wd (0, (const uchar *) addr, length, CHUNKSZ_CRC32);
1125   -
1126   - if (!verify) {
1127   - printf ("CRC32 for %08lx ... %08lx ==> %08lx\n",
1128   - addr, addr + length - 1, crc);
1129   - if (ac > 2) {
1130   - ptr = (ulong *) simple_strtoul (*av++, NULL, 16);
1131   - *ptr = crc;
1132   - }
1133   - } else {
1134   - vcrc = simple_strtoul(*av++, NULL, 16);
1135   - if (vcrc != crc) {
1136   - printf ("CRC32 for %08lx ... %08lx ==> %08lx != %08lx ** ERROR **\n",
1137   - addr, addr + length - 1, crc, vcrc);
1138   - return 1;
1139   - }
1140 1136 }
  1137 +#endif
1141 1138  
1142   - return 0;
1143   -
  1139 + return hash_command("crc32", flags, cmdtp, flag, ac, av);
1144 1140 }
1145   -#endif /* CONFIG_CRC32_VERIFY */
1146 1141  
1147 1142 #endif
1148 1143  
common/cmd_mtdparts.c
... ... @@ -230,7 +230,6 @@
230 230 */
231 231 static void index_partitions(void)
232 232 {
233   - char buf[16];
234 233 u16 mtddevnum;
235 234 struct part_info *part;
236 235 struct list_head *dentry;
... ... @@ -244,8 +243,7 @@
244 243 dev = list_entry(dentry, struct mtd_device, link);
245 244 if (dev == current_mtd_dev) {
246 245 mtddevnum += current_mtd_partnum;
247   - sprintf(buf, "%d", mtddevnum);
248   - setenv("mtddevnum", buf);
  246 + setenv_ulong("mtddevnum", mtddevnum);
249 247 break;
250 248 }
251 249 mtddevnum += dev->num_parts;
... ... @@ -373,7 +373,6 @@
373 373 {
374 374 nand_info_t *nand = &nand_info[idx];
375 375 struct nand_chip *chip = nand->priv;
376   - char buf[32];
377 376  
378 377 printf("Device %d: ", idx);
379 378 if (chip->numchips > 1)
... ... @@ -385,14 +384,9 @@
385 384 printf(" Erase size %8d b\n", nand->erasesize);
386 385  
387 386 /* Set geometry info */
388   - sprintf(buf, "%x", nand->writesize);
389   - setenv("nand_writesize", buf);
390   -
391   - sprintf(buf, "%x", nand->oobsize);
392   - setenv("nand_oobsize", buf);
393   -
394   - sprintf(buf, "%x", nand->erasesize);
395   - setenv("nand_erasesize", buf);
  387 + setenv_hex("nand_writesize", nand->writesize);
  388 + setenv_hex("nand_oobsize", nand->oobsize);
  389 + setenv_hex("nand_erasesize", nand->erasesize);
396 390 }
397 391  
398 392 static int raw_access(nand_info_t *nand, ulong addr, loff_t off, ulong count,
... ... @@ -295,17 +295,17 @@
295 295 }
296 296  
297 297 /**
298   - * Set an environment variable to an address in hex
  298 + * Set an environment variable to an value in hex
299 299 *
300 300 * @param varname Environmet variable to set
301   - * @param addr Value to set it to
  301 + * @param value Value to set it to
302 302 * @return 0 if ok, 1 on error
303 303 */
304   -int setenv_addr(const char *varname, const void *addr)
  304 +int setenv_hex(const char *varname, ulong value)
305 305 {
306 306 char str[17];
307 307  
308   - sprintf(str, "%lx", (uintptr_t)addr);
  308 + sprintf(str, "%lx", value);
309 309 return setenv(varname, str);
310 310 }
311 311  
... ... @@ -891,8 +891,7 @@
891 891 envp->flags = ACTIVE_FLAG;
892 892 #endif
893 893 }
894   - sprintf(buf, "%zX", (size_t)(len + offsetof(env_t, data)));
895   - setenv("filesize", buf);
  894 + setenv_hex("filesize", len + offsetof(env_t, data));
896 895  
897 896 return 0;
898 897  
... ... @@ -100,7 +100,6 @@
100 100 ulong addr = 0, filelen;
101 101 disk_partition_t info;
102 102 block_dev_desc_t *dev_desc = NULL;
103   - char buf [12];
104 103 unsigned long count;
105 104 char *addr_str;
106 105  
... ... @@ -175,8 +174,7 @@
175 174 load_addr = addr;
176 175  
177 176 printf ("\n%ld bytes read\n", filelen);
178   - sprintf(buf, "%lX", filelen);
179   - setenv("filesize", buf);
  177 + setenv_hex("filesize", filelen);
180 178  
181 179 return filelen;
182 180 }
common/cmd_setexpr.c
... ... @@ -53,7 +53,7 @@
53 53 static int do_setexpr(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
54 54 {
55 55 ulong a, b;
56   - char buf[16];
  56 + ulong value;
57 57 int w;
58 58  
59 59 /* Validate arguments */
... ... @@ -67,8 +67,7 @@
67 67 a = get_arg(argv[2], w);
68 68  
69 69 if (argc == 3) {
70   - sprintf(buf, "%lx", a);
71   - setenv(argv[1], buf);
  70 + setenv_hex(argv[1], a);
72 71  
73 72 return 0;
74 73 }
75 74  
... ... @@ -76,20 +75,36 @@
76 75 b = get_arg(argv[4], w);
77 76  
78 77 switch (argv[3][0]) {
79   - case '|': sprintf(buf, "%lx", (a | b)); break;
80   - case '&': sprintf(buf, "%lx", (a & b)); break;
81   - case '+': sprintf(buf, "%lx", (a + b)); break;
82   - case '^': sprintf(buf, "%lx", (a ^ b)); break;
83   - case '-': sprintf(buf, "%lx", (a - b)); break;
84   - case '*': sprintf(buf, "%lx", (a * b)); break;
85   - case '/': sprintf(buf, "%lx", (a / b)); break;
86   - case '%': sprintf(buf, "%lx", (a % b)); break;
  78 + case '|':
  79 + value = a | b;
  80 + break;
  81 + case '&':
  82 + value = a & b;
  83 + break;
  84 + case '+':
  85 + value = a + b;
  86 + break;
  87 + case '^':
  88 + value = a ^ b;
  89 + break;
  90 + case '-':
  91 + value = a - b;
  92 + break;
  93 + case '*':
  94 + value = a * b;
  95 + break;
  96 + case '/':
  97 + value = a / b;
  98 + break;
  99 + case '%':
  100 + value = a % b;
  101 + break;
87 102 default:
88 103 printf("invalid op\n");
89 104 return 1;
90 105 }
91 106  
92   - setenv(argv[1], buf);
  107 + setenv_hex(argv[1], value);
93 108  
94 109 return 0;
95 110 }
common/cmd_sha1sum.c
... ... @@ -31,7 +31,7 @@
31 31  
32 32 int do_sha1sum(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
33 33 {
34   - int verify = 0;
  34 + int flags = HASH_FLAG_ENV;
35 35 int ac;
36 36 char * const *av;
37 37  
38 38  
... ... @@ -42,13 +42,13 @@
42 42 ac = argc - 1;
43 43 #ifdef CONFIG_SHA1SUM_VERIFY
44 44 if (strcmp(*av, "-v") == 0) {
45   - verify = 1;
  45 + flags |= HASH_FLAG_VERIFY;
46 46 av++;
47 47 ac--;
48 48 }
49 49 #endif
50 50  
51   - return hash_command("sha1", verify, cmdtp, flag, ac, av);
  51 + return hash_command("sha1", flags, cmdtp, flag, ac, av);
52 52 }
53 53  
54 54 #ifdef CONFIG_SHA1SUM_VERIFY
... ... @@ -28,7 +28,6 @@
28 28 {
29 29 unsigned long src, dst;
30 30 unsigned long src_len = ~0UL, dst_len = ~0UL;
31   - char buf[32];
32 31  
33 32 switch (argc) {
34 33 case 4:
... ... @@ -46,8 +45,7 @@
46 45 return 1;
47 46  
48 47 printf("Uncompressed size: %ld = 0x%lX\n", src_len, src_len);
49   - sprintf(buf, "%lX", src_len);
50   - setenv("filesize", buf);
  48 + setenv_hex("filesize", src_len);
51 49  
52 50 return 0;
53 51 }
... ... @@ -50,7 +50,6 @@
50 50 ulong data, len, count;
51 51 int verify;
52 52 int part = 0;
53   - char pbuf[10];
54 53 image_header_t *hdr;
55 54 #if defined(CONFIG_FIT)
56 55 const char *uname = NULL;
... ... @@ -256,10 +255,8 @@
256 255 puts("OK\n");
257 256 }
258 257  
259   - sprintf(pbuf, "%8lx", data);
260   - setenv("fileaddr", pbuf);
261   - sprintf(pbuf, "%8lx", len);
262   - setenv("filesize", pbuf);
  258 + setenv_hex("fileaddr", data);
  259 + setenv_hex("filesize", len);
263 260  
264 261 return 0;
265 262 }
... ... @@ -129,8 +129,7 @@
129 129 load_addr = addr;
130 130  
131 131 printf("%llu bytes read\n", zfile.size);
132   - sprintf(buf, "%llX", zfile.size);
133   - setenv("filesize", buf);
  132 + setenv_hex("filesize", zfile.size);
134 133  
135 134 return 0;
136 135 }
... ... @@ -28,7 +28,6 @@
28 28 {
29 29 unsigned long src, dst;
30 30 unsigned long src_len, dst_len = ~0UL;
31   - char buf[32];
32 31  
33 32 switch (argc) {
34 33 case 5:
... ... @@ -47,8 +46,7 @@
47 46 return 1;
48 47  
49 48 printf("Compressed size: %ld = 0x%lX\n", dst_len, dst_len);
50   - sprintf(buf, "%lX", dst_len);
51   - setenv("filesize", buf);
  49 + setenv_hex("filesize", dst_len);
52 50  
53 51 return 0;
54 52 }
... ... @@ -28,49 +28,87 @@
28 28 #include <hash.h>
29 29 #include <sha1.h>
30 30 #include <sha256.h>
  31 +#include <asm/io.h>
31 32  
32 33 /*
33 34 * These are the hash algorithms we support. Chips which support accelerated
34   - * crypto could perhaps add named version of these algorithms here.
  35 + * crypto could perhaps add named version of these algorithms here. Note that
  36 + * algorithm names must be in lower case.
35 37 */
36 38 static struct hash_algo hash_algo[] = {
37   -#ifdef CONFIG_SHA1
  39 + /*
  40 + * This is CONFIG_CMD_SHA1SUM instead of CONFIG_SHA1 since otherwise
  41 + * it bloats the code for boards which use SHA1 but not the 'hash'
  42 + * or 'sha1sum' commands.
  43 + */
  44 +#ifdef CONFIG_CMD_SHA1SUM
38 45 {
39   - "SHA1",
  46 + "sha1",
40 47 SHA1_SUM_LEN,
41 48 sha1_csum_wd,
42 49 CHUNKSZ_SHA1,
43 50 },
  51 +#define MULTI_HASH
44 52 #endif
45 53 #ifdef CONFIG_SHA256
46 54 {
47   - "SHA256",
  55 + "sha256",
48 56 SHA256_SUM_LEN,
49 57 sha256_csum_wd,
50 58 CHUNKSZ_SHA256,
51 59 },
  60 +#define MULTI_HASH
52 61 #endif
  62 + {
  63 + "crc32",
  64 + 4,
  65 + crc32_wd_buf,
  66 + CHUNKSZ_CRC32,
  67 + },
53 68 };
54 69  
  70 +#if defined(CONFIG_HASH_VERIFY) || defined(CONFIG_CMD_HASH)
  71 +#define MULTI_HASH
  72 +#endif
  73 +
  74 +/* Try to minimize code size for boards that don't want much hashing */
  75 +#ifdef MULTI_HASH
  76 +#define multi_hash() 1
  77 +#else
  78 +#define multi_hash() 0
  79 +#endif
  80 +
55 81 /**
56 82 * store_result: Store the resulting sum to an address or variable
57 83 *
58 84 * @algo: Hash algorithm being used
59 85 * @sum: Hash digest (algo->digest_size bytes)
60 86 * @dest: Destination, interpreted as a hex address if it starts
61   - * with * or otherwise as an environment variable.
  87 + * with * (or allow_env_vars is 0) or otherwise as an
  88 + * environment variable.
  89 + * @allow_env_vars: non-zero to permit storing the result to an
  90 + * variable environment
62 91 */
63 92 static void store_result(struct hash_algo *algo, const u8 *sum,
64   - const char *dest)
  93 + const char *dest, int allow_env_vars)
65 94 {
66 95 unsigned int i;
  96 + int env_var = 0;
67 97  
68   - if (*dest == '*') {
69   - u8 *ptr;
  98 + /*
  99 + * If environment variables are allowed, then we assume that 'dest'
  100 + * is an environment variable, unless it starts with *, in which
  101 + * case we assume it is an address. If not allowed, it is always an
  102 + * address. This is to support the crc32 command.
  103 + */
  104 + if (allow_env_vars) {
  105 + if (*dest == '*')
  106 + dest++;
  107 + else
  108 + env_var = 1;
  109 + }
70 110  
71   - ptr = (u8 *)simple_strtoul(dest + 1, NULL, 16);
72   - memcpy(ptr, sum, algo->digest_size);
73   - } else {
  111 + if (env_var) {
74 112 char str_output[HASH_MAX_DIGEST_SIZE * 2 + 1];
75 113 char *str_ptr = str_output;
76 114  
... ... @@ -80,6 +118,14 @@
80 118 }
81 119 str_ptr = '\0';
82 120 setenv(dest, str_output);
  121 + } else {
  122 + ulong addr;
  123 + void *buf;
  124 +
  125 + addr = simple_strtoul(dest, NULL, 16);
  126 + buf = map_sysmem(addr, algo->digest_size);
  127 + memcpy(buf, sum, algo->digest_size);
  128 + unmap_sysmem(buf);
83 129 }
84 130 }
85 131  
86 132  
87 133  
88 134  
... ... @@ -94,15 +140,31 @@
94 140 * Otherwise we assume it is an environment variable, and
95 141 * look up its value (it must contain a hex digest).
96 142 * @vsum: Returns binary digest value (algo->digest_size bytes)
  143 + * @allow_env_vars: non-zero to permit storing the result to an environment
  144 + * variable. If 0 then verify_str is assumed to be an
  145 + * address, and the * prefix is not expected.
97 146 * @return 0 if ok, non-zero on error
98 147 */
99   -static int parse_verify_sum(struct hash_algo *algo, char *verify_str, u8 *vsum)
  148 +static int parse_verify_sum(struct hash_algo *algo, char *verify_str, u8 *vsum,
  149 + int allow_env_vars)
100 150 {
101   - if (*verify_str == '*') {
102   - u8 *ptr;
  151 + int env_var = 0;
103 152  
104   - ptr = (u8 *)simple_strtoul(verify_str + 1, NULL, 16);
105   - memcpy(vsum, ptr, algo->digest_size);
  153 + /* See comment above in store_result() */
  154 + if (allow_env_vars) {
  155 + if (*verify_str == '*')
  156 + verify_str++;
  157 + else
  158 + env_var = 1;
  159 + }
  160 +
  161 + if (env_var) {
  162 + ulong addr;
  163 + void *buf;
  164 +
  165 + addr = simple_strtoul(verify_str, NULL, 16);
  166 + buf = map_sysmem(addr, algo->digest_size);
  167 + memcpy(vsum, buf, algo->digest_size);
106 168 } else {
107 169 unsigned int i;
108 170 char *vsum_str;
... ... @@ -141,7 +203,7 @@
141 203 int i;
142 204  
143 205 for (i = 0; i < ARRAY_SIZE(hash_algo); i++) {
144   - if (!strcasecmp(name, hash_algo[i].name))
  206 + if (!strcmp(name, hash_algo[i].name))
145 207 return &hash_algo[i];
146 208 }
147 209  
148 210  
149 211  
150 212  
151 213  
152 214  
153 215  
154 216  
155 217  
156 218  
157 219  
158 220  
159 221  
160 222  
161 223  
162 224  
... ... @@ -158,63 +220,87 @@
158 220 printf("%02x", output[i]);
159 221 }
160 222  
161   -int hash_command(const char *algo_name, int verify, cmd_tbl_t *cmdtp, int flag,
  223 +int hash_command(const char *algo_name, int flags, cmd_tbl_t *cmdtp, int flag,
162 224 int argc, char * const argv[])
163 225 {
164   - struct hash_algo *algo;
165 226 ulong addr, len;
166   - u8 output[HASH_MAX_DIGEST_SIZE];
167   - u8 vsum[HASH_MAX_DIGEST_SIZE];
168 227  
169 228 if (argc < 2)
170 229 return CMD_RET_USAGE;
171 230  
172   - algo = find_hash_algo(algo_name);
173   - if (!algo) {
174   - printf("Unknown hash algorithm '%s'\n", algo_name);
175   - return CMD_RET_USAGE;
176   - }
177 231 addr = simple_strtoul(*argv++, NULL, 16);
178 232 len = simple_strtoul(*argv++, NULL, 16);
179   - argc -= 2;
180 233  
181   - if (algo->digest_size > HASH_MAX_DIGEST_SIZE) {
182   - puts("HASH_MAX_DIGEST_SIZE exceeded\n");
183   - return 1;
184   - }
  234 + if (multi_hash()) {
  235 + struct hash_algo *algo;
  236 + u8 output[HASH_MAX_DIGEST_SIZE];
  237 + u8 vsum[HASH_MAX_DIGEST_SIZE];
  238 + void *buf;
185 239  
186   - algo->hash_func_ws((const unsigned char *)addr, len, output,
187   - algo->chunk_size);
  240 + algo = find_hash_algo(algo_name);
  241 + if (!algo) {
  242 + printf("Unknown hash algorithm '%s'\n", algo_name);
  243 + return CMD_RET_USAGE;
  244 + }
  245 + argc -= 2;
188 246  
189   - /* Try to avoid code bloat when verify is not needed */
  247 + if (algo->digest_size > HASH_MAX_DIGEST_SIZE) {
  248 + puts("HASH_MAX_DIGEST_SIZE exceeded\n");
  249 + return 1;
  250 + }
  251 +
  252 + buf = map_sysmem(addr, len);
  253 + algo->hash_func_ws(buf, len, output, algo->chunk_size);
  254 + unmap_sysmem(buf);
  255 +
  256 + /* Try to avoid code bloat when verify is not needed */
190 257 #ifdef CONFIG_HASH_VERIFY
191   - if (verify) {
  258 + if (flags & HASH_FLAG_VERIFY) {
192 259 #else
193   - if (0) {
  260 + if (0) {
194 261 #endif
195   - if (!argc)
196   - return CMD_RET_USAGE;
197   - if (parse_verify_sum(algo, *argv, vsum)) {
198   - printf("ERROR: %s does not contain a valid %s sum\n",
199   - *argv, algo->name);
200   - return 1;
201   - }
202   - if (memcmp(output, vsum, algo->digest_size) != 0) {
203   - int i;
  262 + if (!argc)
  263 + return CMD_RET_USAGE;
  264 + if (parse_verify_sum(algo, *argv, vsum,
  265 + flags & HASH_FLAG_ENV)) {
  266 + printf("ERROR: %s does not contain a valid "
  267 + "%s sum\n", *argv, algo->name);
  268 + return 1;
  269 + }
  270 + if (memcmp(output, vsum, algo->digest_size) != 0) {
  271 + int i;
204 272  
  273 + show_hash(algo, addr, len, output);
  274 + printf(" != ");
  275 + for (i = 0; i < algo->digest_size; i++)
  276 + printf("%02x", vsum[i]);
  277 + puts(" ** ERROR **\n");
  278 + return 1;
  279 + }
  280 + } else {
205 281 show_hash(algo, addr, len, output);
206   - printf(" != ");
207   - for (i = 0; i < algo->digest_size; i++)
208   - printf("%02x", vsum[i]);
209   - puts(" ** ERROR **\n");
210   - return 1;
  282 + printf("\n");
  283 +
  284 + if (argc) {
  285 + store_result(algo, output, *argv,
  286 + flags & HASH_FLAG_ENV);
  287 + }
211 288 }
  289 +
  290 + /* Horrible code size hack for boards that just want crc32 */
212 291 } else {
213   - show_hash(algo, addr, len, output);
214   - printf("\n");
  292 + ulong crc;
  293 + ulong *ptr;
215 294  
216   - if (argc)
217   - store_result(algo, output, *argv);
  295 + crc = crc32_wd(0, (const uchar *)addr, len, CHUNKSZ_CRC32);
  296 +
  297 + printf("CRC32 for %08lx ... %08lx ==> %08lx\n",
  298 + addr, addr + len - 1, crc);
  299 +
  300 + if (argc > 3) {
  301 + ptr = (ulong *)simple_strtoul(argv[3], NULL, 16);
  302 + *ptr = crc;
  303 + }
218 304 }
219 305  
220 306 return 0;
... ... @@ -74,6 +74,8 @@
74 74 #include <image.h>
75 75 #endif /* !USE_HOSTCC*/
76 76  
  77 +#include <u-boot/crc.h>
  78 +
77 79 static const table_entry_t uimage_arch[] = {
78 80 { IH_ARCH_INVALID, NULL, "Invalid ARCH", },
79 81 { IH_ARCH_ALPHA, "alpha", "Alpha", },
... ... @@ -160,8 +162,6 @@
160 162 { -1, "", "", },
161 163 };
162 164  
163   -uint32_t crc32(uint32_t, const unsigned char *, uint);
164   -uint32_t crc32_wd(uint32_t, const unsigned char *, uint, uint);
165 165 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
166 166 static void genimg_print_time(time_t timestamp);
167 167 #endif
... ... @@ -362,7 +362,6 @@
362 362 int fm_init_common(int index, struct ccsr_fman *reg)
363 363 {
364 364 int rc;
365   - char env_addr[32];
366 365 #if defined(CONFIG_SYS_QE_FMAN_FW_IN_NOR)
367 366 void *addr = (void *)CONFIG_SYS_QE_FMAN_FW_ADDR;
368 367 #elif defined(CONFIG_SYS_QE_FMAN_FW_IN_NAND)
... ... @@ -416,8 +415,7 @@
416 415 rc = fman_upload_firmware(index, &reg->fm_imem, addr);
417 416 if (rc)
418 417 return rc;
419   - sprintf(env_addr, "0x%lx", (long unsigned int)addr);
420   - setenv("fman_ucode", env_addr);
  418 + setenv_addr("fman_ucode", addr);
421 419  
422 420 fm_init_muram(index, &reg->muram);
423 421 fm_init_qmi(&reg->fm_qmi_common);
drivers/serial/sandbox.c
... ... @@ -30,6 +30,19 @@
30 30 #include <serial.h>
31 31 #include <linux/compiler.h>
32 32  
  33 +/*
  34 + *
  35 + * serial_buf: A buffer that holds keyboard characters for the
  36 + * Sandbox U-boot.
  37 + *
  38 + * invariants:
  39 + * serial_buf_write == serial_buf_read -> empty buffer
  40 + * (serial_buf_write + 1) % 16 == serial_buf_read -> full buffer
  41 + */
  42 +static char serial_buf[16];
  43 +static unsigned int serial_buf_write;
  44 +static unsigned int serial_buf_read;
  45 +
33 46 static int sandbox_serial_init(void)
34 47 {
35 48 os_tty_raw(0);
36 49  
37 50  
38 51  
39 52  
... ... @@ -50,18 +63,37 @@
50 63 os_write(1, str, strlen(str));
51 64 }
52 65  
53   -static int sandbox_serial_getc(void)
  66 +static unsigned int increment_buffer_index(unsigned int index)
54 67 {
55   - char buf;
  68 + return (index + 1) % ARRAY_SIZE(serial_buf);
  69 +}
  70 +
  71 +static int sandbox_serial_tstc(void)
  72 +{
  73 + const unsigned int next_index =
  74 + increment_buffer_index(serial_buf_write);
56 75 ssize_t count;
57 76  
58   - count = os_read(0, &buf, 1);
59   - return count == 1 ? buf : 0;
  77 + os_usleep(100);
  78 + if (next_index == serial_buf_read)
  79 + return 1; /* buffer full */
  80 +
  81 + count = os_read_no_block(0, &serial_buf[serial_buf_write], 1);
  82 + if (count == 1)
  83 + serial_buf_write = next_index;
  84 + return serial_buf_write != serial_buf_read;
60 85 }
61 86  
62   -static int sandbox_serial_tstc(void)
  87 +static int sandbox_serial_getc(void)
63 88 {
64   - return 0;
  89 + int result;
  90 +
  91 + while (!sandbox_serial_tstc())
  92 + ; /* buffer empty */
  93 +
  94 + result = serial_buf[serial_buf_read];
  95 + serial_buf_read = increment_buffer_index(serial_buf_read);
  96 + return result;
65 97 }
66 98  
67 99 static struct serial_device sandbox_serial_drv = {
... ... @@ -256,7 +256,6 @@
256 256 unsigned long bytes;
257 257 unsigned long pos;
258 258 int len_read;
259   - char buf[12];
260 259 unsigned long time;
261 260  
262 261 if (argc < 2)
... ... @@ -308,8 +307,7 @@
308 307 }
309 308 puts("\n");
310 309  
311   - sprintf(buf, "0x%x", len_read);
312   - setenv("filesize", buf);
  310 + setenv_hex("filesize", len_read);
313 311  
314 312 return 0;
315 313 }
... ... @@ -687,7 +687,6 @@
687 687 int i;
688 688 int count;
689 689 int last_block_size = 0;
690   - char buf [10];
691 690  
692 691 c->ubi = ubi_open_volume(c->vi.ubi_num, c->vi.vol_id, UBI_READONLY);
693 692 /* ubifs_findfile will resolve symlinks, so we know that we get
... ... @@ -740,8 +739,7 @@
740 739 if (err)
741 740 printf("Error reading file '%s'\n", filename);
742 741 else {
743   - sprintf(buf, "%X", size);
744   - setenv("filesize", buf);
  742 + setenv_hex("filesize", size);
745 743 printf("Done\n");
746 744 }
747 745  
... ... @@ -270,7 +270,8 @@
270 270 phys_size_t initdram (int);
271 271 int display_options (void);
272 272 void print_size(unsigned long long, const char *);
273   -int print_buffer (ulong addr, void* data, uint width, uint count, uint linelen);
  273 +int print_buffer(ulong addr, const void *data, uint width, uint count,
  274 + uint linelen);
274 275  
275 276 /* common/main.c */
276 277 void main_loop (void);
... ... @@ -357,7 +358,19 @@
357 358 int saveenv (void);
358 359 int setenv (const char *, const char *);
359 360 int setenv_ulong(const char *varname, ulong value);
360   -int setenv_addr(const char *varname, const void *addr);
  361 +int setenv_hex(const char *varname, ulong value);
  362 +/**
  363 + * setenv_addr - Set an environment variable to an address in hex
  364 + *
  365 + * @varname: Environmet variable to set
  366 + * @addr: Value to set it to
  367 + * @return 0 if ok, 1 on error
  368 + */
  369 +static inline int setenv_addr(const char *varname, const void *addr)
  370 +{
  371 + return setenv_hex(varname, (ulong)addr);
  372 +}
  373 +
361 374 #ifdef CONFIG_ARM
362 375 # include <asm/mach-types.h>
363 376 # include <asm/setup.h>
... ... @@ -868,6 +881,18 @@
868 881 int cpu_disable(int nr);
869 882 int cpu_release(int nr, int argc, char * const argv[]);
870 883 #endif
  884 +
  885 +/* Define a null map_sysmem() if the architecture doesn't use it */
  886 +# ifndef CONFIG_ARCH_MAP_SYSMEM
  887 +static inline void *map_sysmem(phys_addr_t paddr, unsigned long len)
  888 +{
  889 + return (void *)(uintptr_t)paddr;
  890 +}
  891 +
  892 +static inline void unmap_sysmem(const void *vaddr)
  893 +{
  894 +}
  895 +# endif
871 896  
872 897 #endif /* __ASSEMBLY__ */
873 898  
include/configs/sandbox.h
... ... @@ -63,8 +63,8 @@
63 63 #define CONFIG_SYS_HZ 1000
64 64  
65 65 /* Memory things - we don't really want a memory test */
66   -#define CONFIG_SYS_LOAD_ADDR 0x10000000
67   -#define CONFIG_SYS_MEMTEST_START 0x10000000
  66 +#define CONFIG_SYS_LOAD_ADDR 0x00000000
  67 +#define CONFIG_SYS_MEMTEST_START 0x00100000
68 68 #define CONFIG_SYS_MEMTEST_END (CONFIG_SYS_MEMTEST_START + 0x1000)
69 69 #define CONFIG_PHYS_64BIT
70 70  
... ... @@ -84,6 +84,11 @@
84 84 /* We don't have networking support yet */
85 85 #undef CONFIG_CMD_NET
86 86 #undef CONFIG_CMD_NFS
  87 +
  88 +#define CONFIG_CMD_HASH
  89 +#define CONFIG_HASH_VERIFY
  90 +#define CONFIG_SHA1
  91 +#define CONFIG_SHA256
87 92  
88 93 #define CONFIG_BOOTARGS ""
89 94  
... ... @@ -22,7 +22,7 @@
22 22 #ifndef _HASH_H
23 23 #define _HASH_H
24 24  
25   -#ifdef CONFIG_SHA1SUM_VERIFY
  25 +#if defined(CONFIG_SHA1SUM_VERIFY) || defined(CONFIG_CRC32_VERIFY)
26 26 #define CONFIG_HASH_VERIFY
27 27 #endif
28 28  
29 29  
30 30  
... ... @@ -51,19 +51,24 @@
51 51 */
52 52 #define HASH_MAX_DIGEST_SIZE 32
53 53  
  54 +enum {
  55 + HASH_FLAG_VERIFY = 1 << 0, /* Enable verify mode */
  56 + HASH_FLAG_ENV = 1 << 1, /* Allow env vars */
  57 +};
  58 +
54 59 /**
55 60 * hash_command: Process a hash command for a particular algorithm
56 61 *
57 62 * This common function is used to implement specific hash commands.
58 63 *
59   - * @algo_name: Hash algorithm being used
60   - * @verify: Non-zero to enable verify mode
  64 + * @algo_name: Hash algorithm being used (lower case!)
  65 + * @flags: Flags value (HASH_FLAG_...)
61 66 * @cmdtp: Pointer to command table entry
62 67 * @flag: Some flags normally 0 (see CMD_FLAG_.. above)
63 68 * @argc: Number of arguments (arg 0 must be the command text)
64 69 * @argv: Arguments
65 70 */
66   -int hash_command(const char *algo_name, int verify, cmd_tbl_t *cmdtp, int flag,
  71 +int hash_command(const char *algo_name, int flags, cmd_tbl_t *cmdtp, int flag,
67 72 int argc, char * const argv[]);
68 73  
69 74 #endif
... ... @@ -40,6 +40,16 @@
40 40 ssize_t os_read(int fd, void *buf, size_t count);
41 41  
42 42 /**
  43 + * Access to the OS read() system call with non-blocking access
  44 + *
  45 + * \param fd File descriptor as returned by os_open()
  46 + * \param buf Buffer to place data
  47 + * \param count Number of bytes to read
  48 + * \return number of bytes read, or -1 on error
  49 + */
  50 +ssize_t os_read_no_block(int fd, void *buf, size_t count);
  51 +
  52 +/**
43 53 * Access to the OS write() system call
44 54 *
45 55 * \param fd File descriptor as returned by os_open()
include/u-boot/crc.h
... ... @@ -30,5 +30,16 @@
30 30 uint32_t crc32_wd (uint32_t, const unsigned char *, uint, uint);
31 31 uint32_t crc32_no_comp (uint32_t, const unsigned char *, uint);
32 32  
  33 +/**
  34 + * crc32_wd_buf - Perform CRC32 on a buffer and return result in buffer
  35 + *
  36 + * @input: Input buffer
  37 + * @ilen: Input buffer length
  38 + * @output: Place to put checksum result (4 bytes)
  39 + * @chunk_sz: Trigger watchdog after processing this many bytes
  40 + */
  41 +void crc32_wd_buf(const unsigned char *input, uint ilen,
  42 + unsigned char *output, uint chunk_sz);
  43 +
33 44 #endif /* _UBOOT_CRC_H */
... ... @@ -249,4 +249,13 @@
249 249  
250 250 return crc;
251 251 }
  252 +
  253 +void crc32_wd_buf(const unsigned char *input, unsigned int ilen,
  254 + unsigned char *output, unsigned int chunk_sz)
  255 +{
  256 + uint32_t crc;
  257 +
  258 + crc = crc32_wd(0, input, ilen, chunk_sz);
  259 + memcpy(output, &crc, sizeof(crc));
  260 +}
lib/display_options.c
... ... @@ -98,7 +98,8 @@
98 98 */
99 99 #define MAX_LINE_LENGTH_BYTES (64)
100 100 #define DEFAULT_LINE_LENGTH_BYTES (16)
101   -int print_buffer (ulong addr, void* data, uint width, uint count, uint linelen)
  101 +int print_buffer(ulong addr, const void *data, uint width, uint count,
  102 + uint linelen)
102 103 {
103 104 /* linebuf as a union causes proper alignment */
104 105 union linebuf {
... ... @@ -528,15 +528,11 @@
528 528 case NETLOOP_SUCCESS:
529 529 net_cleanup_loop();
530 530 if (NetBootFileXferSize > 0) {
531   - char buf[20];
532 531 printf("Bytes transferred = %ld (%lx hex)\n",
533 532 NetBootFileXferSize,
534 533 NetBootFileXferSize);
535   - sprintf(buf, "%lX", NetBootFileXferSize);
536   - setenv("filesize", buf);
537   -
538   - sprintf(buf, "%lX", (unsigned long)load_addr);
539   - setenv("fileaddr", buf);
  534 + setenv_hex("filesize", NetBootFileXferSize);
  535 + setenv_hex("fileaddr", load_addr);
540 536 }
541 537 if (protocol != NETCONS)
542 538 eth_halt();