CMakeLists.txt: Add support for running PSA tests

Add necessary libs and files to the build
Add support for new kconfigs
Add Zephyr-only implementations of tfm_log and tfm_ns_interface.
Add zephyr_tfm_psa_test.c for easily running PSA tests.

Signed-off-by: Øyvind Rønningstad <oyvind.ronningstad@nordicsemi.no>
This commit is contained in:
Øyvind Rønningstad 2021-01-11 15:38:00 +01:00 committed by Ioannis Glaropoulos
parent a0eecfd7f4
commit b220374633
3 changed files with 63 additions and 2 deletions

View file

@ -24,6 +24,9 @@ set(TFM_VALID_PARTITIONS
# BINARY_DIR: The location where the build outputs will be written
# BOARD: The string identifying the board target for TF-M (AN521, etc.)
# CMAKE_BUILD_TYPE: The TF-M build type to use, (Debug, Release, etc.)
# PSA_TEST_SUITE: A PSA test suite to add, choose one of
# PROTECTED_STORAGE/INTERNAL_TRUSTED_STORAGE/STORAGE/CRYPTO/
# INITIAL_ATTESTATION
# IPC: Build TFM IPC library. This library allows a non-secure application to
# interface to secure domain using IPC.
# ISOLATION_LEVEL: The TF-M isolation level to use
@ -45,7 +48,7 @@ set(TFM_VALID_PARTITIONS
function(trusted_firmware_build)
set(options IPC REGRESSION BL2)
set(oneValueArgs BINARY_DIR BOARD ISOLATION_LEVEL CMAKE_BUILD_TYPE BUILD_PROFILE
MCUBOOT_IMAGE_NUMBER)
MCUBOOT_IMAGE_NUMBER PSA_TEST_SUITE)
set(multiValueArgs ENABLED_PARTITIONS)
cmake_parse_arguments(TFM "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
@ -87,9 +90,25 @@ function(trusted_firmware_build)
set(MCUBOOT_IMAGE_NUM_ARG -DMCUBOOT_IMAGE_NUMBER=${TFM_MCUBOOT_IMAGE_NUMBER})
endif()
if(DEFINED TFM_PSA_TEST_SUITE)
set(PSA_TEST_ARG -DTEST_PSA_API=${TFM_PSA_TEST_SUITE})
endif()
set(VENEERS_FILE ${TFM_BINARY_DIR}/secure_fw/s_veneers.o)
set(TFM_API_NS_PATH ${TFM_BINARY_DIR}/app/libtfm_api_ns.a)
set(TFM_GENERATED_INCLUDES ${TFM_BINARY_DIR}/generated/interface/include)
set(PLATFORM_NS_FILE ${TFM_BINARY_DIR}/platform/libplatform_ns.a)
if (TFM_PSA_TEST_SUITE)
set(PSA_TEST_VAL_FILE ${TFM_BINARY_DIR}/app/psa_api_tests/val/val_nspe.a)
set(PSA_TEST_PAL_FILE ${TFM_BINARY_DIR}/app/psa_api_tests/platform/pal_nspe.a)
set(COMBINE_DIR_STORAGE storage)
set(COMBINE_DIR_PROTECTED_STORAGE storage)
set(COMBINE_DIR_INTERNAL_TRUSTED_STORAGE storage)
set(COMBINE_DIR_CRYPTO crypto)
set(COMBINE_DIR_INITIAL_ATTESTATION initial_attestation)
set(PSA_TEST_COMBINE_FILE ${TFM_BINARY_DIR}/app/psa_api_tests/dev_apis/${COMBINE_DIR_${TFM_PSA_TEST_SUITE}}/test_combine.a)
endif()
if(TFM_BL2)
set(BL2_BIN_FILE ${TFM_BINARY_DIR}/bin/bl2.bin)
@ -107,6 +126,10 @@ function(trusted_firmware_build)
${VENEERS_FILE}
${TFM_API_NS_PATH}
${TFM_GENERATED_INCLUDES}/psa_manifest/sid.h
${PSA_TEST_VAL_FILE}
${PSA_TEST_PAL_FILE}
${PSA_TEST_COMBINE_FILE}
${PLATFORM_NS_FILE}
${BL2_BIN_FILE}
${BL2_HEX_FILE}
${TFM_S_BIN_FILE}
@ -149,8 +172,10 @@ function(trusted_firmware_build)
${TFM_REGRESSION_ARG}
${TFM_PROFILE_ARG}
${MCUBOOT_IMAGE_NUM_ARG}
${PSA_TEST_ARG}
-DTFM_TEST_REPO_PATH=${ZEPHYR_TRUSTED_FIRMWARE_M_MODULE_DIR}/tf-m-tests
-DMCUBOOT_PATH=${ZEPHYR_TRUSTED_FIRMWARE_M_MODULE_DIR}/../tfm-mcuboot
-DPSA_ARCH_TESTS_PATH=${ZEPHYR_TRUSTED_FIRMWARE_M_MODULE_DIR}/psa-arch-tests
${TFM_PARTITIONS_ARGS}
BUILD_ALWAYS True
USES_TERMINAL_BUILD True
@ -183,6 +208,7 @@ function(trusted_firmware_build)
add_library(tfm_api
${ZEPHYR_BASE}/modules/trusted-firmware-m/src/zephyr_tfm_log.c
)
zephyr_sources_ifndef(CONFIG_TFM_PSA_TEST_NONE src/zephyr_tfm_psa_test.c)
target_include_directories(tfm_api
PRIVATE
@ -197,6 +223,10 @@ function(trusted_firmware_build)
PUBLIC
zephyr_interface
INTERFACE
${PSA_TEST_VAL_FILE}
${PSA_TEST_PAL_FILE}
${PSA_TEST_COMBINE_FILE}
${PLATFORM_NS_FILE}
${TFM_API_NS_PATH}
${VENEERS_FILE}
$<TARGET_FILE:tfm_api>
@ -225,6 +255,17 @@ if (CONFIG_BUILD_WITH_TFM)
if (CONFIG_TFM_PROFILE)
set(TFM_PROFILE_ARG BUILD_PROFILE ${CONFIG_TFM_PROFILE})
endif()
if (CONFIG_TFM_PSA_TEST_CRYPTO)
set(TFM_PSA_TEST_ARG PSA_TEST_SUITE CRYPTO)
elseif (CONFIG_TFM_PSA_TEST_PROTECTED_STORAGE)
set(TFM_PSA_TEST_ARG PSA_TEST_SUITE PROTECTED_STORAGE)
elseif (CONFIG_TFM_PSA_TEST_INTERNAL_TRUSTED_STORAGE)
set(TFM_PSA_TEST_ARG PSA_TEST_SUITE INTERNAL_TRUSTED_STORAGE)
elseif (CONFIG_TFM_PSA_TEST_STORAGE)
set(TFM_PSA_TEST_ARG PSA_TEST_SUITE STORAGE)
elseif (CONFIG_TFM_PSA_TEST_INITIAL_ATTESTATION)
set(TFM_PSA_TEST_ARG PSA_TEST_SUITE INITIAL_ATTESTATION)
endif()
if (CONFIG_TFM_CMAKE_BUILD_TYPE_RELEASE)
set(TFM_CMAKE_BUILD_TYPE "Release")
elseif (CONFIG_TFM_CMAKE_BUILD_TYPE_MINSIZEREL)
@ -256,6 +297,7 @@ if (CONFIG_BUILD_WITH_TFM)
${TFM_IPC_ARG}
${TFM_REGRESSION_ARG}
ENABLED_PARTITIONS ${TFM_ENABLED_PARTITIONS_ARG}
${TFM_PSA_TEST_ARG}
CMAKE_BUILD_TYPE ${TFM_CMAKE_BUILD_TYPE}
)

View file

@ -0,0 +1,19 @@
/*
* Copyright (c) 2021 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr.h>
/**
* \brief This symbol is the entry point provided by the PSA API compliance
* test libraries
*/
extern void val_entry(void);
void psa_test(void)
{
val_entry();
}

View file

@ -141,7 +141,7 @@ manifest:
revision: 7dd56fc100d79cc45c33d43e7401d1803e26f6e7
- name: trusted-firmware-m
path: modules/tee/tfm
revision: 33216b0d61a6bc585a87e548c4a345d3fd0d2177
revision: 2c2aa3724a040233095a5c41ab79c8ad36134c8e
- name: tfm-mcuboot # This is used by the trusted-firmware-m module.
repo-path: mcuboot
path: modules/tee/tfm-mcuboot