1#-------------------------------------------------------------------------------
2# Copyright (c) 2020-2024, 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
18#========================= Platform common defs ===============================#
19
20# Specify the location of platform specific build dependencies.
21target_sources(tfm_s
22    PRIVATE
23        ${CMAKE_CURRENT_SOURCE_DIR}/device/source/startup_an524.c
24)
25
26target_add_scatter_file(tfm_s
27    $<$<C_COMPILER_ID:ARMClang>:${PLATFORM_DIR}/ext/common/armclang/tfm_common_s.sct>
28    $<$<C_COMPILER_ID:GNU>:${PLATFORM_DIR}/ext/common/gcc/tfm_common_s.ld>
29    $<$<C_COMPILER_ID:IAR>:${PLATFORM_DIR}/ext/common/iar/tfm_common_s.icf>
30)
31
32if(BL2)
33    target_sources(bl2
34        PRIVATE
35            ${CMAKE_CURRENT_SOURCE_DIR}/device/source/startup_an524.c
36    )
37    target_add_scatter_file(bl2
38            $<$<C_COMPILER_ID:ARMClang>:${PLATFORM_DIR}/ext/common/armclang/tfm_common_bl2.sct>
39            $<$<C_COMPILER_ID:GNU>:${PLATFORM_DIR}/ext/common/gcc/tfm_common_bl2.ld>
40            $<$<C_COMPILER_ID:IAR>:${PLATFORM_DIR}/ext/common/iar/tfm_common_bl2.icf>
41    )
42endif()
43
44#========================= Platform Secure ====================================#
45
46target_include_directories(platform_s
47    PUBLIC
48        .
49        ../common
50        cmsis_drivers
51        cmsis_drivers/config
52        native_drivers
53        partition
54        device/include
55        device/config
56        ${CMAKE_SOURCE_DIR}
57        ${PLATFORM_DIR}/ext/target/arm/drivers/usart/cmsdk
58        ${PLATFORM_DIR}/ext/target/arm/drivers/usart/common
59        ${PLATFORM_DIR}/ext/target/arm/drivers/mpc_sie
60        ${PLATFORM_DIR}/ext/target/arm/drivers/timer/cmsdk
61        ${PLATFORM_DIR}/ext/target/arm/drivers/mpu/armv8m
62)
63
64target_sources(platform_s
65    PRIVATE
66        device/source/system_core_init.c
67        device/source/device_definition.c
68        cmsis_drivers/Driver_Flash.c
69        cmsis_drivers/Driver_MPC.c
70        cmsis_drivers/Driver_PPC.c
71        cmsis_drivers/Driver_USART.c
72        native_drivers/ppc_sse200_drv.c
73        ${PLATFORM_DIR}/ext/target/arm/drivers/mpc_sie/mpc_sie_drv.c
74        ${PLATFORM_DIR}/ext/target/arm/drivers/mpu/armv8m/mpu_armv8m_drv.c
75        ${PLATFORM_DIR}/ext/target/arm/drivers/usart/cmsdk/uart_cmsdk_drv.c
76        ${PLATFORM_DIR}/ext/target/arm/drivers/timer/cmsdk/timer_cmsdk_drv.c
77        $<$<BOOL:${TFM_PARTITION_PLATFORM}>:${CMAKE_CURRENT_SOURCE_DIR}/plat_test.c>
78        $<$<BOOL:${TFM_PARTITION_PLATFORM}>:${CMAKE_CURRENT_SOURCE_DIR}/services/src/tfm_platform_system.c>
79)
80
81target_compile_options(platform_s
82    PUBLIC
83        ${COMPILER_CMSE_FLAG}
84)
85
86#========================= Platform BL2 =======================================#
87
88if(BL2)
89    target_sources(platform_bl2
90        PRIVATE
91            device/source/system_core_init.c
92            device/source/device_definition.c
93            cmsis_drivers/Driver_Flash.c
94            cmsis_drivers/Driver_USART.c
95            ${PLATFORM_DIR}/ext/target/arm/drivers/usart/cmsdk/uart_cmsdk_drv.c
96    )
97
98    target_include_directories(platform_bl2
99        PUBLIC
100            partition
101            device/include
102            device/config
103            cmsis_drivers/config
104            ${PLATFORM_DIR}/ext/target/arm/drivers/usart/cmsdk
105            ${PLATFORM_DIR}/ext/target/arm/drivers/usart/common
106            ${PLATFORM_DIR}/ext/target/arm/drivers/mpc_sie
107            ${PLATFORM_DIR}/ext/target/arm/drivers/timer/cmsdk
108        PRIVATE
109            .
110            ${CMAKE_SOURCE_DIR}
111            native_drivers
112            ${PLATFORM_DIR}/ext/common
113    )
114endif()
115
116#========================= tfm_spm ============================================#
117
118target_sources(tfm_spm
119    PRIVATE
120        target_cfg.c
121        tfm_hal_platform.c
122        tfm_peripherals_def.c
123        ${PLATFORM_DIR}/ext/common/tfm_hal_platform_v8m.c
124        ${PLATFORM_DIR}/ext/common/tfm_hal_isolation_v8m.c
125        $<$<OR:$<BOOL:${CONFIG_TFM_FLIH_API}>,$<BOOL:${CONFIG_TFM_SLIH_API}>>:${PLATFORM_DIR}/ext/common/tfm_interrupts.c>
126)
127
128# If this is not added to the tfm_s it will not correctly override the weak
129# default handlers declared in assemebly, and will instead be discarded as they
130# are not in use.
131target_sources(tfm_s
132    PRIVATE
133        ${PLATFORM_DIR}/ext/common/mpc_ppc_faults.c
134)
135
136target_compile_definitions(platform_region_defs
137    INTERFACE
138        PROVISIONING_CODE_PADDED_SIZE=${PROVISIONING_CODE_PADDED_SIZE}
139        PROVISIONING_VALUES_PADDED_SIZE=${PROVISIONING_VALUES_PADDED_SIZE}
140        PROVISIONING_DATA_PADDED_SIZE=${PROVISIONING_DATA_PADDED_SIZE}
141)
142
143if(NOT PLATFORM_DEFAULT_PROVISIONING)
144    add_subdirectory(${PLATFORM_DIR}/ext/target/arm/mps3/common/provisioning provisioning)
145endif()
146
147#========================= Files for building NS side platform ================#
148
149install(FILES       ${TARGET_PLATFORM_PATH}/cmsis_drivers/Driver_USART.c
150                    ${TARGET_PLATFORM_PATH}/device/source/device_definition.c
151                    ${TARGET_PLATFORM_PATH}/device/source/system_core_init.c
152                    ${PLATFORM_DIR}/ext/target/arm/drivers/usart/cmsdk/uart_cmsdk_drv.c
153                    ${PLATFORM_DIR}/ext/target/arm/drivers/timer/cmsdk/timer_cmsdk_drv.c
154        DESTINATION ${INSTALL_PLATFORM_NS_DIR})
155
156install(DIRECTORY   ${TARGET_PLATFORM_PATH}/device
157        DESTINATION ${INSTALL_PLATFORM_NS_DIR})
158
159install(FILES       ${TARGET_PLATFORM_PATH}/device/include/platform_base_address.h
160                    ${PLATFORM_DIR}/ext/target/arm/drivers/usart/cmsdk/uart_cmsdk_drv.h
161                    ${PLATFORM_DIR}/ext/target/arm/drivers/usart/cmsdk/uart_cmsdk_reg_map.h
162                    ${PLATFORM_DIR}/ext/target/arm/drivers/timer/cmsdk/timer_cmsdk_drv.h
163                    ${TARGET_PLATFORM_PATH}/target_cfg.h
164                    ${TARGET_PLATFORM_PATH}/device/config/device_cfg.h
165                    ${TARGET_PLATFORM_PATH}/tfm_peripherals_def.h
166                    ${TARGET_PLATFORM_PATH}/cmsis_drivers/config/cmsis_driver_config.h
167                    ${TARGET_PLATFORM_PATH}/cmsis_drivers/config/RTE_Device.h
168                    ${TARGET_PLATFORM_PATH}/native_drivers/ppc_sse200_drv.h
169                    ${PLATFORM_DIR}/ext/target/arm/drivers/usart/cmsdk/Driver_USART_CMSDK.h
170                    ${PLATFORM_DIR}/ext/target/arm/drivers/usart/common/Driver_USART_Common.h
171                    ${PLATFORM_DIR}/ext/driver/Driver_USART.h
172                    ${PLATFORM_DIR}/ext/driver/Driver_Common.h
173                    ${PLATFORM_DIR}/include/tfm_plat_defs.h
174                    ${PLATFORM_DIR}/ext/target/arm/drivers/mpc_sie/mpc_sie_drv.h
175                    ${PLATFORM_DIR}/ext/target/arm/drivers/mpu/armv8m/mpu_armv8m_drv.h
176        DESTINATION ${INSTALL_PLATFORM_NS_DIR}/include)
177
178install(DIRECTORY   ${TARGET_PLATFORM_PATH}/partition
179        DESTINATION ${INSTALL_PLATFORM_NS_DIR})
180
181install(FILES       ${PLATFORM_DIR}/ext/common/gcc/tfm_common_ns.ld
182                    ${PLATFORM_DIR}/ext/common/armclang/tfm_common_ns.sct
183                    ${PLATFORM_DIR}/ext/common/iar/tfm_common_ns.icf
184        DESTINATION ${INSTALL_PLATFORM_NS_DIR}/linker_scripts)
185
186# copy all files from active platform directory
187install(DIRECTORY   ${TARGET_PLATFORM_PATH}/ns/
188        DESTINATION ${INSTALL_PLATFORM_NS_DIR})
189
190install(FILES       ${TARGET_PLATFORM_PATH}/cpuarch.cmake
191                    ${TARGET_PLATFORM_PATH}/config.cmake
192        DESTINATION ${INSTALL_PLATFORM_NS_DIR})
193