Skip to content

Commit

Permalink
mgmt/MCUmgr/grp/img: Add support for three image configuration
Browse files Browse the repository at this point in the history
The commit adds support for uploading images to secondary slots
of three images.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
  • Loading branch information
de-nordic committed Sep 13, 2023
1 parent 8ea58fc commit 7680cce
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 42 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 @@ -46,7 +46,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
65 changes: 30 additions & 35 deletions subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,43 +41,38 @@
#define FIXED_PARTITION_IS_RUNNING_APP_PARTITION(label) \
(FIXED_PARTITION_OFFSET(label) == CONFIG_FLASH_LOAD_OFFSET)

#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

_Static_assert(sizeof(struct image_header) == IMAGE_HEADER_SIZE,
"struct image_header not required size");

LOG_MODULE_REGISTER(mcumgr_img_grp, CONFIG_MCUMGR_GRP_IMG_LOG_LEVEL);

struct img_mgmt_state g_img_mgmt_state;
Expand Down Expand Up @@ -159,7 +154,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
29 changes: 24 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 @@ -25,12 +25,19 @@ 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

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)),
"Missing partitions?");
(FIXED_PARTITION_EXISTS(SLOT2_PARTITION) &&
FIXED_PARTITION_EXISTS(SLOT3_PARTITION) &&
(CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER >= 2 ||
(CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER == 3 &&
FIXED_PARTITION_EXISTS(SLOT4_PARTITION) &&
FIXED_PARTITION_EXISTS(SLOT5_PARTITION)
)
)
), "Missing partitions?");

/**
* Determines if the specified area of flash is completely unwritten.
Expand Down Expand Up @@ -137,6 +144,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 @@ -194,7 +213,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 7680cce

Please sign in to comment.