Skip to content

Commit f377b05

Browse files
committed
suit: Do not erase on IPUC write setup
Erasing of the IPUC took about 500ms of time, which led to many issues. The erasing was removed, instead different security measures were introduced, erasing parts when the seek offset is greater than the write peek offset. Signed-off-by: Artur Hadasz <artur.hadasz@nordicsemi.no>
1 parent 73c2240 commit f377b05

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

subsys/suit/ipuc/src/suit_ipuc_sdfw.c

+16-9
Original file line numberDiff line numberDiff line change
@@ -297,15 +297,6 @@ suit_plat_err_t suit_ipuc_sdfw_write_setup(int ipc_client_id, struct zcbor_strin
297297
suit_plat_digest_cache_remove(component_id);
298298
#endif /* CONFIG_SUIT_DIGEST_CACHE */
299299

300-
if (ipuc_sink.erase == NULL ||
301-
ipuc_sink.erase(ipuc_sink.ctx) != SUIT_PLAT_SUCCESS) {
302-
LOG_ERR("Erase operation not supported or failed");
303-
if (ipuc_sink.release) {
304-
ipuc_sink.release(ipuc_sink.ctx);
305-
}
306-
k_mutex_unlock(&ipuc_mutex);
307-
return SUIT_PLAT_ERR_IO;
308-
}
309300

310301
if (ipuc_sink.release) {
311302
ipuc_sink.release(ipuc_sink.ctx);
@@ -371,6 +362,22 @@ suit_plat_err_t suit_ipuc_sdfw_write(int ipc_client_id, struct zcbor_string *com
371362
return SUIT_PLAT_ERR_IO;
372363
}
373364

365+
if ((ipuc_sink.write != NULL) && (ipuc_sink.seek != NULL)
366+
&& (offset > ipuc_entry->write_peek_offset)) {
367+
/* Erasing if necessary
368+
*/
369+
uint8_t erase_buffer[READ_CHUNK_MAX_SIZE] = {
370+
[0 ... READ_CHUNK_MAX_SIZE - 1] = 0xFF
371+
};
372+
373+
ipuc_sink.seek(ipuc_sink.ctx, ipuc_entry->write_peek_offset);
374+
for (size_t off = ipuc_entry->write_peek_offset; off < offset;
375+
off += READ_CHUNK_MAX_SIZE) {
376+
ipuc_sink.write(ipuc_sink.ctx, (uint8_t *)erase_buffer,
377+
MIN(sizeof(erase_buffer), slot_size - off));
378+
}
379+
}
380+
374381
if (ipuc_sink.seek == NULL ||
375382
ipuc_sink.seek(ipuc_sink.ctx, offset) != SUIT_PLAT_SUCCESS) {
376383
LOG_ERR("Seek operation not supported or failed");

0 commit comments

Comments
 (0)