summaryrefslogtreecommitdiffstats
path: root/common/command.c
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2012-02-14 19:59:25 +0000
committerWolfgang Denk <wd@denx.de>2012-03-06 21:09:41 +0100
commit9d12d5d41d5653ba2f943886f45b8c2eb0f63450 (patch)
tree03ea18e10cb7c8f06bf82525c8aacad91938ad93 /common/command.c
parent7344f9128dfa797a9b9d51b38832f77a1eaeac2d (diff)
downloadblackbird-obmc-uboot-9d12d5d41d5653ba2f943886f45b8c2eb0f63450.tar.gz
blackbird-obmc-uboot-9d12d5d41d5653ba2f943886f45b8c2eb0f63450.zip
Add cmd_process() to process commands in one place
We currently have the same code in hush.c and main.c. This brings the code into one place. As an added feature, if the command function returns CMD_RET_USAGE then cmd_process() will print a usage message for the command before returning the standard failure code of 1. ARM code size increases about 32 bytes with this clean-up. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'common/command.c')
-rw-r--r--common/command.c41
1 files changed, 40 insertions, 1 deletions
diff --git a/common/command.c b/common/command.c
index fe290759cd..aa0fb0a3d3 100644
--- a/common/command.c
+++ b/common/command.c
@@ -499,7 +499,7 @@ void fixup_cmdtable(cmd_tbl_t *cmdtp, int size)
* @param argv Arguments
* @return 0 if command succeeded, else non-zero (CMD_RET_...)
*/
-int cmd_call(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+static int cmd_call(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
int result;
@@ -508,3 +508,42 @@ int cmd_call(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
debug("Command failed, result=%d", result);
return result;
}
+
+enum command_ret_t cmd_process(int flag, int argc, char * const argv[],
+ int *repeatable)
+{
+ enum command_ret_t rc = CMD_RET_SUCCESS;
+ cmd_tbl_t *cmdtp;
+
+ /* Look up command in command table */
+ cmdtp = find_cmd(argv[0]);
+ if (cmdtp == NULL) {
+ printf("Unknown command '%s' - try 'help'\n", argv[0]);
+ return 1;
+ }
+
+ /* found - check max args */
+ if (argc > cmdtp->maxargs)
+ rc = CMD_RET_USAGE;
+
+#if defined(CONFIG_CMD_BOOTD)
+ /* avoid "bootd" recursion */
+ else if (cmdtp->cmd == do_bootd) {
+ if (flag & CMD_FLAG_BOOTD) {
+ puts("'bootd' recursion detected\n");
+ rc = CMD_RET_FAILURE;
+ } else {
+ flag |= CMD_FLAG_BOOTD;
+ }
+ }
+#endif
+
+ /* If OK so far, then do the command */
+ if (!rc) {
+ rc = cmd_call(cmdtp, flag, argc, argv);
+ *repeatable &= cmdtp->repeatable;
+ }
+ if (rc == CMD_RET_USAGE)
+ rc = cmd_usage(cmdtp);
+ return rc;
+}
OpenPOWER on IntegriCloud