Core: Move memory primitives to separate file
Reduce the dependencies of the services on various header files.
Change-Id: Iaf9c64bc830609d7497fb4a0b825a303dded4a04
Signed-off-by: Tamas Ban <tamas.ban@arm.com>
diff --git a/secure_fw/core/secure_utilities.h b/secure_fw/core/secure_utilities.h
index 32030fd..3501a73 100644
--- a/secure_fw/core/secure_utilities.h
+++ b/secure_fw/core/secure_utilities.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2018, Arm Limited. All rights reserved.
+ * Copyright (c) 2017-2019, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -10,7 +10,6 @@
#include "cmsis_compiler.h"
#include "tfm_svc.h"
-#include "string.h"
#define EXC_RETURN_INDICATOR (0xF << 28)
#define EXC_RETURN_SECURITY_STACK_STATUS_MASK (0x3 << 5)
@@ -104,27 +103,4 @@
__asm("ISB");
}
-/* FIXME: The following functions are wrappers around standard C library
- * functions: memcpy, memcmp, memset
- * In long term standard C library might be removed from TF-M project or
- * replaced with a secure implementation due to security concerns.
- */
-__attribute__ ((always_inline)) __STATIC_INLINE
-void tfm_memcpy(void *dest, const void *src, uint32_t size)
-{
- memcpy(dest, src, size);
-}
-
-__attribute__ ((always_inline)) __STATIC_INLINE
-int32_t tfm_memcmp(const void * ptr1, const void * ptr2, size_t num)
-{
- return (memcmp(ptr1, ptr2, num));
-}
-
-__attribute__ ((always_inline)) __STATIC_INLINE
-void * tfm_memset(void * ptr, int value, size_t num)
-{
- return (memset(ptr, value, num));
-}
-
#endif /* __SECURE_UTILITIES_H__ */
diff --git a/secure_fw/core/tfm_boot_data.c b/secure_fw/core/tfm_boot_data.c
index db40768..e742072 100644
--- a/secure_fw/core/tfm_boot_data.c
+++ b/secure_fw/core/tfm_boot_data.c
@@ -7,7 +7,7 @@
#include <stdint.h>
#include "bl2/include/tfm_boot_status.h"
-#include "secure_utilities.h"
+#include "tfm_memory_utils.h"
#include "tfm_internal.h"
#include "tfm_api.h"
#include "flash_layout.h"
diff --git a/secure_fw/core/tfm_handler.c b/secure_fw/core/tfm_handler.c
index 88ac443..ee59ea1 100644
--- a/secure_fw/core/tfm_handler.c
+++ b/secure_fw/core/tfm_handler.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2018, Arm Limited. All rights reserved.
+ * Copyright (c) 2017-2019, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -16,6 +16,7 @@
#include "region_defs.h"
#include "tfm_api.h"
#include "tfm_internal.h"
+#include "tfm_memory_utils.h"
/* This SVC handler is called when a secure partition requests access to a
* buffer area
diff --git a/secure_fw/core/tfm_memory_utils.h b/secure_fw/core/tfm_memory_utils.h
new file mode 100644
index 0000000..150e3cc
--- /dev/null
+++ b/secure_fw/core/tfm_memory_utils.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2019, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#ifndef __TFM_MEMORY_UTILS_H__
+#define __TFM_MEMORY_UTILS_H__
+
+#include <string.h>
+#include "cmsis_compiler.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* FIXME: The following functions are wrappers around standard C library
+ * functions: memcpy, memcmp, memset
+ * In long term standard C library might be removed from TF-M project or
+ * replaced with a secure implementation due to security concerns.
+ */
+__attribute__ ((always_inline)) __STATIC_INLINE
+void *tfm_memcpy(void *dest, const void *src, size_t num)
+{
+ return (memcpy(dest, src, num));
+}
+
+__attribute__ ((always_inline)) __STATIC_INLINE
+int tfm_memcmp(const void *ptr1, const void *ptr2, size_t num)
+{
+ return (memcmp(ptr1, ptr2, num));
+}
+
+__attribute__ ((always_inline)) __STATIC_INLINE
+void *tfm_memset(void *ptr, int value, size_t num)
+{
+ return (memset(ptr, value, num));
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TFM_MEMORY_UTILS_H__ */
diff --git a/secure_fw/services/crypto/crypto_alloc.c b/secure_fw/services/crypto/crypto_alloc.c
index 627dab7..ede9ba7 100644
--- a/secure_fw/services/crypto/crypto_alloc.c
+++ b/secure_fw/services/crypto/crypto_alloc.c
@@ -13,7 +13,7 @@
#include "tfm_crypto_api.h"
#include "tfm_crypto_struct.h"
-#include "secure_fw/core/secure_utilities.h"
+#include "secure_fw/core/tfm_memory_utils.h"
/**
* \brief This value defines the maximum number of simultaneous operations
diff --git a/secure_fw/services/crypto/crypto_key.c b/secure_fw/services/crypto/crypto_key.c
index f2708d5..277ed10 100644
--- a/secure_fw/services/crypto/crypto_key.c
+++ b/secure_fw/services/crypto/crypto_key.c
@@ -12,7 +12,7 @@
#include "crypto_utils.h"
#include "psa_crypto.h"
#include "tfm_crypto_defs.h"
-#include "secure_fw/core/secure_utilities.h"
+#include "secure_fw/core/tfm_memory_utils.h"
/**
* \brief This is the default value of maximum number of simultaneous
diff --git a/secure_fw/services/crypto/crypto_mac.c b/secure_fw/services/crypto/crypto_mac.c
index 45a7eae..ec49a11 100644
--- a/secure_fw/services/crypto/crypto_mac.c
+++ b/secure_fw/services/crypto/crypto_mac.c
@@ -5,7 +5,7 @@
*
*/
-#include "secure_fw/core/secure_utilities.h"
+#include "secure_fw/core/tfm_memory_utils.h"
#include "tfm_crypto_defs.h"
#include "psa_crypto.h"
diff --git a/secure_fw/services/initial_attestation/attestation_crypto_stub.c b/secure_fw/services/initial_attestation/attestation_crypto_stub.c
index 8731466..5b1df81 100644
--- a/secure_fw/services/initial_attestation/attestation_crypto_stub.c
+++ b/secure_fw/services/initial_attestation/attestation_crypto_stub.c
@@ -5,7 +5,7 @@
*
*/
-#include "secure_utilities.h"
+#include "tfm_memory_utils.h"
#include "tfm_crypto_defs.h"
#include "psa_crypto.h"
diff --git a/secure_fw/services/initial_attestation/tfm_attestation_secure_api.c b/secure_fw/services/initial_attestation/tfm_attestation_secure_api.c
index 14e5f3f..acd9878 100644
--- a/secure_fw/services/initial_attestation/tfm_attestation_secure_api.c
+++ b/secure_fw/services/initial_attestation/tfm_attestation_secure_api.c
@@ -7,7 +7,7 @@
#include "psa_initial_attestation_api.h"
#include "tfm_veneers.h"
-#include "secure_utilities.h"
+#include "tfm_memory_utils.h"
#include "tfm_client.h"
#include "tfm_secure_api.h"
#include <string.h>
diff --git a/secure_fw/spm/spm_api.c b/secure_fw/spm/spm_api.c
index 1e9b99c..efc4306 100644
--- a/secure_fw/spm/spm_api.c
+++ b/secure_fw/spm/spm_api.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2018, Arm Limited. All rights reserved.
+ * Copyright (c) 2017-2019, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -11,7 +11,7 @@
#include <string.h>
#include "spm_api.h"
#include "platform/include/tfm_spm_hal.h"
-#include "secure_utilities.h"
+#include "tfm_memory_utils.h"
#include "spm_db_setup.h"
#include "tfm_internal.h"
#include "tfm_api.h"