2 * (C) Copyright 2000-2003
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
25 * Command Processor Table
31 int do_version(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]){
32 extern char version_string[];
33 printf("%s\n\n", version_string);
38 U_BOOT_CMD(version, 1, 1, do_version, "print U-Boot version\n", NULL);
40 #if (CONFIG_COMMANDS & CFG_CMD_ECHO)
41 int do_echo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]){
44 for(i = 1; i < argc; i++){
51 while((c = *p++) != '\0'){
52 if(c == '\\' && *p == 'c'){
67 U_BOOT_CMD(echo, CFG_MAXARGS, 1, do_echo, "echo args to console\n", "[args..]\n" "\t- echo args to console; \\c suppresses newline\n");
68 #endif /* CFG_CMD_ECHO */
71 * Use puts() instead of printf() to avoid printf buffer overflow
72 * for long help messages
74 int do_help(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]){
78 if(argc == 1){ /*show list of commands */
80 int cmd_items = &__u_boot_cmd_end - &__u_boot_cmd_start; /* pointer arith! */
81 cmd_tbl_t *cmd_array[cmd_items];
82 int i, j, swaps, max_len = 0;
84 /* Make array of commands from .uboot_cmd section */
85 cmdtp = &__u_boot_cmd_start;
87 for(i = 0; i < cmd_items; i++){
88 cmd_array[i] = cmdtp++;
91 /* Sort command list (trivial bubble sort) */
92 for(i = cmd_items - 1; i > 0; --i){
94 for(j = 0; j < i; ++j){
96 const char *name = cmd_array[j]->name;
98 if(strlen(name) >= max_len){
99 max_len = strlen(name);
102 if(strcmp(cmd_array[j]->name, cmd_array[j + 1]->name) > 0){
105 cmd_array[j] = cmd_array[j + 1];
106 cmd_array[j + 1] = tmp;
118 /* print short help (usage) */
119 for(i = 0; i < cmd_items; i++){
120 const char *usage = cmd_array[i]->usage;
121 const char *name = cmd_array[i]->name;
123 /* allow user abort */
131 /* print aligned command name and usage */
132 printf("%-*s - ", max_len, name);
141 * command help (long version)
143 for(i = 1; i < argc; ++i){
144 if((cmdtp = find_cmd(argv[i])) != NULL){
146 /* found - print (long) help info */
153 puts("- there is no help for this command\n");
158 #else /* no long help available */
162 #endif /* CFG_LONGHELP */
164 printf("Unknown command '%s' - try 'help' without arguments\n\n", argv[i]);
172 U_BOOT_CMD(help, CFG_MAXARGS, 1, do_help, "print embedded help\n",
174 "\t- show help information (for 'command')\n"
175 "\twithout arguments, it prints a short usage message for available commands.\n");
177 /* This do not ust the U_BOOT_CMD macro as ? can't be used in symbol names */
179 cmd_tbl_t __u_boot_cmd_question_mark Struct_Section = {"?", CFG_MAXARGS, 1, do_help, "alias for 'help'\n", NULL};
181 cmd_tbl_t __u_boot_cmd_question_mark Struct_Section = {"?", CFG_MAXARGS, 1, do_help, "alias for 'help'\n"};
182 #endif /* CFG_LONGHELP */
184 /***************************************************************************
185 * find command table entry for a command
187 cmd_tbl_t *find_cmd(const char *cmd){
189 cmd_tbl_t *cmdtp_temp = &__u_boot_cmd_start; /*Init value */
195 * Some commands allow length modifiers (like "cp.b");
196 * compare command name only until first dot.
198 len = ((p = strchr(cmd, '.')) == NULL) ? strlen(cmd) : (p - cmd);
200 for(cmdtp = &__u_boot_cmd_start; cmdtp != &__u_boot_cmd_end; cmdtp++){
201 if(strncmp(cmd, cmdtp->name, len) == 0){
202 if(len == strlen(cmdtp->name)){
203 return(cmdtp); /* full match */
206 cmdtp_temp = cmdtp; /* abbreviated command ? */
210 if(n_found == 1){ /* exactly one match */
214 return(NULL); /* not found or ambiguous command */