Skip to content

Commit 53b0962

Browse files
ArekBalysNordicLuDuda
authored andcommitted
dfu: dfu_target: Align dfu_target to SUIT Cache
Aligned dfu_target to allow processing SUIT envelope and all images stored in the Cache partitions. This implementation allows writing of the SUIT manifests to dfu_partition and all following images to the defined dfu_partition_cache_x partitions. After writing manifests and images you can use dfu_target to start processing it and schedule an update. The implementation is integrated with the dfu_multi_target functionality. Added the additional DFU_TARGET_SUIT_CACHE_PROCESSING kconfig. Signed-off-by: Arkadiusz Balys <[email protected]>
1 parent c602283 commit 53b0962

File tree

5 files changed

+183
-63
lines changed

5 files changed

+183
-63
lines changed

include/dfu/dfu_target_suit.h

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023 Nordic Semiconductor ASA
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
33
*
44
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
55
*/
@@ -29,23 +29,22 @@ extern "C" {
2929
int dfu_target_suit_set_buf(uint8_t *buf, size_t len);
3030

3131
/**
32-
* @brief See if data in buf indicates SUIT style upgrade.
32+
* @brief Initialize dfu target for specific image, perform steps necessary to receive firmware.
3333
*
34-
* Not implemented as it does not currently have any use cases.
35-
* Currently always returns -ENOSYS.
36-
*
37-
* @retval -ENOSYS
38-
*/
39-
bool dfu_target_suit_identify(const void *const buf);
40-
41-
/**
42-
* @brief Initialize dfu target, perform steps necessary to receive firmware.
34+
* If you call this function, you must call dfu_target_suit_done() to finalize the firmware upgrade
35+
* before initializing any other images.
4336
*
4437
* @param[in] file_size Size of the current file being downloaded.
45-
* @param[in] img_num Image pair index.
38+
* @param[in] img_num Image index.
4639
* @param[in] cb Callback for signaling events(unused).
4740
*
48-
* @retval 0 If successful, negative errno otherwise.
41+
* @return 0 If successful
42+
* @return -ENODEV errno code if the buffer has not been initialized.
43+
* @return -ENXIO errno code if the partition dedicated for provided image is not found.
44+
* @return -ENOMEM errno code if the buffer is not large enough.
45+
* @return -EFAULT errno code if flash device assigned to the image is not available on the device.
46+
* @return -EBUSY errno code if the any image is already initialized and stream flash is in use.
47+
* @return other negative errno code if the initialization failed.
4948
*/
5049
int dfu_target_suit_init(size_t file_size, int img_num, dfu_target_callback_t cb);
5150

@@ -54,7 +53,7 @@ int dfu_target_suit_init(size_t file_size, int img_num, dfu_target_callback_t cb
5453
*
5554
* @param[out] offset Returns the offset of the firmware upgrade.
5655
*
57-
* @return 0 if success, otherwise negative value if unable to get the offset
56+
* @retval 0 if success, otherwise negative value if unable to get the offset
5857
*/
5958
int dfu_target_suit_offset_get(size_t *offset);
6059

@@ -64,7 +63,9 @@ int dfu_target_suit_offset_get(size_t *offset);
6463
* @param[in] buf Pointer to data that should be written.
6564
* @param[in] len Length of data to write.
6665
*
67-
* @return 0 on success, negative errno otherwise.
66+
* @return 0 on success
67+
* @return -EFAULT errno code if the stream flash has not been initialized for any dfu image.
68+
* @return other negative errno code if the initialization failed.
6869
*/
6970
int dfu_target_suit_write(const void *const buf, size_t len);
7071

@@ -73,21 +74,23 @@ int dfu_target_suit_write(const void *const buf, size_t len);
7374
7475
* @param[in] successful Indicate whether the firmware was successfully recived.
7576
*
76-
* @return 0 on success, negative errno otherwise.
77+
* @retval 0 on success, negative errno otherwise.
7778
*/
7879
int dfu_target_suit_done(bool successful);
7980

8081
/**
81-
* @brief Schedule update and reset the device.
82+
* @brief Schedule an update
83+
*
84+
* This call processes SUIT envelope and requests images update.
8285
*
83-
* This call requests images update and immediately starts it
84-
* by resetting the device.
86+
* Firmware update will start after the device reboot.
87+
* You can reboot device, for example, by calling dfu_target_suit_reboot().
8588
*
8689
* @param[in] img_num Given image pair index or -1 for all
8790
* of image pair indexes.
8891
*
89-
* @return 0 for a successful request or a negative error
90-
* code identicating reason of failure.
92+
* @retval 0 for a successful request or a negative error
93+
* code indicating reason of failure.
9194
**/
9295
int dfu_target_suit_schedule_update(int img_num);
9396

@@ -96,10 +99,19 @@ int dfu_target_suit_schedule_update(int img_num);
9699
*
97100
* Cancels any ongoing updates.
98101
*
99-
* @return 0 on success, negative errno otherwise.
102+
* @retval 0 on success, negative errno otherwise.
100103
*/
101104
int dfu_target_suit_reset(void);
102105

106+
/**
107+
* @brief Reboot the device, and apply new image.
108+
*
109+
* The reboot can be delayed by setting the
110+
* CONFIG_DFU_TARGET_REBOOT_RESET_DELAY_MS kconfig value.
111+
*
112+
* @retval 0 on success, negative errno otherwise.
113+
*/
114+
int dfu_target_suit_reboot(void);
103115

104116
#ifdef __cplusplus
105117
}

subsys/dfu/dfu_target/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ zephyr_library_sources_ifdef(CONFIG_DFU_TARGET_SMP
2929
zephyr_library_sources(src/dfu_stream_flatten.c)
3030
if (CONFIG_DFU_TARGET_SUIT)
3131
zephyr_library_sources(src/dfu_target_suit.c)
32+
zephyr_library_link_libraries(suit_memory_layout_interface)
33+
zephyr_library_link_libraries(suit_envelope_info)
34+
zephyr_library_link_libraries_ifdef(CONFIG_SUIT_CACHE_RW suit_cache_interface)
3235
if (CONFIG_SSF_SUIT_SERVICE_ENABLED)
3336
zephyr_library_link_libraries(suit_utils)
3437
endif()

subsys/dfu/dfu_target/Kconfig

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,42 @@ config DFU_TARGET_SUIT
117117
bool "SUIT DFU target support"
118118
default y
119119
depends on SUIT
120+
depends on SUIT_ENVELOPE_INFO
120121
imply MPU_ALLOW_FLASH_WRITE
121122
select SUIT_UTILS
122123
select ZCBOR
123124
select ZCBOR_CANONICAL
125+
select FLASH
126+
select STREAM_FLASH
124127
select DFU_TARGET_STREAM
125128
help
126129
Enable support for updates using DFU target based on SUIT
127130

131+
if DFU_TARGET_SUIT
132+
133+
config DFU_TARGET_SUIT_CACHE_PROCESSING
134+
bool "SUIT cache processing"
135+
default y
136+
depends on SUIT_CACHE_RW
137+
help
138+
Enable SUIT cache processing to process images ids bigger than 0.
139+
It allows to store the image in the cache cache partitions and
140+
assign them to be processed by the SUIT.
141+
142+
config DFU_TARGET_SUIT_INITIALIZE_SUIT
143+
bool "Initialize SUIT dfu library"
144+
help
145+
Initialize SUIT library during the system startup.
146+
147+
config DFU_TARGET_REBOOT_RESET_DELAY_MS
148+
int "Reboot reset delay in milliseconds"
149+
default 0
150+
help
151+
Set the delay in milliseconds before the device is reset after a reboot
152+
function is called.
153+
154+
endif # DFU_TARGET_SUIT
155+
128156
module=DFU_TARGET
129157
module-dep=LOG
130158
module-str=Device Firmware Upgrade

subsys/dfu/dfu_target/src/dfu_target.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ int dfu_target_init(int img_type, int img_num, size_t file_size, dfu_target_call
127127
* abort and to change the image number.
128128
*/
129129
if (new_target == current_target && img_type != DFU_TARGET_IMAGE_TYPE_MODEM_DELTA &&
130-
img_type != DFU_TARGET_IMAGE_TYPE_SMP && current_img_num == img_num) {
130+
img_type != DFU_TARGET_IMAGE_TYPE_SMP && current_img_num == img_num &&
131+
img_type != DFU_TARGET_IMAGE_TYPE_SUIT) {
131132
return 0;
132133
}
133134

0 commit comments

Comments
 (0)