Skip to content

Commit

Permalink
[nrf fromlist] mgmt/MCUmgr/grp/img: Add support for three image confi…
Browse files Browse the repository at this point in the history
…guration

The commit adds support for uploading images to secondary slots
of three images.

Upstream PR: zephyrproject-rtos/zephyr#59724

(cherry picked from commit a717dd20f3f54bf59d806974714e079f7fdb80bc)
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
  • Loading branch information
de-nordic committed Sep 21, 2023
1 parent 1498d03 commit a0bb599
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 39 deletions.
2 changes: 1 addition & 1 deletion subsys/dfu/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ if !MCUBOOT
config UPDATEABLE_IMAGE_NUMBER
int "Number of updateable images"
default 1
range 1 2
range 1 3
help
If value is set to 2 or greater then, this enables support needed when
application is combined with MCUboot multi-image boot.
Expand Down
2 changes: 1 addition & 1 deletion subsys/mgmt/mcumgr/grp/img_mgmt/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ endif
config MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER
int "Number of supported images"
default UPDATEABLE_IMAGE_NUMBER
range 1 2
range 1 3
help
Sets how many application images are supported (pairs of secondary and primary slots).
Setting this to 2 requires MCUMGR_TRANSPORT_NETBUF_SIZE to be at least 512b.
Expand Down
62 changes: 30 additions & 32 deletions subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,38 +60,36 @@ BUILD_ASSERT(PM_MCUBOOT_PAD_SIZE == PM_MCUBOOT_SECONDARY_PAD_SIZE);
(FIXED_PARTITION_OFFSET(label) == CONFIG_FLASH_LOAD_OFFSET)
#endif /* USE_PARTITION_MANAGER */

#if FIXED_PARTITION_EXISTS(slot0_partition)
#if FIXED_PARTITION_IS_RUNNING_APP_PARTITION(slot0_partition)
#define NUMBER_OF_ACTIVE_IMAGE 0
#endif
#endif

#if !defined(NUMBER_OF_ACTIVE_IMAGE) && FIXED_PARTITION_EXISTS(slot0_ns_partition)
#if FIXED_PARTITION_IS_RUNNING_APP_PARTITION(slot0_ns_partition)
#define NUMBER_OF_ACTIVE_IMAGE 0
#endif
#endif

#if !defined(NUMBER_OF_ACTIVE_IMAGE) && FIXED_PARTITION_EXISTS(slot1_partition)
#if FIXED_PARTITION_IS_RUNNING_APP_PARTITION(slot1_partition)
#define NUMBER_OF_ACTIVE_IMAGE 0
#endif
#endif

#if !defined(NUMBER_OF_ACTIVE_IMAGE) && FIXED_PARTITION_EXISTS(slot2_partition)
#if FIXED_PARTITION_IS_RUNNING_APP_PARTITION(slot2_partition)
#define NUMBER_OF_ACTIVE_IMAGE 1
#endif
#endif

#if !defined(NUMBER_OF_ACTIVE_IMAGE) && FIXED_PARTITION_EXISTS(slot3_partition)
#if FIXED_PARTITION_IS_RUNNING_APP_PARTITION(slot3_partition)
#define NUMBER_OF_ACTIVE_IMAGE 1
#endif
BUILD_ASSERT(sizeof(struct image_header) == IMAGE_HEADER_SIZE,
"struct image_header not required size");

