5353 #define SHARED_MEM_ADDR (0x20000000UL + (64 * 1024))
5454#endif
5555/* Shared memory states (mask, easier to check) */
56- #define SHARED_STATUS_UNKNOWN 0
57- #define SHARED_STATUS_READY 1
58- #define SHARED_STATUS_UPDATE_START 2
59- #define SHARED_STATUS_UPDATE_DONE 4
60- #define SHARED_STATUS_DO_BOOT 8
56+ #define SHARED_STATUS_UNKNOWN 0x00
57+ #define SHARED_STATUS_READY 0x01
58+ #define SHARED_STATUS_UPDATE_START 0x02
59+ #define SHARED_STATUS_UPDATE_DONE 0x04
60+ #define SHARED_STATUS_DO_BOOT 0x08
6161
6262#define SHAREM_MEM_MAGIC 0x5753484D /* WSHM */
6363
@@ -205,7 +205,7 @@ int RAMFUNCTION hal_flash_erase(uint32_t address, int len)
205205{
206206 uint32_t end = address + len - 1 ;
207207 uint32_t p ;
208- #ifdef DEBUG_FLASH
208+ #if defined( DEBUG_FLASH ) && DEBUG_FLASH > 1
209209 wolfBoot_printf ("Internal Flash Erase: addr 0x%x, len %d\n" , address , len );
210210#endif
211211 /* mask to page start address */
@@ -354,6 +354,7 @@ static int hal_shm_status_wait(ShmInfo_t* info, uint32_t status,
354354 return ret ;
355355}
356356
357+ /* Handles network core updates */
357358static void hal_net_check_version (void )
358359{
359360 int ret ;
@@ -374,51 +375,8 @@ static void hal_net_check_version(void)
374375 /* check if network core can continue booting or needs to wait for update */
375376 if (ret != 0 || shm -> app .version <= shm -> net .version ) {
376377 wolfBoot_printf ("Network Core: Releasing for boot\n" );
377- hal_shm_status_set (& shm -> app , SHARED_STATUS_DO_BOOT );
378378 }
379379 else {
380- wolfBoot_printf ("Network Core: Holding for update\n" );
381- }
382- #else /* TARGET_nrf5340_net */
383- hal_net_get_image (& img , & shm -> net );
384- hal_shm_status_set (& shm -> net , SHARED_STATUS_READY );
385-
386- /* wait for do_boot or update from app core */
387- ret = hal_shm_status_wait (& shm -> app ,
388- (SHARED_STATUS_UPDATE_START | SHARED_STATUS_DO_BOOT ), 1000000 );
389- /* are we updating? */
390- if (ret == 0 && shm -> app .status == SHARED_STATUS_UPDATE_START ) {
391- wolfBoot_printf ("Starting update: Ver %d->%d, Size %d->%d\n" ,
392- shm -> net .version , shm -> app .version , shm -> net .size , shm -> net .size );
393- /* Erase network core boot flash */
394- hal_flash_erase ((uintptr_t )img .hdr , shm -> app .size );
395- /* Write new firmware to internal flash */
396- hal_flash_write ((uintptr_t )img .hdr , shm -> data , shm -> app .size );
397-
398- /* Reopen image and refresh information */
399- hal_net_get_image (& img , & shm -> net );
400- wolfBoot_printf ("Network version (after update): 0x%x\n" ,
401- shm -> net .version );
402- hal_shm_status_set (& shm -> net , SHARED_STATUS_UPDATE_DONE );
403-
404- /* continue booting - boot process will validate image hash/signature */
405- }
406- #endif /* TARGET_nrf5340_* */
407- exit :
408- wolfBoot_printf ("Status: App %d (ver %d), Net %d (ver %d)\n" ,
409- shm -> app .status , shm -> app .version , shm -> net .status , shm -> net .version );
410- }
411-
412- #ifdef TARGET_nrf5340_app
413- void hal_net_check_update (void )
414- {
415- int ret ;
416- uint32_t timeout ;
417- struct wolfBoot_image img ;
418-
419- /* handle update for network core */
420- ret = hal_net_get_image (& img , & shm -> app );
421- if (ret == 0 && shm -> app .version > shm -> net .version ) {
422380 wolfBoot_printf ("Found Network Core update: Ver %d->%d, Size %d->%d\n" ,
423381 shm -> net .version , shm -> app .version , shm -> net .size , shm -> app .size );
424382
@@ -452,8 +410,37 @@ void hal_net_check_update(void)
452410 }
453411 /* inform network core to boot */
454412 hal_shm_status_set (& shm -> app , SHARED_STATUS_DO_BOOT );
413+ #else /* TARGET_nrf5340_net */
414+ hal_net_get_image (& img , & shm -> net );
415+ hal_shm_status_set (& shm -> net , SHARED_STATUS_READY );
416+
417+ /* wait for do_boot or update from app core */
418+ wolfBoot_printf ("Waiting for status from app core...\n" );
419+ ret = hal_shm_status_wait (& shm -> app ,
420+ (SHARED_STATUS_UPDATE_START | SHARED_STATUS_DO_BOOT ), 1000000 );
421+
422+ /* are we updating? */
423+ if (ret == 0 && shm -> app .status == SHARED_STATUS_UPDATE_START ) {
424+ wolfBoot_printf ("Starting update: Ver %d->%d, Size %d->%d\n" ,
425+ 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 );
430+
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 );
436+
437+ /* continue booting - boot process will validate image hash/signature */
438+ }
439+ #endif /* TARGET_nrf5340_* */
440+ exit :
441+ wolfBoot_printf ("Status: App %d (ver %d), Net %d (ver %d)\n" ,
442+ shm -> app .status , shm -> app .version , shm -> net .status , shm -> net .version );
455443}
456- #endif
457444
458445void hal_init (void )
459446{
@@ -488,8 +475,6 @@ void hal_prepare_boot(void)
488475 //BOOTLOADER_PARTITION_SIZE
489476
490477#ifdef TARGET_nrf5340_app
491- hal_net_check_update ();
492-
493478 /* Restore defaults preventing network core from accessing shared SDRAM */
494479 SPU_EXTDOMAIN_PERM (0 ) =
495480 (SPU_EXTDOMAIN_PERM_SECATTR_NONSECURE | SPU_EXTDOMAIN_PERM_UNLOCK );
0 commit comments