From 3e87c70fa260a755ab553d5e3905c4834f3e5cc6 Mon Sep 17 00:00:00 2001 From: David Garske Date: Tue, 8 Oct 2024 12:33:29 -0700 Subject: [PATCH] Fix issue with network core update when not a multiple of 4 bytes. The QSPI driver requires READ.CNT to be a multiple of 4 bytes (so read a bit more if odd remainder). --- hal/nrf5340.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/hal/nrf5340.c b/hal/nrf5340.c index 9510dcb7..cd76dddb 100644 --- a/hal/nrf5340.c +++ b/hal/nrf5340.c @@ -595,15 +595,17 @@ static void hal_net_check_version(void) wolfBoot_verify_authenticity(&img) == 0) { wolfBoot_printf("Network image valid, loading into shared mem\n"); - /* initialize remainder of shared memory with 0xFF (erased) */ - memset(shm->data + shm->core.app.size, FLASH_BYTE_ERASED, - sizeof(shm->data) - shm->core.app.size); /* relocate image to shared ram */ #ifdef EXT_FLASH - ret = ext_flash_read(PART_NET_ADDR, shm->data, shm->core.app.size); + /* must be multiple of 4 (READ.CNT length must be multiple of 4) */ + ret = ext_flash_read(PART_NET_ADDR, shm->data, + (shm->core.app.size + 3) & ~3); #else memcpy(shm->data, img.hdr, shm->core.app.size); #endif + /* initialize remainder of shared memory with 0xFF (erased) */ + memset(shm->data + shm->core.app.size, FLASH_BYTE_ERASED, + sizeof(shm->data) - shm->core.app.size); if (ret >= 0) { doUpdateNet = 1;