Skip to content

Commit cf3fd85

Browse files
author
Michael Schwarcz
committed
Align existing partitions to work with TF-M
- ITS - Crypto - Platform
1 parent 2198d5c commit cf3fd85

File tree

18 files changed

+336
-43
lines changed

18 files changed

+336
-43
lines changed

components/TARGET_PSA/inc/psa/lifecycle.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ uint32_t psa_security_lifecycle_state(void);
6262
psa_status_t mbed_psa_reboot_and_request_new_security_state(uint32_t new_state);
6363

6464

65+
/** \brief Resets the system
66+
*
67+
*/
68+
void psa_system_reset();
69+
6570
#ifdef __cplusplus
6671
}
6772
#endif

components/TARGET_PSA/services/crypto/COMPONENT_PSA_SRV_IPC/psa_crypto_spm.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
#include <stdlib.h>
2525
#include <string.h>
2626
#include "psa_crypto_srv_ifs.h"
27-
2827
#include "psa/client.h"
29-
3028
#include "crypto.h"
3129
#include "crypto_platform_spe.h"
3230

components/TARGET_PSA/services/crypto/COMPONENT_SPE/psa_crypto_partition.c

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
// ---------------------------------- Includes ---------------------------------
2-
#include "psa/service.h"
3-
#include "psa/client.h"
4-
#include <stdint.h>
5-
#include <string.h>
62

73

4+
#include "psa/client.h"
5+
#include "psa/service.h"
6+
#if defined(TARGET_TFM)
7+
#define SPM_PANIC(format, ...) \
8+
{ \
9+
while(1){}; \
10+
}
11+
#endif
12+
813
#define PSA_CRYPTO_SECURE 1
914
#include "crypto_spe.h"
1015
#include "crypto_platform_spe.h"
@@ -446,7 +451,11 @@ static void psa_hash_operation(void)
446451
case PSA_HASH_CLONE_BEGIN: {
447452
size_t index = 0;
448453

454+
#if defined(TARGET_MBED_SPM)
449455
status = reserve_hash_clone(psa_identity(msg.handle), msg.rhandle, &index);
456+
#else
457+
status = reserve_hash_clone(msg.client_id, msg.rhandle, &index);
458+
#endif
450459
if (status == PSA_SUCCESS) {
451460
psa_write(msg.handle, 0, &index, sizeof(index));
452461
}
@@ -462,7 +471,11 @@ static void psa_hash_operation(void)
462471
SPM_PANIC("SPM read length mismatch");
463472
}
464473

