Skip to content

Commit 6be3afe

Browse files
tomchydegjorva
authored andcommitted
suit: Add support for MFS_VAR in suit_plat_copy
Add support for copying MFST_VAR content between manifes variables. Ref: NCSDK-30807 Signed-off-by: Tomasz Chyrowicz <[email protected]>
1 parent 39f973c commit 6be3afe

File tree

8 files changed

+451
-106
lines changed

8 files changed

+451
-106
lines changed

subsys/suit/platform/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ zephyr_library_sources(src/suit_plat_commands.c)
1616
zephyr_library_sources(src/suit_plat_version.c)
1717
zephyr_library_sources(src/suit_plat_fetch.c)
1818
zephyr_library_sources(src/suit_plat_retrieve_manifest.c)
19+
zephyr_library_sources(src/suit_plat_copy.c)
1920
zephyr_library_sources(src/suit_plat_write.c)
2021
zephyr_library_sources(src/suit_plat_check_content.c)
2122
zephyr_library_sources_ifdef(CONFIG_SUIT_CHECK_IMAGE_MATCH src/suit_plat_check_image_match.c)

subsys/suit/platform/app/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ zephyr_library()
1313

1414
zephyr_library_sources(src/suit_plat_swap.c)
1515
zephyr_library_sources(src/suit_plat_fetch_app_specific.c)
16-
zephyr_library_sources(src/suit_plat_copy.c)
16+
zephyr_library_sources(src/suit_plat_copy_app_specific.c)
1717
zephyr_library_sources(src/suit_plat_write_app_specific.c)
1818
zephyr_library_sources(src/suit_plat_retrieve_manifest_app_specific.c)
1919
zephyr_library_sources(src/suit_plat_version_app_specific.c)

