1#-------------------------------------------------------------------------------
2# Copyright (c) 2020-2022, Arm Limited. All rights reserved.
3# Copyright (c) 2022 Cypress Semiconductor Corporation (an Infineon company)
4# or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
5#
6# SPDX-License-Identifier: BSD-3-Clause
7#
8#-------------------------------------------------------------------------------
9
10cmake_policy(SET CMP0076 NEW)
11set(CMAKE_CURRENT_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR})
12
13#========================= Platform region defs ===============================#
14
15target_include_directories(platform_region_defs
16    INTERFACE
17        partition
18        cc312
19)
20
21#========================= Platform common defs ===============================#
22
23# Specify the location of platform specific build dependencies.
24target_sources(tfm_s
25    PRIVATE
26        ${CMAKE_CURRENT_SOURCE_DIR}/device/source/startup_rss.c
27)
28target_add_scatter_file(tfm_s
29        $<$<C_COMPILER_ID:ARMClang>:${CMAKE_SOURCE_DIR}/platform/ext/common/armclang/tfm_common_s.sct>
30        $<$<C_COMPILER_ID:GNU>:${CMAKE_SOURCE_DIR}/platform/ext/common/gcc/tfm_common_s.ld>
31)
32
33if(NS)
34    target_sources(tfm_ns
35        PRIVATE
36            ${CMAKE_CURRENT_SOURCE_DIR}/device/source/startup_rss.c
37    )
38    target_add_scatter_file(tfm_ns
39            $<$<C_COMPILER_ID:ARMClang>:${CMAKE_SOURCE_DIR}/platform/ext/common/armclang/tfm_common_ns.sct>
40            $<$<C_COMPILER_ID:GNU>:${CMAKE_SOURCE_DIR}/platform/ext/common/gcc/tfm_common_ns.ld>
41    )
42    target_link_libraries(CMSIS_5_tfm_ns
43        INTERFACE
44            CMSIS_5_RTX_V8MMN
45    )
46endif()
47
48target_sources(bl2
49    PRIVATE
50        ${CMAKE_CURRENT_SOURCE_DIR}/device/source/startup_rss.c
51)
52target_add_scatter_file(bl2
53        $<$<C_COMPILER_ID:ARMClang>:${CMAKE_SOURCE_DIR}/platform/ext/common/armclang/tfm_common_bl2.sct>
54        $<$<C_COMPILER_ID:GNU>:${CMAKE_SOURCE_DIR}/platform/ext/common/gcc/tfm_common_bl2.ld>
55)
56target_compile_definitions(bootutil
57    PRIVATE
58        MULTIPLE_EXECUTABLE_RAM_REGIONS
59)
60
61target_sources(bl1_1
62    PRIVATE
63        ${CMAKE_CURRENT_SOURCE_DIR}/device/source/startup_rss.c
64)
65target_add_scatter_file(bl1_1
66        $<$<C_COMPILER_ID:ARMClang>:${CMAKE_CURRENT_SOURCE_DIR}/device/source/armclang/rss_bl1_1.sct>
67        $<$<C_COMPILER_ID:GNU>:${CMAKE_CURRENT_SOURCE_DIR}/device/source/gcc/rss_bl1_1.ld>
68)
69
70target_sources(bl1_2
71    PRIVATE
72        ${CMAKE_CURRENT_SOURCE_DIR}/device/source/startup_rss.c
73)
74target_add_scatter_file(bl1_2
75        $<$<C_COMPILER_ID:ARMClang>:${CMAKE_CURRENT_SOURCE_DIR}/device/source/armclang/rss_bl1_2.sct>
76        $<$<C_COMPILER_ID:GNU>:${CMAKE_CURRENT_SOURCE_DIR}/device/source/gcc/rss_bl1_2.ld>
77)
78
79
80install(FILES       platform_builtin_key_ids.h
81        DESTINATION ${TFM_INSTALL_PATH}/interface/include)
82
83#========================= Platform Secure ====================================#
84
85if (TFM_MULTI_CORE_TOPOLOGY)
86    add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/rss_comms rss_comms)
87endif()
88
89target_include_directories(platform_s
90    PUBLIC
91        .
92        ../common
93        cmsis_drivers
94        cmsis_drivers/config
95        device
96        device/config
97        device/include
98        device/source/armclang
99        native_drivers
100        libraries
101        partition
102        services/src
103        ${PLATFORM_DIR}/..
104)
105
106target_sources(platform_s
107    PRIVATE
108        cmsis_drivers/Driver_Flash.c
109        cmsis_drivers/Driver_MPC.c
110        cmsis_drivers/Driver_PPC.c
111        cmsis_drivers/Driver_USART.c
112        device/source/device_definition.c
113        device/source/system_core_init.c
114        libraries/dma350_lib.c
115        native_drivers/atu_rss_drv.c
116        native_drivers/dma350_drv.c
117        native_drivers/dma350_ch_drv.c
118        native_drivers/kmu_drv.c
119        native_drivers/mhu_v2_x.c
120        native_drivers/mhu_wrapper_v2_x.c
121        native_drivers/mpc_sie_drv.c
122        native_drivers/mpu_armv8m_drv.c
123        native_drivers/ppc_rss_drv.c
124        native_drivers/syscounter_armv8-m_cntrl_drv.c
125        native_drivers/systimer_armv8-m_drv.c
126        native_drivers/uart_pl011_drv.c
127        tfm_peripherals_def.c
128        $<$<OR:$<BOOL:${TEST_NS_SLIH_IRQ}>,$<BOOL:${TEST_NS_FLIH_IRQ}>>:${CMAKE_CURRENT_SOURCE_DIR}/plat_test.c>
129        $<$<BOOL:${TFM_PARTITION_PLATFORM}>:${CMAKE_CURRENT_SOURCE_DIR}/services/src/tfm_platform_system.c>
130        native_drivers/lcm_drv.c
131        otp_lcm.c
132        nv_counters.c
133        attest_hal.c
134        tfm_hal_platform_reset.c
135        provisioning.c
136        $<$<BOOL:${PLATFORM_SVC_HANDLERS}>:${CMAKE_CURRENT_SOURCE_DIR}/platform_svc_handler.c>
137        $<$<BOOL:${PLATFORM_SVC_HANDLERS}>:${CMAKE_CURRENT_SOURCE_DIR}/libraries/dma350_checker_layer.c>
138        $<$<BOOL:${PLATFORM_SVC_HANDLERS}>:${CMAKE_CURRENT_SOURCE_DIR}/device/source/dma350_checker_device_defs.c>
139        spm_dma_copy.c
140)
141
142target_link_libraries(platform_s
143    PRIVATE
144        tfm_sprt # For tfm_strnlen in attest HAL
145)
146
147target_sources(tfm_sprt
148    PRIVATE
149        # SLIH test Partition and FLIH test Partition access the timer as ARoT Partitions.
150        # Put the driver to SPRT so that both SLIH and FLIH tests can access it.
151        $<$<OR:$<BOOL:${TEST_NS_SLIH_IRQ}>,$<BOOL:${TEST_NS_FLIH_IRQ}>>:${CMAKE_CURRENT_SOURCE_DIR}/native_drivers/systimer_armv8-m_drv.c>
152)
153
154target_compile_definitions(platform_s
155    INTERFACE
156        ATTEST_KEY_BITS=${ATTEST_KEY_BITS}
157        spm_memcpy=spm_dma_memcpy
158    PRIVATE
159        # Needed for DMA-350 library
160        CMSIS_device_header="rss.h"
161        $<$<BOOL:${PLATFORM_SVC_HANDLERS}>:PLATFORM_SVC_HANDLERS>
162)
163
164target_compile_options(platform_s
165    PUBLIC
166        ${COMPILER_CMSE_FLAG}
167)
168
169#========================= Platform Crypto Keys ===============================#
170
171if (TFM_PARTITION_CRYPTO)
172    target_sources(platform_crypto_keys
173        PRIVATE
174            crypto_keys.c
175    )
176
177    target_include_directories(platform_crypto_keys
178        PUBLIC
179            .
180            ./native_drivers
181            ./device/include
182            ./device/config
183    )
184endif()
185
186#========================= Platform Non-Secure ================================#
187
188target_sources(platform_ns
189    PRIVATE
190        cmsis_drivers/Driver_Flash.c
191        cmsis_drivers/Driver_USART.c
192        device/source/device_definition.c
193        device/source/system_core_init.c
194        native_drivers/systimer_armv8-m_drv.c
195        native_drivers/uart_pl011_drv.c
196        $<$<BOOL:${TFM_MULTI_CORE_TOPOLOGY}>:${CMAKE_CURRENT_SOURCE_DIR}/platform_ns_mailbox.c>
197)
198
199target_include_directories(platform_ns
200    PUBLIC
201        .
202        ../common
203        ${PLATFORM_DIR}/..
204        cmsis_drivers
205        cmsis_drivers/config
206        device
207        device/config
208        device/include
209        device/source/armclang
210        native_drivers
211        partition
212)
213
214#========================= Platform BL2 =======================================#
215
216target_sources(platform_bl2
217    PRIVATE
218        tfm_hal_platform_reset.c
219        bl2/provisioning.c
220        cmsis_drivers/Driver_Flash.c
221        cmsis_drivers/Driver_USART.c
222        device/source/device_definition.c
223        device/source/system_core_init.c
224        native_drivers/atu_rss_drv.c
225        native_drivers/kmu_drv.c
226        native_drivers/mhu_v2_x.c
227        native_drivers/uart_pl011_drv.c
228        native_drivers/lcm_drv.c
229        otp_lcm.c
230        nv_counters.c
231)
232
233target_include_directories(platform_bl2
234    PUBLIC
235        .
236        cmsis_drivers
237        cmsis_drivers/config
238        device
239        device/config
240        device/include
241        device/source/armclang
242        native_drivers
243        partition
244        services/src
245
246    PRIVATE
247        ${PLATFORM_DIR}/..
248        native_drivers
249)
250
251target_link_libraries(platform_bl2
252    PRIVATE
253        $<$<AND:$<BOOL:${CONFIG_TFM_BOOT_STORE_MEASUREMENTS}>,$<BOOL:${TFM_PARTITION_MEASURED_BOOT}>>:tfm_boot_status>
254)
255
256target_compile_definitions(platform_bl2
257    PUBLIC
258        $<$<AND:$<BOOL:${CONFIG_TFM_BOOT_STORE_MEASUREMENTS}>,$<BOOL:${TFM_PARTITION_MEASURED_BOOT}>>:MEASURED_BOOT_API>
259)
260
261#========================= Platform BL1 =======================================#
262
263target_sources(platform_bl1
264    PRIVATE
265        ./bl1/boot_hal_bl1.c
266        ./cmsis_drivers/Driver_Flash.c
267        ./cmsis_drivers/Driver_USART.c
268        ./device/source/device_definition.c
269        ./device/source/system_core_init.c
270        ./native_drivers/atu_rss_drv.c
271        ./native_drivers/kmu_drv.c
272        ./native_drivers/uart_pl011_drv.c
273        ./native_drivers/lcm_drv.c
274        ./otp_lcm.c
275        ./nv_counters.c
276        ./tfm_hal_platform_reset.c
277)
278
279target_include_directories(platform_bl1_interface
280    INTERFACE
281        .
282        ./cmsis_drivers
283        ./cmsis_drivers/config
284        ./device/config
285        ./device/include
286        ./native_drivers
287)
288
289target_compile_definitions(platform_bl1
290    PUBLIC
291        $<$<AND:$<BOOL:${CONFIG_TFM_BOOT_STORE_MEASUREMENTS}>,$<BOOL:${TFM_PARTITION_MEASURED_BOOT}>>:MEASURED_BOOT_API>
292)
293
294#========================= ns_agent_mailbox ===================================#
295
296if(TFM_MULTI_CORE_TOPOLOGY)
297    target_sources(tfm_psa_rot_partition_ns_agent_mailbox
298        PRIVATE
299            ${CMAKE_CURRENT_SOURCE_DIR}/tfm_hal_multi_core.c
300    )
301endif()
302
303#========================= tfm_spm ============================================#
304
305target_sources(tfm_spm
306    PRIVATE
307        target_cfg.c
308        tfm_hal_isolation.c
309        tfm_hal_platform.c
310        tfm_interrupts.c
311        faults.c
312)
313
314#=========================== CPAK generator tool ===============================
315
316find_package(Python3)
317
318add_custom_target(cpak_generator
319    SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/cpak_generator/cpak_generator.c
320)
321
322add_dependencies(cpak_generator
323    bl1_2_padded_bin
324)
325
326add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/cpak_generator/cpak_generator
327    DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/cpak_generator/cpak_generator.c
328    COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/cpak_generator
329    COMMAND ${CMAKE_COMMAND} -S ${CMAKE_CURRENT_SOURCE_DIR}/cpak_generator
330                             -B ${CMAKE_CURRENT_BINARY_DIR}/cpak_generator
331                             -G ${CMAKE_GENERATOR}
332                             -DMBEDCRYPTO_PATH=${MBEDCRYPTO_PATH}
333                             -DBL1_2_HASH_PATH=\\\"$<TARGET_FILE_DIR:bl1_2>/bl1_2_padded_hash.bin\\\"
334                             -DGUK_PATH=\\\"${TFM_GUK_PATH}\\\"
335                             -DCPAK_OUTPUT_PATH=\\\"${CMAKE_CURRENT_BINARY_DIR}/cpak_generator/cpak_public.bin\\\"
336    COMMAND ${CMAKE_COMMAND} --build ${CMAKE_CURRENT_BINARY_DIR}/cpak_generator
337)
338
339add_custom_target(cpak_public ALL
340    DEPENDS ${TFM_GUK_PATH}
341    DEPENDS cpak_generator
342    DEPENDS ${CMAKE_BINARY_DIR}/bin/bl1_2_padded_hash.bin
343    DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/cpak_generator/cpak_generator
344    DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/cpak_generator/bin_to_pem.py
345    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/cpak_generator/
346    COMMAND ${CMAKE_CURRENT_BINARY_DIR}/cpak_generator/cpak_generator
347    COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/cpak_generator/bin_to_pem.py
348                    --input_key_file ${CMAKE_CURRENT_BINARY_DIR}/cpak_generator/cpak_public.bin
349                    --output_key_file ${CMAKE_CURRENT_BINARY_DIR}/cpak_generator/cpak_public.pem
350    COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/cpak_generator/cpak_public.bin $<TARGET_FILE_DIR:bl1_1>
351    COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/cpak_generator/cpak_public.pem $<TARGET_FILE_DIR:bl1_1>
352)
353