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_m2354.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_m2354.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/M2354/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        bsp/Library/StdDriver/src/tamper.c
78        ../common/services/src/tfm_platform_system.c
79        ${PLATFORM_DIR}/ext/common/uart_stdout.c
80        $<$<BOOL:${TFM_PARTITION_PLATFORM}>:${CMAKE_CURRENT_SOURCE_DIR}/plat_test.c>
81)
82
83target_compile_options(platform_s
84    PUBLIC
85        ${COMPILER_CMSE_FLAG}
86)
87
88target_link_libraries(platform_s INTERFACE cmsis)
89
90#========================= Platform BL2 =======================================#
91
92if(BL2)
93    target_sources(platform_bl2
94        PRIVATE
95            device/source/system_core_init.c
96            ../common/cmsis_drivers/Driver_Flash.c
97            ../common/native_drivers/arm_uart_drv.c
98            ../common/cmsis_drivers/Driver_USART.c
99            ../common/retarget/platform_retarget_dev.c
100            bsp/Library/StdDriver/src/fmc.c
101            bsp/Library/StdDriver/src/tamper.c
102    )
103    target_include_directories(platform_bl2
104        PUBLIC
105            partition
106            bsp/Device/Nuvoton/M2354/Include
107            bsp/Library/StdDriver/inc
108            ../common/bsp/Include
109            ../common/bsp/StdDriver/inc
110            device/include
111            device/config
112            ../common/cmsis_drivers/config
113        PRIVATE
114            .
115            ../common/
116            ${PLATFORM_DIR}/..
117            ../common/native_drivers
118    )
119endif()
120
121#========================= tfm_spm ============================================#
122
123target_sources(tfm_spm
124    PRIVATE
125        target_cfg.c
126        ../common/tfm_hal_isolation.c
127        ../common/tfm_hal_platform.c
128        ../common/faults.c
129        $<$<OR:$<BOOL:${CONFIG_TFM_FLIH_API}>,$<BOOL:${CONFIG_TFM_SLIH_API}>>:${PLATFORM_DIR}/ext/common/tfm_interrupts.c>
130)
131
132
133
134#========================= Files for building NS platform =====================#
135
136
137if(NS)
138    target_sources(tfm_ns
139        PRIVATE
140            ${CMAKE_CURRENT_SOURCE_DIR}/device/source/startup_m2354.c
141    )
142    target_add_scatter_file(tfm_ns
143        $<$<C_COMPILER_ID:ARMClang>:${CMAKE_CURRENT_SOURCE_DIR}/device/source/armclang/m2354_ns.sct>
144        $<$<C_COMPILER_ID:GNU>:${CMAKE_CURRENT_SOURCE_DIR}/device/source/gcc/m2354_ns.ld>
145        $<$<C_COMPILER_ID:IAR>:${CMAKE_CURRENT_SOURCE_DIR}/device/source/iar/m2354_ns.icf>
146    )
147    target_link_libraries(CMSIS_5_tfm_ns
148        INTERFACE
149            CMSIS_5_RTX_V8MBN
150    )
151endif()
152
153
154install(FILES       ${TARGET_PLATFORM_PATH}/device/source/startup_m2354.c
155                    ${PLATFORM_DIR}/ext/target/nuvoton/common/native_drivers/arm_uart_drv.c
156                    ${PLATFORM_DIR}/ext/target/nuvoton/common/native_drivers/timer_cmsdk.c
157        DESTINATION ${INSTALL_PLATFORM_NS_DIR})
158
159install(DIRECTORY   ${TARGET_PLATFORM_PATH}/device
160                    ${TARGET_PLATFORM_PATH}/bsp
161                    ${TARGET_PLATFORM_PATH}/../common/cmsis_drivers
162                    ${TARGET_PLATFORM_PATH}/../common/retarget
163        DESTINATION ${INSTALL_PLATFORM_NS_DIR})
164
165install(DIRECTORY   ${TARGET_PLATFORM_PATH}/../common/bsp/Include
166        DESTINATION ${INSTALL_PLATFORM_NS_DIR}/bsp/Device/Nuvoton/M2354)
167
168install(DIRECTORY   ${PLATFORM_DIR}/ext/target/nuvoton/common/bsp/StdDriver/inc
169        DESTINATION ${INSTALL_PLATFORM_NS_DIR}/bsp/Library/StdDriver)
170
171install(DIRECTORY   ${PLATFORM_DIR}/ext/driver
172        DESTINATION ${INSTALL_PLATFORM_NS_DIR}/include)
173
174install(FILES       ${PLATFORM_DIR}/ext/target/nuvoton/common/native_drivers/arm_uart_drv.h
175                    ${PLATFORM_DIR}/ext/target/nuvoton/common/native_drivers/timer_cmsdk.h
176                    ${PLATFORM_DIR}/ext/target/nuvoton/common/native_drivers/uart_cmsdk_drv.h
177                    ${PLATFORM_DIR}/ext/target/nuvoton/common/native_drivers/timer_cmsdk_drv.h
178                    ${PLATFORM_DIR}/ext/target/nuvoton/common/target_cfg.h
179                    ${PLATFORM_DIR}/ext/target/nuvoton/common/tfm_peripherals_def.h
180                    ${PLATFORM_DIR}/ext/target/nuvoton/common/bsp/Include/acmp_reg.h
181                    ${PLATFORM_DIR}/ext/target/nuvoton/common/bsp/Include/bpwm_reg.h
182                    ${PLATFORM_DIR}/ext/target/nuvoton/common/bsp/Include/crc_reg.h
183                    ${PLATFORM_DIR}/ext/target/nuvoton/common/bsp/Include/dac_reg.h
184                    ${PLATFORM_DIR}/ext/driver/Driver_USART.h
185                    ${PLATFORM_DIR}/ext/driver/Driver_Common.h
186                    ${PLATFORM_DIR}/include/tfm_plat_defs.h
187                    ${CMAKE_SOURCE_DIR}/lib/fih/inc/fih.h
188        DESTINATION ${INSTALL_PLATFORM_NS_DIR}/include)
189
190install(DIRECTORY   ${TARGET_PLATFORM_PATH}/partition
191        DESTINATION ${INSTALL_PLATFORM_NS_DIR})
192
193# copy all files from active platform directory
194install(DIRECTORY   ${TARGET_PLATFORM_PATH}/ns/
195        DESTINATION ${INSTALL_PLATFORM_NS_DIR})
196
197install(FILES       ${TARGET_PLATFORM_PATH}/cpuarch.cmake
198                    ${TARGET_PLATFORM_PATH}/config.cmake
199        DESTINATION ${INSTALL_PLATFORM_NS_DIR})
200
201install(FILES       ${TARGET_PLATFORM_PATH}/device/source/gcc/m2354_ns.ld
202                    ${TARGET_PLATFORM_PATH}/device/source/armclang/m2354_ns.sct
203                    ${TARGET_PLATFORM_PATH}/device/source/iar/m2354_ns.icf
204        DESTINATION ${INSTALL_PLATFORM_NS_DIR}/linker_scripts)
205
206# Install test configs
207install(DIRECTORY   ${TARGET_PLATFORM_PATH}/tests
208        DESTINATION ${INSTALL_PLATFORM_NS_DIR})
209