Skip to content

Commit 2d2582d

Browse files
gergkvaggarg
authored andcommitted
build: Speech recognition application with split-build
Signed-off-by: Gergely Kovacs <[email protected]>
1 parent 82e5a10 commit 2d2582d

File tree

5 files changed

+58
-53
lines changed

5 files changed

+58
-53
lines changed

applications/speech_recognition/CMakeLists.txt

Lines changed: 25 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
cmake_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)
79
set(ML_INFERENCE_ENGINE "ETHOS" CACHE STRING "Machine Learning inference engine (ETHOS)")
810
set(AUDIO_SOURCE "ROM" CACHE STRING "Source of audio data (ROM | VSI)")
911
set(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")
2627
set(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

3029
if (${ML_INFERENCE_ENGINE} STREQUAL "ETHOS")
3130
set(ETHOS_U_NPU_ENABLED ON)
@@ -36,31 +35,14 @@ endif()
3635
set(ML_USE_CASE "asr")
3736
set(ML_MODEL "GenerateASRModel")
3837
set(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

6547
add_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

9073
target_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.
145124
add_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

169150
include(${IOT_REFERENCE_ARM_CORSTONE3XX_SOURCE_DIR}/bsp/cmake/SetLinkerOptions.cmake)
170151
set_linker_script(speech-recognition)
171152

172153
list(APPEND CMAKE_MODULE_PATH ${IOT_REFERENCE_ARM_CORSTONE3XX_SOURCE_DIR}/tools/cmake)
173154
include(ConvertElfToBin)
174-
include(ExternalProject)
175-
ExternalProject_Get_Property(trusted_firmware-m-build BINARY_DIR)
176155

177156
extract_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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2025 Arm Limited and/or its affiliates
2+
3+
# SPDX-License-Identifier: MIT
4+
5+
include(${ROOT}/cmake/TfmInitialCacheCommon.cmake)
6+
7+
set(TFM_MBEDCRYPTO_CONFIG_CLIENT_PATH "${ROOT}/applications/speech_recognition/configs/mbedtls_config/aws_mbedtls_config.h" CACHE FILEPATH "TFM_MBEDCRYPTO_CONFIG_CLIENT_PATH" FORCE)
8+
9+
set(PROJECT_CONFIG_HEADER_FILE ${ROOT}/applications/speech_recognition/configs/tfm_config/project_config.h CACHE FILEPATH "PROJECT_CONFIG_HEADER_FILE" FORCE)
10+
set(MCUBOOT_IMAGE_NUMBER 2 CACHE STRING "MCUBOOT_IMAGE_NUMBER" FORCE)
11+
set(DEFAULT_MCUBOOT_FLASH_MAP ON CACHE BOOL "DEFAULT_MCUBOOT_FLASH_MAP" FORCE)
12+
set(MCUBOOT_UPGRADE_STRATEGY "SWAP_USING_SCRATCH" CACHE STRING "MCUBOOT_UPGRADE_STRATEGY" FORCE)
13+
set(MCUBOOT_IMAGE_VERSION_NS "0.0.1+10" CACHE STRING "MCUBOOT_IMAGE_VERSION_NS" FORCE)
14+
set(CONFIG_TFM_HALT_ON_CORE_PANIC ON CACHE BOOL "CONFIG_TFM_HALT_ON_CORE_PANIC" FORCE)
15+
set(MCUBOOT_DATA_SHARING ON CACHE BOOL "MCUBOOT_DATA_SHARING" FORCE)
16+
set(PLATFORM_HAS_FIRMWARE_UPDATE_SUPPORT ON CACHE BOOL "PLATFORM_HAS_FIRMWARE_UPDATE_SUPPORT" FORCE)
17+
set(TFM_PARTITION_FIRMWARE_UPDATE ON CACHE BOOL "TFM_PARTITION_FIRMWARE_UPDATE" FORCE)
18+
set(TFM_PARTITION_LOG_LEVEL TFM_PARTITION_LOG_LEVEL_INFO CACHE STRING "TFM_PARTITION_LOG_LEVEL" FORCE)
19+
set(CONFIG_TFM_ENABLE_MVE ON CACHE STRING "CONFIG_TFM_ENABLE_MVE" FORCE)
20+
set(CONFIG_TFM_ENABLE_MVE_FP ON CACHE STRING "CONFIG_TFM_ENABLE_MVE_FP" FORCE)

applications/speech_recognition/configs/freertos_config/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023 Arm Limited and/or its affiliates
1+
# Copyright 2023-2025 Arm Limited and/or its affiliates
22
33
# SPDX-License-Identifier: MIT
44

@@ -14,6 +14,6 @@ target_compile_definitions(freertos_config
1414

1515
target_link_libraries(freertos_config
1616
INTERFACE
17-
tfm-ns-interface
17+
tfm_api_ns
1818
app-config
1919
)

applications/speech_recognition/configs/mbedtls_config/CMakeLists.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023 Arm Limited and/or its affiliates
1+
# Copyright 2023-2025 Arm Limited and/or its affiliates
22
33
# SPDX-License-Identifier: MIT
44

@@ -7,11 +7,6 @@ target_include_directories(mbedtls-config
77
.
88
)
99

10-
target_compile_definitions(mbedtls-config
11-
INTERFACE
12-
MBEDTLS_CONFIG_FILE="aws_mbedtls_config.h"
13-
)
14-
1510
target_link_libraries(mbedtls-config
1611
INTERFACE
1712
freertos_kernel

applications/speech_recognition/configs/mbedtls_config/aws_mbedtls_config.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/*
1212
* Copyright The Mbed TLS Contributors
1313
* SPDX-License-Identifier: Apache-2.0
14-
* Copyright 2024 Arm Limited and/or its affiliates
14+
* Copyright 2024-2025 Arm Limited and/or its affiliates
1515
1616
*
1717
* Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -27,6 +27,11 @@
2727
* limitations under the License.
2828
*/
2929

30+
#ifndef DOMAIN_NS
31+
/* Set if this config file is currently used for TF-M secure clients */
32+
#define PSA_CRYPTO_TFM_SECURE_CONFIG
33+
#endif /* DOMAIN_NS == 1 */
34+
3035
/**
3136
* This is an optional version symbol that enables compatibility handling of
3237
* config files.
@@ -1158,7 +1163,7 @@ void mbedtls_platform_free( void * ptr );
11581163
* \warning This interface is experimental and may change or be removed
11591164
* without notice.
11601165
*/
1161-
#ifdef PSA_CRYPTO_IMPLEMENTATION_TFM
1166+
#if defined( PSA_CRYPTO_IMPLEMENTATION_TFM ) || defined( PSA_CRYPTO_TFM_SECURE_CONFIG )
11621167
#define MBEDTLS_PSA_CRYPTO_CLIENT
11631168
#endif
11641169

@@ -1758,7 +1763,9 @@ void mbedtls_platform_free( void * ptr );
17581763
* This feature is still experimental and is not ready for production since
17591764
* it is not completed.
17601765
*/
1761-
/*#define MBEDTLS_PSA_CRYPTO_CONFIG */
1766+
#ifdef PSA_CRYPTO_TFM_SECURE_CONFIG
1767+
#define MBEDTLS_PSA_CRYPTO_CONFIG
1768+
#endif
17621769

17631770
/**
17641771
* \def MBEDTLS_VERSION_FEATURES

0 commit comments

Comments
 (0)