diff options
-rw-r--r-- | CMakeLists.txt | 10 | ||||
-rw-r--r-- | cmsis.cmake | 32 |
2 files changed, 39 insertions, 3 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 564d4d0..537e9a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,6 +38,15 @@ set_property(CACHE CORE_SOFTWARE_ACCELERATOR PROPERTY STRINGS CPU CMSIS-NN NPU) set(CORE_SOFTWARE_RTOS "None" CACHE STRING "Select RTOS to include. (None, MbedOS, FreeRTOS, Zephyr)") string(TOLOWER ${CORE_SOFTWARE_RTOS} CORE_SOFTWARE_RTOS_LOWER) +# Set trustzone options +set(TRUSTZONE_BUILD OFF CACHE BOOL "Enable TrustZone build") +if (TRUSTZONE_BUILD) + set(TRUSTZONE_SIDE "secure" CACHE STRING "Select secure or nonsecure") + set_property(CACHE TRUSTZONE_SIDE PROPERTY STRINGS secure nonsecure) + set(TRUSTZONE_PARTITION_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" CACHE + FILEPATH "Path to CMSIS partion header for device") +endif() + # # Build # @@ -45,6 +54,7 @@ add_library(ethosu_core INTERFACE) # Build CMSIS include(cmsis.cmake) +target_link_libraries(ethosu_core INTERFACE cmsis_core cmsis_device) # Build core driver if (CORE_SOFTWARE_ACCELERATOR STREQUAL "NPU") diff --git a/cmsis.cmake b/cmsis.cmake index 4615c58..9322240 100644 --- a/cmsis.cmake +++ b/cmsis.cmake @@ -43,15 +43,41 @@ target_include_directories(cmsis_core INTERFACE ${CMSIS_PATH}/CMSIS/Core/Include # CMSIS device add_library(cmsis_device INTERFACE) target_include_directories(cmsis_device INTERFACE ${CMSIS_PATH}/Device/ARM/${ARM_CPU}/Include) +if (TRUSTZONE_BUILD) + # Use Cortex-M Secure Extension when compiling + target_compile_options(cmsis_device INTERFACE -mcmse) + target_compile_definitions(cmsis_device INTERFACE TRUSTZONE_BUILD) + if (TRUSTZONE_SIDE STREQUAL secure) + target_compile_definitions(cmsis_device INTERFACE TRUSTZONE_SECURE) + else() + target_compile_definitions(cmsis_device INTERFACE TRUSTZONE_NONSECURE) + endif() +endif() target_compile_options(cmsis_device INTERFACE -include${ARM_CPU}${ARM_FEATURES}.h) target_link_libraries(cmsis_device INTERFACE cmsis_core) # CMSIS startup -add_library(cmsis_startup STATIC - ${CMSIS_PATH}/Device/ARM/${ARM_CPU}/Source/startup_${ARM_CPU}.c - ${CMSIS_PATH}/Device/ARM/${ARM_CPU}/Source/system_${ARM_CPU}.c) +add_library(cmsis_startup STATIC) +if (TRUSTZONE_BUILD) + if (TRUSTZONE_SIDE STREQUAL secure) + target_sources(cmsis_startup PRIVATE + ${CMSIS_PATH}/Device/ARM/${ARM_CPU}/Source/startup_${ARM_CPU}.c + ${CMSIS_PATH}/Device/ARM/${ARM_CPU}/Source/system_${ARM_CPU}.c) + # Bring in the partion header + target_include_directories(cmsis_startup PRIVATE ${TRUSTZONE_PARTITION_DIRECTORY}) + elseif(TRUSTZONE_SIDE STREQUAL nonsecure) + target_sources(cmsis_startup PRIVATE + ${CMSIS_PATH}/Device/ARM/${ARM_CPU}/Source/startup_${ARM_CPU}.c) + endif() +else() + target_sources(cmsis_startup PRIVATE + ${CMSIS_PATH}/Device/ARM/${ARM_CPU}/Source/startup_${ARM_CPU}.c + ${CMSIS_PATH}/Device/ARM/${ARM_CPU}/Source/system_${ARM_CPU}.c) +endif() + set_source_files_properties(${CMSIS_PATH}/Device/ARM/${ARM_CPU}/Source/startup_${ARM_CPU}.c PROPERTIES COMPILE_FLAGS -Wno-redundant-decls) + target_compile_definitions(cmsis_startup PRIVATE ${ARM_CPU}${ARM_FEATURES}) target_link_libraries(cmsis_startup PRIVATE cmsis_device) |