2 * (C) Copyright 2000-2003
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * SPDX-License-Identifier: GPL-2.0
8 /* Command Processor Table */
12 void print_cmd_help(cmd_tbl_t *cmdtp)
15 if (cmdtp->help != NULL) {
16 printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->help);
18 printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->usage);
21 printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->usage);
25 int do_version(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
27 extern char version_string[];
29 puts("Version and build date:\n");
30 printf(" %s\n " __DATE__ ", " __TIME__ "\n\n", version_string);
32 puts("Modification by:\n");
33 puts(" Piotr Dymacz <piotr@dymacz.pl>\n");
34 puts(" https://github.com/pepe2k/u-boot_mod\n\n");
39 U_BOOT_CMD(version, 1, 1, do_version, "print U-Boot version\n", NULL);
41 #if (CONFIG_COMMANDS & CFG_CMD_ECHO)
42 int do_echo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
46 for (i = 1; i < argc; i++) {
52 while ((c = *p++) != '\0') {
53 if (c == '\\' && *p == 'c') {
68 U_BOOT_CMD(echo, CFG_MAXARGS, 1, do_echo,
69 "echo args to console\n", "[args..]\n"
70 "\t- echo args to console; \\c suppresses newline\n");
71 #endif /* CFG_CMD_ECHO */
73 #ifdef CFG_HUSH_PARSER
74 int do_test(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
77 int adv, expr, last_expr, last_cmp, left, neg;
87 if (left > 0 && strcmp(ap[0], "!") == 0) {
100 if (strcmp(ap[0], "-o") == 0 ||
101 strcmp(ap[0], "-a") == 0) {
103 } else if (strcmp(ap[0], "-z") == 0 ||
104 strcmp(ap[0], "-n") == 0) {
116 if (strcmp(ap[0], "-o") == 0) {
119 } else if (strcmp(ap[0], "-a") == 0) {
129 if (strcmp(ap[0], "-z") == 0) {
130 expr = strlen(ap[1]) == 0 ? 1 : 0;
131 } else if (strcmp(ap[0], "-n") == 0) {
132 expr = strlen(ap[1]) == 0 ? 0 : 1;
139 expr = last_expr || expr;
140 } else if (last_cmp == 1) {
141 expr = last_expr && expr;
148 if (strcmp(ap[1], "=") == 0) {
149 expr = strcmp(ap[0], ap[2]) == 0;
150 } else if (strcmp(ap[1], "!=") == 0) {
151 expr = strcmp(ap[0], ap[2]) != 0;
152 } else if (strcmp(ap[1], ">") == 0) {
153 expr = strcmp(ap[0], ap[2]) > 0;
154 } else if (strcmp(ap[1], "<") == 0) {
155 expr = strcmp(ap[0], ap[2]) < 0;
156 } else if (strcmp(ap[1], "-eq") == 0) {
157 expr = simple_strtol(ap[0], NULL, 10)
158 == simple_strtol(ap[2], NULL, 10);
159 } else if (strcmp(ap[1], "-ne") == 0) {
160 expr = simple_strtol(ap[0], NULL, 10)
161 != simple_strtol(ap[2], NULL, 10);
162 } else if (strcmp(ap[1], "-lt") == 0) {
163 expr = simple_strtol(ap[0], NULL, 10)
164 < simple_strtol(ap[2], NULL, 10);
165 } else if (strcmp(ap[1], "-le") == 0) {
166 expr = simple_strtol(ap[0], NULL, 10)
167 <= simple_strtol(ap[2], NULL, 10);
168 } else if (strcmp(ap[1], "-gt") == 0) {
169 expr = simple_strtol(ap[0], NULL, 10)
170 > simple_strtol(ap[2], NULL, 10);
171 } else if (strcmp(ap[1], "-ge") == 0) {
172 expr = simple_strtol(ap[0], NULL, 10)
173 >= simple_strtol(ap[2], NULL, 10);
180 expr = last_expr || expr;
181 } else if (last_cmp == 1) {
182 expr = last_expr && expr;
188 ap += adv; left -= adv;
199 U_BOOT_CMD(test, CFG_MAXARGS, 1, do_test,
200 "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[])
208 r = simple_strtoul(argv[1], NULL, 10);
213 U_BOOT_CMD(exit, 2, 1, do_exit,
214 "exit script\n", "\n\t- exit functionality\n");
215 #endif /* CFG_HUSH_PARSER */
218 * Use puts() instead of printf() to avoid printf buffer overflow
219 * for long help messages
221 int do_help(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
226 /* Show list of commands */
229 int cmd_items = &__u_boot_cmd_end - &__u_boot_cmd_start;
231 cmd_tbl_t *cmd_array[cmd_items];
232 int i, j, swaps, max_len = 0;
234 /* Make array of commands from .uboot_cmd section */
235 cmdtp = &__u_boot_cmd_start;
237 for (i = 0; i < cmd_items; i++) {
238 cmd_array[i] = cmdtp++;
241 /* Sort command list (trivial bubble sort) */
242 for (i = cmd_items - 1; i > 0; --i) {
244 for (j = 0; j < i; ++j) {
245 const char *name = cmd_array[j]->name;
247 if (strlen(name) >= max_len)
248 max_len = strlen(name);
250 if (strcmp(cmd_array[j]->name,
251 cmd_array[j + 1]->name) > 0) {
254 cmd_array[j] = cmd_array[j + 1];
255 cmd_array[j + 1] = tmp;
264 /* Print short help (usage) */
265 for (i = 0; i < cmd_items; i++) {
266 const char *usage = cmd_array[i]->usage;
267 const char *name = cmd_array[i]->name;
269 /* Allow user abort */
276 /* Print aligned command name and usage */
277 printf("%-*s - ", max_len, name);
285 /* Command help (long version) */
286 for (i = 1; i < argc; ++i) {
287 if ((cmdtp = find_cmd(argv[i])) != NULL) {
289 /* Found - print (long) help info */
296 puts("- there is no help for this command\n");
304 #endif /* CFG_LONGHELP */
306 printf("Unknown command '%s' - try 'help' without arguments\n\n", argv[i]);
314 U_BOOT_CMD(help, CFG_MAXARGS, 1, do_help,
315 "print embedded help\n", "[command ...]\n"
316 "\t- show help information for 'command' or short usage of all commands\n");
318 /* This do not ust the U_BOOT_CMD macro as ? can't be used in symbol names */
320 cmd_tbl_t __u_boot_cmd_question_mark Struct_Section = {"?", CFG_MAXARGS, 1, do_help, "alias for 'help'\n", NULL};
322 cmd_tbl_t __u_boot_cmd_question_mark Struct_Section = {"?", CFG_MAXARGS, 1, do_help, "alias for 'help'\n"};
323 #endif /* CFG_LONGHELP */
326 * Find command table entry for a command
328 cmd_tbl_t *find_cmd(const char *cmd)
334 cmd_tbl_t *cmdtp_temp = &__u_boot_cmd_start; /*Init value */
337 * Some commands allow length modifiers (like "cp.b");
338 * compare command name only until first dot.
340 len = ((p = strchr(cmd, '.')) == NULL) ? strlen(cmd) : (p - cmd);
342 for (cmdtp = &__u_boot_cmd_start; cmdtp != &__u_boot_cmd_end; cmdtp++) {
343 if (strncmp(cmd, cmdtp->name, len) == 0) {
345 if (len == strlen(cmdtp->name))
348 /* Abbreviated command ? */
354 /* Exactly one match */
358 /* Not found or ambiguous command */