Skip to content

Commit 2014ac1

Browse files
sigvartmhmbolivar-nordic
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]> (cherry picked from commit b767052) Signed-off-by: Trond Einar Snekvik <[email protected]> (cherry picked from commit 6402e99)
1 parent 718a823 commit 2014ac1

File tree

2 files changed

+66
-26
lines changed

2 files changed

+66
-26
lines changed

boot/bootutil/src/loader.c

Lines changed: 59 additions & 26 deletions
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
@@ -754,42 +758,47 @@ boot_validated_swap_type(struct boot_loader_state *state,
754758
{
755759
int swap_type;
756760
fih_int fih_rc = FIH_FAILURE;
757-
#ifdef PM_S1_ADDRESS
761+
bool upgrade_valid = false;
762+
763+
#if defined(PM_S1_ADDRESS) || defined(CONFIG_SOC_NRF5340_CPUAPP)
764+
const struct flash_area *secondary_fa =
765+
BOOT_IMG_AREA(state, BOOT_SECONDARY_SLOT);
766+
struct image_header *hdr = (struct image_header *)secondary_fa->fa_off;
767+
uint32_t vtable_addr = 0;
768+
uint32_t *vtable = 0;
769+
uint32_t reset_addr = 0;
758770
/* Patch needed for NCS. Since image 0 (the app) and image 1 (the other
759771
* B1 slot S0 or S1) share the same secondary slot, we need to check
760772
* whether the update candidate in the secondary slot is intended for
761773
* image 0 or image 1 primary by looking at the address of the reset
762774
* vector. Note that there are good reasons for not using img_num from
763775
* the swap info.
764776
*/
765-
const struct flash_area *secondary_fa =
766-
BOOT_IMG_AREA(state, BOOT_SECONDARY_SLOT);
767-
struct image_header *hdr =
768-
(struct image_header *)secondary_fa->fa_off;
769777

770778
if (hdr->ih_magic == IMAGE_MAGIC) {
771-
const struct flash_area *primary_fa;
772-
uint32_t vtable_addr = (uint32_t)hdr + hdr->ih_hdr_size;
773-
uint32_t *vtable = (uint32_t *)(vtable_addr);
774-
uint32_t reset_addr = vtable[1];
775-
int rc = flash_area_open(
776-
flash_area_id_from_multi_image_slot(
777-
BOOT_CURR_IMG(state),
778-
BOOT_PRIMARY_SLOT),
779-
&primary_fa);
780-
781-
if (rc != 0) {
782-
return BOOT_SWAP_TYPE_FAIL;
783-
}
784-
/* Get start and end of primary slot for current image */
785-
if (reset_addr < primary_fa->fa_off ||
786-
reset_addr > (primary_fa->fa_off + primary_fa->fa_size)) {
787-
/* The image in the secondary slot is not intended for this image
788-
*/
789-
return BOOT_SWAP_TYPE_NONE;
790-
}
779+
vtable_addr = (uint32_t)hdr + hdr->ih_hdr_size;
780+
vtable = (uint32_t *)(vtable_addr);
781+
reset_addr = vtable[1];
782+
#ifdef PM_S1_ADDRESS
783+
const struct flash_area *primary_fa;
784+
int rc = flash_area_open(flash_area_id_from_multi_image_slot(
785+
BOOT_CURR_IMG(state),
786+
BOOT_PRIMARY_SLOT),
787+
&primary_fa);
788+
789+
if (rc != 0) {
790+
return BOOT_SWAP_TYPE_FAIL;
791+
}
792+
/* Get start and end of primary slot for current image */
793+
if (reset_addr < primary_fa->fa_off ||
794+
reset_addr > (primary_fa->fa_off + primary_fa->fa_size)) {
795+
/* The image in the secondary slot is not intended for this image
796+
*/
797+
return BOOT_SWAP_TYPE_NONE;
798+
}
799+
#endif /* PM_S1_ADDRESS */
791800
}
792-
#endif
801+
#endif /* PM_S1_ADDRESS || CONFIG_SOC_NRF5340_CPUAPP */
793802

794803
swap_type = boot_swap_type_multi(BOOT_CURR_IMG(state));
795804
if (BOOT_IS_UPGRADE(swap_type)) {
@@ -803,7 +812,31 @@ boot_validated_swap_type(struct boot_loader_state *state,
803812
} else {
804813
swap_type = BOOT_SWAP_TYPE_FAIL;
805814
}
815+
} else {
816+
upgrade_valid = true;
817+
}
818+
819+
#if defined(CONFIG_SOC_NRF5340_CPUAPP) && defined(PM_CPUNET_B0N_ADDRESS)
820+
/* If the update is valid, and it targets the network core: perform the
821+
* update and indicate to the caller of this function that no update is
822+
* available
823+
*/
824+
if (upgrade_valid && reset_addr > PM_CPUNET_B0N_ADDRESS) {
825+
uint32_t fw_size = hdr->ih_img_size;
826+
827+
BOOT_LOG_INF("Starting network core update");
828+
int rc = pcd_network_core_update(vtable, fw_size);
829+
830+
if (rc != 0) {
831+
swap_type = BOOT_SWAP_TYPE_FAIL;
832+
} else {
833+
BOOT_LOG_INF("Done updating network core");
834+
rc = swap_erase_trailer_sectors(state,
835+
secondary_fa);
836+
swap_type = BOOT_SWAP_TYPE_NONE;
837+
}
806838
}
839+
#endif /* CONFIG_SOC_NRF5340_CPUAPP */
807840
}
808841

809842
return swap_type;

boot/zephyr/main.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ const struct boot_uart_funcs boot_funcs = {
5656
#include <arm_cleanup.h>
5757
#endif
5858

59+
#ifdef CONFIG_SOC_NRF5340_CPUAPP
60+
#include <dfu/pcd.h>
61+
#endif
62+
5963
/* CONFIG_LOG_MINIMAL is the legacy Kconfig property,
6064
* replaced by CONFIG_LOG_MODE_MINIMAL.
6165
*/
@@ -575,6 +579,9 @@ void main(void)
575579
;
576580
}
577581
#endif /* USE_PARTITION_MANAGER && CONFIG_FPROTECT */
582+
#if defined(CONFIG_SOC_NRF5340_CPUAPP) && defined(PM_CPUNET_B0N_ADDRESS)
583+
pcd_lock_ram();
584+
#endif
578585

579586
ZEPHYR_BOOT_LOG_STOP();
580587

0 commit comments

Comments
 (0)