Skip to content

Commit b767052

Browse files
sigvartmhnvlsianpu
authored andcommitted
[nrf noup] boot: zephyr: nrf53 network core bootloader implementation
Enables network core updates of nrf53 using MCUBoot by identifying images through their start addresses. Also implements the control and transfer using the PCD module. Signed-off-by: Sigvart Hovland <[email protected]> Signed-off-by: Håkon Øye Amundsen <[email protected]> (cherry picked from commit a401d3a) (cherry picked from commit f35f763) (cherry picked from commit 3373578) Signed-off-by: Ioannis Glaropoulos <[email protected]> (cherry picked from commit df05bff) Signed-off-by: Johann Fischer <[email protected]> (cherry picked from commit 6841a6b) Signed-off-by: Andrzej Puzdrowski <[email protected]>
1 parent ef3af33 commit b767052

File tree

2 files changed

+66
-26
lines changed

2 files changed

+66
-26
lines changed

boot/bootutil/src/loader.c

+59-26
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@
4545
#include "bootutil/boot_record.h"
4646
#include "bootutil/fault_injection_hardening.h"
4747

48+
#ifdef CONFIG_SOC_NRF5340_CPUAPP
49+
#include <dfu/pcd.h>
50+
#endif
51+
4852
#ifdef MCUBOOT_ENC_IMAGES
4953
#include "bootutil/enc_key.h"
5054
#endif
@@ -724,42 +728,47 @@ boot_validated_swap_type(struct boot_loader_state *state,
724728
{
725729
int swap_type;
726730
fih_int fih_rc = FIH_FAILURE;
727-
#ifdef PM_S1_ADDRESS
731+
bool upgrade_valid = false;
732+
733+
#if defined(PM_S1_ADDRESS) || defined(CONFIG_SOC_NRF5340_CPUAPP)
734+
const struct flash_area *secondary_fa =
735+
BOOT_IMG_AREA(state, BOOT_SECONDARY_SLOT);
736+
struct image_header *hdr = (struct image_header *)secondary_fa->fa_off;
737+
uint32_t vtable_addr = 0;
738+
uint32_t *vtable = 0;
739+
uint32_t reset_addr = 0;
728740
/* Patch needed for NCS. Since image 0 (the app) and image 1 (the other
729741
* B1 slot S0 or S1) share the same secondary slot, we need to check
730742
* whether the update candidate in the secondary slot is intended for
731743
* image 0 or image 1 primary by looking at the address of the reset
732744
* vector. Note that there are good reasons for not using img_num from
733745
* the swap info.
734746
*/
735-
const struct flash_area *secondary_fa =
736-
BOOT_IMG_AREA(state, BOOT_SECONDARY_SLOT);
737-
struct image_header *hdr =
738-
(struct image_header *)secondary_fa->fa_off;
739747

740748
if (hdr->ih_magic == IMAGE_MAGIC) {
741-
const struct flash_area *primary_fa;
742-
uint32_t vtable_addr = (uint32_t)hdr + hdr->ih_hdr_size;
743-
uint32_t *vtable = (uint32_t *)(vtable_addr);
744-
uint32_t reset_addr = vtable[1];
745-
int rc = flash_area_open(
746-
flash_area_id_from_multi_image_slot(
747-
BOOT_CURR_IMG(state),
748-
BOOT_PRIMARY_SLOT),
749-
&primary_fa);
750-
751-
if (rc != 0) {
752-
return BOOT_SWAP_TYPE_FAIL;
753-
}
754-
/* Get start and end of primary slot for current image */
755-
if (reset_addr < primary_fa->fa_off ||
756-
reset_addr > (primary_fa->fa_off + primary_fa->fa_size)) {
757-
/* The image in the secondary slot is not intended for this image
758-
*/
759-
return BOOT_SWAP_TYPE_NONE;
760-
}
749+
vtable_addr = (uint32_t)hdr + hdr->ih_hdr_size;
750+
vtable = (uint32_t *)(vtable_addr);
751+
reset_addr = vtable[1];
752+
#ifdef PM_S1_ADDRESS
753+
const struct flash_area *primary_fa;
754+
int rc = flash_area_open(flash_area_id_from_multi_image_slot(
755+
BOOT_CURR_IMG(state),
756+
BOOT_PRIMARY_SLOT),
757+
&primary_fa);
758+
759+
if (rc != 0) {
760+
return BOOT_SWAP_TYPE_FAIL;
761+
}
762+
/* Get start and end of primary slot for current image */
763+
if (reset_addr < primary_fa->fa_off ||
764+
reset_addr > (primary_fa->fa_off + primary_fa->fa_size)) {
765+
/* The image in the secondary slot is not intended for this image
766+
*/
767+
return BOOT_SWAP_TYPE_NONE;
768+
}
769+
#endif /* PM_S1_ADDRESS */
761770
}
762-
#endif
771+
#endif /* PM_S1_ADDRESS || CONFIG_SOC_NRF5340_CPUAPP */
763772

764773
swap_type = boot_swap_type_multi(BOOT_CURR_IMG(state));
765774
if (BOOT_IS_UPGRADE(swap_type)) {
@@ -773,7 +782,31 @@ boot_validated_swap_type(struct boot_loader_state *state,
773782
} else {
774783
swap_type = BOOT_SWAP_TYPE_FAIL;
775784
}
785+
} else {
786+
upgrade_valid = true;
787+
}
788+
789+
#if defined(CONFIG_SOC_NRF5340_CPUAPP) && defined(PM_CPUNET_B0N_ADDRESS)
790+
/* If the update is valid, and it targets the network core: perform the
791+
* update and indicate to the caller of this function that no update is
792+
* available
793+
*/
794+
if (upgrade_valid && reset_addr > PM_CPUNET_B0N_ADDRESS) {
795+
uint32_t fw_size = hdr->ih_img_size;
796+
797+
BOOT_LOG_INF("Starting network core update");
798+
int rc = pcd_network_core_update(vtable, fw_size);
799+
800+
if (rc != 0) {
801+
swap_type = BOOT_SWAP_TYPE_FAIL;
802+
} else {
803+
BOOT_LOG_INF("Done updating network core");
804+
rc = swap_erase_trailer_sectors(state,
805+
secondary_fa);
806+
swap_type = BOOT_SWAP_TYPE_NONE;
807+
}
776808
}
809+
#endif /* CONFIG_SOC_NRF5340_CPUAPP */
777810
}
778811

779812
return swap_type;

boot/zephyr/main.c

+7
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ const struct boot_uart_funcs boot_funcs = {
5555
#include <arm_cleanup.h>
5656
#endif
5757

58+
#ifdef CONFIG_SOC_NRF5340_CPUAPP
59+
#include <dfu/pcd.h>
60+
#endif
61+
5862
/* CONFIG_LOG_MINIMAL is the legacy Kconfig property,
5963
* replaced by CONFIG_LOG_MODE_MINIMAL.
6064
*/
@@ -461,6 +465,9 @@ void main(void)
461465
;
462466
}
463467
#endif /* USE_PARTITION_MANAGER && CONFIG_FPROTECT */
468+
#if defined(CONFIG_SOC_NRF5340_CPUAPP) && defined(PM_CPUNET_B0N_ADDRESS)
469+
pcd_lock_ram();
470+
#endif
464471

465472
ZEPHYR_BOOT_LOG_STOP();
466473

0 commit comments

Comments
 (0)