blob: 2433a89e0a8e10f3098eb453e25db33f574436f5 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenk5dfa25f2002-10-19 19:42:10 +00002/*
Detlev Zundel5e6c06b2009-03-25 17:27:52 +01003 * (C) Copyright 2000-2009
wdenk5dfa25f2002-10-19 19:42:10 +00004 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
wdenk5dfa25f2002-10-19 19:42:10 +00005 */
6
7/*
8 * Command Processor Table
9 */
10
11#include <common.h>
12#include <command.h>
Simon Glassa73bda42015-11-08 23:47:45 -070013#include <console.h>
Jason Hobbscafa1aa2011-08-23 11:06:54 +000014#include <linux/ctype.h>
wdenk5dfa25f2002-10-19 19:42:10 +000015
wdenk5dfa25f2002-10-19 19:42:10 +000016/*
17 * Use puts() instead of printf() to avoid printf buffer overflow
18 * for long help messages
19 */
Detlev Zundel5e6c06b2009-03-25 17:27:52 +010020
Masahiro Yamada682195e2014-10-23 17:27:30 +090021int _do_help(cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t *cmdtp, int flag,
22 int argc, char * const argv[])
wdenk5dfa25f2002-10-19 19:42:10 +000023{
24 int i;
25 int rcode = 0;
26
Masahiro Yamada682195e2014-10-23 17:27:30 +090027 if (argc == 1) { /* show list of commands */
Anatolij Gustschin9ac7cc22012-11-08 12:40:17 +010028 cmd_tbl_t *cmd_array[cmd_items];
wdenk3086a972003-06-28 23:11:04 +000029 int i, j, swaps;
wdenk57b2d802003-06-27 21:31:46 +000030
wdenk3086a972003-06-28 23:11:04 +000031 /* Make array of commands from .uboot_cmd section */
Detlev Zundel5e6c06b2009-03-25 17:27:52 +010032 cmdtp = cmd_start;
wdenk3086a972003-06-28 23:11:04 +000033 for (i = 0; i < cmd_items; i++) {
34 cmd_array[i] = cmdtp++;
wdenk57b2d802003-06-27 21:31:46 +000035 }
wdenk57b2d802003-06-27 21:31:46 +000036
wdenk3086a972003-06-28 23:11:04 +000037 /* Sort command list (trivial bubble sort) */
38 for (i = cmd_items - 1; i > 0; --i) {
39 swaps = 0;
40 for (j = 0; j < i; ++j) {
Masahiro Yamada682195e2014-10-23 17:27:30 +090041 if (strcmp(cmd_array[j]->name,
42 cmd_array[j + 1]->name) > 0) {
wdenk3086a972003-06-28 23:11:04 +000043 cmd_tbl_t *tmp;
44 tmp = cmd_array[j];
45 cmd_array[j] = cmd_array[j + 1];
46 cmd_array[j + 1] = tmp;
47 ++swaps;
48 }
wdenk57b2d802003-06-27 21:31:46 +000049 }
wdenk3086a972003-06-28 23:11:04 +000050 if (!swaps)
51 break;
wdenk57b2d802003-06-27 21:31:46 +000052 }
53
54 /* print short help (usage) */
wdenk3086a972003-06-28 23:11:04 +000055 for (i = 0; i < cmd_items; i++) {
56 const char *usage = cmd_array[i]->usage;
57
wdenk5dfa25f2002-10-19 19:42:10 +000058 /* allow user abort */
Masahiro Yamada682195e2014-10-23 17:27:30 +090059 if (ctrlc())
wdenk5dfa25f2002-10-19 19:42:10 +000060 return 1;
wdenk3086a972003-06-28 23:11:04 +000061 if (usage == NULL)
wdenk5dfa25f2002-10-19 19:42:10 +000062 continue;
Peter Tyserdfb72b82009-01-27 18:03:12 -060063 printf("%-*s- %s\n", CONFIG_SYS_HELP_CMD_WIDTH,
64 cmd_array[i]->name, usage);
wdenk5dfa25f2002-10-19 19:42:10 +000065 }
wdenk5dfa25f2002-10-19 19:42:10 +000066 return 0;
67 }
wdenk5dfa25f2002-10-19 19:42:10 +000068 /*
69 * command help (long version)
70 */
wdenk57b2d802003-06-27 21:31:46 +000071 for (i = 1; i < argc; ++i) {
Masahiro Yamada682195e2014-10-23 17:27:30 +090072 cmdtp = find_cmd_tbl(argv[i], cmd_start, cmd_items);
73 if (cmdtp != NULL) {
Wolfgang Denk9dd775b2009-05-24 19:17:29 +020074 rcode |= cmd_usage(cmdtp);
wdenk7a428cc2003-06-15 22:40:42 +000075 } else {
Masahiro Yamada682195e2014-10-23 17:27:30 +090076 printf("Unknown command '%s' - try 'help' without arguments for list of all known commands\n\n",
77 argv[i]);
wdenk5dfa25f2002-10-19 19:42:10 +000078 rcode = 1;
79 }
80 }
81 return rcode;
82}
83
Masahiro Yamada682195e2014-10-23 17:27:30 +090084/* find command table entry for a command */
85cmd_tbl_t *find_cmd_tbl(const char *cmd, cmd_tbl_t *table, int table_len)
wdenk5dfa25f2002-10-19 19:42:10 +000086{
Simon Glass4ef90b72016-03-19 02:18:38 -060087#ifdef CONFIG_CMDLINE
wdenk5dfa25f2002-10-19 19:42:10 +000088 cmd_tbl_t *cmdtp;
Masahiro Yamada682195e2014-10-23 17:27:30 +090089 cmd_tbl_t *cmdtp_temp = table; /* Init value */
wdenk3086a972003-06-28 23:11:04 +000090 const char *p;
91 int len;
92 int n_found = 0;
wdenk57b2d802003-06-27 21:31:46 +000093
Thomas Weber97ea46f2010-11-24 13:07:51 +010094 if (!cmd)
95 return NULL;
wdenk3086a972003-06-28 23:11:04 +000096 /*
97 * Some commands allow length modifiers (like "cp.b");
98 * compare command name only until first dot.
99 */
100 len = ((p = strchr(cmd, '.')) == NULL) ? strlen (cmd) : (p - cmd);
101
Masahiro Yamada682195e2014-10-23 17:27:30 +0900102 for (cmdtp = table; cmdtp != table + table_len; cmdtp++) {
103 if (strncmp(cmd, cmdtp->name, len) == 0) {
104 if (len == strlen(cmdtp->name))
wdenk3086a972003-06-28 23:11:04 +0000105 return cmdtp; /* full match */
106
107 cmdtp_temp = cmdtp; /* abbreviated command ? */
108 n_found++;
109 }
wdenk5dfa25f2002-10-19 19:42:10 +0000110 }
wdenk3086a972003-06-28 23:11:04 +0000111 if (n_found == 1) { /* exactly one match */
wdenk57b2d802003-06-27 21:31:46 +0000112 return cmdtp_temp;
wdenk3086a972003-06-28 23:11:04 +0000113 }
Simon Glass4ef90b72016-03-19 02:18:38 -0600114#endif /* CONFIG_CMDLINE */
wdenk5dfa25f2002-10-19 19:42:10 +0000115
wdenk3086a972003-06-28 23:11:04 +0000116 return NULL; /* not found or ambiguous command */
wdenk57b2d802003-06-27 21:31:46 +0000117}
wdenk3902d702004-04-15 18:22:41 +0000118
Masahiro Yamada682195e2014-10-23 17:27:30 +0900119cmd_tbl_t *find_cmd(const char *cmd)
Kumar Galaac2dad62008-09-23 10:05:02 -0500120{
Marek Vasut69c5e342012-10-12 10:27:04 +0000121 cmd_tbl_t *start = ll_entry_start(cmd_tbl_t, cmd);
122 const int len = ll_entry_count(cmd_tbl_t, cmd);
123 return find_cmd_tbl(cmd, start, len);
Kumar Galaac2dad62008-09-23 10:05:02 -0500124}
125
Mike Frysinger33e84d12011-04-23 23:43:24 +0000126int cmd_usage(const cmd_tbl_t *cmdtp)
Peter Tyserddb3af92009-01-27 18:03:10 -0600127{
Wolfgang Denk9dd775b2009-05-24 19:17:29 +0200128 printf("%s - %s\n\n", cmdtp->name, cmdtp->usage);
129
130#ifdef CONFIG_SYS_LONGHELP
131 printf("Usage:\n%s ", cmdtp->name);
132
133 if (!cmdtp->help) {
134 puts ("- No additional help available.\n");
135 return 1;
136 }
137
Masahiro Yamada682195e2014-10-23 17:27:30 +0900138 puts(cmdtp->help);
139 putc('\n');
Wolfgang Denk9dd775b2009-05-24 19:17:29 +0200140#endif /* CONFIG_SYS_LONGHELP */
Wolfgang Denk3b683112010-07-17 01:06:04 +0200141 return 1;
Peter Tyserddb3af92009-01-27 18:03:10 -0600142}
143
wdenk3902d702004-04-15 18:22:41 +0000144#ifdef CONFIG_AUTO_COMPLETE
145
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200146int var_complete(int argc, char * const argv[], char last_char, int maxv, char *cmdv[])
wdenk3902d702004-04-15 18:22:41 +0000147{
148 static char tmp_buf[512];
149 int space;
150
Jason Hobbscafa1aa2011-08-23 11:06:54 +0000151 space = last_char == '\0' || isblank(last_char);
wdenk3902d702004-04-15 18:22:41 +0000152
153 if (space && argc == 1)
154 return env_complete("", maxv, cmdv, sizeof(tmp_buf), tmp_buf);
155
156 if (!space && argc == 2)
157 return env_complete(argv[1], maxv, cmdv, sizeof(tmp_buf), tmp_buf);
Mike Frysinger8d882322010-12-17 16:51:59 -0500158
wdenk3902d702004-04-15 18:22:41 +0000159 return 0;
160}
161
wdenk3902d702004-04-15 18:22:41 +0000162/*************************************************************************************/
163
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200164static int complete_cmdv(int argc, char * const argv[], char last_char, int maxv, char *cmdv[])
wdenk3902d702004-04-15 18:22:41 +0000165{
Simon Glass4ef90b72016-03-19 02:18:38 -0600166#ifdef CONFIG_CMDLINE
Marek Vasut69c5e342012-10-12 10:27:04 +0000167 cmd_tbl_t *cmdtp = ll_entry_start(cmd_tbl_t, cmd);
168 const int count = ll_entry_count(cmd_tbl_t, cmd);
169 const cmd_tbl_t *cmdend = cmdtp + count;
wdenk3902d702004-04-15 18:22:41 +0000170 const char *p;
171 int len, clen;
172 int n_found = 0;
173 const char *cmd;
174
175 /* sanity? */
176 if (maxv < 2)
177 return -2;
178
179 cmdv[0] = NULL;
180
181 if (argc == 0) {
182 /* output full list of commands */
Marek Vasut69c5e342012-10-12 10:27:04 +0000183 for (; cmdtp != cmdend; cmdtp++) {
wdenk3902d702004-04-15 18:22:41 +0000184 if (n_found >= maxv - 2) {
Andrew Gabbasova7c03b02013-12-27 10:05:14 -0600185 cmdv[n_found++] = "...";
wdenk3902d702004-04-15 18:22:41 +0000186 break;
187 }
Andrew Gabbasova7c03b02013-12-27 10:05:14 -0600188 cmdv[n_found++] = cmdtp->name;
wdenk3902d702004-04-15 18:22:41 +0000189 }
190 cmdv[n_found] = NULL;
191 return n_found;
192 }
193
194 /* more than one arg or one but the start of the next */
Masahiro Yamada682195e2014-10-23 17:27:30 +0900195 if (argc > 1 || last_char == '\0' || isblank(last_char)) {
wdenk3902d702004-04-15 18:22:41 +0000196 cmdtp = find_cmd(argv[0]);
197 if (cmdtp == NULL || cmdtp->complete == NULL) {
198 cmdv[0] = NULL;
199 return 0;
200 }
201 return (*cmdtp->complete)(argc, argv, last_char, maxv, cmdv);
202 }
203
204 cmd = argv[0];
205 /*
206 * Some commands allow length modifiers (like "cp.b");
207 * compare command name only until first dot.
208 */
209 p = strchr(cmd, '.');
210 if (p == NULL)
211 len = strlen(cmd);
212 else
213 len = p - cmd;
214
215 /* return the partial matches */
Marek Vasut69c5e342012-10-12 10:27:04 +0000216 for (; cmdtp != cmdend; cmdtp++) {
wdenk3902d702004-04-15 18:22:41 +0000217
218 clen = strlen(cmdtp->name);
219 if (clen < len)
220 continue;
221
222 if (memcmp(cmd, cmdtp->name, len) != 0)
223 continue;
224
225 /* too many! */
226 if (n_found >= maxv - 2) {
227 cmdv[n_found++] = "...";
228 break;
229 }
230
231 cmdv[n_found++] = cmdtp->name;
232 }
233
234 cmdv[n_found] = NULL;
235 return n_found;
Simon Glass4ef90b72016-03-19 02:18:38 -0600236#else
237 return 0;
238#endif
wdenk3902d702004-04-15 18:22:41 +0000239}
240
241static int make_argv(char *s, int argvsz, char *argv[])
242{
243 int argc = 0;
244
245 /* split into argv */
246 while (argc < argvsz - 1) {
247
248 /* skip any white space */
Jason Hobbscafa1aa2011-08-23 11:06:54 +0000249 while (isblank(*s))
wdenk3902d702004-04-15 18:22:41 +0000250 ++s;
251
Wolfgang Denka1be4762008-05-20 16:00:29 +0200252 if (*s == '\0') /* end of s, no more args */
wdenk3902d702004-04-15 18:22:41 +0000253 break;
254
255 argv[argc++] = s; /* begin of argument string */
256
257 /* find end of string */
Jason Hobbscafa1aa2011-08-23 11:06:54 +0000258 while (*s && !isblank(*s))
wdenk3902d702004-04-15 18:22:41 +0000259 ++s;
260
261 if (*s == '\0') /* end of s, no more args */
262 break;
263
264 *s++ = '\0'; /* terminate current arg */
265 }
266 argv[argc] = NULL;
267
268 return argc;
269}
270
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200271static void print_argv(const char *banner, const char *leader, const char *sep, int linemax, char * const argv[])
wdenk3902d702004-04-15 18:22:41 +0000272{
273 int ll = leader != NULL ? strlen(leader) : 0;
274 int sl = sep != NULL ? strlen(sep) : 0;
275 int len, i;
276
277 if (banner) {
278 puts("\n");
279 puts(banner);
280 }
281
282 i = linemax; /* force leader and newline */
283 while (*argv != NULL) {
284 len = strlen(*argv) + sl;
285 if (i + len >= linemax) {
286 puts("\n");
287 if (leader)
288 puts(leader);
289 i = ll - sl;
290 } else if (sep)
291 puts(sep);
292 puts(*argv++);
293 i += len;
294 }
295 printf("\n");
296}
297
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200298static int find_common_prefix(char * const argv[])
wdenk3902d702004-04-15 18:22:41 +0000299{
300 int i, len;
301 char *anchor, *s, *t;
302
303 if (*argv == NULL)
304 return 0;
305
306 /* begin with max */
307 anchor = *argv++;
308 len = strlen(anchor);
309 while ((t = *argv++) != NULL) {
310 s = anchor;
311 for (i = 0; i < len; i++, t++, s++) {
312 if (*t != *s)
313 break;
314 }
315 len = s - anchor;
316 }
317 return len;
318}
319
Heinrich Schuchardt831030d2017-11-19 23:07:50 +0100320static char tmp_buf[CONFIG_SYS_CBSIZE + 1]; /* copy of console I/O buffer */
wdenk3902d702004-04-15 18:22:41 +0000321
322int cmd_auto_complete(const char *const prompt, char *buf, int *np, int *colp)
323{
324 int n = *np, col = *colp;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200325 char *argv[CONFIG_SYS_MAXARGS + 1]; /* NULL terminated */
wdenk3902d702004-04-15 18:22:41 +0000326 char *cmdv[20];
327 char *s, *t;
328 const char *sep;
329 int i, j, k, len, seplen, argc;
330 int cnt;
331 char last_char;
332
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200333 if (strcmp(prompt, CONFIG_SYS_PROMPT) != 0)
wdenk3902d702004-04-15 18:22:41 +0000334 return 0; /* not in normal console */
335
336 cnt = strlen(buf);
337 if (cnt >= 1)
338 last_char = buf[cnt - 1];
339 else
340 last_char = '\0';
341
342 /* copy to secondary buffer which will be affected */
343 strcpy(tmp_buf, buf);
344
345 /* separate into argv */
346 argc = make_argv(tmp_buf, sizeof(argv)/sizeof(argv[0]), argv);
347
348 /* do the completion and return the possible completions */
Masahiro Yamada682195e2014-10-23 17:27:30 +0900349 i = complete_cmdv(argc, argv, last_char,
350 sizeof(cmdv) / sizeof(cmdv[0]), cmdv);
wdenk3902d702004-04-15 18:22:41 +0000351
352 /* no match; bell and out */
353 if (i == 0) {
354 if (argc > 1) /* allow tab for non command */
355 return 0;
356 putc('\a');
357 return 1;
358 }
359
360 s = NULL;
361 len = 0;
362 sep = NULL;
363 seplen = 0;
364 if (i == 1) { /* one match; perfect */
365 k = strlen(argv[argc - 1]);
366 s = cmdv[0] + k;
367 len = strlen(s);
368 sep = " ";
369 seplen = 1;
Masahiro Yamada682195e2014-10-23 17:27:30 +0900370 } else if (i > 1 && (j = find_common_prefix(cmdv)) != 0) { /* more */
wdenk3902d702004-04-15 18:22:41 +0000371 k = strlen(argv[argc - 1]);
372 j -= k;
373 if (j > 0) {
374 s = cmdv[0] + k;
375 len = j;
376 }
377 }
378
379 if (s != NULL) {
380 k = len + seplen;
381 /* make sure it fits */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200382 if (n + k >= CONFIG_SYS_CBSIZE - 2) {
wdenk3902d702004-04-15 18:22:41 +0000383 putc('\a');
384 return 1;
385 }
386
387 t = buf + cnt;
388 for (i = 0; i < len; i++)
389 *t++ = *s++;
390 if (sep != NULL)
391 for (i = 0; i < seplen; i++)
392 *t++ = sep[i];
393 *t = '\0';
394 n += k;
395 col += k;
396 puts(t - k);
397 if (sep == NULL)
398 putc('\a');
399 *np = n;
400 *colp = col;
401 } else {
402 print_argv(NULL, " ", " ", 78, cmdv);
403
404 puts(prompt);
405 puts(buf);
406 }
407 return 1;
408}
409
410#endif
Jean-Christophe PLAGNIOL-VILLARD82290f22008-09-10 22:48:05 +0200411
412#ifdef CMD_DATA_SIZE
413int cmd_get_data_size(char* arg, int default_size)
414{
415 /* Check for a size specification .b, .w or .l.
416 */
417 int len = strlen(arg);
418 if (len > 2 && arg[len-2] == '.') {
Masahiro Yamada682195e2014-10-23 17:27:30 +0900419 switch (arg[len-1]) {
Jean-Christophe PLAGNIOL-VILLARD82290f22008-09-10 22:48:05 +0200420 case 'b':
421 return 1;
422 case 'w':
423 return 2;
424 case 'l':
425 return 4;
York Sun6c480012014-02-26 17:03:19 -0800426#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
427 case 'q':
428 return 8;
429#endif
Jean-Christophe PLAGNIOL-VILLARD82290f22008-09-10 22:48:05 +0200430 case 's':
431 return -2;
432 default:
433 return -1;
434 }
435 }
436 return default_size;
437}
438#endif
Heiko Schocher092cf162010-09-17 13:10:33 +0200439
Wolfgang Denkd0813e52010-10-28 20:00:11 +0200440#if defined(CONFIG_NEEDS_MANUAL_RELOC)
Heiko Schocher092cf162010-09-17 13:10:33 +0200441DECLARE_GLOBAL_DATA_PTR;
442
443void fixup_cmdtable(cmd_tbl_t *cmdtp, int size)
444{
445 int i;
446
447 if (gd->reloc_off == 0)
448 return;
449
450 for (i = 0; i < size; i++) {
451 ulong addr;
452
Masahiro Yamada682195e2014-10-23 17:27:30 +0900453 addr = (ulong)(cmdtp->cmd) + gd->reloc_off;
Kun-Hua Huang89299e22015-08-24 14:52:35 +0800454#ifdef DEBUG_COMMANDS
Heiko Schocher092cf162010-09-17 13:10:33 +0200455 printf("Command \"%s\": 0x%08lx => 0x%08lx\n",
Masahiro Yamada682195e2014-10-23 17:27:30 +0900456 cmdtp->name, (ulong)(cmdtp->cmd), addr);
Heiko Schocher092cf162010-09-17 13:10:33 +0200457#endif
458 cmdtp->cmd =
459 (int (*)(struct cmd_tbl_s *, int, int, char * const []))addr;
460 addr = (ulong)(cmdtp->name) + gd->reloc_off;
461 cmdtp->name = (char *)addr;
462 if (cmdtp->usage) {
463 addr = (ulong)(cmdtp->usage) + gd->reloc_off;
464 cmdtp->usage = (char *)addr;
465 }
466#ifdef CONFIG_SYS_LONGHELP
467 if (cmdtp->help) {
468 addr = (ulong)(cmdtp->help) + gd->reloc_off;
469 cmdtp->help = (char *)addr;
470 }
471#endif
Daniel Schwierzecke5166222011-10-13 06:07:39 +0000472#ifdef CONFIG_AUTO_COMPLETE
473 if (cmdtp->complete) {
474 addr = (ulong)(cmdtp->complete) + gd->reloc_off;
Daniel Schwierzeck76deb6c2011-10-18 11:12:22 +0000475 cmdtp->complete =
476 (int (*)(int, char * const [], char, int, char * []))addr;
Daniel Schwierzecke5166222011-10-13 06:07:39 +0000477 }
478#endif
Heiko Schocher092cf162010-09-17 13:10:33 +0200479 cmdtp++;
480 }
481}
482#endif
Simon Glass2176d602012-02-14 19:59:23 +0000483
484/**
485 * Call a command function. This should be the only route in U-Boot to call
486 * a command, so that we can track whether we are waiting for input or
487 * executing a command.
488 *
489 * @param cmdtp Pointer to the command to execute
490 * @param flag Some flags normally 0 (see CMD_FLAG_.. above)
491 * @param argc Number of arguments (arg 0 must be the command text)
492 * @param argv Arguments
493 * @return 0 if command succeeded, else non-zero (CMD_RET_...)
494 */
Simon Glass1727b942012-02-14 19:59:25 +0000495static int cmd_call(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Simon Glass2176d602012-02-14 19:59:23 +0000496{
497 int result;
498
499 result = (cmdtp->cmd)(cmdtp, flag, argc, argv);
500 if (result)
Peng Fand6c09ba2015-07-28 22:45:37 +0800501 debug("Command failed, result=%d\n", result);
Simon Glass2176d602012-02-14 19:59:23 +0000502 return result;
503}
Simon Glass1727b942012-02-14 19:59:25 +0000504
505enum command_ret_t cmd_process(int flag, int argc, char * const argv[],
Richard Genoud94ff0672012-12-03 06:28:28 +0000506 int *repeatable, ulong *ticks)
Simon Glass1727b942012-02-14 19:59:25 +0000507{
508 enum command_ret_t rc = CMD_RET_SUCCESS;
509 cmd_tbl_t *cmdtp;
510
511 /* Look up command in command table */
512 cmdtp = find_cmd(argv[0]);
513 if (cmdtp == NULL) {
514 printf("Unknown command '%s' - try 'help'\n", argv[0]);
515 return 1;
516 }
517
518 /* found - check max args */
519 if (argc > cmdtp->maxargs)
520 rc = CMD_RET_USAGE;
521
522#if defined(CONFIG_CMD_BOOTD)
523 /* avoid "bootd" recursion */
524 else if (cmdtp->cmd == do_bootd) {
525 if (flag & CMD_FLAG_BOOTD) {
526 puts("'bootd' recursion detected\n");
527 rc = CMD_RET_FAILURE;
528 } else {
529 flag |= CMD_FLAG_BOOTD;
530 }
531 }
532#endif
533
534 /* If OK so far, then do the command */
535 if (!rc) {
Richard Genoud94ff0672012-12-03 06:28:28 +0000536 if (ticks)
537 *ticks = get_timer(0);
Simon Glass1727b942012-02-14 19:59:25 +0000538 rc = cmd_call(cmdtp, flag, argc, argv);
Richard Genoud94ff0672012-12-03 06:28:28 +0000539 if (ticks)
540 *ticks = get_timer(*ticks);
Simon Glass1727b942012-02-14 19:59:25 +0000541 *repeatable &= cmdtp->repeatable;
542 }
543 if (rc == CMD_RET_USAGE)
544 rc = cmd_usage(cmdtp);
545 return rc;
546}
Simon Glassd7385532014-02-26 15:59:15 -0700547
548int cmd_process_error(cmd_tbl_t *cmdtp, int err)
549{
Michal Simek2e1b90b2018-06-21 14:49:26 +0200550 if (err == CMD_RET_USAGE)
551 return CMD_RET_USAGE;
552
Simon Glassd7385532014-02-26 15:59:15 -0700553 if (err) {
554 printf("Command '%s' failed: Error %d\n", cmdtp->name, err);
Michal Simek44bdb572018-06-04 13:29:49 +0200555 return CMD_RET_FAILURE;
Simon Glassd7385532014-02-26 15:59:15 -0700556 }
557
Michal Simek44bdb572018-06-04 13:29:49 +0200558 return CMD_RET_SUCCESS;
Simon Glassd7385532014-02-26 15:59:15 -0700559}