]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
Add cmd_process_error() to report and process errors
authorSimon Glass <sjg@chromium.org>
Wed, 26 Feb 2014 22:59:15 +0000 (15:59 -0700)
committerTom Rini <trini@ti.com>
Tue, 4 Mar 2014 17:15:28 +0000 (12:15 -0500)
U-Boot now uses errors defined in include/errno.h which are negative
integers. Commands which fail need to report the error and return 1
to indicate failure. Add this functionality in cmd_process_error().

For now this merely reports the error number. It would be possible
also to produce a helpful error message by storing the error strings
in U-Boot.

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

index 597ab4cb4d83493e1c90d96a85da0669a48a4b8a..26c37f2b9d931373b59a9e59cacaa0b83829a1fa 100644 (file)
@@ -538,3 +538,13 @@ enum command_ret_t cmd_process(int flag, int argc, char * const argv[],
                rc = cmd_usage(cmdtp);
        return rc;
 }
+
+int cmd_process_error(cmd_tbl_t *cmdtp, int err)
+{
+       if (err) {
+               printf("Command '%s' failed: Error %d\n", cmdtp->name, err);
+               return 1;
+       }
+
+       return 0;
+}
index f782779d8bdf6847745dbf056fcfe04aa42b681f..d3f700fc3c83f2f5da74f9d50ccfd6350f2512b1 100644 (file)
@@ -64,6 +64,15 @@ extern int var_complete(int argc, char * const argv[], char last_char, int maxv,
 extern int cmd_auto_complete(const char *const prompt, char *buf, int *np, int *colp);
 #endif
 
+/**
+ * cmd_process_error() - report and process a possible error
+ *
+ * @cmdtp: Command which caused the error
+ * @err: Error code (0 if none, -ve for error, like -EIO)
+ * @return 0 if there is not error, 1 (CMD_RET_FAILURE) if an error is found
+ */
+int cmd_process_error(cmd_tbl_t *cmdtp, int err);
+
 /*
  * Monitor Command
  *