Skip to content

Commit 823e5a2

Browse files
author
Michael Schwarcz
committed
[trusted-firmware-m]: Updated to f876e5c
1 parent ca06f94 commit 823e5a2

File tree

18 files changed

+256
-76
lines changed

18 files changed

+256
-76
lines changed

components/TARGET_PSA/TARGET_TFM/COMPONENT_NSPE/interface/src/tfm_ns_lock_rtx.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <stdbool.h>
99

1010
#include "cmsis.h"
11-
#include "rtx_os.h"
1211
#include "cmsis_os2.h"
1312

1413
#include "tfm_api.h"
@@ -31,14 +30,9 @@ static struct ns_lock_state ns_lock = {.init=false, .id=NULL};
3130
/**
3231
* \brief Mutex properties, NS lock
3332
*/
34-
35-
static osRtxMutex_t ns_lock_cb = { 0 };
36-
3733
static const osMutexAttr_t ns_lock_attrib = {
3834
.name = "ns_lock",
39-
.attr_bits = osMutexPrioInherit,
40-
.cb_mem = &ns_lock_cb,
41-
.cb_size = sizeof(ns_lock_cb)
35+
.attr_bits = osMutexPrioInherit
4236
};
4337

4438
/**
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#-------------------------------------------------------------------------------
2+
# Copyright (c) 2017-2018, Arm Limited. All rights reserved.
3+
#
4+
# SPDX-License-Identifier: BSD-3-Clause
5+
#
6+
#-------------------------------------------------------------------------------
7+
8+
#Definitions to compile the "core" module.
9+
#This file assumes it will be included from a project specific cmakefile, and
10+
#will not create a library or executable.
11+
#Inputs:
12+
# TFM_ROOT_DIR - directory where secure FW sourec is located.
13+
#
14+
#Outputs:
15+
# Will modify include directories to make the source compile.
16+
# ALL_SRC_C: C source files to be compiled will be added to this list.
17+
# This shall be added to your add_executable or add_library command.
18+
# ALL_SRC_CXX: C++ source files to be compiled will be added to this list.
19+
# This shall be added to your add_executable or add_library command.
20+
# ALL_SRC_ASM: assembly source files to be compiled will be added to this
21+
# list. This shall be added to your add_executable or add_library
22+
# command.
23+
# Include directories will be modified by using the include_directories()
24+
# commands as needed.
25+
26+
#Get the current directory where this file is located.
27+
set(SS_CORE_DIR ${CMAKE_CURRENT_LIST_DIR})
28+
if(NOT DEFINED TFM_ROOT_DIR)
29+
message(FATAL_ERROR
30+
"Please set TFM_ROOT_DIR before including this file.")
31+
endif()
32+
33+
set (SS_CORE_C_SRC
34+
"${SS_CORE_DIR}/tfm_core.c"
35+
"${SS_CORE_DIR}/tfm_handler.c"
36+
"${SS_CORE_DIR}/tfm_secure_api.c"
37+
"${SS_CORE_DIR}/tfm_spm_services.c"
38+
"${SS_CORE_DIR}/tfm_nspm.c"
39+
"${SS_CORE_DIR}/tfm_boot_data.c"
40+
)
41+
42+
#Append all our source files to global lists.
43+
list(APPEND ALL_SRC_C ${SS_CORE_C_SRC})
44+
unset(SS_CORE_C_SRC)
45+
46+
#Setting include directories
47+
embedded_include_directories(PATH ${TFM_ROOT_DIR} ABSOLUTE)
48+
embedded_include_directories(PATH ${TFM_ROOT_DIR}/interface/include ABSOLUTE)
49+
embedded_include_directories(PATH ${TFM_ROOT_DIR}/secure_fw/spm ABSOLUTE)
50+
embedded_include_directories(PATH ${TFM_ROOT_DIR}/secure_fw/core ABSOLUTE)
51+
52+
set(BUILD_CMSIS_CORE Off)
53+
set(BUILD_RETARGET Off)
54+
set(BUILD_NATIVE_DRIVERS Off)
55+
set(BUILD_STARTUP Off)
56+
set(BUILD_TARGET_CFG Off)
57+
set(BUILD_TARGET_HARDWARE_KEYS Off)
58+
set(BUILD_TARGET_NV_COUNTERS Off)
59+
set(BUILD_CMSIS_DRIVERS Off)
60+
set(BUILD_TIME Off)
61+
set(BUILD_UART_STDOUT Off)
62+
set(BUILD_FLASH Off)
63+
set(BUILD_BOOT_SEED Off)
64+
set(BUILD_DEVICE_ID Off)
65+
if(NOT DEFINED PLATFORM_CMAKE_FILE)
66+
message (FATAL_ERROR "Platform specific CMake is not defined. Please set PLATFORM_CMAKE_FILE.")
67+
elseif(NOT EXISTS ${PLATFORM_CMAKE_FILE})
68+
message (FATAL_ERROR "Platform specific CMake \"${PLATFORM_CMAKE_FILE}\" file does not exist. Please fix value of PLATFORM_CMAKE_FILE.")
69+
else()
70+
include(${PLATFORM_CMAKE_FILE})
71+
endif()
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#-------------------------------------------------------------------------------
2+
# Copyright (c) 2018, Arm Limited. All rights reserved.
3+
#
4+
# SPDX-License-Identifier: BSD-3-Clause
5+
#
6+
#-------------------------------------------------------------------------------
7+
8+
#Definitions to compile the "ipc" module.
9+
#This file assumes it will be included from a project specific cmakefile, and
10+
#will not create a library or executable.
11+
#Inputs:
12+
# TFM_ROOT_DIR - directory where secure FW sourec is located.
13+
#
14+
#Outputs:
15+
# Will modify include directories to make the source compile.
16+
# ALL_SRC_C: C source files to be compiled will be added to this list.
17+
# This shall be added to your add_executable or add_library command.
18+
# ALL_SRC_CXX: C++ source files to be compiled will be added to this list.
19+
# This shall be added to your add_executable or add_library command.
20+
# ALL_SRC_ASM: assembly source files to be compiled will be added to this
21+
# list. This shall be added to your add_executable or add_library
22+
# command.
23+
# Include directories will be modified by using the include_directories()
24+
# commands as needed.
25+
26+
#Get the current directory where this file is located.
27+
set(SS_IPC_DIR ${CMAKE_CURRENT_LIST_DIR})
28+
if(NOT DEFINED TFM_ROOT_DIR)
29+
message(FATAL_ERROR
30+
"Please set TFM_ROOT_DIR before including this file.")
31+
endif()
32+
33+
if (NOT DEFINED TFM_PSA_API)
34+
message(FATAL_ERROR "Incomplete build configuration: TFM_PSA_API is undefined. ")
35+
elseif (TFM_PSA_API)
36+
set (SS_IPC_C_SRC "${SS_IPC_DIR}/tfm_svcalls.c"
37+
"${SS_IPC_DIR}/psa_service.c"
38+
"${SS_IPC_DIR}/psa_client.c"
39+
"${SS_IPC_DIR}/tfm_arch_v8m.c"
40+
"${SS_IPC_DIR}/tfm_thread.c"
41+
"${SS_IPC_DIR}/tfm_wait.c"
42+
"${SS_IPC_DIR}/tfm_utils.c"
43+
"${SS_IPC_DIR}/tfm_message_queue.c"
44+
"${SS_IPC_DIR}/tfm_pools.c"
45+
"${SS_IPC_DIR}/tfm_spm.c"
46+
"${SS_IPC_DIR}/../tfm_core.c"
47+
"${SS_IPC_DIR}/../tfm_secure_api.c"
48+
"${SS_IPC_DIR}/../tfm_spm_services.c"
49+
"${SS_IPC_DIR}/../tfm_handler.c"
50+
"${SS_IPC_DIR}/../tfm_psa_api_client.c"
51+
"${SS_IPC_DIR}/../tfm_nspm.c"
52+
"${SS_IPC_DIR}/../tfm_boot_data.c"
53+
)
54+
endif()
55+
56+
#Append all our source files to global lists.
57+
list(APPEND ALL_SRC_C ${SS_IPC_C_SRC})
58+
unset(SS_IPC_C_SRC)
59+
60+
#Setting include directories
61+
embedded_include_directories(PATH ${TFM_ROOT_DIR} ABSOLUTE)
62+
embedded_include_directories(PATH ${TFM_ROOT_DIR}/interface/include ABSOLUTE)
63+
embedded_include_directories(PATH ${TFM_ROOT_DIR}/secure_fw/spm ABSOLUTE)
64+
embedded_include_directories(PATH ${TFM_ROOT_DIR}/secure_fw/core ABSOLUTE)
65+
embedded_include_directories(PATH ${TFM_ROOT_DIR}/secure_fw/core/ipc ABSOLUTE)
66+
embedded_include_directories(PATH ${TFM_ROOT_DIR}/secure_fw/core/ipc/include ABSOLUTE)
67+
68+
if(NOT DEFINED PLATFORM_CMAKE_FILE)
69+
message (FATAL_ERROR "Platform specific CMake is not defined. Please set PLATFORM_CMAKE_FILE.")
70+
elseif(NOT EXISTS ${PLATFORM_CMAKE_FILE})
71+
message (FATAL_ERROR "Platform specific CMake \"${PLATFORM_CMAKE_FILE}\" file does not exist. Please fix value of PLATFORM_CMAKE_FILE.")
72+
else()
73+
include(${PLATFORM_CMAKE_FILE})
74+
endif()

components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/include/tfm_message_queue.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
#ifndef __TFM_MESSAGE_QUEUE_H__
88
#define __TFM_MESSAGE_QUEUE_H__
99

10-
#ifndef TFM_MSG_QUEUE_MAX_MSG_NUM
1110
#define TFM_MSG_QUEUE_MAX_MSG_NUM 128
12-
#endif
1311
#define TFM_MSG_MAGIC 0x15154343
1412
/* Message struct to collect parameter from client */
1513
struct tfm_msg_body_t {

components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/include/tfm_spm.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,11 @@
1010
#include <stdbool.h>
1111
#include "tfm_list.h"
1212

13-
#ifndef TFM_SPM_MAX_ROT_SERV_NUM
1413
#define TFM_SPM_MAX_ROT_SERV_NUM 28
15-
#endif
1614
#define TFM_VERSION_POLICY_RELAXED 0
1715
#define TFM_VERSION_POLICY_STRICT 1
1816

19-
#ifndef TFM_CONN_HANDLE_MAX_NUM
2017
#define TFM_CONN_HANDLE_MAX_NUM 32
21-
#endif
2218

2319
/* RoT connection handle list */
2420
struct tfm_conn_handle_t {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*
6+
*/
7+
#ifndef __TFM_SPM_SIGNAL_DEFS_H__
8+
#define __TFM_SPM_SIGNAL_DEFS_H__
9+
10+
#include "test/test_services/tfm_ipc_service/tfm_ipc_service_partition.h"
11+
12+
#endif

components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/tfm_spm.c

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ TFM_POOL_DECLARE(msg_db_pool, sizeof(struct tfm_msg_body_t),
4545
TFM_MSG_QUEUE_MAX_MSG_NUM);
4646

4747
static struct tfm_spm_service_db_t g_spm_service_db[] = {
48-
#include "tfm_service_list.inc"
48+
#include "secure_fw/services/tfm_service_list.inc"
4949
};
5050

5151
/********************** SPM functions for handler mode ***********************/
@@ -108,8 +108,6 @@ int32_t tfm_spm_free_conn_handle(struct tfm_spm_service_t *service,
108108
/* Remove node from handle list */
109109
tfm_list_del_node(&node->list);
110110

111-
node->rhandle = NULL;
112-
113111
/* Back handle buffer to pool */
114112
tfm_pool_free(node);
115113
return IPC_SUCCESS;
@@ -272,7 +270,7 @@ int32_t tfm_spm_check_client_version(struct tfm_spm_service_t *service,
272270

273271
switch (service->service_db->minor_policy) {
274272
case TFM_VERSION_POLICY_RELAXED:
275-
if (minor_version > service->service_db->minor_version) {
273+
if (minor_version < service->service_db->minor_version) {
276274
return IPC_ERROR_VERSION;
277275
}
278276
break;
@@ -435,19 +433,15 @@ tfm_spm_partition_get_thread_info_ext(uint32_t partition_idx)
435433
return &g_spm_partition_db.partitions[partition_idx].sp_thrd;
436434
}
437435

438-
static uint32_t tfm_spm_partition_get_stack_size_ext(uint32_t partition_idx)
436+
static uint32_t tfm_spm_partition_get_stack_base_ext(uint32_t partition_idx)
439437
{
440-
return g_spm_partition_db.partitions[partition_idx].stack_size;
438+
return (uint32_t)&(g_spm_partition_db.partitions[partition_idx].
439+
stack[TFM_STACK_SIZE]);
441440
}
442441

443442
static uint32_t tfm_spm_partition_get_stack_limit_ext(uint32_t partition_idx)
444443
{
445-
return g_spm_partition_db.partitions[partition_idx].stack_limit;
446-
}
447-
448-
static uint32_t tfm_spm_partition_get_stack_base_ext(uint32_t partition_idx)
449-
{
450-
return tfm_spm_partition_get_stack_limit_ext(partition_idx) + tfm_spm_partition_get_stack_size_ext(partition_idx);
444+
return (uint32_t)&g_spm_partition_db.partitions[partition_idx].stack;
451445
}
452446

453447
static tfm_thrd_func_t
@@ -466,12 +460,10 @@ static uint32_t tfm_spm_partition_get_priority_ext(uint32_t partition_idx)
466460
/* Macros to pick linker symbols and allow references to sections in all level*/
467461
#define REGION_DECLARE_EXT(a, b, c) extern uint32_t REGION_NAME(a, b, c)
468462

469-
REGION_DECLARE_EXT(Image$$, ARM_LIB_HEAP, $$ZI$$Base);
470-
REGION_DECLARE_EXT(Image$$, ARM_LIB_HEAP, $$ZI$$Limit);
471-
REGION_DECLARE_EXT(Image$$, ER_TFM_DATA, $$Base);
472-
REGION_DECLARE_EXT(Image$$, ER_TFM_DATA, $$Limit);
473463
REGION_DECLARE_EXT(Image$$, ER_TFM_DATA, $$ZI$$Base);
474464
REGION_DECLARE_EXT(Image$$, ER_TFM_DATA, $$ZI$$Limit);
465+
REGION_DECLARE_EXT(Image$$, ER_TFM_DATA, $$RW$$Base);
466+
REGION_DECLARE_EXT(Image$$, ER_TFM_DATA, $$RW$$Limit);
475467
REGION_DECLARE_EXT(Image$$, TFM_SECURE_STACK, $$ZI$$Base);
476468
REGION_DECLARE_EXT(Image$$, TFM_SECURE_STACK, $$ZI$$Limit);
477469
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)
523515
if (memory_check_range(buffer, len, base, limit) == IPC_SUCCESS) {
524516
return IPC_SUCCESS;
525517
}
526-
527-
base = (uintptr_t)NS_CODE_START;
528-
limit = (uintptr_t)(NS_CODE_START + NS_CODE_SIZE);
529-
if (memory_check_range(buffer, len, base, limit) == IPC_SUCCESS) {
530-
return IPC_SUCCESS;
531-
}
532518
} else {
533-
base = (uintptr_t)&REGION_NAME(Image$$, ARM_LIB_HEAP, $$ZI$$Base);
534-
limit = (uintptr_t)&REGION_NAME(Image$$, ARM_LIB_HEAP, $$ZI$$Limit);
519+
base = (uintptr_t)&REGION_NAME(Image$$, ER_TFM_DATA, $$RW$$Base);
520+
limit = (uintptr_t)&REGION_NAME(Image$$, ER_TFM_DATA, $$RW$$Limit);
535521
if (memory_check_range(buffer, len, base, limit) == IPC_SUCCESS) {
536522
return IPC_SUCCESS;
537523
}
@@ -542,12 +528,6 @@ int32_t tfm_memory_check(void *buffer, size_t len, int32_t ns_caller)
542528
return IPC_SUCCESS;
543529
}
544530

545-
base = (uintptr_t)&REGION_NAME(Image$$, ER_TFM_DATA, $$Base);
546-
limit = (uintptr_t)&REGION_NAME(Image$$, ER_TFM_DATA, $$Limit);
547-
if (memory_check_range(buffer, len, base, limit) == IPC_SUCCESS) {
548-
return IPC_SUCCESS;
549-
}
550-
551531
base = (uintptr_t)&REGION_NAME(Image$$, TFM_SECURE_STACK, $$ZI$$Base);
552532
limit = (uintptr_t)&REGION_NAME(Image$$, TFM_SECURE_STACK, $$ZI$$Limit);
553533
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)
560540
if (memory_check_range(buffer, len, base, limit) == IPC_SUCCESS) {
561541
return IPC_SUCCESS;
562542
}
563-
564-
base = (uintptr_t)S_CODE_START;
565-
limit = (uintptr_t)(S_CODE_START + S_CODE_SIZE);
566-
if (memory_check_range(buffer, len, base, limit) == IPC_SUCCESS) {
567-
return IPC_SUCCESS;
568-
}
569543
}
570544

571545
return IPC_ERROR_MEMORY_CHECK;

components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/tfm_thread.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,23 @@ static struct tfm_thrd_ctx *p_curr_thrd = NULL;
2121
#define RUNN_HEAD p_runn_head
2222
#define CURR_THRD p_curr_thrd
2323

24+
static struct tfm_thrd_ctx *find_next_running_thread(struct tfm_thrd_ctx *pth)
25+
{
26+
while (pth && pth->status != THRD_STAT_RUNNING) {
27+
pth = pth->next;
28+
}
29+
30+
return pth;
31+
}
32+
2433
/* To get next running thread for scheduler */
2534
struct tfm_thrd_ctx *tfm_thrd_next_thread(void)
2635
{
27-
struct tfm_thrd_ctx *pth = RUNN_HEAD;
28-
2936
/*
3037
* First RUNNING thread has highest priority since threads are sorted with
3138
* priority.
3239
*/
33-
while (pth && pth->status != THRD_STAT_RUNNING) {
34-
pth = pth->next;
35-
}
36-
37-
return pth;
40+
return find_next_running_thread(RUNN_HEAD);
3841
}
3942

4043
/* To get current thread for caller */
@@ -69,10 +72,10 @@ static void update_running_head(struct tfm_thrd_ctx **runn,
6972
struct tfm_thrd_ctx *node)
7073
{
7174
if ((node->status == THRD_STAT_RUNNING) &&
72-
(*runn == NULL || (node->prior <= (*runn)->prior))) {
75+
(*runn == NULL || (node->prior < (*runn)->prior))) {
7376
*runn = node;
7477
} else {
75-
*runn = tfm_thrd_next_thread();
78+
*runn = find_next_running_thread(LIST_HEAD);
7679
}
7780
}
7881

components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/secure_utilities.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
#define EXC_NUM_PENDSV (14)
2626
#define EXC_NUM_SYSTICK (15)
2727

28-
#define printf(...)
29-
3028
/* Disable NS exceptions by setting NS PRIMASK to 1 */
3129
#define TFM_NS_EXC_DISABLE() __TZ_set_PRIMASK_NS(1)
3230
/* Enable NS exceptions by setting NS PRIMASK to 0 */

components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/tfm_core.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "tfm_internal.h"
1212
#include "tfm_api.h"
1313
#include "platform/include/tfm_spm_hal.h"
14+
#include "uart_stdout.h"
1415
#include "secure_utilities.h"
1516
#include "secure_fw/spm/spm_api.h"
1617
#include "secure_fw/include/tfm_spm_services_api.h"
@@ -87,6 +88,7 @@ int32_t tfm_core_init(void)
8788

8889
__enable_irq();
8990

91+
stdio_init();
9092
LOG_MSG("Secure image initializing!");
9193

9294
#ifdef TFM_CORE_DEBUG

0 commit comments

Comments
 (0)