Skip to content

Commit 5697c95

Browse files
committed
trusted-firmware-m: tf-m-tests: synchronize with upstream
Synchronize the tf-m-test directory with the corresponding upstream repository up to commit 652bb8a1502c95bfd1ee8e44ccd1126ce74ae41f Signed-off-by: Ioannis Glaropoulos <[email protected]>
1 parent 047ab7a commit 5697c95

File tree

154 files changed

+22933
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

154 files changed

+22933
-4
lines changed

tf-m-tests/app/CMakeLists.txt

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
#-------------------------------------------------------------------------------
2+
# Copyright (c) 2020, Arm Limited. All rights reserved.
3+
#
4+
# SPDX-License-Identifier: BSD-3-Clause
5+
#
6+
#-------------------------------------------------------------------------------
7+
8+
cmake_minimum_required(VERSION 3.13)
9+
project(tfm_ns LANGUAGES ASM C)
10+
11+
# For multi-core projects, the NS app can be run on a different CPU to the
12+
# Secure code. To facilitate this, we once again reload the compiler to load the
13+
# setting for the NS CPU. Cmake settings are directory scoped so this affects
14+
# anything loaded from or declared in this dir.
15+
if (TFM_MULTI_CORE_TOPOLOGY)
16+
include(${CMAKE_SOURCE_DIR}/platform/ext/target/${TFM_PLATFORM}/preload_ns.cmake)
17+
endif()
18+
19+
############################# PSA test integration #############################
20+
21+
if(TEST_PSA_API)
22+
set(SUITE ${TEST_PSA_API})
23+
24+
string(REGEX REPLACE ".*/" "" PSA_API_TEST_TARGET ${TFM_PLATFORM})
25+
26+
if (NOT "${TEST_PSA_API}" STREQUAL "IPC")
27+
set(TARGET tgt_dev_apis_tfm_${PSA_API_TEST_TARGET})
28+
else()
29+
set(TARGET tgt_ff_tfm_${PSA_API_TEST_TARGET})
30+
endif()
31+
32+
set(PSA_INCLUDE_PATHS ${CMAKE_SOURCE_DIR}/interface/include/
33+
${PSA_ARCH_TESTS_PATH}/api-tests/platform/manifests/
34+
${CMAKE_BINARY_DIR}/generated/interface/include
35+
)
36+
37+
set(SP_HEAP_MEM_SUPP=0)
38+
set(PLATFORM_PSA_ISOLATION_LEVEL ${TFM_ISOLATION_LEVEL})
39+
40+
if (${CMAKE_C_COMPILER_ID} STREQUAL GNU)
41+
set(TOOLCHAIN GNUARM)
42+
elseif (${CMAKE_C_COMPILER_ID} STREQUAL ARMClang)
43+
set(TOOLCHAIN ARMCLANG)
44+
endif()
45+
46+
if (${CMAKE_SYSTEM_ARCHITECTURE} STREQUAL armv8-m.main)
47+
set(CPU_ARCH armv8m_ml)
48+
elseif (${CMAKE_SYSTEM_ARCHITECTURE} STREQUAL armv8-m.base)
49+
set(CPU_ARCH armv8m_bl)
50+
elseif (${CMAKE_SYSTEM_ARCHITECTURE} STREQUAL armv7-m)
51+
set(CPU_ARCH armv7m)
52+
endif()
53+
54+
add_subdirectory(${PSA_ARCH_TESTS_PATH}/api-tests ${CMAKE_CURRENT_BINARY_DIR}/psa_api_tests)
55+
endif()
56+
57+
############################# Test integration #################################
58+
59+
add_library(tfm_ns_integration_test STATIC EXCLUDE_FROM_ALL)
60+
61+
target_sources(tfm_ns_integration_test
62+
PRIVATE
63+
tfm_integ_test.c
64+
)
65+
66+
target_include_directories(tfm_ns_integration_test
67+
PUBLIC
68+
.
69+
)
70+
71+
target_link_libraries(tfm_ns_integration_test
72+
PUBLIC
73+
$<$<BOOL:${TEST_NS}>:tfm_ns_tests>
74+
tfm_test_framework
75+
PRIVATE
76+
psa_interface
77+
$<TARGET_PROPERTY:platform_ns,PLATFORM_RTX_LIB_PATH>
78+
psa_api_ns
79+
CMSIS_5_tfm_ns
80+
)
81+
82+
target_compile_definitions(tfm_ns_integration_test
83+
PUBLIC
84+
$<$<BOOL:${TEST_NS}>:TEST_FRAMEWORK_NS>
85+
$<$<BOOL:${TEST_S}>:TEST_FRAMEWORK_S>
86+
)
87+
88+
############################# TFM NS app #######################################
89+
90+
add_executable(tfm_ns)
91+
92+
target_sources(tfm_ns
93+
PRIVATE
94+
main_ns.c
95+
$<$<BOOL:${TEST_PSA_API}>:psa_api_test.c>
96+
)
97+
98+
target_link_libraries(tfm_ns
99+
PRIVATE
100+
platform_ns
101+
CMSIS_5_tfm_ns
102+
$<$<OR:$<BOOL:${TEST_NS}>,$<BOOL:${TEST_S}>>:tfm_ns_integration_test>
103+
$<$<BOOL:${TEST_PSA_API}>:val_nspe>
104+
$<$<BOOL:${TEST_PSA_API}>:pal_nspe>
105+
$<$<BOOL:${TEST_PSA_API}>:test_combine>
106+
$<$<NOT:$<BOOL:${TFM_MULTI_CORE_TOPOLOGY}>>:tfm_s_veneers>
107+
psa_api_ns
108+
)
109+
110+
target_compile_definitions(tfm_ns
111+
PUBLIC
112+
$<$<BOOL:${TEST_PSA_API}>:PSA_API_TEST_NS>
113+
)
114+
115+
set_target_properties(tfm_ns PROPERTIES
116+
SUFFIX ".axf"
117+
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
118+
)
119+
120+
target_link_options(tfm_ns
121+
PRIVATE
122+
$<$<C_COMPILER_ID:GNU>:-Wl,-Map=${CMAKE_BINARY_DIR}/bin/tfm_ns.map>
123+
$<$<C_COMPILER_ID:ARMClang>:--map>
124+
)
125+
126+
add_convert_to_bin_target(tfm_ns)
127+
128+
############################# CMSIS ############################################
129+
130+
include(FetchContent)
131+
132+
set(FETCHCONTENT_QUIET FALSE)
133+
cmake_policy(SET CMP0079 NEW)
134+
135+
add_library(CMSIS_5_tfm_ns INTERFACE)
136+
137+
target_sources(CMSIS_5_tfm_ns
138+
INTERFACE
139+
${CMSIS_5_PATH}/RTOS2/RTX/Config/RTX_Config.c
140+
${CMSIS_5_PATH}/RTOS2/RTX/Source/rtx_lib.c
141+
${CMAKE_CURRENT_SOURCE_DIR}/os_wrapper_cmsis_rtos_v2.c
142+
)
143+
144+
target_include_directories(CMSIS_5_tfm_ns
145+
INTERFACE
146+
${CMSIS_5_PATH}/Core/Include
147+
${CMSIS_5_PATH}/RTOS2/Include
148+
${CMSIS_5_PATH}/RTOS2/RTX/Include
149+
${CMSIS_5_PATH}/RTOS2/RTX/Config
150+
)
151+
152+
target_link_libraries(CMSIS_5_tfm_ns
153+
INTERFACE
154+
platform_ns
155+
)

