Skip to content

Commit 6482d01

Browse files
ahasztagtomchy
authored andcommitted
suit: Workaround for IPUC caches search before initialization
The IPUC cache was being searched for URI-s before it has been initialized (before the first pull into the IPUC). This led to issues - if only some images were already fetched and the update was interrupted, the suit-processor would detect they are already present in the cache. However, when pulling the first missing image, the IPUC cache with the detected images was erased leading to update failure. Signed-off-by: Artur Hadasz <[email protected]>
1 parent a5db2e6 commit 6482d01

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

subsys/suit/cache/src/suit_dfu_cache_helpers.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,34 @@
1515
#include "suit_ram_sink.h"
1616
#include "zcbor_noncanonical_decode.h"
1717

18+
#ifdef CONFIG_FLASH_IPUC
19+
#include <drivers/flash/flash_ipuc.h>
20+
#endif /* CONFIG_FLASH_IPUC */
21+
1822
LOG_MODULE_REGISTER(dfu_cache_helpers, CONFIG_SUIT_LOG_LEVEL);
1923

24+
#ifdef CONFIG_FLASH_IPUC
25+
/* This function returns true if the given cache pool is an IPUC-based cache
26+
* but is not initialized yet.
27+
*/
28+
static bool is_cache_ipuc_uninitialized(struct dfu_cache_pool *cache_pool)
29+
{
30+
uintptr_t ipuc_address;
31+
size_t ipuc_size;
32+
bool ipuc_possible =
33+
flash_cache_ipuc_check((uintptr_t)cache_pool->address, &ipuc_address, &ipuc_size);
34+
35+
if (ipuc_possible) {
36+
if (flash_ipuc_find((uintptr_t)cache_pool->address, cache_pool->size, &ipuc_address,
37+
&ipuc_size) == NULL) {
38+
return true;
39+
}
40+
}
41+
42+
return false;
43+
}
44+
#endif /* CONFIG_FLASH_IPUC */
45+
2046
suit_plat_err_t suit_dfu_cache_partition_slot_foreach(struct dfu_cache_pool *cache_pool,
2147
partition_slot_foreach_cb cb, void *ctx)
2248
{
@@ -49,6 +75,12 @@ suit_plat_err_t suit_dfu_cache_partition_slot_foreach(struct dfu_cache_pool *cac
4975
break;
5076
}
5177

78+
#ifdef CONFIG_FLASH_IPUC
79+
if (is_cache_ipuc_uninitialized(cache_pool)) {
80+
return SUIT_PLAT_ERR_CBOR_DECODING;
81+
}
82+
#endif /* CONFIG_FLASH_IPUC */
83+
5284
err = suit_dfu_cache_memcpy(partition_header_storage, current_address, read_size);
5385

5486
if (err != SUIT_PLAT_SUCCESS) {
@@ -168,6 +200,12 @@ suit_plat_err_t suit_dfu_cache_partition_is_empty(struct dfu_cache_pool *cache_p
168200
const size_t chunk_size = sizeof(buffer);
169201
suit_plat_err_t ret = SUIT_PLAT_SUCCESS;
170202

203+
#ifdef CONFIG_FLASH_IPUC
204+
if (is_cache_ipuc_uninitialized(cache_pool)) {
205+
return SUIT_PLAT_SUCCESS;
206+
}
207+
#endif /* CONFIG_FLASH_IPUC */
208+
171209
while (remaining > 0) {
172210
size_t read_size = MIN(chunk_size, remaining);
173211

0 commit comments

Comments
 (0)