1#------------------------------------------------------------------------------- 2# SPDX-License-Identifier: BSD-3-Clause 3# SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors 4# 5#------------------------------------------------------------------------------- 6 7 8# initialize pico-sdk from GIT 9set(PICO_SDK_FETCH_FROM_GIT on) 10set(PICO_PLATFORM rp2350-arm-s) 11set(SKIP_BOOT_STAGE2 1) 12 13# initialize the Raspberry Pi Pico SDK 14include(${CMAKE_CURRENT_LIST_DIR}/pico_sdk_import.cmake) 15pico_sdk_init() 16 17get_target_property(pico_link_options pico_standard_link INTERFACE_LINK_OPTIONS) 18list(FILTER pico_link_options EXCLUDE REGEX "LINKER.*--script") 19list(APPEND pico_link_options "--entry=_entry_point") 20set_target_properties(pico_standard_link PROPERTIES INTERFACE_LINK_OPTIONS "${pico_link_options}") 21set_target_properties(pico_runtime PROPERTIES INTERFACE_LINK_OPTIONS "") 22 23target_compile_options(cmsis_core 24 INTERFACE 25 ${COMPILER_CMSE_FLAG} 26) 27 28cmake_policy(SET CMP0076 NEW) 29set(CMAKE_CURRENT_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}) 30 31set(STATIC_ASSERT_OVERRIDE_HEADER "${CMAKE_CURRENT_LIST_DIR}/static_assert_override.h") 32add_library(static_assert_override INTERFACE) 33target_compile_options(static_assert_override 34 INTERFACE 35 "$<$<C_COMPILER_ID:Armclang>:SHELL:-include ${STATIC_ASSERT_OVERRIDE_HEADER}>" 36 "$<$<C_COMPILER_ID:GNU>:SHELL:-include ${STATIC_ASSERT_OVERRIDE_HEADER}>" 37 "$<$<C_COMPILER_ID:IAR>:SHELL:--preinclude ${STATIC_ASSERT_OVERRIDE_HEADER}>" 38) 39 40#========================= Platform region defs ===============================# 41 42add_library(platform_s_init INTERFACE) 43target_sources(platform_s_init 44 INTERFACE 45 ${CMAKE_CURRENT_LIST_DIR}/extra_init.c 46) 47 48target_link_libraries(platform_s_init 49 INTERFACE 50 pico_runtime_init 51 pico_runtime_headers 52 pico_bootrom_headers 53) 54 55target_link_options(tfm_s 56 PUBLIC 57 "--entry=_entry_point" 58) 59 60target_include_directories(platform_region_defs 61 INTERFACE 62 partition 63) 64 65target_link_libraries(platform_region_defs 66 INTERFACE 67 tfm_fih_headers 68 hardware_regs_headers 69 static_assert_override 70) 71 72target_compile_definitions(platform_region_defs 73 INTERFACE 74 PROVISIONING_CODE_PADDED_SIZE=${PROVISIONING_CODE_PADDED_SIZE} 75 PROVISIONING_VALUES_PADDED_SIZE=${PROVISIONING_VALUES_PADDED_SIZE} 76 PROVISIONING_DATA_PADDED_SIZE=${PROVISIONING_DATA_PADDED_SIZE} 77) 78 79if(NOT PLATFORM_DEFAULT_PROVISIONING) 80 add_subdirectory(${PLATFORM_DIR}/ext/common/provisioning_bundle provisioning) 81 82 target_include_directories(provisioning_bundle 83 INTERFACE 84 ${PLATFORM_DIR}/../interface/include 85 ) 86 87 if(NOT PLATFORM_DEFAULT_PROV_LINKER_SCRIPT) 88 target_add_scatter_file(provisioning_bundle 89 linker_provisioning.ld 90 ) 91 92 target_compile_definitions(provisioning_bundle_scatter 93 PRIVATE 94 # u modifier in scatter file is not valid 95 NO_U_MODIFIER=1 96 ) 97 endif() 98endif() 99 100if(TFM_PARTITION_CRYPTO) 101 target_include_directories(platform_crypto_keys 102 PRIVATE 103 ${CMAKE_CURRENT_LIST_DIR} 104 ) 105endif() 106 107#========================= Platform common defs ===============================# 108 109# Specify the location of platform specific build dependencies. 110target_add_scatter_file(tfm_s 111 $<$<C_COMPILER_ID:ARMClang>:${CMAKE_BINARY_DIR}/generated/platform/ext/common/armclang/tfm_common_s.sct> 112 linker_s.ld 113 $<$<C_COMPILER_ID:IAR>:${CMAKE_BINARY_DIR}/generated/platform/ext/common/iar/tfm_common_s.icf> 114) 115target_compile_definitions(tfm_s_scatter 116 PRIVATE 117 # u modifier in scatter file is not valid 118 NO_U_MODIFIER=1 119) 120target_compile_options(tfm_s_scatter 121 PUBLIC 122 ${COMPILER_CMSE_FLAG} 123) 124 125if(BL2) 126 # Pico startup and runtime init 127 target_link_libraries(bl2 128 PUBLIC 129 pico_runtime 130 ) 131 target_add_scatter_file(bl2 132 $<$<C_COMPILER_ID:ARMClang>:${PLATFORM_DIR}/ext/common/armclang/tfm_common_bl2.sct> 133 linker_bl2.ld 134 $<$<C_COMPILER_ID:IAR>:${PLATFORM_DIR}/ext/common/iar/tfm_common_bl2.icf> 135 ) 136 target_compile_definitions(bl2_scatter 137 PRIVATE 138 # u modifier in scatter file is not valid 139 NO_U_MODIFIER=1 140 ) 141 142 target_compile_options(bl2_scatter 143 PUBLIC 144 ${COMPILER_CMSE_FLAG} 145 ) 146endif() 147 148#========================= Platform Secure ====================================# 149 150target_include_directories(platform_s 151 PUBLIC 152 . 153 cmsis_drivers 154 partition 155 device/config 156 ${PLATFORM_DIR}/.. 157 INTERFACE 158 ${PLATFORM_DIR}/../interface/include 159) 160 161target_link_libraries(platform_s 162 PUBLIC 163 cmsis_core_headers 164 hardware_uart_headers 165 platform_s_init 166 PRIVATE 167 pico_crt0 168 pico_rand 169 pico_multicore 170 hardware_regs 171 hardware_flash 172 hardware_uart 173 cmsis_core 174 tfm_sprt 175) 176 177target_sources(platform_s 178 INTERFACE 179 $<$<STREQUAL:"${TFM_FIH_PROFILE}","HIGH">:${PLATFORM_DIR}/ext/common/template/tfm_fih_rng.c> 180 PRIVATE 181 cmsis_drivers/Driver_Flash_RPI.c 182 cmsis_drivers/Driver_USART_RPI.c 183 184 tfm_peripherals_def.c 185 186 rpi_trng.c 187 188 $<$<OR:$<BOOL:${TFM_S_REG_TEST}>,$<BOOL:${TFM_NS_REG_TEST}>>:${CMAKE_CURRENT_SOURCE_DIR}/plat_test.c> 189 $<$<BOOL:${TFM_PARTITION_PLATFORM}>:${CMAKE_CURRENT_SOURCE_DIR}/services/src/tfm_platform_system.c> 190 $<$<AND:$<BOOL:${ITS_ENCRYPTION}>,$<BOOL:${TFM_PARTITION_INTERNAL_TRUSTED_STORAGE}>>:${PLATFORM_DIR}/ext/common/template/tfm_hal_its_encryption.c> 191 $<$<NOT:$<BOOL:${PLATFORM_DEFAULT_OTP}>>:${CMAKE_CURRENT_SOURCE_DIR}/rp2350_otp.c> 192 $<$<NOT:$<BOOL:${PLATFORM_DEFAULT_NV_COUNTERS}>>:${CMAKE_CURRENT_SOURCE_DIR}/nv_counters.c> 193 $<$<BOOL:${TFM_MULTI_CORE_TOPOLOGY}>:${CMAKE_CURRENT_SOURCE_DIR}/tfm_hal_multi_core.c> 194 $<$<BOOL:${TFM_NS_MAILBOX_API}>:${CMAKE_CURRENT_SOURCE_DIR}/tfm_hal_mailbox.c> 195) 196 197target_compile_options(platform_s 198 PUBLIC 199 ${COMPILER_CMSE_FLAG} 200) 201 202target_compile_definitions(platform_s 203 PUBLIC 204 CMSIS_device_header=<RP2350.h> 205 PICO_UART_DEFAULT_CRLF=1 206 $<$<BOOL:${PS_NS_NV_COUNTER_IN_ITS}>:PS_NS_NV_COUNTER_IN_ITS=1> 207 $<$<BOOL:${TEST_NS_FPU}>:TEST_NS_FPU> 208 $<$<BOOL:${TEST_S_FPU}>:TEST_S_FPU> 209 $<$<BOOL:${ITS_ENCRYPTION}>:ITS_ENCRYPTION> 210 $<$<BOOL:${TFM_MULTI_CORE_TOPOLOGY}>:TFM_MULTI_CORE_TOPOLOGY> 211) 212 213# GNU Arm compiler version greater equal than *11.3.Rel1* 214# throw warning when linker segments used as rwx 215# Adding --no-warn-rwx-segments like the RPi SDK did. 216if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 11.3.1) 217 target_link_options(platform_s INTERFACE "LINKER:--no-warn-rwx-segments") 218endif() 219 220#========================= Platform BL2 =======================================# 221 222if(BL2) 223 target_sources(platform_bl2 224 PRIVATE 225 cmsis_drivers/Driver_Flash_RPI_bl2.c 226 cmsis_drivers/Driver_USART_RPI.c 227 $<$<NOT:$<BOOL:${PLATFORM_DEFAULT_OTP}>>:${CMAKE_CURRENT_SOURCE_DIR}/rp2350_otp.c> 228 $<$<NOT:$<BOOL:${PLATFORM_DEFAULT_NV_COUNTERS}>>:${CMAKE_CURRENT_SOURCE_DIR}/nv_counters.c> 229 ) 230 231 target_link_libraries(platform_bl2 232 PUBLIC 233 cmsis_core_headers 234 hardware_uart_headers 235 PRIVATE 236 pico_runtime_headers 237 pico_runtime_init 238 hardware_regs 239 hardware_flash 240 hardware_uart 241 cmsis_core 242 ) 243 244 # GNU Arm compiler version greater equal than *11.3.Rel1* 245 # throw warning when linker segments used as rwx 246 # Adding --no-warn-rwx-segments like the RPi SDK did. 247 if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 11.3.1) 248 target_link_options(platform_bl2 INTERFACE "LINKER:--no-warn-rwx-segments") 249 endif() 250 251 target_include_directories(platform_bl2 252 PUBLIC 253 partition 254 retarget 255 device/config 256 device/include 257 PRIVATE 258 . 259 ) 260 261 target_compile_definitions(platform_bl2 262 PUBLIC 263 PICO_UART_DEFAULT_CRLF=1 264 CMSIS_device_header=<RP2350.h> 265 ) 266 267 target_include_directories(bl2 268 PRIVATE 269 ${CMAKE_CURRENT_LIST_DIR} 270) 271 272endif() 273 274#========================= tfm_spm ============================================# 275 276target_sources(tfm_spm 277 PRIVATE 278 target_cfg.c 279 tfm_hal_platform.c 280 tfm_hal_isolation_rp2350.c 281 $<$<OR:$<BOOL:${CONFIG_TFM_FLIH_API}>,$<BOOL:${CONFIG_TFM_SLIH_API}>>:${PLATFORM_DIR}/ext/common/tfm_interrupts.c> 282) 283 284target_link_libraries(tfm_spm 285 PRIVATE 286 pico_bootrom_headers 287) 288 289#========================= Platform Crypto Keys ===============================# 290 291if (TFM_PARTITION_CRYPTO) 292 target_sources(platform_crypto_keys 293 PRIVATE 294 crypto_keys.c 295 ) 296 target_link_libraries(platform_crypto_keys 297 PRIVATE 298 platform_s 299 ) 300endif() 301 302#========================= Files for building NS platform =====================# 303 304install(FILES ${PLATFORM_DIR}/ext/common/test_interrupt.c 305 ${TARGET_PLATFORM_PATH}/cmsis_drivers/Driver_USART_RPI.c 306 ${TARGET_PLATFORM_PATH}/pico-sdk.patch 307 DESTINATION ${INSTALL_PLATFORM_NS_DIR}) 308 309install(DIRECTORY ${TARGET_PLATFORM_PATH}/device 310 ${TARGET_PLATFORM_PATH}/cmsis_drivers 311 DESTINATION ${INSTALL_PLATFORM_NS_DIR}) 312 313install(DIRECTORY ${PLATFORM_DIR}/ext/target/arm/drivers 314 DESTINATION ${INSTALL_PLATFORM_NS_DIR}/ext/target/arm) 315 316install(FILES ${PLATFORM_DIR}/ext/driver/Driver_USART.h 317 ${PLATFORM_DIR}/ext/driver/Driver_Common.h 318 DESTINATION ${INSTALL_PLATFORM_NS_DIR}/ext/driver) 319 320install(FILES ${TARGET_PLATFORM_PATH}/partition/region_defs.h 321 ${TARGET_PLATFORM_PATH}/partition/flash_layout.h 322 ${TARGET_PLATFORM_PATH}/target_cfg.h 323 ${TARGET_PLATFORM_PATH}/tfm_peripherals_def.h 324 ${TARGET_PLATFORM_PATH}/platform_multicore.h 325 ${TARGET_PLATFORM_PATH}/tfm_builtin_key_ids.h 326 ${PLATFORM_DIR}/include/tfm_plat_defs.h 327 ${CMAKE_SOURCE_DIR}/lib/fih/inc/fih.h 328 DESTINATION ${INSTALL_PLATFORM_NS_DIR}/include) 329 330install(FILES ${TARGET_PLATFORM_PATH}/linker_ns.ld 331 DESTINATION ${INSTALL_PLATFORM_NS_DIR}/linker_scripts) 332 333# copy all files from active platform directory 334install(DIRECTORY ${TARGET_PLATFORM_PATH}/ns/ 335 DESTINATION ${INSTALL_PLATFORM_NS_DIR}) 336 337install(FILES ${TARGET_PLATFORM_PATH}/cpuarch.cmake 338 ${TARGET_PLATFORM_PATH}/pico_sdk_import.cmake 339 DESTINATION ${INSTALL_PLATFORM_NS_DIR}) 340 341# Copy the platform specific config 342install(FILES ${TARGET_PLATFORM_PATH}/config.cmake 343 ${STATIC_ASSERT_OVERRIDE_HEADER} 344 DESTINATION ${INSTALL_PLATFORM_NS_DIR}) 345 346# Install test configs 347install(DIRECTORY ${TARGET_PLATFORM_PATH}/tests 348 DESTINATION ${INSTALL_PLATFORM_NS_DIR}) 349