Skip to content

Commit 5bdac09

Browse files
chrtajfischer-no
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]> Signed-off-by: Dominik Ermel <[email protected]> (cherry picked from commit 9403865)
1 parent 83bc352 commit 5bdac09

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
@@ -940,10 +940,9 @@ boot_validated_swap_type(struct boot_loader_state *state,
940940
#if defined(PM_S1_ADDRESS) || defined(CONFIG_SOC_NRF5340_CPUAPP)
941941
const struct flash_area *secondary_fa =
942942
BOOT_IMG_AREA(state, BOOT_SECONDARY_SLOT);
943-
struct image_header *hdr = (struct image_header *)secondary_fa->fa_off;
944-
uint32_t vtable_addr = 0;
945-
uint32_t *vtable = 0;
943+
struct image_header *hdr = boot_img_hdr(state, BOOT_SECONDARY_SLOT);
946944
uint32_t reset_addr = 0;
945+
int rc = 0;
947946
/* Patch needed for NCS. Since image 0 (the app) and image 1 (the other
948947
* B1 slot S0 or S1) share the same secondary slot, we need to check
949948
* whether the update candidate in the secondary slot is intended for
@@ -953,16 +952,19 @@ boot_validated_swap_type(struct boot_loader_state *state,
953952
*/
954953

955954
if (hdr->ih_magic == IMAGE_MAGIC) {
956-
vtable_addr = (uint32_t)hdr + hdr->ih_hdr_size;
957-
vtable = (uint32_t *)(vtable_addr);
958-
reset_addr = vtable[1];
955+
rc = flash_area_read(secondary_fa, hdr->ih_hdr_size +
956+
sizeof(uint32_t), &reset_addr,
957+
sizeof(reset_addr));
958+
if (rc != 0) {
959+
return BOOT_SWAP_TYPE_FAIL;
960+
}
959961
#ifdef PM_S1_ADDRESS
960962
#ifdef PM_CPUNET_B0N_ADDRESS
961963
if(reset_addr < PM_CPUNET_B0N_ADDRESS)
962964
#endif
963965
{
964966
const struct flash_area *primary_fa;
965-
int rc = flash_area_open(flash_area_id_from_multi_image_slot(
967+
rc = flash_area_open(flash_area_id_from_multi_image_slot(
966968
BOOT_CURR_IMG(state),
967969
BOOT_PRIMARY_SLOT),
968970
&primary_fa);
@@ -998,16 +1000,19 @@ boot_validated_swap_type(struct boot_loader_state *state,
9981000
upgrade_valid = true;
9991001
}
10001002

1001-
#if defined(CONFIG_SOC_NRF5340_CPUAPP) && defined(PM_CPUNET_B0N_ADDRESS)
1003+
#if defined(CONFIG_SOC_NRF5340_CPUAPP) && defined(PM_CPUNET_B0N_ADDRESS) \
1004+
&& !defined(CONFIG_NRF53_MULTI_IMAGE_UPDATE)
10021005
/* If the update is valid, and it targets the network core: perform the
10031006
* update and indicate to the caller of this function that no update is
10041007
* available
10051008
*/
10061009
if (upgrade_valid && reset_addr > PM_CPUNET_B0N_ADDRESS) {
1010+
struct image_header *hdr = (struct image_header *)secondary_fa->fa_off;
1011+
uint32_t vtable_addr = (uint32_t)hdr + hdr->ih_hdr_size;
1012+
uint32_t *net_core_fw_addr = (uint32_t *)(vtable_addr);
10071013
uint32_t fw_size = hdr->ih_img_size;
1008-
10091014
BOOT_LOG_INF("Starting network core update");
1010-
int rc = pcd_network_core_update(vtable, fw_size);
1015+
rc = pcd_network_core_update(net_core_fw_addr, fw_size);
10111016

10121017
if (rc != 0) {
10131018
swap_type = BOOT_SWAP_TYPE_FAIL;

0 commit comments

Comments
 (0)