summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Short <keithshort@chromium.org>2022-02-11 13:27:26 -0700
committerCommit Bot <commit-bot@chromium.org>2022-02-25 21:10:09 +0000
commit3ba28b0c41e898d03afcc9432f812fa8e5a9524a (patch)
tree911c4e849c7b2656746077b8e47764c685fd984e
parent84fd17247ac8d55ae4adb67281841a9a2a4c2433 (diff)
downloadchrome-ec-3ba28b0c41e898d03afcc9432f812fa8e5a9524a.tar.gz
zephyr: split legacy and shimmed codes into libraries
Split the legacy EC code and shimmed code into separate libraries. This allows for declaring different compiler definitions to the legacy and shim code. BUG=b:218856245 BRANCH=none TEST=zmake testall Signed-off-by: Keith Short <keithshort@chromium.org> Change-Id: Ice25c21409d33594e7d465092ad5066be7336dbe Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3489101 Reviewed-by: Denis Brockus <dbrockus@chromium.org>
-rw-r--r--docs/zephyr/project_config.md6
-rw-r--r--zephyr/CMakeLists.txt45
-rw-r--r--zephyr/app/ec/CMakeLists.txt2
-rw-r--r--zephyr/projects/corsola/CMakeLists.txt2
-rw-r--r--zephyr/projects/drawcia_riscv/CMakeLists.txt2
-rw-r--r--zephyr/projects/herobrine/CMakeLists.txt2
-rw-r--r--zephyr/projects/skyrim/CMakeLists.txt4
-rw-r--r--zephyr/projects/trogdor/lazor/CMakeLists.txt2
-rw-r--r--zephyr/projects/volteer/volteer/CMakeLists.txt2
-rw-r--r--zephyr/shim/chip/it8xxx2/CMakeLists.txt2
-rw-r--r--zephyr/shim/chip/npcx/CMakeLists.txt2
11 files changed, 49 insertions, 22 deletions
diff --git a/docs/zephyr/project_config.md b/docs/zephyr/project_config.md
index 285e90dbdd..9f658ef62c 100644
--- a/docs/zephyr/project_config.md
+++ b/docs/zephyr/project_config.md
@@ -112,9 +112,9 @@ find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(ec)
```
-You may additionally want to specify any C files or include
-directories your project needs using `zephyr_library_sources` or
-`zephyr_library_include_directories`.
+You may additionally want to specify any C files your project needs
+using `zephyr_library_sources`. If you need to add extra include
+directories, use `cros_ec_library_include_directories`.
### prj.conf and prj_${project_name}.conf
diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt
index ba1672c4ce..ac4e9fcef2 100644
--- a/zephyr/CMakeLists.txt
+++ b/zephyr/CMakeLists.txt
@@ -63,16 +63,40 @@ if(DEFINED CONFIG_PLATFORM_EC)
endif()
endif()
+# The EC application is split into two libraries:
+# app: contains all the legacy code
+# ec_shim: contains all the code under platform/ec/shim
+#
+# This allows us to add an extra compiler definition __REQUIRE_ZEPHYR_GPIOS__
+# that is applied only to the Zephyr sources. This is used to verify that
+# all Zephyr sources are using the upstream Zephyr GPIO API and not the legacy
+# EC API.
+zephyr_library_named(ec_shim)
+get_property(APP_LTO_PROPERTY TARGET app PROPERTY INTERPROCEDURAL_OPTIMIZATION)
+set_property(TARGET ec_shim PROPERTY INTERPROCEDURAL_OPTIMIZATION ${APP_LTO_PROPERTY})
+set_property(TARGET ec_shim APPEND PROPERTY COMPILE_DEFINITIONS __REQUIRE_ZEPHYR_GPIOS__)
+
# Switch from the "zephyr" library to the "app" library for all Chromium OS
# sources.
set(ZEPHYR_CURRENT_LIBRARY app)
-add_subdirectory(linker)
+# Custom function that ensures the include path is always updated for both
+# libraries.
+function(cros_ec_library_include_directories)
+ target_include_directories(app PRIVATE ${ARGN})
+ target_include_directories(ec_shim PRIVATE ${ARGN})
+endfunction()
+function(cros_ec_library_include_directories_ifdef feature_toggle)
+ if(${${feature_toggle}})
+ target_include_directories(app PRIVATE ${ARGN})
+ target_include_directories(ec_shim PRIVATE ${ARGN})
+ endif()
+endfunction()
-zephyr_library_include_directories(include)
+cros_ec_library_include_directories(include)
if (DEFINED CONFIG_PLATFORM_EC)
- zephyr_library_include_directories(
+ cros_ec_library_include_directories(
"${PLATFORM_EC}/zephyr/shim/include"
"${PLATFORM_EC}/fuzz"
"${PLATFORM_EC}/test"
@@ -82,12 +106,6 @@ if (DEFINED CONFIG_PLATFORM_EC)
"${PLATFORM_EC}/third_party")
endif()
-add_subdirectory("app")
-add_subdirectory("drivers")
-add_subdirectory("emul")
-add_subdirectory("subsys")
-
-add_subdirectory_ifdef(CONFIG_PLATFORM_EC "shim")
# Creates a phony target all.libraries in case you only want to build the
# libraries and not the binaries. For example for creating the initial zero
# coverage files.
@@ -483,3 +501,12 @@ zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_RTC
"${PLATFORM_EC}/common/rtc.c")
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_MATH_UTIL
"${PLATFORM_EC}/common/math_util.c")
+
+# Switch to ec_shim library for all Zephyr sources
+set(ZEPHYR_CURRENT_LIBRARY ec_shim)
+
+add_subdirectory(linker)
+add_subdirectory("app")
+add_subdirectory("drivers")
+add_subdirectory("emul")
+add_subdirectory_ifdef(CONFIG_PLATFORM_EC "shim")
diff --git a/zephyr/app/ec/CMakeLists.txt b/zephyr/app/ec/CMakeLists.txt
index f12067a5b5..fc7205462d 100644
--- a/zephyr/app/ec/CMakeLists.txt
+++ b/zephyr/app/ec/CMakeLists.txt
@@ -2,7 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-zephyr_library_include_directories(include)
+cros_ec_library_include_directories(include)
zephyr_library_sources(ec_app_main.c)
if(NOT DEFINED CONFIG_ZTEST)
zephyr_library_sources(main_shim.c)
diff --git a/zephyr/projects/corsola/CMakeLists.txt b/zephyr/projects/corsola/CMakeLists.txt
index 20e4010a1d..389d90521e 100644
--- a/zephyr/projects/corsola/CMakeLists.txt
+++ b/zephyr/projects/corsola/CMakeLists.txt
@@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 3.13.1)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
-zephyr_library_include_directories(include)
+cros_ec_library_include_directories(include)
# Include selected EC source from the baseboard
zephyr_library_sources(
diff --git a/zephyr/projects/drawcia_riscv/CMakeLists.txt b/zephyr/projects/drawcia_riscv/CMakeLists.txt
index 5a80325e31..584aaef34d 100644
--- a/zephyr/projects/drawcia_riscv/CMakeLists.txt
+++ b/zephyr/projects/drawcia_riscv/CMakeLists.txt
@@ -6,6 +6,6 @@ cmake_minimum_required(VERSION 3.13.1)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
-zephyr_library_include_directories(include)
+cros_ec_library_include_directories(include)
project(drawcia_riscv)
diff --git a/zephyr/projects/herobrine/CMakeLists.txt b/zephyr/projects/herobrine/CMakeLists.txt
index 24b29ef897..42752bcb50 100644
--- a/zephyr/projects/herobrine/CMakeLists.txt
+++ b/zephyr/projects/herobrine/CMakeLists.txt
@@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 3.13.1)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
-zephyr_library_include_directories(include)
+cros_ec_library_include_directories(include)
# Board specific implementation
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_USBC
diff --git a/zephyr/projects/skyrim/CMakeLists.txt b/zephyr/projects/skyrim/CMakeLists.txt
index 52146af60c..b364421eb4 100644
--- a/zephyr/projects/skyrim/CMakeLists.txt
+++ b/zephyr/projects/skyrim/CMakeLists.txt
@@ -7,8 +7,8 @@ cmake_minimum_required(VERSION 3.13.1)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(guybrush)
-zephyr_library_include_directories_ifdef(CONFIG_BOARD_SKYRIM include)
-zephyr_library_include_directories_ifdef(CONFIG_BOARD_GUYBRUSH include_guybrush)
+cros_ec_library_include_directories_ifdef(CONFIG_BOARD_SKYRIM include)
+cros_ec_library_include_directories_ifdef(CONFIG_BOARD_GUYBRUSH include_guybrush)
zephyr_library_sources_ifdef(CONFIG_BOARD_SKYRIM "power_signals.c")
zephyr_library_sources_ifdef(CONFIG_BOARD_GUYBRUSH "power_signals_guybrush.c")
diff --git a/zephyr/projects/trogdor/lazor/CMakeLists.txt b/zephyr/projects/trogdor/lazor/CMakeLists.txt
index e9a2c8a20f..325160ec08 100644
--- a/zephyr/projects/trogdor/lazor/CMakeLists.txt
+++ b/zephyr/projects/trogdor/lazor/CMakeLists.txt
@@ -7,7 +7,7 @@ cmake_minimum_required(VERSION 3.13.1)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(lazor)
-zephyr_library_include_directories(include)
+cros_ec_library_include_directories(include)
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_USBC
"src/power.c"
diff --git a/zephyr/projects/volteer/volteer/CMakeLists.txt b/zephyr/projects/volteer/volteer/CMakeLists.txt
index 3a0ec26b4c..01181e4aff 100644
--- a/zephyr/projects/volteer/volteer/CMakeLists.txt
+++ b/zephyr/projects/volteer/volteer/CMakeLists.txt
@@ -14,7 +14,7 @@ set(PLATFORM_EC_BASEBOARD "${PLATFORM_EC}/baseboard/volteer" CACHE PATH
"Path to the platform/ec baseboard directory")
# Include board specific header files
-zephyr_library_include_directories(
+cros_ec_library_include_directories(
include
"${PLATFORM_EC_BASEBOARD}"
"${PLATFORM_EC_BOARD}")
diff --git a/zephyr/shim/chip/it8xxx2/CMakeLists.txt b/zephyr/shim/chip/it8xxx2/CMakeLists.txt
index 6f905a20ba..9558cbc338 100644
--- a/zephyr/shim/chip/it8xxx2/CMakeLists.txt
+++ b/zephyr/shim/chip/it8xxx2/CMakeLists.txt
@@ -2,7 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-zephyr_library_include_directories(include)
+cros_ec_library_include_directories(include)
zephyr_library_sources(clock.c)
zephyr_library_sources(gpio.c)
diff --git a/zephyr/shim/chip/npcx/CMakeLists.txt b/zephyr/shim/chip/npcx/CMakeLists.txt
index 585b072ea8..2e8a34ef95 100644
--- a/zephyr/shim/chip/npcx/CMakeLists.txt
+++ b/zephyr/shim/chip/npcx/CMakeLists.txt
@@ -9,7 +9,7 @@ if (NOT DEFINED CONFIG_COVERAGE)
add_subdirectory(npcx_monitor)
endif()
-zephyr_library_include_directories(include)
+cros_ec_library_include_directories(include)
zephyr_library_sources(clock.c)
zephyr_library_sources(gpio.c)