Skip to content

Commit 4c04771

Browse files
author
Cruz Monrreal
authored
Merge pull request #9653 from kfnta/tfm_src_integ
TF-M sources integration to Mbed-OS
2 parents 19474fc + 6a90da4 commit 4c04771

File tree

109 files changed

+9608
-277
lines changed

Some content is hidden

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

109 files changed

+9608
-277
lines changed

.astyleignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ TESTS/mbed_hal/trng/pithy
2222
targets
2323
components/802.15.4_RF
2424
components/wifi
25+
components/TARGET_PSA/TARGET_TFM
2526
tools

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ matrix:
323323
- env:
324324
- NAME=psa-autogen
325325
script:
326-
# Run SPM code generator and check that changes are not needed
327-
- python tools/spm/generate_partition_code.py
326+
# Run SPM code generators and check that changes are not needed
327+
- python tools/psa/generate_mbed_spm_partition_code.py
328+
- git diff --exit-code
329+
- python tools/psa/generate_tfm_partition_code.py
328330
- git diff --exit-code

LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Folders containing files under different permissive license than Apache 2.0 are
55

66
- [cmsis](./cmsis) - MIT, BSD-3-Clause
77
- [components/802.15.4_RF/mcr20a-rf-driver](./components/802.15.4_RF/mcr20a-rf-driver) - BSD-3-Clause
8+
- [components/TARGET_PSA/TARGET_TFM](./components/TARGET_PSA/TARGET_TFM) - BSD-3-Clause
89
- [features/cryptocell/FEATURE_CRYPTOCELL310](./features/cryptocell/FEATURE_CRYPTOCELL310) - ARM Object Code and Header Files License
910
- [features/FEATURE_BOOTLOADER](./features/FEATURE_BOOTLOADER) - PBL
1011
- [features/FEATURE_BLE/targets](./features/FEATURE_BLE/targets) - BSD-style, PBL, MIT-style

TESTS/psa/spm_client/COMPONENT_NSPE/client_ipc_tests.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
#error [NOT_SUPPORTED] SPM tests can run only on SPM-enabled targets
2020
#endif // COMPONENT_PSA_SRV_IPC
2121

22+
#ifndef TARGET_MBED_SPM
23+
#error [NOT_SUPPORTED] SPM tests currently only run on MBED_SPM targets
24+
#endif // TARGET_MBED_SPM
25+
2226
#include "mbed.h"
2327
#include "greentea-client/test_env.h"
2428
#include "unity.h"

TESTS/psa/spm_server/COMPONENT_NSPE/main.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
#error [NOT_SUPPORTED] SPM tests can run only on SPM-enabled targets
2020
#endif // COMPONENT_PSA_SRV_IPC
2121

22+
#ifndef TARGET_MBED_SPM
23+
#error [NOT_SUPPORTED] SPM tests currently only run on MBED_SPM targets
24+
#endif // TARGET_MBED_SPM
25+
2226
#include "mbed.h"
2327
#include "greentea-client/test_env.h"
2428
#include "unity.h"

TESTS/psa/spm_smoke/COMPONENT_NSPE/main.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
#ifndef COMPONENT_PSA_SRV_IPC
2020
#error [NOT_SUPPORTED] SPM tests can run only on SPM-enabled targets
2121
#endif // COMPONENT_PSA_SRV_IPC
22+
23+
#ifndef TARGET_MBED_SPM
24+
#error [NOT_SUPPORTED] SPM tests currently only run on MBED_SPM targets
25+
#endif // TARGET_MBED_SPM
26+
2227
/* -------------------------------------- Includes ----------------------------------- */
2328

