Skip to content

Commit 524e78d

Browse files
authored
Introduce Trusted Firmware M support in Kernel on ARM Cortex M33 (#108)
This port adds the support that FreeRTOS applications can call the secure services in Trusted Firmware M(TF-M) via PSA Platform Security Architecture(PSA) API based on Arm Cortex-M33 platform with GCC compiler. More information: PSA - https://www.arm.com/why-arm/architecture/platform-security-architecture TF-M - https://git.trustedfirmware.org/trusted-firmware-m.git/ Change-Id: I2e771b66e8d75927abc2505a187a16250d504db2 Signed-off-by: Sherry Zhang <sherry.zhang2@arm.com>
1 parent 651289e commit 524e78d

File tree

2 files changed

+167
-0
lines changed

2 files changed

+167
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Target of this port
2+
3+
This port adds the support that FreeRTOS applications can call the secure
4+
services in Trusted Firmware M(TF-M) through Platform Security Architecture
5+
(PSA) API based on the ARM Cortex-M33 platform.
6+
7+
The Platform Security Architecture (PSA) makes it quicker, easier and cheaper
8+
to design security into a device from the ground up. PSA is made up of four key
9+
stages: analyze, architect, implement, and certify. See [PSA Resource Page](https://developer.arm.com/architectures/security-architectures/platform-security-architecture).
10+
11+
TF-M is an open source project. It provides a reference implementation of PSA
12+
for Arm M-profile architecture. Please get the details from this [link](https://git.trustedfirmware.org/TF-M/trusted-firmware-m.git/about/).
13+
14+
# Derivation of the source code
15+
16+
* ```os_wrapper_freertos.c```
17+
The implementation of APIs which are defined in ```os_wrapper\mutex.h``` by TF-M
18+
(tag: TF-Mv1.1). The implementation is based on FreeRTOS mutex type semaphore.
19+
20+
# Usage notes
21+
22+
To build a project based on this port:
23+
* Step 1: build the secure image. Please follow the **Build the Secure Side** section for details.
24+
* Step 2: build the nonsecure image. Please follow the **Build the Non-Secure Side** for details.
25+
26+
## Build the Secure Side
27+
28+
### Get the TF-M source code
29+
30+
See the [link](https://git.trustedfirmware.org/TF-M/trusted-firmware-m.git/) to get the source code. This port is based on TF-M version **tag: TF-Mv1.1**.
31+
32+
### Build TF-M
33+
34+
Please refer to this [link](https://git.trustedfirmware.org/TF-M/trusted-firmware-m.git/tree/docs/getting_started/tfm_build_instruction.rst) to build the secure side.
35+
_**Note:** ```CONFIG_TFM_ENABLE_CTX_MGMT``` must be configured as "OFF" when building TF-M_.
36+
37+
## Build the Non-Secure Side
38+
39+
Please copy all the files in ```freertos_kernel\portable\GCC\ARM_CM33_NTZ``` into the ```freertos_kernel\portable\GCC\ARM_CM33_TFM``` folder before using this port. Note that TrustZone is enabled in this port. The TF-M runs in the Secure Side.
40+
41+
Please call the API ```tfm_ns_interface_init()``` which is defined in ```os_wrapper_freertos.c``` at the very beginning of your application. Otherwise, it will always fail when calling a TF-M service in the Nonsecure Side.
42+
43+
### Configuration in FreeRTOS kernel
44+
45+
* ```configRUN_FREERTOS_SECURE_ONLY```
46+
This macro should be configured as 0. In this port, TF-M runs in the Secure Side while FreeRTOS
47+
Kernel runs in the Non-Secure Side.
48+
49+
* ```configENABLE_FPU```
50+
The setting of this macro is decided by the setting in Secure Side which is platform-specific.
51+
If the Secure Side enables Non-Secure access to FPU, then this macro can be configured as 0 or 1. Otherwise, this macro can only be configured as 0.
52+
53+
* ```configENABLE_TRUSTZONE```
54+
This macro should be configured as 0 because TF-M doesn't use the secure context management function of FreeRTOS. New secure context management might be introduced when TF-M supports multiple secure context.
55+
56+
57+
### Integrate TF-M Non-Secure interface with FreeRTOS project
58+
59+
To enable calling TF-M services by the Non-Secure Side, the files below should be included in the FreeRTOS project and built together.
60+
* files in ```trusted-firmware-m\build\install\export\tfm\src```
61+
These files contain the implementation of PSA Functional Developer APIs which can be called by Non-Secure Side directly and PSA Firmware Framework APIs in the IPC model. These files should be taken
62+
as part of the Non-Secure source code.
63+
* files in ```trusted-firmware-m\build\install\export\tfm\include```
64+
These files are the necessary header files to call TF-M services.
65+
* ```trusted-firmware-m\build\install\export\tfm\veneers\s_veneers.o```
66+
This object file contains all the Non-Secure callable functions exported by
67+
TF-M and it should be linked when generating the Non-Secure image.
68+
69+
70+
71+
*Copyright (c) 2020, Arm Limited. All rights reserved.*
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* Copyright (c) 2019-2020, Arm Limited. All rights reserved.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
5+
* this software and associated documentation files (the "Software"), to deal in
6+
* the Software without restriction, including without limitation the rights to
7+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8+
* the Software, and to permit persons to whom the Software is furnished to do so,
9+
* subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20+
*
21+
*/
22+
23+
/*
24+
* This file contains the implementation of APIs which are defined in
25+
* os_wrapper/mutex.h by TF-M(tag: TF-Mv1.1). The implementation is based
26+
* on FreeRTOS mutex type semaphore.
27+
*/
28+
29+
#include "os_wrapper/mutex.h"
30+
31+
#include "FreeRTOS.h"
32+
#include "semphr.h"
33+
#include "mpu_wrappers.h"
34+
35+
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
36+
/*
37+
* In the static allocation, the RAM is required to hold the semaphore's
38+
* state.
39+
*/
40+
StaticSemaphore_t xSecureMutexBuffer;
41+
#endif
42+
43+
void * os_wrapper_mutex_create( void )
44+
{
45+
SemaphoreHandle_t xMutexHandle = NULL;
46+
47+
#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
48+
xMutexHandle = xSemaphoreCreateMutex();
49+
#elif( configSUPPORT_STATIC_ALLOCATION == 1 )
50+
xMutexHandle = xSemaphoreCreateMutexStatic( &xSecureMutexBuffer );
51+
#endif
52+
return ( void * ) xMutexHandle;
53+
}
54+
/*-----------------------------------------------------------*/
55+
56+
uint32_t os_wrapper_mutex_acquire( void * handle, uint32_t timeout )
57+
{
58+
BaseType_t xRet;
59+
60+
if( ! handle )
61+
return OS_WRAPPER_ERROR;
62+
63+
xRet = xSemaphoreTake( ( SemaphoreHandle_t ) handle,
64+
( timeout == OS_WRAPPER_WAIT_FOREVER ) ?
65+
portMAX_DELAY : ( TickType_t ) timeout );
66+
67+
if( xRet != pdPASS )
68+
return OS_WRAPPER_ERROR;
69+
else
70+
return OS_WRAPPER_SUCCESS;
71+
}
72+
/*-----------------------------------------------------------*/
73+
74+
uint32_t os_wrapper_mutex_release( void * handle )
75+
{
76+
BaseType_t xRet;
77+
78+
if( !handle )
79+
return OS_WRAPPER_ERROR;
80+
81+
xRet = xSemaphoreGive( ( SemaphoreHandle_t ) handle );
82+
83+
if( xRet != pdPASS )
84+
return OS_WRAPPER_ERROR;
85+
else
86+
return OS_WRAPPER_SUCCESS;
87+
}
88+
/*-----------------------------------------------------------*/
89+
90+
uint32_t os_wrapper_mutex_delete( void * handle )
91+
{
92+
vSemaphoreDelete( ( SemaphoreHandle_t ) handle );
93+
94+
return OS_WRAPPER_SUCCESS;
95+
}
96+
/*-----------------------------------------------------------*/

0 commit comments

Comments
 (0)