Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport v3.7.99-ncs2-branch] [nrf noup] dfu: boot: mcuboot: Fix selecting wrong active slot #2366

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
#endif /* CONFIG_MCUBOOT */
#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
#error Missing partition definitions.
#endif
#endif /* CONFIG_MCUBOOT */

#define ACTIVE_SLOT_FLASH_AREA_ID ACTIVE_SLOT_ID
#endif /* CONFIG_MCUBOOT_APPLICATION_IMAGE_NUMBER != -1 */
#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
Loading