]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
Create a single cmd_call() function to handle command execution
authorSimon Glass <sjg@chromium.org>
Tue, 14 Feb 2012 19:59:23 +0000 (19:59 +0000)
committerWolfgang Denk <wd@denx.de>
Tue, 6 Mar 2012 20:09:34 +0000 (21:09 +0100)
We should aim for a single point of entry to the commands, whichever
parser is used.

Signed-off-by: Simon Glass <sjg@chromium.org>
common/command.c
common/hush.c
common/main.c
include/command.h

index c5cecd3bf5767c033c82286a88d56c052734f490..fe290759cd06d871bd6779585e4c4d2c7ecadd45 100644 (file)
@@ -487,3 +487,24 @@ void fixup_cmdtable(cmd_tbl_t *cmdtp, int size)
        }
 }
 #endif
+
+/**
+ * Call a command function. This should be the only route in U-Boot to call
+ * a command, so that we can track whether we are waiting for input or
+ * executing a command.
+ *
+ * @param cmdtp                Pointer to the command to execute
+ * @param flag         Some flags normally 0 (see CMD_FLAG_.. above)
+ * @param argc         Number of arguments (arg 0 must be the command text)
+ * @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[])
+{
+       int result;
+
+       result = (cmdtp->cmd)(cmdtp, flag, argc, argv);
+       if (result)
+               debug("Command failed, result=%d", result);
+       return result;
+}
index e8e24d7deab952f7e7d0d429febfa94b464398d1..6cb921d4f35151a901b521e8e3b3878cb6582319 100644 (file)
@@ -1679,13 +1679,10 @@ static int run_pipe_real(struct pipe *pi)
                                rcode = x->function(child);
 #else
                                /* OK - call function to do the command */
-
-                               rcode = (cmdtp->cmd)
-(cmdtp, flag,child->argc-i,&child->argv[i]);
-                               if ( !cmdtp->repeatable )
+                               rcode = cmd_call(cmdtp, flag,  child->argc-i,
+                                                &child->argv[i]);
+                               if (!cmdtp->repeatable)
                                        flag_repeat = 0;
-
-
 #endif
                                child->argv-=i;  /* XXX restore hack so free() can work right */
 #ifndef __U_BOOT__
index 637da2b4d34953209fbcd79c306ca6282a739259..6a3eac28aa7e280fbd8b6f508e5cd938c3e15375 100644 (file)
@@ -1370,9 +1370,8 @@ static int builtin_run_command(const char *cmd, int flag)
 #endif
 
                /* OK - call function to do the command */
-               if ((cmdtp->cmd) (cmdtp, flag, argc, argv) != 0) {
+               if (cmd_call(cmdtp, flag, argc, argv) != 0)
                        rc = -1;
-               }
 
                repeatable &= cmdtp->repeatable;
 
index 3912b80cdd8b156f5c54e9a0bd968df1c9c0c882..6dc694f7a83d31d90346b5af875797298620cc0f 100644 (file)
@@ -112,6 +112,8 @@ static inline int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd)
 #endif
 extern int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
 
+int cmd_call(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
+
 #endif /* __ASSEMBLY__ */
 
 /*
@@ -150,4 +152,5 @@ extern int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
 void fixup_cmdtable(cmd_tbl_t *cmdtp, int size);
 #endif
+
 #endif /* __COMMAND_H */