2002-10-20 03:42:10 +08:00
|
|
|
/*
|
2003-06-28 05:31:46 +08:00
|
|
|
* (C) Copyright 2000-2003
|
2002-10-20 03:42:10 +08:00
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
|
|
|
*
|
|
|
|
* See file CREDITS for list of people who contributed to this
|
|
|
|
* project.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Command Processor Table
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
|
|
|
|
|
|
|
int
|
|
|
|
do_version (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
|
|
|
|
{
|
|
|
|
extern char version_string[];
|
|
|
|
printf ("\n%s\n", version_string);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-07-02 05:06:45 +08:00
|
|
|
U_BOOT_CMD(
|
|
|
|
version, 1, 1, do_version,
|
2003-06-30 05:03:46 +08:00
|
|
|
"version - print monitor version\n",
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
|
2002-10-20 03:42:10 +08:00
|
|
|
int
|
|
|
|
do_echo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int i, putnl = 1;
|
|
|
|
|
|
|
|
for (i = 1; i < argc; i++) {
|
|
|
|
char *p = argv[i], c;
|
|
|
|
|
|
|
|
if (i > 1)
|
|
|
|
putc(' ');
|
2003-06-16 06:40:42 +08:00
|
|
|
while ((c = *p++) != '\0') {
|
2002-10-20 03:42:10 +08:00
|
|
|
if (c == '\\' && *p == 'c') {
|
|
|
|
putnl = 0;
|
|
|
|
p++;
|
2003-06-16 06:40:42 +08:00
|
|
|
} else {
|
2002-10-20 03:42:10 +08:00
|
|
|
putc(c);
|
2003-06-16 06:40:42 +08:00
|
|
|
}
|
|
|
|
}
|
2002-10-20 03:42:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (putnl)
|
|
|
|
putc('\n');
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-07-02 05:06:45 +08:00
|
|
|
U_BOOT_CMD(
|
|
|
|
echo, CFG_MAXARGS, 1, do_echo,
|
2003-06-30 05:03:46 +08:00
|
|
|
"echo - echo args to console\n",
|
|
|
|
"[args..]\n"
|
|
|
|
" - echo args to console; \\c suppresses newline\n"
|
|
|
|
);
|
|
|
|
|
2002-10-20 03:42:10 +08:00
|
|
|
/*
|
|
|
|
* Use puts() instead of printf() to avoid printf buffer overflow
|
|
|
|
* for long help messages
|
|
|
|
*/
|
2003-06-28 05:31:46 +08:00
|
|
|
int do_help (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
|
2002-10-20 03:42:10 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int rcode = 0;
|
|
|
|
|
2003-06-28 05:31:46 +08:00
|
|
|
if (argc == 1) { /*show list of commands */
|
|
|
|
|
2003-06-29 07:11:04 +08:00
|
|
|
int cmd_items = &__u_boot_cmd_end -
|
|
|
|
&__u_boot_cmd_start; /* pointer arith! */
|
|
|
|
cmd_tbl_t *cmd_array[cmd_items];
|
|
|
|
int i, j, swaps;
|
|
|
|
|
|
|
|
/* Make array of commands from .uboot_cmd section */
|
|
|
|
cmdtp = &__u_boot_cmd_start;
|
|
|
|
for (i = 0; i < cmd_items; i++) {
|
|
|
|
cmd_array[i] = cmdtp++;
|
2003-06-28 05:31:46 +08:00
|
|
|
}
|
|
|
|
|
2003-06-29 07:11:04 +08:00
|
|
|
/* Sort command list (trivial bubble sort) */
|
|
|
|
for (i = cmd_items - 1; i > 0; --i) {
|
|
|
|
swaps = 0;
|
|
|
|
for (j = 0; j < i; ++j) {
|
|
|
|
if (strcmp (cmd_array[j]->name,
|
|
|
|
cmd_array[j + 1]->name) > 0) {
|
|
|
|
cmd_tbl_t *tmp;
|
|
|
|
tmp = cmd_array[j];
|
|
|
|
cmd_array[j] = cmd_array[j + 1];
|
|
|
|
cmd_array[j + 1] = tmp;
|
|
|
|
++swaps;
|
|
|
|
}
|
2003-06-28 05:31:46 +08:00
|
|
|
}
|
2003-06-29 07:11:04 +08:00
|
|
|
if (!swaps)
|
|
|
|
break;
|
2003-06-28 05:31:46 +08:00
|
|
|
}
|
2002-10-20 03:42:10 +08:00
|
|
|
|
2003-06-28 05:31:46 +08:00
|
|
|
/* print short help (usage) */
|
2003-06-29 07:11:04 +08:00
|
|
|
for (i = 0; i < cmd_items; i++) {
|
|
|
|
const char *usage = cmd_array[i]->usage;
|
|
|
|
|
2002-10-20 03:42:10 +08:00
|
|
|
/* allow user abort */
|
2003-06-28 05:31:46 +08:00
|
|
|
if (ctrlc ())
|
2002-10-20 03:42:10 +08:00
|
|
|
return 1;
|
2003-06-29 07:11:04 +08:00
|
|
|
if (usage == NULL)
|
2002-10-20 03:42:10 +08:00
|
|
|
continue;
|
2003-06-29 07:11:04 +08:00
|
|
|
puts (usage);
|
2002-10-20 03:42:10 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* command help (long version)
|
|
|
|
*/
|
2003-06-28 05:31:46 +08:00
|
|
|
for (i = 1; i < argc; ++i) {
|
|
|
|
if ((cmdtp = find_cmd (argv[i])) != NULL) {
|
2002-10-20 03:42:10 +08:00
|
|
|
#ifdef CFG_LONGHELP
|
|
|
|
/* found - print (long) help info */
|
|
|
|
puts (cmdtp->name);
|
|
|
|
putc (' ');
|
|
|
|
if (cmdtp->help) {
|
|
|
|
puts (cmdtp->help);
|
|
|
|
} else {
|
|
|
|
puts ("- No help available.\n");
|
|
|
|
rcode = 1;
|
|
|
|
}
|
|
|
|
putc ('\n');
|
|
|
|
#else /* no long help available */
|
|
|
|
if (cmdtp->usage)
|
|
|
|
puts (cmdtp->usage);
|
|
|
|
#endif /* CFG_LONGHELP */
|
2003-06-16 06:40:42 +08:00
|
|
|
} else {
|
2002-10-20 03:42:10 +08:00
|
|
|
printf ("Unknown command '%s' - try 'help'"
|
|
|
|
" without arguments for list of all"
|
2003-06-28 05:31:46 +08:00
|
|
|
" known commands\n\n", argv[i]
|
|
|
|
);
|
2002-10-20 03:42:10 +08:00
|
|
|
rcode = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rcode;
|
|
|
|
}
|
|
|
|
|
2003-06-28 05:31:46 +08:00
|
|
|
|
2003-07-02 05:06:45 +08:00
|
|
|
U_BOOT_CMD(
|
|
|
|
help, CFG_MAXARGS, 1, do_help,
|
2003-06-28 05:31:46 +08:00
|
|
|
"help - print online help\n",
|
|
|
|
"[command ...]\n"
|
|
|
|
" - show help information (for 'command')\n"
|
|
|
|
"'help' prints online help for the monitor commands.\n\n"
|
|
|
|
"Without arguments, it prints a short usage message for all commands.\n\n"
|
|
|
|
"To get detailed help information for specific commands you can type\n"
|
|
|
|
"'help' with one or more command names as arguments.\n"
|
|
|
|
);
|
|
|
|
|
2003-07-02 05:06:45 +08:00
|
|
|
/* This do not ust the U_BOOT_CMD macro as ? can't be used in symbol names */
|
|
|
|
#ifdef CFG_LONGHELP
|
|
|
|
cmd_tbl_t __u_boot_cmd_question_mark Struct_Section = {
|
2003-06-28 05:31:46 +08:00
|
|
|
"?", CFG_MAXARGS, 1, do_help,
|
|
|
|
"? - alias for 'help'\n",
|
|
|
|
NULL
|
2003-07-02 05:06:45 +08:00
|
|
|
};
|
|
|
|
#else
|
|
|
|
cmd_tbl_t __u_boot_cmd_question_mark Struct_Section = {
|
|
|
|
"?", CFG_MAXARGS, 1, do_help,
|
|
|
|
"? - alias for 'help'\n"
|
|
|
|
};
|
|
|
|
#endif /* CFG_LONGHELP */
|
2003-06-28 05:31:46 +08:00
|
|
|
|
2002-10-20 03:42:10 +08:00
|
|
|
/***************************************************************************
|
|
|
|
* find command table entry for a command
|
|
|
|
*/
|
2003-06-28 05:31:46 +08:00
|
|
|
cmd_tbl_t *find_cmd (const char *cmd)
|
2002-10-20 03:42:10 +08:00
|
|
|
{
|
|
|
|
cmd_tbl_t *cmdtp;
|
2003-06-28 05:31:46 +08:00
|
|
|
cmd_tbl_t *cmdtp_temp = &__u_boot_cmd_start; /*Init value */
|
2003-06-29 07:11:04 +08:00
|
|
|
const char *p;
|
|
|
|
int len;
|
|
|
|
int n_found = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Some commands allow length modifiers (like "cp.b");
|
|
|
|
* compare command name only until first dot.
|
|
|
|
*/
|
|
|
|
len = ((p = strchr(cmd, '.')) == NULL) ? strlen (cmd) : (p - cmd);
|
|
|
|
|
|
|
|
for (cmdtp = &__u_boot_cmd_start;
|
|
|
|
cmdtp != &__u_boot_cmd_end;
|
|
|
|
cmdtp++) {
|
|
|
|
if (strncmp (cmd, cmdtp->name, len) == 0) {
|
|
|
|
if (len == strlen (cmdtp->name))
|
|
|
|
return cmdtp; /* full match */
|
|
|
|
|
|
|
|
cmdtp_temp = cmdtp; /* abbreviated command ? */
|
|
|
|
n_found++;
|
|
|
|
}
|
2002-10-20 03:42:10 +08:00
|
|
|
}
|
2003-06-29 07:11:04 +08:00
|
|
|
if (n_found == 1) { /* exactly one match */
|
2003-06-28 05:31:46 +08:00
|
|
|
return cmdtp_temp;
|
2003-06-29 07:11:04 +08:00
|
|
|
}
|
2002-10-20 03:42:10 +08:00
|
|
|
|
2003-06-29 07:11:04 +08:00
|
|
|
return NULL; /* not found or ambiguous command */
|
2003-06-28 05:31:46 +08:00
|
|
|
}
|