1515#endif
1616#include <dfu/suit_dfu.h>
1717
18+ #ifdef CONFIG_FLASH_IPUC
19+ #include <drivers/flash/flash_ipuc.h>
20+ #endif /* CONFIG_FLASH_IPUC */
21+
1822LOG_MODULE_REGISTER (dfu_target_suit , CONFIG_DFU_TARGET_LOG_LEVEL );
1923
2024#define IS_ALIGNED_32 (POINTER ) (((uintptr_t)(const void *)(POINTER)) % 4 == 0)
@@ -59,19 +63,40 @@ int dfu_target_suit_init(size_t file_size, int img_num, dfu_target_callback_t cb
5963 return - ENODEV ;
6064 }
6165
66+ device_info .fdev = NULL ;
6267 if (ENVELOPE_IMAGE_NUMBER == img_num ) {
6368 /* Get info about dfu_partition to store the envelope */
6469 err = suit_dfu_partition_device_info_get (& device_info );
6570 } else {
71+ #ifdef CONFIG_FLASH_IPUC
72+ device_info .partition_offset = 0 ;
73+ device_info .erase_block_size = 1 ;
74+ device_info .write_block_size = 1 ;
75+ device_info .fdev = flash_image_ipuc_create (img_num , NULL , NULL ,
76+ (uintptr_t * )& device_info .mapped_address ,
77+ & device_info .partition_size );
78+ if (device_info .fdev != NULL ) {
79+ LOG_INF ("Found IPUC for image %d (0x%lx, 0x%x)" , img_num ,
80+ (uintptr_t )device_info .mapped_address , device_info .partition_size );
81+ }
82+ #endif /* CONFIG_FLASH_IPUC */
6683#ifdef CONFIG_DFU_TARGET_SUIT_CACHE_PROCESSING
6784 /* Cache partitions ids starts from 0, whereas image number 0 is reserved for
6885 * dfu_partition. Decrease img_num value by 1 to reach the correct DFU cache
6986 * partition id.
7087 */
71- err = suit_dfu_cache_rw_device_info_get (img_num - 1 , & device_info );
72- #else
73- return - ENOTSUP ;
74- #endif
88+ if (device_info .fdev == NULL ) {
89+ err = suit_dfu_cache_rw_device_info_get (img_num - 1 , & device_info );
90+ if (device_info .fdev != NULL ) {
91+ LOG_INF ("Found cache pool %d (0x%lx, 0x%x)" , img_num - 1 ,
92+ (uintptr_t )device_info .mapped_address ,
93+ device_info .partition_size );
94+ }
95+ }
96+ #endif /* CONFIG_DFU_TARGET_SUIT_CACHE_PROCESSING */
97+ if (device_info .fdev == NULL ) {
98+ return - ENOTSUP ;
99+ }
75100 }
76101
77102 if (err != SUIT_PLAT_SUCCESS ) {
@@ -140,6 +165,9 @@ int dfu_target_suit_write(const void *const buf, size_t len)
140165
141166int dfu_target_suit_done (bool successful )
142167{
168+ #ifdef CONFIG_FLASH_IPUC
169+ struct stream_flash_ctx * stream = dfu_target_stream_get_stream ();
170+ #endif /* CONFIG_FLASH_IPUC */
143171 stream_flash_in_use = false;
144172
145173 int err = dfu_target_stream_done (successful );
@@ -156,6 +184,11 @@ int dfu_target_suit_done(bool successful)
156184 LOG_ERR ("suit_dfu_candidate_envelope_stored error %d" , err );
157185 return err ;
158186 }
187+ #ifdef CONFIG_FLASH_IPUC
188+ } else {
189+ flash_image_ipuc_release (image_num );
190+ stream -> fdev = NULL ;
191+ #endif /* CONFIG_FLASH_IPUC */
159192 }
160193
161194 if (successful ) {
@@ -187,6 +220,9 @@ int dfu_target_suit_schedule_update(int img_num)
187220
188221int dfu_target_suit_reset (void )
189222{
223+ #ifdef CONFIG_FLASH_IPUC
224+ struct stream_flash_ctx * stream = dfu_target_stream_get_stream ();
225+ #endif /* CONFIG_FLASH_IPUC */
190226 int rc = dfu_target_stream_reset ();
191227
192228 if (rc != 0 ) {
@@ -196,6 +232,11 @@ int dfu_target_suit_reset(void)
196232
197233 int err = suit_dfu_cleanup ();
198234
235+ #ifdef CONFIG_FLASH_IPUC
236+ flash_image_ipuc_release (image_num );
237+ stream -> fdev = NULL ;
238+ #endif /* CONFIG_FLASH_IPUC */
239+
199240 stream_flash_in_use = false;
200241 stream_buf_bytes = 0 ;
201242 image_num = 0 ;
0 commit comments