Skip to content

Commit f995034

Browse files
committed
suit: Split fetch implementation
Split suit_plat_fetch implementation into app-specific and sdfw-specific parts. Ref: NCSDK-30809 Signed-off-by: Tomasz Chyrowicz <[email protected]>
1 parent 987b0b3 commit f995034

File tree

4 files changed

+785
-462
lines changed

4 files changed

+785
-462
lines changed

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

Lines changed: 153 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -4,109 +4,196 @@
44
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
55
*/
66

7+
#include <stdbool.h>
78
#include <zephyr/logging/log.h>
8-
#include <suit_plat_error_convert.h>
9-
#include <suit_plat_fetch_domain_specific.h>
109

11-
#ifdef CONFIG_SUIT_STREAM
10+
#include <suit_platform_internal.h>
11+
#include <suit_plat_decode_util.h>
12+
#include <suit_plat_fetch_domain_specific.h>
13+
#include <suit_plat_err.h>
14+
#include <suit_plat_error_convert.h>
1215

16+
#ifdef CONFIG_SUIT_STREAM_SINK_CACHE
1317
#include <suit_dfu_cache_sink.h>
14-
#include <suit_dfu_cache_streamer.h>
15-
#include <suit_generic_address_streamer.h>
18+
#endif /* CONFIG_SUIT_STREAM_SINK_CACHE */
1619

1720
#ifdef CONFIG_SUIT_STREAM_FETCH_SOURCE_MGR
1821
#include "suit_fetch_source_streamer.h"
1922
#endif /* CONFIG_SUIT_STREAM_FETCH_SOURCE_MGR */
20-
#ifdef CONFIG_SUIT_STREAM_SOURCE_CACHE
21-
#include <suit_dfu_cache_streamer.h>
22-
#endif /* CONFIG_SUIT_STREAM_SOURCE_CACHE */
2323

2424
LOG_MODULE_REGISTER(suit_plat_fetch_app, CONFIG_SUIT_LOG_LEVEL);
2525

