SPM: Sort out tfm_secure_api.c file
- Rename 'tfm_utils.h' to 'utilities.h'.
- Rename 'tfm_spm_services_api.h'to 'tfm_spm_services.h'.
- Move 'tfm_secure_api.c' from spm/runtime to spm/model_func and
sort out the content
Change-Id: Ie8831e2b1430eab6a2edc9b6c0487ef14f2fafc6
Signed-off-by: Summer Qin <summer.qin@arm.com>
diff --git a/secure_fw/spm/model_ipc/CMakeLists.inc b/secure_fw/spm/model_ipc/CMakeLists.inc
index a763ab4..0836022 100644
--- a/secure_fw/spm/model_ipc/CMakeLists.inc
+++ b/secure_fw/spm/model_ipc/CMakeLists.inc
@@ -40,11 +40,10 @@
"${SFW_IPC_SPM_DIR}/spm_psa_client_call.c"
"${SFW_IPC_SPM_DIR}/tfm_core_svcalls_ipc.c"
"${SFW_IPC_SPM_DIR}/tfm_message_queue.c"
- "${SFW_IPC_SPM_DIR}/../runtime/tfm_utils.c"
+ "${SFW_IPC_SPM_DIR}/../runtime/utilities.c"
"${SFW_IPC_SPM_DIR}/../runtime/tfm_core_utils.c"
"${SFW_IPC_SPM_DIR}/../runtime/spm_api.c"
"${SFW_IPC_SPM_DIR}/../runtime/tfm_spm_services.c"
- "${SFW_IPC_SPM_DIR}/../runtime/tfm_secure_api.c"
"${SFW_IPC_SPM_DIR}/tfm_pools.c"
"${SFW_IPC_SPM_DIR}/tfm_thread.c"
"${SFW_IPC_SPM_DIR}/tfm_wait.c"
diff --git a/secure_fw/spm/model_ipc/spm_ipc.c b/secure_fw/spm/model_ipc/spm_ipc.c
index deb7d30..0f25828 100644
--- a/secure_fw/spm/model_ipc/spm_ipc.c
+++ b/secure_fw/spm/model_ipc/spm_ipc.c
@@ -12,7 +12,7 @@
#include "psa/lifecycle.h"
#include "tfm_thread.h"
#include "tfm_wait.h"
-#include "tfm_utils.h"
+#include "utilities.h"
#include "tfm_internal_defines.h"
#include "tfm_message_queue.h"
#include "tfm_spm_hal.h"
@@ -33,7 +33,7 @@
#include "tfm_pools.h"
#include "region.h"
#include "region_defs.h"
-#include "tfm/tfm_spm_services_api.h"
+#include "tfm/tfm_spm_services.h"
#include "secure_fw/partitions/tfm_service_list.inc"
#include "tfm_spm_db_ipc.inc"
diff --git a/secure_fw/spm/model_ipc/spm_psa_client_call.c b/secure_fw/spm/model_ipc/spm_psa_client_call.c
index 3c1de45..9fca10c 100644
--- a/secure_fw/spm/model_ipc/spm_psa_client_call.c
+++ b/secure_fw/spm/model_ipc/spm_psa_client_call.c
@@ -12,7 +12,7 @@
#include "tfm_memory_utils.h"
#include "tfm_message_queue.h"
#include "spm_psa_client_call.h"
-#include "tfm_utils.h"
+#include "utilities.h"
#include "tfm_wait.h"
#include "tfm_nspm.h"
diff --git a/secure_fw/spm/model_ipc/tfm_core_svcalls_ipc.c b/secure_fw/spm/model_ipc/tfm_core_svcalls_ipc.c
index 2db4233..7f8bbd9 100644
--- a/secure_fw/spm/model_ipc/tfm_core_svcalls_ipc.c
+++ b/secure_fw/spm/model_ipc/tfm_core_svcalls_ipc.c
@@ -14,7 +14,7 @@
#include "tfm_core_trustzone.h"
#include "tfm_internal.h"
#include "tfm_svcalls.h"
-#include "tfm_utils.h"
+#include "utilities.h"
#include "tfm/tfm_core_svc.h"
/* The section names come from the scatter file */
diff --git a/secure_fw/spm/model_ipc/tfm_multi_core.c b/secure_fw/spm/model_ipc/tfm_multi_core.c
index 855755b..f8ef7d6 100644
--- a/secure_fw/spm/model_ipc/tfm_multi_core.c
+++ b/secure_fw/spm/model_ipc/tfm_multi_core.c
@@ -9,7 +9,7 @@
#include "tfm_internal.h"
#include "tfm_nspm.h"
#include "tfm_spe_mailbox.h"
-#include "tfm_utils.h"
+#include "utilities.h"
#include "log/tfm_assert.h"
#include "log/tfm_log.h"
#include "log/tfm_assert.h"
diff --git a/secure_fw/spm/model_ipc/tfm_multi_core_mem_check.c b/secure_fw/spm/model_ipc/tfm_multi_core_mem_check.c
index 0eae524..9cf8bf8 100644
--- a/secure_fw/spm/model_ipc/tfm_multi_core_mem_check.c
+++ b/secure_fw/spm/model_ipc/tfm_multi_core_mem_check.c
@@ -12,7 +12,7 @@
#include "tfm_internal.h"
#include "tfm_multi_core.h"
#include "tfm_secure_api.h"
-#include "tfm_utils.h"
+#include "utilities.h"
#include "region.h"
#ifndef TFM_LVL
@@ -28,6 +28,42 @@
#define MEM_CHECK_NONSECURE (MEM_CHECK_AU_NONSECURE | \
MEM_CHECK_MPU_NONSECURE)
+/**
+ * \brief Check whether a memory range is inside a memory region.
+ *
+ * \param[in] p The start address of the range to check
+ * \param[in] s The size of the range to check
+ * \param[in] region_start The start address of the region, which should
+ * contain the range
+ * \param[in] region_limit The end address of the region, which should contain
+ * the range
+ *
+ * \return TFM_SUCCESS if the region contains the range,
+ * TFM_ERROR_GENERIC otherwise.
+ */
+static enum tfm_status_e check_address_range(const void *p, size_t s,
+ uintptr_t region_start,
+ uintptr_t region_limit)
+{
+ int32_t range_in_region;
+
+ /* Check for overflow in the range parameters */
+ if ((uintptr_t)p > UINTPTR_MAX - s) {
+ return TFM_ERROR_GENERIC;
+ }
+
+ /* We trust the region parameters, and don't check for overflow */
+
+ /* Calculate the result */
+ range_in_region = ((uintptr_t)p >= region_start) &&
+ ((uintptr_t)((char *) p + s - 1) <= region_limit);
+ if (range_in_region) {
+ return TFM_SUCCESS;
+ } else {
+ return TFM_ERROR_GENERIC;
+ }
+}
+
void tfm_get_mem_region_security_attr(const void *p, size_t s,
struct security_attr_info_t *p_attr)
{
diff --git a/secure_fw/spm/model_ipc/tfm_nspm_ipc.c b/secure_fw/spm/model_ipc/tfm_nspm_ipc.c
index 8413d46..2237906 100644
--- a/secure_fw/spm/model_ipc/tfm_nspm_ipc.c
+++ b/secure_fw/spm/model_ipc/tfm_nspm_ipc.c
@@ -9,7 +9,7 @@
#include "tfm_spm_hal.h"
#include "psa/error.h"
#include "tfm_nspm.h"
-#include "tfm_utils.h"
+#include "utilities.h"
#include "tfm_internal.h"
#include "log/tfm_assert.h"
#include "log/tfm_log.h"
diff --git a/secure_fw/spm/model_ipc/tfm_pools.c b/secure_fw/spm/model_ipc/tfm_pools.c
index 6ab56af..2fa3d40 100644
--- a/secure_fw/spm/model_ipc/tfm_pools.c
+++ b/secure_fw/spm/model_ipc/tfm_pools.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018-2019, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -13,7 +13,7 @@
#include "psa/service.h"
#include "tfm_internal_defines.h"
#include "cmsis_compiler.h"
-#include "tfm_utils.h"
+#include "utilities.h"
#include "tfm_list.h"
#include "tfm_pools.h"
#include "tfm_memory_utils.h"
diff --git a/secure_fw/spm/model_ipc/tfm_rpc.c b/secure_fw/spm/model_ipc/tfm_rpc.c
index f2778aa..351c971 100644
--- a/secure_fw/spm/model_ipc/tfm_rpc.c
+++ b/secure_fw/spm/model_ipc/tfm_rpc.c
@@ -8,7 +8,7 @@
#include "spm_api.h"
#include "spm_psa_client_call.h"
#include "tfm_rpc.h"
-#include "tfm_utils.h"
+#include "utilities.h"
static void default_handle_req(void)
{
diff --git a/secure_fw/spm/model_ipc/tfm_spe_mailbox.c b/secure_fw/spm/model_ipc/tfm_spe_mailbox.c
index baa02c7..c0affe1 100644
--- a/secure_fw/spm/model_ipc/tfm_spe_mailbox.c
+++ b/secure_fw/spm/model_ipc/tfm_spe_mailbox.c
@@ -9,7 +9,7 @@
#include "psa/error.h"
#include "tfm_core_utils.h"
-#include "tfm_utils.h"
+#include "utilities.h"
#include "tfm_spe_mailbox.h"
#include "tfm_rpc.h"
diff --git a/secure_fw/spm/model_ipc/tfm_thread.c b/secure_fw/spm/model_ipc/tfm_thread.c
index 74af5a9..e3554e3 100644
--- a/secure_fw/spm/model_ipc/tfm_thread.c
+++ b/secure_fw/spm/model_ipc/tfm_thread.c
@@ -7,7 +7,7 @@
#include <inttypes.h>
#include "tfm_arch.h"
#include "tfm_thread.h"
-#include "tfm_utils.h"
+#include "utilities.h"
#include "tfm_memory_utils.h"
#include "tfm/tfm_core_svc.h"
#include "spm_api.h"
diff --git a/secure_fw/spm/model_ipc/tfm_wait.c b/secure_fw/spm/model_ipc/tfm_wait.c
index efb7be6..c199c88 100644
--- a/secure_fw/spm/model_ipc/tfm_wait.c
+++ b/secure_fw/spm/model_ipc/tfm_wait.c
@@ -5,7 +5,7 @@
*
*/
#include "tfm_thread.h"
-#include "tfm_utils.h"
+#include "utilities.h"
#include "tfm_wait.h"
void tfm_event_wait(struct tfm_event_t *pevnt)