Skip to content

Commit 29a30a6

Browse files
dgarskedanielinux
authored andcommitted
Enable backup for network core, so the last known image will still be in shared ram. Fixed bug with swap offset on network core external memory map and "erase" init.
1 parent e6dacde commit 29a30a6

4 files changed

Lines changed: 26 additions & 14 deletions

File tree

config/examples/nrf5340_net.config

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ RAM_CODE?=1
1818

1919
DUALBANK_SWAP?=0
2020
FLAGS_HOME=0
21-
DISABLE_BACKUP=1
21+
DISABLE_BACKUP=0
2222
# Implementation maps to shared application core memory
2323
EXT_FLASH?=1
2424
SPI_FLASH?=0
@@ -42,6 +42,9 @@ WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x100000
4242
# Flash offset for swap (uses shared memory)
4343
WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x12E000
4444

45+
# Network core uses partition ID 2
46+
CFLAGS_EXTRA+=-DHDR_IMG_TYPE_APP=0x2
47+
4548
V?=0
4649
DEBUG?=0
4750
DEBUG_UART?=1

hal/nrf5340.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,17 @@
4040

4141
/* Network updates can be signed with "--id 2" and placed into the normal update partition,
4242
* or they can be placed into the external flash at offset 0x100000 */
43+
/* Partition ID should be set HDR_IMG_TYPE_APP=2 */
4344
#ifndef PART_NET_ID
44-
#define PART_NET_ID 2
45+
#ifdef HDR_IMG_TYPE_APP
46+
#define PART_NET_ID HDR_IMG_TYPE_APP
47+
#else
48+
#define PART_NET_ID 2 /* default */
49+
#endif
4550
#endif
51+
52+
/* Offset in external QSPI flash for network update
53+
* Comes from nrf5340_net.config WOLFBOOT_PARTITION_UPDATE_ADDRESS) */
4654
#ifndef PART_NET_ADDR
4755
#define PART_NET_ADDR 0x100000UL
4856
#endif
@@ -244,14 +252,8 @@ void RAMFUNCTION hal_flash_lock(void)
244252
/* calculates location in shared memory */
245253
static uintptr_t ext_flash_addr_calc(uintptr_t address)
246254
{
247-
if (address >= WOLFBOOT_PARTITION_UPDATE_ADDRESS) {
248-
if (address >= WOLFBOOT_PARTITION_SWAP_ADDRESS) {
249-
address -= WOLFBOOT_PARTITION_SWAP_ADDRESS;
250-
}
251-
else { /* update */
252-
address -= WOLFBOOT_PARTITION_UPDATE_ADDRESS;
253-
}
254-
}
255+
/* offset external flash addresses by the update partition address */
256+
address -= WOLFBOOT_PARTITION_UPDATE_ADDRESS;
255257
/* check address */
256258
if (address >= (FLASH_SIZE_NET + FLASH_PAGESZ_NET)) {
257259
address = 0;
@@ -456,6 +458,9 @@ static void hal_net_check_version(void)
456458
wolfBoot_verify_authenticity(&img) == 0)
457459
{
458460
wolfBoot_printf("Network image valid, loading into shared mem\n");
461+
/* initialize remainder of shared memory with 0xFF (erased) */
462+
memset(shm->data + shm->app.size, FLASH_BYTE_ERASED,
463+
sizeof(shm->data) - shm->app.size);
459464
/* relocate image to shared ram */
460465
#ifdef EXT_FLASH
461466
ret = ext_flash_read(PART_NET_ADDR, shm->data, shm->app.size);

include/wolfboot/wolfboot.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ extern "C" {
112112

113113
#define HDR_IMG_TYPE_PART_MASK 0x000F
114114
#define HDR_IMG_TYPE_WOLFBOOT 0x0000
115+
#ifndef HDR_IMG_TYPE_APP
115116
#define HDR_IMG_TYPE_APP 0x0001
117+
#endif
116118

117119
#define KEYSTORE_PUBKEY_SIZE_NONE 0
118120
#define KEYSTORE_PUBKEY_SIZE_ED25519 32

src/update_flash.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ static int RAMFUNCTION wolfBoot_update(int fallback_allowed)
486486
const uint32_t sector_size = WOLFBOOT_SECTOR_SIZE;
487487
uint32_t sector = 0;
488488
/* we need to pre-set flag to SECT_FLAG_NEW in case magic hasn't been set
489-
* on the update partion as part of the delta update direction check. if
489+
* on the update partition as part of the delta update direction check. if
490490
* magic has not been set flag will have an un-determined value when we go
491491
* to check it */
492492
uint8_t flag = SECT_FLAG_NEW;
@@ -663,9 +663,10 @@ static int RAMFUNCTION wolfBoot_update(int fallback_allowed)
663663
}
664664
}
665665

666+
/* Erase remainder of partitions */
667+
#if defined(WOLFBOOT_FLASH_MULTI_SECTOR_ERASE) || defined(PRINTF_ENABLED)
666668
/* calculate number of remaining bytes */
667669
/* reserve 1 sector for status (2 sectors for NV write once) */
668-
#if defined(WOLFBOOT_FLASH_MULTI_SECTOR_ERASE) || defined(PRINTF_ENABLED)
669670
#ifdef NVM_FLASH_WRITEONCE
670671
size = WOLFBOOT_PARTITION_SIZE - (sector * sector_size) - (2 * sector_size);
671672
#else
@@ -677,8 +678,9 @@ static int RAMFUNCTION wolfBoot_update(int fallback_allowed)
677678
#endif
678679

679680
#ifdef WOLFBOOT_FLASH_MULTI_SECTOR_ERASE
680-
/* Performant option: Erase remainder of flash sectors in one HAL command */
681-
/* If the HAL supports erase of multiple sectors this could improve performance */
681+
/* Erase remainder of flash sectors in one HAL command. */
682+
/* This can improve performance if the HAL supports erase of
683+
* multiple sectors */
682684
wb_flash_erase(&boot, sector * sector_size, size);
683685
wb_flash_erase(&update, sector * sector_size, size);
684686
#else

0 commit comments

Comments
 (0)