@@ -74,9 +74,15 @@ typedef struct {
7474
7575 /* application places firmware here */
7676 uint8_t data [FLASH_SIZE_NET ];
77+ /* used as "swap" */
78+ uint8_t swap [FLASH_PAGESZ_NET ];
7779} SharedMem_t ;
7880static SharedMem_t * shm = (SharedMem_t * )SHARED_MEM_ADDR ;
7981
82+ #ifdef TARGET_nrf5340_net
83+ static int do_update = 0 ;
84+ #endif
85+
8086
8187/* UART */
8288#ifdef DEBUG_UART
@@ -232,6 +238,71 @@ void RAMFUNCTION hal_flash_lock(void)
232238{
233239}
234240
241+ #ifdef TARGET_nrf5340_net
242+ /* external flash is access application core shared memory directly */
243+
244+ /* calculates location in shared memory */
245+ static uintptr_t ext_flash_addr_calc (uintptr_t address )
246+ {
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+ /* check address */
256+ if (address >= (FLASH_SIZE_NET + FLASH_PAGESZ_NET )) {
257+ address = 0 ;
258+ }
259+ return address ;
260+ }
261+
262+ int ext_flash_write (uintptr_t address , const uint8_t * data , int len )
263+ {
264+ uintptr_t addr = ext_flash_addr_calc (address );
265+ #ifdef DEBUG_FLASH
266+ wolfBoot_printf ("Ext Write: Len %d, Addr 0x%x (off 0x%x) -> 0x%x\n" ,
267+ len , address , addr , data );
268+ #endif
269+ memcpy (shm -> data + addr , data , len );
270+ return 0 ;
271+ }
272+
273+ int ext_flash_read (uintptr_t address , uint8_t * data , int len )
274+ {
275+ uintptr_t addr = ext_flash_addr_calc (address );
276+ #ifdef DEBUG_FLASH
277+ wolfBoot_printf ("Ext Read: Len %d, Addr 0x%x (off 0x%x) -> %p\n" ,
278+ len , address , addr , data );
279+ #endif
280+
281+ memcpy (data , shm -> data + addr , len );
282+ return len ;
283+ }
284+
285+ int ext_flash_erase (uintptr_t address , int len )
286+ {
287+ uintptr_t addr = ext_flash_addr_calc (address );
288+ #ifdef DEBUG_FLASH
289+ wolfBoot_printf ("Ext Erase: Len %d, Addr 0x%x (off 0x%x)\n" ,
290+ len , address , addr );
291+ #endif
292+ memset (shm -> data + addr , FLASH_BYTE_ERASED , len );
293+ return 0 ;
294+ }
295+
296+ void ext_flash_lock (void )
297+ {
298+ /* no op */
299+ }
300+ void ext_flash_unlock (void )
301+ {
302+ /* no op */
303+ }
304+ #endif /* TARGET_nrf5340_net */
305+
235306static void clock_init (void )
236307{
237308#ifndef TARGET_nrf5340_net
@@ -423,18 +494,12 @@ static void hal_net_check_version(void)
423494 if (ret == 0 && shm -> app .status == SHARED_STATUS_UPDATE_START ) {
424495 wolfBoot_printf ("Starting update: Ver %d->%d, Size %d->%d\n" ,
425496 shm -> net .version , shm -> app .version , shm -> net .size , shm -> net .size );
426- /* Erase network core boot flash */
427- hal_flash_erase ((uintptr_t )img .hdr , shm -> app .size );
428- /* Write new firmware to internal flash */
429- hal_flash_write ((uintptr_t )img .hdr , shm -> data , shm -> app .size );
497+ do_update = 1 ;
430498
431- /* Reopen image and refresh information */
432- hal_net_get_image (& img , & shm -> net );
433- wolfBoot_printf ("Network version (after update): 0x%x\n" ,
434- shm -> net .version );
435- hal_shm_status_set (& shm -> net , SHARED_STATUS_UPDATE_DONE );
499+ /* trigger update */
500+ wolfBoot_set_partition_state (PART_UPDATE , IMG_STATE_UPDATING );
436501
437- /* continue booting - boot process will validate image hash/signature */
502+ /* proceed to update_flash routines */
438503 }
439504#endif /* TARGET_nrf5340_* */
440505exit :
@@ -474,6 +539,18 @@ void hal_prepare_boot(void)
474539 //WOLFBOOT_ORIGIN
475540 //BOOTLOADER_PARTITION_SIZE
476541
542+ #ifdef TARGET_nrf5340_net
543+ if (do_update ) {
544+ /* signal application core of update */
545+ /* Reopen image and refresh information */
546+ struct wolfBoot_image img ;
547+ hal_net_get_image (& img , & shm -> net );
548+ wolfBoot_printf ("Network version (after update): 0x%x\n" ,
549+ shm -> net .version );
550+ hal_shm_status_set (& shm -> net , SHARED_STATUS_UPDATE_DONE );
551+ }
552+ #endif
553+
477554#ifdef TARGET_nrf5340_app
478555 /* Restore defaults preventing network core from accessing shared SDRAM */
479556 SPU_EXTDOMAIN_PERM (0 ) =
0 commit comments