diff options
author | Nicolas Boichat <drinkcat@google.com> | 2016-05-19 08:58:47 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-05-24 19:23:27 -0700 |
commit | f5bba241fdcefcc0c1d2f82b097caa2923b3ccc5 (patch) | |
tree | 7844194da213c658c2558c54a966e4340e5f4246 /util | |
parent | d2bbc229f378b741bfc2ff0d2092d501531626a9 (diff) | |
download | chrome-ec-f5bba241fdcefcc0c1d2f82b097caa2923b3ccc5.tar.gz |
common/i2c: Add I2C passthru_protect command
This allows the AP to protect a I2C passthru bus. A board-specific
function then defines what I2C commands are allowed, so that we
can white/black list some addresses (e.g. I2C address allowing
PD chip FW updating).
BRANCH=none
BUG=chrome-os-partner:52431
TEST=Book elm-rev1
Change-Id: Ib106924418b16388ea8ea53c7b6bda6ef92e1d09
Signed-off-by: Nicolas Boichat <drinkcat@google.com>
Reviewed-on: https://chromium-review.googlesource.com/345761
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Randall Spangler <rspangler@google.com>
Diffstat (limited to 'util')
-rw-r--r-- | util/ectool.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/util/ectool.c b/util/ectool.c index 0e3c1ee596..f5787efcf2 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -123,6 +123,8 @@ const char help_str[] = " Simulate key press\n" " kbfactorytest\n" " Scan out keyboard if any pins are shorted\n" + " i2cprotect <port> [status]\n" + " Protect EC's I2C bus\n" " i2cread\n" " Read I2C bus\n" " i2cwrite\n" @@ -4880,6 +4882,50 @@ int cmd_wireless(int argc, char *argv[]) } +int cmd_i2c_protect(int argc, char *argv[]) +{ + struct ec_params_i2c_passthru_protect p; + char *e; + int rv; + + if (argc != 2 && (argc != 3 || strcmp(argv[2], "status"))) { + fprintf(stderr, "Usage: %s <port> [status]\n", + argv[0]); + return -1; + } + + p.port = strtol(argv[1], &e, 0); + if (e && *e) { + fprintf(stderr, "Bad port.\n"); + return -1; + } + + if (argc == 3) { + struct ec_response_i2c_passthru_protect r; + + p.subcmd = EC_CMD_I2C_PASSTHRU_PROTECT_STATUS; + + rv = ec_command(EC_CMD_I2C_PASSTHRU_PROTECT, 0, &p, sizeof(p), + &r, sizeof(r)); + + if (rv < 0) + return rv; + + printf("I2C port %d: %s (%d)\n", p.port, + r.status ? "Protected" : "Unprotected", r.status); + } else { + p.subcmd = EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE; + + rv = ec_command(EC_CMD_I2C_PASSTHRU_PROTECT, 0, &p, sizeof(p), + NULL, 0); + + if (rv < 0) + return rv; + } + return 0; +} + + int cmd_i2c_read(int argc, char *argv[]) { struct ec_params_i2c_read p; @@ -6656,6 +6702,7 @@ const struct command commands[] = { {"hello", cmd_hello}, {"hibdelay", cmd_hibdelay}, {"kbpress", cmd_kbpress}, + {"i2cprotect", cmd_i2c_protect}, {"i2cread", cmd_i2c_read}, {"i2cwrite", cmd_i2c_write}, {"i2cxfer", cmd_i2c_xfer}, |