26-
bool suit_plat_fetch_domain_specific_is_type_supported(suit_component_type_t component_type)
26+
#ifdef CONFIG_SUIT_STREAM_SINK_CACHE
27+
static int suit_plat_fetch_cache(suit_component_t dst_handle, struct zcbor_string *uri,
28+
struct zcbor_string *manifest_component_id,
29+
struct suit_encryption_info *enc_info, bool dry_run)
2730
{
28-
if ((component_type == SUIT_COMPONENT_TYPE_CAND_IMG) ||
29-
(component_type == SUIT_COMPONENT_TYPE_CAND_MFST) ||
30-
(component_type == SUIT_COMPONENT_TYPE_CACHE_POOL)) {
31-
return true;
31+
#ifndef CONFIG_SUIT_STREAM_FETCH_SOURCE_MGR
32+
return SUIT_ERR_UNSUPPORTED_COMMAND;
33+
#else
34+
suit_plat_err_t plat_ret = SUIT_PLAT_SUCCESS;
35+
struct stream_sink dst_sink = {0};
36+
struct zcbor_string *component_id = NULL;
37+
int ret = SUIT_SUCCESS;
38+
uint32_t number;
39+
40+
/*
41+
* Validate streaming operation.
42+
*/
43+
ret = suit_plat_component_id_get(dst_handle, &component_id);
44+
if (ret != SUIT_SUCCESS) {
45+
LOG_ERR("Failed to parse component ID from handle: %d", ret);
46+
return SUIT_ERR_UNSUPPORTED_COMPONENT_ID;
3247
}
3348

34-
return false;
49+
if (suit_plat_decode_component_number(component_id, &number) != SUIT_PLAT_SUCCESS) {
50+
LOG_ERR("Missing component id number in cache pool component");
51+
return SUIT_ERR_UNSUPPORTED_COMPONENT_ID;
52+
}
53+
54+
if (enc_info != NULL) {
55+
LOG_ERR("Decryption while streaming to cache pool is not supported");
56+
(void)manifest_component_id;
57+
return SUIT_ERR_UNSUPPORTED_PARAMETER;
58+
}
59+
60+
/*
61+
* Construct the stream.
62+
*/
63+
64+
plat_ret = suit_dfu_cache_sink_get(&dst_sink, number, uri->value, uri->len, !dry_run);
65+
if (plat_ret != SUIT_PLAT_SUCCESS) {
66+
LOG_ERR("Unable to create cache sink: %d", plat_ret);
67+
ret = suit_plat_err_to_processor_err_convert(plat_ret);
68+
}
69+
70+
if (!dry_run) {
71+
/*
72+
* Stream the data.
73+
*/
74+
75+
/* Erase the destination memory area. */
76+
if ((ret == SUIT_SUCCESS) && (dst_sink.erase != NULL)) {
77+
plat_ret = dst_sink.erase(dst_sink.ctx);
78+
if (plat_ret != SUIT_PLAT_SUCCESS) {
79+
LOG_ERR("Sink erase failed: %d", plat_ret);
80+
ret = suit_plat_err_to_processor_err_convert(plat_ret);
81+
}
82+
}
83+
84+
/* Start streaming the data. */
85+
if (ret == SUIT_SUCCESS) {
86+
plat_ret = suit_fetch_source_stream(uri->value, uri->len, &dst_sink);
87+
if (plat_ret == SUIT_PLAT_SUCCESS) {
88+
suit_dfu_cache_sink_commit(dst_sink.ctx);
89+
} else {
90+
LOG_ERR("Streaming to cache failed: %d", plat_ret);
91+
}
92+
93+
/* Failures of fetch_source streamer are treated as "unavailable payload"
94+
* failures. These are cases where suit-condition-image-match will detect
95+
* the failure, however suit-plat-fetch should return success to allow
96+
* soft failures.
97+
*/
98+
ret = SUIT_SUCCESS;
99+
}
100+
101+
if ((ret == SUIT_SUCCESS) && (dst_sink.flush != NULL)) {
102+
plat_ret = dst_sink.flush(dst_sink.ctx);
103+
if (plat_ret != SUIT_PLAT_SUCCESS) {
104+
LOG_ERR("Sink flush failed: %d", plat_ret);
105+
ret = suit_plat_err_to_processor_err_convert(plat_ret);
106+
}
107+
}
108+
}
109+
110+
/*
111+
* Destroy the stream.
112+
*/
113+
114+
plat_ret = release_sink(&dst_sink);
115+
if (plat_ret != SUIT_PLAT_SUCCESS) {
116+
LOG_ERR("Sink release failed: %d", plat_ret);
117+
}
118+
119+
if (ret == SUIT_SUCCESS) {
120+
ret = suit_plat_err_to_processor_err_convert(plat_ret);
121+
}
122+
123+
return ret;
124+
#endif /* CONFIG_SUIT_STREAM_FETCH_SOURCE_MGR */
35125
}
126+
#endif /* CONFIG_SUIT_STREAM_SINK_CACHE */
36127

37-
bool suit_plat_fetch_integrated_domain_specific_is_type_supported(
38-
suit_component_type_t component_type)
128+
bool suit_plat_fetch_domain_specific_is_type_supported(suit_component_type_t dst_component_type)
39129
{
40-
if ((component_type == SUIT_COMPONENT_TYPE_CAND_IMG) ||
41-
(component_type == SUIT_COMPONENT_TYPE_CAND_MFST)) {
130+
#ifdef CONFIG_SUIT_STREAM_SINK_CACHE
131+
if (dst_component_type == SUIT_COMPONENT_TYPE_CACHE_POOL) {
42132
return true;
43133
}
134+
#endif /* CONFIG_SUIT_STREAM_SINK_CACHE */
44135

45136
return false;
46137
}
47138

139+
int suit_plat_check_fetch_domain_specific(suit_component_t dst_handle,
140+
suit_component_type_t dst_component_type,
141+
struct zcbor_string *uri,
142+
struct zcbor_string *manifest_component_id,
143+
struct suit_encryption_info *enc_info)
144+
{
145+
switch (dst_component_type) {
146+
#ifdef CONFIG_SUIT_STREAM_SINK_CACHE
147+
case SUIT_COMPONENT_TYPE_CACHE_POOL:
148+
return suit_plat_fetch_cache(dst_handle, uri, manifest_component_id, enc_info,
149+
true);
150+
#endif /* CONFIG_SUIT_STREAM_SINK_CACHE */
151+
default:
152+
break;
153+
}
154+
155+
return SUIT_ERR_UNSUPPORTED_COMPONENT_ID;
156+
}
157+
48158
int suit_plat_fetch_domain_specific(suit_component_t dst_handle,
49159
suit_component_type_t dst_component_type,
50-
struct stream_sink *dst_sink, struct zcbor_string *uri)
160+
struct zcbor_string *uri,
161+
struct zcbor_string *manifest_component_id,
162+
struct suit_encryption_info *enc_info)
51163
{
52-
int ret = SUIT_SUCCESS;
53-
bool hard_failure = false;
54-
55-
/* Select streamer */
56164
switch (dst_component_type) {
57-
#ifdef CONFIG_SUIT_STREAM_FETCH_SOURCE_MGR
165+
#ifdef CONFIG_SUIT_STREAM_SINK_CACHE
58166
case SUIT_COMPONENT_TYPE_CACHE_POOL:
59-
case SUIT_COMPONENT_TYPE_MEM: {
60-
ret = suit_fetch_source_stream(uri->value, uri->len, dst_sink);
61-
ret = suit_plat_err_to_processor_err_convert(ret);
62-
} break;
63-
#endif /* SUIT_STREAM_FETCH_SOURCE_MGR */
64-
#if defined(CONFIG_SUIT_CACHE_RW) || defined(SUIT_CACHE)
65-
case SUIT_COMPONENT_TYPE_CAND_MFST:
66-
case SUIT_COMPONENT_TYPE_CAND_IMG: {
67-
ret = suit_dfu_cache_streamer_stream(uri->value, uri->len, dst_sink);
68-
ret = suit_plat_err_to_processor_err_convert(ret);
69-
} break;
70-
#endif
167+
return suit_plat_fetch_cache(dst_handle, uri, manifest_component_id, enc_info,
168+
false);
169+
#endif /* CONFIG_SUIT_STREAM_SINK_CACHE */
71170
default:
72-
ret = SUIT_ERR_UNSUPPORTED_COMPONENT_ID;
73-
hard_failure = true;
74171
break;
75172
}
76173

77-
if (ret == SUIT_SUCCESS && dst_component_type == SUIT_COMPONENT_TYPE_CACHE_POOL) {
78-
suit_dfu_cache_sink_commit(dst_sink->ctx);
79-
}
174+
return SUIT_ERR_UNSUPPORTED_COMPONENT_ID;
175+
}
80176

81-
if (!hard_failure) {
82-
/* Failures without hard_failure flag set are treated as "unavailable payload"
83-
* failures. These are cases where suit-condition-image-match will detect
84-
* the failure, however suit-plat-fetch should return success to allow
85-
* soft failures.
86-
*/
87-
ret = SUIT_SUCCESS;
88-
}
177+
bool suit_plat_fetch_integrated_domain_specific_is_type_supported(
178+
suit_component_type_t component_type)
179+
{
180+
return false;
181+
}
89182

90-
return ret;
183+
int suit_plat_check_fetch_integrated_domain_specific(suit_component_t dst_handle,
184+
suit_component_type_t dst_component_type,
185+
struct zcbor_string *payload,
186+
struct zcbor_string *manifest_component_id,
187+
struct suit_encryption_info *enc_info)
188+
{
189+
return SUIT_ERR_UNSUPPORTED_COMMAND;
91190
}
92191

93192
int suit_plat_fetch_integrated_domain_specific(suit_component_t dst_handle,
94193
suit_component_type_t dst_component_type,
95-
struct stream_sink *dst_sink,
96-
struct zcbor_string *payload)
194+
struct zcbor_string *payload,
195+
struct zcbor_string *manifest_component_id,
196+
struct suit_encryption_info *enc_info)
97197
{
98-
suit_plat_err_t ret = SUIT_PLAT_SUCCESS;
99-
100-
(void)dst_handle;
101-
(void)dst_component_type;
102-
103-
if (payload == NULL) {
104-
return SUIT_ERR_UNAVAILABLE_PAYLOAD;
105-
}
106-
107-
ret = suit_generic_address_streamer_stream(payload->value, payload->len, dst_sink);
108-
109-
return suit_plat_err_to_processor_err_convert(ret);
198+
return SUIT_ERR_UNSUPPORTED_COMMAND;
110199
}
111-
112-
#endif /* CONFIG_SUIT_STREAM */

