From 2a9f78ac311d8cafde911f2714e4e4f5b9a937e8 Mon Sep 17 00:00:00 2001 From: Antonio de Angelis Date: Mon, 21 Nov 2022 12:12:02 +0000 Subject: [PATCH 01/22] Crypto: Add additional checks in ECDSA test Add additional tests on reference signature and conversion from and to encoded quantities to formats supported by our implementation of PSA Crypto for signatures and public keys. Signed-off-by: Antonio de Angelis Change-Id: I05e8450d37e1289c9f833dc64ea0865f101f0666 --- .../suites/crypto/crypto_tests_common.c | 139 ++++++++++++++++-- 1 file changed, 126 insertions(+), 13 deletions(-) diff --git a/test/secure_fw/suites/crypto/crypto_tests_common.c b/test/secure_fw/suites/crypto/crypto_tests_common.c index c46d8cd..5493536 100644 --- a/test/secure_fw/suites/crypto/crypto_tests_common.c +++ b/test/secure_fw/suites/crypto/crypto_tests_common.c @@ -2284,17 +2284,51 @@ static const uint8_t ecdsa_private_key[] = { 0x3D, 0xA1, 0x7B, 0x47, 0x68, 0x38, 0xE3, 0x0D, 0x10, 0x4A, 0x6D, 0xA7, 0x2D, 0x48, 0xA4, 0x18 }; -/* Corresponding public key in uncompressed form, i.e. 0x04 X Y */ +/* Corresponding public key in uncompressed form, i.e. 0x04 X Y, and + * encoded as per RFC 5480. This is obtained by running the following + * command: + * + * openssl ec -in private_key.der -inform der -pubout -out public_key.der -outform der + * + * where the private_key.der contains the DER encoding of the private key contained in + * ecdsa_private_key above + */ static const uint8_t ecdsa_public_key[] = { - 0x04, 0x41, 0xC6, 0xFC, 0xC5, 0xA4, 0xBB, 0x70, - 0x45, 0xA7, 0xB2, 0x5E, 0x50, 0xB3, 0x2E, 0xD0, - 0x2A, 0x8D, 0xA8, 0x8E, 0x1B, 0x34, 0xC2, 0x71, - 0x57, 0x38, 0x5C, 0x45, 0xAB, 0xF2, 0x51, 0x7B, - 0x17, 0x5A, 0xC5, 0x05, 0xA9, 0x9E, 0x4B, 0x7D, - 0xDD, 0xD7, 0xBF, 0xBB, 0x45, 0x51, 0x92, 0x7D, - 0x33, 0x33, 0x8B, 0x1B, 0x70, 0x5A, 0xFD, 0x2B, - 0xF2, 0x7A, 0xA4, 0xBD, 0x37, 0x50, 0xED, 0x34, - 0x9F + 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, + 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, + 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, + 0x42, 0x00, 0x04, 0x41, 0xC6, 0xFC, 0xC5, 0xA4, + 0xBB, 0x70, 0x45, 0xA7, 0xB2, 0x5E, 0x50, 0xB3, + 0x2E, 0xD0, 0x2A, 0x8D, 0xA8, 0x8E, 0x1B, 0x34, + 0xC2, 0x71, 0x57, 0x38, 0x5C, 0x45, 0xAB, 0xF2, + 0x51, 0x7B, 0x17, 0x5A, 0xC5, 0x05, 0xA9, 0x9E, + 0x4B, 0x7D, 0xDD, 0xD7, 0xBF, 0xBB, 0x45, 0x51, + 0x92, 0x7D, 0x33, 0x33, 0x8B, 0x1B, 0x70, 0x5A, + 0xFD, 0x2B, 0xF2, 0x7A, 0xA4, 0xBD, 0x37, 0x50, + 0xED, 0x34, 0x9F +}; + +/* Associated encoded signature using the private key above on the reference + * input message, as described in RFC 5480: + * + * message = "This is the message that I would like to sign" + * + * using PSA_ALG_DETERMINISTIC_ECDSA(PSA_ALG_SHA_256), i.e. + * + * Ecdsa-Sig-Value ::= SEQUENCE { + * r INTEGER, + * s INTEGER } + */ +static const uint8_t reference_encoded_r_s[] = { + 0x30, 0x45, 0x02, 0x20, 0x6b, 0xdc, 0xc6, 0xd5, + 0xf5, 0xdc, 0xab, 0xc2, 0x52, 0xb6, 0xa0, 0xcd, + 0x12, 0x9e, 0xfc, 0x3e, 0x86, 0x24, 0x7d, 0xf1, + 0xbd, 0x7b, 0xe9, 0x76, 0xbd, 0xb5, 0x99, 0x82, + 0x44, 0xd4, 0xa5, 0x0c, 0x02, 0x21, 0x00, 0xa6, + 0x25, 0x7b, 0x3b, 0x2a, 0x2d, 0xea, 0xaa, 0x43, + 0xbc, 0x3a, 0xc7, 0x89, 0xdc, 0x1b, 0x52, 0xe0, + 0xd2, 0xb6, 0xbd, 0x8c, 0x5d, 0x5e, 0xf3, 0x32, + 0xe7, 0x32, 0x65, 0xbd, 0x7b, 0xcb, 0x06, }; /* Buffer to hold the peer key of the key agreement process */ @@ -2631,6 +2665,64 @@ void psa_asymmetric_encryption_test(psa_algorithm_t alg, #define SIGNATURE_BUFFER_SIZE \ (PSA_ECDSA_SIGNATURE_SIZE(PSA_BYTES_TO_BITS(sizeof(ecdsa_private_key)))) +/* This helper function parses a signature as specified in RFC 5480 into a pair + * (r,s) of contiguous bytes + * + * \param[in] sig Pointer to a buffer containing the encoded signature + * \param[in] slen Size in bytes of the encoded signature structure + * \param[out] r_s_pair Buffer containing the (r,s) pair extracted. It's caller + * responsibility to ensure the buffer is big enough to + * hold the parsed (r,s) pair. + * + * \return The size in bytes of the parsed signature, i.e. (r,s) pair + */ +static inline size_t parse_signature_from_rfc5480_encoding(const uint8_t *sig, + size_t slen, + uint8_t *r_s_pair) +{ + const uint8_t *sig_ptr = NULL; + /* Move r in place */ + size_t r_len = sig[3]; + if (r_len % 2) { + sig_ptr = &sig[5]; + r_len--; + } else { + sig_ptr = &sig[4]; + } + memcpy(&r_s_pair[0], sig_ptr, r_len); + /* Move s in place */ + size_t s_len = sig_ptr[r_len + 1]; + if (s_len % 2) { + sig_ptr = &sig_ptr[3+r_len]; + s_len--; + } else { + sig_ptr = &sig_ptr[2+r_len]; + } + memcpy(&r_s_pair[r_len], sig_ptr, s_len); + slen = s_len + r_len; /* Update the length of the signature we're passing */ + return slen; +} + +#define LEN_OFF (3) /* Offset for the Length field of the second SEQUENCE */ +#define VAL_OFF (3) /* Offset for the value field of the BIT STRING */ + +/* This helper function gets a pointer to the bitstring associated to the publicKey + * as encoded per RFC 5280. This function assumes that the public key encoding is not + * bigger than 127 bytes (i.e. usually up until 384 bit curves) + * + * \param[in,out] p Double pointer to a buffer containing the RFC 5280 of the ECDSA public key. + * On output, the pointer is updated to point to the start of the public key + * in BIT STRING form. + * \param[in] size Pointer to a buffer containing the size of the public key extracted + * + */ +static inline void get_public_key_from_rfc5280_encoding(uint8_t **p, size_t *size) +{ + uint8_t *key_start = (*p) + (LEN_OFF + 1 + (*p)[LEN_OFF] + VAL_OFF); + *p = key_start; + *size = key_start[-2]-1; /* -2 from VAL_OFF to get the length, -1 to remove the ASN.1 padding byte count */ +} + void psa_sign_verify_message_test(psa_algorithm_t alg, struct test_result_t *ret) { @@ -2649,6 +2741,15 @@ void psa_sign_verify_message_test(psa_algorithm_t alg, uint32_t comp_result = 0; uint8_t hash[32] = {0}; /* Support only SHA-256 based signatures in the tests for simplicity */ size_t hash_length = 0; + uint8_t *p_key = (uint8_t *) ecdsa_public_key; + uint8_t reformatted_signature[64] = {0}; + size_t public_key_size; + size_t parsed_signature_size = parse_signature_from_rfc5480_encoding( + reference_encoded_r_s, + sizeof(reference_encoded_r_s), + reformatted_signature); + /* Get the BIT STRING for the public key */ + get_public_key_from_rfc5280_encoding(&p_key, &public_key_size); /* Initialize to the passing value */ ret->val = TEST_PASSED; @@ -2681,7 +2782,7 @@ void psa_sign_verify_message_test(psa_algorithm_t alg, } /* Check that exported key matches the reference key */ - comp_result = memcmp(ecdsa_pub_key, ecdsa_public_key, pub_key_length); + comp_result = memcmp(ecdsa_pub_key, p_key, pub_key_length); if (comp_result != 0) { TEST_FAIL("Exported ECDSA public key does not match the reference!"); goto destroy_key; @@ -2703,6 +2804,18 @@ void psa_sign_verify_message_test(psa_algorithm_t alg, goto destroy_key; } + if (signature_length != parsed_signature_size) { + TEST_FAIL("Produced signature length does not match the reference!"); + goto destroy_key; + } + + /* Check that signature matches the reference provided */ + comp_result = memcmp(signature, reformatted_signature, signature_length); + if (comp_result != 0) { + TEST_FAIL("Signature does not match the reference!"); + goto destroy_key; + } + status = psa_verify_message(key_id_local, alg, message, sizeof(message) - 1, signature, signature_length); @@ -2725,8 +2838,8 @@ void psa_sign_verify_message_test(psa_algorithm_t alg, key_type = PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_FAMILY_SECP_R1); psa_set_key_type(&input_key_attr, key_type); - status = psa_import_key(&input_key_attr, ecdsa_public_key, - sizeof(ecdsa_public_key), &key_id_local); + status = psa_import_key(&input_key_attr, p_key, + public_key_size, &key_id_local); if (status != PSA_SUCCESS) { TEST_FAIL("Error importing the public key"); return; From 614e8c358377e4146e8ee13d1246e59d01b4bf1b Mon Sep 17 00:00:00 2001 From: David Vincze Date: Thu, 24 Nov 2022 14:37:32 +0100 Subject: [PATCH 02/22] Test: Disable qcbor tests in regression test suite TF-M uses a fixed version of the qcbor library which is rarely modified. For that reason, it is unnecessary to execute these tests as part of the regression test suite. It would be enough to include them in tests that run less frequently - such as a release test. Change-Id: Id0e5472e34486bc2cb22b6d13e0ebebb94d6e439 Signed-off-by: David Vincze --- test/config/default_ns_test_config.cmake | 2 +- test/secure_fw/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/config/default_ns_test_config.cmake b/test/config/default_ns_test_config.cmake index 0fa95d7..bedf691 100644 --- a/test/config/default_ns_test_config.cmake +++ b/test/config/default_ns_test_config.cmake @@ -13,7 +13,6 @@ set(TEST_FRAMEWORK_NS ON CACHE BOOL "Whether to build NS regre set(TEST_NS_ATTESTATION ON CACHE BOOL "Whether to build NS regression Attestation tests") set(TEST_NS_T_COSE ON CACHE BOOL "Whether to build NS regression t_cose tests") -set(TEST_NS_QCBOR ON CACHE BOOL "Whether to build NS regression QCBOR tests") set(TEST_NS_CRYPTO ON CACHE BOOL "Whether to build NS regression Crypto tests") set(TEST_NS_ITS ON CACHE BOOL "Whether to build NS regression ITS tests") set(TEST_NS_PS ON CACHE BOOL "Whether to build NS regression PS tests") @@ -22,6 +21,7 @@ set(TEST_NS_FWU ON CACHE BOOL "Whether to build NS regre set(TEST_NS_MULTI_CORE ON CACHE BOOL "Whether to build NS regression multi-core tests") set(TEST_NS_MANAGE_NSID ON CACHE BOOL "Whether to build NS regression NSID management tests") +set(TEST_NS_QCBOR OFF CACHE BOOL "Whether to build NS regression QCBOR tests") set(TEST_NS_SLIH_IRQ OFF CACHE BOOL "Whether to build NS regression Second-Level Interrupt Handling tests") set(TEST_NS_FLIH_IRQ OFF CACHE BOOL "Whether to build NS regression First-Level Interrupt Handling tests") set(TEST_NS_FPU OFF CACHE BOOL "Whether to build NS regression FPU tests") diff --git a/test/secure_fw/CMakeLists.txt b/test/secure_fw/CMakeLists.txt index 693aa03..8a9a4f4 100644 --- a/test/secure_fw/CMakeLists.txt +++ b/test/secure_fw/CMakeLists.txt @@ -17,8 +17,8 @@ include(utils) TEST_NS_ATTESTATION; TEST_NS_CRYPTO; TEST_NS_ITS; - TEST_NS_QCBOR; TEST_NS_PS; + TEST_NS_QCBOR; TEST_NS_T_COSE; TEST_NS_PLATFORM; TEST_NS_FWU; From 66e119aaece63926736375aadca0a3881bd03de7 Mon Sep 17 00:00:00 2001 From: David Vincze Date: Thu, 10 Nov 2022 18:46:03 +0100 Subject: [PATCH 03/22] QCBOR: update qcbor CMake files The qcbor library's CMake file has been updated in TF-M. Therefore, some modifications are needed here as well. TF-M change-id: If2b6c27e89c163d6358492965e92104fc4ee8eae Change-Id: Ie3c418521a802a8b158b7fc1195d5dc5aa7f1e69 Signed-off-by: David Vincze --- .../suites/attestation/CMakeLists.txt | 4 +-- test/secure_fw/suites/qcbor/CMakeLists.txt | 35 ++++++++++--------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/test/secure_fw/suites/attestation/CMakeLists.txt b/test/secure_fw/suites/attestation/CMakeLists.txt index 5234eeb..c95a05b 100644 --- a/test/secure_fw/suites/attestation/CMakeLists.txt +++ b/test/secure_fw/suites/attestation/CMakeLists.txt @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------- -# Copyright (c) 2020-2022, Arm Limited. All rights reserved. +# Copyright (c) 2020-2023, Arm Limited. All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause # @@ -98,7 +98,7 @@ if (TEST_S_ATTESTATION) target_link_libraries(tfm_test_suite_attestation_s PRIVATE - tfm_qcbor_s + qcbor tfm_t_cose_s tfm_test_framework_s tfm_attestation_defs diff --git a/test/secure_fw/suites/qcbor/CMakeLists.txt b/test/secure_fw/suites/qcbor/CMakeLists.txt index b33e36e..036310a 100644 --- a/test/secure_fw/suites/qcbor/CMakeLists.txt +++ b/test/secure_fw/suites/qcbor/CMakeLists.txt @@ -1,12 +1,18 @@ #------------------------------------------------------------------------------- -# Copyright (c) 2020-2022, Arm Limited. All rights reserved. +# Copyright (c) 2020-2023, Arm Limited. All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause # #------------------------------------------------------------------------------- cmake_policy(SET CMP0079 NEW) -####################### qcbor ns ############################################### +# Adding qcbor and qcbor_test libraries manually as logical target names +# must be globally unique in CMake. The Secure image also relies on the qcbor +# library (including its own CMake files), but a separate Non Secure library +# target must be maintained (with a unique name) as they may be built +# with different configurations - within the same CMake environment. + +####################### Non Secure qcbor library ############################### add_library(tfm_qcbor_ns STATIC EXCLUDE_FROM_ALL) @@ -21,18 +27,6 @@ target_sources(tfm_qcbor_ns target_include_directories(tfm_qcbor_ns PUBLIC $ - INTERFACE - $ -) - -target_link_libraries(tfm_qcbor_ns - PRIVATE - tfm_t_cose_defs -) - -target_compile_options(tfm_qcbor_ns - PUBLIC - ${COMPILER_CP_FLAG} ) target_compile_definitions(tfm_qcbor_ns @@ -42,7 +36,12 @@ target_compile_definitions(tfm_qcbor_ns QCBOR_DISABLE_PREFERRED_FLOAT ) -####################### qcbor test ############################################# +target_compile_options(tfm_qcbor_ns + PUBLIC + ${COMPILER_CP_FLAG} +) + +####################### qcbor test library ##################################### add_library(tfm_qcbor_test STATIC EXCLUDE_FROM_ALL) @@ -66,6 +65,11 @@ target_link_libraries(tfm_qcbor_test tfm_qcbor_ns ) +# Note: All floating point support is disabled in tfm_qcbor_ns library +# to reduce code size. These compile options are public so the qcbor +# test library will also get them. It means that effectively +# the floating point test cases are also disabled. + ####################### Non Secure test ######################################## if (NOT TEST_NS_QCBOR) @@ -82,7 +86,6 @@ target_sources(tfm_test_suite_qcbor_ns target_include_directories(tfm_test_suite_qcbor_ns PUBLIC non_secure - $ ) target_compile_definitions(tfm_test_suite_qcbor_ns From f984f3a34ac63720d4490bc771f066e1aeed6ef3 Mon Sep 17 00:00:00 2001 From: Xinyu Zhang Date: Tue, 31 Jan 2023 14:33:13 +0800 Subject: [PATCH 04/22] NSID: Fix build warning in nsid_testsuite.c Add parentheses and update code format to fix build warning: "suggest parentheses around '+' in operand of '&'". Signed-off-by: Xinyu Zhang Change-Id: Ic19125e6b8e98ffacfb83aac6b0589182665ac6d --- test/secure_fw/suites/nsid/nsid_testsuite.c | 34 ++++++--------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/test/secure_fw/suites/nsid/nsid_testsuite.c b/test/secure_fw/suites/nsid/nsid_testsuite.c index 2137d28..c35890f 100755 --- a/test/secure_fw/suites/nsid/nsid_testsuite.c +++ b/test/secure_fw/suites/nsid/nsid_testsuite.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022, Arm Limited. All rights reserved. + * Copyright (c) 2021-2023, Arm Limited. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * @@ -204,12 +204,8 @@ static void tfm_nsid_test_case_5(struct test_result_t *ret) token_a = nsid_acquire_ctx_svc(VALID_GROUP_ID, thread_id); token_b = nsid_acquire_ctx_svc(VALID_GROUP_ID, thread_id + 1); - if (token_a != MAKE_NS_CLIENT_TOKEN(thread_id, \ - VALID_GROUP_ID, \ - VALID_INDEX) || \ - token_b != MAKE_NS_CLIENT_TOKEN(thread_id + 1, \ - VALID_GROUP_ID, \ - VALID_INDEX)) { + if (token_a != MAKE_NS_CLIENT_TOKEN(thread_id, VALID_GROUP_ID, VALID_INDEX) || + token_b != MAKE_NS_CLIENT_TOKEN((thread_id + 1), VALID_GROUP_ID, VALID_INDEX)) { TEST_FAIL("ACQUIRE shall return a valid token\r\n"); nsid_test_case_finish(ret); return; @@ -267,12 +263,8 @@ static void tfm_nsid_test_case_6(struct test_result_t *ret) token_a = nsid_acquire_ctx_svc(VALID_GROUP_ID, thread_id); token_b = nsid_acquire_ctx_svc(VALID_GROUP_ID, thread_id + 1); - if (token_a != MAKE_NS_CLIENT_TOKEN(thread_id, \ - VALID_GROUP_ID, - VALID_INDEX) || \ - token_b != MAKE_NS_CLIENT_TOKEN(thread_id + 1, \ - VALID_GROUP_ID, \ - VALID_INDEX)) { + if (token_a != MAKE_NS_CLIENT_TOKEN(thread_id, VALID_GROUP_ID, VALID_INDEX) || + token_b != MAKE_NS_CLIENT_TOKEN((thread_id + 1), VALID_GROUP_ID, VALID_INDEX)) { TEST_FAIL("ACQUIRE shall return a valid token\r\n"); nsid_test_case_finish(ret); return; @@ -466,12 +458,8 @@ static void tfm_nsid_test_case_11(struct test_result_t *ret) token_a = nsid_acquire_ctx_svc(VALID_GROUP_ID, thread_id); token_b = nsid_acquire_ctx_svc(VALID_GROUP_ID, thread_id + 1); - if (token_a != MAKE_NS_CLIENT_TOKEN(thread_id, \ - VALID_GROUP_ID, \ - VALID_INDEX) || \ - token_b != MAKE_NS_CLIENT_TOKEN(thread_id + 1, \ - VALID_GROUP_ID, \ - VALID_INDEX)) { + if (token_a != MAKE_NS_CLIENT_TOKEN(thread_id, VALID_GROUP_ID, VALID_INDEX) || + token_b != MAKE_NS_CLIENT_TOKEN((thread_id + 1), VALID_GROUP_ID, VALID_INDEX)) { TEST_FAIL("ACQUIRE shall return a valid token\r\n"); nsid_test_case_finish(ret); return; @@ -894,12 +882,8 @@ static void tfm_nsid_test_case_20(struct test_result_t *ret) token_a = nsid_acquire_ctx_svc(VALID_GROUP_ID, thread_id); token_b = nsid_acquire_ctx_svc(VALID_GROUP_ID, thread_id + 1); - if (token_a != MAKE_NS_CLIENT_TOKEN(thread_id, \ - VALID_GROUP_ID, \ - VALID_INDEX) || \ - token_b != MAKE_NS_CLIENT_TOKEN(thread_id + 1, \ - VALID_GROUP_ID, \ - VALID_INDEX)) { + if (token_a != MAKE_NS_CLIENT_TOKEN(thread_id, VALID_GROUP_ID, VALID_INDEX) || + token_b != MAKE_NS_CLIENT_TOKEN((thread_id + 1), VALID_GROUP_ID, VALID_INDEX)) { TEST_FAIL("ACQUIRE shall return a valid token\r\n"); nsid_test_case_finish(ret); return; From 21a4421de92a676c62bff829921f9980e10c1829 Mon Sep 17 00:00:00 2001 From: David Hu Date: Wed, 15 Feb 2023 14:31:48 +0800 Subject: [PATCH 05/22] Build: Decouple NS from config_impl.cmake config_impl.cmake collects some SPM specific config flags. Those config flags are transparent to NS developers. Remove NS dependency on those config flags to simplify NS integration with TF-M. Signed-off-by: David Hu Change-Id: I39f53284dbf34a42e0ea745fdcd73f493807988d --- app/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 603fcc8..c0146a4 100755 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -115,7 +115,6 @@ endif() target_sources(tfm_api_ns PRIVATE $<$:${INTERFACE_SRC_DIR}/tfm_psa_ns_api.c> - $<$,$>:${INTERFACE_SRC_DIR}/tfm_psa_ns_connection_api.c> # NS specific implementation of NS interface dispacther $<$:${CMAKE_CURRENT_SOURCE_DIR}/tfm_ns_interface.c> ) From 6b219f7f26eb7fe27eaee82b7a33288d17c70520 Mon Sep 17 00:00:00 2001 From: Kevin Peng Date: Fri, 13 Jan 2023 12:00:49 +0800 Subject: [PATCH 06/22] Build: Use the TARGET_PLATFORM_PATH Change-Id: I4b33600ca6ccdaff60994a498123107054eaa62e Signed-off-by: Kevin Peng --- app/CMakeLists.txt | 4 ++-- test/bl1/CMakeLists.txt | 4 ++-- test/bl2/CMakeLists.txt | 4 ++-- test/secure_fw/secure_tests.cmake | 4 ++-- test/secure_fw/suites/CMakeLists.txt | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index c0146a4..97fd3c5 100755 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -14,8 +14,8 @@ project(tfm_ns LANGUAGES ASM C) # Secure code. To facilitate this, we once again reload the compiler to load the # setting for the NS CPU. Cmake settings are directory scoped so this affects # anything loaded from or declared in this dir. -if (EXISTS ${CMAKE_SOURCE_DIR}/platform/ext/target/${TFM_PLATFORM}/preload_ns.cmake) - include(${CMAKE_SOURCE_DIR}/platform/ext/target/${TFM_PLATFORM}/preload_ns.cmake) +if (EXISTS ${TARGET_PLATFORM_PATH}/preload_ns.cmake) + include(${TARGET_PLATFORM_PATH}/preload_ns.cmake) tfm_toolchain_reload_compiler() endif() diff --git a/test/bl1/CMakeLists.txt b/test/bl1/CMakeLists.txt index 37a6d4f..83c6dc0 100644 --- a/test/bl1/CMakeLists.txt +++ b/test/bl1/CMakeLists.txt @@ -12,8 +12,8 @@ if(NOT BL1) endif() # Reload the compiler options for the secure core, if the NS core differs -if (EXISTS ${CMAKE_SOURCE_DIR}/platform/ext/target/${TFM_PLATFORM}/preload_ns.cmake) - include(${CMAKE_SOURCE_DIR}/platform/ext/target/${TFM_PLATFORM}/preload.cmake) +if (EXISTS ${TARGET_PLATFORM_PATH}/preload_ns.cmake) + include(${TARGET_PLATFORM_PATH}/preload.cmake) tfm_toolchain_reload_compiler() endif() diff --git a/test/bl2/CMakeLists.txt b/test/bl2/CMakeLists.txt index 6cc8e85..e559800 100644 --- a/test/bl2/CMakeLists.txt +++ b/test/bl2/CMakeLists.txt @@ -14,8 +14,8 @@ if(NOT TEST_BL2 OR NOT BL2) endif() # Reload the compiler options for the secure core, if the NS core differs -if (EXISTS ${CMAKE_SOURCE_DIR}/platform/ext/target/${TFM_PLATFORM}/preload_ns.cmake) - include(${CMAKE_SOURCE_DIR}/platform/ext/target/${TFM_PLATFORM}/preload.cmake) +if (EXISTS ${TARGET_PLATFORM_PATH}/preload_ns.cmake) + include(${TARGET_PLATFORM_PATH}/preload.cmake) tfm_toolchain_reload_compiler() endif() diff --git a/test/secure_fw/secure_tests.cmake b/test/secure_fw/secure_tests.cmake index c5f6dd5..c942c28 100644 --- a/test/secure_fw/secure_tests.cmake +++ b/test/secure_fw/secure_tests.cmake @@ -9,8 +9,8 @@ # Since the main test directory is a NS dir, this subdir is specifically made a # secure directory as it build the secure side tests and services -if (EXISTS ${CMAKE_SOURCE_DIR}/platform/ext/target/${TFM_PLATFORM}/preload_ns.cmake) - include(${CMAKE_SOURCE_DIR}/platform/ext/target/${TFM_PLATFORM}/preload.cmake) +if (EXISTS ${TARGET_PLATFORM_PATH}/preload_ns.cmake) + include(${TARGET_PLATFORM_PATH}/preload.cmake) tfm_toolchain_reload_compiler() endif() diff --git a/test/secure_fw/suites/CMakeLists.txt b/test/secure_fw/suites/CMakeLists.txt index e359e8d..268b790 100644 --- a/test/secure_fw/suites/CMakeLists.txt +++ b/test/secure_fw/suites/CMakeLists.txt @@ -13,8 +13,8 @@ cmake_minimum_required(VERSION 3.13) # Secure code. To facilitate this, we once again reload the compiler to load the # setting for the NS CPU. Cmake settings are directory scoped so this affects # anything loaded from or declared in this dir. -if (EXISTS ${CMAKE_SOURCE_DIR}/platform/ext/target/${TFM_PLATFORM}/preload_ns.cmake) - include(${CMAKE_SOURCE_DIR}/platform/ext/target/${TFM_PLATFORM}/preload_ns.cmake) +if (EXISTS ${TARGET_PLATFORM_PATH}/preload_ns.cmake) + include(${TARGET_PLATFORM_PATH}/preload_ns.cmake) tfm_toolchain_reload_compiler() endif() From bb479b19b9951935a2970af00f9ac72f0e5e54c0 Mon Sep 17 00:00:00 2001 From: Kevin Peng Date: Sat, 28 Jan 2023 17:07:15 +0800 Subject: [PATCH 07/22] Build: Remove default values for platform cache configs Those config options are changed to normal variables and by default they are disabled. So their cache settings should be removed. Change-Id: I3807304acb42f7dfe7dd77cec85ad59f33ebf72c Signed-off-by: Kevin Peng --- test/config/default_test_config.cmake | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/test/config/default_test_config.cmake b/test/config/default_test_config.cmake index 5446508..9c1f862 100644 --- a/test/config/default_test_config.cmake +++ b/test/config/default_test_config.cmake @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------- -# Copyright (c) 2021-2022, Arm Limited. All rights reserved. +# Copyright (c) 2021-2023, Arm Limited. All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause # @@ -78,9 +78,3 @@ set(TEST_S_FPU OFF CACHE BOOL "Whether to set(EXTRA_NS_TEST_SUITE_PATH "" CACHE PATH "List of extra non-secure test suites directories. An extra test suite folder contains source code, CMakeLists.txt and cmake configuration file") set(EXTRA_S_TEST_SUITE_PATH "" CACHE PATH "List of extra secure test suites directories. An extra test suite folder contains source code, CMakeLists.txt and cmake configuration file") - -######################### Platform specific setting ############################ - -set(PLATFORM_SLIH_IRQ_TEST_SUPPORT OFF CACHE BOOL "Platform supports SLIH IRQ tests") -set(PLATFORM_FLIH_IRQ_TEST_SUPPORT OFF CACHE BOOL "Platform supports FLIH IRQ tests") - From 4009673092f5213f8c4a820085db2d0e0bb5620b Mon Sep 17 00:00:00 2001 From: Sherry Zhang Date: Wed, 15 Feb 2023 11:07:42 +0800 Subject: [PATCH 08/22] Test: Fix build time error in MCUboot tests Signed-off-by: Sherry Zhang Change-Id: I632140e1ac33da468d1e89601803b96744070c52 --- .../suites/integration/mcuboot_integration_tests.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/bl2/mcuboot/suites/integration/mcuboot_integration_tests.c b/test/bl2/mcuboot/suites/integration/mcuboot_integration_tests.c index 603c8b3..da11fdd 100644 --- a/test/bl2/mcuboot/suites/integration/mcuboot_integration_tests.c +++ b/test/bl2/mcuboot/suites/integration/mcuboot_integration_tests.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022, Arm Limited. All rights reserved. + * Copyright (c) 2021-2023, Arm Limited. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * @@ -239,14 +239,14 @@ static void tfm_mcuboot_integration_test_0001(struct test_result_t *ret) return; } + test_image_idx = (original_image_idx + 1) % 2; + rc = read_image_header(original_image_idx, &hdr); if (rc) { TEST_FAIL("Failed to read image header"); goto out; } - test_image_idx = (original_image_idx + 1) % 2; - /* Increasing the version both causes the image to boot preferentially and * also invalidates the signature */ @@ -258,7 +258,7 @@ static void tfm_mcuboot_integration_test_0001(struct test_result_t *ret) goto out; } - rc = fih_int_decode(boot_go(&rsp)); + (void)boot_go(&rsp); if (memcmp(rsp.br_hdr, &hdr, sizeof(struct image_header)) == 0) { TEST_FAIL("Invalid image boot succeeded"); goto out; From 75ee82ba64f65526eac5ba1efdcf0c6895a25229 Mon Sep 17 00:00:00 2001 From: BohdanHunko Date: Fri, 3 Feb 2023 14:47:01 +0200 Subject: [PATCH 09/22] Interface: Move tfm_ns_interface_dispatch() to TF-M repo This patch moves implementation of tfm_ns_interface_dispatch to TF-M repo. This is needed to simplify TF-M integration with NS application. For more details refer to "Default implementation of tfm_ns_interface_dispatch()" mailing thread: https://lists.trustedfirmware.org/archives/list/tf-m@lists.trustedfirmware.org/message/ZCBRUODVTBK26JGAZKKIJEQ62D3XIMSO/ and TF-M tech forum presentation "Default implemeation of tsm_ns_interface_dispatch": https://www.trustedfirmware.org/meetings/tf-m-technical-forum/ Following things are done: * tfm_ns_interface.c was moved from test repo to TF-M repo tfm_ns_interface_rtos.c file * required NS OS wrapper header files are moved from test to TFM repo * updated Cmake files and include paths to be aligned with new committed structure Signed-off-by: Bohdan Hunko Signed-off-by: Chris Brand Change-Id: I95e82bfe3ff8b485b4017c519e998620f7bcbeb2 --- app/CMakeLists.txt | 6 +-- app/tfm_ns_interface.c | 46 --------------------- ns_interface/os_wrapper/common.h | 26 ------------ ns_interface/os_wrapper/delay.h | 4 +- ns_interface/os_wrapper/msg_queue.h | 4 +- ns_interface/os_wrapper/mutex.h | 62 ----------------------------- ns_interface/os_wrapper/semaphore.h | 4 +- ns_interface/os_wrapper/thread.h | 4 +- ns_interface/os_wrapper/tick.h | 4 +- 9 files changed, 18 insertions(+), 142 deletions(-) delete mode 100644 app/tfm_ns_interface.c delete mode 100644 ns_interface/os_wrapper/common.h delete mode 100644 ns_interface/os_wrapper/mutex.h diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 97fd3c5..19ccca7 100755 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------- # Copyright (c) 2020-2022, Arm Limited. All rights reserved. -# Copyright (c) 2022 Cypress Semiconductor Corporation (an Infineon company) +# Copyright (c) 2022-2023 Cypress Semiconductor Corporation (an Infineon company) # or an affiliate of Cypress Semiconductor Corporation. All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause @@ -115,8 +115,8 @@ endif() target_sources(tfm_api_ns PRIVATE $<$:${INTERFACE_SRC_DIR}/tfm_psa_ns_api.c> - # NS specific implementation of NS interface dispacther - $<$:${CMAKE_CURRENT_SOURCE_DIR}/tfm_ns_interface.c> + # NS specific implementation of NS interface dispatcher + $<$:${INTERFACE_SRC_DIR}/os_wrapper/tfm_ns_interface_rtos.c> ) target_link_libraries(tfm_api_ns diff --git a/app/tfm_ns_interface.c b/app/tfm_ns_interface.c deleted file mode 100644 index 3bd401b..0000000 --- a/app/tfm_ns_interface.c +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2017-2021, Arm Limited. All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - * - */ -#include - -#include "os_wrapper/mutex.h" - -#include "tfm_ns_interface.h" - -/** - * \brief the ns_lock ID - */ -static void *ns_lock_handle = NULL; - -int32_t tfm_ns_interface_dispatch(veneer_fn fn, - uint32_t arg0, uint32_t arg1, - uint32_t arg2, uint32_t arg3) -{ - int32_t result; - - /* TFM request protected by NS lock */ - while (os_wrapper_mutex_acquire(ns_lock_handle, OS_WRAPPER_WAIT_FOREVER) - != OS_WRAPPER_SUCCESS); - - result = fn(arg0, arg1, arg2, arg3); - - while (os_wrapper_mutex_release(ns_lock_handle) != OS_WRAPPER_SUCCESS); - - return result; -} - -uint32_t tfm_ns_interface_init(void) -{ - void *handle; - - handle = os_wrapper_mutex_create(); - if (!handle) { - return OS_WRAPPER_ERROR; - } - - ns_lock_handle = handle; - return OS_WRAPPER_SUCCESS; -} diff --git a/ns_interface/os_wrapper/common.h b/ns_interface/os_wrapper/common.h deleted file mode 100644 index 6494723..0000000 --- a/ns_interface/os_wrapper/common.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2017-2019, Arm Limited. All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - * - */ - -#ifndef __OS_WRAPPER_COMMON_H__ -#define __OS_WRAPPER_COMMON_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define OS_WRAPPER_SUCCESS (0x0) -#define OS_WRAPPER_ERROR (0xFFFFFFFFU) -#define OS_WRAPPER_WAIT_FOREVER (0xFFFFFFFFU) -#define OS_WRAPPER_DEFAULT_STACK_SIZE (-1) - -#ifdef __cplusplus -} -#endif - -#endif /* __OS_WRAPPER_COMMON_H__ */ diff --git a/ns_interface/os_wrapper/delay.h b/ns_interface/os_wrapper/delay.h index 4242b81..7e73459 100644 --- a/ns_interface/os_wrapper/delay.h +++ b/ns_interface/os_wrapper/delay.h @@ -1,5 +1,7 @@ /* * Copyright (c) 2022, Arm Limited. All rights reserved. + * Copyright (c) 2023 Cypress Semiconductor Corporation (an Infineon company) + * or an affiliate of Cypress Semiconductor Corporation. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * @@ -12,7 +14,7 @@ extern "C" { #endif -#include "common.h" +#include "os_wrapper/common.h" /** * \brief Waits for a time period specified in kernel ticks. diff --git a/ns_interface/os_wrapper/msg_queue.h b/ns_interface/os_wrapper/msg_queue.h index ac69773..4c9e362 100644 --- a/ns_interface/os_wrapper/msg_queue.h +++ b/ns_interface/os_wrapper/msg_queue.h @@ -1,5 +1,7 @@ /* * Copyright (c) 2020-2021, Arm Limited. All rights reserved. + * Copyright (c) 2023 Cypress Semiconductor Corporation (an Infineon company) + * or an affiliate of Cypress Semiconductor Corporation. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * @@ -14,7 +16,7 @@ extern "C" { #include -#include "common.h" +#include "os_wrapper/common.h" /** * \brief Create and initialize a message queue diff --git a/ns_interface/os_wrapper/mutex.h b/ns_interface/os_wrapper/mutex.h deleted file mode 100644 index e55ef70..0000000 --- a/ns_interface/os_wrapper/mutex.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2017-2019, Arm Limited. All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - * - */ - -#ifndef __OS_WRAPPER_MUTEX_H__ -#define __OS_WRAPPER_MUTEX_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "common.h" - -/** - * \brief Creates a mutex for mutual exclusion of resources - * - * \return The handle of the created mutex on success or NULL on error - */ -void *os_wrapper_mutex_create(void); - -/** - * \brief Acquires a mutex that is created by \ref os_wrapper_mutex_create() - * - * \param[in] handle The handle of the mutex to acquire. Should be one of the - * handles returned by \ref os_wrapper_mutex_create() - * \param[in] timeout The maximum amount of time(in tick periods) for the - * thread to wait for the mutex to be available. - * If timeout is zero, the function will return immediately. - * Setting timeout to \ref OS_WRAPPER_WAIT_FOREVER will - * cause the thread to wait indefinitely - * - * \return \ref OS_WRAPPER_SUCCESS on success or \ref OS_WRAPPER_ERROR on error - */ -uint32_t os_wrapper_mutex_acquire(void *handle, uint32_t timeout); - -/** - * \brief Releases the mutex acquired previously - * - - * \param[in] handle The handle of the mutex that has been acquired - * - * \return \ref OS_WRAPPER_SUCCESS on success or \ref OS_WRAPPER_ERROR on error - */ -uint32_t os_wrapper_mutex_release(void *handle); - -/** - * \brief Deletes a mutex that is created by \ref os_wrapper_mutex_create() - * - * \param[in] handle The handle of the mutex to be deleted - * - * \return \ref OS_WRAPPER_SUCCESS on success or \ref OS_WRAPPER_ERROR on error - */ -uint32_t os_wrapper_mutex_delete(void *handle); - -#ifdef __cplusplus -} -#endif - -#endif /* __OS_WRAPPER_MUTEX_H__ */ diff --git a/ns_interface/os_wrapper/semaphore.h b/ns_interface/os_wrapper/semaphore.h index 83d88ca..ce5aa04 100644 --- a/ns_interface/os_wrapper/semaphore.h +++ b/ns_interface/os_wrapper/semaphore.h @@ -1,5 +1,7 @@ /* * Copyright (c) 2017-2020, Arm Limited. All rights reserved. + * Copyright (c) 2023 Cypress Semiconductor Corporation (an Infineon company) + * or an affiliate of Cypress Semiconductor Corporation. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * @@ -12,7 +14,7 @@ extern "C" { #endif -#include "common.h" +#include "os_wrapper/common.h" /** * \brief Creates a new semaphore diff --git a/ns_interface/os_wrapper/thread.h b/ns_interface/os_wrapper/thread.h index a493593..83633a6 100644 --- a/ns_interface/os_wrapper/thread.h +++ b/ns_interface/os_wrapper/thread.h @@ -1,5 +1,7 @@ /* * Copyright (c) 2017-2020, Arm Limited. All rights reserved. + * Copyright (c) 2023 Cypress Semiconductor Corporation (an Infineon company) + * or an affiliate of Cypress Semiconductor Corporation. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * @@ -12,7 +14,7 @@ extern "C" { #endif -#include "common.h" +#include "os_wrapper/common.h" /* prototype for the thread entry function */ typedef void (*os_wrapper_thread_func) (void *argument); diff --git a/ns_interface/os_wrapper/tick.h b/ns_interface/os_wrapper/tick.h index b377b0e..de7d2f5 100644 --- a/ns_interface/os_wrapper/tick.h +++ b/ns_interface/os_wrapper/tick.h @@ -1,5 +1,7 @@ /* * Copyright (c) 2020, Arm Limited. All rights reserved. + * Copyright (c) 2023 Cypress Semiconductor Corporation (an Infineon company) + * or an affiliate of Cypress Semiconductor Corporation. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * @@ -12,7 +14,7 @@ extern "C" { #endif -#include "common.h" +#include "os_wrapper/common.h" /** * \brief Return RTOS current tick count From 153bd0904166841c148d5acb8aef6133cec5b91c Mon Sep 17 00:00:00 2001 From: David Hu Date: Wed, 1 Feb 2023 20:53:17 +0800 Subject: [PATCH 10/22] Build: Include config_tfm.h instead of config_.h Let regression test include config_tfm.h instead of config_.h. Aligned with TF-M changes of config header files. Signed-off-by: David Hu Change-Id: Icfdd55d6a1d3b5d84420547a188340f9a0e19c2f --- test/secure_fw/suites/attestation/attest_token_decode_common.c | 2 +- test/secure_fw/suites/attestation/attest_token_test_values.h | 2 +- .../suites/crypto/non_secure/crypto_ns_interface_testsuite.c | 2 +- .../suites/crypto/secure/crypto_sec_interface_testsuite.c | 2 +- test/secure_fw/suites/its/its_tests_common.c | 2 +- .../suites/ps/non_secure/psa_ps_ns_interface_testsuite.c | 2 +- test/secure_fw/suites/ps/secure/psa_ps_s_interface_testsuite.c | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/secure_fw/suites/attestation/attest_token_decode_common.c b/test/secure_fw/suites/attestation/attest_token_decode_common.c index 93f46c3..eacc5d8 100644 --- a/test/secure_fw/suites/attestation/attest_token_decode_common.c +++ b/test/secure_fw/suites/attestation/attest_token_decode_common.c @@ -13,7 +13,7 @@ #include "attest.h" #include "q_useful_buf.h" #include "qcbor_util.h" -#include "config_attest.h" +#include "config_tfm.h" /** * \file attest_token_decode_common.c diff --git a/test/secure_fw/suites/attestation/attest_token_test_values.h b/test/secure_fw/suites/attestation/attest_token_test_values.h index ae3c543..433b0c9 100644 --- a/test/secure_fw/suites/attestation/attest_token_test_values.h +++ b/test/secure_fw/suites/attestation/attest_token_test_values.h @@ -12,7 +12,7 @@ #ifndef __ATTEST_TOKEN_TEST_VALUES_H__ #define __ATTEST_TOKEN_TEST_VALUES_H__ -#include "config_attest.h" +#include "config_tfm.h" /** * \file attest_token_test_values.h diff --git a/test/secure_fw/suites/crypto/non_secure/crypto_ns_interface_testsuite.c b/test/secure_fw/suites/crypto/non_secure/crypto_ns_interface_testsuite.c index be2f5d8..0136c40 100644 --- a/test/secure_fw/suites/crypto/non_secure/crypto_ns_interface_testsuite.c +++ b/test/secure_fw/suites/crypto/non_secure/crypto_ns_interface_testsuite.c @@ -5,7 +5,7 @@ * */ -#include "config_crypto.h" +#include "config_tfm.h" #include "test_framework_helpers.h" #include "tfm_api.h" #include "../crypto_tests_common.h" diff --git a/test/secure_fw/suites/crypto/secure/crypto_sec_interface_testsuite.c b/test/secure_fw/suites/crypto/secure/crypto_sec_interface_testsuite.c index bdbd682..7d8ebd6 100644 --- a/test/secure_fw/suites/crypto/secure/crypto_sec_interface_testsuite.c +++ b/test/secure_fw/suites/crypto/secure/crypto_sec_interface_testsuite.c @@ -5,7 +5,7 @@ * */ -#include "config_crypto.h" +#include "config_tfm.h" #include "test_framework_helpers.h" #include "tfm_secure_client_2_api.h" #include "tfm_api.h" diff --git a/test/secure_fw/suites/its/its_tests_common.c b/test/secure_fw/suites/its/its_tests_common.c index a4d55c2..5ca2fdb 100644 --- a/test/secure_fw/suites/its/its_tests_common.c +++ b/test/secure_fw/suites/its/its_tests_common.c @@ -5,7 +5,7 @@ * */ -#include "config_its.h" +#include "config_tfm.h" #include "its_tests_common.h" #include "psa/internal_trusted_storage.h" #include diff --git a/test/secure_fw/suites/ps/non_secure/psa_ps_ns_interface_testsuite.c b/test/secure_fw/suites/ps/non_secure/psa_ps_ns_interface_testsuite.c index 6592b88..4e8b9d1 100644 --- a/test/secure_fw/suites/ps/non_secure/psa_ps_ns_interface_testsuite.c +++ b/test/secure_fw/suites/ps/non_secure/psa_ps_ns_interface_testsuite.c @@ -10,7 +10,7 @@ #include #include -#include "config_ps.h" +#include "config_tfm.h" #include "ns_test_helpers.h" #include "psa/protected_storage.h" #include "test_framework_helpers.h" diff --git a/test/secure_fw/suites/ps/secure/psa_ps_s_interface_testsuite.c b/test/secure_fw/suites/ps/secure/psa_ps_s_interface_testsuite.c index 0edb18c..db912b4 100644 --- a/test/secure_fw/suites/ps/secure/psa_ps_s_interface_testsuite.c +++ b/test/secure_fw/suites/ps/secure/psa_ps_s_interface_testsuite.c @@ -10,7 +10,7 @@ #include #include -#include "config_ps.h" +#include "config_tfm.h" #include "s_test_helpers.h" #include "psa/protected_storage.h" #include "test_framework_helpers.h" From 0c6ab341a864fe5b21a5ee73c96ccdfb0d3870df Mon Sep 17 00:00:00 2001 From: Summer Qin Date: Mon, 12 Dec 2022 15:59:10 +0800 Subject: [PATCH 11/22] Test: Add fetch eRPC remote library Add fetch eRPC remote library. eRPC is integrated with tf-m tests. Signed-off-by: Summer Qin Change-Id: Iad79d5169e3345b52deb79ea2855c29453297db2 --- CMakeLists.txt | 4 +++- lib/ext/CMakeLists.txt | 10 ++++++++++ lib/ext/erpc/CMakeLists.txt | 21 +++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 lib/ext/CMakeLists.txt create mode 100644 lib/ext/erpc/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index ecfd432..0f09d25 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------- -# Copyright (c) 2021-2022, Arm Limited. All rights reserved. +# Copyright (c) 2021-2023, Arm Limited. All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause # @@ -7,6 +7,8 @@ add_subdirectory(log) +add_subdirectory(lib/ext) + if(NS) add_subdirectory(app) endif() diff --git a/lib/ext/CMakeLists.txt b/lib/ext/CMakeLists.txt new file mode 100644 index 0000000..eb53c97 --- /dev/null +++ b/lib/ext/CMakeLists.txt @@ -0,0 +1,10 @@ +#------------------------------------------------------------------------------- +# Copyright (c) 2023, Arm Limited. All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause +# +#------------------------------------------------------------------------------- + +if(CONFIG_TFM_ERPC_TEST_FRAMEWORK) + add_subdirectory(erpc) +endif() diff --git a/lib/ext/erpc/CMakeLists.txt b/lib/ext/erpc/CMakeLists.txt new file mode 100644 index 0000000..66071f9 --- /dev/null +++ b/lib/ext/erpc/CMakeLists.txt @@ -0,0 +1,21 @@ +#------------------------------------------------------------------------------- +# Copyright (c) 2023, Arm Limited. All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause +# +#------------------------------------------------------------------------------- + +set(ERPC_REPO_PATH "DOWNLOAD" CACHE PATH "Path to eRPC repo (or DOWNLOAD to fetch automatically") +set(ERPC_VERSION "1.9.1" CACHE STRING "The version of eRPC to use") + +fetch_remote_library( + LIB_NAME erpc + LIB_SOURCE_PATH_VAR ERPC_REPO_PATH + LIB_BASE_DIR "${CMAKE_BINARY_DIR}/lib/ext" + FETCH_CONTENT_ARGS + GIT_REPOSITORY https://github.com/EmbeddedRPC/erpc.git + GIT_TAG ${ERPC_VERSION} + GIT_SHALLOW TRUE + GIT_PROGRESS TRUE + GIT_SUBMODULES "" +) From 153f3df72f98ed9d9163dbc1262397a436be1ba6 Mon Sep 17 00:00:00 2001 From: Summer Qin Date: Thu, 17 Nov 2022 15:51:02 +0800 Subject: [PATCH 12/22] Test: Add integration of the eRPC system - PSA Client API IDL file - Client and server init and API wrappers - Example client application Signed-off-by: Kevin Peng Signed-off-by: Jamie Fox Signed-off-by: Summer Qin Change-Id: If6180fd3e596c9daabd31262fb10ae0a1583bc9b --- app/CMakeLists.txt | 16 +- app/erpc_app.c | 36 ++ erpc/client/CMakeLists.txt | 68 ++++ erpc/client/config/erpc_config.h | 212 ++++++++++ erpc/client/erpc_client_start.c | 18 + erpc/client/erpc_client_start.h | 28 ++ erpc/client/erpc_client_wrapper.c | 47 +++ .../generated_files/tfm_erpc_psa_client_api.h | 77 ++++ .../tfm_erpc_psa_client_api_client.cpp | 300 ++++++++++++++ .../tfm_erpc_psa_client_api_server.cpp | 367 ++++++++++++++++++ .../tfm_erpc_psa_client_api_server.h | 76 ++++ .../tfm_erpc_psa_connection_api.h | 74 ++++ .../tfm_erpc_psa_connection_api_client.cpp | 155 ++++++++ .../tfm_erpc_psa_connection_api_server.cpp | 179 +++++++++ .../tfm_erpc_psa_connection_api_server.h | 73 ++++ erpc/host_example/CMakeLists.txt | 57 +++ erpc/host_example/README.rst | 92 +++++ erpc/host_example/main.c | 35 ++ erpc/server/CMakeLists.txt | 64 +++ erpc/server/config/erpc_config.h | 212 ++++++++++ erpc/server/erpc_server_start.c | 28 ++ erpc/server/erpc_server_start.h | 28 ++ erpc/server/erpc_server_wrapper.c | 42 ++ erpc/tfm.erpc | 24 ++ 24 files changed, 2306 insertions(+), 2 deletions(-) create mode 100644 app/erpc_app.c create mode 100644 erpc/client/CMakeLists.txt create mode 100644 erpc/client/config/erpc_config.h create mode 100644 erpc/client/erpc_client_start.c create mode 100644 erpc/client/erpc_client_start.h create mode 100644 erpc/client/erpc_client_wrapper.c create mode 100644 erpc/generated_files/tfm_erpc_psa_client_api.h create mode 100644 erpc/generated_files/tfm_erpc_psa_client_api_client.cpp create mode 100644 erpc/generated_files/tfm_erpc_psa_client_api_server.cpp create mode 100644 erpc/generated_files/tfm_erpc_psa_client_api_server.h create mode 100644 erpc/generated_files/tfm_erpc_psa_connection_api.h create mode 100644 erpc/generated_files/tfm_erpc_psa_connection_api_client.cpp create mode 100644 erpc/generated_files/tfm_erpc_psa_connection_api_server.cpp create mode 100644 erpc/generated_files/tfm_erpc_psa_connection_api_server.h create mode 100644 erpc/host_example/CMakeLists.txt create mode 100644 erpc/host_example/README.rst create mode 100644 erpc/host_example/main.c create mode 100644 erpc/server/CMakeLists.txt create mode 100644 erpc/server/config/erpc_config.h create mode 100644 erpc/server/erpc_server_start.c create mode 100644 erpc/server/erpc_server_start.h create mode 100644 erpc/server/erpc_server_wrapper.c create mode 100644 erpc/tfm.erpc diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 19ccca7..449cbc5 100755 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------- -# Copyright (c) 2020-2022, Arm Limited. All rights reserved. +# Copyright (c) 2020-2023, Arm Limited. All rights reserved. # Copyright (c) 2022-2023 Cypress Semiconductor Corporation (an Infineon company) # or an affiliate of Cypress Semiconductor Corporation. All rights reserved. # @@ -250,16 +250,27 @@ endif() ############################# Test integration ################################# +if (CONFIG_TFM_ERPC_TEST_FRAMEWORK) + set(CONFIG_ENABLE_NS_UART_TX_RX_CONTROL ON CACHE BOOL "Whether to enable UART TX RX") + set(ERPC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../erpc) + add_subdirectory(${ERPC_DIR}/server ${CMAKE_CURRENT_BINARY_DIR}/erpc/server) +endif() + add_library(tfm_test_app STATIC EXCLUDE_FROM_ALL) target_sources(tfm_test_app PRIVATE - test_app.c + $<$>:test_app.c> + $<$:erpc_app.c> + $<$:${ERPC_REPO_PATH}/erpc_c/setup/erpc_setup_uart_cmsis.cpp> + $<$:${ERPC_REPO_PATH}/erpc_c/transports/erpc_uart_cmsis_transport.cpp> ) target_include_directories(tfm_test_app PUBLIC . + $<$:${ERPC_DIR}/server> + $<$:${ERPC_REPO_PATH}/erpc_c/transports> ) target_link_libraries(tfm_test_app @@ -268,6 +279,7 @@ target_link_libraries(tfm_test_app $<$:val_nspe> $<$:pal_nspe> $<$:test_combine> + $<$:erpc_server> tfm_api_ns tfm_log ) diff --git a/app/erpc_app.c b/app/erpc_app.c new file mode 100644 index 0000000..af87f94 --- /dev/null +++ b/app/erpc_app.c @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2017-2023, Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + * + */ + +#include "test_app.h" +#include "tfm_log.h" +#include "erpc_server_start.h" +#include "target_cfg.h" + +#include "Driver_USART.h" +#ifdef ERPC_UART +extern ARM_DRIVER_USART ERPC_UART; +#else +#error "ERPC_UART is not provided!" +#endif + +__attribute__((noreturn)) +void test_app(void *argument) +{ + UNUSED_VARIABLE(argument); + + erpc_transport_t transport; + + transport = erpc_transport_cmsis_uart_init((void *)&ERPC_UART); + if (!transport) { + LOG_MSG("eRPC transport init failed!\r\n"); + } + + erpc_server_start(transport); + + for (;;) { + } +} diff --git a/erpc/client/CMakeLists.txt b/erpc/client/CMakeLists.txt new file mode 100644 index 0000000..61a561d --- /dev/null +++ b/erpc/client/CMakeLists.txt @@ -0,0 +1,68 @@ +#------------------------------------------------------------------------------- +# Copyright (c) 2023, Arm Limited. All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause +# +#------------------------------------------------------------------------------- + +cmake_minimum_required(VERSION 3.15) + +if (NOT DEFINED TFM_INSTALL_PATH) + if (DEFINED ENV{TFM_INSTALL_PATH}) + set(TFM_INSTALL_PATH $ENV{TFM_INSTALL_PATH}) + else() + message(FATAL_ERROR "TFM_INSTALL_PATH not found. Please set TFM_INSTALL_PATH environment variable or pass -DTFM_INSTALL_PATH flag.") + endif() +endif() + +if (NOT DEFINED ERPC_REPO_PATH) + if (DEFINED ENV{ERPC_REPO_PATH}) + set(ERPC_REPO_PATH $ENV{ERPC_REPO_PATH}) + else() + message(FATAL_ERROR "ERPC_REPO_PATH not found. Please set ERPC_REPO_PATH environment variable or pass -DERPC_REPO_PATH flag.") + endif() +endif() + +# Set eRPC config file. Need to provide config file with an absolute path. +if (ERPC_CONFIG_FILE) + if (NOT EXISTS ${ERPC_CONFIG_FILE}) + message(FATAL_ERROR "ERPC_CONFIG_FILE does not exist. Please provide it with an absolute path.") + endif() + # Get the path of the customized eRPC config file + get_filename_component(ERPC_CONFIG_FILE_PATH ${ERPC_CONFIG_FILE} DIRECTORY) +else() + # Use default one + set(ERPC_CONFIG_FILE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/config") +endif() + +add_library(erpc_client STATIC) + +target_sources(erpc_client + PRIVATE + erpc_client_wrapper.c + erpc_client_start.c + # eRPC files + ${ERPC_REPO_PATH}/erpc_c/infra/erpc_basic_codec.cpp + ${ERPC_REPO_PATH}/erpc_c/infra/erpc_client_manager.cpp + ${ERPC_REPO_PATH}/erpc_c/infra/erpc_crc16.cpp + ${ERPC_REPO_PATH}/erpc_c/infra/erpc_framed_transport.cpp + ${ERPC_REPO_PATH}/erpc_c/infra/erpc_message_buffer.cpp + ${ERPC_REPO_PATH}/erpc_c/port/erpc_serial.cpp + ${ERPC_REPO_PATH}/erpc_c/setup/erpc_client_setup.cpp + ${ERPC_REPO_PATH}/erpc_c/setup/erpc_setup_mbf_dynamic.cpp + # Generated files + ${CMAKE_CURRENT_SOURCE_DIR}/../generated_files/tfm_erpc_psa_client_api_client.cpp + $<$:${CMAKE_CURRENT_SOURCE_DIR}/../generated_files/tfm_erpc_psa_connection_api_client.cpp> +) + +target_include_directories(erpc_client + PUBLIC + ${ERPC_REPO_PATH}/erpc_c/port + ${ERPC_REPO_PATH}/erpc_c/infra + ${ERPC_REPO_PATH}/erpc_c/transports + ${ERPC_REPO_PATH}/erpc_c/setup + ${CMAKE_CURRENT_SOURCE_DIR}/ + ${CMAKE_CURRENT_SOURCE_DIR}/../generated_files + ${TFM_INSTALL_PATH}/interface/include + ${ERPC_CONFIG_FILE_PATH}/ +) diff --git a/erpc/client/config/erpc_config.h b/erpc/client/config/erpc_config.h new file mode 100644 index 0000000..11aada4 --- /dev/null +++ b/erpc/client/config/erpc_config.h @@ -0,0 +1,212 @@ +/* + * Copyright (c) 2016, Freescale Semiconductor, Inc. + * Copyright 2016-2020 NXP + * Copyright 2020-2021 ACRIOS Systems s.r.o. + * Copyright (c) 2023, Arm Limited. All rights reserved. + * All rights reserved. + * + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _ERPC_CONFIG_H_ +#define _ERPC_CONFIG_H_ + +/*! + * @addtogroup config + * @{ + * @file + */ + +//////////////////////////////////////////////////////////////////////////////// +// Declarations +//////////////////////////////////////////////////////////////////////////////// + +//! @name Threading model options +//@{ +#define ERPC_ALLOCATION_POLICY_DYNAMIC (0U) //!< Dynamic allocation policy +#define ERPC_ALLOCATION_POLICY_STATIC (1U) //!< Static allocation policy + +#define ERPC_THREADS_NONE (0U) //!< No threads. +#define ERPC_THREADS_PTHREADS (1U) //!< POSIX pthreads. +#define ERPC_THREADS_FREERTOS (2U) //!< FreeRTOS. +#define ERPC_THREADS_ZEPHYR (3U) //!< ZEPHYR. +#define ERPC_THREADS_MBED (4U) //!< Mbed OS +#define ERPC_THREADS_WIN32 (5U) //!< WIN32 +#define ERPC_THREADS_THREADX (6U) //!< THREADX + +#define ERPC_NOEXCEPT_DISABLED (0U) //!< Disabling noexcept feature. +#define ERPC_NOEXCEPT_ENABLED (1U) //!< Enabling noexcept feature. + +#define ERPC_NESTED_CALLS_DISABLED (0U) //!< No nested calls support. +#define ERPC_NESTED_CALLS_ENABLED (1U) //!< Nested calls support. + +#define ERPC_NESTED_CALLS_DETECTION_DISABLED (0U) //!< Nested calls detection disabled. +#define ERPC_NESTED_CALLS_DETECTION_ENABLED (1U) //!< Nested calls detection enabled. + +#define ERPC_MESSAGE_LOGGING_DISABLED (0U) //!< Trace functions disabled. +#define ERPC_MESSAGE_LOGGING_ENABLED (1U) //!< Trace functions enabled. + +#define ERPC_TRANSPORT_MU_USE_MCMGR_DISABLED (0U) //!< Do not use MCMGR for MU ISR management. +#define ERPC_TRANSPORT_MU_USE_MCMGR_ENABLED (1U) //!< Use MCMGR for MU ISR management. + +#define ERPC_PRE_POST_ACTION_DISABLED (0U) //!< Pre post shim callbacks functions disabled. +#define ERPC_PRE_POST_ACTION_ENABLED (1U) //!< Pre post shim callback functions enabled. + +#define ERPC_PRE_POST_ACTION_DEFAULT_DISABLED (0U) //!< Pre post shim default callbacks functions disabled. +#define ERPC_PRE_POST_ACTION_DEFAULT_ENABLED (1U) //!< Pre post shim default callback functions enabled. +//@} + +//! @name Configuration options +//@{ + +//! @def ERPC_ALLOCATION_POLICY +//! +//! @brief Choose which allocation policy should be used. +//! +//! Set ERPC_ALLOCATION_POLICY_DYNAMIC if dynamic allocations should be used. +//! Set ERPC_ALLOCATION_POLICY_STATIC if static allocations should be used. +//! +//! Default value is ERPC_ALLOCATION_POLICY_DYNAMIC or in case of FreeRTOS it can be auto-detected if __has_include() is +//! supported by compiler. Uncomment comment bellow to use static allocation policy. In case of static implementation +//! user need consider another values to set (ERPC_CODEC_COUNT, ERPC_MESSAGE_LOGGERS_COUNT, +//! ERPC_CLIENTS_THREADS_AMOUNT). +// #define ERPC_ALLOCATION_POLICY (ERPC_ALLOCATION_POLICY_STATIC) + +//! @def ERPC_CODEC_COUNT +//! +//! @brief Set amount of codecs objects used simultaneously in case of ERPC_ALLOCATION_POLICY is set to +//! ERPC_ALLOCATION_POLICY_STATIC. For example if client or server is used in one thread then 1. If both are used in one +//! thread per each then 2, ... Default value 2. +// #define ERPC_CODEC_COUNT (2U) + +//! @def ERPC_MESSAGE_LOGGERS_COUNT +//! +//! @brief Set amount of message loggers objects used simultaneously in case of ERPC_ALLOCATION_POLICY is set to +//! ERPC_ALLOCATION_POLICY_STATIC. +//! For example if client or server is used in one thread then 1. If both are used in one thread per each then 2, ... +//! For arbitrated client 1 is enough. +//! Default value 0 (May not be used). +// #define ERPC_MESSAGE_LOGGERS_COUNT (0U) + +//! @def ERPC_CLIENTS_THREADS_AMOUNT +//! +//! @brief Set amount of client threads objects used in case of ERPC_ALLOCATION_POLICY is set to +//! ERPC_ALLOCATION_POLICY_STATIC. Default value 1 (Most of current cases). +// #define ERPC_CLIENTS_THREADS_AMOUNT (1U) + +//! @def ERPC_THREADS +//! +//! @brief Select threading model. +//! +//! Set to one of the @c ERPC_THREADS_x macros to specify the threading model used by eRPC. +//! +//! Leave commented out to attempt to auto-detect. Auto-detection works well for pthreads. +//! FreeRTOS can be detected when building with compilers that support __has_include(). +//! Otherwise, the default is no threading. +//#define ERPC_THREADS (ERPC_THREADS_PTHREADS) + +//! @def ERPC_DEFAULT_BUFFER_SIZE +//! +//! Uncomment to change the size of buffers allocated by one of MessageBufferFactory. +//! (@ref client_setup and @ref server_setup). The default size is set to 256. +//! For RPMsg transport layer, ERPC_DEFAULT_BUFFER_SIZE must be 2^n - 16. +//#define ERPC_DEFAULT_BUFFER_SIZE (256U) + +//! @def ERPC_DEFAULT_BUFFERS_COUNT +//! +//! Uncomment to change the count of buffers allocated by one of statically allocated messages. +//! Default value is set to 2. +//#define ERPC_DEFAULT_BUFFERS_COUNT (2U) + +//! @def ERPC_NOEXCEPT +//! +//! @brief Disable/enable noexcept support. +//! +//! Uncomment for using noexcept feature. +//#define ERPC_NOEXCEPT (ERPC_NOEXCEPT_ENABLED) + +//! @def ERPC_NESTED_CALLS +//! +//! Default set to ERPC_NESTED_CALLS_DISABLED. Uncomment when callbacks, or other eRPC +//! functions are called from server implementation of another eRPC call. Nested functions +//! need to be marked as @nested in IDL. +//#define ERPC_NESTED_CALLS (ERPC_NESTED_CALLS_ENABLED) + +//! @def ERPC_NESTED_CALLS_DETECTION +//! +//! Default set to ERPC_NESTED_CALLS_DETECTION_ENABLED when NDEBUG macro is presented. +//! This serve for locating nested calls in code. Nested calls are calls where inside eRPC function +//! on server side is called another eRPC function (like callbacks). Code need be a bit changed +//! to support nested calls. See ERPC_NESTED_CALLS macro. +//#define ERPC_NESTED_CALLS_DETECTION (ERPC_NESTED_CALLS_DETECTION_DISABLED) + +//! @def ERPC_MESSAGE_LOGGING +//! +//! Enable eRPC message logging code through the eRPC. Take look into "erpc_message_loggers.h". Can be used for base +//! printing messages, or sending data to another system for data analysis. Default set to +//! ERPC_MESSAGE_LOGGING_DISABLED. +//! +//! Uncomment for using logging feature. +//#define ERPC_MESSAGE_LOGGING (ERPC_MESSAGE_LOGGING_ENABLED) + +//! @def ERPC_TRANSPORT_MU_USE_MCMGR +//! +//! @brief MU transport layer configuration. +//! +//! Set to one of the @c ERPC_TRANSPORT_MU_USE_MCMGR_x macros to configure the MCMGR usage in MU transport layer. +//! +//! MU transport layer could leverage the Multicore Manager (MCMGR) component for Inter-Core +//! interrupts / MU interrupts management or the Inter-Core interrupts can be managed by itself (MUX_IRQHandler +//! overloading). By default, ERPC_TRANSPORT_MU_USE_MCMGR is set to ERPC_TRANSPORT_MU_USE_MCMGR_ENABLED when mcmgr.h +//! is part of the project, otherwise the ERPC_TRANSPORT_MU_USE_MCMGR_DISABLED option is used. This settings can be +//! overwritten from the erpc_config.h by uncommenting the ERPC_TRANSPORT_MU_USE_MCMGR macro definition. Do not forget +//! to add the MCMGR library into your project when ERPC_TRANSPORT_MU_USE_MCMGR_ENABLED option is used! See the +//! erpc_mu_transport.h for additional MU settings. +//#define ERPC_TRANSPORT_MU_USE_MCMGR ERPC_TRANSPORT_MU_USE_MCMGR_DISABLED +//@} + +//! @def ERPC_PRE_POST_ACTION +//! +//! Enable eRPC pre and post callback functions shim code. Take look into "erpc_pre_post_action.h". Can be used for +//! detection of eRPC call freeze, ... Default set to ERPC_PRE_POST_ACTION_DISABLED. +//! +//! Uncomment for using pre post callback feature. +//#define ERPC_PRE_POST_ACTION (ERPC_PRE_POST_ACTION_ENABLED) + +//! @def ERPC_PRE_POST_ACTION_DEFAULT +//! +//! Enable eRPC pre and post default callback functions. Take look into "erpc_setup_extensions.h". Can be used for +//! detection of eRPC call freeze, ... Default set to ERPC_PRE_POST_ACTION_DEFAULT_DISABLED. +//! +//! Uncomment for using pre post default callback feature. +//#define ERPC_PRE_POST_ACTION_DEFAULT (ERPC_PRE_POST_ACTION_DEFAULT_ENABLED) + +//! @name Assert function definition +//@{ +//! User custom asser defition. Include header file if needed before bellow line. If assert is not enabled, default will +//! be used. +// #define erpc_assert(condition) +//@} + +//! @def ENDIANES_HEADER +//! +//! Include header file that controls the communication endianness +//! +//! Uncomment for example behaviour for endianness agnostic with: +//! 1. communication in little endian. +//! 2. current processor is big endian. +//! 3. pointer size is 32 bit. +//! 4. float+double scheme not defined, so throws assert if passes. +//! #define ERPC_PROCESSOR_ENDIANNESS_LITTLE 0 +//! #define ERPC_COMMUNICATION_LITTLE 1 +//! #define ERPC_POINTER_SIZE_16 0 +//! #define ERPC_POINTER_SIZE_32 1 +//! #define ERPC_POINTER_SIZE_64 0 +//! #define ENDIANNESS_HEADER "erpc_endianness_agnostic_example.h" + +/*! @} */ +#endif // _ERPC_CONFIG_H_ +//////////////////////////////////////////////////////////////////////////////// +// EOF +//////////////////////////////////////////////////////////////////////////////// diff --git a/erpc/client/erpc_client_start.c b/erpc/client/erpc_client_start.c new file mode 100644 index 0000000..f66b73b --- /dev/null +++ b/erpc/client/erpc_client_start.c @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023, Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + * + */ + +#include "erpc_mbf_setup.h" +#include "erpc_client_setup.h" +#include "erpc_client_start.h" + +void erpc_client_start(erpc_transport_t transport) +{ + erpc_mbf_t message_buffer_factory; + + message_buffer_factory = erpc_mbf_dynamic_init(); + erpc_client_init(transport, message_buffer_factory); +} diff --git a/erpc/client/erpc_client_start.h b/erpc/client/erpc_client_start.h new file mode 100644 index 0000000..37c056a --- /dev/null +++ b/erpc/client/erpc_client_start.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023, Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + * + */ + +#ifndef __ERPC_CLIENT_START_H__ +#define __ERPC_CLIENT_START_H__ + +#include "erpc_transport_setup.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * \brief eRPC Client initialization. + * + * \param[in] transport Transport to use. + */ +void erpc_client_start(erpc_transport_t transport); + +#ifdef __cplusplus +} +#endif + +#endif /* __ERPC_CLIENT_START_H__ */ diff --git a/erpc/client/erpc_client_wrapper.c b/erpc/client/erpc_client_wrapper.c new file mode 100644 index 0000000..37b5f82 --- /dev/null +++ b/erpc/client/erpc_client_wrapper.c @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023, Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + * + */ + +#include +#include "psa/client.h" +#include "tfm_erpc_psa_client_api.h" + +psa_status_t psa_call(psa_handle_t handle, int32_t type, + const psa_invec *in_vec, size_t in_len, + psa_outvec *out_vec, size_t out_len) +{ + psa_status_t status; + size_t i; + binary_t in_elements[PSA_MAX_IOVEC]; + binary_t out_elements[PSA_MAX_IOVEC]; + list_binary_1_t erpc_in_vec = {in_elements, in_len}; + list_binary_1_t erpc_out_vec = {out_elements, out_len}; + + if (in_len + out_len > PSA_MAX_IOVEC) { + return PSA_ERROR_PROGRAMMER_ERROR; + } + + /* Copy PSA iovecs into RPC binary lists */ + for (i = 0; i < in_len; ++i) { + in_elements[i] = (binary_t){(void *)in_vec[i].base, in_vec[i].len}; + } + for (i = 0; i < out_len; ++i) { + out_elements[i] = (binary_t){out_vec[i].base, out_vec[i].len}; + } + + status = erpc_psa_call(handle, type, &erpc_in_vec, &erpc_out_vec); + + if (status != PSA_SUCCESS) { + return status; + } + + /* Copy updated out length into PSA outvec */ + for (i = 0; i < out_len; ++i) { + out_vec[i].len = out_elements[i].dataLength; + } + + return status; +} diff --git a/erpc/generated_files/tfm_erpc_psa_client_api.h b/erpc/generated_files/tfm_erpc_psa_client_api.h new file mode 100644 index 0000000..6b6760e --- /dev/null +++ b/erpc/generated_files/tfm_erpc_psa_client_api.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2022, Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + * + */ + +/* + * Generated by erpcgen 1.9.1 on Fri Dec 16 14:51:11 2022. + * + * AUTOGENERATED - DO NOT EDIT + */ + + +#if !defined(_tfm_erpc_psa_client_api_h_) +#define _tfm_erpc_psa_client_api_h_ + +#include +#include +#include +#include "erpc_version.h" +#include "psa/client.h" + +#if 10901 != ERPC_VERSION_NUMBER +#error "The generated shim code version is different to the rest of eRPC code." +#endif + +#if !defined(ERPC_TYPE_DEFINITIONS) +#define ERPC_TYPE_DEFINITIONS + +// Aliases data types declarations +typedef struct list_binary_1_t list_binary_1_t; +typedef struct binary_t binary_t; + +// Structures/unions data types declarations +struct list_binary_1_t +{ + binary_t * elements; + uint32_t elementsCount; +}; + +struct binary_t +{ + uint8_t * data; + uint32_t dataLength; +}; + + +#endif // ERPC_TYPE_DEFINITIONS + +/*! @brief psa_client_api identifiers */ +enum _psa_client_api_ids +{ + kpsa_client_api_service_id = 1, + kpsa_client_api_psa_framework_version_id = 1, + kpsa_client_api_psa_version_id = 2, + kpsa_client_api_erpc_psa_call_id = 3, +}; + +#if defined(__cplusplus) +extern "C" { +#endif + +//! @name psa_client_api +//@{ +uint32_t psa_framework_version(void); + +uint32_t psa_version(uint32_t sid); + +psa_status_t erpc_psa_call(psa_handle_t handle, int32_t t, const list_binary_1_t * erpc_in_vec, list_binary_1_t * erpc_out_vec); +//@} + +#if defined(__cplusplus) +} +#endif + +#endif // _tfm_erpc_psa_client_api_h_ diff --git a/erpc/generated_files/tfm_erpc_psa_client_api_client.cpp b/erpc/generated_files/tfm_erpc_psa_client_api_client.cpp new file mode 100644 index 0000000..fa7dee9 --- /dev/null +++ b/erpc/generated_files/tfm_erpc_psa_client_api_client.cpp @@ -0,0 +1,300 @@ +/* + * Copyright (c) 2022, Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + * + */ + +/* + * Generated by erpcgen 1.9.1 on Fri Dec 16 14:51:11 2022. + * + * AUTOGENERATED - DO NOT EDIT + */ + + +#include "erpc_client_manager.h" +#if ERPC_ALLOCATION_POLICY == ERPC_ALLOCATION_POLICY_DYNAMIC +#include "erpc_port.h" +#endif +#include "erpc_codec.h" +extern "C" +{ +#include "tfm_erpc_psa_client_api.h" +// import callbacks declaration from other groups +#include "tfm_erpc_psa_connection_api.h" +} + +#if 10901 != ERPC_VERSION_NUMBER +#error "The generated shim code version is different to the rest of eRPC code." +#endif + +using namespace erpc; +using namespace std; + +extern ClientManager *g_client; + +//! @brief Function to write struct binary_t +static void write_binary_t_struct(erpc::Codec * codec, const binary_t * data); + +//! @brief Function to write struct list_binary_1_t +static void write_list_binary_1_t_struct(erpc::Codec * codec, const list_binary_1_t * data); + + +// Write struct binary_t function implementation +static void write_binary_t_struct(erpc::Codec * codec, const binary_t * data) +{ + if(NULL == data) + { + return; + } + + codec->writeBinary(data->dataLength, data->data); +} + +// Write struct list_binary_1_t function implementation +static void write_list_binary_1_t_struct(erpc::Codec * codec, const list_binary_1_t * data) +{ + if(NULL == data) + { + return; + } + + codec->startWriteList(data->elementsCount); + for (uint32_t listCount = 0U; listCount < data->elementsCount; ++listCount) + { + write_binary_t_struct(codec, &(data->elements[listCount])); + } +} + + +//! @brief Function to read struct binary_t +static void read_binary_t_struct(erpc::Codec * codec, binary_t * data); + +//! @brief Function to read struct list_binary_1_t +static void read_list_binary_1_t_struct(erpc::Codec * codec, list_binary_1_t * data); + + +// Read struct binary_t function implementation +static void read_binary_t_struct(erpc::Codec * codec, binary_t * data) +{ + if(NULL == data) + { + return; + } + + uint8_t * data_local; + codec->readBinary(&data->dataLength, &data_local); + memcpy(data->data, data_local, data->dataLength); +} + +// Read struct list_binary_1_t function implementation +static void read_list_binary_1_t_struct(erpc::Codec * codec, list_binary_1_t * data) +{ + if(NULL == data) + { + return; + } + + codec->startReadList(&data->elementsCount); + for (uint32_t listCount = 0U; listCount < data->elementsCount; ++listCount) + { + read_binary_t_struct(codec, &(data->elements[listCount])); + } +} + + + +// psa_client_api interface psa_framework_version function client shim. +uint32_t psa_framework_version(void) +{ + erpc_status_t err = kErpcStatus_Success; + + uint32_t result; + +#if ERPC_PRE_POST_ACTION + pre_post_action_cb preCB = g_client->getPreCB(); + if (preCB) + { + preCB(); + } +#endif + + // Get a new request. + RequestContext request = g_client->createRequest(false); + + // Encode the request. + Codec * codec = request.getCodec(); + + if (codec == NULL) + { + err = kErpcStatus_MemoryError; + } + else + { + codec->startWriteMessage(kInvocationMessage, kpsa_client_api_service_id, kpsa_client_api_psa_framework_version_id, request.getSequence()); + + // Send message to server + // Codec status is checked inside this function. + g_client->performRequest(request); + + codec->read(&result); + + err = codec->getStatus(); + } + + // Dispose of the request. + g_client->releaseRequest(request); + + // Invoke error handler callback function + g_client->callErrorHandler(err, kpsa_client_api_psa_framework_version_id); + +#if ERPC_PRE_POST_ACTION + pre_post_action_cb postCB = g_client->getPostCB(); + if (postCB) + { + postCB(); + } +#endif + + + if (err != kErpcStatus_Success) + { + result = 0xFFFFFFFFU; + } + + return result; +} + +// psa_client_api interface psa_version function client shim. +uint32_t psa_version(uint32_t sid) +{ + erpc_status_t err = kErpcStatus_Success; + + uint32_t result; + +#if ERPC_PRE_POST_ACTION + pre_post_action_cb preCB = g_client->getPreCB(); + if (preCB) + { + preCB(); + } +#endif + + // Get a new request. + RequestContext request = g_client->createRequest(false); + + // Encode the request. + Codec * codec = request.getCodec(); + + if (codec == NULL) + { + err = kErpcStatus_MemoryError; + } + else + { + codec->startWriteMessage(kInvocationMessage, kpsa_client_api_service_id, kpsa_client_api_psa_version_id, request.getSequence()); + + codec->write(sid); + + // Send message to server + // Codec status is checked inside this function. + g_client->performRequest(request); + + codec->read(&result); + + err = codec->getStatus(); + } + + // Dispose of the request. + g_client->releaseRequest(request); + + // Invoke error handler callback function + g_client->callErrorHandler(err, kpsa_client_api_psa_version_id); + +#if ERPC_PRE_POST_ACTION + pre_post_action_cb postCB = g_client->getPostCB(); + if (postCB) + { + postCB(); + } +#endif + + + if (err != kErpcStatus_Success) + { + result = 0xFFFFFFFFU; + } + + return result; +} + +// psa_client_api interface erpc_psa_call function client shim. +psa_status_t erpc_psa_call(psa_handle_t handle, int32_t t, const list_binary_1_t * erpc_in_vec, list_binary_1_t * erpc_out_vec) +{ + erpc_status_t err = kErpcStatus_Success; + + psa_status_t result; + +#if ERPC_PRE_POST_ACTION + pre_post_action_cb preCB = g_client->getPreCB(); + if (preCB) + { + preCB(); + } +#endif + + // Get a new request. + RequestContext request = g_client->createRequest(false); + + // Encode the request. + Codec * codec = request.getCodec(); + + if (codec == NULL) + { + err = kErpcStatus_MemoryError; + } + else + { + codec->startWriteMessage(kInvocationMessage, kpsa_client_api_service_id, kpsa_client_api_erpc_psa_call_id, request.getSequence()); + + codec->write(handle); + + codec->write(t); + + write_list_binary_1_t_struct(codec, erpc_in_vec); + + write_list_binary_1_t_struct(codec, erpc_out_vec); + + // Send message to server + // Codec status is checked inside this function. + g_client->performRequest(request); + + read_list_binary_1_t_struct(codec, erpc_out_vec); + + codec->read(&result); + + err = codec->getStatus(); + } + + // Dispose of the request. + g_client->releaseRequest(request); + + // Invoke error handler callback function + g_client->callErrorHandler(err, kpsa_client_api_erpc_psa_call_id); + +#if ERPC_PRE_POST_ACTION + pre_post_action_cb postCB = g_client->getPostCB(); + if (postCB) + { + postCB(); + } +#endif + + + if (err != kErpcStatus_Success) + { + result = -1; + } + + return result; +} diff --git a/erpc/generated_files/tfm_erpc_psa_client_api_server.cpp b/erpc/generated_files/tfm_erpc_psa_client_api_server.cpp new file mode 100644 index 0000000..82fb722 --- /dev/null +++ b/erpc/generated_files/tfm_erpc_psa_client_api_server.cpp @@ -0,0 +1,367 @@ +/* + * Copyright (c) 2022, Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + * + */ + +/* + * Generated by erpcgen 1.9.1 on Fri Dec 16 14:51:11 2022. + * + * AUTOGENERATED - DO NOT EDIT + */ + + +#include "tfm_erpc_psa_client_api_server.h" +#if ERPC_ALLOCATION_POLICY == ERPC_ALLOCATION_POLICY_DYNAMIC +#include +#include "erpc_port.h" +#endif +#include "erpc_manually_constructed.h" + +#if 10901 != ERPC_VERSION_NUMBER +#error "The generated shim code version is different to the rest of eRPC code." +#endif + +using namespace erpc; +using namespace std; + +#if ERPC_NESTED_CALLS_DETECTION +extern bool nestingDetection; +#endif + +ERPC_MANUALLY_CONSTRUCTED_STATIC(psa_client_api_service, s_psa_client_api_service); + + +//! @brief Function to read struct binary_t +static void read_binary_t_struct(erpc::Codec * codec, binary_t * data); + +//! @brief Function to read struct list_binary_1_t +static void read_list_binary_1_t_struct(erpc::Codec * codec, list_binary_1_t * data); + + +// Read struct binary_t function implementation +static void read_binary_t_struct(erpc::Codec * codec, binary_t * data) +{ + if(NULL == data) + { + return; + } + + uint8_t * data_local; + codec->readBinary(&data->dataLength, &data_local); + data->data = (uint8_t *) erpc_malloc(data->dataLength * sizeof(uint8_t)); + if ((data->data == NULL) && (data->dataLength > 0)) + { + codec->updateStatus(kErpcStatus_MemoryError); + } + else + { + memcpy(data->data, data_local, data->dataLength); + } +} + +// Read struct list_binary_1_t function implementation +static void read_list_binary_1_t_struct(erpc::Codec * codec, list_binary_1_t * data) +{ + if(NULL == data) + { + return; + } + + codec->startReadList(&data->elementsCount); + data->elements = (binary_t *) erpc_malloc(data->elementsCount * sizeof(binary_t)); + if ((data->elements == NULL) && (data->elementsCount > 0)) + { + codec->updateStatus(kErpcStatus_MemoryError); + } + for (uint32_t listCount = 0U; listCount < data->elementsCount; ++listCount) + { + read_binary_t_struct(codec, &(data->elements[listCount])); + } +} + + +//! @brief Function to write struct binary_t +static void write_binary_t_struct(erpc::Codec * codec, const binary_t * data); + +//! @brief Function to write struct list_binary_1_t +static void write_list_binary_1_t_struct(erpc::Codec * codec, const list_binary_1_t * data); + + +// Write struct binary_t function implementation +static void write_binary_t_struct(erpc::Codec * codec, const binary_t * data) +{ + if(NULL == data) + { + return; + } + + codec->writeBinary(data->dataLength, data->data); +} + +// Write struct list_binary_1_t function implementation +static void write_list_binary_1_t_struct(erpc::Codec * codec, const list_binary_1_t * data) +{ + if(NULL == data) + { + return; + } + + codec->startWriteList(data->elementsCount); + for (uint32_t listCount = 0U; listCount < data->elementsCount; ++listCount) + { + write_binary_t_struct(codec, &(data->elements[listCount])); + } +} + + +//! @brief Function to free space allocated inside struct binary_t +static void free_binary_t_struct(binary_t * data); + +//! @brief Function to free space allocated inside struct list_binary_1_t +static void free_list_binary_1_t_struct(list_binary_1_t * data); + + +// Free space allocated inside struct binary_t function implementation +static void free_binary_t_struct(binary_t * data) +{ + erpc_free(data->data); +} + +// Free space allocated inside struct list_binary_1_t function implementation +static void free_list_binary_1_t_struct(list_binary_1_t * data) +{ + for (uint32_t listCount = 0; listCount < data->elementsCount; ++listCount) + { + free_binary_t_struct(&data->elements[listCount]); + } + + erpc_free(data->elements); +} + + + +// Call the correct server shim based on method unique ID. +erpc_status_t psa_client_api_service::handleInvocation(uint32_t methodId, uint32_t sequence, Codec * codec, MessageBufferFactory *messageFactory) +{ + erpc_status_t erpcStatus; + switch (methodId) + { + case kpsa_client_api_psa_framework_version_id: + { + erpcStatus = psa_framework_version_shim(codec, messageFactory, sequence); + break; + } + + case kpsa_client_api_psa_version_id: + { + erpcStatus = psa_version_shim(codec, messageFactory, sequence); + break; + } + + case kpsa_client_api_erpc_psa_call_id: + { + erpcStatus = erpc_psa_call_shim(codec, messageFactory, sequence); + break; + } + + default: + { + erpcStatus = kErpcStatus_InvalidArgument; + break; + } + } + + return erpcStatus; +} + +// Server shim for psa_framework_version of psa_client_api interface. +erpc_status_t psa_client_api_service::psa_framework_version_shim(Codec * codec, MessageBufferFactory *messageFactory, uint32_t sequence) +{ + erpc_status_t err = kErpcStatus_Success; + + uint32_t result; + + // startReadMessage() was already called before this shim was invoked. + + err = codec->getStatus(); + if (err == kErpcStatus_Success) + { + // Invoke the actual served function. +#if ERPC_NESTED_CALLS_DETECTION + nestingDetection = true; +#endif + result = psa_framework_version(); +#if ERPC_NESTED_CALLS_DETECTION + nestingDetection = false; +#endif + + // preparing MessageBuffer for serializing data + err = messageFactory->prepareServerBufferForSend(codec->getBuffer()); + } + + if (err == kErpcStatus_Success) + { + // preparing codec for serializing data + codec->reset(); + + // Build response message. + codec->startWriteMessage(kReplyMessage, kpsa_client_api_service_id, kpsa_client_api_psa_framework_version_id, sequence); + + codec->write(result); + + err = codec->getStatus(); + } + + return err; +} + +// Server shim for psa_version of psa_client_api interface. +erpc_status_t psa_client_api_service::psa_version_shim(Codec * codec, MessageBufferFactory *messageFactory, uint32_t sequence) +{ + erpc_status_t err = kErpcStatus_Success; + + uint32_t sid; + uint32_t result; + + // startReadMessage() was already called before this shim was invoked. + + codec->read(&sid); + + err = codec->getStatus(); + if (err == kErpcStatus_Success) + { + // Invoke the actual served function. +#if ERPC_NESTED_CALLS_DETECTION + nestingDetection = true; +#endif + result = psa_version(sid); +#if ERPC_NESTED_CALLS_DETECTION + nestingDetection = false; +#endif + + // preparing MessageBuffer for serializing data + err = messageFactory->prepareServerBufferForSend(codec->getBuffer()); + } + + if (err == kErpcStatus_Success) + { + // preparing codec for serializing data + codec->reset(); + + // Build response message. + codec->startWriteMessage(kReplyMessage, kpsa_client_api_service_id, kpsa_client_api_psa_version_id, sequence); + + codec->write(result); + + err = codec->getStatus(); + } + + return err; +} + +// Server shim for erpc_psa_call of psa_client_api interface. +erpc_status_t psa_client_api_service::erpc_psa_call_shim(Codec * codec, MessageBufferFactory *messageFactory, uint32_t sequence) +{ + erpc_status_t err = kErpcStatus_Success; + + psa_handle_t handle; + int32_t t; + list_binary_1_t *erpc_in_vec = NULL; + erpc_in_vec = (list_binary_1_t *) erpc_malloc(sizeof(list_binary_1_t)); + if (erpc_in_vec == NULL) + { + codec->updateStatus(kErpcStatus_MemoryError); + } + list_binary_1_t *erpc_out_vec = NULL; + erpc_out_vec = (list_binary_1_t *) erpc_malloc(sizeof(list_binary_1_t)); + if (erpc_out_vec == NULL) + { + codec->updateStatus(kErpcStatus_MemoryError); + } + psa_status_t result; + + // startReadMessage() was already called before this shim was invoked. + + codec->read(&handle); + + codec->read(&t); + + read_list_binary_1_t_struct(codec, erpc_in_vec); + + read_list_binary_1_t_struct(codec, erpc_out_vec); + + err = codec->getStatus(); + if (err == kErpcStatus_Success) + { + // Invoke the actual served function. +#if ERPC_NESTED_CALLS_DETECTION + nestingDetection = true; +#endif + result = erpc_psa_call(handle, t, erpc_in_vec, erpc_out_vec); +#if ERPC_NESTED_CALLS_DETECTION + nestingDetection = false; +#endif + + // preparing MessageBuffer for serializing data + err = messageFactory->prepareServerBufferForSend(codec->getBuffer()); + } + + if (err == kErpcStatus_Success) + { + // preparing codec for serializing data + codec->reset(); + + // Build response message. + codec->startWriteMessage(kReplyMessage, kpsa_client_api_service_id, kpsa_client_api_erpc_psa_call_id, sequence); + + write_list_binary_1_t_struct(codec, erpc_out_vec); + + codec->write(result); + + err = codec->getStatus(); + } + + if (erpc_in_vec) + { + free_list_binary_1_t_struct(erpc_in_vec); + } + erpc_free(erpc_in_vec); + + if (erpc_out_vec) + { + free_list_binary_1_t_struct(erpc_out_vec); + } + erpc_free(erpc_out_vec); + + return err; +} + +#if ERPC_ALLOCATION_POLICY == ERPC_ALLOCATION_POLICY_DYNAMIC +erpc_service_t create_psa_client_api_service() +{ + return new (nothrow) psa_client_api_service(); +} + +void destroy_psa_client_api_service(erpc_service_t service) +{ + if (service) + { + delete (psa_client_api_service *)service; + } +} +#elif ERPC_ALLOCATION_POLICY == ERPC_ALLOCATION_POLICY_STATIC +erpc_service_t create_psa_client_api_service() +{ + s_psa_client_api_service.construct(); + return s_psa_client_api_service.get(); +} + +void destroy_psa_client_api_service() +{ + s_psa_client_api_service.destroy(); +} +#else +#warning "Unknown eRPC allocation policy!" +#endif diff --git a/erpc/generated_files/tfm_erpc_psa_client_api_server.h b/erpc/generated_files/tfm_erpc_psa_client_api_server.h new file mode 100644 index 0000000..3146840 --- /dev/null +++ b/erpc/generated_files/tfm_erpc_psa_client_api_server.h @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2022, Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + * + */ + +/* + * Generated by erpcgen 1.9.1 on Fri Dec 16 14:51:11 2022. + * + * AUTOGENERATED - DO NOT EDIT + */ + + +#if !defined(_tfm_erpc_psa_client_api_server_h_) +#define _tfm_erpc_psa_client_api_server_h_ + +#ifdef __cplusplus +#include "erpc_server.h" +#include "erpc_codec.h" +extern "C" +{ +#include "tfm_erpc_psa_client_api.h" +#include +#include +} + +#if 10901 != ERPC_VERSION_NUMBER +#error "The generated shim code version is different to the rest of eRPC code." +#endif + + +/*! + * @brief Service subclass for psa_client_api. + */ +class psa_client_api_service : public erpc::Service +{ +public: + psa_client_api_service() : Service(kpsa_client_api_service_id) {} + + /*! @brief Call the correct server shim based on method unique ID. */ + virtual erpc_status_t handleInvocation(uint32_t methodId, uint32_t sequence, erpc::Codec * codec, erpc::MessageBufferFactory *messageFactory); + +private: + /*! @brief Server shim for psa_framework_version of psa_client_api interface. */ + erpc_status_t psa_framework_version_shim(erpc::Codec * codec, erpc::MessageBufferFactory *messageFactory, uint32_t sequence); + + /*! @brief Server shim for psa_version of psa_client_api interface. */ + erpc_status_t psa_version_shim(erpc::Codec * codec, erpc::MessageBufferFactory *messageFactory, uint32_t sequence); + + /*! @brief Server shim for erpc_psa_call of psa_client_api interface. */ + erpc_status_t erpc_psa_call_shim(erpc::Codec * codec, erpc::MessageBufferFactory *messageFactory, uint32_t sequence); +}; + +extern "C" { +#else +#include "tfm_erpc_psa_client_api.h" +#endif // __cplusplus + +typedef void * erpc_service_t; + +erpc_service_t create_psa_client_api_service(void); + +#if ERPC_ALLOCATION_POLICY == ERPC_ALLOCATION_POLICY_DYNAMIC +void destroy_psa_client_api_service(erpc_service_t service); +#elif ERPC_ALLOCATION_POLICY == ERPC_ALLOCATION_POLICY_STATIC +void destroy_psa_client_api_service(void); +#else +#warning "Unknown eRPC allocation policy!" +#endif + +#ifdef __cplusplus +} +#endif // __cplusplus + +#endif // _tfm_erpc_psa_client_api_server_h_ diff --git a/erpc/generated_files/tfm_erpc_psa_connection_api.h b/erpc/generated_files/tfm_erpc_psa_connection_api.h new file mode 100644 index 0000000..4155916 --- /dev/null +++ b/erpc/generated_files/tfm_erpc_psa_connection_api.h @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2022, Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + * + */ + +/* + * Generated by erpcgen 1.9.1 on Fri Dec 16 14:51:11 2022. + * + * AUTOGENERATED - DO NOT EDIT + */ + + +#if !defined(_tfm_erpc_psa_connection_api_h_) +#define _tfm_erpc_psa_connection_api_h_ + +#include +#include +#include +#include "erpc_version.h" +#include "psa/client.h" + +#if 10901 != ERPC_VERSION_NUMBER +#error "The generated shim code version is different to the rest of eRPC code." +#endif + +#if !defined(ERPC_TYPE_DEFINITIONS) +#define ERPC_TYPE_DEFINITIONS + +// Aliases data types declarations +typedef struct list_binary_1_t list_binary_1_t; +typedef struct binary_t binary_t; + +// Structures/unions data types declarations +struct list_binary_1_t +{ + binary_t * elements; + uint32_t elementsCount; +}; + +struct binary_t +{ + uint8_t * data; + uint32_t dataLength; +}; + + +#endif // ERPC_TYPE_DEFINITIONS + +/*! @brief psa_connection_api identifiers */ +enum _psa_connection_api_ids +{ + kpsa_connection_api_service_id = 2, + kpsa_connection_api_psa_connect_id = 1, + kpsa_connection_api_psa_close_id = 2, +}; + +#if defined(__cplusplus) +extern "C" { +#endif + +//! @name psa_connection_api +//@{ +psa_handle_t psa_connect(uint32_t sid, uint32_t ver); + +void psa_close(psa_handle_t handle); +//@} + +#if defined(__cplusplus) +} +#endif + +#endif // _tfm_erpc_psa_connection_api_h_ diff --git a/erpc/generated_files/tfm_erpc_psa_connection_api_client.cpp b/erpc/generated_files/tfm_erpc_psa_connection_api_client.cpp new file mode 100644 index 0000000..ab24967 --- /dev/null +++ b/erpc/generated_files/tfm_erpc_psa_connection_api_client.cpp @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2022, Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + * + */ + +/* + * Generated by erpcgen 1.9.1 on Fri Dec 16 14:51:11 2022. + * + * AUTOGENERATED - DO NOT EDIT + */ + + +#include "erpc_client_manager.h" +#if ERPC_ALLOCATION_POLICY == ERPC_ALLOCATION_POLICY_DYNAMIC +#include "erpc_port.h" +#endif +#include "erpc_codec.h" +extern "C" +{ +#include "tfm_erpc_psa_connection_api.h" +// import callbacks declaration from other groups +#include "tfm_erpc_psa_client_api.h" +} + +#if 10901 != ERPC_VERSION_NUMBER +#error "The generated shim code version is different to the rest of eRPC code." +#endif + +using namespace erpc; +using namespace std; + +extern ClientManager *g_client; + + +// psa_connection_api interface psa_connect function client shim. +psa_handle_t psa_connect(uint32_t sid, uint32_t ver) +{ + erpc_status_t err = kErpcStatus_Success; + + psa_handle_t result; + +#if ERPC_PRE_POST_ACTION + pre_post_action_cb preCB = g_client->getPreCB(); + if (preCB) + { + preCB(); + } +#endif + + // Get a new request. + RequestContext request = g_client->createRequest(false); + + // Encode the request. + Codec * codec = request.getCodec(); + + if (codec == NULL) + { + err = kErpcStatus_MemoryError; + } + else + { + codec->startWriteMessage(kInvocationMessage, kpsa_connection_api_service_id, kpsa_connection_api_psa_connect_id, request.getSequence()); + + codec->write(sid); + + codec->write(ver); + + // Send message to server + // Codec status is checked inside this function. + g_client->performRequest(request); + + codec->read(&result); + + err = codec->getStatus(); + } + + // Dispose of the request. + g_client->releaseRequest(request); + + // Invoke error handler callback function + g_client->callErrorHandler(err, kpsa_connection_api_psa_connect_id); + +#if ERPC_PRE_POST_ACTION + pre_post_action_cb postCB = g_client->getPostCB(); + if (postCB) + { + postCB(); + } +#endif + + + if (err != kErpcStatus_Success) + { + result = -1; + } + + return result; +} + +// psa_connection_api interface psa_close function client shim. +void psa_close(psa_handle_t handle) +{ + erpc_status_t err = kErpcStatus_Success; + + +#if ERPC_PRE_POST_ACTION + pre_post_action_cb preCB = g_client->getPreCB(); + if (preCB) + { + preCB(); + } +#endif + + // Get a new request. + RequestContext request = g_client->createRequest(false); + + // Encode the request. + Codec * codec = request.getCodec(); + + if (codec == NULL) + { + err = kErpcStatus_MemoryError; + } + else + { + codec->startWriteMessage(kInvocationMessage, kpsa_connection_api_service_id, kpsa_connection_api_psa_close_id, request.getSequence()); + + codec->write(handle); + + // Send message to server + // Codec status is checked inside this function. + g_client->performRequest(request); + + err = codec->getStatus(); + } + + // Dispose of the request. + g_client->releaseRequest(request); + + // Invoke error handler callback function + g_client->callErrorHandler(err, kpsa_connection_api_psa_close_id); + +#if ERPC_PRE_POST_ACTION + pre_post_action_cb postCB = g_client->getPostCB(); + if (postCB) + { + postCB(); + } +#endif + + + return; +} diff --git a/erpc/generated_files/tfm_erpc_psa_connection_api_server.cpp b/erpc/generated_files/tfm_erpc_psa_connection_api_server.cpp new file mode 100644 index 0000000..8e51d8d --- /dev/null +++ b/erpc/generated_files/tfm_erpc_psa_connection_api_server.cpp @@ -0,0 +1,179 @@ +/* + * Copyright (c) 2022, Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + * + */ + +/* + * Generated by erpcgen 1.9.1 on Fri Dec 16 14:51:11 2022. + * + * AUTOGENERATED - DO NOT EDIT + */ + + +#include "tfm_erpc_psa_connection_api_server.h" +#if ERPC_ALLOCATION_POLICY == ERPC_ALLOCATION_POLICY_DYNAMIC +#include +#include "erpc_port.h" +#endif +#include "erpc_manually_constructed.h" + +#if 10901 != ERPC_VERSION_NUMBER +#error "The generated shim code version is different to the rest of eRPC code." +#endif + +using namespace erpc; +using namespace std; + +#if ERPC_NESTED_CALLS_DETECTION +extern bool nestingDetection; +#endif + +ERPC_MANUALLY_CONSTRUCTED_STATIC(psa_connection_api_service, s_psa_connection_api_service); + + + +// Call the correct server shim based on method unique ID. +erpc_status_t psa_connection_api_service::handleInvocation(uint32_t methodId, uint32_t sequence, Codec * codec, MessageBufferFactory *messageFactory) +{ + erpc_status_t erpcStatus; + switch (methodId) + { + case kpsa_connection_api_psa_connect_id: + { + erpcStatus = psa_connect_shim(codec, messageFactory, sequence); + break; + } + + case kpsa_connection_api_psa_close_id: + { + erpcStatus = psa_close_shim(codec, messageFactory, sequence); + break; + } + + default: + { + erpcStatus = kErpcStatus_InvalidArgument; + break; + } + } + + return erpcStatus; +} + +// Server shim for psa_connect of psa_connection_api interface. +erpc_status_t psa_connection_api_service::psa_connect_shim(Codec * codec, MessageBufferFactory *messageFactory, uint32_t sequence) +{ + erpc_status_t err = kErpcStatus_Success; + + uint32_t sid; + uint32_t ver; + psa_handle_t result; + + // startReadMessage() was already called before this shim was invoked. + + codec->read(&sid); + + codec->read(&ver); + + err = codec->getStatus(); + if (err == kErpcStatus_Success) + { + // Invoke the actual served function. +#if ERPC_NESTED_CALLS_DETECTION + nestingDetection = true; +#endif + result = psa_connect(sid, ver); +#if ERPC_NESTED_CALLS_DETECTION + nestingDetection = false; +#endif + + // preparing MessageBuffer for serializing data + err = messageFactory->prepareServerBufferForSend(codec->getBuffer()); + } + + if (err == kErpcStatus_Success) + { + // preparing codec for serializing data + codec->reset(); + + // Build response message. + codec->startWriteMessage(kReplyMessage, kpsa_connection_api_service_id, kpsa_connection_api_psa_connect_id, sequence); + + codec->write(result); + + err = codec->getStatus(); + } + + return err; +} + +// Server shim for psa_close of psa_connection_api interface. +erpc_status_t psa_connection_api_service::psa_close_shim(Codec * codec, MessageBufferFactory *messageFactory, uint32_t sequence) +{ + erpc_status_t err = kErpcStatus_Success; + + psa_handle_t handle; + + // startReadMessage() was already called before this shim was invoked. + + codec->read(&handle); + + err = codec->getStatus(); + if (err == kErpcStatus_Success) + { + // Invoke the actual served function. +#if ERPC_NESTED_CALLS_DETECTION + nestingDetection = true; +#endif + psa_close(handle); +#if ERPC_NESTED_CALLS_DETECTION + nestingDetection = false; +#endif + + // preparing MessageBuffer for serializing data + err = messageFactory->prepareServerBufferForSend(codec->getBuffer()); + } + + if (err == kErpcStatus_Success) + { + // preparing codec for serializing data + codec->reset(); + + // Build response message. + codec->startWriteMessage(kReplyMessage, kpsa_connection_api_service_id, kpsa_connection_api_psa_close_id, sequence); + + err = codec->getStatus(); + } + + return err; +} + +#if ERPC_ALLOCATION_POLICY == ERPC_ALLOCATION_POLICY_DYNAMIC +erpc_service_t create_psa_connection_api_service() +{ + return new (nothrow) psa_connection_api_service(); +} + +void destroy_psa_connection_api_service(erpc_service_t service) +{ + if (service) + { + delete (psa_connection_api_service *)service; + } +} +#elif ERPC_ALLOCATION_POLICY == ERPC_ALLOCATION_POLICY_STATIC +erpc_service_t create_psa_connection_api_service() +{ + s_psa_connection_api_service.construct(); + return s_psa_connection_api_service.get(); +} + +void destroy_psa_connection_api_service() +{ + s_psa_connection_api_service.destroy(); +} +#else +#warning "Unknown eRPC allocation policy!" +#endif diff --git a/erpc/generated_files/tfm_erpc_psa_connection_api_server.h b/erpc/generated_files/tfm_erpc_psa_connection_api_server.h new file mode 100644 index 0000000..01dbc1f --- /dev/null +++ b/erpc/generated_files/tfm_erpc_psa_connection_api_server.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2022, Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + * + */ + +/* + * Generated by erpcgen 1.9.1 on Fri Dec 16 14:51:11 2022. + * + * AUTOGENERATED - DO NOT EDIT + */ + + +#if !defined(_tfm_erpc_psa_connection_api_server_h_) +#define _tfm_erpc_psa_connection_api_server_h_ + +#ifdef __cplusplus +#include "erpc_server.h" +#include "erpc_codec.h" +extern "C" +{ +#include "tfm_erpc_psa_connection_api.h" +#include +#include +} + +#if 10901 != ERPC_VERSION_NUMBER +#error "The generated shim code version is different to the rest of eRPC code." +#endif + + +/*! + * @brief Service subclass for psa_connection_api. + */ +class psa_connection_api_service : public erpc::Service +{ +public: + psa_connection_api_service() : Service(kpsa_connection_api_service_id) {} + + /*! @brief Call the correct server shim based on method unique ID. */ + virtual erpc_status_t handleInvocation(uint32_t methodId, uint32_t sequence, erpc::Codec * codec, erpc::MessageBufferFactory *messageFactory); + +private: + /*! @brief Server shim for psa_connect of psa_connection_api interface. */ + erpc_status_t psa_connect_shim(erpc::Codec * codec, erpc::MessageBufferFactory *messageFactory, uint32_t sequence); + + /*! @brief Server shim for psa_close of psa_connection_api interface. */ + erpc_status_t psa_close_shim(erpc::Codec * codec, erpc::MessageBufferFactory *messageFactory, uint32_t sequence); +}; + +extern "C" { +#else +#include "tfm_erpc_psa_connection_api.h" +#endif // __cplusplus + +typedef void * erpc_service_t; + +erpc_service_t create_psa_connection_api_service(void); + +#if ERPC_ALLOCATION_POLICY == ERPC_ALLOCATION_POLICY_DYNAMIC +void destroy_psa_connection_api_service(erpc_service_t service); +#elif ERPC_ALLOCATION_POLICY == ERPC_ALLOCATION_POLICY_STATIC +void destroy_psa_connection_api_service(void); +#else +#warning "Unknown eRPC allocation policy!" +#endif + +#ifdef __cplusplus +} +#endif // __cplusplus + +#endif // _tfm_erpc_psa_connection_api_server_h_ diff --git a/erpc/host_example/CMakeLists.txt b/erpc/host_example/CMakeLists.txt new file mode 100644 index 0000000..3caf2b2 --- /dev/null +++ b/erpc/host_example/CMakeLists.txt @@ -0,0 +1,57 @@ +#------------------------------------------------------------------------------- +# Copyright (c) 2023, Arm Limited. All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause +# +#------------------------------------------------------------------------------- + +cmake_minimum_required(VERSION 3.15) + +project("ERPC Host" LANGUAGES CXX C) +set(CMAKE_CXX_FLAGS "-m32") +set(CMAKE_C_FLAGS "-m32") + +add_executable(erpc_main) + +add_subdirectory(../client client) + +if (NOT DEFINED ERPC_TRANSPORT) + message(FATAL_ERROR "Please select ERPC_TRANSPORT, currently only UART and TCP are supported!") +endif() + +if (ERPC_TRANSPORT STREQUAL "UART") + if (NOT DEFINED PORT_NAME) + message(FATAL_ERROR "Please provide PORT_NAME!") + endif() +elseif (ERPC_TRANSPORT STREQUAL "TCP") + if((NOT DEFINED ERPC_HOST) OR (NOT DEFINED ERPC_PORT)) + message(FATAL_ERROR "Please provide ERPC_HOST and ERPC_PORT!") + endif() +else() + message(FATAL_ERROR "Please provided supported transportation type (UART and TCP)!") +endif() + +target_sources(erpc_main + PRIVATE + main.c + ${ERPC_REPO_PATH}/erpc_c/port/erpc_threading_pthreads.cpp + $<$:${ERPC_REPO_PATH}/erpc_c/setup/erpc_setup_serial.cpp> + $<$:${ERPC_REPO_PATH}/erpc_c/transports/erpc_serial_transport.cpp> + $<$:${ERPC_REPO_PATH}/erpc_c/setup/erpc_setup_tcp.cpp> + $<$:${ERPC_REPO_PATH}/erpc_c/transports/erpc_tcp_transport.cpp> +) + +target_link_libraries(erpc_main + PRIVATE + erpc_client + pthread +) + +target_compile_definitions(erpc_main + PRIVATE + $<$:ERPC_TRANSPORT_UART> + $<$:ERPC_TRANSPORT_TCP> + $<$,$>:PORT_NAME="${PORT_NAME}"> + $<$,$>:ERPC_HOST="${ERPC_HOST}"> + $<$,$>:ERPC_PORT=${ERPC_PORT}> +) diff --git a/erpc/host_example/README.rst b/erpc/host_example/README.rst new file mode 100644 index 0000000..a00b024 --- /dev/null +++ b/erpc/host_example/README.rst @@ -0,0 +1,92 @@ +********* +eRPC Host +********* + +This host example is only tested for Linux. + +Example: UART Transportation on Musca_S1 +======================================== + +Build instructions on the target +-------------------------------- + +.. code-block:: bash + + cd + cmake -G"Unix Makefiles" -S . -B cmake_build -DTFM_PLATFORM=musca_s1 -DTFM_TOOLCHAIN_FILE=toolchain_GNUARM.cmake -DCMAKE_BUILD_TYPE=Debug -DCONFIG_TFM_ERPC_TEST_FRAMEWORK=ON ../ + cmake --build cmake_build/ -- install -j32 + +Build instructions on the host +------------------------------ + +.. code-block:: bash + + cd /erpc/host_example + cmake -S . -B build -G "Unix Makefiles" -DTFM_INSTALL_PATH= -DERPC_REPO_PATH= -DERPC_TRANSPORT=UART -DPORT_NAME="/dev/ttyACM0" + cmake --build build/ + +Run instructions on the host +---------------------------- + +.. code-block:: bash + + cd /erpc/host_example + ./build/erpc_main + +Example: TCP Transportation on AN521 FVP +======================================== + +Build instructions on the target +-------------------------------- + +.. code-block:: bash + + cd + cmake -G"Unix Makefiles" -S . -B cmake_build -DTFM_PLATFORM=an521 -DTFM_TOOLCHAIN_FILE=toolchain_GNUARM.cmake -DCMAKE_BUILD_TYPE=Debug -DCONFIG_TFM_ERPC_TEST_FRAMEWORK=ON ../ + cmake --build cmake_build/ -- install -j32 + +Build instructions on the host +------------------------------ + +.. code-block:: bash + + cd /erpc/host_example + cmake -S . -B build -G "Unix Makefiles" -DTFM_INSTALL_PATH= -DERPC_REPO_PATH= -DERPC_TRANSPORT=TCP -DERPC_HOST="0.0.0.0" -DERPC_PORT=5001 + cmake --build build/ + +Run instructions on the host +---------------------------- + +Start the AN521 FVP: + +.. code-block:: bash + + /sw/models/bin/FVP_MPS2_AEMv8M \ + --parameter fvp_mps2.platform_type=2 \ + --parameter cpu0.baseline=0 \ + --parameter cpu0.INITVTOR_S=0x10000000 \ + --parameter cpu0.semihosting-enable=0 \ + --parameter fvp_mps2.DISABLE_GATING=0 \ + --parameter fvp_mps2.telnetterminal0.start_telnet=1 \ + --parameter fvp_mps2.telnetterminal1.start_telnet=0 \ + --parameter fvp_mps2.telnetterminal2.start_telnet=0 \ + --parameter fvp_mps2.telnetterminal0.quiet=0 \ + --parameter fvp_mps2.telnetterminal1.quiet=1 \ + --parameter fvp_mps2.telnetterminal2.quiet=1 \ + --parameter fvp_mps2.UART0.out_file=/dev/stdout \ + --parameter fvp_mps2.UART0.unbuffered_output=1 \ + --parameter fvp_mps2.telnetterminal1.mode=raw \ + --parameter fvp_mps2.UART1.unbuffered_output=1 \ + --parameter fvp_mps2.mps2_visualisation.disable-visualisation=1 \ + --application cpu0= \ + --data cpu0=@0x10080000 \ + -M 1 + +.. code-block:: bash + + cd /erpc/host_example + ./build/erpc_main + +-------------- + +*Copyright (c) 2023, Arm Limited. All rights reserved.* diff --git a/erpc/host_example/main.c b/erpc/host_example/main.c new file mode 100644 index 0000000..b46ab27 --- /dev/null +++ b/erpc/host_example/main.c @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023, Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + * + */ + +#include +#include "erpc_port.h" +#include "erpc_client_start.h" +#include "tfm_erpc_psa_client_api.h" + +int main(int argc, char *argv[]) +{ + erpc_transport_t transport; + +#ifdef ERPC_TRANSPORT_UART + transport = erpc_transport_serial_init(PORT_NAME, 115200); +#elif defined(ERPC_TRANSPORT_TCP) + transport = erpc_transport_tcp_init(ERPC_HOST, ERPC_PORT, false); +#else +#error "No valid transportation layer selected." +#endif + + if (!transport) { + printf("eRPC transport init failed!\r\n"); + return 1; + } + + erpc_client_start(transport); + + printf("psa_framework_version: %d\r\n", psa_framework_version()); + + return 0; +} diff --git a/erpc/server/CMakeLists.txt b/erpc/server/CMakeLists.txt new file mode 100644 index 0000000..fe61fb7 --- /dev/null +++ b/erpc/server/CMakeLists.txt @@ -0,0 +1,64 @@ +#------------------------------------------------------------------------------- +# Copyright (c) 2023, Arm Limited. All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause +# +#------------------------------------------------------------------------------- + +cmake_minimum_required(VERSION 3.15) +cmake_policy(SET CMP0097 NEW) + +# Set eRPC config file. Need to provide config file with an absolute path. +if (ERPC_CONFIG_FILE) + if (NOT EXISTS ${ERPC_CONFIG_FILE}) + message(FATAL_ERROR "ERPC_CONFIG_FILE does not exist. Please provide it with an absolute path.") + endif() + # Get the path of the customized eRPC config file + get_filename_component(ERPC_CONFIG_FILE_PATH ${ERPC_CONFIG_FILE} DIRECTORY) +else() + # Use default one + set(ERPC_CONFIG_FILE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/config") +endif() + +add_library(erpc_server STATIC) + +target_sources(erpc_server + PRIVATE + erpc_server_start.c + erpc_server_wrapper.c + # eRPC files + ${ERPC_REPO_PATH}/erpc_c/infra/erpc_basic_codec.cpp + ${ERPC_REPO_PATH}/erpc_c/infra/erpc_crc16.cpp + ${ERPC_REPO_PATH}/erpc_c/infra/erpc_framed_transport.cpp + ${ERPC_REPO_PATH}/erpc_c/infra/erpc_message_buffer.cpp + ${ERPC_REPO_PATH}/erpc_c/infra/erpc_server.cpp + ${ERPC_REPO_PATH}/erpc_c/infra/erpc_simple_server.cpp + ${ERPC_REPO_PATH}/erpc_c/port/erpc_port_stdlib.cpp + ${ERPC_REPO_PATH}/erpc_c/setup/erpc_setup_mbf_dynamic.cpp + ${ERPC_REPO_PATH}/erpc_c/setup/erpc_server_setup.cpp + # Generated files + ${CMAKE_CURRENT_SOURCE_DIR}/../generated_files/tfm_erpc_psa_client_api_server.cpp + $<$:${CMAKE_CURRENT_SOURCE_DIR}/../generated_files/tfm_erpc_psa_connection_api_server.cpp> +) + +target_include_directories(erpc_server + PUBLIC + ${ERPC_REPO_PATH}/erpc_c/port + ${ERPC_REPO_PATH}/erpc_c/infra + ${ERPC_REPO_PATH}/erpc_c/transports + ${ERPC_REPO_PATH}/erpc_c/setup + ${CMAKE_CURRENT_SOURCE_DIR}/ + ${CMAKE_CURRENT_SOURCE_DIR}/../generated_files + ${ERPC_CONFIG_FILE_PATH}/ +) + +target_link_libraries(erpc_server + PUBLIC + tfm_api_ns + platform_ns # UART driver header and target config +) + +target_compile_definitions(erpc_server + PUBLIC + $<$:CONFIG_TFM_CONNECTION_BASED_SERVICE_API=1> +) diff --git a/erpc/server/config/erpc_config.h b/erpc/server/config/erpc_config.h new file mode 100644 index 0000000..9ef5f66 --- /dev/null +++ b/erpc/server/config/erpc_config.h @@ -0,0 +1,212 @@ +/* + * Copyright (c) 2016, Freescale Semiconductor, Inc. + * Copyright 2016-2020 NXP + * Copyright 2020-2021 ACRIOS Systems s.r.o. + * Copyright (c) 2023, Arm Limited. All rights reserved. + * All rights reserved. + * + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _ERPC_CONFIG_H_ +#define _ERPC_CONFIG_H_ + +/*! + * @addtogroup config + * @{ + * @file + */ + +//////////////////////////////////////////////////////////////////////////////// +// Declarations +//////////////////////////////////////////////////////////////////////////////// + +//! @name Threading model options +//@{ +#define ERPC_ALLOCATION_POLICY_DYNAMIC (0U) //!< Dynamic allocation policy +#define ERPC_ALLOCATION_POLICY_STATIC (1U) //!< Static allocation policy + +#define ERPC_THREADS_NONE (0U) //!< No threads. +#define ERPC_THREADS_PTHREADS (1U) //!< POSIX pthreads. +#define ERPC_THREADS_FREERTOS (2U) //!< FreeRTOS. +#define ERPC_THREADS_ZEPHYR (3U) //!< ZEPHYR. +#define ERPC_THREADS_MBED (4U) //!< Mbed OS +#define ERPC_THREADS_WIN32 (5U) //!< WIN32 +#define ERPC_THREADS_THREADX (6U) //!< THREADX + +#define ERPC_NOEXCEPT_DISABLED (0U) //!< Disabling noexcept feature. +#define ERPC_NOEXCEPT_ENABLED (1U) //!< Enabling noexcept feature. + +#define ERPC_NESTED_CALLS_DISABLED (0U) //!< No nested calls support. +#define ERPC_NESTED_CALLS_ENABLED (1U) //!< Nested calls support. + +#define ERPC_NESTED_CALLS_DETECTION_DISABLED (0U) //!< Nested calls detection disabled. +#define ERPC_NESTED_CALLS_DETECTION_ENABLED (1U) //!< Nested calls detection enabled. + +#define ERPC_MESSAGE_LOGGING_DISABLED (0U) //!< Trace functions disabled. +#define ERPC_MESSAGE_LOGGING_ENABLED (1U) //!< Trace functions enabled. + +#define ERPC_TRANSPORT_MU_USE_MCMGR_DISABLED (0U) //!< Do not use MCMGR for MU ISR management. +#define ERPC_TRANSPORT_MU_USE_MCMGR_ENABLED (1U) //!< Use MCMGR for MU ISR management. + +#define ERPC_PRE_POST_ACTION_DISABLED (0U) //!< Pre post shim callbacks functions disabled. +#define ERPC_PRE_POST_ACTION_ENABLED (1U) //!< Pre post shim callback functions enabled. + +#define ERPC_PRE_POST_ACTION_DEFAULT_DISABLED (0U) //!< Pre post shim default callbacks functions disabled. +#define ERPC_PRE_POST_ACTION_DEFAULT_ENABLED (1U) //!< Pre post shim default callback functions enabled. +//@} + +//! @name Configuration options +//@{ + +//! @def ERPC_ALLOCATION_POLICY +//! +//! @brief Choose which allocation policy should be used. +//! +//! Set ERPC_ALLOCATION_POLICY_DYNAMIC if dynamic allocations should be used. +//! Set ERPC_ALLOCATION_POLICY_STATIC if static allocations should be used. +//! +//! Default value is ERPC_ALLOCATION_POLICY_DYNAMIC or in case of FreeRTOS it can be auto-detected if __has_include() is +//! supported by compiler. Uncomment comment bellow to use static allocation policy. In case of static implementation +//! user need consider another values to set (ERPC_CODEC_COUNT, ERPC_MESSAGE_LOGGERS_COUNT, +//! ERPC_CLIENTS_THREADS_AMOUNT). +// #define ERPC_ALLOCATION_POLICY (ERPC_ALLOCATION_POLICY_STATIC) + +//! @def ERPC_CODEC_COUNT +//! +//! @brief Set amount of codecs objects used simultaneously in case of ERPC_ALLOCATION_POLICY is set to +//! ERPC_ALLOCATION_POLICY_STATIC. For example if client or server is used in one thread then 1. If both are used in one +//! thread per each then 2, ... Default value 2. +// #define ERPC_CODEC_COUNT (2U) + +//! @def ERPC_MESSAGE_LOGGERS_COUNT +//! +//! @brief Set amount of message loggers objects used simultaneously in case of ERPC_ALLOCATION_POLICY is set to +//! ERPC_ALLOCATION_POLICY_STATIC. +//! For example if client or server is used in one thread then 1. If both are used in one thread per each then 2, ... +//! For arbitrated client 1 is enough. +//! Default value 0 (May not be used). +// #define ERPC_MESSAGE_LOGGERS_COUNT (0U) + +//! @def ERPC_CLIENTS_THREADS_AMOUNT +//! +//! @brief Set amount of client threads objects used in case of ERPC_ALLOCATION_POLICY is set to +//! ERPC_ALLOCATION_POLICY_STATIC. Default value 1 (Most of current cases). +// #define ERPC_CLIENTS_THREADS_AMOUNT (1U) + +//! @def ERPC_THREADS +//! +//! @brief Select threading model. +//! +//! Set to one of the @c ERPC_THREADS_x macros to specify the threading model used by eRPC. +//! +//! Leave commented out to attempt to auto-detect. Auto-detection works well for pthreads. +//! FreeRTOS can be detected when building with compilers that support __has_include(). +//! Otherwise, the default is no threading. +#define ERPC_THREADS (ERPC_THREADS_NONE) + +//! @def ERPC_DEFAULT_BUFFER_SIZE +//! +//! Uncomment to change the size of buffers allocated by one of MessageBufferFactory. +//! (@ref client_setup and @ref server_setup). The default size is set to 256. +//! For RPMsg transport layer, ERPC_DEFAULT_BUFFER_SIZE must be 2^n - 16. +//#define ERPC_DEFAULT_BUFFER_SIZE (256U) + +//! @def ERPC_DEFAULT_BUFFERS_COUNT +//! +//! Uncomment to change the count of buffers allocated by one of statically allocated messages. +//! Default value is set to 2. +//#define ERPC_DEFAULT_BUFFERS_COUNT (2U) + +//! @def ERPC_NOEXCEPT +//! +//! @brief Disable/enable noexcept support. +//! +//! Uncomment for using noexcept feature. +//#define ERPC_NOEXCEPT (ERPC_NOEXCEPT_ENABLED) + +//! @def ERPC_NESTED_CALLS +//! +//! Default set to ERPC_NESTED_CALLS_DISABLED. Uncomment when callbacks, or other eRPC +//! functions are called from server implementation of another eRPC call. Nested functions +//! need to be marked as @nested in IDL. +//#define ERPC_NESTED_CALLS (ERPC_NESTED_CALLS_ENABLED) + +//! @def ERPC_NESTED_CALLS_DETECTION +//! +//! Default set to ERPC_NESTED_CALLS_DETECTION_ENABLED when NDEBUG macro is presented. +//! This serve for locating nested calls in code. Nested calls are calls where inside eRPC function +//! on server side is called another eRPC function (like callbacks). Code need be a bit changed +//! to support nested calls. See ERPC_NESTED_CALLS macro. +//#define ERPC_NESTED_CALLS_DETECTION (ERPC_NESTED_CALLS_DETECTION_DISABLED) + +//! @def ERPC_MESSAGE_LOGGING +//! +//! Enable eRPC message logging code through the eRPC. Take look into "erpc_message_loggers.h". Can be used for base +//! printing messages, or sending data to another system for data analysis. Default set to +//! ERPC_MESSAGE_LOGGING_DISABLED. +//! +//! Uncomment for using logging feature. +//#define ERPC_MESSAGE_LOGGING (ERPC_MESSAGE_LOGGING_ENABLED) + +//! @def ERPC_TRANSPORT_MU_USE_MCMGR +//! +//! @brief MU transport layer configuration. +//! +//! Set to one of the @c ERPC_TRANSPORT_MU_USE_MCMGR_x macros to configure the MCMGR usage in MU transport layer. +//! +//! MU transport layer could leverage the Multicore Manager (MCMGR) component for Inter-Core +//! interrupts / MU interrupts management or the Inter-Core interrupts can be managed by itself (MUX_IRQHandler +//! overloading). By default, ERPC_TRANSPORT_MU_USE_MCMGR is set to ERPC_TRANSPORT_MU_USE_MCMGR_ENABLED when mcmgr.h +//! is part of the project, otherwise the ERPC_TRANSPORT_MU_USE_MCMGR_DISABLED option is used. This settings can be +//! overwritten from the erpc_config.h by uncommenting the ERPC_TRANSPORT_MU_USE_MCMGR macro definition. Do not forget +//! to add the MCMGR library into your project when ERPC_TRANSPORT_MU_USE_MCMGR_ENABLED option is used! See the +//! erpc_mu_transport.h for additional MU settings. +//#define ERPC_TRANSPORT_MU_USE_MCMGR ERPC_TRANSPORT_MU_USE_MCMGR_DISABLED +//@} + +//! @def ERPC_PRE_POST_ACTION +//! +//! Enable eRPC pre and post callback functions shim code. Take look into "erpc_pre_post_action.h". Can be used for +//! detection of eRPC call freeze, ... Default set to ERPC_PRE_POST_ACTION_DISABLED. +//! +//! Uncomment for using pre post callback feature. +//#define ERPC_PRE_POST_ACTION (ERPC_PRE_POST_ACTION_ENABLED) + +//! @def ERPC_PRE_POST_ACTION_DEFAULT +//! +//! Enable eRPC pre and post default callback functions. Take look into "erpc_setup_extensions.h". Can be used for +//! detection of eRPC call freeze, ... Default set to ERPC_PRE_POST_ACTION_DEFAULT_DISABLED. +//! +//! Uncomment for using pre post default callback feature. +//#define ERPC_PRE_POST_ACTION_DEFAULT (ERPC_PRE_POST_ACTION_DEFAULT_ENABLED) + +//! @name Assert function definition +//@{ +//! User custom asser defition. Include header file if needed before bellow line. If assert is not enabled, default will +//! be used. +// #define erpc_assert(condition) +//@} + +//! @def ENDIANES_HEADER +//! +//! Include header file that controls the communication endianness +//! +//! Uncomment for example behaviour for endianness agnostic with: +//! 1. communication in little endian. +//! 2. current processor is big endian. +//! 3. pointer size is 32 bit. +//! 4. float+double scheme not defined, so throws assert if passes. +//! #define ERPC_PROCESSOR_ENDIANNESS_LITTLE 0 +//! #define ERPC_COMMUNICATION_LITTLE 1 +//! #define ERPC_POINTER_SIZE_16 0 +//! #define ERPC_POINTER_SIZE_32 1 +//! #define ERPC_POINTER_SIZE_64 0 +//! #define ENDIANNESS_HEADER "erpc_endianness_agnostic_example.h" + +/*! @} */ +#endif // _ERPC_CONFIG_H_ +//////////////////////////////////////////////////////////////////////////////// +// EOF +//////////////////////////////////////////////////////////////////////////////// diff --git a/erpc/server/erpc_server_start.c b/erpc/server/erpc_server_start.c new file mode 100644 index 0000000..71fc26d --- /dev/null +++ b/erpc/server/erpc_server_start.c @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023, Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + * + */ + +#include "erpc_server_start.h" + +#include "erpc_mbf_setup.h" +#include "erpc_server_setup.h" +#include "tfm_erpc_psa_client_api_server.h" +#if CONFIG_TFM_CONNECTION_BASED_SERVICE_API == 1 +#include "tfm_erpc_psa_connection_api_server.h" +#endif + +void erpc_server_start(erpc_transport_t transport) +{ + erpc_server_init(transport, erpc_mbf_dynamic_init()); + erpc_add_service_to_server(create_psa_client_api_service()); +#if CONFIG_TFM_CONNECTION_BASED_SERVICE_API == 1 + erpc_add_service_to_server(create_psa_connection_api_service()); +#endif + + erpc_server_run(); + + return; +} diff --git a/erpc/server/erpc_server_start.h b/erpc/server/erpc_server_start.h new file mode 100644 index 0000000..3ab870e --- /dev/null +++ b/erpc/server/erpc_server_start.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023, Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + * + */ + +#ifndef __ERPC_SERVER_START_H__ +#define __ERPC_SERVER_START_H__ + +#include "erpc_transport_setup.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * \brief eRPC Server initialization. + * + * \param[in] transport Transport to use. + */ +void erpc_server_start(erpc_transport_t transport); + +#ifdef __cplusplus +} +#endif + +#endif /* __ERPC_SERVER_START_H__ */ diff --git a/erpc/server/erpc_server_wrapper.c b/erpc/server/erpc_server_wrapper.c new file mode 100644 index 0000000..8215c9a --- /dev/null +++ b/erpc/server/erpc_server_wrapper.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2023, Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + * + */ + +#include +#include "psa/client.h" +#include "tfm_erpc_psa_client_api.h" + +psa_status_t erpc_psa_call(psa_handle_t handle, int32_t t, + const list_binary_1_t *erpc_in_vec, + list_binary_1_t *erpc_out_vec) +{ + psa_status_t status; + psa_invec in_vec[PSA_MAX_IOVEC]; + psa_outvec out_vec[PSA_MAX_IOVEC]; + size_t i; + size_t in_len = erpc_in_vec->elementsCount; + size_t out_len = erpc_out_vec->elementsCount; + + /* Copy RPC iovecs into PSA iovecs */ + for (i = 0; i < in_len; ++i) { + in_vec[i] = (psa_invec){erpc_in_vec->elements[i].data, + erpc_in_vec->elements[i].dataLength}; + } + + for (i = 0; i < out_len; ++i) { + out_vec[i] = (psa_outvec){erpc_out_vec->elements[i].data, + erpc_out_vec->elements[i].dataLength}; + } + + status = psa_call(handle, t, in_vec, in_len, out_vec, out_len); + + /* Copy updated PSA outvec lens into RPC outvecs */ + for (i = 0; i < out_len; ++i) { + erpc_out_vec->elements[i].dataLength = out_vec[i].len; + } + + return status; +} diff --git a/erpc/tfm.erpc b/erpc/tfm.erpc new file mode 100644 index 0000000..20a7d1e --- /dev/null +++ b/erpc/tfm.erpc @@ -0,0 +1,24 @@ +/*! + * Copyright (c) 2023, Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + * + */ + +@c:include("psa/client.h") + +program tfm_erpc + +@external type psa_handle_t = int32 +@external type psa_status_t = int32 + +@group(psa_client_api) interface psa_client_api { + psa_framework_version() -> uint32 + psa_version(uint32 sid) -> uint32 + erpc_psa_call(psa_handle_t handle, int32 t, list erpc_in_vec, inout list erpc_out_vec) -> psa_status_t +} + +@group(psa_connection_api) interface psa_connection_api { + psa_connect(uint32 sid, uint32 ver) -> psa_handle_t + psa_close(psa_handle_t handle) -> void +} From 46f1c986e53f9ed34535402bd72f04590bed01c0 Mon Sep 17 00:00:00 2001 From: Summer Qin Date: Wed, 14 Dec 2022 15:24:50 +0800 Subject: [PATCH 13/22] Test: Add erpc test case Add psa_hash_compute test case. Signed-off-by: Summer Qin Change-Id: I210a4799846b7a825ee994ae6e1ecce4baa04c30 --- erpc/host_example/CMakeLists.txt | 2 ++ erpc/host_example/README.rst | 4 ++-- erpc/host_example/main.c | 25 +++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/erpc/host_example/CMakeLists.txt b/erpc/host_example/CMakeLists.txt index 3caf2b2..626e08a 100644 --- a/erpc/host_example/CMakeLists.txt +++ b/erpc/host_example/CMakeLists.txt @@ -39,6 +39,7 @@ target_sources(erpc_main $<$:${ERPC_REPO_PATH}/erpc_c/transports/erpc_serial_transport.cpp> $<$:${ERPC_REPO_PATH}/erpc_c/setup/erpc_setup_tcp.cpp> $<$:${ERPC_REPO_PATH}/erpc_c/transports/erpc_tcp_transport.cpp> + ${TFM_INSTALL_PATH}/interface/src/tfm_crypto_api.c ) target_link_libraries(erpc_main @@ -54,4 +55,5 @@ target_compile_definitions(erpc_main $<$,$>:PORT_NAME="${PORT_NAME}"> $<$,$>:ERPC_HOST="${ERPC_HOST}"> $<$,$>:ERPC_PORT=${ERPC_PORT}> + PLATFORM_DEFAULT_CRYPTO_KEYS ) diff --git a/erpc/host_example/README.rst b/erpc/host_example/README.rst index a00b024..d0e25f1 100644 --- a/erpc/host_example/README.rst +++ b/erpc/host_example/README.rst @@ -13,7 +13,7 @@ Build instructions on the target .. code-block:: bash cd - cmake -G"Unix Makefiles" -S . -B cmake_build -DTFM_PLATFORM=musca_s1 -DTFM_TOOLCHAIN_FILE=toolchain_GNUARM.cmake -DCMAKE_BUILD_TYPE=Debug -DCONFIG_TFM_ERPC_TEST_FRAMEWORK=ON ../ + cmake -G"Unix Makefiles" -S . -B cmake_build -DTFM_PLATFORM=musca_s1 -DTFM_TOOLCHAIN_FILE=toolchain_GNUARM.cmake -DCMAKE_BUILD_TYPE=Debug -DCONFIG_TFM_ERPC_TEST_FRAMEWORK=ON -DTFM_PARTITION_CRYPTO=ON -DTFM_PARTITION_INTERNAL_TRUSTED_STORAGE=ON ../ cmake --build cmake_build/ -- install -j32 Build instructions on the host @@ -42,7 +42,7 @@ Build instructions on the target .. code-block:: bash cd - cmake -G"Unix Makefiles" -S . -B cmake_build -DTFM_PLATFORM=an521 -DTFM_TOOLCHAIN_FILE=toolchain_GNUARM.cmake -DCMAKE_BUILD_TYPE=Debug -DCONFIG_TFM_ERPC_TEST_FRAMEWORK=ON ../ + cmake -G"Unix Makefiles" -S . -B cmake_build -DTFM_PLATFORM=an521 -DTFM_TOOLCHAIN_FILE=toolchain_GNUARM.cmake -DCMAKE_BUILD_TYPE=Debug -DCONFIG_TFM_ERPC_TEST_FRAMEWORK=ON -DTFM_PARTITION_CRYPTO=ON -DTFM_PARTITION_INTERNAL_TRUSTED_STORAGE=ON ../ cmake --build cmake_build/ -- install -j32 Build instructions on the host diff --git a/erpc/host_example/main.c b/erpc/host_example/main.c index b46ab27..ddf2665 100644 --- a/erpc/host_example/main.c +++ b/erpc/host_example/main.c @@ -5,10 +5,33 @@ * */ +#include #include +#include #include "erpc_port.h" #include "erpc_client_start.h" #include "tfm_erpc_psa_client_api.h" +#include "tfm_crypto_defs.h" +#include "psa/client.h" +#include "psa/crypto.h" + +static void test_call(void) +{ + psa_status_t status; + uint8_t hash[PSA_HASH_LENGTH(PSA_ALG_SHA_256)] = {0}; + size_t hash_size = sizeof(hash); + const uint8_t *msg = "test"; + + status = psa_hash_compute(PSA_ALG_SHA_256, msg, strlen(msg), hash, hash_size, &hash_size); + + printf("psa_hash_compute: %d\r\n", status); + printf("> hash_size = %zu\r\n", hash_size); + printf("> hash = "); + for (size_t i = 0; i < sizeof(hash); ++i) { + printf("%02hhX", hash[i]); + } + printf("\r\n"); +} int main(int argc, char *argv[]) { @@ -31,5 +54,7 @@ int main(int argc, char *argv[]) printf("psa_framework_version: %d\r\n", psa_framework_version()); + test_call(); + return 0; } From a72eaca30c7a297375a7dfc857e3947fec5e686f Mon Sep 17 00:00:00 2001 From: Kevin Peng Date: Thu, 2 Mar 2023 09:57:08 +0800 Subject: [PATCH 14/22] Docs: Clarify licensing information Change-Id: Iaec2ccc317e1b17f5f12ceb8c7e04a8efa228d40 Signed-off-by: Kevin Peng --- license.rst | 15 +-------------- readme.rst | 28 +++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/license.rst b/license.rst index 7c038e3..7f5a799 100644 --- a/license.rst +++ b/license.rst @@ -1,4 +1,4 @@ -Copyright (c) 2020, Arm Limited. All rights reserved. +Copyright (c) 2020-2023, Arm Limited. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -34,16 +34,3 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This enables machine processing of license information based on the SPDX License Identifiers that are here available: http://spdx.org/licenses/ - -Other Projects --------------- - -This project contains code or pre-built binaries from other projects as listed -below. The original license text is included in the source files in case of -imported code. - -- The CMSIS source code and pre-built binaries are licensed under the - `Apache License`_ Version 2.0 license. The license text can be found in CMSIS - folder. - -.. _Apache License: http://www.apache.org/licenses/ diff --git a/readme.rst b/readme.rst index 5f885e0..39df659 100644 --- a/readme.rst +++ b/readme.rst @@ -1,26 +1,44 @@ ######################## Trusted Firmware-M Tests ######################## - The Trusted Firmware-M(TF-M) Tests repo is meant to hold various tests for the `Trusted Firmware-M`_. The TF-M tests mainly focus on functionalities of various TF-M componentes such -as the TF-M core and various secure partitions. +as the TF-M SPM and various Secure Partitions. There is also the `psa-arch-tests`_ suite which mainly focuses on the -implementation compliance of the Platform Security Architecture(PSA). +implementation compliance of the Platform Security Architecture (PSA). **************** Folder Structure **************** - - app - The application code that executes the testing, including both the TF-M tests and the `psa-arch-tests`_. - docs - The documents about test developments. - CMSIS - The libraries of RTX which is the Non-secure RTOS of the tests - test - The TF-M test codes including test framework, test suites and test services +- lib/ext - 3rd party projects. May contain either imported source codes or CMake files to fetch the + projects. + +####### +License +####### +The software is provided under a BSD-3-Clause :doc:`License `. +Contributions to this project are accepted under the same license with developer sign-off as +described in the +`TF-M Contributing Guidelines `__ + +This project contains code or pre-built binaries from other projects as listed below. +The code from external projects is limited to ``CMSIS`` and ``lib`` folders. +The original license texts are included in those folders. + + - ``CMSIS`` - `Apache License `__ Version 2.0 license + - The ``lib/ext`` folder may contain 3rd party projects and files with diverse licenses. + Here are some that are different from the BSD-3-Clause and may be a part of the runtime image. + The source code for these projects is fetched from upstream at build time only. + - ``erpc`` - `Modified BSD-3-Clause license `__ #################### Feedback and support @@ -31,4 +49,4 @@ Feedback can be submitted via email to .. _Trusted Firmware-M: https://git.trustedfirmware.org/TF-M/trusted-firmware-m.git/ .. _psa-arch-tests: https://github.com/ARM-software/psa-arch-tests -*Copyright (c) 2020-2022, Arm Limited. All rights reserved.* +*Copyright (c) 2020-2023, Arm Limited. All rights reserved.* From ee2c3a97e9da11094109178735a7d43af27d2ae0 Mon Sep 17 00:00:00 2001 From: Kevin Peng Date: Tue, 20 Dec 2022 12:12:59 +0800 Subject: [PATCH 15/22] Docs: Add document for eRPC framework Change-Id: I66a8d2a441042c40fb35a1a670aa57273133cf7b Signed-off-by: Kevin Peng --- docs/media/erpc_test_framework.svg | 4 + docs/tfm_erpc_test_framework.rst | 194 +++++++++++++++++++++++++++++ 2 files changed, 198 insertions(+) create mode 100755 docs/media/erpc_test_framework.svg create mode 100644 docs/tfm_erpc_test_framework.rst diff --git a/docs/media/erpc_test_framework.svg b/docs/media/erpc_test_framework.svg new file mode 100755 index 0000000..cae4bec --- /dev/null +++ b/docs/media/erpc_test_framework.svg @@ -0,0 +1,4 @@ + + + +TF-M eRPC FrameworkApplication LayerGenerated shim codeProtocal LayerTransportation LayereRPC FrameworkeRPC FrameworkHost AppTest SuitesAPI WrappereRPC ClientShimTargetAppAPI WrappereRPC ServerShimTF-M
Host
Host
Device
Device
Text is not SVG - cannot display
\ No newline at end of file diff --git a/docs/tfm_erpc_test_framework.rst b/docs/tfm_erpc_test_framework.rst new file mode 100644 index 0000000..5fa33ee --- /dev/null +++ b/docs/tfm_erpc_test_framework.rst @@ -0,0 +1,194 @@ +############################ +The TF-M eRPC Test Framework +############################ + +The TF-M eRPC Test Framework is an Remote Procedure Call (RPC) framework for testing purpose. +It's based on the `eRPC `__ system. +It is an additional framework to the existing one for running NS test suites. +It enables you to run test codes on host machines as if they were running on the device. +It has the following advantages. + +- Off-load test codes from device to host + + Arm M-profile devices usually have limited flash storage which can only fit limited test suites. + With test codes running on hosts you can run far more tests than on the devices. + +- Less frequent image downloading for test code development. + + As the test codes run on the host, you don't need to update the image on device when you update + test codes. + +- Host can get test pass or failure directly from the return codes. + + This would be helpful for test automation because you don't need to parse the test logs. + +**************** +How Does It Work +**************** +Originally, the NS tests are executed in the NSPE of the device. +The NS image on the device contains the test codes, which calls into TF-M through the PSA client +APIs. + +With the eRPC test framework, the NS tests code are executed on the host machine. +The NSPE of device side does not run the test codes anymore. +When the tests call the PSA client APIs, they call into the eRPC framework. +The eRPC framework communicates with the NSPE on the device, which calls into TF-M through the PSA +client APIs. + +The prototypes of the PSA client APIs are the same while the implementations are different. +Refer to the following sections for more details. + +The Stucture +============ + +The following diagram shows the software structure. + +.. figure:: media/erpc_test_framework.svg + +- eRPC Framework + + The eRPC framework system + +- eRPC Client Shim + + The eRPC generated shim layer of remote APIs for clients. + It serializes the identifier of the API and its parameters into a stream of bytes and transports + to the server through a communication channel such as UART and TCP/IP. + The codes are generated by the `erpcgen tool `_. + +- eRPC Server Shim + + The generated shim layer of the server. + It registers a callback function to the eRPC framework. + When the framework receives any requests from the client, it calls the callback function. + The callback unserializes the bytes streams to determine what API to call and then invoke it with + the corresponding parameters from the bytes streams. + And then it returns the results to the client in the reverse routine. + +- API Wrapper + + Part of the parameters of ``psa_call`` API is not supported by eRPC directly, thus an API wrapper + is required to transform the ``in_vec/out_vec`` structures to the eRPC supported data types. + The wrapper API is named as ``erpc_psa_call``. + + On the client side, the wrapper implements the ``psa_call`` which calls the ``erpc_psa_call`` in + the client shim layer. + On the server side, the wrapper implements the ``erpc_psa_call`` which is called by the shim layer. + The ``erpc_psa_call`` then calls the ``psa_call``. + +- Test Suites + + Can be the existing TF-M regression tests or any other tests that interact with TF-M using the + PSA Client APIs. + +- Host App + + Initializes the eRPC client and starts test suites. + +- Target App + + Initializes the eRPC server and listens for requests from the client. + +Supported APIs +============== + +The APIs supported for doing RPC are the PSA Client APIs because they are the lowest level APIs that +interact with TF-M. You can build lots of test suites upon them. +You can also add your own APIs in the ``tfm.erpc`` file. +Please refer to `IDL Reference `_ for the +syntax of the file. + +API Grouping +************ + +PSA client APIs are categorised into common APIs and connection-based service APIs. +Connection-based APIs are available when there are connection-based services in the TF-M. +So in the eRPC integration, the APIs are also split into two groups so that the shim layer of the +APIs can be separated into different files as well. +Then build systems can decide which source files to build based on the existence of connection-based +services. + +Common APIs: + +- psa_framework_version() +- psa_version() +- psa_call() + +Connection-based specific: + +- psa_connect() +- psa_close() + +Transportation +============== + +On device side, only UART transportation is supported in NSPE. +For the host side, both UART and TCP are supported. +The TCP transportation support is basically for fast models where UART data are transferred between +a TCP/IP socket on the host and a serial port on the target. +See the +`fast model reference guide `_ +for more details. + +******************** +Platform Integration +******************** + +First, the UART drivers of platforms shall support TX/RX control feature. +The TF-M build system provides a ``CONFIG_ENABLE_NS_UART_TX_RX_CONTROL`` option to enable or disable +the TX/RX control feature and it is disabled by default. +When the eRPC test framework is enabled, the ``CONFIG_ENABLE_NS_UART_TX_RX_CONTROL`` will be enabled +automatically. + +Secondly, platforms need to specify the UART port and driver for eRPC transportation config via +``target_cfg.h``. + +.. code-block:: + + #define ERPC_UART Driver_USART0 + +It's recommended to use a different UART to the stdio UART. +If the same UART is used for both, then the TF-M logs (both SPM and Secure Partitions) must be +disabled. +Otherwise, the eRPC transportation might fail. + +*********************** +Application Integration +*********************** + +The TF-M eRPC test framework provides two CMake libraries for integration. +One is the ``erpc_client``, the other is the ``erpc_server``. +Both include the eRPC framework, the shim layers, API wrappers and expose an initialization API +for client and server respectively. + +The initialization does not include the initialization of the transportation layer because it is use +case specific which kind of transportation is used. +So it is the client and server's responsibilities to initialize the transportation layers and pass +them to the ``erpc_client`` and ``erpc_server``. + +TF-M provides a ``app/erpc_app.c`` as the default server application which initializes the UART +transportation and starts the eRPC server. + +A config option ``CONFIG_TFM_ERPC_TEST_FRAMEWORK`` is provided to enable the eRPC framework on +device (server) side. +The default server will be built and developers only need to focus on the client application +developments. + +In summary, on the server side, you only need to build with the ``CONFIG_TFM_ERPC_TEST_FRAMEWORK`` +enabled. +On the client side, you must + +- Initializes the transportation layer using eRPC provided APIs. +- Call the initialization function provided by TF-M eRPC test framework with the transportation + instance initialized above. +- Develop the application code +- Building with CMake + + - ``add_subdirectory`` with the ``erpc/client`` + - link the ``erpc_client`` library + +There is an example at ``erpc/host_example`` for reference. + +-------------- + +*Copyright (c) 2023, Arm Limited. All rights reserved.* From dc6e81c926df63d9519795598e3adc78ea4abe75 Mon Sep 17 00:00:00 2001 From: Kevin Peng Date: Tue, 7 Mar 2023 17:29:01 +0800 Subject: [PATCH 16/22] RPC: Remove option of connection-based API The connection-based APIs are now always implemented on NS client side (eRPC Server). It is not necessary to optionally build them because the config option is set manually anyway. This patch removes the optional build and makes them built always. The grouping of the APIs are kept in case of future use. Change-Id: I798894b3e8f97f0bff336e0db185ee744ca70f87 Signed-off-by: Kevin Peng --- erpc/client/CMakeLists.txt | 2 +- erpc/server/CMakeLists.txt | 7 +------ erpc/server/erpc_server_start.c | 4 ---- 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/erpc/client/CMakeLists.txt b/erpc/client/CMakeLists.txt index 61a561d..53658aa 100644 --- a/erpc/client/CMakeLists.txt +++ b/erpc/client/CMakeLists.txt @@ -52,7 +52,7 @@ target_sources(erpc_client ${ERPC_REPO_PATH}/erpc_c/setup/erpc_setup_mbf_dynamic.cpp # Generated files ${CMAKE_CURRENT_SOURCE_DIR}/../generated_files/tfm_erpc_psa_client_api_client.cpp - $<$:${CMAKE_CURRENT_SOURCE_DIR}/../generated_files/tfm_erpc_psa_connection_api_client.cpp> + ${CMAKE_CURRENT_SOURCE_DIR}/../generated_files/tfm_erpc_psa_connection_api_client.cpp ) target_include_directories(erpc_client diff --git a/erpc/server/CMakeLists.txt b/erpc/server/CMakeLists.txt index fe61fb7..0562f7f 100644 --- a/erpc/server/CMakeLists.txt +++ b/erpc/server/CMakeLists.txt @@ -38,7 +38,7 @@ target_sources(erpc_server ${ERPC_REPO_PATH}/erpc_c/setup/erpc_server_setup.cpp # Generated files ${CMAKE_CURRENT_SOURCE_DIR}/../generated_files/tfm_erpc_psa_client_api_server.cpp - $<$:${CMAKE_CURRENT_SOURCE_DIR}/../generated_files/tfm_erpc_psa_connection_api_server.cpp> + ${CMAKE_CURRENT_SOURCE_DIR}/../generated_files/tfm_erpc_psa_connection_api_server.cpp ) target_include_directories(erpc_server @@ -57,8 +57,3 @@ target_link_libraries(erpc_server tfm_api_ns platform_ns # UART driver header and target config ) - -target_compile_definitions(erpc_server - PUBLIC - $<$:CONFIG_TFM_CONNECTION_BASED_SERVICE_API=1> -) diff --git a/erpc/server/erpc_server_start.c b/erpc/server/erpc_server_start.c index 71fc26d..4d27876 100644 --- a/erpc/server/erpc_server_start.c +++ b/erpc/server/erpc_server_start.c @@ -10,17 +10,13 @@ #include "erpc_mbf_setup.h" #include "erpc_server_setup.h" #include "tfm_erpc_psa_client_api_server.h" -#if CONFIG_TFM_CONNECTION_BASED_SERVICE_API == 1 #include "tfm_erpc_psa_connection_api_server.h" -#endif void erpc_server_start(erpc_transport_t transport) { erpc_server_init(transport, erpc_mbf_dynamic_init()); erpc_add_service_to_server(create_psa_client_api_service()); -#if CONFIG_TFM_CONNECTION_BASED_SERVICE_API == 1 erpc_add_service_to_server(create_psa_connection_api_service()); -#endif erpc_server_run(); From f5fa7a846575bc38cc63f6af5ee80f2788f8f490 Mon Sep 17 00:00:00 2001 From: Kevin Peng Date: Tue, 7 Mar 2023 17:20:03 +0800 Subject: [PATCH 17/22] Test: Remove unnecessary inclusion of IRQ test This patch removes unnecessary header file inclusion of the IRQ test suite. Change-Id: I62e02cefac0de8ff0a17d9d4db26923595d8772f Signed-off-by: Kevin Peng --- test/secure_fw/suites/spm/irq/irq_testsuite.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/secure_fw/suites/spm/irq/irq_testsuite.c b/test/secure_fw/suites/spm/irq/irq_testsuite.c index f4e92a5..8a8807a 100644 --- a/test/secure_fw/suites/spm/irq/irq_testsuite.c +++ b/test/secure_fw/suites/spm/irq/irq_testsuite.c @@ -5,12 +5,9 @@ * */ -#include "cmsis.h" #include "psa_manifest/sid.h" #include "psa/client.h" #include "test_framework.h" -#include "tfm_peripherals_def.h" -#include "tfm_plat_test.h" #include "irq_test.h" #ifdef TEST_NS_SLIH_IRQ From a663b8e2ca3c2cbb9f501cd13ffae375b73cc9bb Mon Sep 17 00:00:00 2001 From: Kevin Peng Date: Tue, 7 Mar 2023 17:23:32 +0800 Subject: [PATCH 18/22] Test: Remove unnecessary lib link for NS ITS suite Change-Id: I8d7b137f319dc4b2f145de5ed9ae1eb0668579ea Signed-off-by: Kevin Peng --- test/secure_fw/suites/its/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/secure_fw/suites/its/CMakeLists.txt b/test/secure_fw/suites/its/CMakeLists.txt index a7796bf..8b10a90 100644 --- a/test/secure_fw/suites/its/CMakeLists.txt +++ b/test/secure_fw/suites/its/CMakeLists.txt @@ -38,8 +38,6 @@ if (TEST_NS_ITS) PRIVATE tfm_config tfm_test_framework_ns - CMSIS_5_tfm_ns - platform_region_defs ) target_link_libraries(tfm_ns_tests From 4294da44e945ebf461e30e75819a301feffd55f5 Mon Sep 17 00:00:00 2001 From: Xinyu Zhang Date: Mon, 27 Mar 2023 11:21:11 +0800 Subject: [PATCH 19/22] FLIH: Use WFI for busy wait For energy efficiency, it is recommanded to use WFI for busy wait. Signed-off-by: Xinyu Zhang Change-Id: Ia4c4c77300c7cfcb2aaba616a8b601f5e09a0b8b --- .../suites/spm/common/service/tfm_irq_test_service.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/secure_fw/suites/spm/common/service/tfm_irq_test_service.c b/test/secure_fw/suites/spm/common/service/tfm_irq_test_service.c index 13a645e..219e3aa 100644 --- a/test/secure_fw/suites/spm/common/service/tfm_irq_test_service.c +++ b/test/secure_fw/suites/spm/common/service/tfm_irq_test_service.c @@ -5,6 +5,7 @@ * */ +#include "cmsis_compiler.h" #include "spm_test_defs.h" #include "tfm_irq_test_service.h" #include "tfm_plat_test.h" @@ -58,7 +59,10 @@ void flih_test_case_1(const psa_msg_t *msg, psa_signal_t timer_irq_signal) tfm_plat_test_secure_timer_start(); - while (flih_timer_triggered < 10); + while (flih_timer_triggered < 10) { + __WFI(); + } + tfm_plat_test_secure_timer_stop(); psa_irq_disable(timer_irq_signal); From 7cf20ef136068907953f78c6749269f7c5fe1cd8 Mon Sep 17 00:00:00 2001 From: Kevin Peng Date: Mon, 27 Mar 2023 15:29:58 +0800 Subject: [PATCH 20/22] Build: Take NULL string as NOT DEFINED for PSA_API_TEST_TARGET This is because the Kconfig system will generate a NULL string for PSA_API_TEST_TARGET by default, which is equal to "NOT DEFINED". Change-Id: I3766cb4a08c9d9e9c6f262e3e2df842394e2f58b Signed-off-by: Kevin Peng --- app/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 449cbc5..3a3ee09 100755 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -134,7 +134,7 @@ if(TEST_PSA_API AND NOT PSA_ARCH_TESTS_BINARY_PATH) set(SUITE ${TEST_PSA_API}) endif() - if (NOT DEFINED PSA_API_TEST_TARGET) + if (NOT DEFINED PSA_API_TEST_TARGET OR PSA_API_TEST_TARGET STREQUAL "") string(REGEX REPLACE ".*/" "" PSA_API_TEST_TARGET ${TFM_PLATFORM}) endif() From b84b9b8bae2d7915d9419cae8f2b51fdb49585d6 Mon Sep 17 00:00:00 2001 From: Kevin Peng Date: Fri, 14 Apr 2023 13:46:13 +0800 Subject: [PATCH 21/22] RPC: Update the host example document Change-Id: I33d8fc1ca7d91c126f17be0c7f49ddbebbbc4d93 Signed-off-by: Kevin Peng --- erpc/host_example/README.rst | 43 +++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/erpc/host_example/README.rst b/erpc/host_example/README.rst index d0e25f1..e516e2b 100644 --- a/erpc/host_example/README.rst +++ b/erpc/host_example/README.rst @@ -2,9 +2,9 @@ eRPC Host ********* -This host example is only tested for Linux. +This host example is only tested on Linux machine with Musca-S1 and AN521 FVP. -Example: UART Transportation on Musca_S1 +Example: UART Transportation on Musca-S1 ======================================== Build instructions on the target @@ -13,25 +13,38 @@ Build instructions on the target .. code-block:: bash cd - cmake -G"Unix Makefiles" -S . -B cmake_build -DTFM_PLATFORM=musca_s1 -DTFM_TOOLCHAIN_FILE=toolchain_GNUARM.cmake -DCMAKE_BUILD_TYPE=Debug -DCONFIG_TFM_ERPC_TEST_FRAMEWORK=ON -DTFM_PARTITION_CRYPTO=ON -DTFM_PARTITION_INTERNAL_TRUSTED_STORAGE=ON ../ + cmake -G"Unix Makefiles" -S . -B cmake_build -DTFM_PLATFORM=musca_s1 \ + -DCONFIG_TFM_ERPC_TEST_FRAMEWORK=ON -DTFM_PARTITION_CRYPTO=ON -DTFM_PARTITION_INTERNAL_TRUSTED_STORAGE=ON \ + -DTFM_SPM_LOG_LEVEL=TFM_SPM_LOG_LEVEL_SILENCE -DTFM_PARTITION_LOG_LEVEL=TFM_PARTITION_LOG_LEVEL_SILENCE \ + -DMCUBOOT_LOG_LEVEL=OFF ../ cmake --build cmake_build/ -- install -j32 +.. Note:: + All the logs must be disabled to avoid interferences between logs and eRPC transportation as + they share the same UART device. + Otherwise, the RPC test framework may not work. + This might only happen on platforms using the same UART devices. + Build instructions on the host ------------------------------ .. code-block:: bash cd /erpc/host_example - cmake -S . -B build -G "Unix Makefiles" -DTFM_INSTALL_PATH= -DERPC_REPO_PATH= -DERPC_TRANSPORT=UART -DPORT_NAME="/dev/ttyACM0" + cmake -S . -B build -G "Unix Makefiles" -DTFM_INSTALL_PATH= -DERPC_REPO_PATH= \ + -DERPC_TRANSPORT=UART -DPORT_NAME="/dev/ttyACM0" cmake --build build/ -Run instructions on the host ----------------------------- +Run instructions +---------------- -.. code-block:: bash +- Flash the image to the device and boot it up. +- Start the host example - cd /erpc/host_example - ./build/erpc_main + .. code-block:: bash + + cd /erpc/host_example + ./build/erpc_main Example: TCP Transportation on AN521 FVP ======================================== @@ -42,7 +55,8 @@ Build instructions on the target .. code-block:: bash cd - cmake -G"Unix Makefiles" -S . -B cmake_build -DTFM_PLATFORM=an521 -DTFM_TOOLCHAIN_FILE=toolchain_GNUARM.cmake -DCMAKE_BUILD_TYPE=Debug -DCONFIG_TFM_ERPC_TEST_FRAMEWORK=ON -DTFM_PARTITION_CRYPTO=ON -DTFM_PARTITION_INTERNAL_TRUSTED_STORAGE=ON ../ + cmake -G"Unix Makefiles" -S . -B cmake_build -DTFM_PLATFORM=an521 \ + -DCONFIG_TFM_ERPC_TEST_FRAMEWORK=ON -DTFM_PARTITION_CRYPTO=ON -DTFM_PARTITION_INTERNAL_TRUSTED_STORAGE=ON ../ cmake --build cmake_build/ -- install -j32 Build instructions on the host @@ -51,11 +65,12 @@ Build instructions on the host .. code-block:: bash cd /erpc/host_example - cmake -S . -B build -G "Unix Makefiles" -DTFM_INSTALL_PATH= -DERPC_REPO_PATH= -DERPC_TRANSPORT=TCP -DERPC_HOST="0.0.0.0" -DERPC_PORT=5001 + cmake -S . -B build -G "Unix Makefiles" -DTFM_INSTALL_PATH= -DERPC_REPO_PATH= \ + -DERPC_TRANSPORT=TCP -DERPC_HOST="0.0.0.0" -DERPC_PORT=5001 cmake --build build/ -Run instructions on the host ----------------------------- +Run instructions +---------------- Start the AN521 FVP: @@ -82,6 +97,8 @@ Start the AN521 FVP: --data cpu0=@0x10080000 \ -M 1 +Start the host example + .. code-block:: bash cd /erpc/host_example From 1273c5bcd3d8ade60d51524797e0b22b6fd7eea1 Mon Sep 17 00:00:00 2001 From: Michel Jaouen Date: Thu, 13 Apr 2023 15:48:34 +0200 Subject: [PATCH 22/22] Test: BL2: Fix to support encrypted image This fix applies for boards supporting encrypted image, and initializing board with an encrypted image in secondary slot. Change-Id: I2f802e22e6ed581a6cd0110e6ba5dccfc1f1092f Signed-off-by: Michel Jaouen --- .../suites/integration/mcuboot_integration_tests.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/bl2/mcuboot/suites/integration/mcuboot_integration_tests.c b/test/bl2/mcuboot/suites/integration/mcuboot_integration_tests.c index da11fdd..c326fd9 100644 --- a/test/bl2/mcuboot/suites/integration/mcuboot_integration_tests.c +++ b/test/bl2/mcuboot/suites/integration/mcuboot_integration_tests.c @@ -156,9 +156,11 @@ static int test_setup(int *original_image_idx) } else { return 0; } - } else if (hdr_1.ih_magic == IMAGE_MAGIC) { + } else if ((hdr_1.ih_magic == IMAGE_MAGIC) && + !(hdr_1.ih_flags & (IMAGE_F_ENCRYPTED_AES128 | IMAGE_F_ENCRYPTED_AES256))) { /* Else copy slot 1 to slot 0. We assume that one of the slots has a - * valid image. + * valid image, but if image is valid but encrypted , it cannot be + * recopied in primary slot. */ *original_image_idx = 1; rc = copy_image_to_slot(1, 0); @@ -168,7 +170,7 @@ static int test_setup(int *original_image_idx) return 0; } } else { - /* No valid images are loaded, error */ + /* No valid unencrypted images are loaded, error */ return 1; } }