44
55cmake_minimum_required (VERSION 3.21.0 FATAL_ERROR)
66
7+ # NS target name the TF-M api_ns CMakeLists.txt uses
8+ set (NS_TARGET_NAME speech-recognition)
79set (ML_INFERENCE_ENGINE "ETHOS" CACHE STRING "Machine Learning inference engine (ETHOS)" )
810set (AUDIO_SOURCE "ROM" CACHE STRING "Source of audio data (ROM | VSI)" )
911set (APPLICATION_PATH "${IOT_REFERENCE_ARM_CORSTONE3XX_SOURCE_DIR} /applications/speech_recognition" CACHE STRING "Path to the application folder" )
@@ -22,10 +24,7 @@ set(AWS_OTA_SIGNATURE_TYPE "RSA-3072" CACHE STRING "Supported algorithms for si
2224# Because of this, if only PATCH version is changed then the OTA will be rejected
2325# due to same firmware version.
2426# We will therefore change the build version from TF-M.
25- set (MCUBOOT_IMAGE_VERSION_NS "0.0.1+10" )
2627set (MCUBOOT_IMAGE_VERSION_NS_UPDATE "0.0.1+20" )
27- set (MCUBOOT_IMAGE_NUMBER 2 CACHE STRING "Total number of firmware images" )
28- set (DEFAULT_MCUBOOT_FLASH_MAP ON )
2928
3029if (${ML_INFERENCE_ENGINE} STREQUAL "ETHOS" )
3130 set (ETHOS_U_NPU_ENABLED ON )
@@ -36,31 +35,14 @@ endif()
3635set (ML_USE_CASE "asr" )
3736set (ML_MODEL "GenerateASRModel" )
3837set (ML_USE_CASE_RESOURCES_FILE "${CMAKE_CURRENT_LIST_DIR} /resources/use_case_resources.json" )
39- set (TFM_PLATFORM_UPGRADE_STRATEGY "SWAP_USING_SCRATCH" )
40- set (TFM_PLATFORM_CONFIRM_IMAGE ON )
41-
42- # Trusted Firmware-M setup
43- set (TFM_CMAKE_APP_ARGS
44- -DPROJECT_CONFIG_HEADER_FILE=${IOT_REFERENCE_ARM_CORSTONE3XX_SOURCE_DIR} /applications/speech_recognition/configs/tfm_config/project_config.h
45- -DMCUBOOT_CONFIRM_IMAGE=${TFM_PLATFORM_CONFIRM_IMAGE}
46- -DMCUBOOT_UPGRADE_STRATEGY=${TFM_PLATFORM_UPGRADE_STRATEGY}
47- -DMCUBOOT_IMAGE_VERSION_NS=${MCUBOOT_IMAGE_VERSION_NS}
48- -DCONFIG_TFM_HALT_ON_CORE_PANIC=ON
49- -DMCUBOOT_DATA_SHARING=ON
50- -DPLATFORM_HAS_FIRMWARE_UPDATE_SUPPORT=ON
51- -DTFM_PARTITION_FIRMWARE_UPDATE=ON
52- -DTFM_PARTITION_LOG_LEVEL=TFM_PARTITION_LOG_LEVEL_INFO
53- )
5438
55- project (speech-recognition LANGUAGES C CXX)
39+ # Toolchain file has to be included before the very first project() call
40+ include (${IOT_REFERENCE_ARM_CORSTONE3XX_SOURCE_DIR} /components/security/trusted_firmware-m/integration/cmake/TfmNsToolchain.cmake)
5641
57- # Set global optimization level to reduce code size while keeping the debug experience.
58- if (${CMAKE_C_COMPILER_ID} STREQUAL "GNU" )
59- add_compile_options (-Og)
60- elseif (${CMAKE_C_COMPILER_ID} STREQUAL "ARMClang" )
61- add_compile_options (-O1)
62- endif ()
42+ project (speech-recognition LANGUAGES C CXX)
6343
44+ set_compiler_and_linker_flags()
45+ include (${CONFIG_SPE_PATH} /config/cp_check.cmake)
6446
6547add_subdirectory (${IOT_REFERENCE_ARM_CORSTONE3XX_SOURCE_DIR} ${CMAKE_BINARY_DIR} /iot_reference_arm_corstone3xx)
6648
@@ -85,6 +67,7 @@ add_executable(speech-recognition
8567 main.c
8668 ml_interface.cc
8769 model_config.cc
70+ ${CONFIG_SPE_PATH} /interface /src/os_wrapper/tfm_ns_interface_rtos.c
8871)
8972
9073target_include_directories (speech-recognition
@@ -136,10 +119,6 @@ target_compile_options(speech-recognition
136119 $<$<COMPILE_LANGUAGE:C>:-std=c99>
137120)
138121
139- # Trusted Firmware-M must be built before the application, because
140- # the application depends on the NS interface and the BL2 signing scripts,
141- # both of which are generated as parts of the Trusted Firmware-M build process.
142- add_dependencies (speech-recognition trusted_firmware-m-build )
143122# The provision data must be built before the application because
144123# it provides credentials to connect to AWS.
145124add_dependencies (speech-recognition provisioning_data_bin)
@@ -159,37 +138,41 @@ target_link_libraries(speech-recognition
159138 ota-update
160139 provisioning-lib
161140 speexdsp
162- tfm-ns- interface
141+ tfm_api_ns
163142 toolchain-override
164143 asr_api
165144 asr_model
166145 helpers-logging
146+ # FRI always uses TrustZone
147+ tfm_api_ns_tz
167148)
168149
169150include (${IOT_REFERENCE_ARM_CORSTONE3XX_SOURCE_DIR} /bsp/cmake/SetLinkerOptions.cmake)
170151set_linker_script(speech-recognition)
171152
172153list (APPEND CMAKE_MODULE_PATH ${IOT_REFERENCE_ARM_CORSTONE3XX_SOURCE_DIR} /tools/cmake)
173154include (ConvertElfToBin)
174- include (ExternalProject)
175- ExternalProject_Get_Property(trusted_firmware-m-build BINARY_DIR)
176155
177156extract_sections_from_axf(
178157 speech-recognition
179158 SECTIONS_NAMES "ddr.bin"
180159 OUTPUT_BIN_NAME "ns_image"
181160)
182161
183- # The non-secure application image should be padded while being signed
184- # Hence, passing "TRUE" as the input parameter to the pad option of sign function.
185- iot_reference_arm_corstone3xx_tf_m_sign_image(
186- speech-recognition
187- "ns_image"
188- speech-recognition_signed
189- ${MCUBOOT_IMAGE_VERSION_NS}
190- "${BINARY_DIR} /api_ns/image_signing/layout_files/signing_layout_ns.o"
191- TRUE
162+ # Copy the binary flash content to the location expected by default signing
163+ # Signing is implemented in the exported TF-M NS CMakeLists.txt (in the
164+ # ${CONFIG_SPE_PATH} directory)
165+ add_custom_target (speech-recognition_bin
166+ SOURCES ${CMAKE_BINARY_DIR} /speech-recognition.bin
167+ DEPENDS speech-recognition
192168)
169+ add_custom_command (OUTPUT ${CMAKE_BINARY_DIR} /speech-recognition.bin
170+ DEPENDS speech-recognition
171+ COMMAND ${CMAKE_COMMAND}
172+ -E copy ${SECTORS_BIN_DIR} /ns_image.bin
173+ ${CMAKE_BINARY_DIR} /speech-recognition.bin
174+ )
175+
193176
194177# The update image is not padded to fill the whole slot (no --pad), because
195178# 1) the image to download is smaller without padding
@@ -200,7 +183,7 @@ iot_reference_arm_corstone3xx_tf_m_sign_image(
200183 "ns_image"
201184 speech-recognition-update_signed
202185 ${MCUBOOT_IMAGE_VERSION_NS_UPDATE}
203- "${BINARY_DIR} /api_ns /image_signing/layout_files/signing_layout_ns.o"
186+ "${CONFIG_SPE_PATH} /image_signing/layout_files/signing_layout_ns.o"
204187 FALSE
205188)
206189
0 commit comments