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
32 do_version (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
34 extern char version_string[];
35 printf ("\n%s\n", version_string);
40 version, 1, 1, do_version,
41 "version - print monitor version\n",
46 do_echo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
50 for (i = 1; i < argc; i++) {
55 while ((c = *p++) != '\0') {
56 if (c == '\\' && *p == 'c') {
71 echo, CFG_MAXARGS, 1, do_echo,
72 "echo - echo args to console\n",
74 " - echo args to console; \\c suppresses newline\n"
78 * Use puts() instead of printf() to avoid printf buffer overflow
79 * for long help messages
81 int do_help (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
86 if (argc == 1) { /*show list of commands */
88 int cmd_items = &__u_boot_cmd_end -
89 &__u_boot_cmd_start; /* pointer arith! */
90 cmd_tbl_t *cmd_array[cmd_items];
93 /* Make array of commands from .uboot_cmd section */
94 cmdtp = &__u_boot_cmd_start;
95 for (i = 0; i < cmd_items; i++) {
96 cmd_array[i] = cmdtp++;
99 /* Sort command list (trivial bubble sort) */
100 for (i = cmd_items - 1; i > 0; --i) {
102 for (j = 0; j < i; ++j) {
103 if (strcmp (cmd_array[j]->name,
104 cmd_array[j + 1]->name) > 0) {
107 cmd_array[j] = cmd_array[j + 1];
108 cmd_array[j + 1] = tmp;
116 /* print short help (usage) */
117 for (i = 0; i < cmd_items; i++) {
118 const char *usage = cmd_array[i]->usage;
120 /* allow user abort */
130 * command help (long version)
132 for (i = 1; i < argc; ++i) {
133 if ((cmdtp = find_cmd (argv[i])) != NULL) {
135 /* found - print (long) help info */
141 puts ("- No help available.\n");
145 #else /* no long help available */
148 #endif /* CFG_LONGHELP */
150 printf ("Unknown command '%s' - try 'help'"
151 " without arguments for list of all"
152 " known commands\n\n", argv[i]
162 help, CFG_MAXARGS, 1, do_help,
163 "help - print online help\n",
165 " - show help information (for 'command')\n"
166 "'help' prints online help for the monitor commands.\n\n"
167 "Without arguments, it prints a short usage message for all commands.\n\n"
168 "To get detailed help information for specific commands you can type\n"
169 "'help' with one or more command names as arguments.\n"
172 /* This do not ust the U_BOOT_CMD macro as ? can't be used in symbol names */
174 cmd_tbl_t __u_boot_cmd_question_mark Struct_Section = {
175 "?", CFG_MAXARGS, 1, do_help,
176 "? - alias for 'help'\n",
180 cmd_tbl_t __u_boot_cmd_question_mark Struct_Section = {
181 "?", CFG_MAXARGS, 1, do_help,
182 "? - alias for 'help'\n"
184 #endif /* CFG_LONGHELP */
186 /***************************************************************************
187 * find command table entry for a command
189 cmd_tbl_t *find_cmd (const char *cmd)
192 cmd_tbl_t *cmdtp_temp = &__u_boot_cmd_start; /*Init value */
198 * Some commands allow length modifiers (like "cp.b");
199 * compare command name only until first dot.
201 len = ((p = strchr(cmd, '.')) == NULL) ? strlen (cmd) : (p - cmd);
203 for (cmdtp = &__u_boot_cmd_start;
204 cmdtp != &__u_boot_cmd_end;
206 if (strncmp (cmd, cmdtp->name, len) == 0) {
207 if (len == strlen (cmdtp->name))
208 return cmdtp; /* full match */
210 cmdtp_temp = cmdtp; /* abbreviated command ? */
214 if (n_found == 1) { /* exactly one match */
218 return NULL; /* not found or ambiguous command */