mirror of https://github.com/wolfSSL/wolfBoot.git
Switch network core to use external flash HAL, but map to shared memory. Allows using update_flash logic including encrypted and delta updates.
parent
f2b929affd
commit
eb175cdfec
|
@ -19,7 +19,8 @@ RAM_CODE?=1
|
||||||
DUALBANK_SWAP?=0
|
DUALBANK_SWAP?=0
|
||||||
FLAGS_HOME=0
|
FLAGS_HOME=0
|
||||||
DISABLE_BACKUP=1
|
DISABLE_BACKUP=1
|
||||||
EXT_FLASH?=0
|
# Implementation maps to shared application core memory
|
||||||
|
EXT_FLASH?=1
|
||||||
SPI_FLASH?=0
|
SPI_FLASH?=0
|
||||||
QSPI_FLASH?=0
|
QSPI_FLASH?=0
|
||||||
|
|
||||||
|
@ -35,11 +36,11 @@ WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x0100C000
|
||||||
# Application Partition Size (184KB)
|
# Application Partition Size (184KB)
|
||||||
WOLFBOOT_PARTITION_SIZE?=0x2E000
|
WOLFBOOT_PARTITION_SIZE?=0x2E000
|
||||||
|
|
||||||
# Flash offset for update (not used - handled by application core)
|
# Flash offset for update (provided by application core to shared memory)
|
||||||
WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x0100C000
|
WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x100000
|
||||||
|
|
||||||
# Flash offset for swap (not used - handled by application core)
|
# Flash offset for swap (uses shared memory)
|
||||||
WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x103A800
|
WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x12E000
|
||||||
|
|
||||||
V?=0
|
V?=0
|
||||||
DEBUG?=0
|
DEBUG?=0
|
||||||
|
|
|
@ -74,9 +74,15 @@ typedef struct {
|
||||||
|
|
||||||
/* application places firmware here */
|
/* application places firmware here */
|
||||||
uint8_t data[FLASH_SIZE_NET];
|
uint8_t data[FLASH_SIZE_NET];
|
||||||
|
/* used as "swap" */
|
||||||
|
uint8_t swap[FLASH_PAGESZ_NET];
|
||||||
} SharedMem_t;
|
} SharedMem_t;
|
||||||
static SharedMem_t* shm = (SharedMem_t*)SHARED_MEM_ADDR;
|
static SharedMem_t* shm = (SharedMem_t*)SHARED_MEM_ADDR;
|
||||||
|
|
||||||
|
#ifdef TARGET_nrf5340_net
|
||||||
|
static int do_update = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* UART */
|
/* UART */
|
||||||
#ifdef DEBUG_UART
|
#ifdef DEBUG_UART
|
||||||
|
@ -232,6 +238,71 @@ void RAMFUNCTION hal_flash_lock(void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef TARGET_nrf5340_net
|
||||||
|
/* external flash is access application core shared memory directly */
|
||||||
|
|
||||||
|
/* calculates location in shared memory */
|
||||||
|
static uintptr_t ext_flash_addr_calc(uintptr_t address)
|
||||||
|
{
|
||||||
|
if (address >= WOLFBOOT_PARTITION_UPDATE_ADDRESS) {
|
||||||
|
if (address >= WOLFBOOT_PARTITION_SWAP_ADDRESS) {
|
||||||
|
address -= WOLFBOOT_PARTITION_SWAP_ADDRESS;
|
||||||
|
}
|
||||||
|
else { /* update */
|
||||||
|
address -= WOLFBOOT_PARTITION_UPDATE_ADDRESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* check address */
|
||||||
|
if (address >= (FLASH_SIZE_NET + FLASH_PAGESZ_NET)) {
|
||||||
|
address = 0;
|
||||||
|
}
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ext_flash_write(uintptr_t address, const uint8_t *data, int len)
|
||||||
|
{
|
||||||
|
uintptr_t addr = ext_flash_addr_calc(address);
|
||||||
|
#ifdef DEBUG_FLASH
|
||||||
|
wolfBoot_printf("Ext Write: Len %d, Addr 0x%x (off 0x%x) -> 0x%x\n",
|
||||||
|
len, address, addr, data);
|
||||||
|
#endif
|
||||||
|
memcpy(shm->data + addr, data, len);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ext_flash_read(uintptr_t address, uint8_t *data, int len)
|
||||||
|
{
|
||||||
|
uintptr_t addr = ext_flash_addr_calc(address);
|
||||||
|
#ifdef DEBUG_FLASH
|
||||||
|
wolfBoot_printf("Ext Read: Len %d, Addr 0x%x (off 0x%x) -> %p\n",
|
||||||
|
len, address, addr, data);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
memcpy(data, shm->data + addr, len);
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ext_flash_erase(uintptr_t address, int len)
|
||||||
|
{
|
||||||
|
uintptr_t addr = ext_flash_addr_calc(address);
|
||||||
|
#ifdef DEBUG_FLASH
|
||||||
|
wolfBoot_printf("Ext Erase: Len %d, Addr 0x%x (off 0x%x)\n",
|
||||||
|
len, address, addr);
|
||||||
|
#endif
|
||||||
|
memset(shm->data + addr, FLASH_BYTE_ERASED, len);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ext_flash_lock(void)
|
||||||
|
{
|
||||||
|
/* no op */
|
||||||
|
}
|
||||||
|
void ext_flash_unlock(void)
|
||||||
|
{
|
||||||
|
/* no op */
|
||||||
|
}
|
||||||
|
#endif /* TARGET_nrf5340_net */
|
||||||
|
|
||||||
static void clock_init(void)
|
static void clock_init(void)
|
||||||
{
|
{
|
||||||
#ifndef TARGET_nrf5340_net
|
#ifndef TARGET_nrf5340_net
|
||||||
|
@ -423,18 +494,12 @@ static void hal_net_check_version(void)
|
||||||
if (ret == 0 && shm->app.status == SHARED_STATUS_UPDATE_START) {
|
if (ret == 0 && shm->app.status == SHARED_STATUS_UPDATE_START) {
|
||||||
wolfBoot_printf("Starting update: Ver %d->%d, Size %d->%d\n",
|
wolfBoot_printf("Starting update: Ver %d->%d, Size %d->%d\n",
|
||||||
shm->net.version, shm->app.version, shm->net.size, shm->net.size);
|
shm->net.version, shm->app.version, shm->net.size, shm->net.size);
|
||||||
/* Erase network core boot flash */
|
do_update = 1;
|
||||||
hal_flash_erase((uintptr_t)img.hdr, shm->app.size);
|
|
||||||
/* Write new firmware to internal flash */
|
|
||||||
hal_flash_write((uintptr_t)img.hdr, shm->data, shm->app.size);
|
|
||||||
|
|
||||||
/* Reopen image and refresh information */
|
/* trigger update */
|
||||||
hal_net_get_image(&img, &shm->net);
|
wolfBoot_set_partition_state(PART_UPDATE, IMG_STATE_UPDATING);
|
||||||
wolfBoot_printf("Network version (after update): 0x%x\n",
|
|
||||||
shm->net.version);
|
|
||||||
hal_shm_status_set(&shm->net, SHARED_STATUS_UPDATE_DONE);
|
|
||||||
|
|
||||||
/* continue booting - boot process will validate image hash/signature */
|
/* proceed to update_flash routines */
|
||||||
}
|
}
|
||||||
#endif /* TARGET_nrf5340_* */
|
#endif /* TARGET_nrf5340_* */
|
||||||
exit:
|
exit:
|
||||||
|
@ -474,6 +539,18 @@ void hal_prepare_boot(void)
|
||||||
//WOLFBOOT_ORIGIN
|
//WOLFBOOT_ORIGIN
|
||||||
//BOOTLOADER_PARTITION_SIZE
|
//BOOTLOADER_PARTITION_SIZE
|
||||||
|
|
||||||
|
#ifdef TARGET_nrf5340_net
|
||||||
|
if (do_update) {
|
||||||
|
/* signal application core of update */
|
||||||
|
/* Reopen image and refresh information */
|
||||||
|
struct wolfBoot_image img;
|
||||||
|
hal_net_get_image(&img, &shm->net);
|
||||||
|
wolfBoot_printf("Network version (after update): 0x%x\n",
|
||||||
|
shm->net.version);
|
||||||
|
hal_shm_status_set(&shm->net, SHARED_STATUS_UPDATE_DONE);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef TARGET_nrf5340_app
|
#ifdef TARGET_nrf5340_app
|
||||||
/* Restore defaults preventing network core from accessing shared SDRAM */
|
/* Restore defaults preventing network core from accessing shared SDRAM */
|
||||||
SPU_EXTDOMAIN_PERM(0) =
|
SPU_EXTDOMAIN_PERM(0) =
|
||||||
|
|
|
@ -408,7 +408,7 @@ int spi_flash_read(uint32_t address, void *data, int len)
|
||||||
);
|
);
|
||||||
|
|
||||||
#ifdef DEBUG_QSPI
|
#ifdef DEBUG_QSPI
|
||||||
wolfBoot_printf("QSPI Flash Read: Ret %d, Cmd 0x%x, Len %d , 0x%x -> %p\n",
|
wolfBoot_printf("QSPI Flash Read: Ret %d, Cmd 0x%x, Len %d, 0x%x -> %p\n",
|
||||||
ret, FLASH_READ_CMD, len, address, data);
|
ret, FLASH_READ_CMD, len, address, data);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue