Core: Apply core memory functions
- Use core memory functions instead of standard C
runtime library for core and spm.
Change-Id: Iad8037c77676a5418d9fec3626bb51dd3cead425
Signed-off-by: Mingyang Sun <mingyang.sun@arm.com>
diff --git a/secure_fw/core/arch/tfm_arch_v8m_main.c b/secure_fw/core/arch/tfm_arch_v8m_main.c
index 7ae6832..61bd86a 100644
--- a/secure_fw/core/arch/tfm_arch_v8m_main.c
+++ b/secure_fw/core/arch/tfm_arch_v8m_main.c
@@ -11,6 +11,7 @@
#include "secure_utilities.h"
#include "tfm_arch.h"
#include "tfm_memory_utils.h"
+#include "tfm_core_utils.h"
#include "tfm_secure_api.h"
#include "spm_api.h"
#include "tfm_svc.h"
@@ -169,9 +170,9 @@
sp <= (S_DATA_LIMIT - sizeof(tfm_fault_context)) + 1) ||
(sp >= NS_DATA_START &&
sp <= (NS_DATA_LIMIT - sizeof(tfm_fault_context)) + 1)) {
- tfm_memcpy(&tfm_fault_context,
- (const void *)sp,
- sizeof(tfm_fault_context));
+ tfm_core_util_memcpy(&tfm_fault_context,
+ (const void *)sp,
+ sizeof(tfm_fault_context));
}
LOG_MSG("Oops... Secure fault!!! You're not going anywhere!");
diff --git a/secure_fw/core/ipc/tfm_pools.c b/secure_fw/core/ipc/tfm_pools.c
index 8e954f4..1549460 100644
--- a/secure_fw/core/ipc/tfm_pools.c
+++ b/secure_fw/core/ipc/tfm_pools.c
@@ -17,6 +17,7 @@
#include "tfm_list.h"
#include "tfm_pools.h"
#include "tfm_memory_utils.h"
+#include "tfm_core_utils.h"
int32_t tfm_pool_init(struct tfm_pool_instance_t *pool, size_t poolsz,
size_t chunksz, size_t num)
@@ -35,7 +36,7 @@
}
/* Buffer should be BSS cleared but clear it again */
- tfm_memset(pool, 0, poolsz);
+ tfm_core_util_memset(pool, 0, poolsz);
/* Chain pool chunks */
tfm_list_init(&pool->chunks_list);
diff --git a/secure_fw/core/ipc/tfm_svcalls.c b/secure_fw/core/ipc/tfm_svcalls.c
index 8b85dcd..18ccf24 100644
--- a/secure_fw/core/ipc/tfm_svcalls.c
+++ b/secure_fw/core/ipc/tfm_svcalls.c
@@ -24,6 +24,7 @@
#include "spm_api.h"
#include "tfm_peripherals_def.h"
#include "spm_db.h"
+#include "tfm_core_utils.h"
void tfm_irq_handler(uint32_t partition_id, psa_signal_t signal,
int32_t irq_line);
@@ -236,12 +237,12 @@
tfm_panic();
}
- tfm_memset(invecs, 0, sizeof(invecs));
- tfm_memset(outvecs, 0, sizeof(outvecs));
+ tfm_core_util_memset(invecs, 0, sizeof(invecs));
+ tfm_core_util_memset(outvecs, 0, sizeof(outvecs));
/* Copy the address out to avoid TOCTOU attacks. */
- tfm_memcpy(invecs, inptr, in_num * sizeof(psa_invec));
- tfm_memcpy(outvecs, outptr, out_num * sizeof(psa_outvec));
+ tfm_core_util_memcpy(invecs, inptr, in_num * sizeof(psa_invec));
+ tfm_core_util_memcpy(outvecs, outptr, out_num * sizeof(psa_outvec));
/*
* For client input vector, it is a fatal error if the provided payload
@@ -466,7 +467,7 @@
return PSA_ERROR_DOES_NOT_EXIST;
}
- tfm_memcpy(msg, &tmp_msg->msg, sizeof(psa_msg_t));
+ tfm_core_util_memcpy(msg, &tmp_msg->msg, sizeof(psa_msg_t));
/*
* There may be mutiple messages for this RoT Service signal, do not clear
@@ -591,7 +592,7 @@
bytes = num_bytes > msg->msg.in_size[invec_idx] ?
msg->msg.in_size[invec_idx] : num_bytes;
- tfm_memcpy(buffer, msg->invec[invec_idx].base, bytes);
+ tfm_core_util_memcpy(buffer, msg->invec[invec_idx].base, bytes);
/* There maybe some remaining data */
msg->invec[invec_idx].base += bytes;
@@ -749,8 +750,8 @@
tfm_panic();
}
- tfm_memcpy(msg->outvec[outvec_idx].base + msg->outvec[outvec_idx].len,
- buffer, num_bytes);
+ tfm_core_util_memcpy(msg->outvec[outvec_idx].base +
+ msg->outvec[outvec_idx].len, buffer, num_bytes);
/* Update the write number */
msg->outvec[outvec_idx].len += num_bytes;
diff --git a/secure_fw/core/ipc/tfm_thread.c b/secure_fw/core/ipc/tfm_thread.c
index 5b18096..70d4d20 100644
--- a/secure_fw/core/ipc/tfm_thread.c
+++ b/secure_fw/core/ipc/tfm_thread.c
@@ -11,6 +11,7 @@
#include "tfm_memory_utils.h"
#include "tfm_svc.h"
#include "spm_api.h"
+#include "tfm_core_utils.h"
/* Force ZERO in case ZI(bss) clear is missing */
static struct tfm_thrd_ctx *p_thrd_head = NULL;
@@ -117,13 +118,13 @@
p_ctxa--;
/* Basic context is considerate at thread start.*/
- tfm_memset(p_ctxa, 0, sizeof(*p_ctxa));
+ tfm_core_util_memset(p_ctxa, 0, sizeof(*p_ctxa));
p_ctxa->r0 = (uint32_t)param;
p_ctxa->ra = (uint32_t)pfn;
p_ctxa->lr = (uint32_t)exit_zone;
p_ctxa->xpsr = XPSR_T32;
- tfm_memset(ctx, 0, sizeof(*ctx));
+ tfm_core_util_memset(ctx, 0, sizeof(*ctx));
tfm_arch_initialize_ctx_ext(&ctx->ctxb, (uint32_t)p_ctxa, (uint32_t)sp_top);
}
@@ -207,8 +208,9 @@
* First, update latest context into the current thread context.
* Then, update background context with next thread's context.
*/
- tfm_memcpy(&prev->state_ctx.ctxb, ctxb, sizeof(*ctxb));
- tfm_memcpy(ctxb, &next->state_ctx.ctxb, sizeof(next->state_ctx.ctxb));
+ tfm_core_util_memcpy(&prev->state_ctx.ctxb, ctxb, sizeof(*ctxb));
+ tfm_core_util_memcpy(ctxb, &next->state_ctx.ctxb,
+ sizeof(next->state_ctx.ctxb));
/* Update current thread indicator */
CURR_THRD = next;
diff --git a/secure_fw/core/tfm_boot_data.c b/secure_fw/core/tfm_boot_data.c
index 83414bf..21211f4 100644
--- a/secure_fw/core/tfm_boot_data.c
+++ b/secure_fw/core/tfm_boot_data.c
@@ -12,6 +12,7 @@
#include "tfm_internal.h"
#include "tfm_api.h"
#include "secure_fw/spm/spm_api.h"
+#include "tfm_core_utils.h"
#ifdef TFM_PSA_API
#include "tfm_internal_defines.h"
#include "tfm_utils.h"
@@ -140,9 +141,9 @@
*/
for (; offset < tlv_end; offset += tlv_entry.tlv_len) {
/* Create local copy to avoid unaligned access */
- (void)tfm_memcpy(&tlv_entry,
- (const void *)offset,
- SHARED_DATA_ENTRY_HEADER_SIZE);
+ (void)tfm_core_util_memcpy(&tlv_entry,
+ (const void *)offset,
+ SHARED_DATA_ENTRY_HEADER_SIZE);
if (GET_MAJOR(tlv_entry.tlv_type) == tlv_major) {
/* Check buffer overflow */
if (((ptr - buf_start) + tlv_entry.tlv_len) > buf_size) {
@@ -150,7 +151,8 @@
return;
}
- (void)tfm_memcpy(ptr, (const void *)offset, tlv_entry.tlv_len);
+ (void)tfm_core_util_memcpy(ptr, (const void *)offset,
+ tlv_entry.tlv_len);
ptr += tlv_entry.tlv_len;
boot_data->header.tlv_tot_len += tlv_entry.tlv_len;
diff --git a/secure_fw/spm/spm_api_ipc.c b/secure_fw/spm/spm_api_ipc.c
index 2b701ed..70980f2 100644
--- a/secure_fw/spm/spm_api_ipc.c
+++ b/secure_fw/spm/spm_api_ipc.c
@@ -27,6 +27,7 @@
#include "region_defs.h"
#include "tfm_nspm.h"
#include "tfm_memory_utils.h"
+#include "tfm_core_utils.h"
#include "secure_fw/services/tfm_service_list.inc"
@@ -298,7 +299,7 @@
TFM_ASSERT(in_len + out_len <= PSA_MAX_IOVEC);
/* Clear message buffer before using it */
- tfm_memset(msg, 0, sizeof(struct tfm_msg_body_t));
+ tfm_core_util_memset(msg, 0, sizeof(struct tfm_msg_body_t));
tfm_event_init(&msg->ack_evnt);
msg->magic = TFM_MSG_MAGIC;