474+
#if defined(TARGET_MBED_SPM)
465475
status = get_hash_clone(index, psa_identity(msg.handle), &hash_clone);
476+
#else
477+
status = get_hash_clone(index, msg.client_id, &hash_clone);
478+
#endif
466479
if (status == PSA_SUCCESS) {
467480
status = psa_hash_clone(hash_clone->source_operation, msg.rhandle);
468481
release_hash_clone(hash_clone);
@@ -1488,7 +1501,12 @@ void psa_crypto_generator_operations(void)
14881501
void crypto_main(void *ptr)
14891502
{
14901503
while (1) {
1491-
uint32_t signals = psa_wait_any(PSA_BLOCK);
1504+
uint32_t signals = 0;
1505+
#if defined(TARGET_MBED_SPM)
1506+
signals = psa_wait_any(PSA_BLOCK);
1507+
#else
1508+
signals = psa_wait(CRYPTO_SRV_WAIT_ANY_SID_MSK, PSA_BLOCK);
1509+
#endif
14921510
if (signals & PSA_CRYPTO_INIT) {
14931511
psa_crypto_init_operation();
14941512
}

components/TARGET_PSA/services/platform/COMPONENT_PSA_SRV_EMUL/platform_emul.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,8 @@ psa_status_t mbed_psa_reboot_and_request_new_security_state(uint32_t new_state)
2828
{
2929
return psa_platfrom_lifecycle_change_request_impl(new_state);
3030
}
31+
32+
void psa_system_reset(void)
33+
{
34+
psa_system_reset_impl();
35+
}

components/TARGET_PSA/services/platform/COMPONENT_PSA_SRV_IMPL/platform_srv_impl.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include "psa/lifecycle.h"
1919
#include "psa/internal_trusted_storage.h"
2020
#include "platform_srv_impl.h"
21+
#include "mbed_toolchain.h"
22+
#include "cmsis.h"
2123

2224
#ifndef MBED_CONF_LIFECYCLE_STATE
2325
#define MBED_CONF_LIFECYCLE_STATE PSA_LIFECYCLE_ASSEMBLY_AND_TEST
@@ -38,3 +40,9 @@ psa_status_t psa_platfrom_lifecycle_change_request_impl(uint32_t state)
3840
}
3941
return PSA_LIFECYCLE_ERROR;
4042
}
43+
44+
MBED_WEAK void psa_system_reset_impl(void)
45+
{
46+
/* Reset the system */
47+
NVIC_SystemReset();
48+
}

components/TARGET_PSA/services/platform/COMPONENT_PSA_SRV_IMPL/platform_srv_impl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@
2222

2323
psa_status_t psa_platfrom_lifecycle_get_impl(uint32_t *lc_state);
2424
psa_status_t psa_platfrom_lifecycle_change_request_impl(uint32_t lc_state);
25+
void psa_system_reset_impl(void);
2526

2627
#endif // __PLATFROM_SRV_IMPL_H__

components/TARGET_PSA/services/platform/COMPONENT_PSA_SRV_IPC/platform_ipc.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "psa_platform_ifs.h"
1919
#include "psa/lifecycle.h"
2020
#include "psa/client.h"
21+
#include "mbed_toolchain.h"
2122

2223
uint32_t psa_security_lifecycle_state(void)
2324
{
@@ -56,3 +57,12 @@ psa_status_t mbed_psa_reboot_and_request_new_security_state(uint32_t new_state)
5657
return status;
5758
}
5859

60+
MBED_NORETURN void psa_system_reset(void)
61+
{
62+
psa_handle_t conn = psa_connect(PSA_PLATFORM_LC_SET, 1);
63+
if (conn <= PSA_NULL_HANDLE) {
64+
return;
65+
}
66+
67+
psa_call(conn, NULL, 0, NULL, 0);
68+
}

components/TARGET_PSA/services/platform/COMPONENT_SPE/TARGET_MBED_SPM/psa_platform_partition.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@ spm_rot_service_t platform_rot_services[PLATFORM_ROT_SRV_COUNT] = {
7777
.tail = NULL
7878
}
7979
},
80+
{
81+
.sid = PSA_PLATFORM_SYSTEM_RESET,
82+
.mask = PSA_PLATFORM_SYSTEM_RESET_MSK,
83+
.partition = NULL,
84+
.min_version = 1,
85+
.min_version_policy = PSA_MINOR_VERSION_POLICY_RELAXED,
86+
.allow_nspe = true,
87+
.queue = {
88+
.head = NULL,
89+
.tail = NULL
90+
}
91+
},
8092
};
8193

8294
/* External SIDs used by PLATFORM */

components/TARGET_PSA/services/platform/COMPONENT_SPE/platform_partition.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020
#include "psa/internal_trusted_storage.h"
2121
#include "psa/service.h"
2222

23+
#if defined(TARGET_TFM)
24+
#define SPM_PANIC(format, ...) \
25+
{ \
26+
while(1){}; \
27+
}
28+
#endif
29+
2330
typedef psa_status_t (*SignalHandler)(psa_msg_t *);
2431

2532
static psa_status_t lifecycle_get(psa_msg_t *msg)
@@ -52,6 +59,12 @@ static psa_status_t lifecycle_change_request(psa_msg_t *msg)
5259

5360
}
5461

