compatible with PSA configs and test improvements

Signed-off-by: Yi Wu <yi.wu2@arm.com>
This commit is contained in:
Yi Wu 2026-08-19 15:56:46 +01:00
parent c734d57590
commit 5c906f7fa0
2 changed files with 62 additions and 17 deletions

View File

@ -139,6 +139,13 @@ set(MBEDTLS_CONFIG_NAME "" CACHE STRING "Named Mbed TLS configuration (see confi
set(MBEDTLS_CONFIG_SET "" CACHE STRING "Options to set, separated by semicolons (OPTION or OPTION=VALUE).")
set(MBEDTLS_CONFIG_UNSET "" CACHE STRING "Options to unset, separated by semicolons.")
set(MBEDTLS_CONFIG_TRANSFORMED FALSE)
if(NOT "${MBEDTLS_CONFIG_NAME}" STREQUAL "" OR
NOT "${MBEDTLS_CONFIG_SET}" STREQUAL "" OR
NOT "${MBEDTLS_CONFIG_UNSET}" STREQUAL "")
set(MBEDTLS_CONFIG_TRANSFORMED TRUE)
endif()
if(NOT "${MBEDTLS_CONFIG_FILE}" STREQUAL "" AND
(NOT "${MBEDTLS_CONFIG_BASE_FILE}" STREQUAL "" OR
NOT "${MBEDTLS_CONFIG_NAME}" STREQUAL "" OR
@ -149,6 +156,19 @@ if(NOT "${MBEDTLS_CONFIG_FILE}" STREQUAL "" AND
"MBEDTLS_CONFIG_NAME, MBEDTLS_CONFIG_SET or MBEDTLS_CONFIG_UNSET.")
endif()
if(MBEDTLS_CONFIG_TRANSFORMED AND
(NOT "${TF_PSA_CRYPTO_CONFIG_FILE}" STREQUAL "" OR
NOT "${TF_PSA_CRYPTO_CONFIG_BASE_FILE}" STREQUAL "" OR
NOT "${TF_PSA_CRYPTO_CONFIG_NAME}" STREQUAL "" OR
NOT "${TF_PSA_CRYPTO_CONFIG_SET}" STREQUAL "" OR
NOT "${TF_PSA_CRYPTO_CONFIG_UNSET}" STREQUAL ""))
message(FATAL_ERROR
"TF_PSA_CRYPTO_CONFIG_FILE, TF_PSA_CRYPTO_CONFIG_BASE_FILE, "
"TF_PSA_CRYPTO_CONFIG_NAME, TF_PSA_CRYPTO_CONFIG_SET and "
"TF_PSA_CRYPTO_CONFIG_UNSET cannot be combined with "
"MBEDTLS_CONFIG_NAME, MBEDTLS_CONFIG_SET or MBEDTLS_CONFIG_UNSET.")
endif()
if(NOT "${MBEDTLS_CONFIG_BASE_FILE}" STREQUAL "" OR
NOT "${MBEDTLS_CONFIG_NAME}" STREQUAL "" OR
NOT "${MBEDTLS_CONFIG_SET}" STREQUAL "" OR
@ -185,16 +205,21 @@ if(NOT "${MBEDTLS_CONFIG_BASE_FILE}" STREQUAL "" OR
set(MBEDTLS_GENERATED_CONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated/include")
set(MBEDTLS_GENERATED_CONFIG_FILE "${MBEDTLS_GENERATED_CONFIG_DIR}/mbedtls/mbedtls_config.h")
set(MBEDTLS_GENERATED_CRYPTO_CONFIG_FILE "${MBEDTLS_GENERATED_CONFIG_DIR}/psa/crypto_config.h")
file(MAKE_DIRECTORY "${MBEDTLS_GENERATED_CONFIG_DIR}/mbedtls")
file(MAKE_DIRECTORY "${MBEDTLS_GENERATED_CONFIG_DIR}/psa")
configure_file("${MBEDTLS_BASE_CONFIG_FILE}"
"${MBEDTLS_GENERATED_CONFIG_FILE}" COPYONLY)
# config.py handles the Mbed TLS and PSA configurations together. Give it
# a build-tree PSA configuration so that it never modifies the source tree.
if(MBEDTLS_CONFIG_TRANSFORMED)
set(MBEDTLS_GENERATED_CRYPTO_CONFIG_FILE
"${MBEDTLS_GENERATED_CONFIG_DIR}/psa/crypto_config.h")
file(MAKE_DIRECTORY "${MBEDTLS_GENERATED_CONFIG_DIR}/psa")
# config.py handles the Mbed TLS and PSA configurations together. Give
# it a build-tree PSA configuration so that it never modifies the
# source tree.
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/tf-psa-crypto/include/psa/crypto_config.h"
"${MBEDTLS_GENERATED_CRYPTO_CONFIG_FILE}" COPYONLY)
endif()
function(mbedtls_configure_generated_file)
execute_process(
@ -231,12 +256,9 @@ if(NOT "${MBEDTLS_CONFIG_BASE_FILE}" STREQUAL "" OR
set(MBEDTLS_CONFIG_FILE
"$<BUILD_INTERFACE:${MBEDTLS_GENERATED_CONFIG_FILE}>$<INSTALL_INTERFACE:mbedtls/mbedtls_config.h>")
if("${TF_PSA_CRYPTO_CONFIG_FILE}" STREQUAL "" AND
"${TF_PSA_CRYPTO_CONFIG_NAME}" STREQUAL "")
# Named configurations can adjust both configuration files.
if(MBEDTLS_CONFIG_TRANSFORMED)
set(TF_PSA_CRYPTO_CONFIG_FILE
"$<BUILD_INTERFACE:${MBEDTLS_GENERATED_CRYPTO_CONFIG_FILE}>$<INSTALL_INTERFACE:psa/crypto_config_mbedtls.h>"
CACHE STRING "TF-PSA-Crypto config file (overrides default)." FORCE)
"$<BUILD_INTERFACE:${MBEDTLS_GENERATED_CRYPTO_CONFIG_FILE}>$<INSTALL_INTERFACE:psa/crypto_config_mbedtls.h>")
endif()
endif()

View File

@ -303,6 +303,8 @@ component_build_cmake_config_options () {
msg "configure: cmake with a false-like option name"
cmake -DMBEDTLS_CONFIG_SET=NO "$MBEDTLS_ROOT_DIR"
grep '^#define NO$' generated/include/mbedtls/mbedtls_config.h
cmake -DMBEDTLS_CONFIG_SET= .
grep '^TF_PSA_CRYPTO_CONFIG_FILE:FILEPATH=$' CMakeCache.txt
cd "$MBEDTLS_ROOT_DIR"
rm -rf "$OUT_OF_SOURCE_DIR"
@ -314,6 +316,7 @@ component_build_cmake_config_options () {
"$MBEDTLS_ROOT_DIR"
cmp "$MBEDTLS_ROOT_DIR/configs/config-ccm-psk-tls1_2.h" \
generated/include/mbedtls/mbedtls_config.h
not test -e generated/include/psa/crypto_config.h
cd "$MBEDTLS_ROOT_DIR"
rm -rf "$OUT_OF_SOURCE_DIR"
@ -325,6 +328,24 @@ component_build_cmake_config_options () {
-DMBEDTLS_CONFIG_SET=MBEDTLS_DEBUG_C "$MBEDTLS_ROOT_DIR"
cd "$MBEDTLS_ROOT_DIR"
for option in \
"TF_PSA_CRYPTO_CONFIG_FILE=$MBEDTLS_ROOT_DIR/tf-psa-crypto/include/psa/crypto_config.h" \
"TF_PSA_CRYPTO_CONFIG_BASE_FILE=$MBEDTLS_ROOT_DIR/tf-psa-crypto/include/psa/crypto_config.h" \
"TF_PSA_CRYPTO_CONFIG_NAME=full" \
"TF_PSA_CRYPTO_CONFIG_SET=PSA_WANT_ALG_SHA_256" \
"TF_PSA_CRYPTO_CONFIG_UNSET=PSA_WANT_ALG_CMAC"
do
rm -rf "$OUT_OF_SOURCE_DIR"
mkdir "$OUT_OF_SOURCE_DIR"
cd "$OUT_OF_SOURCE_DIR"
msg "configure: reject $option with Mbed TLS transformations"
not cmake "-D$option" -DMBEDTLS_CONFIG_SET=MBEDTLS_DEBUG_C \
"$MBEDTLS_ROOT_DIR"
cd "$MBEDTLS_ROOT_DIR"
done
rm -rf "$OUT_OF_SOURCE_DIR"
mkdir "$OUT_OF_SOURCE_DIR"
cd "$OUT_OF_SOURCE_DIR"
@ -358,7 +379,7 @@ component_build_cmake_config_options () {
"$MBEDTLS_ROOT_DIR/configs/config-ccm-psk-tls1_2.h"
msg "install: generated configurations are relocatable"
install_dir="$OUT_OF_SOURCE_DIR/install"
install_dir="$OUT_OF_SOURCE_DIR.install"
cmake -DCMAKE_INSTALL_PREFIX="$install_dir" .
cmake --build . --target install
cmp generated/include/mbedtls/mbedtls_config.h \
@ -366,9 +387,11 @@ component_build_cmake_config_options () {
cmp generated/include/psa/crypto_config.h \
"$install_dir/include/psa/crypto_config_mbedtls.h"
# The installed targets must not refer to configuration headers in the
# build tree.
mv generated generated.moved
# The installed targets must not refer to the build tree.
cd "$MBEDTLS_ROOT_DIR"
mv "$OUT_OF_SOURCE_DIR" "$OUT_OF_SOURCE_DIR.moved"
mkdir "$OUT_OF_SOURCE_DIR"
cd "$OUT_OF_SOURCE_DIR"
mkdir consumer
cat >consumer/CMakeLists.txt <<EOF
cmake_minimum_required(VERSION 3.10)
@ -386,7 +409,7 @@ EOF
cd ..
cd "$MBEDTLS_ROOT_DIR"
rm -rf "$OUT_OF_SOURCE_DIR"
rm -rf "$OUT_OF_SOURCE_DIR" "$OUT_OF_SOURCE_DIR.moved" "$install_dir"
msg "configure: reject transformations in an in-tree build"
not cmake -DMBEDTLS_CONFIG_SET=NO .