Skip to content

Commit 9b7ef82

Browse files
committed
psa: Init IPC, Mailbox and Non-secure Interface
These changes are for TFM_DUALCPU and TFM_V8M platforms. The initialization happens after mbed-os kernel is kicked off and when the thread is up and running. We are initializing the following for TFM_DUALCPU platforms: * IPC Interrupts for syncing multi-core platforms. * NS Mailbox to receive messages. * NS interface. We are only initializing Non-secure interface for TFM_V8M platforms. mbed_tfm_init() in tfm_mbed_boot.c overrides the WEAK mbed_tfm_init() for a specific platform. Signed-off-by: Vikas Katariya <[email protected]>
1 parent c447278 commit 9b7ef82

File tree

4 files changed

+128
-2
lines changed

4 files changed

+128
-2
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2020 ARM Limited
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "mbed_error.h"
19+
#include "tfm_multi_core_api.h"
20+
#include "tfm_ns_mailbox.h"
21+
#include "platform_multicore.h"
22+
#include "tfm_ns_interface.h"
23+
24+
static struct ns_mailbox_queue_t ns_mailbox_queue;
25+
26+
void mbed_tfm_init(void)
27+
{
28+
/*
29+
* In case the of dual CPU, we need to initialize IPC, mailbox
30+
* and NS interface after the RTOS has started to enable
31+
* communication from Secure and Non-Secure cores.
32+
*/
33+
int32_t ret;
34+
35+
ret = tfm_ns_wait_for_s_cpu_ready();
36+
/*
37+
* Normally would expect "TFM_SUCCESS" returned here by TF-M, as this
38+
* isn't a mailbox function. There may be some platforms other than PSoC6,
39+
* which doesn't require tfm_ns_wait_for_s_cpu_ready() implementation.
40+
* "PLATFORM_MAILBOX_SUCCESS" is a low-level error code and should be
41+
* replaced by "TFM_SUCCESS".
42+
* As the function definition has been imported from the TF-M, therefore
43+
* a issue has been raised - https://developer.trustedfirmware.org/T660
44+
*/
45+
if (ret != PLATFORM_MAILBOX_SUCCESS) {
46+
/* Avoid undefined behavior after multi-core sync-up failed */
47+
MBED_ERROR(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM,
48+
MBED_ERROR_CODE_INITIALIZATION_FAILED),
49+
"Failed to sync-up multi-core");
50+
}
51+
52+
ret = tfm_ns_mailbox_init(&ns_mailbox_queue);
53+
if (ret != MAILBOX_SUCCESS) {
54+
/* Avoid undefined behavior after NS mailbox initialization failed */
55+
MBED_ERROR(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM,
56+
MBED_ERROR_CODE_INITIALIZATION_FAILED),
57+
"Failed to initialize NS mailbox");
58+
}
59+
60+
ret = tfm_ns_interface_init();
61+
if (ret != TFM_SUCCESS) {
62+
/* Avoid undefined behavior after NS interface initialization failed */
63+
MBED_ERROR(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM,
64+
MBED_ERROR_CODE_INITIALIZATION_FAILED),
65+
"Failed to initialize NS interface");
66+
}
67+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2020 ARM Limited
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "mbed_error.h"
19+
#include "tfm_ns_interface.h"
20+
21+
void mbed_tfm_init(void)
22+
{
23+
/*
24+
* In case of V8-M, we need to initialize NS interface
25+
* after the RTOS has started to enable
26+
* communication from Secure and Non-Secure cores.
27+
*/
28+
int32_t ret;
29+
30+
ret = tfm_ns_interface_init();
31+
if (ret != TFM_SUCCESS) {
32+
/* Avoid undefined behavior after NS interface initialization failed */
33+
MBED_ERROR(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM,
34+
MBED_ERROR_CODE_INITIALIZATION_FAILED),
35+
"Failed to initialize NS interface");
36+
}
37+
}

rtos/source/TARGET_CORTEX/mbed_boot.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* mbed Microcontroller Library
2-
* Copyright (c) 2006-2016 ARM Limited
2+
* Copyright (c) 2006-2020 ARM Limited
33
* SPDX-License-Identifier: Apache-2.0
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -95,6 +95,7 @@ void mbed_init(void)
9595
void mbed_start(void)
9696
{
9797
mbed_toolchain_init();
98+
mbed_tfm_init();
9899
mbed_main();
99100
mbed_error_initialize();
100101
main();
@@ -110,6 +111,11 @@ MBED_WEAK void software_init_hook_rtos()
110111
// Nothing by default
111112
}
112113

114+
MBED_WEAK void mbed_tfm_init(void)
115+
{
116+
// Nothing by default
117+
}
118+
113119
MBED_WEAK void mbed_main(void)
114120
{
115121
// Nothing by default

rtos/source/TARGET_CORTEX/mbed_boot.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* mbed Microcontroller Library
2-
* Copyright (c) 2018-2019 ARM Limited
2+
* Copyright (c) 2018-2020 ARM Limited
33
* SPDX-License-Identifier: Apache-2.0
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -47,6 +47,7 @@ extern "C" {
4747
* - Start scheduler
4848
* - main thread calls start mbed
4949
* 4. Start mbed
50+
* - Call mbed_tfm_init
5051
* - Call mbed_main
5152
* - Call main
5253
*
@@ -149,6 +150,20 @@ void mbed_toolchain_init(void);
149150
*/
150151
void mbed_sdk_init(void);
151152

153+
/**
154+
* TF-M specific application hook for running code before mbed_main
155+
*
156+
* This is a weak function which can be overridden by an application
157+
* to allow code to run before mbed_main is called.
158+
* Some TF-M supported platforms require synchronization between
159+
* Secure and Non-Secure cores, therefore these tasks are done here.
160+
*
161+
* Preconditions:
162+
* - The RTOS has been started by a call to mbed_rtos_start
163+
* - The toolchain has been initialized by a call to mbed_toolchain_init
164+
*/
165+
void mbed_tfm_init(void);
166+
152167
/**
153168
* Application hook for running code before main
154169
*
@@ -157,6 +172,7 @@ void mbed_sdk_init(void);
157172
*
158173
* Preconditions:
159174
* - The RTOS has been started by a call to mbed_rtos_start
175+
* - TFM support has been initialized by a call to mbed_tfm_init.
160176
* - The toolchain has been initialized by a call to mbed_toolchain_init
161177
*/
162178
void mbed_main(void);

0 commit comments

Comments
 (0)