Skip to content

Commit af600c4

Browse files
SylwesterKonczykrlubos
authored andcommitted
suit: Cleanup on DFU partitions
Cleanup on DFU and DFU cache partitions as part of SUIT initialization Signed-off-by: Sylwester Konczyk <[email protected]>
1 parent 8d881cd commit af600c4

File tree

4 files changed

+53
-4
lines changed

4 files changed

+53
-4
lines changed

subsys/suit/envelope_info/include/suit_envelope_info.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ suit_plat_err_t suit_dfu_partition_envelope_info_get(const uint8_t **address, si
3333
*/
3434
suit_plat_err_t suit_dfu_partition_device_info_get(struct suit_nvm_device_info *device_info);
3535

36+
/**
37+
* @brief Chcecks if dfu partition is empty.
38+
*
39+
* @return true if empty, false otherwise
40+
*/
41+
bool suit_dfu_partition_is_empty(void);
42+
3643
#ifdef __cplusplus
3744
}
3845
#endif

subsys/suit/envelope_info/src/suit_envelope_info.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ suit_plat_err_t suit_dfu_partition_envelope_info_get(const uint8_t **address, si
4848
uintptr_t mapped_address = 0;
4949

5050
if (!suit_memory_nvm_address_to_global_address(&device_offset, &mapped_address)) {
51-
LOG_ERR("Cannot obtain memory-mapped DFU Partition address");
51+
LOG_ERR("Cannot obtain memory-mapped DFU partition address");
5252
return SUIT_PLAT_ERR_IO;
5353
}
5454

5555
const uint8_t *envelope_address = (uint8_t *)mapped_address;
5656
size_t envelope_size = DFU_PARTITION_SIZE;
5757

5858
if (*((uint32_t *)envelope_address) == EMPTY_STORAGE_VALUE) {
59-
LOG_DBG("DFU Partition empty");
59+
LOG_DBG("DFU partition empty");
6060
return SUIT_PLAT_ERR_NOT_FOUND;
6161
}
6262

@@ -108,3 +108,26 @@ suit_plat_err_t suit_dfu_partition_device_info_get(struct suit_nvm_device_info *
108108

109109
return SUIT_PLAT_SUCCESS;
110110
}
111+
112+
bool suit_dfu_partition_is_empty(void)
113+
{
114+
struct nvm_address device_offset = {
115+
.fdev = DFU_PARTITION_DEVICE,
116+
.offset = DFU_PARTITION_OFFSET,
117+
};
118+
119+
uintptr_t mapped_address = 0;
120+
121+
if (!suit_memory_nvm_address_to_global_address(&device_offset, &mapped_address)) {
122+
LOG_ERR("Cannot obtain memory-mapped DFU partition address");
123+
return false;
124+
}
125+
126+
for (size_t i = 0; i < DFU_PARTITION_SIZE / sizeof(uint32_t); i++) {
127+
if (*(((uint32_t *)mapped_address) + i) != EMPTY_STORAGE_VALUE) {
128+
return false;
129+
}
130+
}
131+
132+
return true;
133+
}

subsys/suit/orchestrator_app/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,9 @@ config SUIT_ORCHESTRATOR_APP_CANDIDATE_PROCESSING
1414
bool "Enable processing of the candidate envelope by the SUIT application orchestrator"
1515
depends on SUIT_ENVELOPE_INFO
1616

17+
config SUIT_CLEANUP_ON_INIT
18+
bool "Performs cleanup on DFU and DFU cache partitions as part of initialization"
19+
depends on SUIT_ORCHESTRATOR_APP_CANDIDATE_PROCESSING
20+
default y
21+
1722
endif # SUIT_ORCHESTRATOR_APP

subsys/suit/orchestrator_app/src/suit_orchestrator_app.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ LOG_MODULE_REGISTER(suit_dfu, CONFIG_SUIT_LOG_LEVEL);
3434

3535
static int dfu_partition_erase(void)
3636
{
37+
38+
if (suit_dfu_partition_is_empty()) {
39+
LOG_DBG("DFU partition is arleady erased");
40+
return 0;
41+
}
42+
3743
struct suit_nvm_device_info device_info;
3844
int err = suit_dfu_partition_device_info_get(&device_info);
3945

@@ -45,6 +51,7 @@ static int dfu_partition_erase(void)
4551
return -ENODEV;
4652
}
4753

54+
LOG_DBG("Erasing DFU partition");
4855
int rc = flash_erase(device_info.fdev, device_info.partition_offset,
4956
device_info.partition_size);
5057
if (rc < 0) {
@@ -61,8 +68,6 @@ int suit_dfu_initialize(void)
6168
LOG_DBG("Enter");
6269

6370
struct suit_nvm_device_info device_info;
64-
const uint8_t *uc_env_addr = NULL;
65-
size_t uc_env_size = 0;
6671
int err = suit_dfu_partition_device_info_get(&device_info);
6772

6873
if (err != SUIT_PLAT_SUCCESS) {
@@ -73,6 +78,13 @@ int suit_dfu_initialize(void)
7378
LOG_INF("DFU partition detected, addr: %p, size %d bytes",
7479
(void *)device_info.mapped_address, device_info.partition_size);
7580

81+
#if CONFIG_SUIT_CLEANUP_ON_INIT
82+
suit_dfu_cleanup();
83+
84+
#else /* CONFIG_SUIT_CLEANUP_ON_INIT */
85+
const uint8_t *uc_env_addr = NULL;
86+
size_t uc_env_size = 0;
87+
7688
err = suit_dfu_partition_envelope_info_get(&uc_env_addr, &uc_env_size);
7789
if (err == SUIT_PLAT_SUCCESS) {
7890
LOG_INF("Update candidate envelope detected, addr: %p, size %d bytes",
@@ -83,6 +95,8 @@ int suit_dfu_initialize(void)
8395
suit_dfu_cache_validate_content();
8496
#endif /* CONFIG_SUIT_CACHE_RW */
8597

98+
#endif /* CONFIG_SUIT_CLEANUP_ON_INIT */
99+
86100
#if CONFIG_SUIT_STREAM_IPC_PROVIDER
87101
suit_ipc_streamer_provider_init();
88102
#endif

0 commit comments

Comments
 (0)