subsys/suit/platform/app/src/suit_plat_copy.c

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2023 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <suit_plat_copy_domain_specific.h>
8+
9+
bool suit_plat_copy_domain_specific_is_type_supported(suit_component_type_t dst_component_type,
10+
suit_component_type_t src_component_type)
11+
{
12+
return false;
13+
}
14+
15+
int suit_plat_check_copy_domain_specific(suit_component_t dst_handle,
16+
suit_component_type_t dst_component_type,
17+
suit_component_t src_handle,
18+
suit_component_type_t src_component_type,
19+
struct zcbor_string *manifest_component_id,
20+
struct suit_encryption_info *enc_info)
21+
{
22+
return SUIT_ERR_UNSUPPORTED_COMMAND;
23+
}
24+
25+
int suit_plat_copy_domain_specific(suit_component_t dst_handle,
26+
suit_component_type_t dst_component_type,
27+
suit_component_t src_handle,
28+
suit_component_type_t src_component_type,
29+
struct zcbor_string *manifest_component_id,
30+
struct suit_encryption_info *enc_info)
31+
{
32+
return SUIT_ERR_UNSUPPORTED_COMMAND;
33+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#ifndef SUIT_PLAT_COPY_DOMAIN_SPECIFIC_H__
8+
#define SUIT_PLAT_COPY_DOMAIN_SPECIFIC_H__
9+
10+
#include <stdint.h>
11+
#include <suit_types.h>
12+
#include <suit_platform_internal.h>
13+
14+
#ifdef __cplusplus
15+
extern "C" {
16+
#endif
17+
18+
/**
19+
* @brief Return destination component type supported by suit_plat_copy for the current domain.
20+
*/
21+
bool suit_plat_copy_domain_specific_is_type_supported(suit_component_type_t dst_component_type,
22+
suit_component_type_t src_component_type);
23+
24+
/**
25+
* @brief Domain specific part of the core part of the suit_plat_copy function.
26+
*/
27+
int suit_plat_check_copy_domain_specific(suit_component_t dst_handle,
28+
suit_component_type_t dst_component_type,
29+
suit_component_t src_handle,
30+
suit_component_type_t src_component_type,
31+
struct zcbor_string *manifest_component_id,
32+
struct suit_encryption_info *enc_info);
33+
34+
/**
35+
* @brief Domain specific part of the core part of the suit_plat_copy function.
36+
*/
37+
int suit_plat_copy_domain_specific(suit_component_t dst_handle,
38+
suit_component_type_t dst_component_type,
39+
suit_component_t src_handle,
40+
suit_component_type_t src_component_type,
41+
struct zcbor_string *manifest_component_id,
42+
struct suit_encryption_info *enc_info);
43+
44+
#ifdef __cplusplus
45+
}
46+
#endif
47+
48+
#endif /* SUIT_PLAT_COPY_DOMAIN_SPECIFIC_H__ */

subsys/suit/platform/sdfw/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ zephyr_library()
1313

1414
zephyr_library_sources(src/suit_plat_swap.c)
1515
zephyr_library_sources(src/suit_plat_fetch_sdfw_specific.c)
16-
zephyr_library_sources(src/suit_plat_copy.c)
16+
zephyr_library_sources(src/suit_plat_copy_sdfw_specific.c)
1717
zephyr_library_sources(src/suit_plat_write_sdfw_specific.c)
1818
zephyr_library_sources(src/suit_plat_retrieve_manifest_sdfw_specific.c)
1919
zephyr_library_sources(src/suit_plat_version_sdfw_specific.c)

subsys/suit/platform/sdfw/src/suit_plat_copy.c renamed to subsys/suit/platform/sdfw/src/suit_plat_copy_sdfw_specific.c

Lines changed: 90 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <suit_plat_digest_cache.h>
1414
#include <suit_plat_memptr_size_update.h>
1515
#include <suit_memory_layout.h>
16+
#include <suit_plat_copy_domain_specific.h>
1617

1718
#if CONFIG_SUIT_IPUC
1819
#include <suit_plat_ipuc.h>
@@ -33,53 +34,98 @@
3334
#include <suit_decrypt_filter.h>
3435
#endif /* CONFIG_SUIT_STREAM_FILTER_DECRYPT */
3536

36-
LOG_MODULE_REGISTER(suit_plat_copy, CONFIG_SUIT_LOG_LEVEL);
37+
LOG_MODULE_DECLARE(suit_plat_copy, CONFIG_SUIT_LOG_LEVEL);
3738

38-
int suit_plat_check_copy(suit_component_t dst_handle, suit_component_t src_handle,
39-
struct zcbor_string *manifest_component_id,
40-
struct suit_encryption_info *enc_info)
39+
#ifdef CONFIG_SUIT_STREAM
40+
static bool
41+
decode_supported_soc_specific_component(suit_component_t handle,
42+
suit_secure_domain_component_number_t *soc_component)
43+
{
44+
struct zcbor_string *component_id = NULL;
45+
uint32_t component_number = 0;
46+
suit_plat_err_t plat_ret;
47+
int ret;
48+
49+
ret = suit_plat_component_id_get(handle, &component_id);
50+
if (ret != SUIT_SUCCESS) {
51+
LOG_ERR("Failed to get component ID: %d", ret);
52+
return false;
53+
}
54+
55+
plat_ret = suit_plat_decode_component_number(component_id, &component_number);
56+
if (plat_ret != SUIT_PLAT_SUCCESS) {
57+
LOG_ERR("Failed to decode SOC specific component number: %d", plat_ret);
58+
ret = suit_plat_err_to_processor_err_convert(plat_ret);
59+
return false;
60+
}
61+
62+
*soc_component = (suit_secure_domain_component_number_t)component_number;
63+
64+
if ((*soc_component) != SUIT_SECDOM_COMPONENT_NUMBER_SDFW &&
65+
(*soc_component) != SUIT_SECDOM_COMPONENT_NUMBER_SDFW_RECOVERY) {
66+
LOG_ERR("Unsupported SOC specific component type: %d", *soc_component);
67+
return false;
68+
}
69+
70+
return true;
71+
}
72+
#endif /* CONFIG_SUIT_STREAM */
73+
74+
bool suit_plat_copy_domain_specific_is_type_supported(suit_component_type_t dst_component_type,
75+
suit_component_type_t src_component_type)
4176
{
4277
#ifdef CONFIG_SUIT_STREAM
78+
/* Check if destination component type is supported */
79+
if ((dst_component_type != SUIT_COMPONENT_TYPE_MEM) &&
80+
(dst_component_type != SUIT_COMPONENT_TYPE_SOC_SPEC)) {
81+
return false;
82+
}
83+
84+
/* Check if source component type is supported */
85+
if ((src_component_type != SUIT_COMPONENT_TYPE_MEM) &&
86+
(src_component_type != SUIT_COMPONENT_TYPE_CAND_IMG)) {
87+
return false;
88+
}
89+
90+
return true;
91+
#else /* CONFIG_SUIT_STREAM */
92+
return false;
93+
#endif /* CONFIG_SUIT_STREAM */
94+
}
95+
96+
int suit_plat_check_copy_domain_specific(suit_component_t dst_handle,
97+
suit_component_type_t dst_component_type,
98+
suit_component_t src_handle,
99+
suit_component_type_t src_component_type,
100+
struct zcbor_string *manifest_component_id,
101+
struct suit_encryption_info *enc_info)
102+
{
103+
#ifdef CONFIG_SUIT_STREAM
104+
suit_secure_domain_component_number_t soc_component = 0;
43105
struct stream_sink dst_sink;
44106
#ifdef CONFIG_SUIT_STREAM_SOURCE_MEMPTR
45107
const uint8_t *payload_ptr;
46108
size_t payload_size;
47109
#endif /* CONFIG_SUIT_STREAM_SOURCE_MEMPTR */
48-
suit_component_type_t src_component_type = SUIT_COMPONENT_TYPE_UNSUPPORTED;
49-
suit_component_type_t dst_component_type = SUIT_COMPONENT_TYPE_UNSUPPORTED;
50110
suit_plat_err_t plat_ret = SUIT_PLAT_SUCCESS;
51111
int ret = SUIT_SUCCESS;
52112

53113
/*
54114
* Validate streaming operation.
55115
*/
56116

57-
/* Get destination component type based on component handle*/
58-
ret = suit_plat_component_type_get(dst_handle, &dst_component_type);
59-
if (ret != SUIT_SUCCESS) {
60-
LOG_ERR("Failed to decode destination component type");
61-
return ret;
62-
}
63-
64-
/* Check if destination component type is supported */
65-
if ((dst_component_type != SUIT_COMPONENT_TYPE_MEM) &&
66-
(dst_component_type != SUIT_COMPONENT_TYPE_SOC_SPEC)) {
67-
LOG_ERR("Unsupported destination component type");
117+
if (!suit_plat_copy_domain_specific_is_type_supported(dst_component_type,
118+
src_component_type)) {
119+
LOG_ERR("Unsupported component type pair: (dst: %d, src: %d)", dst_component_type,
120+
src_component_type);
68121
return SUIT_ERR_UNSUPPORTED_COMPONENT_ID;
69122
}
70123

71-
/* Get source component type based on component handle*/
72-
ret = suit_plat_component_type_get(src_handle, &src_component_type);
73-
if (ret != SUIT_SUCCESS) {
74-
LOG_ERR("Failed to decode source component type");
75-
return ret;
76-
}
77-
78-
/* Check if source component type is supported */
79-
if ((src_component_type != SUIT_COMPONENT_TYPE_MEM) &&
80-
(src_component_type != SUIT_COMPONENT_TYPE_CAND_IMG)) {
81-
LOG_ERR("Unsupported source component type");
82-
return SUIT_ERR_UNSUPPORTED_COMPONENT_ID;
124+
if (dst_component_type == SUIT_COMPONENT_TYPE_SOC_SPEC) {
125+
if (!decode_supported_soc_specific_component(dst_handle, &soc_component)) {
126+
LOG_ERR("Failed to decode SOC specific component");
127+
return SUIT_ERR_UNSUPPORTED_COMPONENT_ID;
128+
}
83129
}
84130

85131
/*
@@ -146,77 +192,41 @@ int suit_plat_check_copy(suit_component_t dst_handle, suit_component_t src_handl
146192
#endif /* CONFIG_SUIT_STREAM */
147193
}
148194

149-
int suit_plat_copy(suit_component_t dst_handle, suit_component_t src_handle,
150-
struct zcbor_string *manifest_component_id,
151-
struct suit_encryption_info *enc_info)
195+
int suit_plat_copy_domain_specific(suit_component_t dst_handle,
196+
suit_component_type_t dst_component_type,
197+
suit_component_t src_handle,
198+
suit_component_type_t src_component_type,
199+
struct zcbor_string *manifest_component_id,
200+
struct suit_encryption_info *enc_info)
152201
{
153202
#ifdef CONFIG_SUIT_STREAM
203+
suit_secure_domain_component_number_t soc_component = 0;
154204
struct stream_sink dst_sink;
155-
uint32_t soc_spec_number = 0;
156205
#ifdef CONFIG_SUIT_STREAM_SOURCE_MEMPTR
157206
const uint8_t *payload_ptr;
158207
size_t payload_size;
159208
#endif /* CONFIG_SUIT_STREAM_SOURCE_MEMPTR */
160-
suit_component_type_t src_component_type = SUIT_COMPONENT_TYPE_UNSUPPORTED;
161-
suit_component_type_t dst_component_type = SUIT_COMPONENT_TYPE_UNSUPPORTED;
162209
suit_plat_err_t plat_ret = SUIT_PLAT_SUCCESS;
163210
int ret = SUIT_SUCCESS;
164211

165212
/*
166213
* Validate streaming operation.
167214
*/
168215

169-
/* Get destination component type based on component handle*/
170-
ret = suit_plat_component_type_get(dst_handle, &dst_component_type);
171-
if (ret != SUIT_SUCCESS) {
172-
LOG_ERR("Failed to decode destination component type");
173-
return ret;
174-
}
175-
176-
/* Check if destination component type is supported */
177-
if ((dst_component_type != SUIT_COMPONENT_TYPE_MEM) &&
178-
(dst_component_type != SUIT_COMPONENT_TYPE_SOC_SPEC)) {
179-
LOG_ERR("Unsupported destination component type");
216+
if (!suit_plat_copy_domain_specific_is_type_supported(dst_component_type,
217+
src_component_type)) {
218+
LOG_ERR("Unsupported component type pair: (dst: %d, src: %d)", dst_component_type,
219+
src_component_type);
180220
return SUIT_ERR_UNSUPPORTED_COMPONENT_ID;
181221
}
182222

183223
if (dst_component_type == SUIT_COMPONENT_TYPE_SOC_SPEC) {
184-
struct zcbor_string *component_id = NULL;
185-
186-
ret = suit_plat_component_id_get(dst_handle, &component_id);
187-
if (ret != SUIT_SUCCESS) {
188-
LOG_ERR("suit_plat_component_id_get failed - error %i", ret);
189-
return ret;
190-
}
191-
192-
plat_ret = suit_plat_decode_component_number(component_id, &soc_spec_number);
193-
if (plat_ret != SUIT_PLAT_SUCCESS) {
194-
LOG_ERR("suit_plat_decode_component_number failed - error %i", plat_ret);
195-
ret = suit_plat_err_to_processor_err_convert(plat_ret);
196-
return ret;
197-
}
198-
199-
if (soc_spec_number != SUIT_SECDOM_COMPONENT_NUMBER_SDFW &&
200-
soc_spec_number != SUIT_SECDOM_COMPONENT_NUMBER_SDFW_RECOVERY) {
201-
LOG_ERR("Unsupported destination component type");
224+
if (!decode_supported_soc_specific_component(dst_handle, &soc_component)) {
225+
LOG_ERR("Failed to decode SOC specific component");
202226
return SUIT_ERR_UNSUPPORTED_COMPONENT_ID;
203227
}
204228
}
205229

206-
/* Get source component type based on component handle*/
207-
ret = suit_plat_component_type_get(src_handle, &src_component_type);
208-
if (ret != SUIT_SUCCESS) {
209-
LOG_ERR("Failed to decode source component type");
210-
return ret;
211-
}
212-
213-
/* Check if source component type is supported */
214-
if ((src_component_type != SUIT_COMPONENT_TYPE_MEM) &&
215-
(src_component_type != SUIT_COMPONENT_TYPE_CAND_IMG)) {
216-
LOG_ERR("Unsupported source component type");
217-
return SUIT_ERR_UNSUPPORTED_COMPONENT_ID;
218-
}
219-
220230
/*
221231
* Construct the stream.
222232
*/
@@ -295,8 +305,8 @@ int suit_plat_copy(suit_component_t dst_handle, suit_component_t src_handle,
295305
}
296306

297307
if (ret == SUIT_SUCCESS && dst_component_type == SUIT_COMPONENT_TYPE_SOC_SPEC &&
298-
(soc_spec_number == SUIT_SECDOM_COMPONENT_NUMBER_SDFW ||
299-
soc_spec_number == SUIT_SECDOM_COMPONENT_NUMBER_SDFW_RECOVERY)) {
308+
(soc_component == SUIT_SECDOM_COMPONENT_NUMBER_SDFW ||
309+
soc_component == SUIT_SECDOM_COMPONENT_NUMBER_SDFW_RECOVERY)) {
300310
uintptr_t sdfw_update_area_addr = 0;
301311
size_t sdfw_update_area_size = 0;
302312

0 commit comments

Comments
 (0)