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 #ifdef CFG_HUSH_PARSER
72 int do_test(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]){
74 int left, adv, expr, last_expr, neg, last_cmp;
85 printf(" %s", argv[left++]);
90 left = argc - 1; ap = argv + 1;
92 if(left > 0 && strcmp(ap[0], "!") == 0){
106 if(strcmp(ap[0], "-o") == 0 || strcmp(ap[0], "-a") == 0){
108 } else if(strcmp(ap[0], "-z") == 0 || strcmp(ap[0], "-n") == 0){
120 if (strcmp(ap[0], "-o") == 0){
123 } else if(strcmp(ap[0], "-a") == 0){
133 if (strcmp(ap[0], "-z") == 0){
134 expr = strlen(ap[1]) == 0 ? 1 : 0;
135 } else if(strcmp(ap[0], "-n") == 0){
136 expr = strlen(ap[1]) == 0 ? 0 : 1;
143 expr = last_expr || expr;
144 } else if(last_cmp == 1){
145 expr = last_expr && expr;
151 if(strcmp(ap[1], "=") == 0){
152 expr = strcmp(ap[0], ap[2]) == 0;
153 } else if(strcmp(ap[1], "!=") == 0){
154 expr = strcmp(ap[0], ap[2]) != 0;
155 } else if(strcmp(ap[1], ">") == 0){
156 expr = strcmp(ap[0], ap[2]) > 0;
157 } else if(strcmp(ap[1], "<") == 0){
158 expr = strcmp(ap[0], ap[2]) < 0;
159 } else if(strcmp(ap[1], "-eq") == 0){
160 expr = simple_strtol(ap[0], NULL, 10) == simple_strtol(ap[2], NULL, 10);
161 } else if(strcmp(ap[1], "-ne") == 0){
162 expr = simple_strtol(ap[0], NULL, 10) != simple_strtol(ap[2], NULL, 10);
163 } else if(strcmp(ap[1], "-lt") == 0){
164 expr = simple_strtol(ap[0], NULL, 10) < simple_strtol(ap[2], NULL, 10);
165 } else if(strcmp(ap[1], "-le") == 0){
166 expr = simple_strtol(ap[0], NULL, 10) <= simple_strtol(ap[2], NULL, 10);
167 } else if(strcmp(ap[1], "-gt") == 0){
168 expr = simple_strtol(ap[0], NULL, 10) > simple_strtol(ap[2], NULL, 10);
169 } else if(strcmp(ap[1], "-ge") == 0){
170 expr = simple_strtol(ap[0], NULL, 10) >= simple_strtol(ap[2], NULL, 10);
177 expr = last_expr || expr;
178 } else if(last_cmp == 1){
179 expr = last_expr && expr;
184 ap += adv; left -= adv;
194 printf(": returns %d\n", expr);
200 U_BOOT_CMD(test, CFG_MAXARGS, 1, do_test, "minimal test like /bin/sh\n", "[args..]\n"
201 "\t- test functionality\n");
203 int do_exit(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]){
207 r = simple_strtoul(argv[1], NULL, 10);
213 U_BOOT_CMD(exit, 2, 1, do_exit, "exit script\n", "\n\t- exit functionality\n");
214 #endif /* CFG_HUSH_PARSER */
217 * Use puts() instead of printf() to avoid printf buffer overflow
218 * for long help messages
220 int do_help(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]){
224 if(argc == 1){ /*show list of commands */
226 int cmd_items = &__u_boot_cmd_end - &__u_boot_cmd_start; /* pointer arith! */
227 cmd_tbl_t *cmd_array[cmd_items];
228 int i, j, swaps, max_len = 0;
230 /* Make array of commands from .uboot_cmd section */
231 cmdtp = &__u_boot_cmd_start;
233 for(i = 0; i < cmd_items; i++){
234 cmd_array[i] = cmdtp++;
237 /* Sort command list (trivial bubble sort) */
238 for(i = cmd_items - 1; i > 0; --i){
240 for(j = 0; j < i; ++j){
242 const char *name = cmd_array[j]->name;
244 if(strlen(name) >= max_len){
245 max_len = strlen(name);
248 if(strcmp(cmd_array[j]->name, cmd_array[j + 1]->name) > 0){
251 cmd_array[j] = cmd_array[j + 1];
252 cmd_array[j + 1] = tmp;
262 /* print short help (usage) */
263 for(i = 0; i < cmd_items; i++){
264 const char *usage = cmd_array[i]->usage;
265 const char *name = cmd_array[i]->name;
267 /* allow user abort */
275 /* print aligned command name and usage */
276 printf("%-*s - ", max_len, name);
285 * command help (long version)
287 for(i = 1; i < argc; ++i){
288 if((cmdtp = find_cmd(argv[i])) != NULL){
290 /* found - print (long) help info */
297 puts("- there is no help for this command\n");
302 #else /* no long help available */
306 #endif /* CFG_LONGHELP */
308 printf("Unknown command '%s' - try 'help' without arguments\n\n", argv[i]);
316 U_BOOT_CMD(help, CFG_MAXARGS, 1, do_help, "print embedded help\n",
318 "\t- show help information (for 'command')\n"
319 "\twithout arguments, it prints a short usage message for available commands.\n");
321 /* This do not ust the U_BOOT_CMD macro as ? can't be used in symbol names */
323 cmd_tbl_t __u_boot_cmd_question_mark Struct_Section = {"?", CFG_MAXARGS, 1, do_help, "alias for 'help'\n", NULL};
325 cmd_tbl_t __u_boot_cmd_question_mark Struct_Section = {"?", CFG_MAXARGS, 1, do_help, "alias for 'help'\n"};
326 #endif /* CFG_LONGHELP */
328 /***************************************************************************
329 * find command table entry for a command
331 cmd_tbl_t *find_cmd(const char *cmd){
333 cmd_tbl_t *cmdtp_temp = &__u_boot_cmd_start; /*Init value */
339 * Some commands allow length modifiers (like "cp.b");
340 * compare command name only until first dot.
342 len = ((p = strchr(cmd, '.')) == NULL) ? strlen(cmd) : (p - cmd);
344 for(cmdtp = &__u_boot_cmd_start; cmdtp != &__u_boot_cmd_end; cmdtp++){
345 if(strncmp(cmd, cmdtp->name, len) == 0){
346 if(len == strlen(cmdtp->name)){
347 return(cmdtp); /* full match */
350 cmdtp_temp = cmdtp; /* abbreviated command ? */
354 if(n_found == 1){ /* exactly one match */
358 return(NULL); /* not found or ambiguous command */