|
13 | 13 | #include <suit_plat_digest_cache.h> |
14 | 14 | #include <suit_plat_memptr_size_update.h> |
15 | 15 | #include <suit_memory_layout.h> |
| 16 | +#include <suit_plat_copy_domain_specific.h> |
16 | 17 |
|
17 | 18 | #if CONFIG_SUIT_IPUC |
18 | 19 | #include <suit_plat_ipuc.h> |
|
33 | 34 | #include <suit_decrypt_filter.h> |
34 | 35 | #endif /* CONFIG_SUIT_STREAM_FILTER_DECRYPT */ |
35 | 36 |
|
36 | | -LOG_MODULE_REGISTER(suit_plat_copy, CONFIG_SUIT_LOG_LEVEL); |
| 37 | +LOG_MODULE_DECLARE(suit_plat_copy, CONFIG_SUIT_LOG_LEVEL); |
37 | 38 |
|
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) |
41 | 76 | { |
42 | 77 | #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; |
43 | 105 | struct stream_sink dst_sink; |
44 | 106 | #ifdef CONFIG_SUIT_STREAM_SOURCE_MEMPTR |
45 | 107 | const uint8_t *payload_ptr; |
46 | 108 | size_t payload_size; |
47 | 109 | #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; |
50 | 110 | suit_plat_err_t plat_ret = SUIT_PLAT_SUCCESS; |
51 | 111 | int ret = SUIT_SUCCESS; |
52 | 112 |
|
53 | 113 | /* |
54 | 114 | * Validate streaming operation. |
55 | 115 | */ |
56 | 116 |
|
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); |
68 | 121 | return SUIT_ERR_UNSUPPORTED_COMPONENT_ID; |
69 | 122 | } |
70 | 123 |
|
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 | + } |
83 | 129 | } |
84 | 130 |
|
85 | 131 | /* |
@@ -146,77 +192,41 @@ int suit_plat_check_copy(suit_component_t dst_handle, suit_component_t src_handl |
146 | 192 | #endif /* CONFIG_SUIT_STREAM */ |
147 | 193 | } |
148 | 194 |
|
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) |
152 | 201 | { |
153 | 202 | #ifdef CONFIG_SUIT_STREAM |
| 203 | + suit_secure_domain_component_number_t soc_component = 0; |
154 | 204 | struct stream_sink dst_sink; |
155 | | - uint32_t soc_spec_number = 0; |
156 | 205 | #ifdef CONFIG_SUIT_STREAM_SOURCE_MEMPTR |
157 | 206 | const uint8_t *payload_ptr; |
158 | 207 | size_t payload_size; |
159 | 208 | #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; |
162 | 209 | suit_plat_err_t plat_ret = SUIT_PLAT_SUCCESS; |
163 | 210 | int ret = SUIT_SUCCESS; |
164 | 211 |
|
165 | 212 | /* |
166 | 213 | * Validate streaming operation. |
167 | 214 | */ |
168 | 215 |
|
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); |
180 | 220 | return SUIT_ERR_UNSUPPORTED_COMPONENT_ID; |
181 | 221 | } |
182 | 222 |
|
183 | 223 | 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"); |
202 | 226 | return SUIT_ERR_UNSUPPORTED_COMPONENT_ID; |
203 | 227 | } |
204 | 228 | } |
205 | 229 |
|
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 | | - |
220 | 230 | /* |
221 | 231 | * Construct the stream. |
222 | 232 | */ |
@@ -295,8 +305,8 @@ int suit_plat_copy(suit_component_t dst_handle, suit_component_t src_handle, |
295 | 305 | } |
296 | 306 |
|
297 | 307 | 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)) { |
300 | 310 | uintptr_t sdfw_update_area_addr = 0; |
301 | 311 | size_t sdfw_update_area_size = 0; |
302 | 312 |
|
|
0 commit comments