summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Honscheid <honscheid@google.com>2021-10-29 11:03:51 -0600
committerCommit Bot <commit-bot@chromium.org>2021-11-02 21:06:04 +0000
commit644fdfdcc5f4bd133af431abdaaf6ea6741bd4d8 (patch)
tree9298b3e89b70d2b4247822c9afc5622779e0094a
parente88d582ee2f34f2423525a96d650c0da58506b4a (diff)
downloadchrome-ec-644fdfdcc5f4bd133af431abdaaf6ea6741bd4d8.tar.gz
zephyr: Add Kconfig for init_rom region
Add support for setting CONFIG_CHIP_INIT_ROM_REGION in unit tests. Add FFF mocks for init_rom functions. BRANCH=None BUG=b:184856157 TEST=zmake configure --test zephyr/test/drivers Signed-off-by: Tristan Honscheid <honscheid@google.com> Change-Id: Ife649a4341381dbe2f5e10b87fa767ed14b6bc5f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3252365 Reviewed-by: Yuval Peress <peress@google.com>
-rw-r--r--include/init_rom.h24
-rw-r--r--zephyr/Kconfig6
-rw-r--r--zephyr/shim/include/config_chip.h21
-rw-r--r--zephyr/test/drivers/include/test_mocks.h11
-rw-r--r--zephyr/test/drivers/prj.conf1
-rw-r--r--zephyr/test/drivers/src/test_mocks.c13
6 files changed, 66 insertions, 10 deletions
diff --git a/include/init_rom.h b/include/init_rom.h
index 2c1ab33cd5..84fe53d4ff 100644
--- a/include/init_rom.h
+++ b/include/init_rom.h
@@ -14,7 +14,6 @@
#include "stdbool.h"
-#ifdef CONFIG_CHIP_INIT_ROM_REGION
/**
* Get the memory mapped address of an .init_rom data object.
*
@@ -27,7 +26,14 @@
* @return Pointer to data object in memory. Return NULL if the object
* is not memory mapped.
*/
+#ifdef CONFIG_CHIP_INIT_ROM_REGION
const void *init_rom_map(const void *addr, int size);
+#else
+static inline const void *init_rom_map(const void *addr, int size)
+{
+ return addr;
+}
+#endif
/**
* Unmaps an .init_rom data object. Must be called when init_rom_map() is
@@ -36,7 +42,13 @@ const void *init_rom_map(const void *addr, int size);
* @param offset Address of the data object assigned by the linker.
* @param size Size of the data object.
*/
+#ifdef CONFIG_CHIP_INIT_ROM_REGION
void init_rom_unmap(const void *addr, int size);
+#else
+static inline void init_rom_unmap(const void *addr, int size)
+{
+}
+#endif
/**
* Copy an .init_rom data object into a RAM location. This routine must be used
@@ -49,17 +61,9 @@ void init_rom_unmap(const void *addr, int size);
*
* @return 0 on success.
*/
+#ifdef CONFIG_CHIP_INIT_ROM_REGION
int init_rom_copy(int offset, int size, char *data);
#else
-static inline const void *init_rom_map(const void *addr, int size)
-{
- return addr;
-}
-
-static inline void init_rom_unmap(const void *addr, int size)
-{
-}
-
static inline int init_rom_copy(int offset, int size, char *data)
{
return 0;
diff --git a/zephyr/Kconfig b/zephyr/Kconfig
index 8647c1bfac..e80a10d476 100644
--- a/zephyr/Kconfig
+++ b/zephyr/Kconfig
@@ -219,6 +219,12 @@ config PLATFORM_EC_CHIPSET_RESUME_INIT_HOOK
Require to initialize it first such that it can receive a host resume
event, that notifies the normal resume hook.
+config PLATFORM_EC_CHIP_INIT_ROM_REGION
+ bool "Enables the use of a dedicated init ROM region"
+ help
+ Enable this flag if the board has a `.init_rom` region. This will
+ activate routines in `init_rom.h` to access objects in this region.
+
config PLATFORM_EC_CONSOLE_CMD_HCDEBUG
bool "Console command: hcdebug"
default y
diff --git a/zephyr/shim/include/config_chip.h b/zephyr/shim/include/config_chip.h
index 59593665c1..63f1ed6cdf 100644
--- a/zephyr/shim/include/config_chip.h
+++ b/zephyr/shim/include/config_chip.h
@@ -303,6 +303,11 @@
#define CONFIG_CHIPSET_RESUME_INIT_HOOK
#endif
+#undef CONFIG_CHIP_INIT_ROM_REGION
+#ifdef CONFIG_PLATFORM_EC_CHIP_INIT_ROM_REGION
+#define CONFIG_CHIP_INIT_ROM_REGION
+#endif
+
#ifdef CONFIG_PLATFORM_EC_EXTPOWER_GPIO
#define CONFIG_EXTPOWER_GPIO
@@ -366,6 +371,22 @@
#define CONFIG_RO_SIZE CONFIG_CROS_EC_RO_SIZE
#define CONFIG_RW_SIZE CONFIG_CROS_EC_RW_SIZE
+/*
+ * ROM resident area in flash used to store data objects that are not copied
+ * into code RAM. Enable using the CONFIG_CHIP_INIT_ROM_REGION option.
+ */
+#define CONFIG_RO_ROM_RESIDENT_MEM_OFF CONFIG_RO_SIZE
+#define CONFIG_RO_ROM_RESIDENT_SIZE \
+ (CONFIG_EC_PROTECTED_STORAGE_SIZE - CONFIG_RO_SIZE)
+
+/*
+ * RW firmware in program memory - Identical to RO, only one image loaded at
+ * a time.
+ */
+#define CONFIG_RW_ROM_RESIDENT_MEM_OFF CONFIG_RW_SIZE
+#define CONFIG_RW_ROM_RESIDENT_SIZE \
+ (CONFIG_EC_WRITABLE_STORAGE_SIZE - CONFIG_RW_SIZE)
+
/* Flash settings */
#undef CONFIG_EXTERNAL_STORAGE
#undef CONFIG_INTERNAL_STORAGE
diff --git a/zephyr/test/drivers/include/test_mocks.h b/zephyr/test/drivers/include/test_mocks.h
new file mode 100644
index 0000000000..8ce47014cf
--- /dev/null
+++ b/zephyr/test/drivers/include/test_mocks.h
@@ -0,0 +1,11 @@
+/* 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.
+ */
+
+#include <fff.h>
+
+/* Mocks for common/init_rom.c */
+DECLARE_FAKE_VALUE_FUNC(const void *, init_rom_map, const void *, int);
+DECLARE_FAKE_VOID_FUNC(init_rom_unmap, const void *, int);
+DECLARE_FAKE_VALUE_FUNC(int, init_rom_copy, int, int, int);
diff --git a/zephyr/test/drivers/prj.conf b/zephyr/test/drivers/prj.conf
index e5dceeec85..c2931fbf77 100644
--- a/zephyr/test/drivers/prj.conf
+++ b/zephyr/test/drivers/prj.conf
@@ -59,6 +59,7 @@ CONFIG_PLATFORM_EC_CHARGER_SENSE_RESISTOR=10
CONFIG_PLATFORM_EC_CHARGER_SENSE_RESISTOR_AC=10
CONFIG_PLATFORM_EC_CHARGER_ISL9238=y
CONFIG_PLATFORM_EC_CHARGER_ISL9241=y
+CONFIG_PLATFORM_EC_CHIP_INIT_ROM_REGION=y
CONFIG_PLATFORM_EC_USB_PD_VBUS_MEASURE_CHARGER=y
CONFIG_PLATFORM_EC_BATTERY_FUEL_GAUGE=y
CONFIG_PLATFORM_EC_HOSTCMD=y
diff --git a/zephyr/test/drivers/src/test_mocks.c b/zephyr/test/drivers/src/test_mocks.c
new file mode 100644
index 0000000000..7b25bcfa3e
--- /dev/null
+++ b/zephyr/test/drivers/src/test_mocks.c
@@ -0,0 +1,13 @@
+/* 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.
+ */
+
+#include "test_mocks.h"
+
+DEFINE_FFF_GLOBALS;
+
+/* Mocks for common/init_rom.c */
+DEFINE_FAKE_VALUE_FUNC(const void *, init_rom_map, const void *, int);
+DEFINE_FAKE_VOID_FUNC(init_rom_unmap, const void *, int);
+DEFINE_FAKE_VALUE_FUNC(int, init_rom_copy, int, int, int);