Skip to content

Commit 68b4648

Browse files
chrtatmon-nordic
authored andcommitted
[nrf noup] loader: Fix reading reset addr to support ext flash
When mcuboot_secondary is on external flash, the image header cannot dircetly be accessed via secondary_fa->fa_off. Instead the provided function boot_img_hdr() is used now. Additionally a similar issue is present when trying to read the address of the reset handler. For this flash_area_read() is used now. With this patch is possible to have the update partiton mcuboot_secondary on external flash and update a updatable bootloader (mcuboot) in s0 and/or s1. Signed-off-by: Christian Taedcke <[email protected]> Signed-off-by: Ole Sæther <[email protected]> Signed-off-by: Sigvart Hovland <[email protected]>
1 parent e9086ca commit 68b4648

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

boot/bootutil/src/loader.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -917,10 +917,9 @@ boot_validated_swap_type(struct boot_loader_state *state,
917917
#if defined(PM_S1_ADDRESS) || defined(CONFIG_SOC_NRF5340_CPUAPP)
918918
const struct flash_area *secondary_fa =
919919
BOOT_IMG_AREA(state, BOOT_SECONDARY_SLOT);
920-
struct image_header *hdr = (struct image_header *)secondary_fa->fa_off;
921-
uint32_t vtable_addr = 0;
922-
uint32_t *vtable = 0;
920+
struct image_header *hdr = boot_img_hdr(state, BOOT_SECONDARY_SLOT);
923921
uint32_t reset_addr = 0;
922+
int rc = 0;
924923
/* Patch needed for NCS. Since image 0 (the app) and image 1 (the other
925924
* B1 slot S0 or S1) share the same secondary slot, we need to check
926925
* whether the update candidate in the secondary slot is intended for
@@ -930,16 +929,19 @@ boot_validated_swap_type(struct boot_loader_state *state,
930929
*/
931930

932931
if (hdr->ih_magic == IMAGE_MAGIC) {
933-
vtable_addr = (uint32_t)hdr + hdr->ih_hdr_size;
934-
vtable = (uint32_t *)(vtable_addr);
935-
reset_addr = vtable[1];
932+
rc = flash_area_read(secondary_fa, hdr->ih_hdr_size +
933+
sizeof(uint32_t), &reset_addr,
934+
sizeof(reset_addr));
935+
if (rc != 0) {
936+
return BOOT_SWAP_TYPE_FAIL;
937+
}
936938
#ifdef PM_S1_ADDRESS
937939
#ifdef PM_CPUNET_B0N_ADDRESS
938940
if(reset_addr < PM_CPUNET_B0N_ADDRESS)
939941
#endif
940942
{
941943
const struct flash_area *primary_fa;
942-
int rc = flash_area_open(flash_area_id_from_multi_image_slot(
944+
rc = flash_area_open(flash_area_id_from_multi_image_slot(
943945
BOOT_CURR_IMG(state),
944946
BOOT_PRIMARY_SLOT),
945947
&primary_fa);
@@ -975,16 +977,19 @@ boot_validated_swap_type(struct boot_loader_state *state,
975977
upgrade_valid = true;
976978
}
977979

978-
#if defined(CONFIG_SOC_NRF5340_CPUAPP) && defined(PM_CPUNET_B0N_ADDRESS)
980+
#if defined(CONFIG_SOC_NRF5340_CPUAPP) && defined(PM_CPUNET_B0N_ADDRESS) \
981+
&& !defined(CONFIG_NRF53_MULTI_IMAGE_UPDATE)
979982
/* If the update is valid, and it targets the network core: perform the
980983
* update and indicate to the caller of this function that no update is
981984
* available
982985
*/
983986
if (upgrade_valid && reset_addr > PM_CPUNET_B0N_ADDRESS) {
987+
struct image_header *hdr = (struct image_header *)secondary_fa->fa_off;
988+
uint32_t vtable_addr = (uint32_t)hdr + hdr->ih_hdr_size;
989+
uint32_t *net_core_fw_addr = (uint32_t *)(vtable_addr);
984990
uint32_t fw_size = hdr->ih_img_size;
985-
986991
BOOT_LOG_INF("Starting network core update");
987-
int rc = pcd_network_core_update(vtable, fw_size);
992+
rc = pcd_network_core_update(net_core_fw_addr, fw_size);
988993

989994
if (rc != 0) {
990995
swap_type = BOOT_SWAP_TYPE_FAIL;

0 commit comments

Comments
 (0)