1#-------------------------------------------------------------------------------
2# Copyright (c) 2020-2024, Arm Limited. All rights reserved.
3# Copyright (c) 2020 Nuvoton Technology Corp. All rights reserved.
4#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7#-------------------------------------------------------------------------------
8
9cmake_policy(SET CMP0076 NEW)
10set(CMAKE_CURRENT_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR})
11
12#========================= Platform region defs ===============================#
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_m2351.c
24)
25target_add_scatter_file(tfm_s
26    $<$<AND:$<VERSION_LESS:${TFM_ISOLATION_LEVEL},3>,$<C_COMPILER_ID:ARMClang>>:${CMAKE_SOURCE_DIR}/platform/ext/common/armclang/tfm_common_s.sct>
27    $<$<AND:$<VERSION_LESS:${TFM_ISOLATION_LEVEL},3>,$<C_COMPILER_ID:GNU>>:${CMAKE_SOURCE_DIR}/platform/ext/common/gcc/tfm_common_s.ld>
28    $<$<AND:$<VERSION_LESS:${TFM_ISOLATION_LEVEL},3>,$<C_COMPILER_ID:IAR>>:${CMAKE_SOURCE_DIR}/platform/ext/common/iar/tfm_common_s.icf>
29)
30
31if(BL2)
32    target_sources(bl2
33        PRIVATE
34            ${CMAKE_CURRENT_SOURCE_DIR}/device/source/startup_m2351.c
35    )
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        ../common/cmsis_drivers/config
51        ../common/native_drivers
52        ../common/retarget
53        partition
54        device/include
55        device/config
56        bsp/Device/Nuvoton/M2351/Include
57        bsp/Library/StdDriver/inc
58        ../common/bsp/Include
59        ../common/bsp/StdDriver/inc
60        ${PLATFORM_DIR}/ext/driver
61)
62
63target_sources(platform_s
64    PRIVATE
65        device/source/system_core_init.c
66        ../common/cmsis_drivers/Driver_Flash.c
67        ../common/cmsis_drivers/Driver_USART.c
68        ../common/native_drivers/arm_uart_drv.c
69        ../common/native_drivers/mpu_armv8m_drv.c
70        ../common/native_drivers/timer_cmsdk_drv.c
71        ../common/native_drivers/timer_cmsdk.c
72        ../common/retarget/platform_retarget_dev.c
73        bsp/Library/StdDriver/src/timer.c
74        bsp/Library/StdDriver/src/clk.c
75        bsp/Library/StdDriver/src/sys.c
76        bsp/Library/StdDriver/src/fmc.c
77        ../common/services/src/tfm_platform_system.c
78        ${PLATFORM_DIR}/ext/common/uart_stdout.c
79        $<$<BOOL:${TFM_PARTITION_PLATFORM}>:${CMAKE_CURRENT_SOURCE_DIR}/plat_test.c>
80)
81
82target_compile_options(platform_s
83    PUBLIC
84        ${COMPILER_CMSE_FLAG}
85)
86
87target_link_libraries(platform_s INTERFACE cmsis)
88
89#========================= Platform BL2 =======================================#
90
91if(BL2)
92    target_sources(platform_bl2
93        PRIVATE
94            device/source/system_core_init.c
95            ../common/cmsis_drivers/Driver_Flash.c
96            ../common/native_drivers/arm_uart_drv.c
97            ../common/cmsis_drivers/Driver_USART.c
98            ../common/retarget/platform_retarget_dev.c
99            bsp/Library/StdDriver/src/fmc.c
100    )
101    target_include_directories(platform_bl2
102        PUBLIC
103            partition
104            bsp/Device/Nuvoton/M2351/Include
105            bsp/Library/StdDriver/inc
106            ../common/bsp/Include
107            ../common/bsp/StdDriver/inc
108            device/include
109            device/config
110            ../common/cmsis_drivers/config
111        PRIVATE
112            .
113            ../common/
114            ${PLATFORM_DIR}/..
115            ../common/native_drivers
116    )
117endif()
118
119#========================= tfm_spm ============================================#
120
121target_sources(tfm_spm
122    PRIVATE
123        target_cfg.c
124        ../common/tfm_hal_isolation.c
125        ../common/tfm_hal_platform.c
126        ../common/faults.c
127        $<$<OR:$<BOOL:${CONFIG_TFM_FLIH_API}>,$<BOOL:${CONFIG_TFM_SLIH_API}>>:${PLATFORM_DIR}/ext/common/tfm_interrupts.c>
128)
129
130
131
132#========================= Files for building NS platform =====================#
133
134
135if(NS)
136    target_sources(tfm_ns
137        PRIVATE
138            ${CMAKE_CURRENT_SOURCE_DIR}/device/source/startup_m2351.c
139    )
140    target_add_scatter_file(tfm_ns
141        $<$<C_COMPILER_ID:ARMClang>:${CMAKE_CURRENT_SOURCE_DIR}/device/source/armclang/m2351_ns.sct>
142        $<$<C_COMPILER_ID:GNU>:${CMAKE_CURRENT_SOURCE_DIR}/device/source/gcc/m2351_ns.ld>
143        $<$<C_COMPILER_ID:IAR>:${CMAKE_CURRENT_SOURCE_DIR}/device/source/iar/m2351_ns.icf>
144    )
145    target_link_libraries(CMSIS_5_tfm_ns
146        INTERFACE
147            CMSIS_5_RTX_V8MBN
148    )
149endif()
150
151
152install(FILES       ${TARGET_PLATFORM_PATH}/device/source/startup_m2351.c
153                    ${PLATFORM_DIR}/ext/target/nuvoton/common/native_drivers/arm_uart_drv.c
154                    ${PLATFORM_DIR}/ext/target/nuvoton/common/native_drivers/timer_cmsdk.c
155        DESTINATION ${INSTALL_PLATFORM_NS_DIR})
156
157install(DIRECTORY   ${TARGET_PLATFORM_PATH}/device
158                    ${TARGET_PLATFORM_PATH}/bsp
159                    ${TARGET_PLATFORM_PATH}/../common/cmsis_drivers
160                    ${TARGET_PLATFORM_PATH}/../common/retarget
161        DESTINATION ${INSTALL_PLATFORM_NS_DIR})
162
163install(DIRECTORY   ${TARGET_PLATFORM_PATH}/../common/bsp/Include
164        DESTINATION ${INSTALL_PLATFORM_NS_DIR}/bsp/Device/Nuvoton/M2351)
165
166install(DIRECTORY   ${PLATFORM_DIR}/ext/target/nuvoton/common/bsp/StdDriver/inc
167        DESTINATION ${INSTALL_PLATFORM_NS_DIR}/bsp/Library/StdDriver)
168
169install(DIRECTORY   ${PLATFORM_DIR}/ext/driver
170        DESTINATION ${INSTALL_PLATFORM_NS_DIR}/include)
171
172install(FILES       ${PLATFORM_DIR}/ext/target/nuvoton/common/native_drivers/arm_uart_drv.h
173                    ${PLATFORM_DIR}/ext/target/nuvoton/common/native_drivers/timer_cmsdk.h
174                    ${PLATFORM_DIR}/ext/target/nuvoton/common/native_drivers/uart_cmsdk_drv.h
175                    ${PLATFORM_DIR}/ext/target/nuvoton/common/native_drivers/timer_cmsdk_drv.h
176                    ${PLATFORM_DIR}/ext/target/nuvoton/common/target_cfg.h
177                    ${PLATFORM_DIR}/ext/target/nuvoton/common/tfm_peripherals_def.h
178                    ${PLATFORM_DIR}/ext/target/nuvoton/common/bsp/Include/acmp_reg.h
179                    ${PLATFORM_DIR}/ext/target/nuvoton/common/bsp/Include/bpwm_reg.h
180                    ${PLATFORM_DIR}/ext/target/nuvoton/common/bsp/Include/crc_reg.h
181                    ${PLATFORM_DIR}/ext/target/nuvoton/common/bsp/Include/dac_reg.h
182                    ${PLATFORM_DIR}/ext/driver/Driver_USART.h
183                    ${PLATFORM_DIR}/ext/driver/Driver_Common.h
184                    ${PLATFORM_DIR}/include/tfm_plat_defs.h
185                    ${CMAKE_SOURCE_DIR}/lib/fih/inc/fih.h
186        DESTINATION ${INSTALL_PLATFORM_NS_DIR}/include)
187
188install(DIRECTORY   ${TARGET_PLATFORM_PATH}/partition
189        DESTINATION ${INSTALL_PLATFORM_NS_DIR})
190
191# copy all files from active platform directory
192install(DIRECTORY   ${TARGET_PLATFORM_PATH}/ns/
193        DESTINATION ${INSTALL_PLATFORM_NS_DIR})
194
195install(FILES       ${TARGET_PLATFORM_PATH}/cpuarch.cmake
196                    ${TARGET_PLATFORM_PATH}/config.cmake
197        DESTINATION ${INSTALL_PLATFORM_NS_DIR})
198
199install(FILES       ${TARGET_PLATFORM_PATH}/device/source/gcc/m2351_ns.ld
200                    ${TARGET_PLATFORM_PATH}/device/source/armclang/m2351_ns.sct
201                    ${TARGET_PLATFORM_PATH}/device/source/iar/m2351_ns.icf
202        DESTINATION ${INSTALL_PLATFORM_NS_DIR}/linker_scripts)
203
204# Install test configs
205install(DIRECTORY   ${TARGET_PLATFORM_PATH}/tests
206        DESTINATION ${INSTALL_PLATFORM_NS_DIR})
207