Skip to content

Commit

Permalink
[nrf noup] dfu: boot: mcuboot: Fix selecting wrong active slot
Browse files Browse the repository at this point in the history
fixup! [nrf noup] dfu/boot/mcuboot: fix confirmation in case of USE_PARTITION_MANAGER

Fixes this code to correctly check which slot is active, albeit
without firmware loader support

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
  • Loading branch information
nordicjm committed Nov 11, 2024
1 parent a70d6bd commit 539722a
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions subsys/dfu/boot/mcuboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,42 @@
#if USE_PARTITION_MANAGER
#include <pm_config.h>

#if CONFIG_MCUBOOT_APPLICATION_IMAGE_NUMBER != -1
/* Sysbuild */
#ifdef CONFIG_MCUBOOT
/* lib is part of MCUboot -> operate on the primary application slot */
#define ACTIVE_SLOT_FLASH_AREA_ID PM_MCUBOOT_PRIMARY_ID
#else
/* TODO: Add firmware loader support */
/* lib is part of the app -> operate on active slot */
#if defined(CONFIG_NCS_IS_VARIANT_IMAGE)
#define ACTIVE_SLOT_FLASH_AREA_ID PM_MCUBOOT_SECONDARY_ID
#else
#define ACTIVE_SLOT_FLASH_AREA_ID PM_MCUBOOT_PRIMARY_ID
#endif

Check notice on line 52 in subsys/dfu/boot/mcuboot.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/dfu/boot/mcuboot.c:52 -#define ACTIVE_SLOT_FLASH_AREA_ID PM_MCUBOOT_PRIMARY_ID +#define ACTIVE_SLOT_FLASH_AREA_ID PM_MCUBOOT_PRIMARY_ID #else /* TODO: Add firmware loader support */ /* lib is part of the app -> operate on active slot */ #if defined(CONFIG_NCS_IS_VARIANT_IMAGE) -#define ACTIVE_SLOT_FLASH_AREA_ID PM_MCUBOOT_SECONDARY_ID -#else -#define ACTIVE_SLOT_FLASH_AREA_ID PM_MCUBOOT_PRIMARY_ID +#define ACTIVE_SLOT_FLASH_AREA_ID PM_MCUBOOT_SECONDARY_ID +#else +#define ACTIVE_SLOT_FLASH_AREA_ID PM_MCUBOOT_PRIMARY_ID

Check notice on line 52 in subsys/dfu/boot/mcuboot.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/dfu/boot/mcuboot.c:52 -#define ACTIVE_SLOT_FLASH_AREA_ID PM_MCUBOOT_PRIMARY_ID +#define ACTIVE_SLOT_FLASH_AREA_ID PM_MCUBOOT_PRIMARY_ID #else /* TODO: Add firmware loader support */ /* lib is part of the app -> operate on active slot */ #if defined(CONFIG_NCS_IS_VARIANT_IMAGE) -#define ACTIVE_SLOT_FLASH_AREA_ID PM_MCUBOOT_SECONDARY_ID -#else -#define ACTIVE_SLOT_FLASH_AREA_ID PM_MCUBOOT_PRIMARY_ID +#define ACTIVE_SLOT_FLASH_AREA_ID PM_MCUBOOT_SECONDARY_ID +#else +#define ACTIVE_SLOT_FLASH_AREA_ID PM_MCUBOOT_PRIMARY_ID
#endif
#else
/* Legacy child/parent */
#if CONFIG_BUILD_WITH_TFM
#define PM_ADDRESS_OFFSET (PM_MCUBOOT_PAD_SIZE + PM_TFM_SIZE)
#else
#define PM_ADDRESS_OFFSET (PM_MCUBOOT_PAD_SIZE)
#endif

