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.
pull/15050/head
Robert Walton 2021-09-03 10:10:41 +01:00
parent 6850192508
commit 56ffd54dd4
5 changed files with 48 additions and 1 deletions

View File

@ -18,7 +18,6 @@ if("TFM_V8M" IN_LIST MBED_TARGET_LABELS)
INTERFACE
TARGET_TFM_V8M/src/cmsis_nvic_virtual.c
TARGET_TFM_V8M/src/tfm_mbed_boot.c
TARGET_TFM_V8M/src/tfm_ns_interface.c
TARGET_TFM_V8M/src/tfm_psa_ns_api.c
)
endif()

View File

@ -43,6 +43,7 @@ target_sources(mbed-arm-musca-b1
serial_api.c
sleep_api.c
tfm_ioctl_ns_api.c
tfm_ns_interface.c
us_ticker.c
device/device_definition.c

View File

@ -45,6 +45,7 @@ target_sources(mbed-arm-musca-s1
serial_api.c
sleep_api.c
tfm_ioctl_ns_api.c
tfm_ns_interface.c
us_ticker.c
device/device_definition.c

View File

@ -0,0 +1,46 @@
/*
* Copyright (c) 2017-2021, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#include <stdint.h>
#include "os_wrapper/mutex.h"
#include "tfm_ns_interface.h"
/**
* \brief the ns_lock ID
*/
static void *ns_lock_handle = NULL;
int32_t tfm_ns_interface_dispatch(veneer_fn fn,
uint32_t arg0, uint32_t arg1,
uint32_t arg2, uint32_t arg3)
{
int32_t result;
/* TFM request protected by NS lock */
while (os_wrapper_mutex_acquire(ns_lock_handle, OS_WRAPPER_WAIT_FOREVER)
!= OS_WRAPPER_SUCCESS);
result = fn(arg0, arg1, arg2, arg3);
while (os_wrapper_mutex_release(ns_lock_handle) != OS_WRAPPER_SUCCESS);
return result;
}
uint32_t tfm_ns_interface_init(void)
{
void *handle;
handle = os_wrapper_mutex_create();
if (!handle) {
return OS_WRAPPER_ERROR;
}
ns_lock_handle = handle;
return OS_WRAPPER_SUCCESS;
}