summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Marheine <pmarheine@chromium.org>2021-12-02 15:31:46 +1100
committerCommit Bot <commit-bot@chromium.org>2021-12-08 02:49:59 +0000
commit4c170fe6c0299023884a063ffbdc7e54cc515743 (patch)
treeb3544887b4af3ec4cf3432f0fa0d7be9c37edec3
parent517800e82a8c3c6a2441e2cc26bbb9ea08b394de (diff)
downloadchrome-ec-4c170fe6c0299023884a063ffbdc7e54cc515743.tar.gz
zephyr: use a chosen device for bbram shim
Rather than assume the bbram device is named 'bbram', get the device from a chosen cros-ec,bbram node instead. To accommodate this in testing, this also converts the system test that exercises bbram shimming to use a Zephyr emulated bbram device rather than rolling its own that replaces the one in the shim only. An unused include file is also removed. BUG=b:205615358 TEST=zmake testall BRANCH=none Change-Id: I68c31b7be6b63c065ada65aba3b49ec0e6df7448 Signed-off-by: Peter Marheine <pmarheine@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3312509 Reviewed-by: Yuval Peress <peress@google.com> Reviewed-by: Keith Short <keithshort@chromium.org>
-rw-r--r--zephyr/include/cros/ite/it8xxx2.dtsi1
-rw-r--r--zephyr/include/cros/nuvoton/npcx.dtsi1
-rw-r--r--zephyr/shim/include/bbram.h16
-rw-r--r--zephyr/shim/src/system.c10
-rw-r--r--zephyr/test/system/overlay.dts10
-rw-r--r--zephyr/test/system/prj.conf6
-rw-r--r--zephyr/test/system/test_system.c37
7 files changed, 32 insertions, 49 deletions
diff --git a/zephyr/include/cros/ite/it8xxx2.dtsi b/zephyr/include/cros/ite/it8xxx2.dtsi
index 1bd3dcfbf8..35676e03ce 100644
--- a/zephyr/include/cros/ite/it8xxx2.dtsi
+++ b/zephyr/include/cros/ite/it8xxx2.dtsi
@@ -8,6 +8,7 @@
/ {
chosen {
cros-ec,adc = &adc0;
+ cros-ec,bbram = &bbram;
cros-ec,espi = &espi0;
cros-ec,flash = &fiu0;
cros-ec,watchdog = &twd0;
diff --git a/zephyr/include/cros/nuvoton/npcx.dtsi b/zephyr/include/cros/nuvoton/npcx.dtsi
index d4103a2bdc..eecc533c74 100644
--- a/zephyr/include/cros/nuvoton/npcx.dtsi
+++ b/zephyr/include/cros/nuvoton/npcx.dtsi
@@ -12,6 +12,7 @@
/ {
chosen {
cros-ec,adc = &adc0;
+ cros-ec,bbram = &bbram;
cros-ec,espi = &espi0;
cros-ec,flash = &fiu0;
cros-ec,watchdog = &twd0;
diff --git a/zephyr/shim/include/bbram.h b/zephyr/shim/include/bbram.h
deleted file mode 100644
index 3eba4b157b..0000000000
--- a/zephyr/shim/include/bbram.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/* Copyright 2021 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef ZEPHYR_SHIM_INCLUDE_BBRAM_H_
-#define ZEPHYR_SHIM_INCLUDE_BBRAM_H_
-
-#include <devicetree.h>
-
-#define BBRAM_SIZE DT_REG_SIZE_BY_NAME(DT_NODELABEL(bbram), memory)
-#define BBRAM_ADDR DT_REG_ADDR_BY_NAME(DT_NODELABEL(bbram), memory)
-#define BBRAM(offset) REG8(BBRAM_ADDR + offset)
-#define BBRAM_BKUP_STS BBRAM(CONFIG_BBRAM_BKUP_STS)
-
-#endif /* ZEPHYR_SHIM_INCLUDE_BBRAM_H_ */
diff --git a/zephyr/shim/src/system.c b/zephyr/shim/src/system.c
index 8db8ba437a..802da6c838 100644
--- a/zephyr/shim/src/system.c
+++ b/zephyr/shim/src/system.c
@@ -8,7 +8,6 @@
#include <drivers/cros_system.h>
#include <logging/log.h>
-#include "bbram.h"
#include "common.h"
#include "console.h"
#include "cros_version.h"
@@ -31,7 +30,9 @@
LOG_MODULE_REGISTER(shim_system, LOG_LEVEL_ERR);
-STATIC_IF_NOT(CONFIG_ZTEST) const struct device *bbram_dev;
+static const struct device *const bbram_dev =
+ COND_CODE_1(DT_HAS_CHOSEN(cros_ec_bbram),
+ DEVICE_DT_GET(DT_CHOSEN(cros_ec_bbram)), NULL);
static const struct device *sys_dev;
/* Map idx to a bbram offset/size, or return -1 on invalid idx */
@@ -326,13 +327,10 @@ static int system_preinitialize(const struct device *unused)
{
ARG_UNUSED(unused);
-#if DT_NODE_EXISTS(DT_NODELABEL(bbram))
- bbram_dev = DEVICE_DT_GET(DT_NODELABEL(bbram));
- if (!device_is_ready(bbram_dev)) {
+ if (bbram_dev && !device_is_ready(bbram_dev)) {
LOG_ERR("Error: device %s is not ready", bbram_dev->name);
return -1;
}
-#endif
sys_dev = device_get_binding("CROS_SYSTEM");
if (!sys_dev) {
diff --git a/zephyr/test/system/overlay.dts b/zephyr/test/system/overlay.dts
index 37bac97680..bba99a0b81 100644
--- a/zephyr/test/system/overlay.dts
+++ b/zephyr/test/system/overlay.dts
@@ -4,6 +4,16 @@
*/
/ {
+ chosen {
+ cros-ec,bbram = &bbram;
+ };
+
+ bbram: test-bbram-dev {
+ compatible = "zephyr,bbram-emul";
+ label = "TEST_BBRAM_DEV";
+ size = <64>;
+ };
+
named-bbram-regions {
compatible = "named-bbram-regions";
pd0 {
diff --git a/zephyr/test/system/prj.conf b/zephyr/test/system/prj.conf
index 03357fa10f..4b3055b39b 100644
--- a/zephyr/test/system/prj.conf
+++ b/zephyr/test/system/prj.conf
@@ -1,4 +1,10 @@
+# Copyright 2021 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
CONFIG_ZTEST=y
CONFIG_PLATFORM_EC=y
CONFIG_CROS_EC=y
CONFIG_LOG=y
+CONFIG_BBRAM=y
+CONFIG_BBRAM_EMUL=y
diff --git a/zephyr/test/system/test_system.c b/zephyr/test/system/test_system.c
index e8eba44fc8..96befde553 100644
--- a/zephyr/test/system/test_system.c
+++ b/zephyr/test/system/test_system.c
@@ -8,7 +8,6 @@
#include <logging/log.h>
#include <ztest.h>
-#include "bbram.h"
#include "system.h"
LOG_MODULE_REGISTER(test);
@@ -21,50 +20,34 @@ LOG_MODULE_REGISTER(test);
static char mock_data[64] =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@";
-static int mock_bbram_read(const struct device *unused, size_t offset,
- size_t size, uint8_t *data)
-{
- if (offset < 0 || offset + size >= ARRAY_SIZE(mock_data))
- return -1;
- memcpy(data, mock_data + offset, size);
- return EC_SUCCESS;
-}
-
-static const struct bbram_driver_api bbram_api = {
- .read = mock_bbram_read,
-};
-
-static const struct device bbram_dev_instance = {
- .name = "TEST_BBRAM_DEV",
- .config = NULL,
- .api = &bbram_api,
- .data = NULL,
-};
-
-const struct device *bbram_dev = &bbram_dev_instance;
-
static void test_bbram_get(void)
{
+ const struct device *const bbram_dev =
+ DEVICE_DT_GET(DT_CHOSEN(cros_ec_bbram));
uint8_t output[10];
int rc;
+ /* Write expected data to read back */
+ rc = bbram_write(bbram_dev, 0, ARRAY_SIZE(mock_data), mock_data);
+ zassert_ok(rc, NULL);
+
rc = system_get_bbram(SYSTEM_BBRAM_IDX_PD0, output);
- zassert_equal(rc, 0, NULL);
+ zassert_ok(rc, NULL);
zassert_mem_equal(output, mock_data + BBRAM_REGION_OFF(pd0),
BBRAM_REGION_SIZE(pd0), NULL);
rc = system_get_bbram(SYSTEM_BBRAM_IDX_PD1, output);
- zassert_equal(rc, 0, NULL);
+ zassert_ok(rc, NULL);
zassert_mem_equal(output, mock_data + BBRAM_REGION_OFF(pd1),
BBRAM_REGION_SIZE(pd1), NULL);
rc = system_get_bbram(SYSTEM_BBRAM_IDX_PD2, output);
- zassert_equal(rc, 0, NULL);
+ zassert_ok(rc, NULL);
zassert_mem_equal(output, mock_data + BBRAM_REGION_OFF(pd2),
BBRAM_REGION_SIZE(pd2), NULL);
rc = system_get_bbram(SYSTEM_BBRAM_IDX_TRY_SLOT, output);
- zassert_equal(rc, 0, NULL);
+ zassert_ok(rc, NULL);
zassert_mem_equal(output, mock_data + BBRAM_REGION_OFF(try_slot),
BBRAM_REGION_SIZE(try_slot), NULL);
}