Skip to content

Commit 95f8dbc

Browse files
Alexander ZilberkantOren Cohen
authored andcommitted
Add new platform partition
1 parent cae1ebf commit 95f8dbc

File tree

13 files changed

+563
-2
lines changed

13 files changed

+563
-2
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/* Copyright (c) 2018 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+
#ifndef __LIFECYCLE_H__
19+
#define __LIFECYCLE_H__
20+
21+
/** @file
22+
@brief This file describes the PSA RoT Lifecycle API
23+
*/
24+
25+
#include <stddef.h>
26+
#include <stdint.h>
27+
28+
#ifdef __cplusplus
29+
extern "C"
30+
{
31+
#endif
32+
33+
typedef int32_t psa_status_t;
34+
35+
#define PSA_LIFECYCLE_STATE_MASK (0xff00u) /**< A mask value that extracts the main lifecycle state */
36+
#define PSA_LIFECYCLE_SUBSTATE_MASK (0x00ffu) /**< A mask value that extracts the IMPLEMENTATION DEFINED lifecycle sub-state */
37+
38+
#define PSA_LIFECYCLE_UNKNOWN (0x0000u) /**< State is unknown */
39+
#define PSA_LIFECYCLE_ASSEMBLY_AND_TEST (0x1000u) /**< Assembly and Test state */
40+
#define PSA_LIFECYCLE_PSA_ROT_PROVISIONING (0x2000u) /**< PSA RoT Provisioning state */
41+
#define PSA_LIFECYCLE_SECURED (0x3000u) /**< Secured state */
42+
#define PSA_LIFECYCLE_NON_PSA_ROT_DEBUG (0x4000u) /**< Non PSA RoT debug state */
43+
#define PSA_LIFECYCLE_RECOVERABLE_PSA_ROT_DEBUG (0x5000u) /**< Recoverable PSA RoT Debug state */
44+
#define PSA_LIFECYCLE_DECOMMISSIONED (0x6000u) /**< Decommissioned state */
45+
46+
#define PSA_LIFECYCLE_SUCCESS 0
47+
#define PSA_LIFECYCLE_ERROR (INT32_MIN + 1000)
48+
49+
/** \brief Get PSA RoT lifecycle state
50+
*
51+
* \retval The main state and sub-state are encoded as follows:@n
52+
@a version[15:8] – main lifecycle state
53+
@a version[7:0] – IMPLEMENTATION DEFINED sub-state
54+
*/
55+
uint32_t psa_security_lifecycle_state(void);
56+
57+
/** \brief Request state change
58+
*
59+
* State change requested and the system.
60+
* TODO when not drunk
61+
*/
62+
psa_status_t mbed_psa_reboot_and_request_new_security_state(uint32_t new_state);
63+
64+
65+
#ifdef __cplusplus
66+
}
67+
#endif
68+
69+
#endif // __LIFECYCLE_H__
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* Copyright (c) 2018 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+
#include "psa/lifecycle.h"
19+
#include "platform_srv_impl.h"
20+
21+
uint32_t psa_security_lifecycle_state(void)
22+
{
23+
uint32_t lc_state = 0;
24+
return psa_platfrom_lifecycle_get_impl(&lc_state);
25+
}
26+
27+
psa_status_t mbed_psa_reboot_and_request_new_security_state(uint32_t new_state)
28+
{
29+
return psa_platfrom_lifecycle_change_request_impl(new_state);
30+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/* Copyright (c) 2018 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+
#include "psa/lifecycle.h"
19+
#include "psa/internal_trusted_storage.h"
20+
#include "platform_srv_impl.h"
21+
22+
#ifndef MBED_CONF_LIFECYCLE_STATE
23+
#define MBED_CONF_LIFECYCLE_STATE PSA_LIFECYCLE_ASSEMBLY_AND_TEST
24+
#endif
25+
26+
psa_status_t psa_platfrom_lifecycle_get_impl(uint32_t *lc_state)
27+
{
28+
// SPM_ASSERT(lc_state);
29+
*lc_state = MBED_CONF_LIFECYCLE_STATE;
30+
return PSA_LIFECYCLE_SUCCESS;
31+
}
32+
33+
psa_its_status_t psa_its_reset();
34+
35+
psa_status_t psa_platfrom_lifecycle_change_request_impl(uint32_t state)
36+
{
37+
if (PSA_LIFECYCLE_ASSEMBLY_AND_TEST == state) {
38+
return psa_its_reset();
39+
}
40+
return PSA_LIFECYCLE_ERROR;
41+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* Copyright (c) 2018 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+
#ifndef __PLATFROM_SRV_IMPL_H__
19+
#define __PLATFROM_SRV_IMPL_H__
20+
21+
#include "psa/client.h"
22+
23+
psa_status_t psa_platfrom_lifecycle_get_impl(uint32_t *lc_state);
24+
psa_status_t psa_platfrom_lifecycle_change_request_impl(uint32_t lc_state);
25+
26+
#endif // __PLATFROM_SRV_IMPL_H__
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/* Copyright (c) 2018 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+
#include "psa_platform_ifs.h"
19+
#include "psa/lifecycle.h"
20+
#include "psa/client.h"
21+
22+
uint32_t psa_security_lifecycle_state(void)
23+
{
24+
psa_handle_t conn = psa_connect(PSA_PLATFORM_LC_GET, 1);
25+
if (conn <= PSA_NULL_HANDLE) {
26+
return PSA_LIFECYCLE_UNKNOWN;
27+
}
28+
29+
uint32_t lc_state = 0;
30+
psa_outvec resp[1] = { &lc_state, sizeof(lc_state) };
31+
32+
psa_status_t status = psa_call(conn, NULL, 0, resp, 1);
33+
if (status == PSA_DROP_CONNECTION) {
34+
lc_state = PSA_LIFECYCLE_UNKNOWN;
35+
}
36+
37+
psa_close(conn);
38+
39+
return lc_state;
40+
}
41+
42+
psa_status_t mbed_psa_reboot_and_request_new_security_state(uint32_t new_state)
43+
{
44+
psa_handle_t conn = psa_connect(PSA_PLATFORM_LC_SET, 1);
45+
if (conn <= PSA_NULL_HANDLE) {
46+
return (psa_status_t) conn;
47+
}
48+
49+
psa_invec msg[1] = {
50+
{ &new_state, sizeof(new_state) }
51+
};
52+
53+
psa_status_t status = psa_call(conn, msg, 1, NULL, 0);
54+
55+
psa_close(conn);
56+
return status;
57+
}
58+
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/* Copyright (c) 2017-2018 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+
/***********************************************************************************************************************
19+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
20+
* THIS FILE IS AN AUTO-GENERATED FILE - DO NOT MODIFY IT.
21+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
22+
* Template Version 1.0
23+
* Generated by tools/spm/generate_partition_code.py Version 1.0
24+
**********************************************************************************************************************/
25+
26+
#if !defined(TARGET_TFM)
27+
28+
#include "cmsis.h"
29+
#include "mbed_toolchain.h" /* For using MBED_ALIGN macro */
30+
#include "rtx_os.h"
31+
#include "spm_panic.h"
32+
#include "spm_internal.h"
33+
#include "psa_platform_partition.h"
34+
#include "psa_platform_ifs.h"
35+
36+
37+
/* Threads stacks */
38+
MBED_ALIGN(8) uint8_t platform_thread_stack[1024] = {0};
39+
40+
/* Threads control blocks */
41+
osRtxThread_t platform_thread_cb = {0};
42+
43+
/* Thread attributes - for thread initialization */
44+
osThreadAttr_t platform_thread_attr = {
45+
.name = "platform",
46+
.attr_bits = 0,
47+
.cb_mem = &platform_thread_cb,
48+
.cb_size = sizeof(platform_thread_cb),
49+
.stack_mem = platform_thread_stack,
50+
.stack_size = 1024,
51+
.priority = osPriorityNormal,
52+
.tz_module = 0,
53+
.reserved = 0
54+
};
55+
56+
spm_rot_service_t platform_rot_services[PLATFORM_ROT_SRV_COUNT] = {
57+
{
58+
.sid = PSA_PLATFORM_LC_GET,
59+
.mask = PSA_PLATFORM_LC_GET_MSK,
60+
.partition = NULL,
61+
.min_version = 1,
62+
.min_version_policy = PSA_MINOR_VERSION_POLICY_RELAXED,
63+
.allow_nspe = true,
64+
.queue = {
65+
.head = NULL,
66+
.tail = NULL
67+
}
68+
},
69+
{
70+
.sid = PSA_PLATFORM_LC_SET,
71+
.mask = PSA_PLATFORM_LC_SET_MSK,
72+
.partition = NULL,
73+
.min_version = 1,
74+
.min_version_policy = PSA_MINOR_VERSION_POLICY_RELAXED,
75+
.allow_nspe = true,
76+
.queue = {
77+
.head = NULL,
78+
.tail = NULL
79+
}
80+
},
81+
};
82+
83+
84+
static osRtxMutex_t platform_mutex = {0};
85+
static const osMutexAttr_t platform_mutex_attr = {
86+
.name = "platform_mutex",
87+
.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust,
88+
.cb_mem = &platform_mutex,
89+
.cb_size = sizeof(platform_mutex),
90+
};
91+
92+
93+
extern void platform_partition_entry(void *ptr);
94+
95+
void platform_init(spm_partition_t *partition)
96+
{
97+
if (NULL == partition) {
98+
SPM_PANIC("partition is NULL!\n");
99+
}
100+
101+
partition->mutex = osMutexNew(&platform_mutex_attr);
102+
if (NULL == partition->mutex) {
103+
SPM_PANIC("Failed to create mutex for secure partition platform!\n");
104+
}
105+
106+
for (uint32_t i = 0; i < PLATFORM_ROT_SRV_COUNT; ++i) {
107+
platform_rot_services[i].partition = partition;
108+
}
109+
partition->rot_services = platform_rot_services;
110+
111+
partition->thread_id = osThreadNew(platform_partition_entry, NULL, &platform_thread_attr);
112+
if (NULL == partition->thread_id) {
113+
SPM_PANIC("Failed to create start main thread of partition platform!\n");
114+
}
115+
}
116+
117+
#endif // !defined(TARGET_TFM)

0 commit comments

Comments
 (0)