diff --git a/components/TARGET_PSA/TARGET_TFM/COMPONENT_NSPE/interface/src/tfm_ns_lock_rtx.c b/components/TARGET_PSA/TARGET_TFM/COMPONENT_NSPE/interface/src/tfm_ns_lock_rtx.c index 76b284efff..ef6cfe0f92 100644 --- a/components/TARGET_PSA/TARGET_TFM/COMPONENT_NSPE/interface/src/tfm_ns_lock_rtx.c +++ b/components/TARGET_PSA/TARGET_TFM/COMPONENT_NSPE/interface/src/tfm_ns_lock_rtx.c @@ -8,7 +8,6 @@ #include #include "cmsis.h" -#include "rtx_os.h" #include "cmsis_os2.h" #include "tfm_api.h" @@ -31,14 +30,9 @@ static struct ns_lock_state ns_lock = {.init=false, .id=NULL}; /** * \brief Mutex properties, NS lock */ - -static osRtxMutex_t ns_lock_cb = { 0 }; - static const osMutexAttr_t ns_lock_attrib = { .name = "ns_lock", - .attr_bits = osMutexPrioInherit, - .cb_mem = &ns_lock_cb, - .cb_size = sizeof(ns_lock_cb) + .attr_bits = osMutexPrioInherit }; /** diff --git a/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/CMakeLists.inc b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/CMakeLists.inc new file mode 100644 index 0000000000..0b290d5b01 --- /dev/null +++ b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/CMakeLists.inc @@ -0,0 +1,71 @@ +#------------------------------------------------------------------------------- +# Copyright (c) 2017-2018, Arm Limited. All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause +# +#------------------------------------------------------------------------------- + +#Definitions to compile the "core" module. +#This file assumes it will be included from a project specific cmakefile, and +#will not create a library or executable. +#Inputs: +# TFM_ROOT_DIR - directory where secure FW sourec is located. +# +#Outputs: +# Will modify include directories to make the source compile. +# ALL_SRC_C: C source files to be compiled will be added to this list. +# This shall be added to your add_executable or add_library command. +# ALL_SRC_CXX: C++ source files to be compiled will be added to this list. +# This shall be added to your add_executable or add_library command. +# ALL_SRC_ASM: assembly source files to be compiled will be added to this +# list. This shall be added to your add_executable or add_library +# command. +# Include directories will be modified by using the include_directories() +# commands as needed. + +#Get the current directory where this file is located. +set(SS_CORE_DIR ${CMAKE_CURRENT_LIST_DIR}) +if(NOT DEFINED TFM_ROOT_DIR) + message(FATAL_ERROR + "Please set TFM_ROOT_DIR before including this file.") +endif() + +set (SS_CORE_C_SRC + "${SS_CORE_DIR}/tfm_core.c" + "${SS_CORE_DIR}/tfm_handler.c" + "${SS_CORE_DIR}/tfm_secure_api.c" + "${SS_CORE_DIR}/tfm_spm_services.c" + "${SS_CORE_DIR}/tfm_nspm.c" + "${SS_CORE_DIR}/tfm_boot_data.c" + ) + +#Append all our source files to global lists. +list(APPEND ALL_SRC_C ${SS_CORE_C_SRC}) +unset(SS_CORE_C_SRC) + +#Setting include directories +embedded_include_directories(PATH ${TFM_ROOT_DIR} ABSOLUTE) +embedded_include_directories(PATH ${TFM_ROOT_DIR}/interface/include ABSOLUTE) +embedded_include_directories(PATH ${TFM_ROOT_DIR}/secure_fw/spm ABSOLUTE) +embedded_include_directories(PATH ${TFM_ROOT_DIR}/secure_fw/core ABSOLUTE) + +set(BUILD_CMSIS_CORE Off) +set(BUILD_RETARGET Off) +set(BUILD_NATIVE_DRIVERS Off) +set(BUILD_STARTUP Off) +set(BUILD_TARGET_CFG Off) +set(BUILD_TARGET_HARDWARE_KEYS Off) +set(BUILD_TARGET_NV_COUNTERS Off) +set(BUILD_CMSIS_DRIVERS Off) +set(BUILD_TIME Off) +set(BUILD_UART_STDOUT Off) +set(BUILD_FLASH Off) +set(BUILD_BOOT_SEED Off) +set(BUILD_DEVICE_ID Off) +if(NOT DEFINED PLATFORM_CMAKE_FILE) + message (FATAL_ERROR "Platform specific CMake is not defined. Please set PLATFORM_CMAKE_FILE.") +elseif(NOT EXISTS ${PLATFORM_CMAKE_FILE}) + message (FATAL_ERROR "Platform specific CMake \"${PLATFORM_CMAKE_FILE}\" file does not exist. Please fix value of PLATFORM_CMAKE_FILE.") +else() + include(${PLATFORM_CMAKE_FILE}) +endif() diff --git a/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/CMakeLists.inc b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/CMakeLists.inc new file mode 100644 index 0000000000..59c074e60f --- /dev/null +++ b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/CMakeLists.inc @@ -0,0 +1,74 @@ +#------------------------------------------------------------------------------- +# Copyright (c) 2018, Arm Limited. All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause +# +#------------------------------------------------------------------------------- + +#Definitions to compile the "ipc" module. +#This file assumes it will be included from a project specific cmakefile, and +#will not create a library or executable. +#Inputs: +# TFM_ROOT_DIR - directory where secure FW sourec is located. +# +#Outputs: +# Will modify include directories to make the source compile. +# ALL_SRC_C: C source files to be compiled will be added to this list. +# This shall be added to your add_executable or add_library command. +# ALL_SRC_CXX: C++ source files to be compiled will be added to this list. +# This shall be added to your add_executable or add_library command. +# ALL_SRC_ASM: assembly source files to be compiled will be added to this +# list. This shall be added to your add_executable or add_library +# command. +# Include directories will be modified by using the include_directories() +# commands as needed. + +#Get the current directory where this file is located. +set(SS_IPC_DIR ${CMAKE_CURRENT_LIST_DIR}) +if(NOT DEFINED TFM_ROOT_DIR) + message(FATAL_ERROR + "Please set TFM_ROOT_DIR before including this file.") +endif() + +if (NOT DEFINED TFM_PSA_API) + message(FATAL_ERROR "Incomplete build configuration: TFM_PSA_API is undefined. ") +elseif (TFM_PSA_API) + set (SS_IPC_C_SRC "${SS_IPC_DIR}/tfm_svcalls.c" + "${SS_IPC_DIR}/psa_service.c" + "${SS_IPC_DIR}/psa_client.c" + "${SS_IPC_DIR}/tfm_arch_v8m.c" + "${SS_IPC_DIR}/tfm_thread.c" + "${SS_IPC_DIR}/tfm_wait.c" + "${SS_IPC_DIR}/tfm_utils.c" + "${SS_IPC_DIR}/tfm_message_queue.c" + "${SS_IPC_DIR}/tfm_pools.c" + "${SS_IPC_DIR}/tfm_spm.c" + "${SS_IPC_DIR}/../tfm_core.c" + "${SS_IPC_DIR}/../tfm_secure_api.c" + "${SS_IPC_DIR}/../tfm_spm_services.c" + "${SS_IPC_DIR}/../tfm_handler.c" + "${SS_IPC_DIR}/../tfm_psa_api_client.c" + "${SS_IPC_DIR}/../tfm_nspm.c" + "${SS_IPC_DIR}/../tfm_boot_data.c" + ) +endif() + +#Append all our source files to global lists. +list(APPEND ALL_SRC_C ${SS_IPC_C_SRC}) +unset(SS_IPC_C_SRC) + +#Setting include directories +embedded_include_directories(PATH ${TFM_ROOT_DIR} ABSOLUTE) +embedded_include_directories(PATH ${TFM_ROOT_DIR}/interface/include ABSOLUTE) +embedded_include_directories(PATH ${TFM_ROOT_DIR}/secure_fw/spm ABSOLUTE) +embedded_include_directories(PATH ${TFM_ROOT_DIR}/secure_fw/core ABSOLUTE) +embedded_include_directories(PATH ${TFM_ROOT_DIR}/secure_fw/core/ipc ABSOLUTE) +embedded_include_directories(PATH ${TFM_ROOT_DIR}/secure_fw/core/ipc/include ABSOLUTE) + +if(NOT DEFINED PLATFORM_CMAKE_FILE) + message (FATAL_ERROR "Platform specific CMake is not defined. Please set PLATFORM_CMAKE_FILE.") +elseif(NOT EXISTS ${PLATFORM_CMAKE_FILE}) + message (FATAL_ERROR "Platform specific CMake \"${PLATFORM_CMAKE_FILE}\" file does not exist. Please fix value of PLATFORM_CMAKE_FILE.") +else() + include(${PLATFORM_CMAKE_FILE}) +endif() diff --git a/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/include/tfm_message_queue.h b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/include/tfm_message_queue.h index 31bcda9482..6ecb34a631 100644 --- a/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/include/tfm_message_queue.h +++ b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/include/tfm_message_queue.h @@ -7,9 +7,7 @@ #ifndef __TFM_MESSAGE_QUEUE_H__ #define __TFM_MESSAGE_QUEUE_H__ -#ifndef TFM_MSG_QUEUE_MAX_MSG_NUM #define TFM_MSG_QUEUE_MAX_MSG_NUM 128 -#endif #define TFM_MSG_MAGIC 0x15154343 /* Message struct to collect parameter from client */ struct tfm_msg_body_t { diff --git a/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/include/tfm_spm.h b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/include/tfm_spm.h index 0fd3a8f800..e9e18d04d4 100644 --- a/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/include/tfm_spm.h +++ b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/include/tfm_spm.h @@ -10,15 +10,11 @@ #include #include "tfm_list.h" -#ifndef TFM_SPM_MAX_ROT_SERV_NUM #define TFM_SPM_MAX_ROT_SERV_NUM 28 -#endif #define TFM_VERSION_POLICY_RELAXED 0 #define TFM_VERSION_POLICY_STRICT 1 -#ifndef TFM_CONN_HANDLE_MAX_NUM #define TFM_CONN_HANDLE_MAX_NUM 32 -#endif /* RoT connection handle list */ struct tfm_conn_handle_t { diff --git a/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/include/tfm_spm_signal_defs.h b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/include/tfm_spm_signal_defs.h new file mode 100644 index 0000000000..e632354680 --- /dev/null +++ b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/include/tfm_spm_signal_defs.h @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2018, Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + * + */ +#ifndef __TFM_SPM_SIGNAL_DEFS_H__ +#define __TFM_SPM_SIGNAL_DEFS_H__ + +#include "test/test_services/tfm_ipc_service/tfm_ipc_service_partition.h" + +#endif diff --git a/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/tfm_spm.c b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/tfm_spm.c index b69a0ce5ba..1c06cd3d82 100644 --- a/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/tfm_spm.c +++ b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/tfm_spm.c @@ -45,7 +45,7 @@ TFM_POOL_DECLARE(msg_db_pool, sizeof(struct tfm_msg_body_t), TFM_MSG_QUEUE_MAX_MSG_NUM); static struct tfm_spm_service_db_t g_spm_service_db[] = { - #include "tfm_service_list.inc" + #include "secure_fw/services/tfm_service_list.inc" }; /********************** SPM functions for handler mode ***********************/ @@ -108,8 +108,6 @@ int32_t tfm_spm_free_conn_handle(struct tfm_spm_service_t *service, /* Remove node from handle list */ tfm_list_del_node(&node->list); - node->rhandle = NULL; - /* Back handle buffer to pool */ tfm_pool_free(node); return IPC_SUCCESS; @@ -272,7 +270,7 @@ int32_t tfm_spm_check_client_version(struct tfm_spm_service_t *service, switch (service->service_db->minor_policy) { case TFM_VERSION_POLICY_RELAXED: - if (minor_version > service->service_db->minor_version) { + if (minor_version < service->service_db->minor_version) { return IPC_ERROR_VERSION; } break; @@ -435,19 +433,15 @@ tfm_spm_partition_get_thread_info_ext(uint32_t partition_idx) return &g_spm_partition_db.partitions[partition_idx].sp_thrd; } -static uint32_t tfm_spm_partition_get_stack_size_ext(uint32_t partition_idx) +static uint32_t tfm_spm_partition_get_stack_base_ext(uint32_t partition_idx) { - return g_spm_partition_db.partitions[partition_idx].stack_size; + return (uint32_t)&(g_spm_partition_db.partitions[partition_idx]. + stack[TFM_STACK_SIZE]); } static uint32_t tfm_spm_partition_get_stack_limit_ext(uint32_t partition_idx) { - return g_spm_partition_db.partitions[partition_idx].stack_limit; -} - -static uint32_t tfm_spm_partition_get_stack_base_ext(uint32_t partition_idx) -{ - return tfm_spm_partition_get_stack_limit_ext(partition_idx) + tfm_spm_partition_get_stack_size_ext(partition_idx); + return (uint32_t)&g_spm_partition_db.partitions[partition_idx].stack; } static tfm_thrd_func_t @@ -466,12 +460,10 @@ static uint32_t tfm_spm_partition_get_priority_ext(uint32_t partition_idx) /* Macros to pick linker symbols and allow references to sections in all level*/ #define REGION_DECLARE_EXT(a, b, c) extern uint32_t REGION_NAME(a, b, c) -REGION_DECLARE_EXT(Image$$, ARM_LIB_HEAP, $$ZI$$Base); -REGION_DECLARE_EXT(Image$$, ARM_LIB_HEAP, $$ZI$$Limit); -REGION_DECLARE_EXT(Image$$, ER_TFM_DATA, $$Base); -REGION_DECLARE_EXT(Image$$, ER_TFM_DATA, $$Limit); REGION_DECLARE_EXT(Image$$, ER_TFM_DATA, $$ZI$$Base); REGION_DECLARE_EXT(Image$$, ER_TFM_DATA, $$ZI$$Limit); +REGION_DECLARE_EXT(Image$$, ER_TFM_DATA, $$RW$$Base); +REGION_DECLARE_EXT(Image$$, ER_TFM_DATA, $$RW$$Limit); REGION_DECLARE_EXT(Image$$, TFM_SECURE_STACK, $$ZI$$Base); REGION_DECLARE_EXT(Image$$, TFM_SECURE_STACK, $$ZI$$Limit); REGION_DECLARE_EXT(Image$$, TFM_UNPRIV_SCRATCH, $$ZI$$Base); @@ -523,15 +515,9 @@ int32_t tfm_memory_check(void *buffer, size_t len, int32_t ns_caller) if (memory_check_range(buffer, len, base, limit) == IPC_SUCCESS) { return IPC_SUCCESS; } - - base = (uintptr_t)NS_CODE_START; - limit = (uintptr_t)(NS_CODE_START + NS_CODE_SIZE); - if (memory_check_range(buffer, len, base, limit) == IPC_SUCCESS) { - return IPC_SUCCESS; - } } else { - base = (uintptr_t)®ION_NAME(Image$$, ARM_LIB_HEAP, $$ZI$$Base); - limit = (uintptr_t)®ION_NAME(Image$$, ARM_LIB_HEAP, $$ZI$$Limit); + base = (uintptr_t)®ION_NAME(Image$$, ER_TFM_DATA, $$RW$$Base); + limit = (uintptr_t)®ION_NAME(Image$$, ER_TFM_DATA, $$RW$$Limit); if (memory_check_range(buffer, len, base, limit) == IPC_SUCCESS) { return IPC_SUCCESS; } @@ -542,12 +528,6 @@ int32_t tfm_memory_check(void *buffer, size_t len, int32_t ns_caller) return IPC_SUCCESS; } - base = (uintptr_t)®ION_NAME(Image$$, ER_TFM_DATA, $$Base); - limit = (uintptr_t)®ION_NAME(Image$$, ER_TFM_DATA, $$Limit); - if (memory_check_range(buffer, len, base, limit) == IPC_SUCCESS) { - return IPC_SUCCESS; - } - base = (uintptr_t)®ION_NAME(Image$$, TFM_SECURE_STACK, $$ZI$$Base); limit = (uintptr_t)®ION_NAME(Image$$, TFM_SECURE_STACK, $$ZI$$Limit); if (memory_check_range(buffer, len, base, limit) == IPC_SUCCESS) { @@ -560,12 +540,6 @@ int32_t tfm_memory_check(void *buffer, size_t len, int32_t ns_caller) if (memory_check_range(buffer, len, base, limit) == IPC_SUCCESS) { return IPC_SUCCESS; } - - base = (uintptr_t)S_CODE_START; - limit = (uintptr_t)(S_CODE_START + S_CODE_SIZE); - if (memory_check_range(buffer, len, base, limit) == IPC_SUCCESS) { - return IPC_SUCCESS; - } } return IPC_ERROR_MEMORY_CHECK; diff --git a/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/tfm_thread.c b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/tfm_thread.c index 39f42ee234..359aa71db8 100644 --- a/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/tfm_thread.c +++ b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/tfm_thread.c @@ -21,15 +21,8 @@ static struct tfm_thrd_ctx *p_curr_thrd = NULL; #define RUNN_HEAD p_runn_head #define CURR_THRD p_curr_thrd -/* To get next running thread for scheduler */ -struct tfm_thrd_ctx *tfm_thrd_next_thread(void) +static struct tfm_thrd_ctx *find_next_running_thread(struct tfm_thrd_ctx *pth) { - struct tfm_thrd_ctx *pth = RUNN_HEAD; - - /* - * First RUNNING thread has highest priority since threads are sorted with - * priority. - */ while (pth && pth->status != THRD_STAT_RUNNING) { pth = pth->next; } @@ -37,6 +30,16 @@ struct tfm_thrd_ctx *tfm_thrd_next_thread(void) return pth; } +/* To get next running thread for scheduler */ +struct tfm_thrd_ctx *tfm_thrd_next_thread(void) +{ + /* + * First RUNNING thread has highest priority since threads are sorted with + * priority. + */ + return find_next_running_thread(RUNN_HEAD); +} + /* To get current thread for caller */ struct tfm_thrd_ctx *tfm_thrd_curr_thread() { @@ -69,10 +72,10 @@ static void update_running_head(struct tfm_thrd_ctx **runn, struct tfm_thrd_ctx *node) { if ((node->status == THRD_STAT_RUNNING) && - (*runn == NULL || (node->prior <= (*runn)->prior))) { + (*runn == NULL || (node->prior < (*runn)->prior))) { *runn = node; } else { - *runn = tfm_thrd_next_thread(); + *runn = find_next_running_thread(LIST_HEAD); } } diff --git a/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/secure_utilities.h b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/secure_utilities.h index d35cdc7de2..32030fd564 100644 --- a/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/secure_utilities.h +++ b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/secure_utilities.h @@ -25,8 +25,6 @@ #define EXC_NUM_PENDSV (14) #define EXC_NUM_SYSTICK (15) -#define printf(...) - /* Disable NS exceptions by setting NS PRIMASK to 1 */ #define TFM_NS_EXC_DISABLE() __TZ_set_PRIMASK_NS(1) /* Enable NS exceptions by setting NS PRIMASK to 0 */ diff --git a/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/tfm_core.c b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/tfm_core.c index db5921061e..7cf65082a9 100644 --- a/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/tfm_core.c +++ b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/tfm_core.c @@ -11,6 +11,7 @@ #include "tfm_internal.h" #include "tfm_api.h" #include "platform/include/tfm_spm_hal.h" +#include "uart_stdout.h" #include "secure_utilities.h" #include "secure_fw/spm/spm_api.h" #include "secure_fw/include/tfm_spm_services_api.h" @@ -87,6 +88,7 @@ int32_t tfm_core_init(void) __enable_irq(); + stdio_init(); LOG_MSG("Secure image initializing!"); #ifdef TFM_CORE_DEBUG diff --git a/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/tfm_psa_api_client.c b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/tfm_psa_api_client.c index 36f2c16358..4b35c58e7f 100644 --- a/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/tfm_psa_api_client.c +++ b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/tfm_psa_api_client.c @@ -48,8 +48,7 @@ int32_t tfm_core_ns_ipc_request(void *fn, int32_t arg1, int32_t arg2, int32_t arg3, int32_t arg4) { int32_t args[4] = {arg1, arg2, arg3, arg4}; - volatile struct tfm_sfn_req_s desc; - struct tfm_sfn_req_s *desc_ptr = &desc; + struct tfm_sfn_req_s desc, *desc_ptr = &desc; int32_t res; desc.sfn = fn; @@ -99,7 +98,7 @@ psa_handle_t tfm_psa_connect_veneer(uint32_t sid, uint32_t minor_version) __tfm_secure_gateway_attributes__ psa_status_t tfm_psa_call_veneer(psa_handle_t handle, const psa_invec *in_vecs, - psa_outvec *out_vecs) + const psa_invec *out_vecs) { TFM_CORE_NS_IPC_REQUEST_VENEER(tfm_svcall_psa_call, handle, in_vecs, out_vecs, 0); diff --git a/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/tfm_secure_api.c b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/tfm_secure_api.c index e0663b4adb..698f17af2f 100644 --- a/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/tfm_secure_api.c +++ b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/tfm_secure_api.c @@ -12,6 +12,7 @@ #include "tfm_secure_api.h" #include "tfm_nspm.h" #include "secure_utilities.h" +#include "uart_stdout.h" #include "secure_fw/spm/spm_api.h" #include "region_defs.h" #include "tfm_api.h" diff --git a/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/spm/CMakeLists.inc b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/spm/CMakeLists.inc new file mode 100644 index 0000000000..d1e57d888f --- /dev/null +++ b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/spm/CMakeLists.inc @@ -0,0 +1,61 @@ +#------------------------------------------------------------------------------- +# Copyright (c) 2017-2018, Arm Limited. All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause +# +#------------------------------------------------------------------------------- + +#Definitions to compile the "spm" module. +#This file assumes it will be included from a project specific cmakefile, and +#will not create a library or executable. +#Inputs: +# TFM_ROOT_DIR - root directory of the TF-M repository. +# +#Outputs: +# Will modify include directories to make the source compile. +# ALL_SRC_C: C source files to be compiled will be added to this list. This shall be added to your add_executable or add_library command. +# ALL_SRC_CXX: C++ source files to be compiled will be added to this list. This shall be added to your add_executable or add_library command. +# ALL_SRC_ASM: assembly source files to be compiled will be added to this list. This shall be added to your add_executable or add_library command. +# Include directories will be modified by using the include_directories() commands as needed. + +#Get the current directory where this file is located. +set(SS_SPM_DIR ${CMAKE_CURRENT_LIST_DIR}) +if(NOT DEFINED TFM_ROOT_DIR) + message(FATAL_ERROR "Please set TFM_ROOT_DIR before including this file.") +endif() + +set (SS_SPM_C_SRC "${SS_SPM_DIR}/spm_api.c") + + +#Append all our source files to global lists. +list(APPEND ALL_SRC_C ${SS_SPM_C_SRC}) +unset(SS_SPM_C_SRC) + +#Setting include directories +embedded_include_directories(PATH ${TFM_ROOT_DIR} ABSOLUTE) +embedded_include_directories(PATH ${TFM_ROOT_DIR}/interface/include ABSOLUTE) +embedded_include_directories(PATH ${TFM_ROOT_DIR}/secure_fw/spm ABSOLUTE) +embedded_include_directories(PATH ${TFM_ROOT_DIR}/secure_fw/core ABSOLUTE) +embedded_include_directories(PATH ${TFM_ROOT_DIR} ABSOLUTE) + +set(BUILD_CMSIS_CORE Off) +set(BUILD_RETARGET Off) +set(BUILD_NATIVE_DRIVERS Off) +set(BUILD_STARTUP Off) +set(BUILD_TARGET_CFG Off) +set(BUILD_TARGET_HARDWARE_KEYS Off) +set(BUILD_TARGET_NV_COUNTERS Off) +set(BUILD_CMSIS_DRIVERS Off) +set(BUILD_TIME Off) +set(BUILD_UART_STDOUT Off) +set(BUILD_FLASH Off) +set(BUILD_BOOT_SEED Off) +set(BUILD_DEVICE_ID Off) +if(NOT DEFINED PLATFORM_CMAKE_FILE) + message (FATAL_ERROR "Platform specific CMake is not defined. Please set PLATFORM_CMAKE_FILE.") +elseif(NOT EXISTS ${PLATFORM_CMAKE_FILE}) + message (FATAL_ERROR "Platform specific CMake \"${PLATFORM_CMAKE_FILE}\" file does not exist. Please fix value of PLATFORM_CMAKE_FILE.") +else() + include(${PLATFORM_CMAKE_FILE}) +endif() + diff --git a/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/spm/spm_api.c b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/spm/spm_api.c index 6331c30c49..bcdf42138c 100644 --- a/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/spm/spm_api.c +++ b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/spm/spm_api.c @@ -123,7 +123,7 @@ enum spm_err_t tfm_spm_db_init(void) ++g_spm_partition_db.partition_count; /* Add user-defined secure partitions */ - #include "tfm_partition_list.inc" + #include "secure_fw/services/tfm_partition_list.inc" g_spm_partition_db.is_init = 1; @@ -141,12 +141,12 @@ enum spm_err_t tfm_spm_partition_init(void) /* Call the init function for each partition */ for (idx = 0; idx < g_spm_partition_db.partition_count; ++idx) { part = &g_spm_partition_db.partitions[idx]; + tfm_spm_hal_configure_default_isolation(part->platform_data); #ifdef TFM_PSA_API if (part->static_data.partition_flags & SPM_PART_FLAG_IPC) { continue; } #endif - tfm_spm_hal_configure_default_isolation(part->platform_data); if (part->static_data.partition_init == NULL) { tfm_spm_partition_set_state(idx, SPM_PARTITION_STATE_IDLE); tfm_spm_partition_set_caller_partition_idx(idx, diff --git a/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/spm/spm_db.h b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/spm/spm_db.h index 60b5fbd456..fc3da43e45 100644 --- a/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/spm/spm_db.h +++ b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/spm/spm_db.h @@ -66,10 +66,11 @@ struct spm_partition_desc_t { #ifdef TFM_PSA_API struct tfm_thrd_ctx sp_thrd; /* - * stack_limit points to starting address of the partitions' stack plus the partitions' stack size. + * FixMe: Hard code stack is not aligned with the definition in the + * manifest. It will use the partition stacks in the linker scripts/sct + * files include Level 1 to 3. */ - uint32_t stack_limit; - uint32_t stack_size; + uint8_t stack[TFM_STACK_SIZE] __attribute__((aligned(8))); #endif }; diff --git a/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/spm/spm_db_setup.h b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/spm/spm_db_setup.h index a15e7b7cb1..217cfaa39b 100644 --- a/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/spm/spm_db_setup.h +++ b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/spm/spm_db_setup.h @@ -71,7 +71,7 @@ struct spm_partition_db_t { } while (0) #endif -#define PARTITION_DECLARE(partition, flag, type, id, priority, part_stack_size) \ +#define PARTITION_DECLARE(partition, flag, type, id, priority) \ do { \ REGION_DECLARE(Image$$, partition, $$Base); \ REGION_DECLARE(Image$$, partition, $$Limit); \ @@ -97,12 +97,8 @@ struct spm_partition_db_t { if (g_spm_partition_db.partition_count >= SPM_MAX_PARTITIONS) { \ return SPM_ERR_INVALID_CONFIG; \ } \ - __attribute__((section(".data.partitions_stacks"))) \ - static uint8_t partition##_stack[part_stack_size] __attribute__((aligned(8))); \ part_ptr = &(g_spm_partition_db.partitions[ \ g_spm_partition_db.partition_count]); \ - part_ptr->stack_limit = (uint32_t)partition##_stack; \ - part_ptr->stack_size = part_stack_size; \ PARTITION_INIT_STATIC_DATA(part_ptr->static_data, partition, flags, \ id, priority); \ PARTITION_INIT_RUNTIME_DATA(part_ptr->runtime_data, partition); \ diff --git a/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/spm/spm_partition_defs.h b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/spm/spm_partition_defs.h index 0533881f87..85ab1eca6e 100644 --- a/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/spm/spm_partition_defs.h +++ b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/spm/spm_partition_defs.h @@ -29,7 +29,7 @@ */ #define TFM_SP_CORE_ID (1) -#include "tfm_partition_defs.inc" +#include "secure_fw/services/tfm_partition_defs.inc" /* This limit is only used to define the size of the database reserved for * partitions. There's no requirement that it match the number of partitions diff --git a/components/TARGET_PSA/TARGET_TFM/interface/include/tfm_api.h b/components/TARGET_PSA/TARGET_TFM/interface/include/tfm_api.h index 79a94cbdd0..7656908fa4 100644 --- a/components/TARGET_PSA/TARGET_TFM/interface/include/tfm_api.h +++ b/components/TARGET_PSA/TARGET_TFM/interface/include/tfm_api.h @@ -105,13 +105,13 @@ psa_handle_t tfm_psa_connect_veneer(uint32_t sid, uint32_t minor_version); * * \param[in] handle Handle to connection * \param[in] in_vecs invec containing pointer/count of input vectors - * \param[in] out_vecs outvec containing pointer/count of output vectors + * \param[in] out_vecs invec containing pointer/count of output vectors * * \return Returns \ref psa_status_t status code */ psa_status_t tfm_psa_call_veneer(psa_handle_t handle, const psa_invec *in_vecs, - psa_outvec *out_vecs); + const psa_invec *out_vecs); /** * \brief Close connection to secure function referenced by a connection handle