From 6a2cbe77fa822d0a6f6c519fb9bd94498f2b18db Mon Sep 17 00:00:00 2001 From: Ronald Cron Date: Wed, 13 Nov 2024 09:20:30 +0100 Subject: [PATCH] Move driver wrappers generation to tf-psa-crypto Signed-off-by: Ronald Cron --- docs/psa-driver-example-and-guide.md | 2 +- library/Makefile | 8 ++++---- scripts/make_generated_files.bat | 2 +- tests/Makefile | 3 ++- tests/scripts/check-generated-files.sh | 6 ++++-- tf-psa-crypto/core/CMakeLists.txt | 8 ++++---- .../data_files/driver_jsons/driver_opaque_schema.json | 0 .../driver_jsons/driver_transparent_schema.json | 0 .../scripts}/data_files/driver_jsons/driverlist.json | 0 .../driver_jsons/mbedtls_test_opaque_driver.json | 0 .../driver_jsons/mbedtls_test_transparent_driver.json | 0 .../data_files/driver_jsons/p256_transparent_driver.json | 0 .../data_files/driver_templates/OS-template-opaque.jinja | 0 .../driver_templates/OS-template-transparent.jinja | 0 .../driver_templates/psa_crypto_driver_wrappers.h.jinja | 0 .../psa_crypto_driver_wrappers_no_static.c.jinja | 0 .../scripts}/generate_driver_wrappers.py | 2 ++ 17 files changed, 18 insertions(+), 13 deletions(-) rename {scripts => tf-psa-crypto/scripts}/data_files/driver_jsons/driver_opaque_schema.json (100%) rename {scripts => tf-psa-crypto/scripts}/data_files/driver_jsons/driver_transparent_schema.json (100%) rename {scripts => tf-psa-crypto/scripts}/data_files/driver_jsons/driverlist.json (100%) rename {scripts => tf-psa-crypto/scripts}/data_files/driver_jsons/mbedtls_test_opaque_driver.json (100%) rename {scripts => tf-psa-crypto/scripts}/data_files/driver_jsons/mbedtls_test_transparent_driver.json (100%) rename {scripts => tf-psa-crypto/scripts}/data_files/driver_jsons/p256_transparent_driver.json (100%) rename {scripts => tf-psa-crypto/scripts}/data_files/driver_templates/OS-template-opaque.jinja (100%) rename {scripts => tf-psa-crypto/scripts}/data_files/driver_templates/OS-template-transparent.jinja (100%) rename {scripts => tf-psa-crypto/scripts}/data_files/driver_templates/psa_crypto_driver_wrappers.h.jinja (100%) rename {scripts => tf-psa-crypto/scripts}/data_files/driver_templates/psa_crypto_driver_wrappers_no_static.c.jinja (100%) rename {scripts => tf-psa-crypto/scripts}/generate_driver_wrappers.py (98%) diff --git a/docs/psa-driver-example-and-guide.md b/docs/psa-driver-example-and-guide.md index 15aa155b56..b392a85e0a 100644 --- a/docs/psa-driver-example-and-guide.md +++ b/docs/psa-driver-example-and-guide.md @@ -43,7 +43,7 @@ There are three deliverables for creating such a driver. These are: - C header files defining the types required by the driver description. The names of these header files are declared in the driver description file. - An object file compiled for the target platform defining the functions required by the driver description. Implementations may allow drivers to be provided as source files and compiled with the core instead of being pre-compiled. -The Mbed TLS driver tests for the aforementioned entry points provide examples of how these deliverables can be implemented. For sample driver description JSON files, see [`mbedtls_test_transparent_driver.json`](https://github.com/Mbed-TLS/mbedtls/blob/development/scripts/data_files/driver_jsons/mbedtls_test_transparent_driver.json) or [`mbedtls_test_opaque_driver.json`](https://github.com/Mbed-TLS/mbedtls/blob/development/scripts/data_files/driver_jsons/mbedtls_test_transparent_driver.json). The header file required by the driver description is [`test_driver.h`](https://github.com/Mbed-TLS/mbedtls/blob/development/framework/tests/include/test/drivers/test_driver.h). As Mbed TLS tests are built from source, there is no object file for the test driver. However, the source for the test driver can be found under `framework/tests/src/drivers`. +The Mbed TLS driver tests for the aforementioned entry points provide examples of how these deliverables can be implemented. For sample driver description JSON files, see [`mbedtls_test_transparent_driver.json`](https://github.com/Mbed-TLS/mbedtls/blob/development/tf-psa-crypto/scripts/data_files/driver_jsons/mbedtls_test_transparent_driver.json) or [`mbedtls_test_opaque_driver.json`](https://github.com/Mbed-TLS/mbedtls/blob/development/tf-psa-crypto/scripts/data_files/driver_jsons/mbedtls_test_transparent_driver.json). The header file required by the driver description is [`test_driver.h`](https://github.com/Mbed-TLS/mbedtls/blob/development/framework/tests/include/test/drivers/test_driver.h). As Mbed TLS tests are built from source, there is no object file for the test driver. However, the source for the test driver can be found under `framework/tests/src/drivers`. ### Process for Entry Points where auto-generation is not implemented diff --git a/library/Makefile b/library/Makefile index 7378687eb3..b874acf27a 100644 --- a/library/Makefile +++ b/library/Makefile @@ -389,12 +389,12 @@ version_features.c: GENERATED_WRAPPER_FILES = \ $(TF_PSA_CRYPTO_CORE_PATH)/psa_crypto_driver_wrappers.h \ $(TF_PSA_CRYPTO_CORE_PATH)/psa_crypto_driver_wrappers_no_static.c -$(GENERATED_WRAPPER_FILES): ../scripts/generate_driver_wrappers.py -$(GENERATED_WRAPPER_FILES): ../scripts/data_files/driver_templates/psa_crypto_driver_wrappers.h.jinja -$(GENERATED_WRAPPER_FILES): ../scripts/data_files/driver_templates/psa_crypto_driver_wrappers_no_static.c.jinja +$(GENERATED_WRAPPER_FILES): ../tf-psa-crypto/scripts/generate_driver_wrappers.py +$(GENERATED_WRAPPER_FILES): ../tf-psa-crypto/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.h.jinja +$(GENERATED_WRAPPER_FILES): ../tf-psa-crypto/scripts/data_files/driver_templates/psa_crypto_driver_wrappers_no_static.c.jinja $(GENERATED_WRAPPER_FILES): echo " Gen $(GENERATED_WRAPPER_FILES)" - $(PYTHON) ../scripts/generate_driver_wrappers.py $(TF_PSA_CRYPTO_CORE_PATH) + $(PYTHON) ../tf-psa-crypto/scripts/generate_driver_wrappers.py $(TF_PSA_CRYPTO_CORE_PATH) $(TF_PSA_CRYPTO_CORE_PATH)/psa_crypto.o:$(TF_PSA_CRYPTO_CORE_PATH)/psa_crypto_driver_wrappers.h diff --git a/scripts/make_generated_files.bat b/scripts/make_generated_files.bat index 4612cc2d25..0d2c0718f3 100644 --- a/scripts/make_generated_files.bat +++ b/scripts/make_generated_files.bat @@ -9,7 +9,7 @@ @rem @@@@ library\** @@@@ @rem psa_crypto_driver_wrappers.h needs to be generated prior to @rem generate_visualc_files.pl being invoked. -python scripts\generate_driver_wrappers.py || exit /b 1 +python tf-psa-crypto\scripts\generate_driver_wrappers.py || exit /b 1 perl scripts\generate_errors.pl || exit /b 1 perl scripts\generate_query_config.pl || exit /b 1 perl scripts\generate_features.pl || exit /b 1 diff --git a/tests/Makefile b/tests/Makefile index 1a1c185d8d..752a025cc9 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -332,10 +332,11 @@ libtestdriver1.a: cp -Rf ../framework ./libtestdriver1 cp -Rf ../library ./libtestdriver1 cp -Rf ../include ./libtestdriver1 + cp -Rf ../scripts ./libtestdriver1 cp -Rf ../tf-psa-crypto/core ./libtestdriver1/tf-psa-crypto cp -Rf ../tf-psa-crypto/include ./libtestdriver1/tf-psa-crypto cp -Rf ../tf-psa-crypto/drivers/builtin ./libtestdriver1/tf-psa-crypto/drivers - cp -Rf ../scripts ./libtestdriver1 + cp -Rf ../tf-psa-crypto/scripts ./libtestdriver1/tf-psa-crypto # Set the test driver base (minimal) configuration. cp ../tf-psa-crypto/tests/configs/config_test_driver.h ./libtestdriver1/include/mbedtls/mbedtls_config.h diff --git a/tests/scripts/check-generated-files.sh b/tests/scripts/check-generated-files.sh index d4bfca4143..edac387f6f 100755 --- a/tests/scripts/check-generated-files.sh +++ b/tests/scripts/check-generated-files.sh @@ -145,6 +145,8 @@ if [ -d tf-psa-crypto ]; then check ../framework/scripts/generate_ecp_tests.py $(../framework/scripts/generate_ecp_tests.py --list) check ../framework/scripts/generate_psa_tests.py $(../framework/scripts/generate_psa_tests.py --list) cd .. + check tf-psa-crypto/scripts/generate_driver_wrappers.py ${crypto_core_dir}/psa_crypto_driver_wrappers.h \ + ${crypto_core_dir}/psa_crypto_driver_wrappers_no_static.c check framework/scripts/generate_config_tests.py tests/suites/test_suite_config.mbedtls_boolean.data else check framework/scripts/generate_bignum_tests.py $(framework/scripts/generate_bignum_tests.py --list) @@ -155,12 +157,12 @@ else fi check framework/scripts/generate_ecp_tests.py $(framework/scripts/generate_ecp_tests.py --list) check framework/scripts/generate_psa_tests.py $(framework/scripts/generate_psa_tests.py --list) + check scripts/generate_driver_wrappers.py ${crypto_core_dir}/psa_crypto_driver_wrappers.h \ + ${crypto_core_dir}/psa_crypto_driver_wrappers_no_static.c fi check scripts/generate_psa_constants.py programs/psa/psa_constant_names_generated.c check framework/scripts/generate_test_keys.py framework/tests/src/test_keys.h -check scripts/generate_driver_wrappers.py ${crypto_core_dir}/psa_crypto_driver_wrappers.h \ - ${crypto_core_dir}/psa_crypto_driver_wrappers_no_static.c # Additional checks for Mbed TLS only if in_mbedtls_repo; then diff --git a/tf-psa-crypto/core/CMakeLists.txt b/tf-psa-crypto/core/CMakeLists.txt index 3e4092c1ae..ccf11480a0 100644 --- a/tf-psa-crypto/core/CMakeLists.txt +++ b/tf-psa-crypto/core/CMakeLists.txt @@ -15,12 +15,12 @@ if(GEN_FILES) ${CMAKE_CURRENT_BINARY_DIR}/psa_crypto_driver_wrappers_no_static.c COMMAND ${TF_PSA_CRYPTO_PYTHON_EXECUTABLE} - ${MBEDTLS_DIR}/scripts/generate_driver_wrappers.py + ${TF_PSA_CRYPTO_DIR}/scripts/generate_driver_wrappers.py ${CMAKE_CURRENT_BINARY_DIR} DEPENDS - ${MBEDTLS_DIR}/scripts/generate_driver_wrappers.py - ${MBEDTLS_DIR}/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.h.jinja - ${MBEDTLS_DIR}/scripts/data_files/driver_templates/psa_crypto_driver_wrappers_no_static.c.jinja + ${TF_PSA_CRYPTO_DIR}/scripts/generate_driver_wrappers.py + ${TF_PSA_CRYPTO_DIR}/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.h.jinja + ${TF_PSA_CRYPTO_DIR}/scripts/data_files/driver_templates/psa_crypto_driver_wrappers_no_static.c.jinja ) else() link_to_source(psa_crypto_driver_wrappers.h) diff --git a/scripts/data_files/driver_jsons/driver_opaque_schema.json b/tf-psa-crypto/scripts/data_files/driver_jsons/driver_opaque_schema.json similarity index 100% rename from scripts/data_files/driver_jsons/driver_opaque_schema.json rename to tf-psa-crypto/scripts/data_files/driver_jsons/driver_opaque_schema.json diff --git a/scripts/data_files/driver_jsons/driver_transparent_schema.json b/tf-psa-crypto/scripts/data_files/driver_jsons/driver_transparent_schema.json similarity index 100% rename from scripts/data_files/driver_jsons/driver_transparent_schema.json rename to tf-psa-crypto/scripts/data_files/driver_jsons/driver_transparent_schema.json diff --git a/scripts/data_files/driver_jsons/driverlist.json b/tf-psa-crypto/scripts/data_files/driver_jsons/driverlist.json similarity index 100% rename from scripts/data_files/driver_jsons/driverlist.json rename to tf-psa-crypto/scripts/data_files/driver_jsons/driverlist.json diff --git a/scripts/data_files/driver_jsons/mbedtls_test_opaque_driver.json b/tf-psa-crypto/scripts/data_files/driver_jsons/mbedtls_test_opaque_driver.json similarity index 100% rename from scripts/data_files/driver_jsons/mbedtls_test_opaque_driver.json rename to tf-psa-crypto/scripts/data_files/driver_jsons/mbedtls_test_opaque_driver.json diff --git a/scripts/data_files/driver_jsons/mbedtls_test_transparent_driver.json b/tf-psa-crypto/scripts/data_files/driver_jsons/mbedtls_test_transparent_driver.json similarity index 100% rename from scripts/data_files/driver_jsons/mbedtls_test_transparent_driver.json rename to tf-psa-crypto/scripts/data_files/driver_jsons/mbedtls_test_transparent_driver.json diff --git a/scripts/data_files/driver_jsons/p256_transparent_driver.json b/tf-psa-crypto/scripts/data_files/driver_jsons/p256_transparent_driver.json similarity index 100% rename from scripts/data_files/driver_jsons/p256_transparent_driver.json rename to tf-psa-crypto/scripts/data_files/driver_jsons/p256_transparent_driver.json diff --git a/scripts/data_files/driver_templates/OS-template-opaque.jinja b/tf-psa-crypto/scripts/data_files/driver_templates/OS-template-opaque.jinja similarity index 100% rename from scripts/data_files/driver_templates/OS-template-opaque.jinja rename to tf-psa-crypto/scripts/data_files/driver_templates/OS-template-opaque.jinja diff --git a/scripts/data_files/driver_templates/OS-template-transparent.jinja b/tf-psa-crypto/scripts/data_files/driver_templates/OS-template-transparent.jinja similarity index 100% rename from scripts/data_files/driver_templates/OS-template-transparent.jinja rename to tf-psa-crypto/scripts/data_files/driver_templates/OS-template-transparent.jinja diff --git a/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.h.jinja b/tf-psa-crypto/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.h.jinja similarity index 100% rename from scripts/data_files/driver_templates/psa_crypto_driver_wrappers.h.jinja rename to tf-psa-crypto/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.h.jinja diff --git a/scripts/data_files/driver_templates/psa_crypto_driver_wrappers_no_static.c.jinja b/tf-psa-crypto/scripts/data_files/driver_templates/psa_crypto_driver_wrappers_no_static.c.jinja similarity index 100% rename from scripts/data_files/driver_templates/psa_crypto_driver_wrappers_no_static.c.jinja rename to tf-psa-crypto/scripts/data_files/driver_templates/psa_crypto_driver_wrappers_no_static.c.jinja diff --git a/scripts/generate_driver_wrappers.py b/tf-psa-crypto/scripts/generate_driver_wrappers.py similarity index 98% rename from scripts/generate_driver_wrappers.py rename to tf-psa-crypto/scripts/generate_driver_wrappers.py index 9579764045..7f5be2a923 100755 --- a/scripts/generate_driver_wrappers.py +++ b/tf-psa-crypto/scripts/generate_driver_wrappers.py @@ -179,6 +179,8 @@ def main() -> int: args = parser.parse_args() project_root = os.path.abspath(args.project_root) + if build_tree.looks_like_mbedtls_root(project_root): + project_root = os.path.join(project_root, 'tf-psa-crypto') crypto_core_directory = build_tree.crypto_core_directory(project_root)