aboutsummaryrefslogtreecommitdiff
path: root/secure_fw
diff options
context:
space:
mode:
authorXinyu Zhang <xinyu.zhang@arm.com>2021-03-18 16:20:54 +0800
committerKen Liu <ken.liu@arm.com>2021-04-28 07:51:28 +0200
commitade2e0a3a339ae1c165cbe3bfe5171636ac798a7 (patch)
tree21da67764faa0fd19d02e01a35b4d2a02729f9b2 /secure_fw
parente99f95f5a0b704ae5daac9a465f008889b4f9400 (diff)
downloadtrusted-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
Diffstat (limited to 'secure_fw')
-rw-r--r--secure_fw/include/tfm/array.h27
-rw-r--r--secure_fw/partitions/audit_logging/tfm_audit_secure_api.c5
-rw-r--r--secure_fw/partitions/crypto/tfm_crypto_secure_api.c3
-rw-r--r--secure_fw/partitions/firmware_update/CMakeLists.txt2
-rw-r--r--secure_fw/partitions/firmware_update/tfm_fwu_secure_api.c3
-rw-r--r--secure_fw/partitions/initial_attestation/tfm_attest_req_mngr.c6
-rw-r--r--secure_fw/partitions/initial_attestation/tfm_attest_secure_api.c5
-rw-r--r--secure_fw/partitions/internal_trusted_storage/tfm_its_secure_api.c5
-rw-r--r--secure_fw/partitions/lib/sprt/CMakeLists.txt1
-rw-r--r--secure_fw/partitions/protected_storage/tfm_ps_secure_api.c5
-rwxr-xr-xsecure_fw/spm/CMakeLists.txt1
-rw-r--r--secure_fw/spm/cmsis_func/tfm_spm_db_func.inc.template3
-rw-r--r--secure_fw/spm/cmsis_psa/tfm_spm_db_ipc.inc.template3
-rw-r--r--secure_fw/spm/ffm/tfm_boot_data.c4
14 files changed, 50 insertions, 23 deletions
diff --git a/secure_fw/include/tfm/array.h b/secure_fw/include/tfm/array.h
new file mode 100644
index 000000000..ecf7a068b
--- /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 ad54d7b06..098333a26 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 d7ae1374f..1c136d1d0 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 360d44ea5..861e3d132 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 de4f45c2f..a1663b4cf 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 6f022eecb..c2fdbd4b6 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 fbbaf98e4..8b0e6ee77 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 4e02a9b1f..260d4aa79 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 1cac79856..35f8f43b3 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 abfdd6488..b9a45c640 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 67363d08b..3803a357f 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 904424959..35dda5d58 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 ad9e8a1d9..45a1f7163 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 b2115f5e6..8003f2140 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();