Skip to content

Commit 56ffd54

Browse files
committed
tfm: Move tfm_ns_interface.c
tfm_ns_interface.c is intended to be overriden by clients to support different targets. We copy this file from upstream into the mbed-os platform library. We also have a specific "strong" overridden version for the NU_M2354 target, which is located in its target library. Previously the implementations in the platform library were decorated with __attribute__(weak), and we provided a strong definition for the NU_M2354 target. This worked fine because of weak linking, the linker will pick the first "strong" definition and use that, avoiding any ODR violations. However, upstream have removed __attribute__(weak) from the function definitions, which caused multiply defined symbol errors when trying to build the NU_M2354 target. To work around the above issue, we remove the common definition in the platform library; instead we copy the file to the Musca B1 and Musca S1 target libaries. This means the appropriate tfm_ns_interface.c is only included in the build when compiling for the specific target which uses it.
1 parent 6850192 commit 56ffd54

File tree

5 files changed

+48
-1
lines changed

5 files changed

+48
-1
lines changed

platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ if("TFM_V8M" IN_LIST MBED_TARGET_LABELS)
1818
INTERFACE
1919
TARGET_TFM_V8M/src/cmsis_nvic_virtual.c
2020
TARGET_TFM_V8M/src/tfm_mbed_boot.c
21-
TARGET_TFM_V8M/src/tfm_ns_interface.c
2221
TARGET_TFM_V8M/src/tfm_psa_ns_api.c
2322
)
2423
endif()

targets/TARGET_ARM_SSG/TARGET_MUSCA_B1/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ target_sources(mbed-arm-musca-b1
4343
serial_api.c
4444
sleep_api.c
4545
tfm_ioctl_ns_api.c
46+
tfm_ns_interface.c
4647
us_ticker.c
4748

4849
device/device_definition.c

targets/TARGET_ARM_SSG/TARGET_MUSCA_S1/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ target_sources(mbed-arm-musca-s1
4545
serial_api.c
4646
sleep_api.c
4747
tfm_ioctl_ns_api.c
48+
tfm_ns_interface.c
4849
us_ticker.c
4950

5051
device/device_definition.c
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (c) 2017-2021, Arm Limited. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*
6+
*/
7+
#include <stdint.h>
8+
9+
#include "os_wrapper/mutex.h"
10+
11+
#include "tfm_ns_interface.h"
12+
13+
/**
14+
* \brief the ns_lock ID
15+
*/
16+
static void *ns_lock_handle = NULL;
17+
18+
int32_t tfm_ns_interface_dispatch(veneer_fn fn,
19+
uint32_t arg0, uint32_t arg1,
20+
uint32_t arg2, uint32_t arg3)
21+
{
22+
int32_t result;
23+
24+
/* TFM request protected by NS lock */
25+
while (os_wrapper_mutex_acquire(ns_lock_handle, OS_WRAPPER_WAIT_FOREVER)
26+
!= OS_WRAPPER_SUCCESS);
27+
28+
result = fn(arg0, arg1, arg2, arg3);
29+
30+
while (os_wrapper_mutex_release(ns_lock_handle) != OS_WRAPPER_SUCCESS);
31+
32+
return result;
33+
}
34+
35+
uint32_t tfm_ns_interface_init(void)
36+
{
37+
void *handle;
38+
39+
handle = os_wrapper_mutex_create();
40+
if (!handle) {
41+
return OS_WRAPPER_ERROR;
42+
}
43+
44+
ns_lock_handle = handle;
45+
return OS_WRAPPER_SUCCESS;
46+
}

0 commit comments

Comments
 (0)