Commit 9d2b18a0f9df38cfe15e10766b1302f10d426355
1 parent
d1cbe85b08
Exists in
master
and in
54 other branches
Rewrite command lookup and help command (fix problems with bubble
sort when sorting command name list). Minor cleanup here and there.
Showing 6 changed files with 79 additions and 80 deletions Side-by-side Diff
CHANGELOG
... | ... | @@ -2,6 +2,9 @@ |
2 | 2 | Changes since U-Boot 0.4.0: |
3 | 3 | ====================================================================== |
4 | 4 | |
5 | +* Rewrite command lookup and help command (fix problems with bubble | |
6 | + sort when sorting command name list). Minor cleanup here and there. | |
7 | + | |
5 | 8 | * Merge from "stable branch", tag LABEL_2003_06_28_1800-stable: |
6 | 9 | - Allow to call sysmon function interactively |
7 | 10 | - PIC on LWMON board needs delay after power-on |
common/cmd_bdinfo.c
common/cmd_bootm.c
... | ... | @@ -873,7 +873,14 @@ |
873 | 873 | } |
874 | 874 | |
875 | 875 | cmd_tbl_t U_BOOT_CMD(BOOTD) = MK_CMD_ENTRY( |
876 | - "bootd", 1, 1, do_bootd, | |
876 | + "boot", 1, 1, do_bootd, | |
877 | + "boot - boot default, i.e., run 'bootcmd'\n", | |
878 | + NULL | |
879 | +); | |
880 | + | |
881 | +/* keep old command name "bootd" for backward compatibility */ | |
882 | +cmd_tbl_t U_BOOT_CMD(BOOTD) = MK_CMD_ENTRY( | |
883 | + "bootd", 1, 1, do_bootd, | |
877 | 884 | "bootd - boot default, i.e., run 'bootcmd'\n", |
878 | 885 | NULL |
879 | 886 | ); |
common/cmd_mem.c
... | ... | @@ -36,8 +36,10 @@ |
36 | 36 | #include <dataflash.h> |
37 | 37 | #endif |
38 | 38 | |
39 | -#if (CONFIG_COMMANDS & (CFG_CMD_MEMORY | CFG_CMD_PCI | CFG_CMD_I2C\ | |
40 | - | CMD_CMD_PORTIO)) | |
39 | +#if (CONFIG_COMMANDS & (CFG_CMD_MEMORY | \ | |
40 | + CFG_CMD_I2C | \ | |
41 | + CFG_CMD_PCI | \ | |
42 | + CMD_CMD_PORTIO ) ) | |
41 | 43 | int cmd_get_data_size(char* arg, int default_size) |
42 | 44 | { |
43 | 45 | /* Check for a size specification .b, .w or .l. |
common/command.c
... | ... | @@ -72,44 +72,44 @@ |
72 | 72 | |
73 | 73 | if (argc == 1) { /*show list of commands */ |
74 | 74 | |
75 | - int cmd_items = (((int) &__u_boot_cmd_end) - | |
76 | - ((int) &__u_boot_cmd_start)) / | |
77 | - sizeof (*cmdtp); | |
78 | - int end_sort; | |
79 | - cmd_tbl_t *cmd_array[(cmd_items + 1)]; | |
80 | - int i; | |
75 | + int cmd_items = &__u_boot_cmd_end - | |
76 | + &__u_boot_cmd_start; /* pointer arith! */ | |
77 | + cmd_tbl_t *cmd_array[cmd_items]; | |
78 | + int i, j, swaps; | |
81 | 79 | |
82 | - /* Make list of commands from .uboot_cmd section */ | |
83 | - cmdtp = (cmd_tbl_t *) & __u_boot_cmd_start; | |
84 | - for (i = 1; i <= cmd_items; i++) { | |
85 | - cmd_array[i] = cmdtp; | |
86 | - cmdtp++; | |
80 | + /* Make array of commands from .uboot_cmd section */ | |
81 | + cmdtp = &__u_boot_cmd_start; | |
82 | + for (i = 0; i < cmd_items; i++) { | |
83 | + cmd_array[i] = cmdtp++; | |
87 | 84 | } |
88 | - /* Sort command list */ | |
89 | - end_sort = 0; | |
90 | - for (i = 1; end_sort != 1 || i <= cmd_items - 1; i++) { | |
91 | - if (i == cmd_items) { /* Last command */ | |
92 | - end_sort = 1; | |
93 | - i = 1; | |
94 | - } | |
95 | 85 | |
96 | - if (strcmp (cmd_array[i]->name, cmd_array[i + 1]->name) > 0) { | |
97 | - end_sort = 0; | |
98 | - *cmd_array[0] = *cmd_array[i]; | |
99 | - *cmd_array[i] = *cmd_array[i + 1]; | |
100 | - *cmd_array[i + 1] = *cmd_array[0]; | |
86 | + /* Sort command list (trivial bubble sort) */ | |
87 | + for (i = cmd_items - 1; i > 0; --i) { | |
88 | + swaps = 0; | |
89 | + for (j = 0; j < i; ++j) { | |
90 | + if (strcmp (cmd_array[j]->name, | |
91 | + cmd_array[j + 1]->name) > 0) { | |
92 | + cmd_tbl_t *tmp; | |
93 | + tmp = cmd_array[j]; | |
94 | + cmd_array[j] = cmd_array[j + 1]; | |
95 | + cmd_array[j + 1] = tmp; | |
96 | + ++swaps; | |
97 | + } | |
101 | 98 | } |
99 | + if (!swaps) | |
100 | + break; | |
102 | 101 | } |
103 | 102 | |
104 | 103 | /* print short help (usage) */ |
105 | - for (cmdtp = (cmd_tbl_t *) & __u_boot_cmd_start; | |
106 | - cmdtp != (cmd_tbl_t *) & __u_boot_cmd_end; cmdtp++) { | |
104 | + for (i = 0; i < cmd_items; i++) { | |
105 | + const char *usage = cmd_array[i]->usage; | |
106 | + | |
107 | 107 | /* allow user abort */ |
108 | 108 | if (ctrlc ()) |
109 | 109 | return 1; |
110 | - if (cmdtp->usage == NULL) | |
110 | + if (usage == NULL) | |
111 | 111 | continue; |
112 | - puts (cmdtp->usage); | |
112 | + puts (usage); | |
113 | 113 | } |
114 | 114 | return 0; |
115 | 115 | } |
116 | 116 | |
117 | 117 | |
118 | 118 | |
119 | 119 | |
120 | 120 | |
... | ... | @@ -181,22 +181,32 @@ |
181 | 181 | cmd_tbl_t *find_cmd (const char *cmd) |
182 | 182 | { |
183 | 183 | cmd_tbl_t *cmdtp; |
184 | - | |
185 | 184 | cmd_tbl_t *cmdtp_temp = &__u_boot_cmd_start; /*Init value */ |
186 | - int one_cmd_name = 0; | |
185 | + const char *p; | |
186 | + int len; | |
187 | + int n_found = 0; | |
187 | 188 | |
188 | - for (cmdtp = &__u_boot_cmd_start; cmdtp != &__u_boot_cmd_end; cmdtp++) { | |
189 | - if ((strncmp (cmd, cmdtp->name, strlen (cmd)) == 0) && | |
190 | - (strlen (cmd) == strlen (cmdtp->name))) | |
191 | - return cmdtp; | |
192 | - else if (strncmp (cmd, cmdtp->name, strlen (cmd)) == 0) { | |
193 | - cmdtp_temp = cmdtp; | |
194 | - one_cmd_name++; | |
195 | - } else; | |
189 | + /* | |
190 | + * Some commands allow length modifiers (like "cp.b"); | |
191 | + * compare command name only until first dot. | |
192 | + */ | |
193 | + len = ((p = strchr(cmd, '.')) == NULL) ? strlen (cmd) : (p - cmd); | |
194 | + | |
195 | + for (cmdtp = &__u_boot_cmd_start; | |
196 | + cmdtp != &__u_boot_cmd_end; | |
197 | + cmdtp++) { | |
198 | + if (strncmp (cmd, cmdtp->name, len) == 0) { | |
199 | + if (len == strlen (cmdtp->name)) | |
200 | + return cmdtp; /* full match */ | |
201 | + | |
202 | + cmdtp_temp = cmdtp; /* abbreviated command ? */ | |
203 | + n_found++; | |
204 | + } | |
196 | 205 | } |
197 | - if (one_cmd_name == 1) | |
206 | + if (n_found == 1) { /* exactly one match */ | |
198 | 207 | return cmdtp_temp; |
208 | + } | |
199 | 209 | |
200 | - return NULL; /* not found || one_cmd_name >2 */ | |
210 | + return NULL; /* not found or ambiguous command */ | |
201 | 211 | } |
lib_ppc/board.c
... | ... | @@ -401,9 +401,7 @@ |
401 | 401 | #ifdef CONFIG_LOGBUFFER |
402 | 402 | /* reserve kernel log buffer */ |
403 | 403 | addr -= (LOGBUFF_RESERVE); |
404 | -# ifdef DEBUG | |
405 | - printf ("Reserving %ldk for kernel logbuffer at %08lx\n", LOGBUFF_LEN, addr); | |
406 | -# endif | |
404 | + debug ("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN, addr); | |
407 | 405 | #endif |
408 | 406 | |
409 | 407 | #ifdef CONFIG_PRAM |
410 | 408 | |
... | ... | @@ -413,16 +411,12 @@ |
413 | 411 | i = getenv_r ("pram", tmp, sizeof (tmp)); |
414 | 412 | reg = (i > 0) ? simple_strtoul (tmp, NULL, 10) : CONFIG_PRAM; |
415 | 413 | addr -= (reg << 10); /* size is in kB */ |
416 | -# ifdef DEBUG | |
417 | - printf ("Reserving %ldk for protected RAM at %08lx\n", reg, addr); | |
418 | -# endif | |
414 | + debug ("Reserving %ldk for protected RAM at %08lx\n", reg, addr); | |
419 | 415 | #endif /* CONFIG_PRAM */ |
420 | 416 | |
421 | 417 | /* round down to next 4 kB limit */ |
422 | 418 | addr &= ~(4096 - 1); |
423 | -#ifdef DEBUG | |
424 | - printf ("Top of RAM usable for U-Boot at: %08lx\n", addr); | |
425 | -#endif | |
419 | + debug ("Top of RAM usable for U-Boot at: %08lx\n", addr); | |
426 | 420 | |
427 | 421 | #ifdef CONFIG_LCD |
428 | 422 | /* reserve memory for LCD display (always full pages) */ |
... | ... | @@ -443,9 +437,7 @@ |
443 | 437 | addr -= len; |
444 | 438 | addr &= ~(4096 - 1); |
445 | 439 | |
446 | -#ifdef DEBUG | |
447 | - printf ("Reserving %ldk for U-Boot at: %08lx\n", len >> 10, addr); | |
448 | -#endif | |
440 | + debug ("Reserving %ldk for U-Boot at: %08lx\n", len >> 10, addr); | |
449 | 441 | |
450 | 442 | #ifdef CONFIG_AMIGAONEG3SE |
451 | 443 | gd->relocaddr = addr; |
452 | 444 | |
... | ... | @@ -455,10 +447,8 @@ |
455 | 447 | * reserve memory for malloc() arena |
456 | 448 | */ |
457 | 449 | addr_sp = addr - TOTAL_MALLOC_LEN; |
458 | -#ifdef DEBUG | |
459 | - printf ("Reserving %dk for malloc() at: %08lx\n", | |
450 | + debug ("Reserving %dk for malloc() at: %08lx\n", | |
460 | 451 | TOTAL_MALLOC_LEN >> 10, addr_sp); |
461 | -#endif | |
462 | 452 | |
463 | 453 | /* |
464 | 454 | * (permanently) allocate a Board Info struct |
465 | 455 | |
466 | 456 | |
467 | 457 | |
... | ... | @@ -467,16 +457,12 @@ |
467 | 457 | addr_sp -= sizeof (bd_t); |
468 | 458 | bd = (bd_t *) addr_sp; |
469 | 459 | gd->bd = bd; |
470 | -#ifdef DEBUG | |
471 | - printf ("Reserving %d Bytes for Board Info at: %08lx\n", | |
460 | + debug ("Reserving %d Bytes for Board Info at: %08lx\n", | |
472 | 461 | sizeof (bd_t), addr_sp); |
473 | -#endif | |
474 | 462 | addr_sp -= sizeof (gd_t); |
475 | 463 | id = (gd_t *) addr_sp; |
476 | -#ifdef DEBUG | |
477 | - printf ("Reserving %d Bytes for Global Data at: %08lx\n", | |
464 | + debug ("Reserving %d Bytes for Global Data at: %08lx\n", | |
478 | 465 | sizeof (gd_t), addr_sp); |
479 | -#endif | |
480 | 466 | |
481 | 467 | /* |
482 | 468 | * Finally, we set up a new (bigger) stack. |
... | ... | @@ -488,9 +474,7 @@ |
488 | 474 | addr_sp &= ~0xF; |
489 | 475 | *((ulong *) addr_sp)-- = 0; |
490 | 476 | *((ulong *) addr_sp)-- = 0; |
491 | -#ifdef DEBUG | |
492 | - printf ("Stack Pointer at: %08lx\n", addr_sp); | |
493 | -#endif | |
477 | + debug ("Stack Pointer at: %08lx\n", addr_sp); | |
494 | 478 | |
495 | 479 | /* |
496 | 480 | * Save local variables to board info struct |
... | ... | @@ -536,9 +520,7 @@ |
536 | 520 | #endif |
537 | 521 | #endif |
538 | 522 | |
539 | -#ifdef DEBUG | |
540 | - printf ("New Stack Pointer is: %08lx\n", addr_sp); | |
541 | -#endif | |
523 | + debug ("New Stack Pointer is: %08lx\n", addr_sp); | |
542 | 524 | |
543 | 525 | WATCHDOG_RESET (); |
544 | 526 | |
... | ... | @@ -588,9 +570,7 @@ |
588 | 570 | |
589 | 571 | gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */ |
590 | 572 | |
591 | -#ifdef DEBUG | |
592 | - printf ("Now running in RAM - U-Boot at: %08lx\n", dest_addr); | |
593 | -#endif | |
573 | + debug ("Now running in RAM - U-Boot at: %08lx\n", dest_addr); | |
594 | 574 | |
595 | 575 | WATCHDOG_RESET (); |
596 | 576 | |
... | ... | @@ -847,9 +827,7 @@ |
847 | 827 | defined(CONFIG_SPD823TS) ) |
848 | 828 | |
849 | 829 | WATCHDOG_RESET (); |
850 | -# ifdef DEBUG | |
851 | - puts ("Reset Ethernet PHY\n"); | |
852 | -# endif | |
830 | + debug ("Reset Ethernet PHY\n"); | |
853 | 831 | reset_phy (); |
854 | 832 | #endif |
855 | 833 | |
... | ... | @@ -859,9 +837,7 @@ |
859 | 837 | kgdb_init (); |
860 | 838 | #endif |
861 | 839 | |
862 | -#ifdef DEBUG | |
863 | - printf ("U-Boot relocated to %08lx\n", dest_addr); | |
864 | -#endif | |
840 | + debug ("U-Boot relocated to %08lx\n", dest_addr); | |
865 | 841 | |
866 | 842 | /* |
867 | 843 | * Enable Interrupts |