From c1bcb14e84e1252a0313cd14b0df7666778fae0d Mon Sep 17 00:00:00 2001 From: Randall Spangler Date: Wed, 1 Aug 2012 10:16:29 -0700 Subject: Add additional host command debug output Prints when a host command returns an error code. When 'hcdebug on', hex-dumps the host command params and response. BUG=none TEST=manual (> is ec console, $ is root shell) $ ectool gpioget foobar --> EC console shows error 2 returned > hcdebug on $ ectool hello --> EC console shows params and response as hex > hcdebug off $ ectool hello --> no extra output on EC debug console Original-Change-Id: I2dbc77be5b59125f394d970cf1c83c2a976e926e Signed-off-by: Randall Spangler (cherry picked from commit 903dc92ec1ae25a3807ad4ec673b412917e4cf28) Change-Id: Ic87c2338acbb0c102c99864a977b1363db692af3 Reviewed-on: https://gerrit.chromium.org/gerrit/29214 Reviewed-by: Randall Spangler Tested-by: Randall Spangler --- common/host_command.c | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/common/host_command.c b/common/host_command.c index df83e9f00b..088f8e8521 100644 --- a/common/host_command.c +++ b/common/host_command.c @@ -28,6 +28,8 @@ static struct host_cmd_handler_args *pending_args; static uint8_t host_memmap[EC_MEMMAP_SIZE]; #endif +static int hcdebug; /* Enable extra host command debug output */ + uint8_t *host_get_memmap(int offset) { #ifdef CONFIG_LPC @@ -181,16 +183,29 @@ DECLARE_HOST_COMMAND(EC_CMD_GET_CMD_VERSIONS, enum ec_status host_command_process(struct host_cmd_handler_args *args) { const struct host_command *cmd = find_host_command(args->command); + enum ec_status rv; - CPRINTF("[%T hostcmd 0x%02x]\n", args->command); + if (hcdebug && args->params_size) + CPRINTF("[%T HC 0x%02x:%.*h]\n", args->command, + args->params_size, args->params); + else + CPRINTF("[%T HC 0x%02x]\n", args->command); if (!cmd) - return EC_RES_INVALID_COMMAND; + rv = EC_RES_INVALID_COMMAND; + else if (!(EC_VER_MASK(args->version) & cmd->version_mask)) + rv = EC_RES_INVALID_VERSION; + else + rv = cmd->handler(args); - if (!(EC_VER_MASK(args->version) & cmd->version_mask)) - return EC_RES_INVALID_VERSION; + if (rv != EC_RES_SUCCESS) { + CPRINTF("[%T HC err %d]\n", rv); + } else if (hcdebug && args->response_size) { + CPRINTF("[%T HC resp:%.*h]\n", + args->response_size, args->response); + } - return cmd->handler(args); + return rv; } /*****************************************************************************/ @@ -315,3 +330,22 @@ DECLARE_CONSOLE_COMMAND(hostcmd, command_host_command, "cmd ver param", "Fake host command", NULL); + +static int command_hcdebug(int argc, char **argv) +{ + if (argc > 1) { + if (!strcasecmp(argv[1], "on")) + hcdebug = 1; + else if (!strcasecmp(argv[1], "off")) + hcdebug = 0; + else + return EC_ERROR_PARAM1; + } + + ccprintf("Host command debug is %s\n", hcdebug ? "on" : "off"); + return EC_SUCCESS; +} +DECLARE_CONSOLE_COMMAND(hcdebug, command_hcdebug, + "hcdebug [on | off]", + "Toggle extra host command debug output", + NULL); -- cgit v1.2.1