summaryrefslogtreecommitdiff
path: root/zephyr/fake
diff options
context:
space:
mode:
Diffstat (limited to 'zephyr/fake')
-rw-r--r--zephyr/fake/CMakeLists.txt7
-rw-r--r--zephyr/fake/Kconfig11
-rw-r--r--zephyr/fake/include/system_fake.h23
-rw-r--r--zephyr/fake/system_fake.c46
4 files changed, 87 insertions, 0 deletions
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..b80624e289
--- /dev/null
+++ b/zephyr/fake/include/system_fake.h
@@ -0,0 +1,23 @@
+/* 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);
+
+/**
+ * @brief Set the fake environment
+ */
+void system_fake_setenv(jmp_buf *env);
+
+#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..75beb62b23
--- /dev/null
+++ b/zephyr/fake/system_fake.c
@@ -0,0 +1,46 @@
+/* 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 <setjmp.h>
+
+#include "system.h"
+#include "system_fake.h"
+
+static enum ec_image shrspi_image_copy = EC_IMAGE_RO;
+
+/* setjmp environment to use for reboot (NULL if none) */
+static jmp_buf *jump_env;
+
+void system_fake_setenv(jmp_buf *env)
+{
+ jump_env = env;
+}
+
+void system_jump_to_booter(void)
+{
+ if (jump_env)
+ longjmp(*jump_env, 1);
+}
+
+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)
+{
+}