|
4 | 4 | * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause |
5 | 5 | */ |
6 | 6 |
|
| 7 | +#include <stdbool.h> |
7 | 8 | #include <zephyr/logging/log.h> |
8 | | -#include <suit_plat_error_convert.h> |
9 | | -#include <suit_plat_fetch_domain_specific.h> |
10 | 9 |
|
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> |
12 | 15 |
|
| 16 | +#ifdef CONFIG_SUIT_STREAM_SINK_CACHE |
13 | 17 | #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 */ |
16 | 19 |
|
17 | 20 | #ifdef CONFIG_SUIT_STREAM_FETCH_SOURCE_MGR |
18 | 21 | #include "suit_fetch_source_streamer.h" |
19 | 22 | #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 */ |
23 | 23 |
|
24 | 24 | LOG_MODULE_REGISTER(suit_plat_fetch_app, CONFIG_SUIT_LOG_LEVEL); |
25 | 25 |
|
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) |
27 | 30 | { |
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; |
32 | 47 | } |
33 | 48 |
|
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 */ |
35 | 125 | } |
| 126 | +#endif /* CONFIG_SUIT_STREAM_SINK_CACHE */ |
36 | 127 |
|
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) |
39 | 129 | { |
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) { |
42 | 132 | return true; |
43 | 133 | } |
| 134 | +#endif /* CONFIG_SUIT_STREAM_SINK_CACHE */ |
44 | 135 |
|
45 | 136 | return false; |
46 | 137 | } |
47 | 138 |
|
| 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 | + |
48 | 158 | int suit_plat_fetch_domain_specific(suit_component_t dst_handle, |
49 | 159 | 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) |
51 | 163 | { |
52 | | - int ret = SUIT_SUCCESS; |
53 | | - bool hard_failure = false; |
54 | | - |
55 | | - /* Select streamer */ |
56 | 164 | switch (dst_component_type) { |
57 | | -#ifdef CONFIG_SUIT_STREAM_FETCH_SOURCE_MGR |
| 165 | +#ifdef CONFIG_SUIT_STREAM_SINK_CACHE |
58 | 166 | 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 */ |
71 | 170 | default: |
72 | | - ret = SUIT_ERR_UNSUPPORTED_COMPONENT_ID; |
73 | | - hard_failure = true; |
74 | 171 | break; |
75 | 172 | } |
76 | 173 |
|
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 | +} |
80 | 176 |
|
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 | +} |
89 | 182 |
|
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; |
91 | 190 | } |
92 | 191 |
|
93 | 192 | int suit_plat_fetch_integrated_domain_specific(suit_component_t dst_handle, |
94 | 193 | 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) |
97 | 197 | { |
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; |
110 | 199 | } |
111 | | - |
112 | | -#endif /* CONFIG_SUIT_STREAM */ |
|
0 commit comments