blob: af423015fb7b493bf8dcd819f860d053b3700735 [file] [log] [blame]
Anton Komlevc0ad6042023-08-29 18:23:26 +01001#-------------------------------------------------------------------------------
Jackson Cooper-Driverebf52612025-07-09 11:54:56 +01002# SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
Anton Komlevc0ad6042023-08-29 18:23:26 +01003#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6#-------------------------------------------------------------------------------
7#
David Vincze223d7c82024-07-25 11:38:57 +02008# This CMake script is used in a split build only. In the legacy 'single' build
9# this file is ignored.
Anton Komlevc0ad6042023-08-29 18:23:26 +010010#
David Hu4c3c0ca2023-12-02 22:09:18 +080011cmake_minimum_required(VERSION 3.21)
Anton Komlevc0ad6042023-08-29 18:23:26 +010012
13# This is important to add this SPE subdirectory at first as it
14# brings configuration from TF-M build
15add_subdirectory(${CONFIG_SPE_PATH} ${CMAKE_BINARY_DIR}/spe)
16
David Hu87b46a82023-10-21 23:23:42 +080017####################### NS application libraries #######################
Anton Komlevc0ad6042023-08-29 18:23:26 +010018
David Hu87b46a82023-10-21 23:23:42 +080019# Build all the NS application libraries here under app_broker
20# Those NS libraries depend on each other. It is more convenient to sort out the dependencies here.
21#
22# Those NS libraries also link to libraries exported from TF-M secure build. Specify all the
23# dependencies on TF-M exported libraries here, rather than under each NS library folder.
24# Therefore, NS library can be shared and re-used in other downstream projects, without specially
25# handling the differences of dependencies and paths in NS builds.
26
Jamie Foxcd0c2212023-11-28 17:47:53 +000027# Choose whether to use the TF-M mailbox API or TrustZone API to communicate
28# with the SPE based on the TF-M config. If the TF-M config provides both, then
29# default to the TrustZone APIs. This default needs to be overridden to do a
30# mailbox build on platforms with both agents.
31if (TFM_PARTITION_NS_AGENT_MAILBOX AND NOT CONFIG_TFM_USE_TRUSTZONE)
32 set(TFM_NS_MAILBOX_API ON CACHE BOOL "Build NS code for a remote processing element using mailbox APIs")
33else()
34 set(TFM_NS_MAILBOX_API OFF CACHE BOOL "Build NS code for a remote processing element using mailbox APIs")
35endif()
36
David Hu87b46a82023-10-21 23:23:42 +080037# Interface files exported from TF-M secure build
38set(SPE_INSTALL_INTERFACE_SRC ${CONFIG_SPE_PATH}/interface/src)
39set(SPE_INSTALL_INTERFACE_INC ${CONFIG_SPE_PATH}/interface/include)
David Vincze223d7c82024-07-25 11:38:57 +020040# lib path
David Hu87b46a82023-10-21 23:23:42 +080041set(APP_LIB_DIR ${CMAKE_CURRENT_LIST_DIR}/../lib)
42
David Hu87b46a82023-10-21 23:23:42 +080043# OS wrapper library consists of the wrapper layer of RTOSes, such as RTX
44add_library(os_wrapper STATIC)
45
46target_sources(os_wrapper
47 PRIVATE
48 ${CMAKE_CURRENT_LIST_DIR}/os_wrapper_cmsis_rtos_v2.c
Xinyu Zhang09174dc2023-11-01 14:32:00 +080049 $<$<BOOL:${TFM_NS_MANAGE_NSID}>:${CMAKE_CURRENT_LIST_DIR}/tfm_nsid_map_table.c>
Anton Komlevc0ad6042023-08-29 18:23:26 +010050)
51
David Hu87b46a82023-10-21 23:23:42 +080052target_include_directories(os_wrapper
53 PUBLIC
54 ${CMAKE_CURRENT_LIST_DIR}/../lib/os_wrapper
55 # Some NS files include "os_wrapper/xxx.h" instead
56 ${CMAKE_CURRENT_LIST_DIR}/../lib
57 # Some OS wrapper header files are exported from TF-M secure build
58 ${SPE_INSTALL_INTERFACE_INC}
59)
60
61target_link_libraries(os_wrapper
62 PRIVATE
63 RTX_OS
64 tfm_nsid_manager
65)
66
67# NSID manager
68add_library(tfm_nsid_manager INTERFACE)
69
70target_include_directories(tfm_nsid_manager
71 INTERFACE
72 ${APP_LIB_DIR}/nsid_manager
73)
74
75target_sources(tfm_nsid_manager
76 INTERFACE
77 $<$<BOOL:${TFM_NS_MANAGE_NSID}>:${APP_LIB_DIR}/nsid_manager/tfm_nsid_manager.c>
78)
79
80target_compile_definitions(tfm_nsid_manager
81 INTERFACE
82 $<$<BOOL:${TFM_NS_MANAGE_NSID}>:TFM_NS_MANAGE_NSID>
83 $<$<BOOL:${TEST_NS_MANAGE_NSID}>:TEST_NS_MANAGE_NSID>
84)
85
David Hu87b46a82023-10-21 23:23:42 +080086target_sources(RTX_OS
87 INTERFACE
David Vincze223d7c82024-07-25 11:38:57 +020088 # Provide TZ context management stub to RTOS if protected by TrustZone
Jamie Foxcd0c2212023-11-28 17:47:53 +000089 $<$<NOT:$<BOOL:${TFM_NS_MAILBOX_API}>>:${APP_LIB_DIR}/nsid_manager/tz_shim_layer.c>
Jamie Fox6d4ee162023-11-27 17:27:37 +000090 # Provide CMSIS-RTX config implementation
91 os_config_cmsis_rtx.c
David Hu87b46a82023-10-21 23:23:42 +080092)
93
94target_link_libraries(RTX_OS
95 INTERFACE
96 tfm_nsid_manager
97)
98
99# Multi-core library
Jamie Foxcd0c2212023-11-28 17:47:53 +0000100if(TFM_NS_MAILBOX_API)
David Hu87b46a82023-10-21 23:23:42 +0800101 add_library(ns_multi_core STATIC)
102
103 target_sources(ns_multi_core
104 PRIVATE
105 $<$<NOT:$<BOOL:${TFM_MULTI_CORE_NS_OS_MAILBOX_THREAD}>>:${SPE_INSTALL_INTERFACE_SRC}/multi_core/tfm_ns_mailbox.c>
106 $<$<BOOL:${TFM_MULTI_CORE_NS_OS_MAILBOX_THREAD}>:${SPE_INSTALL_INTERFACE_SRC}/multi_core/tfm_ns_mailbox_thread.c>
107 # NS RTOS specific implementation of NS mailbox
108 ${APP_LIB_DIR}/multi_core/tfm_ns_mailbox_rtos_api.c
109 $<$<BOOL:${TEST_NS_MULTI_CORE}>:${APP_LIB_DIR}/multi_core/tfm_ns_mailbox_test.c>
Nicola Mazzucato88b4e952025-06-10 09:10:27 +0100110 ${SPE_INSTALL_INTERFACE_SRC}/multi_core/tfm_ns_mailbox_common.c
David Hu87b46a82023-10-21 23:23:42 +0800111 )
112
113 target_compile_definitions(ns_multi_core
114 PUBLIC
115 $<$<BOOL:${TFM_MULTI_CORE_NS_OS_MAILBOX_THREAD}>:TFM_MULTI_CORE_NS_OS_MAILBOX_THREAD>
116 TFM_MULTI_CORE_NS_OS
117 )
118
119 target_link_libraries(ns_multi_core
120 PRIVATE
121 platform_ns
122 tfm_api_ns
123 os_wrapper
124 )
125endif()
126
127################## Update plaform_ns with NS settings #################
128
129target_include_directories(platform_ns
130 PUBLIC
Jamie Foxcd0c2212023-11-28 17:47:53 +0000131 $<$<BOOL:${TFM_NS_MAILBOX_API}>:${SPE_INSTALL_INTERFACE_INC}/multi_core>
David Hu87b46a82023-10-21 23:23:42 +0800132 ${SPE_INSTALL_INTERFACE_INC}
133)
134
135target_compile_definitions(platform_ns
136 PUBLIC
Jamie Foxcd0c2212023-11-28 17:47:53 +0000137 $<$<BOOL:${TFM_NS_MAILBOX_API}>:TFM_MULTI_CORE_NS_OS>
David Hu87b46a82023-10-21 23:23:42 +0800138)
139
140################# Update NS interface with NS settings ################
141
142target_sources(tfm_api_ns
143 PRIVATE
144 # NS specific implementation of NS interface dispatcher
Jamie Foxcd0c2212023-11-28 17:47:53 +0000145 $<$<NOT:$<BOOL:${TFM_NS_MAILBOX_API}>>:${SPE_INSTALL_INTERFACE_SRC}/os_wrapper/tfm_ns_interface_rtos.c>
David Hu87b46a82023-10-21 23:23:42 +0800146)
147
148target_compile_definitions(tfm_api_ns
149 PUBLIC
150 $<$<BOOL:${TEST_NS_MULTI_CORE}>:TFM_MULTI_CORE_TEST>
151)
152
153target_link_libraries(tfm_api_ns
154 PRIVATE
Jamie Foxcd0c2212023-11-28 17:47:53 +0000155 $<$<BOOL:${TFM_NS_MAILBOX_API}>:tfm_api_ns_mailbox>
156 $<$<NOT:$<BOOL:${TFM_NS_MAILBOX_API}>>:tfm_api_ns_tz>
157 $<$<NOT:$<BOOL:${TFM_NS_MAILBOX_API}>>:os_wrapper>
David Hu87b46a82023-10-21 23:23:42 +0800158)
159
160######################## NS application broker ########################
161
162add_library(tfm_test_broker STATIC)
163
164target_sources(tfm_test_broker
165 PRIVATE
Antonio de Angelis6bceab82025-07-10 17:05:14 +0100166 assert.c
David Hu87b46a82023-10-21 23:23:42 +0800167 main_ns.c
David Hu87b46a82023-10-21 23:23:42 +0800168)
169
170target_include_directories(tfm_test_broker
171 PUBLIC
172 .
Jackson Cooper-Driverebf52612025-07-09 11:54:56 +0100173 ${APP_LIB_DIR}/log/
David Hu87b46a82023-10-21 23:23:42 +0800174)
Anton Komlevc0ad6042023-08-29 18:23:26 +0100175
176target_link_libraries(tfm_test_broker
David Hu87b46a82023-10-21 23:23:42 +0800177 PRIVATE
178 os_wrapper
179 tfm_nsid_manager
Anton Komlevc0ad6042023-08-29 18:23:26 +0100180 PUBLIC
David Hu87b46a82023-10-21 23:23:42 +0800181 RTX_OS
Anton Komlevc0ad6042023-08-29 18:23:26 +0100182 tfm_api_ns
Jamie Foxcd0c2212023-11-28 17:47:53 +0000183 $<$<BOOL:${TFM_NS_MAILBOX_API}>:ns_multi_core>
Anton Komlevc0ad6042023-08-29 18:23:26 +0100184)
David Hu479ef002023-10-20 14:44:32 +0800185
186target_compile_definitions(tfm_test_broker
187 PUBLIC
188 $<$<BOOL:${TFM_NS_REG_TEST}>:TFM_NS_REG_TEST>
Jamie Foxcd0c2212023-11-28 17:47:53 +0000189 $<$<BOOL:${TFM_NS_MAILBOX_API}>:TFM_NS_MAILBOX_API>
David Hu479ef002023-10-20 14:44:32 +0800190)