From 7bef731f0b709f3b9858bf6210fab79c0b675c23 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Wed, 10 Dec 2025 18:16:03 +0100 Subject: [PATCH] Create a TF-PSA-Crypto make helper for Mbed TLS Currently, Mbed TLS can be built with make, and we rely on this in many `all.sh` components. Mbed TLS knows how to build TF-PSA-Crypto, but this changes from time to time, and it's hard to do the necessary changes in both repositories at the same time. Create a file that Mbed TLS can consume to find out some information needed to build TF-PSA-Crypto, such as the locations of various files. Create this file in Mbed TLS. Once we have finished moving code to it, the file will move to TF-PSA-Crypto. Signed-off-by: Gilles Peskine --- library/Makefile | 2 ++ scripts/common.make | 2 ++ scripts/crypto-common.make | 25 +++++++++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 scripts/crypto-common.make diff --git a/library/Makefile b/library/Makefile index 807e3f1adb..8195e2423a 100644 --- a/library/Makefile +++ b/library/Makefile @@ -14,6 +14,8 @@ This is a fatal error endif include $(MBEDTLS_PATH)/framework/exported.make +include $(MBEDTLS_PATH)/scripts/crypto-common.make + TF_PSA_CRYPTO_CORE_PATH = $(MBEDTLS_PATH)/tf-psa-crypto/core TF_PSA_CRYPTO_DRIVERS_BUILTIN_SRC_PATH = $(MBEDTLS_PATH)/tf-psa-crypto/drivers/builtin/src diff --git a/scripts/common.make b/scripts/common.make index 5350d87efc..9be3b2db53 100644 --- a/scripts/common.make +++ b/scripts/common.make @@ -16,6 +16,8 @@ This is a fatal error endif include $(MBEDTLS_PATH)/framework/exported.make +include $(MBEDTLS_PATH)/scripts/crypto-common.make + CFLAGS ?= -O2 WARNING_CFLAGS ?= -Wall -Wextra -Wformat=2 -Wno-format-nonliteral WARNING_CXXFLAGS ?= -Wall -Wextra -Wformat=2 -Wno-format-nonliteral -std=c++11 -pedantic diff --git a/scripts/crypto-common.make b/scripts/crypto-common.make new file mode 100644 index 0000000000..5a79bc482b --- /dev/null +++ b/scripts/crypto-common.make @@ -0,0 +1,25 @@ +# Helper code for the make build system in Mbed TLS: define some variables +# providing information such as file paths. +# This file is only meant to exist for a short transition period. +# It may change or be removed without notice. +# Do not use it if you are not Mbed TLS! + +# Assume that this makefile is located in a first-level subdirectory of the +# Mbed TLS root, and is accessed directly (not via VPATH or such). +# If this is not the case, TF_PSA_CRYPTO_PATH or MBEDTLS_PATH must be defined +# before including this file. +ifneq ($(origin TF_PSA_CRYPTO_PATH), undefined) + # TF_PSA_CRYPTO_PATH was defined before including this file, good. +else ifneq ($(origin MBEDTLS_PATH), undefined) + TF_PSA_CRYPTO_PATH := $(MBEDTLS_PATH)/tf-psa-crypto +else + # $(dir $(lastword $(MAKEFILE_LIST))) is the path to this file, possibly + # a relative path, with a trailing slash. Strip off another directory + # from that. + TF_PSA_CRYPTO_PATH := $(patsubst %/,%,$(dir $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))))/tf-psa-crypto +endif + +ifeq (,$(wildcard $(TF_PSA_CRYPTO_PATH)/core/psa_crypto.c)) + $(error $$(TF_PSA_CRYPTO_PATH)/core/psa_crypto.c not found) +endif +