Skip to content

Commit 91dd66b

Browse files
SylwesterKonczyknordicjm
authored andcommitted
suit: SDFW update over sdfw_mirror
Copy directive checks a location of SDFW/SDFW_Recovery update candidate and tries to install it using sdfw_mirror, if necessary Signed-off-by: Sylwester Konczyk <[email protected]>
1 parent 78f806d commit 91dd66b

File tree

12 files changed

+123
-2
lines changed

12 files changed

+123
-2
lines changed

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

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
#include <suit_platform_internal.h>
1313
#include <suit_plat_digest_cache.h>
1414
#include <suit_plat_memptr_size_update.h>
15+
#include <suit_memory_layout.h>
1516

1617
#if CONFIG_SUIT_IPUC
1718
#include <suit_plat_ipuc.h>
19+
#include <suit_flash_sink.h>
1820
#endif /* CONFIG_SUIT_IPUC */
1921

2022
#ifdef CONFIG_SUIT_STREAM
@@ -140,6 +142,7 @@ int suit_plat_copy(suit_component_t dst_handle, suit_component_t src_handle,
140142
{
141143
#ifdef CONFIG_SUIT_STREAM
142144
struct stream_sink dst_sink;
145+
uint32_t soc_spec_number = 0;
143146
#ifdef CONFIG_SUIT_STREAM_SOURCE_MEMPTR
144147
const uint8_t *payload_ptr;
145148
size_t payload_size;
@@ -167,6 +170,29 @@ int suit_plat_copy(suit_component_t dst_handle, suit_component_t src_handle,
167170
return SUIT_ERR_UNSUPPORTED_COMPONENT_ID;
168171
}
169172

173+
if (dst_component_type == SUIT_COMPONENT_TYPE_SOC_SPEC) {
174+
struct zcbor_string *component_id = NULL;
175+
176+
ret = suit_plat_component_id_get(dst_handle, &component_id);
177+
if (ret != SUIT_SUCCESS) {
178+
LOG_ERR("suit_plat_component_id_get failed - error %i", ret);
179+
return ret;
180+
}
181+
182+
plat_ret = suit_plat_decode_component_number(component_id, &soc_spec_number);
183+
if (plat_ret != SUIT_PLAT_SUCCESS) {
184+
LOG_ERR("suit_plat_decode_component_number failed - error %i", plat_ret);
185+
ret = suit_plat_err_to_processor_err_convert(plat_ret);
186+
return ret;
187+
}
188+
189+
if (soc_spec_number != SUIT_SECDOM_COMPONENT_NUMBER_SDFW &&
190+
soc_spec_number != SUIT_SECDOM_COMPONENT_NUMBER_SDFW_RECOVERY) {
191+
LOG_ERR("Unsupported destination component type");
192+
return SUIT_ERR_UNSUPPORTED_COMPONENT_ID;
193+
}
194+
}
195+
170196
/* Get source component type based on component handle*/
171197
ret = suit_plat_component_type_get(src_handle, &src_component_type);
172198
if (ret != SUIT_SUCCESS) {
@@ -250,6 +276,92 @@ int suit_plat_copy(suit_component_t dst_handle, suit_component_t src_handle,
250276
}
251277
}
252278

279+
if (ret == SUIT_SUCCESS && dst_component_type == SUIT_COMPONENT_TYPE_SOC_SPEC &&
280+
(soc_spec_number == SUIT_SECDOM_COMPONENT_NUMBER_SDFW ||
281+
soc_spec_number == SUIT_SECDOM_COMPONENT_NUMBER_SDFW_RECOVERY)) {
282+
uintptr_t sdfw_update_area_addr = 0;
283+
size_t sdfw_update_area_size = 0;
284+
285+
suit_memory_sdfw_update_area_info_get(&sdfw_update_area_addr,
286+
&sdfw_update_area_size);
287+
288+
if (sdfw_update_area_size > 0) {
289+
/* SoC enforces constrains on update candidate location
290+
*/
291+
if ((uintptr_t)payload_ptr < sdfw_update_area_addr ||
292+
(uintptr_t)payload_ptr + payload_size >
293+
sdfw_update_area_addr + sdfw_update_area_size) {
294+
295+
LOG_WRN("SDFW or SDFW_RECOVERY update - candidate mirror required "
296+
"(%d bytes)",
297+
payload_size);
298+
#ifdef CONFIG_SUIT_IPUC
299+
struct stream_sink mirror_sink;
300+
intptr_t mirror_addr =
301+
suit_plat_ipuc_sdfw_mirror_addr(payload_size);
302+
303+
if (mirror_addr == 0) {
304+
LOG_ERR("SDFW or SDFW_RECOVERY update - candidate mirror "
305+
"not found");
306+
ret = suit_plat_err_to_processor_err_convert(
307+
SUIT_PLAT_ERR_NOMEM);
308+
}
309+
310+
if (ret == SUIT_SUCCESS) {
311+
plat_ret = suit_flash_sink_get(
312+
&mirror_sink, (uint8_t *)mirror_addr, payload_size);
313+
if (plat_ret != SUIT_PLAT_SUCCESS) {
314+
LOG_ERR("Could not acquire SDFW or SDFW_RECOVERY "
315+
"mirror sink: %d",
316+
plat_ret);
317+
ret = suit_plat_err_to_processor_err_convert(
318+
plat_ret);
319+
}
320+
}
321+
322+
if (ret == SUIT_SUCCESS && mirror_sink.erase != NULL) {
323+
plat_ret = mirror_sink.erase(mirror_sink.ctx);
324+
if (plat_ret != SUIT_PLAT_SUCCESS) {
325+
LOG_ERR("SDFW or SDFW_RECOVERY mirror sink erase "
326+
"failed: %d",
327+
plat_ret);
328+
}
329+
}
330+
331+
if (ret == SUIT_SUCCESS) {
332+
LOG_INF("Streaming to SDFW or SDFW_RECOVERY mirror sink, "
333+
"%d bytes",
334+
payload_size);
335+
plat_ret = suit_generic_address_streamer_stream(
336+
payload_ptr, payload_size, &mirror_sink);
337+
338+
if (mirror_sink.flush != NULL) {
339+
mirror_sink.flush(mirror_sink.ctx);
340+
}
341+
342+
if (mirror_sink.release != NULL) {
343+
mirror_sink.release(mirror_sink.ctx);
344+
}
345+
346+
if (plat_ret != SUIT_PLAT_SUCCESS) {
347+
LOG_ERR("Streaming to SDFW or SDFW_RECOVERY mirror "
348+
"sink failed: %d",
349+
plat_ret);
350+
ret = suit_plat_err_to_processor_err_convert(
351+
plat_ret);
352+
}
353+
}
354+
355+
if (ret == SUIT_SUCCESS) {
356+
payload_ptr = (uint8_t *)mirror_addr;
357+
}
358+
#else
359+
ret = suit_plat_err_to_processor_err_convert(SUIT_PLAT_ERR_NOMEM);
360+
#endif
361+
}
362+
}
363+
}
364+
253365
if (ret == SUIT_SUCCESS) {
254366
ret = suit_generic_address_streamer_stream(payload_ptr, payload_size, &dst_sink);
255367
if (ret != SUIT_PLAT_SUCCESS) {

subsys/suit/platform/sdfw/src/suit_plat_ipuc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ suit_plat_err_t suit_plat_ipuc_revoke(suit_component_t handle)
183183
intptr_t slot_address = 0;
184184
size_t slot_size = 0;
185185

186-
if (suit_plat_decode_address_size(&p_entry->component_id, &slot_address, &slot_size) ==
186+
if (suit_plat_decode_address_size(&ipuc_entry->component_id, &slot_address, &slot_size) ==
187187
SUIT_PLAT_SUCCESS) {
188188
LOG_INF("Revoking IPUC, address: %p, size: %d bytes", (void *)slot_address,
189189
slot_size);

subsys/suit/utils/include/suit_plat_decode_util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <zcbor_common.h>
1111
#ifdef CONFIG_SUIT_METADATA
1212
#include <suit_metadata.h>
13-
#endif /* CONFIG_SUIT_METaDATA */
13+
#endif /* CONFIG_SUIT_METADATA */
1414
#ifdef CONFIG_SUIT_PLATFORM
1515
#include <suit_platform_internal.h>
1616
#endif /* CONFIG_SUIT_PLATFORM*/

tests/subsys/suit/cache_fetch/prj.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ CONFIG_ZTEST=y
99
CONFIG_SUIT=y
1010
CONFIG_SUIT_PROCESSOR=y
1111
CONFIG_SUIT_PLATFORM=y
12+
CONFIG_SUIT_METADATA=y
1213

1314
CONFIG_SUIT_STREAM=y
1415
CONFIG_SUIT_SINK_SELECTOR=y

tests/subsys/suit/check_content/prj.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ CONFIG_ZTEST=y
99
CONFIG_SUIT=y
1010
CONFIG_SUIT_PROCESSOR=y
1111
CONFIG_SUIT_PLATFORM=y
12+
CONFIG_SUIT_METADATA=y
1213

1314
CONFIG_SUIT_STREAM=y
1415
CONFIG_SUIT_STREAM_SINK_DIGEST=y

tests/subsys/suit/copy/prj.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ CONFIG_ZTEST=y
99
CONFIG_SUIT=y
1010
CONFIG_SUIT_PROCESSOR=y
1111
CONFIG_SUIT_PLATFORM=y
12+
CONFIG_SUIT_METADATA=y
1213

1314
CONFIG_SUIT_STREAM=y
1415
CONFIG_SUIT_SINK_SELECTOR=y

tests/subsys/suit/digest/prj.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ CONFIG_ZTEST=y
99
CONFIG_SUIT=y
1010
CONFIG_SUIT_PROCESSOR=y
1111
CONFIG_SUIT_PLATFORM=y
12+
CONFIG_SUIT_METADATA=y
1213

1314
CONFIG_SUIT_STREAM=y
1415
CONFIG_SUIT_STREAM_SINK_DIGEST=y

tests/subsys/suit/digest_sink/prj.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ CONFIG_ZTEST=y
99
CONFIG_SUIT=y
1010
CONFIG_SUIT_PROCESSOR=y
1111
CONFIG_SUIT_PLATFORM=y
12+
CONFIG_SUIT_METADATA=y
1213

1314
CONFIG_SUIT_STREAM=y
1415
CONFIG_SUIT_STREAM_SINK_DIGEST=y

tests/subsys/suit/fetch/prj.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ CONFIG_ZTEST=y
99
CONFIG_SUIT=y
1010
CONFIG_SUIT_PROCESSOR=y
1111
CONFIG_SUIT_PLATFORM=y
12+
CONFIG_SUIT_METADATA=y
1213

1314
CONFIG_SUIT_STREAM=y
1415
CONFIG_SUIT_SINK_SELECTOR=y

tests/subsys/suit/integrated_fetch/prj.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ CONFIG_ZTEST=y
99
CONFIG_SUIT=y
1010
CONFIG_SUIT_PROCESSOR=y
1111
CONFIG_SUIT_PLATFORM=y
12+
CONFIG_SUIT_METADATA=y
1213

1314
CONFIG_SUIT_STREAM=y
1415
CONFIG_SUIT_SINK_SELECTOR=y

0 commit comments

Comments
 (0)