Skip to content

Commit d6c6170

Browse files
chrtade-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]> (cherry picked from commit 68b4648) Signed-off-by: Dominik Ermel <[email protected]>
1 parent 36c37c0 commit d6c6170

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
@@ -921,10 +921,9 @@ boot_validated_swap_type(struct boot_loader_state *state,
921921
#if defined(PM_S1_ADDRESS) || defined(CONFIG_SOC_NRF5340_CPUAPP)
922922
const struct flash_area *secondary_fa =
923923
BOOT_IMG_AREA(state, BOOT_SECONDARY_SLOT);
924-
struct image_header *hdr = (struct image_header *)secondary_fa->fa_off;
925-
uint32_t vtable_addr = 0;
926-
uint32_t *vtable = 0;
924+
struct image_header *hdr = boot_img_hdr(state, BOOT_SECONDARY_SLOT);
927925
uint32_t reset_addr = 0;
926+
int rc = 0;
928927
/* Patch needed for NCS. Since image 0 (the app) and image 1 (the other
929928
* B1 slot S0 or S1) share the same secondary slot, we need to check
930929
* whether the update candidate in the secondary slot is intended for
@@ -934,16 +933,19 @@ boot_validated_swap_type(struct boot_loader_state *state,
934933
*/
935934

936935
if (hdr->ih_magic == IMAGE_MAGIC) {
937-
vtable_addr = (uint32_t)hdr + hdr->ih_hdr_size;
938-
vtable = (uint32_t *)(vtable_addr);
939-
reset_addr = vtable[1];
936+
rc = flash_area_read(secondary_fa, hdr->ih_hdr_size +
937+
sizeof(uint32_t), &reset_addr,
938+
sizeof(reset_addr));
939+
if (rc != 0) {
940+
return BOOT_SWAP_TYPE_FAIL;
941+
}
940942
#ifdef PM_S1_ADDRESS
941943
#ifdef PM_CPUNET_B0N_ADDRESS
942944
if(reset_addr < PM_CPUNET_B0N_ADDRESS)
943945
#endif
944946
{
945947
const struct flash_area *primary_fa;
946-
int rc = flash_area_open(flash_area_id_from_multi_image_slot(
948+
rc = flash_area_open(flash_area_id_from_multi_image_slot(
947949
BOOT_CURR_IMG(state),
948950
BOOT_PRIMARY_SLOT),
949951
&primary_fa);
@@ -979,16 +981,19 @@ boot_validated_swap_type(struct boot_loader_state *state,
979981
upgrade_valid = true;
980982
}
981983

982-
#if defined(CONFIG_SOC_NRF5340_CPUAPP) && defined(PM_CPUNET_B0N_ADDRESS)
984+
#if defined(CONFIG_SOC_NRF5340_CPUAPP) && defined(PM_CPUNET_B0N_ADDRESS) \
985+
&& !defined(CONFIG_NRF53_MULTI_IMAGE_UPDATE)
983986
/* If the update is valid, and it targets the network core: perform the
984987
* update and indicate to the caller of this function that no update is
985988
* available
986989
*/
987990
if (upgrade_valid && reset_addr > PM_CPUNET_B0N_ADDRESS) {
991+
struct image_header *hdr = (struct image_header *)secondary_fa->fa_off;
992+
uint32_t vtable_addr = (uint32_t)hdr + hdr->ih_hdr_size;
993+
uint32_t *net_core_fw_addr = (uint32_t *)(vtable_addr);
988994
uint32_t fw_size = hdr->ih_img_size;
989-
990995
BOOT_LOG_INF("Starting network core update");
991-
int rc = pcd_network_core_update(vtable, fw_size);
996+
rc = pcd_network_core_update(net_core_fw_addr, fw_size);
992997

993998
if (rc != 0) {
994999
swap_type = BOOT_SWAP_TYPE_FAIL;

0 commit comments

Comments
 (0)