summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2012-07-30 10:08:18 -0700
committerGerrit <chrome-bot@google.com>2012-07-30 14:15:03 -0700
commit30b2bd27f671529f2e9af341efb78204f787bbee (patch)
tree57546aa882c771eabd73780f28205190ef18d641
parentc846102714e5b31abe19330f9102762c89910ed7 (diff)
downloadchrome-ec-30b2bd27f671529f2e9af341efb78204f787bbee.tar.gz
Improve hostcmd command
Version and params fields are optional. Output uses "%h" format code. BUG=none TEST=manual > hostcmd 0 Response: 02000000 > hostcmd 0 0 Response: 02000000 > hostcmd 0 1 Command returned 6 > hostcmd 1 0 10203040 Response: 14233241 Change-Id: I8b3ff0f7d9a1131f942604724e04c59ff818396d Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/28705 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
-rw-r--r--common/host_command.c44
1 files changed, 23 insertions, 21 deletions
diff --git a/common/host_command.c b/common/host_command.c
index 515962d987..df83e9f00b 100644
--- a/common/host_command.c
+++ b/common/host_command.c
@@ -263,17 +263,6 @@ static int parse_params(char *s, uint8_t *params)
return len;
}
-static void dump_hex(char *resp, int size)
-{
- int i;
- for (i = 0; i < size; ++i) {
- ccprintf("%02x", (int)resp[i]);
- if ((i & 15) == 15)
- ccputs("\n");
- }
- ccputs("\n");
-}
-
static int command_host_command(int argc, char **argv)
{
struct host_cmd_handler_args args;
@@ -282,20 +271,31 @@ static int command_host_command(int argc, char **argv)
char *e;
int rv;
- if (argc != 4)
+ /* Assume no version or params unless proven otherwise */
+ args.version = 0;
+ args.params_size = 0;
+ args.params = cmd_params;
+
+ if (argc < 2)
return EC_ERROR_PARAM_COUNT;
args.command = strtoi(argv[1], &e, 0);
if (*e)
return EC_ERROR_PARAM1;
- args.version = strtoi(argv[2], &e, 0);
- if (*e)
- return EC_ERROR_PARAM2;
- args.params = cmd_params;
- rv = parse_params(argv[3], cmd_params);
- if (rv < 0)
- return EC_ERROR_PARAM3;
- args.params_size = rv;
+
+ if (argc > 2) {
+ args.version = strtoi(argv[2], &e, 0);
+ if (*e)
+ return EC_ERROR_PARAM2;
+ }
+
+ if (argc > 3) {
+ rv = parse_params(argv[3], cmd_params);
+ if (rv < 0)
+ return EC_ERROR_PARAM3;
+ args.params_size = rv;
+ }
+
args.response = cmd_params;
args.response_max = EC_HOST_PARAM_SIZE;
args.response_size = 0;
@@ -304,8 +304,10 @@ static int command_host_command(int argc, char **argv)
if (res != EC_RES_SUCCESS)
ccprintf("Command returned %d\n", res);
+ else if (args.response_size)
+ ccprintf("Response: %.*h\n", args.response_size, cmd_params);
else
- dump_hex(cmd_params, args.response_size);
+ ccprintf("Command succeeded; no response.\n");
return EC_SUCCESS;
}