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 #include <environment.h>
36 #include <linux/utsrelease.h>
38 const char version_string
[] =
39 "U-Boot " UTS_RELEASE
" (" __DATE__
" - " __TIME__
")";
41 LIST_HEAD(command_list
);
42 EXPORT_SYMBOL(command_list
);
44 #ifdef CONFIG_SHELL_HUSH
46 static int do_exit (cmd_tbl_t
*cmdtp
, int argc
, char *argv
[])
52 r
= simple_strtoul(argv
[1], NULL
, 0);
57 U_BOOT_CMD_START(exit
)
60 .usage
= "exit script",
65 void u_boot_cmd_usage(cmd_tbl_t
*cmdtp
)
67 #ifdef CONFIG_LONGHELP
68 /* found - print (long) help info */
74 puts ("- No help available.\n");
77 #else /* no long help available */
82 #endif /* CONFIG_LONGHELP */
84 EXPORT_SYMBOL(u_boot_cmd_usage
);
86 static int compare(struct list_head
*a
, struct list_head
*b
)
88 char *na
= (char*)list_entry(a
, cmd_tbl_t
, list
)->name
;
89 char *nb
= (char*)list_entry(b
, cmd_tbl_t
, list
)->name
;
91 return strcmp(na
, nb
);
94 int register_command(cmd_tbl_t
*cmd
)
97 * We do not check if the command already exists.
98 * This allows us to overwrite a builtin command
102 debug("register command %s\n", cmd
->name
);
104 list_add_sort(&cmd
->list
, &command_list
, compare
);
107 char **aliases
= (char**)cmd
->aliases
;
109 char *usage
= "alias for ";
110 cmd_tbl_t
*c
= xzalloc(sizeof(cmd_tbl_t
));
112 memcpy(c
, cmd
, sizeof(cmd_tbl_t
));
115 c
->usage
= xmalloc(strlen(usage
) + strlen(cmd
->name
) + 1);
116 sprintf((char*)c
->usage
, "%s%s", usage
, cmd
->name
);
128 EXPORT_SYMBOL(register_command
);
131 * find command table entry for a command
133 cmd_tbl_t
*find_cmd (const char *cmd
)
136 cmd_tbl_t
*cmdtp_temp
= &__u_boot_cmd_start
; /*Init value */
141 cmdtp
= list_entry(&command_list
, cmd_tbl_t
, list
);
143 for_each_command(cmdtp
) {
144 if (strncmp (cmd
, cmdtp
->name
, len
) == 0) {
145 if (len
== strlen (cmdtp
->name
))
146 return cmdtp
; /* full match */
148 cmdtp_temp
= cmdtp
; /* abbreviated command ? */
153 if (n_found
== 1) { /* exactly one match */
157 return NULL
; /* not found or ambiguous command */
161 * Put all commands into a linked list. Without module support we could use
162 * the raw command array, but with module support a list is easier to handle.
163 * It does not create significant overhead so do it also without module
166 static int init_command_list(void)
170 for (cmdtp
= &__u_boot_cmd_start
;
171 cmdtp
!= &__u_boot_cmd_end
;
173 register_command(cmdtp
);
178 late_initcall(init_command_list
);