diff options
author | Yi Chou <yich@google.com> | 2022-09-27 18:29:50 +0800 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-09-28 08:40:49 +0000 |
commit | 5c4cfb226932720387b79f21e36595a4a122542c (patch) | |
tree | 591377852ae72c297d56becd71ef45dc9e3fe2e9 | |
parent | 9504a20e83033e996b09719aef22ec9722a591cd (diff) | |
download | chrome-ec-5c4cfb226932720387b79f21e36595a4a122542c.tar.gz |
util/ectool.c: Support cmdversions v1
There are some EC_CMD are greater than 0xFF (e.g. FP. PD...), the ectool
should support the v1 cmdversion to get the command version for those 16
bits command code command.
BUG=b:248508087
TEST=ectool --name cros_fp cmdversions 0x400
BRANCH=none
Signed-off-by: Yi Chou <yich@google.com>
Change-Id: I07c6e9b3d0472259e0899807ca699efa1b00786f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3920539
Reviewed-by: Eric Yilun Lin <yllin@google.com>
-rw-r--r-- | util/ectool.cc | 57 |
1 files changed, 48 insertions, 9 deletions
diff --git a/util/ectool.cc b/util/ectool.cc index b05e75d14e..dc0ff723d8 100644 --- a/util/ectool.cc +++ b/util/ectool.cc @@ -984,10 +984,30 @@ int cmd_inventory(int argc, char *argv[]) return 0; } -int cmd_cmdversions(int argc, char *argv[]) +static int get_cmdversions_v0(uint8_t cmd, uint32_t *version_mask) { struct ec_params_get_cmd_versions p; struct ec_response_get_cmd_versions r; + int rv; + + p.cmd = cmd; + rv = ec_command(EC_CMD_GET_CMD_VERSIONS, 0, &p, sizeof(p), &r, + sizeof(r)); + if (rv < 0) { + if (rv == -EC_RES_INVALID_PARAM) + printf("Command 0x%02x not supported by EC.\n", cmd); + + return rv; + } + + *version_mask = r.version_mask; + return 0; +} + +int cmd_cmdversions(int argc, char *argv[]) +{ + struct ec_params_get_cmd_versions_v1 p; + struct ec_response_get_cmd_versions r; char *e; int cmd; int rv; @@ -997,19 +1017,38 @@ int cmd_cmdversions(int argc, char *argv[]) return -1; } cmd = strtol(argv[1], &e, 0); - if ((e && *e) || cmd < 0 || cmd > 0xff) { + if ((e && *e) || cmd < 0 || cmd > 0xffff) { fprintf(stderr, "Bad command number.\n"); return -1; } - p.cmd = cmd; - rv = ec_command(EC_CMD_GET_CMD_VERSIONS, 0, &p, sizeof(p), &r, - sizeof(r)); - if (rv < 0) { - if (rv == -EC_RES_INVALID_PARAM) - printf("Command 0x%02x not supported by EC.\n", cmd); + if (cmd > 0xff) { + /* Ensure the EC support GET_CMD_VERSIONS v1. */ + rv = get_cmdversions_v0(EC_CMD_GET_CMD_VERSIONS, + &r.version_mask); + if (rv < 0) + return rv; - return rv; + if (!(r.version_mask & EC_VER_MASK(1))) { + printf("16 bits cmdversions not supported by EC.\n"); + return -1; + } + + /* Use GET_CMD_VERSIONS v1. */ + p.cmd = cmd; + rv = ec_command(EC_CMD_GET_CMD_VERSIONS, 1, &p, sizeof(p), &r, + sizeof(r)); + if (rv < 0) { + if (rv == -EC_RES_INVALID_PARAM) + printf("Command 0x%02x not supported by EC.\n", + cmd); + + return rv; + } + } else { + rv = get_cmdversions_v0(cmd, &r.version_mask); + if (rv < 0) + return rv; } printf("Command 0x%02x supports version mask 0x%08x\n", cmd, |