blob: 858e28885a2cf0fe1ab6f409c2370305eebdca2f [file] [log] [blame]
wdenk5dfa25f2002-10-19 19:42:10 +00001/*
Detlev Zundel2dce5512009-03-25 17:27:52 +01002 * (C) Copyright 2000-2009
wdenk5dfa25f2002-10-19 19:42:10 +00003 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenk5dfa25f2002-10-19 19:42:10 +00006 */
7
8/*
9 * Command Processor Table
10 */
11
12#include <common.h>
13#include <command.h>
Simon Glass24b852a2015-11-08 23:47:45 -070014#include <console.h>
Jason Hobbs4d91a6e2011-08-23 11:06:54 +000015#include <linux/ctype.h>
wdenk5dfa25f2002-10-19 19:42:10 +000016
wdenk5dfa25f2002-10-19 19:42:10 +000017/*
18 * Use puts() instead of printf() to avoid printf buffer overflow
19 * for long help messages
20 */
Detlev Zundel2dce5512009-03-25 17:27:52 +010021
Masahiro Yamada616e2162014-10-23 17:27:30 +090022int _do_help(cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t *cmdtp, int flag,
23 int argc, char * const argv[])
wdenk5dfa25f2002-10-19 19:42:10 +000024{
25 int i;
26 int rcode = 0;
27
Masahiro Yamada616e2162014-10-23 17:27:30 +090028 if (argc == 1) { /* show list of commands */
Anatolij Gustschin22b6fcb2012-11-08 12:40:17 +010029 cmd_tbl_t *cmd_array[cmd_items];
wdenk9d2b18a2003-06-28 23:11:04 +000030 int i, j, swaps;
wdenk8bde7f72003-06-27 21:31:46 +000031
wdenk9d2b18a2003-06-28 23:11:04 +000032 /* Make array of commands from .uboot_cmd section */
Detlev Zundel2dce5512009-03-25 17:27:52 +010033 cmdtp = cmd_start;
wdenk9d2b18a2003-06-28 23:11:04 +000034 for (i = 0; i < cmd_items; i++) {
35 cmd_array[i] = cmdtp++;
wdenk8bde7f72003-06-27 21:31:46 +000036 }
wdenk8bde7f72003-06-27 21:31:46 +000037
wdenk9d2b18a2003-06-28 23:11:04 +000038 /* Sort command list (trivial bubble sort) */
39 for (i = cmd_items - 1; i > 0; --i) {
40 swaps = 0;
41 for (j = 0; j < i; ++j) {
Masahiro Yamada616e2162014-10-23 17:27:30 +090042 if (strcmp(cmd_array[j]->name,
43 cmd_array[j + 1]->name) > 0) {
wdenk9d2b18a2003-06-28 23:11:04 +000044 cmd_tbl_t *tmp;
45 tmp = cmd_array[j];
46 cmd_array[j] = cmd_array[j + 1];
47 cmd_array[j + 1] = tmp;
48 ++swaps;
49 }
wdenk8bde7f72003-06-27 21:31:46 +000050 }
wdenk9d2b18a2003-06-28 23:11:04 +000051 if (!swaps)
52 break;
wdenk8bde7f72003-06-27 21:31:46 +000053 }
54
55 /* print short help (usage) */
wdenk9d2b18a2003-06-28 23:11:04 +000056 for (i = 0; i < cmd_items; i++) {
57 const char *usage = cmd_array[i]->usage;
58
wdenk5dfa25f2002-10-19 19:42:10 +000059 /* allow user abort */
Masahiro Yamada616e2162014-10-23 17:27:30 +090060 if (ctrlc())
wdenk5dfa25f2002-10-19 19:42:10 +000061 return 1;
wdenk9d2b18a2003-06-28 23:11:04 +000062 if (usage == NULL)
wdenk5dfa25f2002-10-19 19:42:10 +000063 continue;
Peter Tyser2fb26042009-01-27 18:03:12 -060064 printf("%-*s- %s\n", CONFIG_SYS_HELP_CMD_WIDTH,
65 cmd_array[i]->name, usage);
wdenk5dfa25f2002-10-19 19:42:10 +000066 }
wdenk5dfa25f2002-10-19 19:42:10 +000067 return 0;
68 }
wdenk5dfa25f2002-10-19 19:42:10 +000069 /*
70 * command help (long version)
71 */
wdenk8bde7f72003-06-27 21:31:46 +000072 for (i = 1; i < argc; ++i) {
Masahiro Yamada616e2162014-10-23 17:27:30 +090073 cmdtp = find_cmd_tbl(argv[i], cmd_start, cmd_items);
74 if (cmdtp != NULL) {
Wolfgang Denk94796d82009-05-24 19:17:29 +020075 rcode |= cmd_usage(cmdtp);
wdenk71f95112003-06-15 22:40:42 +000076 } else {
Masahiro Yamada616e2162014-10-23 17:27:30 +090077 printf("Unknown command '%s' - try 'help' without arguments for list of all known commands\n\n",
78 argv[i]);
wdenk5dfa25f2002-10-19 19:42:10 +000079 rcode = 1;
80 }
81 }
82 return rcode;
83}
84
Masahiro Yamada616e2162014-10-23 17:27:30 +090085/* find command table entry for a command */
86cmd_tbl_t *find_cmd_tbl(const char *cmd, cmd_tbl_t *table, int table_len)
wdenk5dfa25f2002-10-19 19:42:10 +000087{
88 cmd_tbl_t *cmdtp;
Masahiro Yamada616e2162014-10-23 17:27:30 +090089 cmd_tbl_t *cmdtp_temp = table; /* Init value */
wdenk9d2b18a2003-06-28 23:11:04 +000090 const char *p;
91 int len;
92 int n_found = 0;
wdenk8bde7f72003-06-27 21:31:46 +000093
Thomas Weber7013c062010-11-24 13:07:51 +010094 if (!cmd)
95 return NULL;
wdenk9d2b18a2003-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 Yamada616e2162014-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))
wdenk9d2b18a2003-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 }
wdenk9d2b18a2003-06-28 23:11:04 +0000111 if (n_found == 1) { /* exactly one match */
wdenk8bde7f72003-06-27 21:31:46 +0000112 return cmdtp_temp;
wdenk9d2b18a2003-06-28 23:11:04 +0000113 }
wdenk8bde7f72003-06-27 21:31:46 +0000114
wdenk9d2b18a2003-06-28 23:11:04 +0000115 return NULL; /* not found or ambiguous command */
wdenk5dfa25f2002-10-19 19:42:10 +0000116}
wdenk04a85b32004-04-15 18:22:41 +0000117
Masahiro Yamada616e2162014-10-23 17:27:30 +0900118cmd_tbl_t *find_cmd(const char *cmd)
Kumar Galab799cb42008-09-23 10:05:02 -0500119{
Marek Vasut6c7c9462012-10-12 10:27:04 +0000120 cmd_tbl_t *start = ll_entry_start(cmd_tbl_t, cmd);
121 const int len = ll_entry_count(cmd_tbl_t, cmd);
122 return find_cmd_tbl(cmd, start, len);
Kumar Galab799cb42008-09-23 10:05:02 -0500123}
124
Mike Frysingere84ffdd2011-04-23 23:43:24 +0000125int cmd_usage(const cmd_tbl_t *cmdtp)
Peter Tyser62c3ae72009-01-27 18:03:10 -0600126{
Wolfgang Denk94796d82009-05-24 19:17:29 +0200127 printf("%s - %s\n\n", cmdtp->name, cmdtp->usage);
128
129#ifdef CONFIG_SYS_LONGHELP
130 printf("Usage:\n%s ", cmdtp->name);
131
132 if (!cmdtp->help) {
133 puts ("- No additional help available.\n");
134 return 1;
135 }
136
Masahiro Yamada616e2162014-10-23 17:27:30 +0900137 puts(cmdtp->help);
138 putc('\n');
Wolfgang Denk94796d82009-05-24 19:17:29 +0200139#endif /* CONFIG_SYS_LONGHELP */
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200140 return 1;
Peter Tyser62c3ae72009-01-27 18:03:10 -0600141}
142
wdenk04a85b32004-04-15 18:22:41 +0000143#ifdef CONFIG_AUTO_COMPLETE
144
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200145int var_complete(int argc, char * const argv[], char last_char, int maxv, char *cmdv[])
wdenk04a85b32004-04-15 18:22:41 +0000146{
147 static char tmp_buf[512];
148 int space;
149
Jason Hobbs4d91a6e2011-08-23 11:06:54 +0000150 space = last_char == '\0' || isblank(last_char);
wdenk04a85b32004-04-15 18:22:41 +0000151
152 if (space && argc == 1)
153 return env_complete("", maxv, cmdv, sizeof(tmp_buf), tmp_buf);
154
155 if (!space && argc == 2)
156 return env_complete(argv[1], maxv, cmdv, sizeof(tmp_buf), tmp_buf);
Mike Frysinger560d4242010-12-17 16:51:59 -0500157
wdenk04a85b32004-04-15 18:22:41 +0000158 return 0;
159}
160
wdenk04a85b32004-04-15 18:22:41 +0000161/*************************************************************************************/
162
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200163static int complete_cmdv(int argc, char * const argv[], char last_char, int maxv, char *cmdv[])
wdenk04a85b32004-04-15 18:22:41 +0000164{
Marek Vasut6c7c9462012-10-12 10:27:04 +0000165 cmd_tbl_t *cmdtp = ll_entry_start(cmd_tbl_t, cmd);
166 const int count = ll_entry_count(cmd_tbl_t, cmd);
167 const cmd_tbl_t *cmdend = cmdtp + count;
wdenk04a85b32004-04-15 18:22:41 +0000168 const char *p;
169 int len, clen;
170 int n_found = 0;
171 const char *cmd;
172
173 /* sanity? */
174 if (maxv < 2)
175 return -2;
176
177 cmdv[0] = NULL;
178
179 if (argc == 0) {
180 /* output full list of commands */
Marek Vasut6c7c9462012-10-12 10:27:04 +0000181 for (; cmdtp != cmdend; cmdtp++) {
wdenk04a85b32004-04-15 18:22:41 +0000182 if (n_found >= maxv - 2) {
Andrew Gabbasov9b438942013-12-27 10:05:14 -0600183 cmdv[n_found++] = "...";
wdenk04a85b32004-04-15 18:22:41 +0000184 break;
185 }
Andrew Gabbasov9b438942013-12-27 10:05:14 -0600186 cmdv[n_found++] = cmdtp->name;
wdenk04a85b32004-04-15 18:22:41 +0000187 }
188 cmdv[n_found] = NULL;
189 return n_found;
190 }
191
192 /* more than one arg or one but the start of the next */
Masahiro Yamada616e2162014-10-23 17:27:30 +0900193 if (argc > 1 || last_char == '\0' || isblank(last_char)) {
wdenk04a85b32004-04-15 18:22:41 +0000194 cmdtp = find_cmd(argv[0]);
195 if (cmdtp == NULL || cmdtp->complete == NULL) {
196 cmdv[0] = NULL;
197 return 0;
198 }
199 return (*cmdtp->complete)(argc, argv, last_char, maxv, cmdv);
200 }
201
202 cmd = argv[0];
203 /*
204 * Some commands allow length modifiers (like "cp.b");
205 * compare command name only until first dot.
206 */
207 p = strchr(cmd, '.');
208 if (p == NULL)
209 len = strlen(cmd);
210 else
211 len = p - cmd;
212
213 /* return the partial matches */
Marek Vasut6c7c9462012-10-12 10:27:04 +0000214 for (; cmdtp != cmdend; cmdtp++) {
wdenk04a85b32004-04-15 18:22:41 +0000215
216 clen = strlen(cmdtp->name);
217 if (clen < len)
218 continue;
219
220 if (memcmp(cmd, cmdtp->name, len) != 0)
221 continue;
222
223 /* too many! */
224 if (n_found >= maxv - 2) {
225 cmdv[n_found++] = "...";
226 break;
227 }
228
229 cmdv[n_found++] = cmdtp->name;
230 }
231
232 cmdv[n_found] = NULL;
233 return n_found;
234}
235
236static int make_argv(char *s, int argvsz, char *argv[])
237{
238 int argc = 0;
239
240 /* split into argv */
241 while (argc < argvsz - 1) {
242
243 /* skip any white space */
Jason Hobbs4d91a6e2011-08-23 11:06:54 +0000244 while (isblank(*s))
wdenk04a85b32004-04-15 18:22:41 +0000245 ++s;
246
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200247 if (*s == '\0') /* end of s, no more args */
wdenk04a85b32004-04-15 18:22:41 +0000248 break;
249
250 argv[argc++] = s; /* begin of argument string */
251
252 /* find end of string */
Jason Hobbs4d91a6e2011-08-23 11:06:54 +0000253 while (*s && !isblank(*s))
wdenk04a85b32004-04-15 18:22:41 +0000254 ++s;
255
256 if (*s == '\0') /* end of s, no more args */
257 break;
258
259 *s++ = '\0'; /* terminate current arg */
260 }
261 argv[argc] = NULL;
262
263 return argc;
264}
265
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200266static void print_argv(const char *banner, const char *leader, const char *sep, int linemax, char * const argv[])
wdenk04a85b32004-04-15 18:22:41 +0000267{
268 int ll = leader != NULL ? strlen(leader) : 0;
269 int sl = sep != NULL ? strlen(sep) : 0;
270 int len, i;
271
272 if (banner) {
273 puts("\n");
274 puts(banner);
275 }
276
277 i = linemax; /* force leader and newline */
278 while (*argv != NULL) {
279 len = strlen(*argv) + sl;
280 if (i + len >= linemax) {
281 puts("\n");
282 if (leader)
283 puts(leader);
284 i = ll - sl;
285 } else if (sep)
286 puts(sep);
287 puts(*argv++);
288 i += len;
289 }
290 printf("\n");
291}
292
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200293static int find_common_prefix(char * const argv[])
wdenk04a85b32004-04-15 18:22:41 +0000294{
295 int i, len;
296 char *anchor, *s, *t;
297
298 if (*argv == NULL)
299 return 0;
300
301 /* begin with max */
302 anchor = *argv++;
303 len = strlen(anchor);
304 while ((t = *argv++) != NULL) {
305 s = anchor;
306 for (i = 0; i < len; i++, t++, s++) {
307 if (*t != *s)
308 break;
309 }
310 len = s - anchor;
311 }
312 return len;
313}
314
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200315static char tmp_buf[CONFIG_SYS_CBSIZE]; /* copy of console I/O buffer */
wdenk04a85b32004-04-15 18:22:41 +0000316
317int cmd_auto_complete(const char *const prompt, char *buf, int *np, int *colp)
318{
319 int n = *np, col = *colp;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200320 char *argv[CONFIG_SYS_MAXARGS + 1]; /* NULL terminated */
wdenk04a85b32004-04-15 18:22:41 +0000321 char *cmdv[20];
322 char *s, *t;
323 const char *sep;
324 int i, j, k, len, seplen, argc;
325 int cnt;
326 char last_char;
327
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200328 if (strcmp(prompt, CONFIG_SYS_PROMPT) != 0)
wdenk04a85b32004-04-15 18:22:41 +0000329 return 0; /* not in normal console */
330
331 cnt = strlen(buf);
332 if (cnt >= 1)
333 last_char = buf[cnt - 1];
334 else
335 last_char = '\0';
336
337 /* copy to secondary buffer which will be affected */
338 strcpy(tmp_buf, buf);
339
340 /* separate into argv */
341 argc = make_argv(tmp_buf, sizeof(argv)/sizeof(argv[0]), argv);
342
343 /* do the completion and return the possible completions */
Masahiro Yamada616e2162014-10-23 17:27:30 +0900344 i = complete_cmdv(argc, argv, last_char,
345 sizeof(cmdv) / sizeof(cmdv[0]), cmdv);
wdenk04a85b32004-04-15 18:22:41 +0000346
347 /* no match; bell and out */
348 if (i == 0) {
349 if (argc > 1) /* allow tab for non command */
350 return 0;
351 putc('\a');
352 return 1;
353 }
354
355 s = NULL;
356 len = 0;
357 sep = NULL;
358 seplen = 0;
359 if (i == 1) { /* one match; perfect */
360 k = strlen(argv[argc - 1]);
361 s = cmdv[0] + k;
362 len = strlen(s);
363 sep = " ";
364 seplen = 1;
Masahiro Yamada616e2162014-10-23 17:27:30 +0900365 } else if (i > 1 && (j = find_common_prefix(cmdv)) != 0) { /* more */
wdenk04a85b32004-04-15 18:22:41 +0000366 k = strlen(argv[argc - 1]);
367 j -= k;
368 if (j > 0) {
369 s = cmdv[0] + k;
370 len = j;
371 }
372 }
373
374 if (s != NULL) {
375 k = len + seplen;
376 /* make sure it fits */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200377 if (n + k >= CONFIG_SYS_CBSIZE - 2) {
wdenk04a85b32004-04-15 18:22:41 +0000378 putc('\a');
379 return 1;
380 }
381
382 t = buf + cnt;
383 for (i = 0; i < len; i++)
384 *t++ = *s++;
385 if (sep != NULL)
386 for (i = 0; i < seplen; i++)
387 *t++ = sep[i];
388 *t = '\0';
389 n += k;
390 col += k;
391 puts(t - k);
392 if (sep == NULL)
393 putc('\a');
394 *np = n;
395 *colp = col;
396 } else {
397 print_argv(NULL, " ", " ", 78, cmdv);
398
399 puts(prompt);
400 puts(buf);
401 }
402 return 1;
403}
404
405#endif
Jean-Christophe PLAGNIOL-VILLARD8a40fb12008-09-10 22:48:05 +0200406
407#ifdef CMD_DATA_SIZE
408int cmd_get_data_size(char* arg, int default_size)
409{
410 /* Check for a size specification .b, .w or .l.
411 */
412 int len = strlen(arg);
413 if (len > 2 && arg[len-2] == '.') {
Masahiro Yamada616e2162014-10-23 17:27:30 +0900414 switch (arg[len-1]) {
Jean-Christophe PLAGNIOL-VILLARD8a40fb12008-09-10 22:48:05 +0200415 case 'b':
416 return 1;
417 case 'w':
418 return 2;
419 case 'l':
420 return 4;
York Sun4d1fd7f2014-02-26 17:03:19 -0800421#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
422 case 'q':
423 return 8;
424#endif
Jean-Christophe PLAGNIOL-VILLARD8a40fb12008-09-10 22:48:05 +0200425 case 's':
426 return -2;
427 default:
428 return -1;
429 }
430 }
431 return default_size;
432}
433#endif
Heiko Schocher620f1f62010-09-17 13:10:33 +0200434
Wolfgang Denk2e5167c2010-10-28 20:00:11 +0200435#if defined(CONFIG_NEEDS_MANUAL_RELOC)
Heiko Schocher620f1f62010-09-17 13:10:33 +0200436DECLARE_GLOBAL_DATA_PTR;
437
438void fixup_cmdtable(cmd_tbl_t *cmdtp, int size)
439{
440 int i;
441
442 if (gd->reloc_off == 0)
443 return;
444
445 for (i = 0; i < size; i++) {
446 ulong addr;
447
Masahiro Yamada616e2162014-10-23 17:27:30 +0900448 addr = (ulong)(cmdtp->cmd) + gd->reloc_off;
Kun-Hua Huang2e88bb22015-08-24 14:52:35 +0800449#ifdef DEBUG_COMMANDS
Heiko Schocher620f1f62010-09-17 13:10:33 +0200450 printf("Command \"%s\": 0x%08lx => 0x%08lx\n",
Masahiro Yamada616e2162014-10-23 17:27:30 +0900451 cmdtp->name, (ulong)(cmdtp->cmd), addr);
Heiko Schocher620f1f62010-09-17 13:10:33 +0200452#endif
453 cmdtp->cmd =
454 (int (*)(struct cmd_tbl_s *, int, int, char * const []))addr;
455 addr = (ulong)(cmdtp->name) + gd->reloc_off;
456 cmdtp->name = (char *)addr;
457 if (cmdtp->usage) {
458 addr = (ulong)(cmdtp->usage) + gd->reloc_off;
459 cmdtp->usage = (char *)addr;
460 }
461#ifdef CONFIG_SYS_LONGHELP
462 if (cmdtp->help) {
463 addr = (ulong)(cmdtp->help) + gd->reloc_off;
464 cmdtp->help = (char *)addr;
465 }
466#endif
Daniel Schwierzeckfa28bd22011-10-13 06:07:39 +0000467#ifdef CONFIG_AUTO_COMPLETE
468 if (cmdtp->complete) {
469 addr = (ulong)(cmdtp->complete) + gd->reloc_off;
Daniel Schwierzeck3668d8f2011-10-18 11:12:22 +0000470 cmdtp->complete =
471 (int (*)(int, char * const [], char, int, char * []))addr;
Daniel Schwierzeckfa28bd22011-10-13 06:07:39 +0000472 }
473#endif
Heiko Schocher620f1f62010-09-17 13:10:33 +0200474 cmdtp++;
475 }
476}
477#endif
Simon Glassbdf8e342012-02-14 19:59:23 +0000478
479/**
480 * Call a command function. This should be the only route in U-Boot to call
481 * a command, so that we can track whether we are waiting for input or
482 * executing a command.
483 *
484 * @param cmdtp Pointer to the command to execute
485 * @param flag Some flags normally 0 (see CMD_FLAG_.. above)
486 * @param argc Number of arguments (arg 0 must be the command text)
487 * @param argv Arguments
488 * @return 0 if command succeeded, else non-zero (CMD_RET_...)
489 */
Simon Glass9d12d5d2012-02-14 19:59:25 +0000490static int cmd_call(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Simon Glassbdf8e342012-02-14 19:59:23 +0000491{
492 int result;
493
494 result = (cmdtp->cmd)(cmdtp, flag, argc, argv);
495 if (result)
Peng Fan58b6ad62015-07-28 22:45:37 +0800496 debug("Command failed, result=%d\n", result);
Simon Glassbdf8e342012-02-14 19:59:23 +0000497 return result;
498}
Simon Glass9d12d5d2012-02-14 19:59:25 +0000499
500enum command_ret_t cmd_process(int flag, int argc, char * const argv[],
Richard Genoud34765e82012-12-03 06:28:28 +0000501 int *repeatable, ulong *ticks)
Simon Glass9d12d5d2012-02-14 19:59:25 +0000502{
503 enum command_ret_t rc = CMD_RET_SUCCESS;
504 cmd_tbl_t *cmdtp;
505
506 /* Look up command in command table */
507 cmdtp = find_cmd(argv[0]);
508 if (cmdtp == NULL) {
509 printf("Unknown command '%s' - try 'help'\n", argv[0]);
510 return 1;
511 }
512
513 /* found - check max args */
514 if (argc > cmdtp->maxargs)
515 rc = CMD_RET_USAGE;
516
517#if defined(CONFIG_CMD_BOOTD)
518 /* avoid "bootd" recursion */
519 else if (cmdtp->cmd == do_bootd) {
520 if (flag & CMD_FLAG_BOOTD) {
521 puts("'bootd' recursion detected\n");
522 rc = CMD_RET_FAILURE;
523 } else {
524 flag |= CMD_FLAG_BOOTD;
525 }
526 }
527#endif
528
529 /* If OK so far, then do the command */
530 if (!rc) {
Richard Genoud34765e82012-12-03 06:28:28 +0000531 if (ticks)
532 *ticks = get_timer(0);
Simon Glass9d12d5d2012-02-14 19:59:25 +0000533 rc = cmd_call(cmdtp, flag, argc, argv);
Richard Genoud34765e82012-12-03 06:28:28 +0000534 if (ticks)
535 *ticks = get_timer(*ticks);
Simon Glass9d12d5d2012-02-14 19:59:25 +0000536 *repeatable &= cmdtp->repeatable;
537 }
538 if (rc == CMD_RET_USAGE)
539 rc = cmd_usage(cmdtp);
540 return rc;
541}
Simon Glass16ff9902014-02-26 15:59:15 -0700542
543int cmd_process_error(cmd_tbl_t *cmdtp, int err)
544{
545 if (err) {
546 printf("Command '%s' failed: Error %d\n", cmdtp->name, err);
547 return 1;
548 }
549
550 return 0;
551}