62+
static psa_status_t system_reset_request(psa_msg_t *msg)
63+
{
64+
(void)msg;
65+
psa_system_reset_impl();
66+
}
67+
5568
static void message_handler(psa_msg_t *msg, SignalHandler handler)
5669
{
5770
psa_status_t status = PSA_SUCCESS;
@@ -77,7 +90,12 @@ void platform_partition_entry(void *ptr)
7790
uint32_t signals = 0;
7891
psa_msg_t msg = {0};
7992
while (1) {
93+
#if defined(TARGET_MBED_SPM)
8094
signals = psa_wait_any(PSA_BLOCK);
95+
#else
96+
signals = psa_wait(PLATFORM_WAIT_ANY_SID_MSK, PSA_BLOCK);
97+
#endif
98+
8199
if ((signals & PSA_PLATFORM_LC_GET_MSK) != 0) {
82100
psa_get(PSA_PLATFORM_LC_GET_MSK, &msg);
83101
message_handler(&msg, lifecycle_get);
@@ -86,5 +104,9 @@ void platform_partition_entry(void *ptr)
86104
psa_get(PSA_PLATFORM_LC_SET_MSK, &msg);
87105
message_handler(&msg, lifecycle_change_request);
88106
}
107+
if ((signals & PSA_PLATFORM_SYSTEM_RESET_MSK) != 0) {
108+
psa_get(PSA_PLATFORM_SYSTEM_RESET_MSK, &msg);
109+
message_handler(&msg, system_reset_request);
110+
}
89111
}
90112
}

components/TARGET_PSA/services/platform/COMPONENT_SPE/psa_platform_partition.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
#define PLATFORM_ID 8
3030

31-
#define PLATFORM_ROT_SRV_COUNT (2UL)
31+
#define PLATFORM_ROT_SRV_COUNT (3UL)
3232
#define PLATFORM_EXT_ROT_SRV_COUNT (1UL)
3333

3434
/* PLATFORM event flags */
@@ -44,10 +44,13 @@
4444
#define PSA_PLATFORM_LC_GET_MSK (1UL << PSA_PLATFORM_LC_GET_MSK_POS)
4545
#define PSA_PLATFORM_LC_SET_MSK_POS (5UL)
4646
#define PSA_PLATFORM_LC_SET_MSK (1UL << PSA_PLATFORM_LC_SET_MSK_POS)
47+
#define PSA_PLATFORM_SYSTEM_RESET_MSK_POS (6UL)
48+
#define PSA_PLATFORM_SYSTEM_RESET_MSK (1UL << PSA_PLATFORM_SYSTEM_RESET_MSK_POS)
4749

4850
#define PLATFORM_WAIT_ANY_SID_MSK (\
4951
PSA_PLATFORM_LC_GET_MSK | \
50-
PSA_PLATFORM_LC_SET_MSK)
52+
PSA_PLATFORM_LC_SET_MSK | \
53+
PSA_PLATFORM_SYSTEM_RESET_MSK)
5154

5255

5356
#endif // PSA_PLATFORM_PARTITION_H

components/TARGET_PSA/services/platform/platform_psa.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@
2121
"non_secure_clients": true,
2222
"minor_version": 1,
2323
"minor_policy": "RELAXED"
24+
},
25+
{
26+
"name": "PSA_PLATFORM_SYSTEM_RESET",
27+
"identifier": "0x00011002",
28+
"signal": "PSA_PLATFORM_SYSTEM_RESET_MSK",
29+
"non_secure_clients": true,
30+
"minor_version": 1,
31+
"minor_policy": "RELAXED"
2432
}
2533
],
2634
"extern_sids": [

components/TARGET_PSA/services/platform/psa_platform_ifs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@
2828

2929
#define PSA_PLATFORM_LC_GET 0x00011000
3030
#define PSA_PLATFORM_LC_SET 0x00011001
31+
#define PSA_PLATFORM_SYSTEM_RESET 0x00011002
3132

3233
#endif // PSA_PLATFORM_PARTITION_ROT_SERVICES_H

0 commit comments

Comments
 (0)