summaryrefslogtreecommitdiff
path: root/common/usb_i2c.c
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2017-07-25 16:22:27 -0700
committerchrome-bot <chrome-bot@chromium.org>2017-07-31 21:39:39 -0700
commit00ea73ab166ebc8a2c4b5693b7fa776c76c7fe45 (patch)
treec99009ec5bce12c97a85a32695bd7f0f435c1e2c /common/usb_i2c.c
parentddbfe690e294e595c6ed3511dcf417410d9b2804 (diff)
downloadchrome-ec-00ea73ab166ebc8a2c4b5693b7fa776c76c7fe45.tar.gz
usb_i2c: Fail if board I2C bridge is disabled
Add usb_i2c_board_is_enabled(). On Cr50, this is now also connected to the I2C CCD capability. The USB-I2C bridge can only be used when the capability is available. On other platforms (Servo V4, etc.) where usb_i2c_board_enable() is a no-op, add a dummy implementation which always returns true. See go/cr50-ccd-wp for more information. BUG=b:62537474 BRANCH=cr50 TEST=manual with CR50_DEV=1 Connect host PC to dev board USB port On host PC: sudo servod -c ccd_cr50.xml -c reef_r1_inas.xml dut-control pp3300_ec_shv_reg --> fail, error 0x8001 ccdoops --> reset I2C config ccd i2c disable --> I2C disabled On host PC: sudo servod -c ccd_cr50.xml -c reef_r1_inas.xml dut-control pp3300_ec_shv_reg --> fail, error 0x0006 ccd i2c enable --> I2C enabled ccdunlock --> I2C disabled ccdoops --> I2C enabled ccdset i2c unlesslocked ccdlock --> I2C disabled ccdunlock --> I2C enabled Change-Id: Ia3df32e239a5f7c5915bc6c7e408ce0dc8b26c89 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/590577 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Mary Ruthven <mruthven@chromium.org>
Diffstat (limited to 'common/usb_i2c.c')
-rw-r--r--common/usb_i2c.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/common/usb_i2c.c b/common/usb_i2c.c
index 64d7135a89..a6f5acc99c 100644
--- a/common/usb_i2c.c
+++ b/common/usb_i2c.c
@@ -90,7 +90,9 @@ void usb_i2c_execute(struct usb_i2c_config const *config)
if (!count || (!read_count && !write_count))
return;
- if (write_count > CONFIG_USB_I2C_MAX_WRITE_COUNT ||
+ if (!usb_i2c_board_is_enabled()) {
+ config->buffer[0] = USB_I2C_DISABLED;
+ } else if (write_count > CONFIG_USB_I2C_MAX_WRITE_COUNT ||
write_count != (count - 4)) {
config->buffer[0] = USB_I2C_WRITE_COUNT_INVALID;
} else if (read_count > USB_I2C_MAX_READ_COUNT) {
@@ -98,6 +100,12 @@ void usb_i2c_execute(struct usb_i2c_config const *config)
} else if (portindex >= i2c_ports_used) {
config->buffer[0] = USB_I2C_PORT_INVALID;
} else {
+ /*
+ * TODO (crbug.com/750397): Add security. This currently
+ * blindly passes through ALL I2C commands on any bus the EC
+ * knows about. It should behave closer to
+ * EC_CMD_I2C_PASSTHRU, which can protect ports and ranges.
+ */
port = i2c_ports[portindex].port;
config->buffer[0] = usb_i2c_map_error(
i2c_xfer(port, slave_addr,