tf-m-tests/app/main_ns.c

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
/*
2+
* Copyright (c) 2017-2020, Arm Limited. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*
6+
*/
7+
8+
#include "tfm_api.h"
9+
#include "cmsis_os2.h"
10+
#include "tfm_integ_test.h"
11+
#include "tfm_ns_svc.h"
12+
#include "tfm_ns_interface.h"
13+
#if defined(TEST_FRAMEWORK_NS) || defined(TEST_FRAMEWORK_S)
14+
#include "test_framework_integ_test.h"
15+
#endif
16+
#ifdef PSA_API_TEST_NS
17+
#include "psa_api_test.h"
18+
#endif
19+
#include "target_cfg.h"
20+
#include "tfm_plat_ns.h"
21+
#include "driver/Driver_USART.h"
22+
#include "device_cfg.h"
23+
#ifdef TFM_MULTI_CORE_TOPOLOGY
24+
#include "tfm_multi_core_api.h"
25+
#include "tfm_ns_mailbox.h"
26+
#endif
27+
#include "log/tfm_assert.h"
28+
#include "tfm_log.h"
29+
#include "uart_stdout.h"
30+
#include "region.h"
31+
32+
/**
33+
* \brief Modified table template for user defined SVC functions
34+
*
35+
* \details RTX has a weak definition of osRtxUserSVC, which
36+
* is overridden here
37+
*/
38+
#if (defined(__ARMCC_VERSION) && (__ARMCC_VERSION == 6110004))
39+
/* Workaround needed for a bug in Armclang 6.11, more details at:
40+
* http://www.keil.com/support/docs/4089.htm
41+
*/
42+
__attribute__((section(".gnu.linkonce")))
43+
#endif
44+
extern void * const osRtxUserSVC[1+USER_SVC_COUNT];
45+
void * const osRtxUserSVC[1+USER_SVC_COUNT] = {
46+
(void *)USER_SVC_COUNT,
47+
48+
#define X(SVC_ENUM, SVC_HANDLER) (void*)SVC_HANDLER,
49+
50+
/* SVC API for Services */
51+
#ifdef TFM_NS_CLIENT_IDENTIFICATION
52+
LIST_SVC_NSPM
53+
#endif
54+
55+
#undef X
56+
57+
/*
58+
* (void *)user_function1,
59+
* ...
60+
*/
61+
};
62+
63+
/**
64+
* \brief List of RTOS thread attributes
65+
*/
66+
#if defined(TEST_FRAMEWORK_NS) || defined(TEST_FRAMEWORK_S) \
67+
|| defined(PSA_API_TEST_NS)
68+
static uint64_t test_app_stack[(4u * 1024u) / (sizeof(uint64_t))]; /* 4KB */
69+
static const osThreadAttr_t thread_attr = {
70+
.name = "test_thread",
71+
.stack_mem = test_app_stack,
72+
.stack_size = sizeof(test_app_stack),
73+
};
74+
#endif
75+
76+
/**
77+
* \brief Static globals to hold RTOS related quantities,
78+
* main thread
79+
*/
80+
#if defined(TEST_FRAMEWORK_NS) || defined(TEST_FRAMEWORK_S) \
81+
|| defined(PSA_API_TEST_NS)
82+
static osThreadFunc_t thread_func;
83+
#endif
84+
85+
#ifdef TFM_MULTI_CORE_TOPOLOGY
86+
static struct ns_mailbox_queue_t ns_mailbox_queue;
87+
88+
static void tfm_ns_multi_core_boot(void)
89+
{
90+
int32_t ret;
91+
92+
LOG_MSG("Non-secure code running on non-secure core.");
93+
94+
if (tfm_ns_wait_for_s_cpu_ready()) {
95+
LOG_MSG("Error sync'ing with secure core.");
96+
97+
/* Avoid undefined behavior after multi-core sync-up failed */
98+
for (;;) {
99+
}
100+
}
101+
102+
ret = tfm_ns_mailbox_init(&ns_mailbox_queue);
103+
if (ret != MAILBOX_SUCCESS) {
104+
LOG_MSG("Non-secure mailbox initialization failed.");
105+
106+
/* Avoid undefined behavior after NS mailbox initialization failed */
107+
for (;;) {
108+
}
109+
}
110+
}
111+
#endif
112+
113+
/**
114+
* \brief Platform peripherals and devices initialization.
115+
* Can be overridden for platform specific initialization.
116+
*
117+
* \return ARM_DRIVER_OK if the initialization succeeds
118+
*/
119+
__WEAK int32_t tfm_ns_platform_init(void)
120+
{
121+
stdio_init();
122+
123+
return ARM_DRIVER_OK;
124+
}
125+
126+
/**
127+
* \brief Platform peripherals and devices de-initialization.
128+
* Can be overridden for platform specific initialization.
129+
*
130+
* \return ARM_DRIVER_OK if the de-initialization succeeds
131+
*/
132+
__WEAK int32_t tfm_ns_platform_uninit(void)
133+
{
134+
stdio_uninit();
135+
136+
return ARM_DRIVER_OK;
137+
}
138+
139+
/**
140+
* \brief main() function
141+
*/
142+
#ifndef __GNUC__
143+
__attribute__((noreturn))
144+
#endif
145+
int main(void)
146+
{
147+
#if defined(__ARM_ARCH_8_1M_MAIN__) || defined(__ARM_ARCH_8M_MAIN__)
148+
/* Set Main Stack Pointer limit */
149+
REGION_DECLARE(Image$$, ARM_LIB_STACK_MSP, $$ZI$$Base);
150+
__set_MSPLIM((uint32_t)&REGION_NAME(Image$$, ARM_LIB_STACK_MSP,
151+
$$ZI$$Base));
152+
#endif
153+
154+
if (tfm_ns_platform_init() != ARM_DRIVER_OK) {
155+
/* Avoid undefined behavior if platform init failed */
156+
while(1);
157+
}
158+
159+
#ifdef TFM_MULTI_CORE_TOPOLOGY
160+
tfm_ns_multi_core_boot();
161+
#endif
162+
163+
(void) osKernelInitialize();
164+
165+
/* Initialize the TFM NS interface */
166+
tfm_ns_interface_init();
167+
168+
#if defined(TEST_FRAMEWORK_NS) || defined(TEST_FRAMEWORK_S)
169+
thread_func = test_app;
170+
#elif defined(PSA_API_TEST_NS)
171+
thread_func = psa_api_test;
172+
#endif
173+
174+
#if defined(TEST_FRAMEWORK_NS) || defined(TEST_FRAMEWORK_S) \
175+
|| defined(PSA_API_TEST_NS)
176+
(void) osThreadNew(thread_func, NULL, &thread_attr);
177+
#endif
178+
179+
LOG_MSG("Non-Secure system starting...\r\n");
180+
(void) osKernelStart();
181+
182+
/* Reached only in case of error */
183+
for (;;) {
184+
}
185+
}

0 commit comments

Comments
 (0)