diff options
author | Fabio Baltieri <fabiobaltieri@google.com> | 2022-11-02 12:33:02 +0000 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-11-09 19:08:47 +0000 |
commit | df7862fa54ab94007110e1683351ee8d24a74f9a (patch) | |
tree | 0d04ab53d45a9fdc65067aaf9abab1723e478473 | |
parent | 85e2dd2916894347fb627d57bd0e7c2a517d3124 (diff) | |
download | chrome-ec-df7862fa54ab94007110e1683351ee8d24a74f9a.tar.gz |
zephyr: cbi_eeprom: stop silently drop the code if misconfigured
Change the cbi_eeprom code to not get blanked if enabled but no eeprom
device is defined, fire a build warning instead. Also make sure that the
device is ready before trying to use it.
BRANCH=none
BUG=none
TEST=cq dry run
Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
Change-Id: I9c3a00be98c40ea8c1be307ef02c08c856aa770f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3999729
Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
Reviewed-by: Al Semjonovs <asemjonovs@google.com>
-rw-r--r-- | zephyr/shim/src/cbi/cbi_eeprom.c | 29 | ||||
-rw-r--r-- | zephyr/test/drivers/boards/native_posix.overlay | 6 | ||||
-rw-r--r-- | zephyr/test/drivers/common_cbi/src/test_common_cbi.c | 11 | ||||
-rw-r--r-- | zephyr/test/drivers/testcase.yaml | 1 |
4 files changed, 40 insertions, 7 deletions
diff --git a/zephyr/shim/src/cbi/cbi_eeprom.c b/zephyr/shim/src/cbi/cbi_eeprom.c index ecc78ba41e..652c76f959 100644 --- a/zephyr/shim/src/cbi/cbi_eeprom.c +++ b/zephyr/shim/src/cbi/cbi_eeprom.c @@ -10,8 +10,9 @@ #include "cros_board_info.h" #include "write_protect.h" -#if DT_NODE_EXISTS(DT_NODELABEL(cbi_eeprom)) -#define CBI_EEPROM_DEV DEVICE_DT_GET(DT_NODELABEL(cbi_eeprom)) +#define CBI_EEPROM_NODE DT_NODELABEL(cbi_eeprom) + +BUILD_ASSERT(DT_NODE_EXISTS(CBI_EEPROM_NODE), "cbi_eeprom node not defined"); #ifdef CONFIG_PLATFORM_EC_EEPROM_CBI_WP #if !DT_NODE_EXISTS(DT_ALIAS(gpio_cbi_wp)) @@ -27,20 +28,37 @@ void cbi_latch_eeprom_wp(void) test_mockable_static int eeprom_load(uint8_t offset, uint8_t *data, int len) { - return eeprom_read(CBI_EEPROM_DEV, offset, data, len); + const struct device *dev; + + dev = DEVICE_DT_GET(CBI_EEPROM_NODE); + + if (!device_is_ready(dev)) { + return -ENODEV; + } + + return eeprom_read(dev, offset, data, len); } static int eeprom_is_write_protected(void) { - if (IS_ENABLED(CONFIG_PLATFORM_EC_BYPASS_CBI_EEPROM_WP_CHECK)) + if (IS_ENABLED(CONFIG_PLATFORM_EC_BYPASS_CBI_EEPROM_WP_CHECK)) { return 0; + } return write_protect_is_asserted(); } static int eeprom_store(uint8_t *cbi) { - return eeprom_write(CBI_EEPROM_DEV, 0, cbi, + const struct device *dev; + + dev = DEVICE_DT_GET(CBI_EEPROM_NODE); + + if (!device_is_ready(dev)) { + return -ENODEV; + } + + return eeprom_write(dev, 0, cbi, ((struct cbi_header *)cbi)->total_size); } @@ -54,4 +72,3 @@ const struct cbi_storage_config_t cbi_config = { .storage_type = CBI_STORAGE_TYPE_EEPROM, .drv = &eeprom_drv, }; -#endif diff --git a/zephyr/test/drivers/boards/native_posix.overlay b/zephyr/test/drivers/boards/native_posix.overlay index 3a0461badd..0a8547930d 100644 --- a/zephyr/test/drivers/boards/native_posix.overlay +++ b/zephyr/test/drivers/boards/native_posix.overlay @@ -27,6 +27,7 @@ bmi160-int = &ms_bmi160_accel; tcs3400-int = &tcs3400_clear; gpio-wp = &gpio_wp_l; + gpio-cbi-wp = &gpio_ec_cbi_wp; gpio-kbd-kso2 = &gpio_ec_kso_02_inv; }; @@ -236,6 +237,9 @@ gpio_brd_id0: brd_id0 { gpios = <&gpio1 8 GPIO_INPUT>; }; + gpio_ec_cbi_wp: ec_cbi_wp { + gpios = <&gpio1 9 GPIO_OUTPUT>; + }; }; gpio1: gpio@101 { @@ -248,7 +252,7 @@ low-level; gpio-controller; #gpio-cells = <2>; - ngpios = <9>; + ngpios = <10>; }; gpio-interrupts { diff --git a/zephyr/test/drivers/common_cbi/src/test_common_cbi.c b/zephyr/test/drivers/common_cbi/src/test_common_cbi.c index ab29f7c2e6..fcd5624e09 100644 --- a/zephyr/test/drivers/common_cbi/src/test_common_cbi.c +++ b/zephyr/test/drivers/common_cbi/src/test_common_cbi.c @@ -34,6 +34,17 @@ static int __test_eeprom_load_default_impl(uint8_t offset, uint8_t *data, return ret; } +ZTEST(common_cbi, test_cbi_latch_eeprom_wp) +{ + const struct gpio_dt_spec *wp = GPIO_DT_FROM_ALIAS(gpio_cbi_wp); + + zassert_equal(gpio_emul_output_get(wp->port, wp->pin), 0); + + cbi_latch_eeprom_wp(); + + zassert_equal(gpio_emul_output_get(wp->port, wp->pin), 1); +} + ZTEST(common_cbi, test_do_cbi_read__cant_load_head) { enum cbi_data_tag arbitrary_unused_tag = CBI_TAG_SKU_ID; diff --git a/zephyr/test/drivers/testcase.yaml b/zephyr/test/drivers/testcase.yaml index 48317113c9..f364612897 100644 --- a/zephyr/test/drivers/testcase.yaml +++ b/zephyr/test/drivers/testcase.yaml @@ -45,6 +45,7 @@ tests: drivers.common_cbi: extra_configs: - CONFIG_LINK_TEST_SUITE_COMMON_CBI=y + - CONFIG_PLATFORM_EC_EEPROM_CBI_WP=y drivers.common_cbi_gpio: extra_configs: - CONFIG_LINK_TEST_SUITE_COMMON_CBI_GPIO=y |