#ifdef CONFIG_MCUBOOT
/* lib is part of MCUboot -> operate on the primart application slot */
#define ACTIVE_SLOT_ID PM_MCUBOOT_PRIMARY_ID
/* lib is part of MCUboot -> operate on the primary application slot */
#define ACTIVE_SLOT_FLASH_AREA_ID PM_MCUBOOT_PRIMARY_ID
#else
/* lib is part of the App -> operate on active slot */
#if (PM_ADDRESS - PM_ADDRESS_OFFSET) == PM_MCUBOOT_PRIMARY_ADDRESS
#define ACTIVE_SLOT_ID PM_MCUBOOT_PRIMARY_ID
#define ACTIVE_SLOT_FLASH_AREA_ID PM_MCUBOOT_PRIMARY_ID
#elif (PM_ADDRESS - PM_ADDRESS_OFFSET) == PM_MCUBOOT_SECONDARY_ADDRESS
#define ACTIVE_SLOT_ID PM_MCUBOOT_SECONDARY_ID
#define ACTIVE_SLOT_FLASH_AREA_ID PM_MCUBOOT_SECONDARY_ID
#else

Check notice on line 71 in subsys/dfu/boot/mcuboot.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/dfu/boot/mcuboot.c:71 - /* lib is part of MCUboot -> operate on the primary application slot */ - #define ACTIVE_SLOT_FLASH_AREA_ID PM_MCUBOOT_PRIMARY_ID -#else - /* lib is part of the App -> operate on active slot */ +/* lib is part of MCUboot -> operate on the primary application slot */ +#define ACTIVE_SLOT_FLASH_AREA_ID PM_MCUBOOT_PRIMARY_ID +#else +/* lib is part of the App -> operate on active slot */ #if (PM_ADDRESS - PM_ADDRESS_OFFSET) == PM_MCUBOOT_PRIMARY_ADDRESS - #define ACTIVE_SLOT_FLASH_AREA_ID PM_MCUBOOT_PRIMARY_ID +#define ACTIVE_SLOT_FLASH_AREA_ID PM_MCUBOOT_PRIMARY_ID #elif (PM_ADDRESS - PM_ADDRESS_OFFSET) == PM_MCUBOOT_SECONDARY_ADDRESS - #define ACTIVE_SLOT_FLASH_AREA_ID PM_MCUBOOT_SECONDARY_ID +#define ACTIVE_SLOT_FLASH_AREA_ID PM_MCUBOOT_SECONDARY_ID

Check notice on line 71 in subsys/dfu/boot/mcuboot.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/dfu/boot/mcuboot.c:71 - /* lib is part of MCUboot -> operate on the primary application slot */ - #define ACTIVE_SLOT_FLASH_AREA_ID PM_MCUBOOT_PRIMARY_ID -#else - /* lib is part of the App -> operate on active slot */ +/* lib is part of MCUboot -> operate on the primary application slot */ +#define ACTIVE_SLOT_FLASH_AREA_ID PM_MCUBOOT_PRIMARY_ID +#else +/* lib is part of the App -> operate on active slot */ #if (PM_ADDRESS - PM_ADDRESS_OFFSET) == PM_MCUBOOT_PRIMARY_ADDRESS - #define ACTIVE_SLOT_FLASH_AREA_ID PM_MCUBOOT_PRIMARY_ID +#define ACTIVE_SLOT_FLASH_AREA_ID PM_MCUBOOT_PRIMARY_ID #elif (PM_ADDRESS - PM_ADDRESS_OFFSET) == PM_MCUBOOT_SECONDARY_ADDRESS - #define ACTIVE_SLOT_FLASH_AREA_ID PM_MCUBOOT_SECONDARY_ID +#define ACTIVE_SLOT_FLASH_AREA_ID PM_MCUBOOT_SECONDARY_ID
#error Missing partition definitions.
#endif
#endif /* CONFIG_MCUBOOT_APPLICATION_IMAGE_NUMBER != -1 */
#endif /* CONFIG_MCUBOOT */

#define ACTIVE_SLOT_FLASH_AREA_ID ACTIVE_SLOT_ID
#else
/* Get active partition. zephyr,code-partition chosen node must be defined */
#define ACTIVE_SLOT_FLASH_AREA_ID DT_FIXED_PARTITION_ID(DT_CHOSEN(zephyr_code_partition))
Expand Down

0 comments on commit 539722a

Please sign in to comment.