#if CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER >= 2
#if FIXED_PARTITION_EXISTS(slot0_ns_partition) && \
FIXED_PARTITION_IS_RUNNING_APP_PARTITION(slot0_ns_partition)
#define ACTIVE_IMAGE_IS 0
#elif FIXED_PARTITION_EXISTS(slot0_partition) && \
FIXED_PARTITION_IS_RUNNING_APP_PARTITION(slot0_partition)
#define ACTIVE_IMAGE_IS 0
#elif FIXED_PARTITION_EXISTS(slot1_partition) && \
FIXED_PARTITION_IS_RUNNING_APP_PARTITION(slot1_partition)
#define ACTIVE_IMAGE_IS 0
#elif FIXED_PARTITION_EXISTS(slot2_partition) && \
FIXED_PARTITION_IS_RUNNING_APP_PARTITION(slot2_partition)
#define ACTIVE_IMAGE_IS 1
#elif FIXED_PARTITION_EXISTS(slot3_partition) && \
FIXED_PARTITION_IS_RUNNING_APP_PARTITION(slot3_partition)
#define ACTIVE_IMAGE_IS 1
#elif FIXED_PARTITION_EXISTS(slot4_partition) && \
FIXED_PARTITION_IS_RUNNING_APP_PARTITION(slot4_partition)
#define ACTIVE_IMAGE_IS 2
#elif FIXED_PARTITION_EXISTS(slot5_partition) && \
FIXED_PARTITION_IS_RUNNING_APP_PARTITION(slot5_partition)
#define ACTIVE_IMAGE_IS 2
#else
#define ACTIVE_IMAGE_IS 0
#endif

#ifndef NUMBER_OF_ACTIVE_IMAGE
#error "Unsupported code parition is set as active application partition"
#else
#define ACTIVE_IMAGE_IS 0
#endif

LOG_MODULE_REGISTER(mcumgr_img_grp, CONFIG_MCUMGR_GRP_IMG_LOG_LEVEL);
Expand Down Expand Up @@ -173,7 +171,7 @@ int img_mgmt_active_slot(int image)

int img_mgmt_active_image(void)
{
return NUMBER_OF_ACTIVE_IMAGE;
return ACTIVE_IMAGE_IS;
}

/*
Expand Down
36 changes: 31 additions & 5 deletions subsys/mgmt/mcumgr/grp/img_mgmt/src/zephyr_img_mgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,26 @@ LOG_MODULE_DECLARE(mcumgr_img_grp, CONFIG_MCUMGR_GRP_IMG_LOG_LEVEL);
#define SLOT1_PARTITION slot1_partition
#define SLOT2_PARTITION slot2_partition
#define SLOT3_PARTITION slot3_partition
#define SLOT4_PARTITION slot4_partition
#define SLOT5_PARTITION slot5_partition

/* SLOT0_PARTITION and SLOT1_PARTITION are not checked because
* there is not conditional code that depends on them. If they do
* not exist compilation will fail, but in case if some of other
* partitions do not exist, code will compile and will not work
* properly.
*/
#if CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER >= 2
BUILD_ASSERT(FIXED_PARTITION_EXISTS(SLOT2_PARTITION) &&
FIXED_PARTITION_EXISTS(SLOT3_PARTITION),
"Missing partitions?");
#endif

BUILD_ASSERT(CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER == 1 ||
(CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER == 2 &&
FIXED_PARTITION_EXISTS(SLOT2_PARTITION) &&
FIXED_PARTITION_EXISTS(SLOT3_PARTITION)),
#if CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER == 3
BUILD_ASSERT(FIXED_PARTITION_EXISTS(SLOT4_PARTITION) &&
FIXED_PARTITION_EXISTS(SLOT5_PARTITION),
"Missing partitions?");
#endif

/**
* Determines if the specified area of flash is completely unwritten.
Expand Down Expand Up @@ -138,6 +152,18 @@ img_mgmt_flash_area_id(int slot)
break;
#endif

#if FIXED_PARTITION_EXISTS(SLOT4_PARTITION)
case 4:
fa_id = FIXED_PARTITION_ID(SLOT4_PARTITION);
break;
#endif

#if FIXED_PARTITION_EXISTS(SLOT5_PARTITION)
case 5:
fa_id = FIXED_PARTITION_ID(SLOT5_PARTITION);
break;
#endif

default:
fa_id = -1;
break;
Expand Down Expand Up @@ -195,7 +221,7 @@ static int img_mgmt_get_unused_slot_area_id(int slot)
return slot != -1 ? img_mgmt_flash_area_id(slot) : -1;
#endif
}
#elif CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER == 2
#elif CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER >= 2
static int img_mgmt_get_unused_slot_area_id(int image)
{
int area_id = -1;
Expand Down

0 comments on commit a0bb599

Please sign in to comment.