Skip to content

Commit e3b98f1

Browse files
dgarskedanielinux
authored andcommitted
Fixes for properly functioning network core updates.
1 parent 8a9fbe5 commit e3b98f1

5 files changed

Lines changed: 82 additions & 53 deletions

File tree

docs/Targets.md

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2202,18 +2202,33 @@ QSPI Freq=24MHz (Div Clk=3/Sck=1), Addr=24-bits, PageSz=256
22022202
QSPI Activate
22032203
QSPI Flash ID (ret 0): 0xC2 0x28 0x17
22042204
Status Reg: Ret 0, 0x40 (Quad Enabled: Yes)
2205-
QSPI Flash Read: Ret 0, Cmd 0xEB, Len 4 , 0xEDFFC -> 0x2000022C
2206-
QSPI Flash Read: Ret 0, Cmd 0xEB, Len 4 , 0xEDFFC -> 0x2000022C
2207-
Boot partition: 0xC000 (size 7428, version 0x1)
2208-
QSPI Flash Read: Ret 0, Cmd 0xEB, Len 256 , 0x0 -> 0x20000128
2209-
Update partition: 0x0 (size 7428, version 0x2)
2210-
QSPI Flash Read: Ret 0, Cmd 0xEB, Len 4 , 0xEDFFC -> 0x2000022C
2211-
Boot partition: 0xC000 (size 7428, version 0x1)
2205+
QSPI Flash Read: Ret 0, Cmd 0xEB, Len 256 , 0x0 -> 0x2000012C
2206+
Update partition: 0x0 (sz 7864, ver 0x2, type 0x201)
2207+
QSPI Flash Read: Ret 0, Cmd 0xEB, Len 256 , 0x100000 -> 0x2000012C
2208+
Update partition: 0x100000 (sz 5780, ver 0x2, type 0x202)
2209+
Network Image: Ver 0x2, Size 5780
2210+
Network Core: Holding for update
2211+
Status: App 1 (ver 2), Net 1 (ver 1)
2212+
QSPI Flash ID (ret 0): 0xC2 0x28 0x17
2213+
Status Reg: Ret 0, 0x40 (Quad Enabled: Yes)
2214+
QSPI Flash Read: Ret 0, Cmd 0xEB, Len 4 , 0xEDFFC -> 0x20000230
2215+
QSPI Flash Read: Ret 0, Cmd 0xEB, Len 4 , 0xEDFFC -> 0x20000230
2216+
Boot partition: 0xC000 (sz 7864, ver 0x1, type 0x201)
2217+
QSPI Flash Read: Ret 0, Cmd 0xEB, Len 256 , 0x0 -> 0x2000012C
2218+
Update partition: 0x0 (sz 7864, ver 0x2, type 0x201)
2219+
QSPI Flash Read: Ret 0, Cmd 0xEB, Len 4 , 0xEDFFC -> 0x20000230
2220+
Boot partition: 0xC000 (sz 7864, ver 0x1, type 0x201)
22122221
Booting version: 0x1
2213-
QSPI Flash Read: Ret 0, Cmd 0xEB, Len 256 , 0x100000 -> 0x20000128
2214-
Update partition: 0x100000 (size 5492, version 0x2)
2215-
QSPI Flash Read: Ret 0, Cmd 0xEB, Len 256 , 0x0 -> 0x20000230
2216-
Network version: 0x2
2222+
QSPI Flash Read: Ret 0, Cmd 0xEB, Len 256 , 0x0 -> 0x2000012C
2223+
Update partition: 0x0 (sz 7864, ver 0x2, type 0x201)
2224+
QSPI Flash Read: Ret 0, Cmd 0xEB, Len 256 , 0x100000 -> 0x2000012C
2225+
Update partition: 0x100000 (sz 5780, ver 0x2, type 0x202)
2226+
Network Image: Ver 0x2, Size 5780
2227+
Found Network Core update: Ver 1->2, Size 6036->6036
2228+
QSPI Flash Read: Ret 0, Cmd 0xEB, Len 256 , 0x101700 -> 0x2000002C
2229+
Network image valid, loading into shared mem
2230+
QSPI Flash Read: Ret 0, Cmd 0xEB, Len 6036 , 0x100000 -> 0x20010020
2231+
Network core firmware update done
22172232
========================
22182233
nRF5340 wolfBoot (app core)
22192234
Copyright 2024 wolfSSL Inc
@@ -2228,15 +2243,25 @@ Network Core:
22282243
22292244
```
22302245
wolfBoot HAL Init (net core)
2231-
Boot partition: 0x100C000 (size 5492, version 0x1)
2232-
Update partition: 0x100C000 (size 5492, version 0x1)
2233-
Boot partition: 0x100C000 (size 5492, version 0x1)
2234-
Booting version: 0x1
2246+
Boot partition: 0x100C000 (sz 5780, ver 0x1, type 0x201)
2247+
Network Image: Ver 0x1, Size 5780
2248+
Starting update: Ver 1->2, Size 6036->6036
2249+
Internal Flash Erase: addr 0x100C000, len 6036
2250+
Internal Flash Erase: page 0x100C000
2251+
Internal Flash Erase: page 0x100C800
2252+
Internal Flash Erase: page 0x100D000
2253+
Internal Flash Write: addr 0x100C000, len 6036
2254+
Boot partition: 0x100C000 (sz 5780, ver 0x2, type 0x202)
2255+
Network Image: Ver 0x2, Size 5780
2256+
Network version (after update): 0x2
2257+
Status: App 2 (ver 2), Net 4 (ver 2)
2258+
Boot partition: 0x100C000 (sz 5780, ver 0x2, type 0x202)
2259+
Booting version: 0x2
22352260
========================
22362261
nRF5340 wolfBoot (net core)
22372262
Copyright 2024 wolfSSL Inc
22382263
GPL v3
2239-
Version : 0x1
2264+
Version : 0x2
22402265
========================
22412266
Internal Flash Write: addr 0x1039FFC, len 4
22422267
Internal Flash Write: addr 0x1039FFB, len 1
@@ -3050,8 +3075,8 @@ repository that can be directly flashed into the BIOS flash of the board.
30503075

30513076
## Infineon AURIX TC3xx
30523077

3053-
wolfBoot supports the AURIX TC3xx family of devices, and provides a demo application targeting the TC375 AURIX LiteKit-V2.
3078+
wolfBoot supports the AURIX TC3xx family of devices, and provides a demo application targeting the TC375 AURIX LiteKit-V2.
30543079

3055-
For detailed instructions on using wolfBoot with the AURIX TC3xx, please refer to [IDE/AURIX/README.md](../IDE/AURIX/README.md)
3080+
For detailed instructions on using wolfBoot with the AURIX TC3xx, please refer to [IDE/AURIX/README.md](../IDE/AURIX/README.md)
30563081

3057-
wolfBoot can also integrate with [wolfHSM](https://www.wolfssl.com/products/wolfhsm/) on AURIX TC3xx devices, offloading cryptographic operations and key storage to the AURIX HSM core. For more information on using wolfBoot with wolfHSM on AURIX devices, please contact us at facts@wolfssl.com.
3082+
wolfBoot can also integrate with [wolfHSM](https://www.wolfssl.com/products/wolfhsm/) on AURIX TC3xx devices, offloading cryptographic operations and key storage to the AURIX HSM core. For more information on using wolfBoot with wolfHSM on AURIX devices, please contact us at facts@wolfssl.com.

hal/nrf5340.c

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -209,19 +209,21 @@ int RAMFUNCTION hal_flash_erase(uint32_t address, int len)
209209
{
210210
uint32_t end = address + len - 1;
211211
uint32_t p;
212-
uint32_t page_sz = (address < FLASH_BASE_NET) ?
213-
FLASH_PAGESZ_APP :
214-
FLASH_PAGESZ_NET;
215212
#ifdef DEBUG_FLASH
216213
wolfBoot_printf("Internal Flash Erase: addr 0x%x, len %d\n", address, len);
217214
#endif
218-
for (p = address; p <= end; p += page_sz) {
215+
/* mask to page start address */
216+
address &= ~(FLASH_PAGE_SIZE-1);
217+
for (p = address; p <= end; p += FLASH_PAGE_SIZE) {
219218
/* set both secure and non-secure registers */
220219
NVMC_CONFIG = NVMC_CONFIG_EEN;
221220
NVMC_CONFIGNS = NVMC_CONFIG_EEN;
222221
while (NVMC_READY == 0);
223222
*(volatile uint32_t *)p = 0xFFFFFFFF;
224223
while (NVMC_READY == 0);
224+
#ifdef DEBUG_FLASH
225+
wolfBoot_printf("Internal Flash Erase: page 0x%x\n", p);
226+
#endif
225227
}
226228
return 0;
227229
}
@@ -319,10 +321,13 @@ static int hal_net_get_image(struct wolfBoot_image* img, ShmInfo_t* info)
319321
ret = wolfBoot_open_image(img, PART_BOOT);
320322
#endif /* TARGET_nrf5340_* */
321323
if (ret == 0) {
322-
info->version = wolfBoot_get_blob_version(get_image_hdr(img));
323-
info->size = img->fw_size;
324+
uint32_t ver = wolfBoot_get_blob_version(get_image_hdr(img));
325+
/* Note: network core fault writing to shared memory means application
326+
* core did not enable access at run-time yet */
327+
info->version = ver;
328+
info->size = IMAGE_HEADER_SIZE + img->fw_size;
324329
wolfBoot_printf("Network Image: Ver 0x%x, Size %d\n",
325-
info->version, info->size);
330+
ver, img->fw_size);
326331
}
327332
else {
328333
info->version = 0; /* not known */
@@ -390,18 +395,17 @@ static void hal_net_check_version(void)
390395
wolfBoot_printf("Starting update: Ver %d->%d, Size %d->%d\n",
391396
shm->net.version, shm->app.version, shm->net.size, shm->net.size);
392397
/* Erase network core boot flash */
393-
wb_flash_erase(&img, 0, WOLFBOOT_PARTITION_SIZE);
398+
hal_flash_erase((uintptr_t)img.hdr, shm->app.size);
394399
/* Write new firmware to internal flash */
395-
wb_flash_write(&img, 0, shm->data, shm->app.size);
400+
hal_flash_write((uintptr_t)img.hdr, shm->data, shm->app.size);
396401

397402
/* Reopen image and refresh information */
398-
wolfBoot_open_image(&img, PART_BOOT);
403+
hal_net_get_image(&img, &shm->net);
399404
wolfBoot_printf("Network version (after update): 0x%x\n",
400405
shm->net.version);
401-
hal_net_get_image(&img, &shm->net);
402406
hal_shm_status_set(&shm->net, SHARED_STATUS_UPDATE_DONE);
403407

404-
/* continue booting */
408+
/* continue booting - boot process will validate image hash/signature */
405409
}
406410
#endif /* TARGET_nrf5340_* */
407411
exit:
@@ -420,19 +424,18 @@ void hal_net_check_update(void)
420424
ret = hal_net_get_image(&img, &shm->app);
421425
if (ret == 0 && shm->app.version > shm->net.version) {
422426
wolfBoot_printf("Found Network Core update: Ver %d->%d, Size %d->%d\n",
423-
shm->net.version, shm->app.version, shm->net.size, shm->net.size);
427+
shm->net.version, shm->app.version, shm->net.size, shm->app.size);
424428

425429
/* validate the update is valid */
426430
if (wolfBoot_verify_integrity(&img) == 0 &&
427431
wolfBoot_verify_authenticity(&img) == 0)
428432
{
429-
uint32_t fw_size = IMAGE_HEADER_SIZE + img.fw_size;
430433
wolfBoot_printf("Network image valid, loading into shared mem\n");
431434
/* relocate image to shared ram */
432435
#ifdef EXT_FLASH
433-
ret = ext_flash_read(PART_NET_ADDR, shm->data, fw_size);
436+
ret = ext_flash_read(PART_NET_ADDR, shm->data, shm->app.size);
434437
#else
435-
memcpy(shm->data, img.hdr, fw_size);
438+
memcpy(shm->data, img.hdr, shm->app.size);
436439
#endif
437440
if (ret >= 0) {
438441
/* signal network core to do update */
@@ -441,8 +444,9 @@ void hal_net_check_update(void)
441444
/* wait for update_done */
442445
ret = hal_shm_status_wait(&shm->net,
443446
SHARED_STATUS_UPDATE_DONE, 1000000);
444-
if (ret == 0)
445-
wolfBoot_printf("Network core firmware update sent\n");
447+
if (ret == 0) {
448+
wolfBoot_printf("Network core firmware update done\n");
449+
}
446450
}
447451
}
448452
else {
@@ -474,15 +478,15 @@ void hal_init(void)
474478
(SPU_EXTDOMAIN_PERM_SECATTR_SECURE | SPU_EXTDOMAIN_PERM_UNLOCK);
475479
#endif
476480

477-
spi_flash_probe();
478-
479-
hal_net_check_version();
480-
481481
#ifdef TEST_FLASH
482482
if (test_flash() != 0) {
483483
wolfBoot_printf("Internal flash Test Failed!\n");
484484
}
485485
#endif
486+
487+
spi_flash_probe();
488+
489+
hal_net_check_version();
486490
}
487491

488492

@@ -506,7 +510,8 @@ void hal_prepare_boot(void)
506510
#ifdef TEST_FLASH
507511

508512
#ifndef TEST_ADDRESS
509-
#define TEST_ADDRESS (FLASH_BASE_ADDR + (FLASH_SIZE - WOLFBOOT_SECTOR_SIZE))
513+
#define TEST_SZ (WOLFBOOT_SECTOR_SIZE * 2)
514+
#define TEST_ADDRESS (FLASH_BASE_ADDR + (FLASH_SIZE - TEST_SZ))
510515
#endif
511516

512517
/* #define TEST_FLASH_READONLY */
@@ -516,7 +521,7 @@ static int test_flash(void)
516521
int ret = 0;
517522
uint32_t i, len;
518523
uint8_t* pagePtr = (uint8_t*)TEST_ADDRESS;
519-
static uint8_t pageData[WOLFBOOT_SECTOR_SIZE];
524+
static uint8_t pageData[TEST_SZ];
520525

521526
wolfBoot_printf("Internal flash test at 0x%x\n", TEST_ADDRESS);
522527

@@ -528,7 +533,7 @@ static int test_flash(void)
528533
#ifndef TEST_FLASH_READONLY
529534
/* Erase sector */
530535
hal_flash_unlock();
531-
ret = hal_flash_erase(TEST_ADDRESS, WOLFBOOT_SECTOR_SIZE);
536+
ret = hal_flash_erase(TEST_ADDRESS, sizeof(pageData));
532537
hal_flash_lock();
533538
if (ret != 0) {
534539
wolfBoot_printf("Erase Sector failed: Ret %d\n", ret);

include/spi_drv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ int spi_xfer(int cs, const uint8_t* tx, uint8_t* rx, uint32_t sz, int flags);
9999
#define QSPI_ADDR_MODE QSPI_DATA_MODE_SPI
100100
#endif
101101
#ifndef QSPI_ADDR_SZ /* default to 24-bit address */
102-
#define QSPI_ADDR_SZ 3
102+
#define QSPI_ADDR_SZ 3
103103
#endif
104104
#ifndef QSPI_DATA_MODE /* data defaults to Quad mode */
105105
#define QSPI_DATA_MODE QSPI_DATA_MODE_QSPI

src/image.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ int wolfBoot_open_image_address(struct wolfBoot_image *img, uint8_t *image)
885885
img->hdr_cache = image;
886886
#endif
887887

888-
wolfBoot_printf("%s partition: %p (sz %d, ver 0x%x, type 0x%d)\n",
888+
wolfBoot_printf("%s partition: %p (sz %d, ver 0x%x, type 0x%x)\n",
889889
(img->part == PART_BOOT) ? "Boot" : "Update",
890890
img->hdr, (unsigned int)img->fw_size,
891891
wolfBoot_get_blob_version(image),

src/update_flash.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -526,22 +526,22 @@ static int RAMFUNCTION wolfBoot_update(int fallback_allowed)
526526
* checks on the firmware update
527527
* before starting the swap
528528
*/
529-
530529
update_type = wolfBoot_get_image_type(PART_UPDATE);
531530

532531
wolfBoot_get_update_sector_flag(0, &flag);
533532
/* Check the first sector to detect interrupted update */
534533
if (flag == SECT_FLAG_NEW) {
535-
if (((update_type & 0x000F) != HDR_IMG_TYPE_APP) ||
536-
((update_type & 0xFF00) != HDR_IMG_TYPE_AUTH)) {
537-
wolfBoot_printf("Invalid update type %d\n", update_type);
534+
if (((update_type & HDR_IMG_TYPE_PART_MASK) != HDR_IMG_TYPE_APP) ||
535+
((update_type & HDR_IMG_TYPE_AUTH_MASK) != HDR_IMG_TYPE_AUTH)) {
536+
wolfBoot_printf("Invalid update type 0x%x\n", update_type);
538537
return -1;
539538
}
540539
if (update.fw_size > MAX_UPDATE_SIZE - 1) {
541540
wolfBoot_printf("Invalid update size %u\n", update.fw_size);
542541
return -1;
543542
}
544-
if (!update.hdr_ok || (wolfBoot_verify_integrity(&update) < 0)
543+
if (!update.hdr_ok
544+
|| (wolfBoot_verify_integrity(&update) < 0)
545545
|| (wolfBoot_verify_authenticity(&update) < 0)) {
546546
wolfBoot_printf("Update integrity/verification failed!\n");
547547
return -1;
@@ -872,10 +872,9 @@ void RAMFUNCTION wolfBoot_start(void)
872872
wolfBoot_check_self_update();
873873
#endif
874874

875-
bootRet = wolfBoot_get_partition_state(PART_BOOT, &bootState);
875+
bootRet = wolfBoot_get_partition_state(PART_BOOT, &bootState);
876876
updateRet = wolfBoot_get_partition_state(PART_UPDATE, &updateState);
877877

878-
879878
#if !defined(DISABLE_BACKUP)
880879
/* resume the final erase in case the power failed before it finished */
881880
resumedFinalErase = wolfBoot_swap_and_final_erase(1);

0 commit comments

Comments
 (0)