From 87b1bb8916c913e492e1d37156cb8b846481bb1f Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Fri, 4 Jul 2025 09:09:58 +0100 Subject: [PATCH] dfu: img_util: Upload to slot0 if not running from slot0 Fixes an issue for MCUboot DFU whereby images would always be uploaded to slot1 instead of slot0 meaning that updates would never take effect, but retains uploading to slot1 if the application is running from slot0 Signed-off-by: Jamie McCrae --- subsys/dfu/img_util/flash_img.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/subsys/dfu/img_util/flash_img.c b/subsys/dfu/img_util/flash_img.c index 8f287404da3..322174c0c8f 100644 --- a/subsys/dfu/img_util/flash_img.c +++ b/subsys/dfu/img_util/flash_img.c @@ -23,14 +23,18 @@ LOG_MODULE_REGISTER(flash_img, CONFIG_IMG_MANAGER_LOG_LEVEL); #include #endif +#define FIXED_PARTITION_IS_RUNNING_APP_PARTITION(label) \ + (FIXED_PARTITION_OFFSET(label) == CONFIG_FLASH_LOAD_OFFSET) + #include #ifdef CONFIG_TRUSTED_EXECUTION_NONSECURE - #define UPLOAD_FLASH_AREA_LABEL slot1_ns_partition +#define UPLOAD_FLASH_AREA_LABEL slot1_ns_partition #else -#if FIXED_PARTITION_EXISTS(slot1_partition) - #define UPLOAD_FLASH_AREA_LABEL slot1_partition +#if FIXED_PARTITION_EXISTS(slot1_partition) && \ + FIXED_PARTITION_IS_RUNNING_APP_PARTITION(slot0_partition) +#define UPLOAD_FLASH_AREA_LABEL slot1_partition #else - #define UPLOAD_FLASH_AREA_LABEL slot0_partition +#define UPLOAD_FLASH_AREA_LABEL slot0_partition #endif #endif