From 372c81680d8fdce7c792c3dffb849214a7517f6f Mon Sep 17 00:00:00 2001 From: Elena Uziunaite Date: Tue, 29 Oct 2024 16:44:24 +0000 Subject: [PATCH 1/9] Fix typo Signed-off-by: Elena Uziunaite --- scripts/mbedtls_framework/build_tree.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/mbedtls_framework/build_tree.py b/scripts/mbedtls_framework/build_tree.py index 75f9b6b0be87..2d720a404f81 100644 --- a/scripts/mbedtls_framework/build_tree.py +++ b/scripts/mbedtls_framework/build_tree.py @@ -133,7 +133,7 @@ def guess_tf_psa_crypto_root(root: Optional[str] = None) -> str: def is_mbedtls_3_6() -> bool: """Whether the working tree is an Mbed TLS 3.6 one or not - Return false in we are in TF-PSA-Crypto or in Mbed TLS but with a version + Return false if we are in TF-PSA-Crypto or in Mbed TLS but with a version different from 3.6.x. Raise an exception if we are neither in Mbed TLS nor in TF-PSA-Crypto. """ From 25405012ec246b33f0bdee0c67db2cb49659e258 Mon Sep 17 00:00:00 2001 From: Elena Uziunaite Date: Tue, 29 Oct 2024 17:08:09 +0000 Subject: [PATCH 2/9] Create project-detection.sh Move in_mbedtls_repo() and in_tf_psa_repo() there Signed-off-by: Elena Uziunaite --- scripts/project_detection.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 scripts/project_detection.sh diff --git a/scripts/project_detection.sh b/scripts/project_detection.sh new file mode 100755 index 000000000000..34716f8b64d6 --- /dev/null +++ b/scripts/project_detection.sh @@ -0,0 +1,29 @@ +# project-detection.sh +# +# Copyright The Mbed TLS Contributors +# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later +# +# Purpose +# +# This script contains functions for shell scripts to +# help detect which project (Mbed TLS, TF-PSA-Crypto) +# or which Mbed TLS branch they are in. + +# Project detection +read_project_name_file () { + PROJECT_NAME_FILE='../../scripts/project_name.txt' + if read -r PROJECT_NAME < "$PROJECT_NAME_FILE"; then :; else + echo "$PROJECT_NAME_FILE does not exist... Exiting..." >&2 + exit 1 + fi +} + +in_mbedtls_repo () { + read_project_name_file + test "$PROJECT_NAME" = "Mbed TLS" +} + +in_tf_psa_crypto_repo () { + read_project_name_file + test "$PROJECT_NAME" = "TF-PSA-Crypto" +} From 0d2389a8c449a813db5fc138eaf07933c61d8357 Mon Sep 17 00:00:00 2001 From: Elena Uziunaite Date: Fri, 1 Nov 2024 16:08:36 +0000 Subject: [PATCH 3/9] Add branch detection Signed-off-by: Elena Uziunaite --- scripts/project_detection.sh | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/scripts/project_detection.sh b/scripts/project_detection.sh index 34716f8b64d6..3f40cc55ea6f 100755 --- a/scripts/project_detection.sh +++ b/scripts/project_detection.sh @@ -27,3 +27,36 @@ in_tf_psa_crypto_repo () { read_project_name_file test "$PROJECT_NAME" = "TF-PSA-Crypto" } + +#Branch detection +read_build_info () { + BUILD_INFO_FILE='../../include/mbedtls/build_info.h' + + if [ ! -f "$BUILD_INFO_FILE" ]; then + echo "File $BUILD_INFO_FILE not found." + exit 1 + fi + + MBEDTLS_VERSION_MAJOR=$(grep "^#define MBEDTLS_VERSION_MAJOR" "$BUILD_INFO_FILE" | awk '{print $3}') + MBEDTLS_VERSION_MINOR=$(grep "^#define MBEDTLS_VERSION_MINOR" "$BUILD_INFO_FILE" | awk '{print $3}') + + if [ -z "$MBEDTLS_VERSION_MAJOR" ]; then + echo "MBEDTLS_VERSION_MAJOR not found in $BUILD_INFO_FILE." + exit 1 + fi + + if [ -z "$MBEDTLS_VERSION_MINOR" ]; then + echo "MBEDTLS_VERSION_MINOR not found in $BUILD_INFO_FILE." + exit 1 + fi +} + +in_3_6_branch () { + read_build_info + test $MBEDTLS_VERSION_MAJOR = "3" && test $MBEDTLS_VERSION_MINOR = "6" +} + +in_4_x_branch () { + read_build_info + test $MBEDTLS_VERSION_MAJOR = "4" +} From d74f989831532a6734f4046a20297260b38ad2a7 Mon Sep 17 00:00:00 2001 From: Elena Uziunaite Date: Thu, 7 Nov 2024 14:36:07 +0000 Subject: [PATCH 4/9] Edit file paths Signed-off-by: Elena Uziunaite --- scripts/project_detection.sh | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/scripts/project_detection.sh b/scripts/project_detection.sh index 3f40cc55ea6f..ab57f006d716 100755 --- a/scripts/project_detection.sh +++ b/scripts/project_detection.sh @@ -11,7 +11,16 @@ # Project detection read_project_name_file () { - PROJECT_NAME_FILE='../../scripts/project_name.txt' + SCRIPT_DIR=$(pwd) + + PROJECT_NAME_FILE="scripts/project_name.txt" + + if echo "$SCRIPT_DIR" | grep -q "/framework/scripts" || echo "$SCRIPT_DIR" | grep -q "/tests/scripts"; then + PROJECT_NAME_FILE="../../scripts/project_name.txt" + elif echo "$SCRIPT_DIR" | grep -q "/mbedtls/scripts" || echo "$SCRIPT_DIR" | grep -q "/TF-PSA-Crypto/scripts"; then + PROJECT_NAME_FILE="project_name.txt" + fi + if read -r PROJECT_NAME < "$PROJECT_NAME_FILE"; then :; else echo "$PROJECT_NAME_FILE does not exist... Exiting..." >&2 exit 1 @@ -30,7 +39,15 @@ in_tf_psa_crypto_repo () { #Branch detection read_build_info () { - BUILD_INFO_FILE='../../include/mbedtls/build_info.h' + SCRIPT_DIR=$(pwd) + + BUILD_INFO_FILE="include/mbedtls/build_info.h" + + if echo "$SCRIPT_DIR" | grep -q "/framework/scripts" || echo "$SCRIPT_DIR" | grep -q "/tests/scripts"; then + BUILD_INFO_FILE="../../include/mbedtls/build_info.h" + elif echo "$SCRIPT_DIR" | grep -q "/mbedtls/scripts"; then + BUILD_INFO_FILE="../include/mbedtls/build_info.h" + fi if [ ! -f "$BUILD_INFO_FILE" ]; then echo "File $BUILD_INFO_FILE not found." From 030283508b273adb91c2b958dd1529438e8526dc Mon Sep 17 00:00:00 2001 From: Elena Uziunaite Date: Tue, 12 Nov 2024 14:46:16 +0000 Subject: [PATCH 5/9] Remove unnecessary code Because the scripts are always invoked from the project's root Signed-off-by: Elena Uziunaite --- scripts/project_detection.sh | 12 ------------ 1 file changed, 12 deletions(-) mode change 100755 => 100644 scripts/project_detection.sh diff --git a/scripts/project_detection.sh b/scripts/project_detection.sh old mode 100755 new mode 100644 index ab57f006d716..bbe28139d5ba --- a/scripts/project_detection.sh +++ b/scripts/project_detection.sh @@ -15,12 +15,6 @@ read_project_name_file () { PROJECT_NAME_FILE="scripts/project_name.txt" - if echo "$SCRIPT_DIR" | grep -q "/framework/scripts" || echo "$SCRIPT_DIR" | grep -q "/tests/scripts"; then - PROJECT_NAME_FILE="../../scripts/project_name.txt" - elif echo "$SCRIPT_DIR" | grep -q "/mbedtls/scripts" || echo "$SCRIPT_DIR" | grep -q "/TF-PSA-Crypto/scripts"; then - PROJECT_NAME_FILE="project_name.txt" - fi - if read -r PROJECT_NAME < "$PROJECT_NAME_FILE"; then :; else echo "$PROJECT_NAME_FILE does not exist... Exiting..." >&2 exit 1 @@ -43,12 +37,6 @@ read_build_info () { BUILD_INFO_FILE="include/mbedtls/build_info.h" - if echo "$SCRIPT_DIR" | grep -q "/framework/scripts" || echo "$SCRIPT_DIR" | grep -q "/tests/scripts"; then - BUILD_INFO_FILE="../../include/mbedtls/build_info.h" - elif echo "$SCRIPT_DIR" | grep -q "/mbedtls/scripts"; then - BUILD_INFO_FILE="../include/mbedtls/build_info.h" - fi - if [ ! -f "$BUILD_INFO_FILE" ]; then echo "File $BUILD_INFO_FILE not found." exit 1 From dc49da5121caa037439c797802d4e838327eb096 Mon Sep 17 00:00:00 2001 From: Elena Uziunaite Date: Mon, 18 Nov 2024 14:58:17 +0000 Subject: [PATCH 6/9] Edit file paths in all-core.sh Signed-off-by: Elena Uziunaite --- scripts/all-core.sh | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/scripts/all-core.sh b/scripts/all-core.sh index f0e3018676d7..216c935a346e 100644 --- a/scripts/all-core.sh +++ b/scripts/all-core.sh @@ -131,21 +131,14 @@ pre_set_shell_options () { set -e -o pipefail -u } -# For project detection -in_mbedtls_repo () { - test "$PROJECT_NAME" = "Mbed TLS" -} - -in_tf_psa_crypto_repo () { - test "$PROJECT_NAME" = "TF-PSA-Crypto" -} - pre_check_environment () { # For project detection - PROJECT_NAME_FILE='./scripts/project_name.txt' - if read -r PROJECT_NAME < "$PROJECT_NAME_FILE"; then :; else - echo "$PROJECT_NAME_FILE does not exist... Exiting..." >&2 - exit 1 + if [[ -d ../include/mbedtls && -r ../framework/scripts/project_detection.sh ]]; then + # we're in tf-psa-crypto as a submodule of mbedtls, grab the framework from mbedtls + . ../framework/scripts/project_detection.sh + else + # we're in TF-PSA-Crypto standalone or in mbedtls, use the local framework + . framework/scripts/project_detection.sh fi if in_mbedtls_repo || in_tf_psa_crypto_repo; then :; else From c812d5d3ef98ece6a8f8e499f40dc2f1efb9598e Mon Sep 17 00:00:00 2001 From: Elena Uziunaite Date: Tue, 19 Nov 2024 14:33:09 +0000 Subject: [PATCH 7/9] Undo temporary changes in all-helpers.sh Signed-off-by: Elena Uziunaite --- scripts/all-helpers.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/scripts/all-helpers.sh b/scripts/all-helpers.sh index 82609b52e5e9..423f445234ae 100644 --- a/scripts/all-helpers.sh +++ b/scripts/all-helpers.sh @@ -68,10 +68,9 @@ helper_libtestdriver1_adjust_config() { fi # Enable PSA-based config (necessary to use drivers) - # The configuration option has been removed for 4.0. While the project and - # branch detection shell in shell work is not completed, just ignore the - # failure to set MBEDTLS_PSA_CRYPTO_CONFIG. - scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG || true + if in_mbedtls_repo && in_3_6_branch; then + scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG + fi # Dynamic secure element support is a deprecated feature and needs to be disabled here. # This is done to have the same form of psa_key_attributes_s for libdriver and library. From b20fcb55e7bf3cff8ac0bec5326636f8572b25ef Mon Sep 17 00:00:00 2001 From: Elena Uziunaite Date: Wed, 20 Nov 2024 16:24:04 +0000 Subject: [PATCH 8/9] Define FRAMEWORK Signed-off-by: Elena Uziunaite --- scripts/all-core.sh | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/scripts/all-core.sh b/scripts/all-core.sh index 216c935a346e..a2dc0d14ebb6 100644 --- a/scripts/all-core.sh +++ b/scripts/all-core.sh @@ -132,14 +132,8 @@ pre_set_shell_options () { } pre_check_environment () { - # For project detection - if [[ -d ../include/mbedtls && -r ../framework/scripts/project_detection.sh ]]; then - # we're in tf-psa-crypto as a submodule of mbedtls, grab the framework from mbedtls - . ../framework/scripts/project_detection.sh - else - # we're in TF-PSA-Crypto standalone or in mbedtls, use the local framework - . framework/scripts/project_detection.sh - fi + + source $FRAMEWORK/scripts/project_detection.sh if in_mbedtls_repo || in_tf_psa_crypto_repo; then :; else echo "Must be run from Mbed TLS / TF-PSA-Crypto root" >&2 From c3cee628f52aab5b9b2a617f2e594683122014f3 Mon Sep 17 00:00:00 2001 From: Elena Uziunaite Date: Thu, 21 Nov 2024 15:52:19 +0000 Subject: [PATCH 9/9] Revert "Undo temporary changes in all-helpers.sh" This reverts commit b1eee4934879253539db15e996fbb7baed9e3ffc. Signed-off-by: Elena Uziunaite --- scripts/all-helpers.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/all-helpers.sh b/scripts/all-helpers.sh index 423f445234ae..82609b52e5e9 100644 --- a/scripts/all-helpers.sh +++ b/scripts/all-helpers.sh @@ -68,9 +68,10 @@ helper_libtestdriver1_adjust_config() { fi # Enable PSA-based config (necessary to use drivers) - if in_mbedtls_repo && in_3_6_branch; then - scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG - fi + # The configuration option has been removed for 4.0. While the project and + # branch detection shell in shell work is not completed, just ignore the + # failure to set MBEDTLS_PSA_CRYPTO_CONFIG. + scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG || true # Dynamic secure element support is a deprecated feature and needs to be disabled here. # This is done to have the same form of psa_key_attributes_s for libdriver and library.