summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2022-09-08 12:20:40 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-09-10 01:49:06 +0000
commit50fee8d0021835b2a41519f4e58fac7e2574846f (patch)
treeef1290fa0125ad08d8cd4f37693ddf857013a9b6
parent1e1cc37b4078e241f9b97fd50b5ebbcd3079ab33 (diff)
downloadchrome-ec-50fee8d0021835b2a41519f4e58fac7e2574846f.tar.gz
zephyr: Move the fake system functions into their own file
Move this out of the flash emulator so we can add to it and use it from other tests. Put it in a new 'fake' subdirectory, since we don't seem to have of this sort of thing yet. BUG=b:243982872 BRANCH=none TEST=./twister -c -T zephyr/test/drivers/ Signed-off-by: Simon Glass <sjg@chromium.org> Change-Id: Ia4cd3b10e2f38dbacadf0d20198be8f9bbc026e3 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3883773 Reviewed-by: Aaron Massey <aaronmassey@google.com> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
-rw-r--r--zephyr/CMakeLists.txt1
-rw-r--r--zephyr/Kconfig1
-rw-r--r--zephyr/emul/Kconfig1
-rw-r--r--zephyr/emul/emul_flash.c25
-rw-r--r--zephyr/fake/CMakeLists.txt7
-rw-r--r--zephyr/fake/Kconfig11
-rw-r--r--zephyr/fake/include/system_fake.h18
-rw-r--r--zephyr/fake/system_fake.c34
-rw-r--r--zephyr/include/emul/emul_flash.h5
-rw-r--r--zephyr/test/drivers/default/prj.conf1
10 files changed, 74 insertions, 30 deletions
diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt
index 92e488ab16..9182e0eb1c 100644
--- a/zephyr/CMakeLists.txt
+++ b/zephyr/CMakeLists.txt
@@ -563,6 +563,7 @@ add_subdirectory(linker)
add_subdirectory("app")
add_subdirectory("drivers")
add_subdirectory("emul")
+add_subdirectory("fake")
add_subdirectory("mock")
add_subdirectory_ifdef(CONFIG_PLATFORM_EC "shim")
diff --git a/zephyr/Kconfig b/zephyr/Kconfig
index 7678869f97..211f2e0152 100644
--- a/zephyr/Kconfig
+++ b/zephyr/Kconfig
@@ -5,6 +5,7 @@
rsource "app/Kconfig"
rsource "drivers/Kconfig"
rsource "emul/Kconfig"
+rsource "fake/Kconfig"
rsource "mock/Kconfig"
rsource "subsys/Kconfig"
diff --git a/zephyr/emul/Kconfig b/zephyr/emul/Kconfig
index eda680a4d4..55d13d217e 100644
--- a/zephyr/emul/Kconfig
+++ b/zephyr/emul/Kconfig
@@ -77,6 +77,7 @@ config EMUL_KB_RAW
config EMUL_CROS_FLASH
bool "Emulated flash driver for the Zephyr shim"
select PLATFORM_EC_FLASH_CROS
+ imply SYSTEM_FAKE
help
This option enables the flash emulator for testing.
diff --git a/zephyr/emul/emul_flash.c b/zephyr/emul/emul_flash.c
index 25a3f78018..2e2cb8da75 100644
--- a/zephyr/emul/emul_flash.c
+++ b/zephyr/emul/emul_flash.c
@@ -32,31 +32,6 @@ struct flash_emul_cfg {
/* Variables to emulate the protection */
bool ro_protected, all_protected;
-static enum ec_image shrspi_image_copy = EC_IMAGE_RO;
-
-void system_jump_to_booter(void)
-{
-}
-
-uint32_t system_get_lfw_address(void)
-{
- uint32_t jump_addr = (uint32_t)system_jump_to_booter;
- return jump_addr;
-}
-
-enum ec_image system_get_shrspi_image_copy(void)
-{
- return shrspi_image_copy;
-}
-
-void system_set_shrspi_image_copy(enum ec_image new_image_copy)
-{
- shrspi_image_copy = new_image_copy;
-}
-
-void system_set_image_copy(enum ec_image copy)
-{
-}
static int cros_flash_emul_init(const struct device *dev)
{
diff --git a/zephyr/fake/CMakeLists.txt b/zephyr/fake/CMakeLists.txt
new file mode 100644
index 0000000000..6b9f16bc20
--- /dev/null
+++ b/zephyr/fake/CMakeLists.txt
@@ -0,0 +1,7 @@
+# Copyright 2022 The ChromiumOS Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+zephyr_library_sources_ifdef(CONFIG_SYSTEM_FAKE system_fake.c)
+
+cros_ec_library_include_directories(include)
diff --git a/zephyr/fake/Kconfig b/zephyr/fake/Kconfig
new file mode 100644
index 0000000000..c5f6fef669
--- /dev/null
+++ b/zephyr/fake/Kconfig
@@ -0,0 +1,11 @@
+# Copyright 2022 The ChromiumOS Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+config SYSTEM_FAKE
+ bool "Use a fake system module"
+ help
+ This provides a fake implementation of some of the hooks used by
+ common/system.c so that EC reboots can be faked.
+
+ It should only be included in tests.
diff --git a/zephyr/fake/include/system_fake.h b/zephyr/fake/include/system_fake.h
new file mode 100644
index 0000000000..42fcc5d596
--- /dev/null
+++ b/zephyr/fake/include/system_fake.h
@@ -0,0 +1,18 @@
+/* Copyright 2022 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef ZEPHYR_FAKE_SYSTEM_FAKE_H
+#define ZEPHYR_FAKE_SYSTEM_FAKE_H
+
+#include <setjmp.h>
+
+#include "ec_commands.h"
+
+/**
+ * @brief Set the current image copy.
+ */
+void system_set_shrspi_image_copy(enum ec_image new_image_copy);
+
+#endif /* ZEPHYR_FAKE_SYSTEM_FAKE_H */
diff --git a/zephyr/fake/system_fake.c b/zephyr/fake/system_fake.c
new file mode 100644
index 0000000000..4a5df444cc
--- /dev/null
+++ b/zephyr/fake/system_fake.c
@@ -0,0 +1,34 @@
+/* Copyright 2022 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "system.h"
+#include "system_fake.h"
+
+static enum ec_image shrspi_image_copy = EC_IMAGE_RO;
+
+void system_jump_to_booter(void)
+{
+}
+
+uint32_t system_get_lfw_address(void)
+{
+ uint32_t jump_addr = (uint32_t)system_jump_to_booter;
+
+ return jump_addr;
+}
+
+enum ec_image system_get_shrspi_image_copy(void)
+{
+ return shrspi_image_copy;
+}
+
+void system_set_shrspi_image_copy(enum ec_image new_image_copy)
+{
+ shrspi_image_copy = new_image_copy;
+}
+
+void system_set_image_copy(enum ec_image copy)
+{
+}
diff --git a/zephyr/include/emul/emul_flash.h b/zephyr/include/emul/emul_flash.h
index e5d8ef1d5a..80d1bfadc7 100644
--- a/zephyr/include/emul/emul_flash.h
+++ b/zephyr/include/emul/emul_flash.h
@@ -19,9 +19,4 @@
*/
void cros_flash_emul_protect_reset(void);
-/**
- * @brief Set the current image copy.
- */
-void system_set_shrspi_image_copy(enum ec_image new_image_copy);
-
#endif /* ZEPHYR_INCLUDE_EMUL_EMUL_FLASH_H_ */
diff --git a/zephyr/test/drivers/default/prj.conf b/zephyr/test/drivers/default/prj.conf
index 31707ba52b..232bd184e3 100644
--- a/zephyr/test/drivers/default/prj.conf
+++ b/zephyr/test/drivers/default/prj.conf
@@ -9,4 +9,5 @@ CONFIG_PLATFORM_EC_LED_DT=y
CONFIG_PLATFORM_EC_RTC=y
CONFIG_PLATFORM_EC_VOLUME_BUTTONS=y
+CONFIG_SYSTEM_FAKE=y
CONFIG_PWM_MOCK=y