blob: caad0cfb08b0950c54852bf3a178f2c020f11781 [file] [log] [blame]
Anton Komlevc0ad6042023-08-29 18:23:26 +01001#-------------------------------------------------------------------------------
David Vincze223d7c82024-07-25 11:38:57 +02002# Copyright (c) 2023-2024, Arm Limited. All rights reserved.
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
David Vinczefa2f53a2024-11-26 15:35:48 +0000127# TF-M NS logging
David Hu479ef002023-10-20 14:44:32 +0800128add_library(tfm_ns_log STATIC EXCLUDE_FROM_ALL)
129
130target_sources(tfm_ns_log
131 PRIVATE
132 ${APP_LIB_DIR}/log/tfm_log_raw.c
133)
134
135target_include_directories(tfm_ns_log
136 PUBLIC
137 ${APP_LIB_DIR}/log/
138)
139
David Vinczefa2f53a2024-11-26 15:35:48 +0000140target_compile_definitions(tfm_ns_log
141 INTERFACE
142 $<$<NOT:$<BOOL:${TFM_NS_LOG_DISABLE}>>:TFM_NS_LOG>
143)
144
David Hu479ef002023-10-20 14:44:32 +0800145target_link_libraries(tfm_ns_log
146 PRIVATE
147 platform_ns
148)
149
David Hu87b46a82023-10-21 23:23:42 +0800150################## Update plaform_ns with NS settings #################
151
152target_include_directories(platform_ns
153 PUBLIC
Jamie Foxcd0c2212023-11-28 17:47:53 +0000154 $<$<BOOL:${TFM_NS_MAILBOX_API}>:${SPE_INSTALL_INTERFACE_INC}/multi_core>
David Hu87b46a82023-10-21 23:23:42 +0800155 ${SPE_INSTALL_INTERFACE_INC}
156)
157
158target_compile_definitions(platform_ns
159 PUBLIC
Jamie Foxcd0c2212023-11-28 17:47:53 +0000160 $<$<BOOL:${TFM_NS_MAILBOX_API}>:TFM_MULTI_CORE_NS_OS>
David Hu87b46a82023-10-21 23:23:42 +0800161)
162
163################# Update NS interface with NS settings ################
164
165target_sources(tfm_api_ns
166 PRIVATE
167 # NS specific implementation of NS interface dispatcher
Jamie Foxcd0c2212023-11-28 17:47:53 +0000168 $<$<NOT:$<BOOL:${TFM_NS_MAILBOX_API}>>:${SPE_INSTALL_INTERFACE_SRC}/os_wrapper/tfm_ns_interface_rtos.c>
David Hu87b46a82023-10-21 23:23:42 +0800169)
170
171target_compile_definitions(tfm_api_ns
172 PUBLIC
173 $<$<BOOL:${TEST_NS_MULTI_CORE}>:TFM_MULTI_CORE_TEST>
174)
175
176target_link_libraries(tfm_api_ns
177 PRIVATE
Jamie Foxcd0c2212023-11-28 17:47:53 +0000178 $<$<BOOL:${TFM_NS_MAILBOX_API}>:tfm_api_ns_mailbox>
179 $<$<NOT:$<BOOL:${TFM_NS_MAILBOX_API}>>:tfm_api_ns_tz>
180 $<$<NOT:$<BOOL:${TFM_NS_MAILBOX_API}>>:os_wrapper>
David Hu87b46a82023-10-21 23:23:42 +0800181)
182
183######################## NS application broker ########################
184
185add_library(tfm_test_broker STATIC)
186
187target_sources(tfm_test_broker
188 PRIVATE
189 main_ns.c
David Hu87b46a82023-10-21 23:23:42 +0800190)
191
192target_include_directories(tfm_test_broker
193 PUBLIC
194 .
195)
Anton Komlevc0ad6042023-08-29 18:23:26 +0100196
197target_link_libraries(tfm_test_broker
David Hu87b46a82023-10-21 23:23:42 +0800198 PRIVATE
199 os_wrapper
200 tfm_nsid_manager
Anton Komlevc0ad6042023-08-29 18:23:26 +0100201 PUBLIC
David Hu87b46a82023-10-21 23:23:42 +0800202 RTX_OS
Anton Komlevc0ad6042023-08-29 18:23:26 +0100203 tfm_api_ns
David Hu479ef002023-10-20 14:44:32 +0800204 tfm_ns_log
Jamie Foxcd0c2212023-11-28 17:47:53 +0000205 $<$<BOOL:${TFM_NS_MAILBOX_API}>:ns_multi_core>
Anton Komlevc0ad6042023-08-29 18:23:26 +0100206)
David Hu479ef002023-10-20 14:44:32 +0800207
208target_compile_definitions(tfm_test_broker
209 PUBLIC
210 $<$<BOOL:${TFM_NS_REG_TEST}>:TFM_NS_REG_TEST>
Jamie Foxcd0c2212023-11-28 17:47:53 +0000211 $<$<BOOL:${TFM_NS_MAILBOX_API}>:TFM_NS_MAILBOX_API>
David Hu479ef002023-10-20 14:44:32 +0800212)