subsys/suit/platform/include/suit_plat_fetch_domain_specific.h

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
#include <stdint.h>
1111
#include <suit_types.h>
1212
#include <suit_platform_internal.h>
13-
#ifdef CONFIG_SUIT_STREAM
14-
#include <suit_sink.h>
1513

1614
#ifdef __cplusplus
1715
extern "C" {
@@ -28,24 +26,44 @@ bool suit_plat_fetch_domain_specific_is_type_supported(suit_component_type_t com
2826
bool suit_plat_fetch_integrated_domain_specific_is_type_supported(
2927
suit_component_type_t component_type);
3028

29+
/**
30+
* @brief Domain specific part of the core part of the suit_plat_fetch function.
31+
*/
32+
int suit_plat_check_fetch_domain_specific(suit_component_t dst_handle,
33+
suit_component_type_t dst_component_type,
34+
struct zcbor_string *uri,
35+
struct zcbor_string *manifest_component_id,
36+
struct suit_encryption_info *enc_info);
37+
3138
/**
3239
* @brief Domain specific part of the core part of the suit_plat_fetch function.
3340
*/
3441
int suit_plat_fetch_domain_specific(suit_component_t dst_handle,
3542
suit_component_type_t dst_component_type,
36-
struct stream_sink *dst_sink, struct zcbor_string *uri);
43+
struct zcbor_string *uri,
44+
struct zcbor_string *manifest_component_id,
45+
struct suit_encryption_info *enc_info);
46+
47+
/**
48+
* @brief Domain specific part of the core part of the suit_plat_fetch_integrated function
49+
*/
50+
int suit_plat_check_fetch_integrated_domain_specific(suit_component_t dst_handle,
51+
suit_component_type_t dst_component_type,
52+
struct zcbor_string *payload,
53+
struct zcbor_string *manifest_component_id,
54+
struct suit_encryption_info *enc_info);
3755

3856
/**
3957
* @brief Domain specific part of the core part of the suit_plat_fetch_integrated function
4058
*/
4159
int suit_plat_fetch_integrated_domain_specific(suit_component_t dst_handle,
4260
suit_component_type_t dst_component_type,
43-
struct stream_sink *dst_sink,
44-
struct zcbor_string *payload);
61+
struct zcbor_string *payload,
62+
struct zcbor_string *manifest_component_id,
63+
struct suit_encryption_info *enc_info);
4564

4665
#ifdef __cplusplus
4766
}
4867
#endif
4968

50-
#endif /* CONFIG_SUIT_STREAM */
5169
#endif /* SUIT_PLAT_FETCH_DOMAIN_SPECIFIC_H__ */

0 commit comments

Comments
 (0)