1#-------------------------------------------------------------------------------
2# Copyright (c) 2020-2023, Arm Limited. All rights reserved.
3#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6#-------------------------------------------------------------------------------
7
8cmake_policy(SET CMP0076 NEW)
9set(CMAKE_CURRENT_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR})
10
11#========================= Platform region defs ===============================#
12
13target_include_directories(platform_region_defs
14    INTERFACE
15        partition
16)
17
18target_link_libraries(platform_region_defs
19    INTERFACE
20        tfm_fih_headers
21)
22
23#========================= Platform common defs ===============================#
24
25# Specify the location of platform specific build dependencies.
26target_sources(tfm_s
27    PRIVATE
28        ${CMAKE_CURRENT_SOURCE_DIR}/cmsis_core/startup_an521.c
29)
30
31# Use a common scatter file for Isolation L1 and L2, a dedicated one for Isolation L3
32# IAR is not supported for L3
33target_add_scatter_file(tfm_s
34    $<$<AND:$<VERSION_LESS:${TFM_ISOLATION_LEVEL},3>,$<C_COMPILER_ID:ARMClang>>:${PLATFORM_DIR}/ext/common/armclang/tfm_common_s.sct>
35    $<$<AND:$<VERSION_LESS:${TFM_ISOLATION_LEVEL},3>,$<C_COMPILER_ID:GNU>>:${PLATFORM_DIR}/ext/common/gcc/tfm_common_s.ld>
36    $<$<AND:$<VERSION_LESS:${TFM_ISOLATION_LEVEL},3>,$<C_COMPILER_ID:IAR>>:${PLATFORM_DIR}/ext/common/iar/tfm_common_s.icf>
37    $<$<AND:$<VERSION_EQUAL:${TFM_ISOLATION_LEVEL},3>,$<C_COMPILER_ID:ARMClang>>:${CMAKE_BINARY_DIR}/generated/platform/ext/common/armclang/tfm_isolation_l3.sct>
38    $<$<AND:$<VERSION_EQUAL:${TFM_ISOLATION_LEVEL},3>,$<C_COMPILER_ID:GNU>>:${CMAKE_BINARY_DIR}/generated/platform/ext/common/gcc/tfm_isolation_l3.ld>
39    $<$<AND:$<VERSION_EQUAL:${TFM_ISOLATION_LEVEL},3>,$<C_COMPILER_ID:IAR>>:${CMAKE_BINARY_DIR}/generated/platform/ext/common/iar/tfm_isolation_l3.icf>
40)
41
42if(BL2)
43    target_sources(bl2
44        PRIVATE
45            ${CMAKE_CURRENT_SOURCE_DIR}/cmsis_core/startup_an521.c
46    )
47    target_add_scatter_file(bl2
48            $<$<C_COMPILER_ID:ARMClang>:${PLATFORM_DIR}/ext/common/armclang/tfm_common_bl2.sct>
49            $<$<C_COMPILER_ID:GNU>:${PLATFORM_DIR}/ext/common/gcc/tfm_common_bl2.ld>
50            $<$<C_COMPILER_ID:IAR>:${PLATFORM_DIR}/ext/common/iar/tfm_common_bl2.icf>
51    )
52endif()
53
54#========================= Platform Secure ====================================#
55
56target_include_directories(platform_s
57    PUBLIC
58        .
59        ../common
60        cmsis_drivers
61        native_drivers
62        partition
63        retarget
64        cmsis_core
65        native_drivers/timer_cmsdk
66        ${PLATFORM_DIR}/..
67)
68
69target_sources(platform_s
70    INTERFACE
71        $<$<STREQUAL:"${TFM_FIH_PROFILE}","HIGH">:${PLATFORM_DIR}/ext/common/template/tfm_fih_rng.c>
72    PRIVATE
73        cmsis_drivers/Driver_Flash.c
74        cmsis_drivers/Driver_MPC.c
75        cmsis_drivers/Driver_PPC.c
76        cmsis_drivers/Driver_USART.c
77        retarget/platform_retarget_dev.c
78        cmsis_core/system_core_init.c
79        native_drivers/mpc_sie200_drv.c
80        native_drivers/mpu_armv8m_drv.c
81        native_drivers/ppc_sse200_drv.c
82        native_drivers/ppc_sse200_drv.c
83        native_drivers/arm_uart_drv.c
84        $<$<AND:$<NOT:$<BOOL:${TFM_PARTITION_SLIH_TEST}>>,$<NOT:$<BOOL:${TFM_PARTITION_FLIH_TEST}>>>:${CMAKE_CURRENT_SOURCE_DIR}/native_drivers/timer_cmsdk/timer_cmsdk.c>
85        $<$<OR:$<BOOL:${TFM_S_REG_TEST}>,$<BOOL:${TFM_NS_REG_TEST}>>:${CMAKE_CURRENT_SOURCE_DIR}/plat_test.c>
86        $<$<BOOL:${TFM_PARTITION_PLATFORM}>:${CMAKE_CURRENT_SOURCE_DIR}/services/src/tfm_platform_system.c>
87)
88
89target_sources(tfm_sprt
90    PRIVATE
91        # SLIH test Partition and FLIH test Partition access the timer as ARoT Partitions.
92        # Put the driver to SPRT so that both SLIH and FLIH tests can access it.
93        $<$<OR:$<BOOL:${TFM_PARTITION_SLIH_TEST}>,$<BOOL:${TFM_PARTITION_FLIH_TEST}>>:${CMAKE_CURRENT_SOURCE_DIR}/native_drivers/timer_cmsdk/timer_cmsdk.c>
94)
95
96target_compile_options(platform_s
97    PUBLIC
98        ${COMPILER_CMSE_FLAG}
99)
100
101target_compile_definitions(platform_s
102    PUBLIC
103        $<$<BOOL:${TEST_NS_FPU}>:TEST_NS_FPU>
104        $<$<BOOL:${TEST_S_FPU}>:TEST_S_FPU>
105)
106
107#========================= Platform BL2 =======================================#
108
109if(BL2)
110    target_sources(platform_bl2
111        PRIVATE
112            retarget/platform_retarget_dev.c
113            cmsis_core/system_core_init.c
114            cmsis_drivers/Driver_Flash.c
115            native_drivers/arm_uart_drv.c
116            cmsis_drivers/Driver_USART.c
117    )
118
119    target_include_directories(platform_bl2
120        PUBLIC
121            partition
122            cmsis_core
123            retarget
124        PRIVATE
125            .
126            ${PLATFORM_DIR}/..
127            native_drivers
128            native_drivers/timer_cmsdk
129    )
130endif()
131
132#========================= tfm_spm ============================================#
133
134target_sources(tfm_spm
135    PRIVATE
136        target_cfg.c
137        tfm_hal_isolation.c
138        tfm_hal_platform.c
139        faults.c
140        $<$<OR:$<BOOL:${CONFIG_TFM_FLIH_API}>,$<BOOL:${CONFIG_TFM_SLIH_API}>>:${CMAKE_CURRENT_SOURCE_DIR}/tfm_interrupts.c>
141)
142
143#========================= Files for building NS platform =====================#
144
145install(FILES       ${PLATFORM_DIR}/ext/common/test_interrupt.c
146                    ${TARGET_PLATFORM_PATH}/native_drivers/arm_uart_drv.c
147                    ${TARGET_PLATFORM_PATH}/native_drivers/timer_cmsdk/timer_cmsdk.c
148                    ${TARGET_PLATFORM_PATH}/cmsis_drivers/Driver_USART.c
149                    ${TARGET_PLATFORM_PATH}/retarget/platform_retarget_dev.c
150        DESTINATION ${INSTALL_PLATFORM_NS_DIR})
151
152install(DIRECTORY   ${TARGET_PLATFORM_PATH}/cmsis_core
153                    ${TARGET_PLATFORM_PATH}/retarget
154        DESTINATION ${INSTALL_PLATFORM_NS_DIR})
155
156install(DIRECTORY   ${PLATFORM_DIR}/ext/driver
157        DESTINATION ${INSTALL_PLATFORM_NS_DIR}/include)
158
159install(FILES       ${TARGET_PLATFORM_PATH}/partition/region_defs.h
160                    ${TARGET_PLATFORM_PATH}/partition/flash_layout.h
161                    ${TARGET_PLATFORM_PATH}/native_drivers/arm_uart_drv.h
162                    ${TARGET_PLATFORM_PATH}/native_drivers/timer_cmsdk/timer_cmsdk.h
163                    ${TARGET_PLATFORM_PATH}/native_drivers/mpc_sie200_drv.h
164                    ${TARGET_PLATFORM_PATH}/native_drivers/ppc_sse200_drv.h
165                    ${TARGET_PLATFORM_PATH}/retarget/platform_retarget.h
166                    ${TARGET_PLATFORM_PATH}/retarget/platform_retarget_pins.h
167                    ${TARGET_PLATFORM_PATH}/target_cfg.h
168                    ${TARGET_PLATFORM_PATH}/device_cfg.h
169                    ${TARGET_PLATFORM_PATH}/tfm_peripherals_def.h
170                    ${TARGET_PLATFORM_PATH}/cmsis_driver_config.h
171                    ${TARGET_PLATFORM_PATH}/RTE_Device.h
172                    ${PLATFORM_DIR}/ext/common/test_interrupt.h
173                    ${PLATFORM_DIR}/ext/driver/Driver_USART.h
174                    ${PLATFORM_DIR}/ext/driver/Driver_Common.h
175                    ${PLATFORM_DIR}/include/tfm_plat_defs.h
176                    ${CMAKE_SOURCE_DIR}/lib/fih/inc/fih.h
177        DESTINATION ${INSTALL_PLATFORM_NS_DIR}/include)
178
179install(FILES       ${PLATFORM_DIR}/ext/common/gcc/tfm_common_ns.ld
180                    ${PLATFORM_DIR}/ext/common/armclang/tfm_common_ns.sct
181                    ${PLATFORM_DIR}/ext/common/iar/tfm_common_ns.icf
182        DESTINATION ${INSTALL_PLATFORM_NS_DIR}/linker_scripts)
183
184# copy all files from active platform directory
185install(DIRECTORY   ${TARGET_PLATFORM_PATH}/ns/
186        DESTINATION ${INSTALL_PLATFORM_NS_DIR})
187
188install(FILES       ${TARGET_PLATFORM_PATH}/cpuarch.cmake
189        DESTINATION ${INSTALL_PLATFORM_NS_DIR})
190
191# Copy the platform specific config
192install(FILES       ${TARGET_PLATFORM_PATH}/config.cmake
193        DESTINATION ${INSTALL_PLATFORM_NS_DIR})
194
195# Install test configs
196install(DIRECTORY   ${TARGET_PLATFORM_PATH}/tests
197        DESTINATION ${INSTALL_PLATFORM_NS_DIR})
198