diff options
-rw-r--r-- | common/host_command.c | 17 | ||||
-rw-r--r-- | include/ec_commands.h | 17 | ||||
-rw-r--r-- | util/comm-dev.c | 11 | ||||
-rw-r--r-- | util/cros_ec_dev.h | 2 | ||||
-rw-r--r-- | util/ectool.c | 34 |
5 files changed, 78 insertions, 3 deletions
diff --git a/common/host_command.c b/common/host_command.c index bf310991b6..fe270d013a 100644 --- a/common/host_command.c +++ b/common/host_command.c @@ -525,6 +525,23 @@ DECLARE_HOST_COMMAND(EC_CMD_RESEND_RESPONSE, EC_VER_MASK(0)); #endif /* CONFIG_HOST_COMMAND_STATUS */ +/* Returns what we tell it to. */ +static int host_command_test_protocol(struct host_cmd_handler_args *args) +{ + const struct ec_params_test_protocol *p = args->params; + struct ec_response_test_protocol *r = args->response; + int copy_len = MIN(p->ret_len, sizeof(r->buf)); /* p,r bufs same size */ + + memset(r->buf, 0, sizeof(r->buf)); + memcpy(r->buf, p->buf, copy_len); + args->response_size = p->ret_len; + + return p->ec_result; +} +DECLARE_HOST_COMMAND(EC_CMD_TEST_PROTOCOL, + host_command_test_protocol, + EC_VER_MASK(0)); + /*****************************************************************************/ /* Console commands */ diff --git a/include/ec_commands.h b/include/ec_commands.h index d17bb444d9..f1792af1b1 100644 --- a/include/ec_commands.h +++ b/include/ec_commands.h @@ -484,6 +484,23 @@ struct ec_response_get_comms_status { uint32_t flags; /* Mask of enum ec_comms_status */ } __packed; +/* + * Fake a variety of responses, purely for testing purposes. + * FIXME: Would be nice to force checksum errors. + */ +#define EC_CMD_TEST_PROTOCOL 0x0a + +/* Tell the EC what to send back to us. */ +struct ec_params_test_protocol { + uint32_t ec_result; + uint32_t ret_len; + uint8_t buf[32]; +} __packed; + +/* Here it comes... */ +struct ec_response_test_protocol { + uint8_t buf[32]; +} __packed; /*****************************************************************************/ /* Flash commands */ diff --git a/util/comm-dev.c b/util/comm-dev.c index 2802aeca24..4dae913a82 100644 --- a/util/comm-dev.c +++ b/util/comm-dev.c @@ -24,6 +24,7 @@ static int ec_command_dev(int command, int version, void *indata, int insize) { struct cros_ec_command s_cmd; + int r; s_cmd.command = command; s_cmd.version = version; @@ -33,8 +34,14 @@ static int ec_command_dev(int command, int version, s_cmd.insize = insize; s_cmd.indata = indata; - if (ioctl(fd, CROS_EC_DEV_IOCXCMD, &s_cmd)) - return -1; + r = ioctl(fd, CROS_EC_DEV_IOCXCMD, &s_cmd); + if (r < 0) { + fprintf(stderr, "ioctl %d, errno %d (%s), EC result %d\n", + r, errno, strerror(errno), s_cmd.result); + return r; + } + if (s_cmd.result != EC_RES_SUCCESS) + fprintf(stderr, "EC result %d\n", s_cmd.result); return s_cmd.insize; } diff --git a/util/cros_ec_dev.h b/util/cros_ec_dev.h index f56c3ef67f..f6f5a5542c 100644 --- a/util/cros_ec_dev.h +++ b/util/cros_ec_dev.h @@ -19,7 +19,7 @@ * @outdata: Outgoing data to EC * @outsize: Outgoing length in bytes * @indata: Where to put the incoming data from EC - * @insize: Incoming length in bytes (filled in by EC) + * @insize: On call, how much we can accept. On return, how much we got. * @result: EC's response to the command (separate from communication failure) * ioctl returns zero on success, negative on error */ diff --git a/util/ectool.c b/util/ectool.c index 94a5f3d4ef..1c5a424e61 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -329,6 +329,39 @@ int cmd_hello(int argc, char *argv[]) return 0; } +int cmd_test(int argc, char *argv[]) +{ + struct ec_params_test_protocol p = { + .buf = "0123456789abcdef0123456789ABCDEF" + }; + struct ec_response_test_protocol r; + int rv; + char *e; + + if (argc < 3) { + fprintf(stderr, "Usage: %s result length\n", argv[0]); + return -1; + } + + p.ec_result = strtol(argv[1], &e, 0); + if (e && *e) { + fprintf(stderr, "invalid param (result)\n"); + return -1; + } + p.ret_len = strtol(argv[2], &e, 0); + if (e && *e) { + fprintf(stderr, "invalid param (length)\n"); + return -1; + } + + rv = ec_command(EC_CMD_TEST_PROTOCOL, 0, &p, sizeof(p), &r, sizeof(r)); + printf("rv = %d\n", rv); + + return rv; +} + + + int cmd_cmdversions(int argc, char *argv[]) { struct ec_params_get_cmd_versions p; @@ -3067,6 +3100,7 @@ const struct command commands[] = { {"switches", cmd_switches}, {"temps", cmd_temperature}, {"tempsinfo", cmd_temp_sensor_info}, + {"test", cmd_test}, {"thermalget", cmd_thermal_get_threshold}, {"thermalset", cmd_thermal_set_threshold}, {"tmp006cal", cmd_tmp006cal}, |