Skip to content

Commit 6579348

Browse files
mswarowskyVge0rge
authored andcommitted
[nrf fromtree] samples: tfm_psa_test: Adapt to TF-M split build
The sample now builds the psa-arch-tests itself and doesn't rely anymore on the TF-M module CMakeFile. Additionally it will not run the zephyr main.c anymore but therefore only uses the tf-m non-secure application. Signed-off-by: Markus Swarowsky <[email protected]> (cherry picked from commit ad9cdf0) Signed-off-by: Markus Swarowsky <[email protected]>
1 parent 7798610 commit 6579348

File tree

6 files changed

+114
-12
lines changed

6 files changed

+114
-12
lines changed

modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,8 @@ install(FILES ${CMAKE_CURRENT_LIST_DIR}/ns/cpuarch_ns.cmake
1616

1717
install(FILES config.cmake
1818
DESTINATION ${INSTALL_PLATFORM_NS_DIR})
19+
20+
install(DIRECTORY ${Trusted\ Firmware\ M_SOURCE_DIR}/platform/ext/target/nordic_nrf/nrf5340dk_nrf5340_cpuapp/tests
21+
22+
DESTINATION ${INSTALL_PLATFORM_NS_DIR}
23+
)

modules/trusted-firmware-m/nordic_nrf/nrf9120/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ install(FILES ${Trusted\ Firmware\ M_SOURCE_DIR}/platform/ext/target/nordi
1919

2020
install(FILES config.cmake
2121
DESTINATION ${INSTALL_PLATFORM_NS_DIR})
22+
23+
install(DIRECTORY ${Trusted\ Firmware\ M_SOURCE_DIR}/platform/ext/target/nordic_nrf/nrf9161dk_nrf9161/tests
24+
25+
DESTINATION ${INSTALL_PLATFORM_NS_DIR})

modules/trusted-firmware-m/nordic_nrf/nrf9160/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ install(FILES ${Trusted\ Firmware\ M_SOURCE_DIR}/platform/ext/target/nordi
1919

2020
install(FILES config.cmake
2121
DESTINATION ${INSTALL_PLATFORM_NS_DIR})
22+
23+
install(DIRECTORY ${Trusted\ Firmware\ M_SOURCE_DIR}/platform/ext/target/nordic_nrf/nrf9160dk_nrf9160/tests
24+
25+
DESTINATION ${INSTALL_PLATFORM_NS_DIR})

samples/tfm_integration/tfm_psa_test/CMakeLists.txt

Lines changed: 96 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,103 @@ cmake_minimum_required(VERSION 3.20.0)
88

99
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
1010

11-
project(tfm_psa_storage_test)
11+
project(tfm_psa_arch_test)
1212

1313
target_sources(app PRIVATE src/main.c)
1414

15-
target_include_directories(app PRIVATE
16-
$<TARGET_PROPERTY:tfm,TFM_BINARY_DIR>/api_ns/interface/include
15+
get_target_property(TFM_BINARY_DIR tfm TFM_BINARY_DIR)
16+
get_target_property(TFM_NS_BIN_FILE tfm TFM_NS_BIN_FILE)
17+
get_target_property(TFM_NS_HEX_FILE tfm TFM_NS_HEX_FILE)
18+
get_target_property(TFM_NS_SIGNED_BIN_FILE tfm TFM_NS_SIGNED_BIN_FILE)
19+
20+
get_target_property(TFM_TOOLCHAIN_PATH tfm TFM_TOOLCHAIN_PATH)
21+
get_target_property(TFM_TOOLCHAIN_PREFIX tfm TFM_TOOLCHAIN_PREFIX)
22+
get_target_property(TFM_TOOLCHAIN_NS_FILE tfm TFM_TOOLCHAIN_NS_FILE)
23+
24+
set(TFM_TEST_REPO_PATH ${ZEPHYR_TRUSTED_FIRMWARE_M_MODULE_DIR}/../tf-m-tests)
25+
set(TFM_PSA_ARCHTEST_REPO_PATH ${ZEPHYR_TRUSTED_FIRMWARE_M_MODULE_DIR}/../psa-arch-tests)
26+
27+
if (CONFIG_TFM_PSA_TEST_INITIAL_ATTESTATION AND CONFIG_TFM_QCBOR_PATH STREQUAL "")
28+
# TODO: Remove this when QCBOR licensing issues w/t_cose have been resolved,
29+
# or only allow it when 'QCBOR_PATH' is set to a local path where QCBOR has
30+
# been manually downloaded by the user before starting the build.
31+
message(FATAL_ERROR "CONFIG_TFM_PSA_TEST_INITIAL_ATTESTATION is not available "
32+
"with TF-M 2.0.0 due to licensing issues with a dependent library. This "
33+
"restriction will be removed once licensing issues have been resolved."
34+
)
35+
endif()
36+
37+
38+
set(TFM_TEST_DIR "${TFM_TEST_REPO_PATH}/tests_psa_arch/spe/partitions")
39+
set(PSA_ARCH_TESTS_CONFIG_FILE "${TFM_TEST_REPO_PATH}/tests_psa_arch/spe/config/config_test_psa_api.cmake")
40+
if (CONFIG_TFM_PSA_TEST_CRYPTO)
41+
set(TFM_PSA_TEST_SUITE CRYPTO)
42+
elseif (CONFIG_TFM_PSA_TEST_PROTECTED_STORAGE)
43+
set(TFM_PSA_TEST_SUITE PROTECTED_STORAGE)
44+
elseif (CONFIG_TFM_PSA_TEST_INTERNAL_TRUSTED_STORAGE)
45+
set(TFM_PSA_TEST_SUITE INTERNAL_TRUSTED_STORAGE)
46+
elseif (CONFIG_TFM_PSA_TEST_STORAGE)
47+
set(TFM_PSA_TEST_SUITE STORAGE)
48+
elseif (CONFIG_TFM_PSA_TEST_INITIAL_ATTESTATION)
49+
set(TFM_PSA_TEST_SUITE INITIAL_ATTESTATION)
50+
endif()
51+
52+
if (NOT DEFINED TFM_PSA_TEST_SUITE)
53+
message(FATAL_ERROR "Please define witch test suite to run:
54+
CONFIG_TFM_PSA_TEST_CRYPTO
55+
CONFIG_TFM_PSA_TEST_PROTECTED_STORAGE
56+
CONFIG_TFM_PSA_TEST_STORAGE
57+
CONFIG_TFM_PSA_TEST_INITIAL_ATTESTATION")
58+
endif()
59+
set(TEST_PSA_API "${TFM_PSA_TEST_SUITE}")
60+
61+
set_property(TARGET zephyr_property_target
62+
APPEND PROPERTY TFM_CMAKE_OPTIONS
63+
-DPSA_ARCH_TESTS_PATH=${TFM_PSA_ARCHTEST_REPO_PATH}
64+
)
65+
66+
set_property(TARGET zephyr_property_target
67+
APPEND PROPERTY TFM_CMAKE_OPTIONS
68+
-DCONFIG_TFM_TEST_DIR=${TFM_TEST_DIR}
1769
)
70+
71+
set_property(TARGET zephyr_property_target
72+
APPEND PROPERTY TFM_CMAKE_OPTIONS
73+
-DCONFIG_PSA_ARCH_TESTS_CONFIG_FILE=${PSA_ARCH_TESTS_CONFIG_FILE}
74+
)
75+
76+
set_property(TARGET zephyr_property_target
77+
APPEND PROPERTY TFM_CMAKE_OPTIONS
78+
-DTEST_PSA_API=${TEST_PSA_API}
79+
)
80+
81+
include(ExternalProject)
82+
83+
ExternalProject_Add(tfm_psa_arch_test_app
84+
SOURCE_DIR ${TFM_TEST_REPO_PATH}/tests_psa_arch
85+
BINARY_DIR ${PROJECT_BINARY_DIR}/tfm_ns
86+
CONFIGURE_COMMAND
87+
${CMAKE_COMMAND}
88+
-G ${CMAKE_GENERATOR}
89+
-S ${TFM_TEST_REPO_PATH}/tests_psa_arch
90+
-B ${PROJECT_BINARY_DIR}/tfm_ns
91+
-DCROSS_COMPILE=${TFM_TOOLCHAIN_PATH}/${TFM_TOOLCHAIN_PREFIX}
92+
-DPSA_TOOLCHAIN_FILE=${TFM_BINARY_DIR}/api_ns/cmake/${TFM_TOOLCHAIN_NS_FILE}
93+
-DCONFIG_SPE_PATH=${TFM_BINARY_DIR}/api_ns
94+
-DTFM_TOOLCHAIN_FILE=cmake/${TFM_TOOLCHAIN_NS_FILE}
95+
-DQCBOR_PATH${QCBOR_PATH_TYPE}=${CONFIG_TFM_QCBOR_PATH}
96+
-DCMAKE_BUILD_TYPE=RelWithDebInfo
97+
-DTEST_PSA_API=${TEST_PSA_API}
98+
BUILD_COMMAND ${CMAKE_COMMAND} --build .
99+
INSTALL_COMMAND ""
100+
BUILD_ALWAYS True
101+
USES_TERMINAL_BUILD True
102+
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/tfm_ns
103+
DEPENDS tfm
104+
BUILD_BYPRODUCTS
105+
${TFM_NS_HEX_FILE}
106+
${TFM_NS_BIN_FILE}
107+
${TFM_NS_SIGNED_BIN_FILE}
108+
)
109+
110+
add_dependencies(app tfm_psa_arch_test_app)

samples/tfm_integration/tfm_psa_test/prj.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
CONFIG_BUILD_WITH_TFM=y
88
CONFIG_TFM_PROFILE_TYPE_NOT_SET=y
9+
CONFIG_TFM_USE_NS_APP=y
910
CONFIG_QEMU_ICOUNT_SHIFT=1
1011

12+
1113
# Needed for CRYPTO and INITIAL_ATTESTATION
1214
CONFIG_MAIN_STACK_SIZE=4096

samples/tfm_integration/tfm_psa_test/src/main.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
/*
2-
* Copyright (c) 2021 Nordic Semiconductor ASA.
2+
* Copyright (c) 2023 Nordic Semiconductor ASA.
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

77
#include <zephyr/kernel.h>
88

9-
/* Run the PSA test suite */
10-
void psa_test(void);
11-
129
int main(void)
1310
{
14-
#ifdef CONFIG_TFM_PSA_TEST_NONE
15-
#error "No PSA test suite set. Use Kconfig to enable a test suite.\n"
16-
#else
17-
psa_test();
18-
#endif
11+
printk("Should not be printed, expected TF-M's NS application to be run instead.\n");
12+
k_panic();
1913

2014
for (;;) {
2115
}

0 commit comments

Comments
 (0)