diff options
author | David Hu <david.hu@arm.com> | 2019-07-09 18:14:09 +0800 |
---|---|---|
committer | David Hu <david.hu@arm.com> | 2019-08-01 11:39:54 +0800 |
commit | 3b7c45658d3d70fb79399b0e4872b097eb83a656 (patch) | |
tree | 4d756da30036116e7fab9d6d831fc4db0da610ab | |
parent | cebca73fe0f9a55561ce39d095be52663d6c31fb (diff) | |
download | trusted-firmware-m-3b7c45658d3d70fb79399b0e4872b097eb83a656.tar.gz |
Twincpu: Add a dummy configure_ns_code() for multi-core topology.
Move single Armv8-M specific configure_ns_code() implementation to
tfm_nspm.c and remove preprocessor directives in tfm_core.c.
Define an empty configure_ns_code() for multi-core topology.
Change-Id: If35570b4d23f9795c3efd16ab8a2b18a30c4e821
Signed-off-by: David Hu <david.hu@arm.com>
-rw-r--r-- | secure_fw/core/tfm_core.c | 35 | ||||
-rw-r--r-- | secure_fw/core/tfm_nspm.c | 32 | ||||
-rw-r--r-- | secure_fw/core/tfm_nspm.h | 10 |
3 files changed, 42 insertions, 35 deletions
diff --git a/secure_fw/core/tfm_core.c b/secure_fw/core/tfm_core.c index aadc58b135..5404903382 100644 --- a/secure_fw/core/tfm_core.c +++ b/secure_fw/core/tfm_core.c @@ -11,6 +11,7 @@ #include "tfm_internal.h" #include "tfm_api.h" #include "tfm_arch.h" +#include "tfm_nspm.h" #include "platform/include/tfm_spm_hal.h" #include "uart_stdout.h" #include "secure_utilities.h" @@ -33,17 +34,6 @@ __asm(" .global __ARM_use_no_argv\n"); #endif -#if defined ( __GNUC__ ) -#if !TFM_MULTI_CORE_TOPOLOGY -/* The macro cmse_nsfptr_create defined in the gcc library uses the non-standard - * gcc C lanuage extension 'typeof'. TF-M is built with '-std=c99' so typeof - * cannot be used in the code. As a workaround cmse_nsfptr_create is redefined - * here to use only standard language elements. */ -#undef cmse_nsfptr_create -#define cmse_nsfptr_create(p) ((intptr_t) (p) & ~1) -#endif -#endif - #ifndef TFM_LVL #error TFM_LVL is not defined! #endif @@ -63,27 +53,6 @@ REGION_DECLARE(Image$$, TFM_UNPRIV_SCRATCH, $$ZI$$Limit); REGION_DECLARE(Image$$, ARM_LIB_STACK_MSP, $$ZI$$Base); -#if !TFM_MULTI_CORE_TOPOLOGY -void configure_ns_code(void) -{ - /* SCB_NS.VTOR points to the Non-secure vector table base address */ - SCB_NS->VTOR = tfm_spm_hal_get_ns_VTOR(); - - /* Setups Main stack pointer of the non-secure code */ - uint32_t ns_msp = tfm_spm_hal_get_ns_MSP(); - - __TZ_set_MSP_NS(ns_msp); - - /* Get the address of non-secure code entry point to jump there */ - uint32_t entry_ptr = tfm_spm_hal_get_ns_entry_point(); - - /* Clears LSB of the function address to indicate the function-call - * will perform the switch from secure to non-secure - */ - ns_entry = (nsfptr_t) cmse_nsfptr_create(entry_ptr); -} -#endif - int32_t tfm_core_init(void) { /* Enables fault handlers */ @@ -108,9 +77,7 @@ int32_t tfm_core_init(void) tfm_spm_hal_init_isolation_hw(); -#if !TFM_MULTI_CORE_TOPOLOGY configure_ns_code(); -#endif /* Configures all interrupts to retarget NS state, except for * secure peripherals diff --git a/secure_fw/core/tfm_nspm.c b/secure_fw/core/tfm_nspm.c index 6753dba77a..e9a71d1a13 100644 --- a/secure_fw/core/tfm_nspm.c +++ b/secure_fw/core/tfm_nspm.c @@ -6,12 +6,14 @@ */ #include <stdbool.h> +#include "cmsis_compiler.h" +#include "platform/include/tfm_spm_hal.h" #include "secure_utilities.h" #include "tfm_arch.h" #include "tfm_api.h" +#include "tfm_internal.h" #if TFM_PSA_API #include "tfm_utils.h" -#include "tfm_internal.h" #endif #ifndef TFM_MAX_NS_THREAD_COUNT @@ -24,6 +26,15 @@ #define INVALID_NS_CLIENT_IDX (-1) #define DEFAULT_NS_CLIENT_IDX 0 +#if defined ( __GNUC__ ) +/* The macro cmse_nsfptr_create defined in the gcc library uses the non-standard + * gcc C lanuage extension 'typeof'. TF-M is built with '-std=c99' so typeof + * cannot be used in the code. As a workaround cmse_nsfptr_create is redefined + * here to use only standard language elements. */ +#undef cmse_nsfptr_create +#define cmse_nsfptr_create(p) ((intptr_t) (p) & ~1) +#endif + typedef uint32_t TZ_ModuleId_t; typedef uint32_t TZ_MemoryId_t; @@ -322,3 +333,22 @@ psa_status_t tfm_nspm_thread_entry(void) return PSA_SUCCESS; } #endif + +void configure_ns_code(void) +{ + /* SCB_NS.VTOR points to the Non-secure vector table base address */ + SCB_NS->VTOR = tfm_spm_hal_get_ns_VTOR(); + + /* Setups Main stack pointer of the non-secure code */ + uint32_t ns_msp = tfm_spm_hal_get_ns_MSP(); + + __TZ_set_MSP_NS(ns_msp); + + /* Get the address of non-secure code entry point to jump there */ + uint32_t entry_ptr = tfm_spm_hal_get_ns_entry_point(); + + /* Clears LSB of the function address to indicate the function-call + * will perform the switch from secure to non-secure + */ + ns_entry = (nsfptr_t) cmse_nsfptr_create(entry_ptr); +} diff --git a/secure_fw/core/tfm_nspm.h b/secure_fw/core/tfm_nspm.h index 572c734c0f..fa2f59f0f7 100644 --- a/secure_fw/core/tfm_nspm.h +++ b/secure_fw/core/tfm_nspm.h @@ -34,4 +34,14 @@ int32_t tfm_nspm_get_current_client_id(void); psa_status_t tfm_nspm_thread_entry(void); #endif +#ifdef TFM_MULTI_CORE_TOPOLOGY +/* Unnecessary to configure Non-secure side code */ +#define configure_ns_code() do {} while (0) +#else +/* + * \brief Configure Non-secure code, such as vector table, MSP and entry point. + */ +void configure_ns_code(void); +#endif + #endif /* __TFM_NSPM_H__ */ |