diff options
author | Xinyu Zhang <xinyu.zhang@arm.com> | 2021-03-18 16:20:54 +0800 |
---|---|---|
committer | Ken Liu <ken.liu@arm.com> | 2021-04-28 07:51:28 +0200 |
commit | ade2e0a3a339ae1c165cbe3bfe5171636ac798a7 (patch) | |
tree | 21da67764faa0fd19d02e01a35b4d2a02729f9b2 | |
parent | e99f95f5a0b704ae5daac9a465f008889b4f9400 (diff) | |
download | trusted-firmware-m-ade2e0a3a339ae1c165cbe3bfe5171636ac798a7.tar.gz |
Unify to use ARRAY_SIZE in TF-M codes
ARRAY_SIZE(foo) is preferred over sizeof(foo)/sizeof(foo[0]).
Signed-off-by: Xinyu Zhang <xinyu.zhang@arm.com>
Change-Id: I6d95ceece2edc6267491923e282e28710b68ab8d
26 files changed, 90 insertions, 81 deletions
diff --git a/interface/include/psa/client.h b/interface/include/psa/client.h index 8fd2d13674..d92de026f2 100644 --- a/interface/include/psa/client.h +++ b/interface/include/psa/client.h @@ -17,6 +17,10 @@ extern "C" { #endif +#ifndef IOVEC_LEN +#define IOVEC_LEN(arr) ((uint32_t)(sizeof(arr)/sizeof(arr[0]))) +#endif + /*********************** PSA Client Macros and Types *************************/ /** diff --git a/interface/src/tfm_audit_func_api.c b/interface/src/tfm_audit_func_api.c index 3439635020..4141970a69 100644 --- a/interface/src/tfm_audit_func_api.c +++ b/interface/src/tfm_audit_func_api.c @@ -1,29 +1,28 @@ /* - * Copyright (c) 2018-2019, Arm Limited. All rights reserved. + * Copyright (c) 2018-2021, Arm Limited. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * */ +#include "psa/client.h" #include "psa_audit_api.h" #include "tfm_veneers.h" #include "tfm_ns_interface.h" -#define ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0])) - #define API_DISPATCH(sfn_name) \ tfm_ns_interface_dispatch((veneer_fn)tfm_##sfn_name##_veneer, \ - (uint32_t)in_vec, (uint32_t)ARRAY_SIZE(in_vec), \ - (uint32_t)out_vec, (uint32_t)ARRAY_SIZE(out_vec)) + (uint32_t)in_vec, IOVEC_LEN(in_vec), \ + (uint32_t)out_vec, IOVEC_LEN(out_vec)) #define API_DISPATCH_NO_INVEC(sfn_name) \ tfm_ns_interface_dispatch((veneer_fn)tfm_##sfn_name##_veneer, \ (uint32_t)NULL, 0, \ - (uint32_t)out_vec, (uint32_t)ARRAY_SIZE(out_vec)) + (uint32_t)out_vec, IOVEC_LEN(out_vec)) #define API_DISPATCH_NO_OUTVEC(sfn_name) \ tfm_ns_interface_dispatch((veneer_fn)tfm_##sfn_name##_veneer, \ - (uint32_t)in_vec, (uint32_t)ARRAY_SIZE(in_vec), \ + (uint32_t)in_vec, IOVEC_LEN(in_vec), \ (uint32_t)NULL, 0) psa_status_t psa_audit_retrieve_record(const uint32_t record_index, diff --git a/interface/src/tfm_crypto_func_api.c b/interface/src/tfm_crypto_func_api.c index dd6a90a9ff..328699715a 100644 --- a/interface/src/tfm_crypto_func_api.c +++ b/interface/src/tfm_crypto_func_api.c @@ -5,21 +5,20 @@ * */ +#include "psa/client.h" #include "tfm_veneers.h" #include "tfm_crypto_defs.h" #include "psa/crypto.h" #include "tfm_ns_interface.h" -#define ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0])) - #define API_DISPATCH(sfn_name, sfn_id) \ tfm_ns_interface_dispatch((veneer_fn)tfm_##sfn_name##_veneer,\ - (uint32_t)in_vec, ARRAY_SIZE(in_vec), \ - (uint32_t)out_vec, ARRAY_SIZE(out_vec)) + (uint32_t)in_vec, IOVEC_LEN(in_vec), \ + (uint32_t)out_vec, IOVEC_LEN(out_vec)) #define API_DISPATCH_NO_OUTVEC(sfn_name, sfn_id) \ tfm_ns_interface_dispatch((veneer_fn)tfm_##sfn_name##_veneer,\ - (uint32_t)in_vec, ARRAY_SIZE(in_vec), \ + (uint32_t)in_vec, IOVEC_LEN(in_vec), \ (uint32_t)NULL, 0) psa_status_t psa_crypto_init(void) diff --git a/interface/src/tfm_crypto_ipc_api.c b/interface/src/tfm_crypto_ipc_api.c index a89dd2b9ca..b5f59c2217 100644 --- a/interface/src/tfm_crypto_ipc_api.c +++ b/interface/src/tfm_crypto_ipc_api.c @@ -11,8 +11,6 @@ #include "psa_manifest/sid.h" #include "psa/client.h" -#define ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0])) - #define PSA_CONNECT(service) \ psa_handle_t ipc_handle; \ ipc_handle = psa_connect(service##_SID, service##_VERSION); \ @@ -24,12 +22,12 @@ #define API_DISPATCH(sfn_name, sfn_id) \ psa_call(ipc_handle, PSA_IPC_CALL, \ - in_vec, ARRAY_SIZE(in_vec), \ - out_vec, ARRAY_SIZE(out_vec)) + in_vec, IOVEC_LEN(in_vec), \ + out_vec, IOVEC_LEN(out_vec)) #define API_DISPATCH_NO_OUTVEC(sfn_name, sfn_id) \ psa_call(ipc_handle, PSA_IPC_CALL, \ - in_vec, ARRAY_SIZE(in_vec), \ + in_vec, IOVEC_LEN(in_vec), \ (psa_outvec *)NULL, 0) psa_status_t psa_crypto_init(void) @@ -947,12 +945,12 @@ psa_status_t psa_aead_encrypt(psa_key_id_t key, PSA_CONNECT(TFM_CRYPTO); - size_t in_len = ARRAY_SIZE(in_vec); + size_t in_len = IOVEC_LEN(in_vec); if (additional_data == NULL) { in_len--; } status = psa_call(ipc_handle, PSA_IPC_CALL, in_vec, in_len, - out_vec, ARRAY_SIZE(out_vec)); + out_vec, IOVEC_LEN(out_vec)); *ciphertext_length = out_vec[0].len; @@ -1008,12 +1006,12 @@ psa_status_t psa_aead_decrypt(psa_key_id_t key, PSA_CONNECT(TFM_CRYPTO); - size_t in_len = ARRAY_SIZE(in_vec); + size_t in_len = IOVEC_LEN(in_vec); if (additional_data == NULL) { in_len--; } status = psa_call(ipc_handle, PSA_IPC_CALL, in_vec, in_len, - out_vec, ARRAY_SIZE(out_vec)); + out_vec, IOVEC_LEN(out_vec)); *plaintext_length = out_vec[0].len; @@ -1142,12 +1140,12 @@ psa_status_t psa_asymmetric_encrypt(psa_key_id_t key, PSA_CONNECT(TFM_CRYPTO); - size_t in_len = ARRAY_SIZE(in_vec); + size_t in_len = IOVEC_LEN(in_vec); if (salt == NULL) { in_len--; } status = psa_call(ipc_handle, PSA_IPC_CALL, in_vec, in_len, - out_vec, ARRAY_SIZE(out_vec)); + out_vec, IOVEC_LEN(out_vec)); *output_length = out_vec[0].len; @@ -1190,12 +1188,12 @@ psa_status_t psa_asymmetric_decrypt(psa_key_id_t key, PSA_CONNECT(TFM_CRYPTO); - size_t in_len = ARRAY_SIZE(in_vec); + size_t in_len = IOVEC_LEN(in_vec); if (salt == NULL) { in_len--; } status = psa_call(ipc_handle, PSA_IPC_CALL, in_vec, in_len, - out_vec, ARRAY_SIZE(out_vec)); + out_vec, IOVEC_LEN(out_vec)); *output_length = out_vec[0].len; diff --git a/interface/src/tfm_firmware_update_func_api.c b/interface/src/tfm_firmware_update_func_api.c index b8d35413b2..1d34d03124 100644 --- a/interface/src/tfm_firmware_update_func_api.c +++ b/interface/src/tfm_firmware_update_func_api.c @@ -5,14 +5,12 @@ * */ +#include "psa/client.h" #include "psa/update.h" #include "tfm_api.h" - #include "tfm_ns_interface.h" #include "tfm_veneers.h" -#define IOVEC_LEN(x) (uint32_t)(sizeof(x)/sizeof(x[0])) - psa_status_t psa_fwu_write(uint32_t image_id, size_t block_offset, const void *block, diff --git a/interface/src/tfm_firmware_update_ipc_api.c b/interface/src/tfm_firmware_update_ipc_api.c index 0118488f57..a21a3339fa 100644 --- a/interface/src/tfm_firmware_update_ipc_api.c +++ b/interface/src/tfm_firmware_update_ipc_api.c @@ -5,13 +5,10 @@ * */ -#include "psa/update.h" -#include "tfm_api.h" - #include "psa/client.h" +#include "psa/update.h" #include "psa_manifest/sid.h" - -#define IOVEC_LEN(x) (uint32_t)(sizeof(x)/sizeof(x[0])) +#include "tfm_api.h" psa_status_t psa_fwu_write(const psa_image_id_t image_id, size_t block_offset, diff --git a/interface/src/tfm_initial_attestation_func_api.c b/interface/src/tfm_initial_attestation_func_api.c index 5efe9040cf..48dbbe183f 100644 --- a/interface/src/tfm_initial_attestation_func_api.c +++ b/interface/src/tfm_initial_attestation_func_api.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, Arm Limited. All rights reserved. + * Copyright (c) 2018-2021, Arm Limited. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * @@ -11,8 +11,6 @@ #include "psa/client.h" #include "psa/crypto_types.h" -#define IOVEC_LEN(x) (sizeof(x)/sizeof(x[0])) - psa_status_t psa_initial_attest_get_token(const uint8_t *auth_challenge, size_t challenge_size, diff --git a/interface/src/tfm_initial_attestation_ipc_api.c b/interface/src/tfm_initial_attestation_ipc_api.c index b4a8f379e3..fa7a956bd1 100644 --- a/interface/src/tfm_initial_attestation_ipc_api.c +++ b/interface/src/tfm_initial_attestation_ipc_api.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, Arm Limited. All rights reserved. + * Copyright (c) 2018-2021, Arm Limited. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * @@ -11,8 +11,6 @@ #include "psa/crypto_types.h" #include "psa_manifest/sid.h" -#define IOVEC_LEN(x) (sizeof(x)/sizeof(x[0])) - psa_status_t psa_initial_attest_get_token(const uint8_t *auth_challenge, size_t challenge_size, diff --git a/interface/src/tfm_its_func_api.c b/interface/src/tfm_its_func_api.c index 483cbee790..b554a34573 100644 --- a/interface/src/tfm_its_func_api.c +++ b/interface/src/tfm_its_func_api.c @@ -1,18 +1,16 @@ /* - * Copyright (c) 2019, Arm Limited. All rights reserved. + * Copyright (c) 2019-2021, Arm Limited. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * */ +#include "psa/client.h" #include "psa/internal_trusted_storage.h" #include "tfm_api.h" - #include "tfm_ns_interface.h" #include "tfm_veneers.h" -#define IOVEC_LEN(x) (sizeof(x)/sizeof(x[0])) - psa_status_t psa_its_set(psa_storage_uid_t uid, size_t data_length, const void *p_data, diff --git a/interface/src/tfm_its_ipc_api.c b/interface/src/tfm_its_ipc_api.c index 8ad4a3bbb3..543b88f3d1 100644 --- a/interface/src/tfm_its_ipc_api.c +++ b/interface/src/tfm_its_ipc_api.c @@ -1,17 +1,14 @@ /* - * Copyright (c) 2019, Arm Limited. All rights reserved. + * Copyright (c) 2019-2021, Arm Limited. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * */ -#include "psa/internal_trusted_storage.h" -#include "tfm_api.h" - #include "psa/client.h" +#include "psa/internal_trusted_storage.h" #include "psa_manifest/sid.h" - -#define IOVEC_LEN(x) (sizeof(x)/sizeof(x[0])) +#include "tfm_api.h" psa_status_t psa_its_set(psa_storage_uid_t uid, size_t data_length, diff --git a/interface/src/tfm_ps_func_api.c b/interface/src/tfm_ps_func_api.c index d3c53a4009..4674a350a1 100644 --- a/interface/src/tfm_ps_func_api.c +++ b/interface/src/tfm_ps_func_api.c @@ -1,17 +1,15 @@ /* - * Copyright (c) 2017-2020, Arm Limited. All rights reserved. + * Copyright (c) 2017-2021, Arm Limited. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * */ +#include "psa/client.h" #include "psa/protected_storage.h" - #include "tfm_ns_interface.h" #include "tfm_veneers.h" -#define IOVEC_LEN(x) (uint32_t)(sizeof(x)/sizeof(x[0])) - psa_status_t psa_ps_set(psa_storage_uid_t uid, size_t data_length, const void *p_data, diff --git a/interface/src/tfm_ps_ipc_api.c b/interface/src/tfm_ps_ipc_api.c index 4f937db2d0..106917e9bc 100644 --- a/interface/src/tfm_ps_ipc_api.c +++ b/interface/src/tfm_ps_ipc_api.c @@ -1,16 +1,14 @@ /* - * Copyright (c) 2017-2020, Arm Limited. All rights reserved. + * Copyright (c) 2017-2021, Arm Limited. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * */ +#include "psa/client.h" #include "psa/protected_storage.h" - -#include "tfm_ns_interface.h" #include "psa_manifest/sid.h" - -#define IOVEC_LEN(x) (uint32_t)(sizeof(x)/sizeof(x[0])) +#include "tfm_ns_interface.h" psa_status_t psa_ps_set(psa_storage_uid_t uid, size_t data_length, diff --git a/secure_fw/include/tfm/array.h b/secure_fw/include/tfm/array.h new file mode 100644 index 0000000000..ecf7a068b0 --- /dev/null +++ b/secure_fw/include/tfm/array.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2021, Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + * + */ + +#ifndef __ARRAY_H__ +#define __ARRAY_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0])) +#endif + +#ifndef IOVEC_LEN +#define IOVEC_LEN(x) (uint32_t)ARRAY_SIZE(x) +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* __ARRAY_H__ */ diff --git a/secure_fw/partitions/audit_logging/tfm_audit_secure_api.c b/secure_fw/partitions/audit_logging/tfm_audit_secure_api.c index ad54d7b063..098333a262 100644 --- a/secure_fw/partitions/audit_logging/tfm_audit_secure_api.c +++ b/secure_fw/partitions/audit_logging/tfm_audit_secure_api.c @@ -1,15 +1,14 @@ /* - * Copyright (c) 2018-2020, Arm Limited. All rights reserved. + * Copyright (c) 2018-2021, Arm Limited. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * */ +#include "array.h" #include "psa_audit_api.h" #include "tfm_veneers.h" -#define ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0])) - #define API_DISPATCH(sfn_name) \ tfm_##sfn_name##_veneer( \ in_vec, ARRAY_SIZE(in_vec), \ diff --git a/secure_fw/partitions/crypto/tfm_crypto_secure_api.c b/secure_fw/partitions/crypto/tfm_crypto_secure_api.c index d7ae1374f8..1c136d1d03 100644 --- a/secure_fw/partitions/crypto/tfm_crypto_secure_api.c +++ b/secure_fw/partitions/crypto/tfm_crypto_secure_api.c @@ -5,6 +5,7 @@ * */ +#include "array.h" #include "tfm_veneers.h" #include "tfm_crypto_defs.h" #include "psa/crypto.h" @@ -12,8 +13,6 @@ #include "psa_manifest/sid.h" #endif -#define ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0])) - #ifdef TFM_PSA_API #include "psa/client.h" diff --git a/secure_fw/partitions/firmware_update/CMakeLists.txt b/secure_fw/partitions/firmware_update/CMakeLists.txt index 360d44ea5f..861e3d1329 100644 --- a/secure_fw/partitions/firmware_update/CMakeLists.txt +++ b/secure_fw/partitions/firmware_update/CMakeLists.txt @@ -15,6 +15,8 @@ cmake_policy(SET CMP0079 NEW) add_library(tfm_psa_rot_partition_fwu STATIC) target_include_directories(tfm_psa_rot_partition_fwu + INTERFACE + ${CMAKE_SOURCE_DIR}/secure_fw/include/tfm PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> ${CMAKE_BINARY_DIR}/generated/secure_fw/partitions/firmware_update diff --git a/secure_fw/partitions/firmware_update/tfm_fwu_secure_api.c b/secure_fw/partitions/firmware_update/tfm_fwu_secure_api.c index de4f45c2f6..a1663b4cf1 100644 --- a/secure_fw/partitions/firmware_update/tfm_fwu_secure_api.c +++ b/secure_fw/partitions/firmware_update/tfm_fwu_secure_api.c @@ -5,6 +5,7 @@ * */ +#include "array.h" #include "psa/update.h" #include "tfm_api.h" @@ -15,8 +16,6 @@ #include "tfm_veneers.h" #endif -#define IOVEC_LEN(x) (uint32_t)(sizeof(x)/sizeof(x[0])) - psa_status_t psa_fwu_write(uint32_t image_id, size_t block_offset, const void *block, diff --git a/secure_fw/partitions/initial_attestation/tfm_attest_req_mngr.c b/secure_fw/partitions/initial_attestation/tfm_attest_req_mngr.c index 6f022eecbd..c2fdbd4b69 100644 --- a/secure_fw/partitions/initial_attestation/tfm_attest_req_mngr.c +++ b/secure_fw/partitions/initial_attestation/tfm_attest_req_mngr.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020, Arm Limited. All rights reserved. + * Copyright (c) 2019-2021, Arm Limited. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * @@ -11,13 +11,13 @@ #include "attest.h" #ifdef TFM_PSA_API -#include "psa_manifest/tfm_initial_attestation.h" +#include "array.h" #include "psa/client.h" #include "psa/service.h" +#include "psa_manifest/tfm_initial_attestation.h" #include "region_defs.h" #define ECC_P256_PUBLIC_KEY_SIZE PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(256) -#define IOVEC_LEN(x) (sizeof(x)/sizeof(x[0])) typedef psa_status_t (*attest_func_t)(const psa_msg_t *msg); diff --git a/secure_fw/partitions/initial_attestation/tfm_attest_secure_api.c b/secure_fw/partitions/initial_attestation/tfm_attest_secure_api.c index fbbaf98e45..8b0e6ee772 100644 --- a/secure_fw/partitions/initial_attestation/tfm_attest_secure_api.c +++ b/secure_fw/partitions/initial_attestation/tfm_attest_secure_api.c @@ -1,10 +1,11 @@ /* - * Copyright (c) 2018-2020, Arm Limited. All rights reserved. + * Copyright (c) 2018-2021, Arm Limited. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * */ +#include "array.h" #include "psa/initial_attestation.h" #include "psa/client.h" #include "tfm_veneers.h" @@ -15,8 +16,6 @@ #endif #include <string.h> -#define IOVEC_LEN(x) (sizeof(x)/sizeof(x[0])) - psa_status_t psa_initial_attest_get_token(const uint8_t *auth_challenge, size_t challenge_size, diff --git a/secure_fw/partitions/internal_trusted_storage/tfm_its_secure_api.c b/secure_fw/partitions/internal_trusted_storage/tfm_its_secure_api.c index 4e02a9b1f8..260d4aa792 100644 --- a/secure_fw/partitions/internal_trusted_storage/tfm_its_secure_api.c +++ b/secure_fw/partitions/internal_trusted_storage/tfm_its_secure_api.c @@ -1,10 +1,11 @@ /* - * Copyright (c) 2019-2020, Arm Limited. All rights reserved. + * Copyright (c) 2019-2021, Arm Limited. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * */ +#include "array.h" #include "psa/internal_trusted_storage.h" #include "tfm_api.h" @@ -15,8 +16,6 @@ #include "tfm_veneers.h" #endif -#define IOVEC_LEN(x) (sizeof(x)/sizeof(x[0])) - psa_status_t psa_its_set(psa_storage_uid_t uid, size_t data_length, const void *p_data, diff --git a/secure_fw/partitions/lib/sprt/CMakeLists.txt b/secure_fw/partitions/lib/sprt/CMakeLists.txt index 1cac798567..35f8f43b33 100644 --- a/secure_fw/partitions/lib/sprt/CMakeLists.txt +++ b/secure_fw/partitions/lib/sprt/CMakeLists.txt @@ -12,6 +12,7 @@ add_library(tfm_sprt STATIC) target_include_directories(tfm_sprt PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> + ${CMAKE_SOURCE_DIR}/secure_fw/include/tfm ) target_sources(tfm_sprt diff --git a/secure_fw/partitions/protected_storage/tfm_ps_secure_api.c b/secure_fw/partitions/protected_storage/tfm_ps_secure_api.c index abfdd6488d..b9a45c640d 100644 --- a/secure_fw/partitions/protected_storage/tfm_ps_secure_api.c +++ b/secure_fw/partitions/protected_storage/tfm_ps_secure_api.c @@ -1,18 +1,17 @@ /* - * Copyright (c) 2018-2020, Arm Limited. All rights reserved. + * Copyright (c) 2018-2021, Arm Limited. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * */ +#include "array.h" #include "psa/protected_storage.h" #include "tfm_veneers.h" #ifdef TFM_PSA_API #include "psa_manifest/sid.h" #endif -#define IOVEC_LEN(x) (sizeof(x)/sizeof(x[0])) - psa_status_t psa_ps_set(psa_storage_uid_t uid, size_t data_length, const void *p_data, diff --git a/secure_fw/spm/CMakeLists.txt b/secure_fw/spm/CMakeLists.txt index 67363d08bc..3803a357f4 100755 --- a/secure_fw/spm/CMakeLists.txt +++ b/secure_fw/spm/CMakeLists.txt @@ -24,6 +24,7 @@ target_include_directories(tfm_spm $<$<NOT:$<BOOL:${TFM_PSA_API}>>:${CMAKE_CURRENT_SOURCE_DIR}/cmsis_func/include> PRIVATE ${CMAKE_SOURCE_DIR} + ${CMAKE_SOURCE_DIR}/secure_fw/include/tfm ${CMAKE_BINARY_DIR}/generated $<$<BOOL:${TFM_PSA_API}>:${CMAKE_BINARY_DIR}/generated/secure_fw/spm/cmsis_psa> $<$<NOT:$<BOOL:${TFM_PSA_API}>>:${CMAKE_BINARY_DIR}/generated/secure_fw/spm/cmsis_func> diff --git a/secure_fw/spm/cmsis_func/tfm_spm_db_func.inc.template b/secure_fw/spm/cmsis_func/tfm_spm_db_func.inc.template index 904424959c..35dda5d582 100644 --- a/secure_fw/spm/cmsis_func/tfm_spm_db_func.inc.template +++ b/secure_fw/spm/cmsis_func/tfm_spm_db_func.inc.template @@ -10,6 +10,7 @@ #ifndef __TFM_SPM_DB_FUNC_INC__ #define __TFM_SPM_DB_FUNC_INC__ +#include "array.h" #include "psa_manifest/sid.h" {# Produce a build error if heap_size is presented in the manifest, because of the dynamic memory allocation is not supported now. #} @@ -250,7 +251,7 @@ static struct spm_partition_desc_t partition_list [] = struct spm_partition_db_t g_spm_partition_db = { .is_init = 0, - .partition_count = sizeof(partition_list) / sizeof(partition_list[0]), + .partition_count = ARRAY_SIZE(partition_list), .running_partition_idx = 0, .partitions = partition_list, }; diff --git a/secure_fw/spm/cmsis_psa/tfm_spm_db_ipc.inc.template b/secure_fw/spm/cmsis_psa/tfm_spm_db_ipc.inc.template index ad9e8a1d9c..45a1f71637 100644 --- a/secure_fw/spm/cmsis_psa/tfm_spm_db_ipc.inc.template +++ b/secure_fw/spm/cmsis_psa/tfm_spm_db_ipc.inc.template @@ -10,6 +10,7 @@ #ifndef __TFM_SPM_DB_IPC_INC__ #define __TFM_SPM_DB_IPC_INC__ +#include "array.h" #include "psa_manifest/sid.h" {# Produce a build error if heap_size is presented in the manifest, because of the dynamic memory allocation is not supported now. #} @@ -228,7 +229,7 @@ static struct partition_t partition_list [] = }; struct spm_partition_db_t g_spm_partition_db = { - .partition_count = sizeof(partition_list) / sizeof(partition_list[0]), + .partition_count = ARRAY_SIZE(partition_list), .partitions = partition_list, }; diff --git a/secure_fw/spm/ffm/tfm_boot_data.c b/secure_fw/spm/ffm/tfm_boot_data.c index b2115f5e62..8003f2140a 100644 --- a/secure_fw/spm/ffm/tfm_boot_data.c +++ b/secure_fw/spm/ffm/tfm_boot_data.c @@ -6,6 +6,7 @@ */ #include <stdint.h> +#include "array.h" #include "tfm_boot_status.h" #include "region_defs.h" #include "tfm_memory_utils.h" @@ -84,8 +85,7 @@ static int32_t tfm_core_check_boot_data_access_policy(uint8_t major_type) uint32_t partition_id; uint32_t i; int32_t rc = -1; - const uint32_t array_size = - sizeof(access_policy_table) / sizeof(access_policy_table[0]); + const uint32_t array_size = ARRAY_SIZE(access_policy_table); #ifndef TFM_PSA_API uint32_t partition_idx = tfm_spm_partition_get_running_partition_idx(); |