2429
#include "greentea-client/test_env.h"
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright (c) 2017-2018, Arm Limited. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*
6+
*/
7+
#include <stdint.h>
8+
#include <stdbool.h>
9+
10+
#include "cmsis.h"
11+
#include "rtx_os.h"
12+
#include "cmsis_os2.h"
13+
14+
#include "tfm_api.h"
15+
#include "tfm_ns_lock.h"
16+
17+
/**
18+
* \brief struct ns_lock_state type
19+
*/
20+
struct ns_lock_state
21+
{
22+
bool init;
23+
osMutexId_t id;
24+
};
25+
26+
/**
27+
* \brief ns_lock status
28+
*/
29+
static struct ns_lock_state ns_lock = {.init=false, .id=NULL};
30+
31+
/**
32+
* \brief Mutex properties, NS lock
33+
*/
34+
35+
static osRtxMutex_t ns_lock_cb = { 0 };
36+
37+
static const osMutexAttr_t ns_lock_attrib = {
38+
.name = "ns_lock",
39+
.attr_bits = osMutexPrioInherit,
40+
.cb_mem = &ns_lock_cb,
41+
.cb_size = sizeof(ns_lock_cb)
42+
};
43+
44+
/**
45+
* \brief NS world, NS lock based dispatcher
46+
*/
47+
uint32_t tfm_ns_lock_dispatch(veneer_fn fn,
48+
uint32_t arg0, uint32_t arg1,
49+
uint32_t arg2, uint32_t arg3)
50+
{
51+
uint32_t result;
52+
53+
/* Check the NS lock has been initialized */
54+
if (ns_lock.init == false) {
55+
return TFM_ERROR_GENERIC;
56+
}
57+
58+
/* TFM request protected by NS lock */
59+
osMutexAcquire(ns_lock.id,osWaitForever);
60+
61+
result = fn(arg0, arg1, arg2, arg3);
62+
63+
osMutexRelease(ns_lock.id);
64+
65+
return result;
66+
}
67+
68+
/**
69+
* \brief NS world, Init NS lock
70+
*/
71+
uint32_t tfm_ns_lock_init()
72+
{
73+
if (ns_lock.init == false) {
74+
ns_lock.id = osMutexNew(&ns_lock_attrib);
75+
ns_lock.init = true;
76+
return TFM_SUCCESS;
77+
}
78+
else {
79+
return TFM_ERROR_GENERIC;
80+
}
81+
}
82+
83+
bool tfm_ns_lock_get_init_state()
84+
{
85+
return ns_lock.init;
86+
}
87+
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*
6+
*/
7+
8+
#include "interface/include/psa_client.h"
9+
#include "tfm_ns_lock.h"
10+
#include "tfm_api.h"
11+
12+
/**** API functions ****/
13+
14+
uint32_t psa_framework_version(void)
15+
{
16+
return tfm_ns_lock_dispatch((veneer_fn)tfm_psa_framework_version_veneer,
17+
0,
18+
0,
19+
0,
20+
0);
21+
}
22+
23+
uint32_t psa_version(uint32_t sid)
24+
{
25+
return tfm_ns_lock_dispatch((veneer_fn)tfm_psa_version_veneer,
26+
sid,
27+
0,
28+
0,
29+
0);
30+
}
31+
32+
psa_handle_t psa_connect(uint32_t sid, uint32_t minor_version)
33+
{
34+
return tfm_ns_lock_dispatch((veneer_fn)tfm_psa_connect_veneer,
35+
sid,
36+
minor_version,
37+
0,
38+
0);
39+
}
40+
41+
psa_status_t psa_call(psa_handle_t handle,
42+
const psa_invec *in_vec,
43+
size_t in_len,
44+
psa_outvec *out_vec,
45+
size_t out_len)
46+
{
47+
/* FixMe: sanity check can be added to offload some NS thread checks from
48+
* TFM secure API
49+
*/
50+
51+
/* Due to v8M restrictions, TF-M NS API needs to add another layer of
52+
* serialization in order for NS to pass arguments to S
53+
*/
54+
psa_invec in_vecs, out_vecs;
55+
56+
in_vecs.base = in_vec;
57+
in_vecs.len = in_len;
58+
out_vecs.base = out_vec;
59+
out_vecs.len = out_len;
60+
return tfm_ns_lock_dispatch((veneer_fn)tfm_psa_call_veneer,
61+
(uint32_t)handle,
62+
(uint32_t)&in_vecs,
63+
(uint32_t)&out_vecs,
64+
0);
65+
}
66+
67+
void psa_close(psa_handle_t handle)
68+
{
69+
tfm_ns_lock_dispatch((veneer_fn)tfm_psa_close_veneer,
70+
(uint32_t)handle,
71+
0,
72+
0,
73+
0);
74+
}
75+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* Copyright (c) 2017-2019 ARM Limited
2+
*
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+
/*********** WARNING: This is an auto-generated file. Do not edit! ***********/
19+
20+
#ifndef __TFM_PARTITION_DEFS_INC__
21+
#define __TFM_PARTITION_DEFS_INC__
22+
23+
#ifdef TFM_PSA_API
24+
#define ITS_ID (TFM_SP_BASE + 0)
25+
#endif
26+
27+
#ifdef TFM_PSA_API
28+
#define PLATFORM_ID (TFM_SP_BASE + 1)
29+
#endif
30+
31+
#ifdef TFM_PSA_API
32+
#define CRYPTO_SRV_ID (TFM_SP_BASE + 2)
33+
#endif
34+
35+
#define TFM_MAX_USER_PARTITIONS (3)
36+
37+
#endif /* __TFM_PARTITION_DEFS_INC__ */
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2018-2019, Arm Limited. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*
6+
*/
7+
8+
/*********** WARNING: This is an auto-generated file. Do not edit! ***********/
9+
10+
#ifndef __TFM_PARTITION_LIST_INC__
11+
#define __TFM_PARTITION_LIST_INC__
12+
13+
#ifdef TFM_PSA_API
14+
/******** ITS ********/
15+
PARTITION_DECLARE(ITS, 0
16+
| SPM_PART_FLAG_IPC
17+
, "APPLICATION-ROT", 10, NORMAL, 2048);
18+
PARTITION_ADD_INIT_FUNC(ITS, its_entry);
19+
#endif /* TFM_PSA_API */
20+
21+
#ifdef TFM_PSA_API
22+
/******** PLATFORM ********/
23+
PARTITION_DECLARE(PLATFORM, 0
24+
| SPM_PART_FLAG_IPC
25+
, "APPLICATION-ROT", 8, NORMAL, 1024);
26+
PARTITION_ADD_INIT_FUNC(PLATFORM, platform_partition_entry);
27+
#endif /* TFM_PSA_API */
28+
29+
#ifdef TFM_PSA_API
30+
/******** CRYPTO_SRV ********/
31+
PARTITION_DECLARE(CRYPTO_SRV, 0
32+
| SPM_PART_FLAG_IPC
33+
, "APPLICATION-ROT", 35, NORMAL, 16384);
34+
PARTITION_ADD_INIT_FUNC(CRYPTO_SRV, crypto_main);
35+
#endif /* TFM_PSA_API */
36+
37+
#endif /* __TFM_PARTITION_LIST_INC__ */
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) 2018-2019, Arm Limited. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*
6+
*/
7+
8+
/*********** WARNING: This is an auto-generated file. Do not edit! ***********/
9+
10+
#ifndef __TFM_SERVICE_LIST_INC__
11+
#define __TFM_SERVICE_LIST_INC__
12+
13+
#ifdef TFM_PSA_API
14+
/******** ITS ********/
15+
{"PSA_ITS_GET", ITS_ID, PSA_ITS_GET_MSK, 0x00011A00, true, 1, TFM_VERSION_POLICY_RELAXED},
16+
{"PSA_ITS_SET", ITS_ID, PSA_ITS_SET_MSK, 0x00011A01, true, 1, TFM_VERSION_POLICY_RELAXED},
17+
{"PSA_ITS_INFO", ITS_ID, PSA_ITS_INFO_MSK, 0x00011A02, true, 1, TFM_VERSION_POLICY_RELAXED},
18+
{"PSA_ITS_REMOVE", ITS_ID, PSA_ITS_REMOVE_MSK, 0x00011A03, true, 1, TFM_VERSION_POLICY_RELAXED},
19+
{"PSA_ITS_RESET", ITS_ID, PSA_ITS_RESET_MSK, 0x00011A04, false, 1, TFM_VERSION_POLICY_RELAXED},
20+
#endif /* TFM_PSA_API */
21+
22+
#ifdef TFM_PSA_API
23+
/******** PLATFORM ********/
24+
{"PSA_PLATFORM_LC_GET", PLATFORM_ID, PSA_PLATFORM_LC_GET_MSK, 0x00011000, true, 1, TFM_VERSION_POLICY_RELAXED},
25+
{"PSA_PLATFORM_LC_SET", PLATFORM_ID, PSA_PLATFORM_LC_SET_MSK, 0x00011001, true, 1, TFM_VERSION_POLICY_RELAXED},
26+
{"PSA_PLATFORM_SYSTEM_RESET", PLATFORM_ID, PSA_PLATFORM_SYSTEM_RESET_MSK, 0x00011002, true, 1, TFM_VERSION_POLICY_RELAXED},
27+
#endif /* TFM_PSA_API */
28+
29+
#ifdef TFM_PSA_API
30+
/******** CRYPTO_SRV ********/
31+
{"PSA_CRYPTO_INIT_ID", CRYPTO_SRV_ID, PSA_CRYPTO_INIT, 0x00000F00, true, 1, TFM_VERSION_POLICY_STRICT},
32+
{"PSA_MAC_ID", CRYPTO_SRV_ID, PSA_MAC, 0x00000F01, true, 1, TFM_VERSION_POLICY_STRICT},
33+
{"PSA_HASH_ID", CRYPTO_SRV_ID, PSA_HASH, 0x00000F02, true, 1, TFM_VERSION_POLICY_STRICT},
34+
{"PSA_ASYMMETRIC_ID", CRYPTO_SRV_ID, PSA_ASYMMETRIC, 0x00000F03, true, 1, TFM_VERSION_POLICY_STRICT},
35+
{"PSA_SYMMETRIC_ID", CRYPTO_SRV_ID, PSA_SYMMETRIC, 0x00000F04, true, 1, TFM_VERSION_POLICY_STRICT},
36+
{"PSA_AEAD_ID", CRYPTO_SRV_ID, PSA_AEAD, 0x00000F05, true, 1, TFM_VERSION_POLICY_STRICT},
37+
{"PSA_KEY_MNG_ID", CRYPTO_SRV_ID, PSA_KEY_MNG, 0x00000F06, true, 1, TFM_VERSION_POLICY_STRICT},
38+
{"PSA_RNG_ID", CRYPTO_SRV_ID, PSA_RNG, 0x00000F07, true, 1, TFM_VERSION_POLICY_STRICT},
39+
{"PSA_CRYPTO_FREE_ID", CRYPTO_SRV_ID, PSA_CRYPTO_FREE, 0x00000F08, true, 1, TFM_VERSION_POLICY_STRICT},
40+
{"PSA_GENERATOR_ID", CRYPTO_SRV_ID, PSA_GENERATOR, 0x00000F09, true, 1, TFM_VERSION_POLICY_STRICT},
41+
{"PSA_ENTROPY_ID", CRYPTO_SRV_ID, PSA_ENTROPY_INJECT, 0x00000F0A, true, 1, TFM_VERSION_POLICY_STRICT},
42+
#endif /* TFM_PSA_API */
43+
44+
#endif /* __TFM_SERVICE_LIST_INC__ */

0 commit comments

Comments
 (0)