Core: Use separate '.inc' file and init function
- Remove the 'tfm_spm_db.inc', use separate files, separate SPM
initialization functions for different models.
- Remove unused inclusion of header file 'spm_db.h'.
Change-Id: I7427eaee691a02c9b25579972902974ac9d32fd7
Signed-off-by: Mingyang Sun <mingyang.sun@arm.com>
diff --git a/platform/ext/target/cypress/psoc64/spm_hal.c b/platform/ext/target/cypress/psoc64/spm_hal.c
index 83255a5..62115a0 100644
--- a/platform/ext/target/cypress/psoc64/spm_hal.c
+++ b/platform/ext/target/cypress/psoc64/spm_hal.c
@@ -17,7 +17,6 @@
#include "secure_utilities.h"
#include "spe_ipc_config.h"
#include "tfm/spm_api.h"
-#include "tfm/spm_db.h"
#include "target_cfg.h"
#include "tfm_multi_core.h"
#include "tfm_platform_core_api.h"
diff --git a/platform/ext/target/mps2/an519/spm_hal.c b/platform/ext/target/mps2/an519/spm_hal.c
index 93efa87..7939e7c 100644
--- a/platform/ext/target/mps2/an519/spm_hal.c
+++ b/platform/ext/target/mps2/an519/spm_hal.c
@@ -9,7 +9,6 @@
#include "cmsis.h"
#include "tfm_spm_hal.h"
#include "tfm/spm_api.h"
-#include "tfm/spm_db.h"
#include "tfm_platform_core_api.h"
#include "target_cfg.h"
#include "Driver_MPC.h"
diff --git a/platform/ext/target/mps2/an521/spm_hal.c b/platform/ext/target/mps2/an521/spm_hal.c
index d1a6acb..4e22b1a 100644
--- a/platform/ext/target/mps2/an521/spm_hal.c
+++ b/platform/ext/target/mps2/an521/spm_hal.c
@@ -9,7 +9,6 @@
#include "cmsis.h"
#include "tfm_spm_hal.h"
#include "tfm/spm_api.h"
-#include "tfm/spm_db.h"
#include "tfm_platform_core_api.h"
#include "target_cfg.h"
#include "Driver_MPC.h"
diff --git a/platform/ext/target/mps2/an539/spm_hal.c b/platform/ext/target/mps2/an539/spm_hal.c
index bc88fff..08d99b4 100644
--- a/platform/ext/target/mps2/an539/spm_hal.c
+++ b/platform/ext/target/mps2/an539/spm_hal.c
@@ -9,7 +9,6 @@
#include "tfm_spm_hal.h"
#include "tfm_platform_core_api.h"
#include "tfm/spm_api.h"
-#include "tfm/spm_db.h"
#include "target_cfg.h"
#include "mpu_armv8m_drv.h"
#include "region_defs.h"
diff --git a/platform/ext/target/mps2/fvp_sse300/spm_hal.c b/platform/ext/target/mps2/fvp_sse300/spm_hal.c
index 206e621..52e35b8 100644
--- a/platform/ext/target/mps2/fvp_sse300/spm_hal.c
+++ b/platform/ext/target/mps2/fvp_sse300/spm_hal.c
@@ -9,7 +9,6 @@
#include "cmsis.h"
#include "tfm_spm_hal.h"
#include "tfm/spm_api.h"
-#include "tfm/spm_db.h"
#include "tfm_platform_core_api.h"
#include "target_cfg.h"
#include "Driver_MPC.h"
diff --git a/platform/ext/target/mps3/an524/spm_hal.c b/platform/ext/target/mps3/an524/spm_hal.c
index 606993c..028e8e6 100644
--- a/platform/ext/target/mps3/an524/spm_hal.c
+++ b/platform/ext/target/mps3/an524/spm_hal.c
@@ -10,7 +10,6 @@
#include "tfm_spm_hal.h"
#include "tfm_platform_core_api.h"
#include "tfm/spm_api.h"
-#include "tfm/spm_db.h"
#include "target_cfg.h"
#include "mpu_armv8m_drv.h"
#include "region_defs.h"
diff --git a/platform/ext/target/musca_a/spm_hal.c b/platform/ext/target/musca_a/spm_hal.c
index cf7fdb7..4b87afe 100644
--- a/platform/ext/target/musca_a/spm_hal.c
+++ b/platform/ext/target/musca_a/spm_hal.c
@@ -9,7 +9,6 @@
#include "cmsis.h"
#include "tfm_spm_hal.h"
#include "tfm/spm_api.h"
-#include "tfm/spm_db.h"
#include "tfm_platform_core_api.h"
#include "target_cfg.h"
#include "Driver_MPC.h"
diff --git a/platform/ext/target/musca_b1/spm_hal.c b/platform/ext/target/musca_b1/spm_hal.c
index 6ed2caf..405f559 100644
--- a/platform/ext/target/musca_b1/spm_hal.c
+++ b/platform/ext/target/musca_b1/spm_hal.c
@@ -9,7 +9,6 @@
#include "cmsis.h"
#include "tfm_spm_hal.h"
#include "tfm/spm_api.h"
-#include "tfm/spm_db.h"
#include "tfm_platform_core_api.h"
#include "target_cfg.h"
#include "Driver_MPC.h"
diff --git a/platform/ext/target/musca_s1/spm_hal.c b/platform/ext/target/musca_s1/spm_hal.c
index bdb4803..9c1693e 100644
--- a/platform/ext/target/musca_s1/spm_hal.c
+++ b/platform/ext/target/musca_s1/spm_hal.c
@@ -9,7 +9,6 @@
#include "cmsis.h"
#include "tfm_spm_hal.h"
#include "tfm/spm_api.h"
-#include "tfm/spm_db.h"
#include "tfm_platform_core_api.h"
#include "target_cfg.h"
#include "Driver_MPC.h"
diff --git a/platform/ext/target/nxp/lpcxpresso55s69/spm_hal.c b/platform/ext/target/nxp/lpcxpresso55s69/spm_hal.c
index 909cd1e..a718ac3 100755
--- a/platform/ext/target/nxp/lpcxpresso55s69/spm_hal.c
+++ b/platform/ext/target/nxp/lpcxpresso55s69/spm_hal.c
@@ -9,7 +9,6 @@
#include "cmsis.h"
#include "tfm_spm_hal.h"
#include "tfm/spm_api.h"
-#include "tfm/spm_db.h"
#include "tfm_platform_core_api.h"
#include "target_cfg.h"
#include "mpu_armv8m_drv.h"
diff --git a/platform/ext/target/sse-200_aws/spm_hal.c b/platform/ext/target/sse-200_aws/spm_hal.c
index bb58cdf..2490c89 100644
--- a/platform/ext/target/sse-200_aws/spm_hal.c
+++ b/platform/ext/target/sse-200_aws/spm_hal.c
@@ -9,7 +9,6 @@
#include "cmsis.h"
#include "tfm_spm_hal.h"
#include "tfm/spm_api.h"
-#include "tfm/spm_db.h"
#include "tfm_platform_core_api.h"
#include "target_cfg.h"
#include "Driver_MPC.h"
diff --git a/platform/ext/target/stm/stm32l5xx/secure/spm_hal.c b/platform/ext/target/stm/stm32l5xx/secure/spm_hal.c
index 0ac0f1c..f96e09d 100644
--- a/platform/ext/target/stm/stm32l5xx/secure/spm_hal.c
+++ b/platform/ext/target/stm/stm32l5xx/secure/spm_hal.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
*
@@ -8,7 +8,6 @@
#include <stdio.h>
#include "tfm_spm_hal.h"
#include "tfm/spm_api.h"
-#include "tfm/spm_db.h"
#include "tfm_platform_core_api.h"
#include "target_cfg.h"
#include "Driver_MPC.h"
diff --git a/secure_fw/spm/init/tfm_core.c b/secure_fw/spm/init/tfm_core.c
index e1f0c14..d4df240 100644
--- a/secure_fw/spm/init/tfm_core.c
+++ b/secure_fw/spm/init/tfm_core.c
@@ -14,7 +14,6 @@
#include "tfm_version.h"
#include "log/tfm_log.h"
#include "tfm/spm_api.h"
-#include "tfm/spm_db.h"
/*
* Avoids the semihosting issue
diff --git a/secure_fw/spm/model_func/spm_func.c b/secure_fw/spm/model_func/spm_func.c
index cd88329..9f040b8 100644
--- a/secure_fw/spm/model_func/spm_func.c
+++ b/secure_fw/spm/model_func/spm_func.c
@@ -15,6 +15,7 @@
#include "tfm_irq_list.h"
#include "psa/service.h"
#include "tfm_core_mem_check.h"
+#include "tfm_peripherals_def.h"
#include "tfm_secure_api.h"
#include "tfm_spm_hal.h"
#include "tfm/spm_api.h"
@@ -22,6 +23,7 @@
#include "region_defs.h"
#include "region.h"
#include "tfm/tfm_spm_services_api.h"
+#include "tfm_spm_db_func.inc"
#define EXC_RETURN_SECURE_FUNCTION 0xFFFFFFFD
#define EXC_RETURN_SECURE_HANDLER 0xFFFFFFF1
@@ -40,8 +42,6 @@
extern int32_t tfm_secure_lock;
static int32_t tfm_secure_api_initializing = 1;
-extern struct spm_partition_db_t g_spm_partition_db;
-
static uint32_t *prepare_partition_iovec_ctx(
const struct tfm_state_context_t *svc_ctx,
const struct tfm_sfn_req_s *desc_ptr,
@@ -1318,3 +1318,30 @@
*res_ptr = (uint32_t)TFM_ERROR_INVALID_PARAMETER;
}
}
+
+enum spm_err_t tfm_spm_db_init(void)
+{
+ uint32_t i;
+
+ /* This function initialises partition db */
+
+ /* For the non secure Execution environment */
+ tfm_nspm_configure_clients();
+
+ for (i = 0; i < g_spm_partition_db.partition_count; i++) {
+ g_spm_partition_db.partitions[i].runtime_data.partition_state =
+ SPM_PARTITION_STATE_UNINIT;
+ g_spm_partition_db.partitions[i].runtime_data.caller_partition_idx =
+ SPM_INVALID_PARTITION_IDX;
+ g_spm_partition_db.partitions[i].runtime_data.caller_client_id =
+ TFM_INVALID_CLIENT_ID;
+ g_spm_partition_db.partitions[i].runtime_data.ctx_stack_ptr =
+ ctx_stack_list[i];
+ g_spm_partition_db.partitions[i].static_data = &static_data_list[i];
+ g_spm_partition_db.partitions[i].platform_data_list =
+ platform_data_list_list[i];
+ }
+ g_spm_partition_db.is_init = 1;
+
+ return SPM_ERR_OK;
+}
diff --git a/secure_fw/spm/model_ipc/spm_ipc.c b/secure_fw/spm/model_ipc/spm_ipc.c
index 780fc7a..ea1a368 100644
--- a/secure_fw/spm/model_ipc/spm_ipc.c
+++ b/secure_fw/spm/model_ipc/spm_ipc.c
@@ -31,18 +31,17 @@
#include "tfm_core_mem_check.h"
#include "tfm_list.h"
#include "tfm_pools.h"
+#include "region.h"
#include "region_defs.h"
#include "tfm/tfm_spm_services_api.h"
#include "secure_fw/partitions/tfm_service_list.inc"
+#include "tfm_spm_db_ipc.inc"
/* Extern service variable */
extern struct tfm_spm_service_t service[];
extern const struct tfm_spm_service_db_t service_db[];
-/* Extern SPM variable */
-extern struct spm_partition_db_t g_spm_partition_db;
-
/* Pools */
TFM_POOL_DECLARE(conn_handle_pool, sizeof(struct tfm_conn_handle_t),
TFM_CONN_HANDLE_MAX_NUM);
@@ -1658,3 +1657,20 @@
*res_ptr = (uint32_t)TFM_ERROR_INVALID_PARAMETER;
}
}
+
+enum spm_err_t tfm_spm_db_init(void)
+{
+ uint32_t i;
+
+ /* This function initialises partition db */
+
+ for (i = 0; i < g_spm_partition_db.partition_count; i++) {
+ g_spm_partition_db.partitions[i].static_data = &static_data_list[i];
+ g_spm_partition_db.partitions[i].platform_data_list =
+ platform_data_list_list[i];
+ g_spm_partition_db.partitions[i].memory_data = &memory_data_list[i];
+ }
+ g_spm_partition_db.is_init = 1;
+
+ return SPM_ERR_OK;
+}
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 25a8632..ff97cf5 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
@@ -10,7 +10,6 @@
#include "region_defs.h"
#include "secure_utilities.h"
#include "tfm/spm_api.h"
-#include "tfm/spm_db.h"
#include "tfm_internal.h"
#include "tfm_multi_core.h"
#include "tfm_secure_api.h"
diff --git a/secure_fw/spm/runtime/spm_api.c b/secure_fw/spm/runtime/spm_api.c
index a72b402..5ff1dc3 100644
--- a/secure_fw/spm/runtime/spm_api.c
+++ b/secure_fw/spm/runtime/spm_api.c
@@ -7,25 +7,11 @@
/* All the APIs defined in this file are common for library and IPC model. */
-#include <stdio.h>
-#include <string.h>
#include "tfm/spm_api.h"
-#include "tfm_spm_hal.h"
-#include "tfm_memory_utils.h"
#include "tfm/spm_db.h"
-#include "tfm_internal.h"
-#include "tfm_api.h"
-#include "tfm_nspm.h"
-#include "tfm_core.h"
-#include "tfm_peripherals_def.h"
-#include "tfm/spm_partition_defs.h"
-#include "region.h"
-#define NON_SECURE_INTERNAL_PARTITION_DB_IDX 0
-#define TFM_CORE_INTERNAL_PARTITION_DB_IDX 1
-
-/* Define SPM DB structure */
-#include "tfm_spm_db.inc"
+/* Extern SPM variable */
+extern struct spm_partition_db_t g_spm_partition_db;
uint32_t get_partition_idx(uint32_t partition_id)
{
@@ -44,40 +30,6 @@
return SPM_INVALID_PARTITION_IDX;
}
-enum spm_err_t tfm_spm_db_init(void)
-{
- uint32_t i;
-
- /* This function initialises partition db */
-
- /* For the non secure Execution environment */
-#ifndef TFM_PSA_API
- tfm_nspm_configure_clients();
-#endif
-
- for (i = 0; i < g_spm_partition_db.partition_count; i++) {
-#ifndef TFM_PSA_API
- g_spm_partition_db.partitions[i].runtime_data.partition_state =
- SPM_PARTITION_STATE_UNINIT;
- g_spm_partition_db.partitions[i].runtime_data.caller_partition_idx =
- SPM_INVALID_PARTITION_IDX;
- g_spm_partition_db.partitions[i].runtime_data.caller_client_id =
- TFM_INVALID_CLIENT_ID;
- g_spm_partition_db.partitions[i].runtime_data.ctx_stack_ptr =
- ctx_stack_list[i];
-#endif /* !defined(TFM_PSA_API) */
- g_spm_partition_db.partitions[i].static_data = &static_data_list[i];
- g_spm_partition_db.partitions[i].platform_data_list =
- platform_data_list_list[i];
-#ifdef TFM_PSA_API
- g_spm_partition_db.partitions[i].memory_data = &memory_data_list[i];
-#endif
- }
- g_spm_partition_db.is_init = 1;
-
- return SPM_ERR_OK;
-}
-
uint32_t tfm_spm_partition_get_partition_id(uint32_t partition_idx)
{
return g_spm_partition_db.partitions[partition_idx].static_data->
diff --git a/secure_fw/spm/runtime/tfm_spm_db.inc b/secure_fw/spm/runtime/tfm_spm_db.inc
deleted file mode 100644
index afc9c79..0000000
--- a/secure_fw/spm/runtime/tfm_spm_db.inc
+++ /dev/null
@@ -1,17 +0,0 @@
-/*
- * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- *
- */
-
-#ifndef __TFM_SPM_DB_INC__
-#define __TFM_SPM_DB_INC__
-
-#ifdef TFM_PSA_API
-#include "tfm_spm_db_ipc.inc"
-#else
-#include "tfm_spm_db_func.inc"
-#endif
-
-#endif /* __TFM_SPM_DB_INC__ */
\ No newline at end of file