Skip to content

Commit ac38411

Browse files
de-nordiccarlescufi
authored andcommitted
mgmt/MCUmgr/grp/img: Rework image list to support DirectXIP
Image list will only report active flag for active image and pending flag for other slot, but only if image in that slot has higher version than currently running image. Signed-off-by: Dominik Ermel <[email protected]>
1 parent ea591e2 commit ac38411

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ LOG_MODULE_DECLARE(mcumgr_img_grp, CONFIG_MCUMGR_GRP_IMG_LOG_LEVEL);
5454
/**
5555
* Collects information about the specified image slot.
5656
*/
57+
#ifndef CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP
5758
uint8_t
5859
img_mgmt_state_flags(int query_slot)
5960
{
@@ -105,6 +106,34 @@ img_mgmt_state_flags(int query_slot)
105106

106107
return flags;
107108
}
109+
#else
110+
uint8_t
111+
img_mgmt_state_flags(int query_slot)
112+
{
113+
uint8_t flags = 0;
114+
int image = query_slot / 2; /* We support max 2 images for now */
115+
int active_slot = img_mgmt_active_slot(image);
116+
117+
/* In case when MCUboot is configured for DirectXIP slot may only be
118+
* active or pending. Slot is marked pending only when version in that slot
119+
* is higher than version of active slot.
120+
*/
121+
if (image == img_mgmt_active_image() && query_slot == active_slot) {
122+
flags = IMG_MGMT_STATE_F_ACTIVE;
123+
} else {
124+
struct image_version sver;
125+
struct image_version aver;
126+
int rcs = img_mgmt_read_info(query_slot, &sver, NULL, NULL);
127+
int rca = img_mgmt_read_info(active_slot, &aver, NULL, NULL);
128+
129+
if (rcs == 0 && rca == 0 && img_mgmt_vercmp(&aver, &sver) < 0) {
130+
flags = IMG_MGMT_STATE_F_PENDING;
131+
}
132+
}
133+
134+
return flags;
135+
}
136+
#endif
108137

109138
/**
110139
* Indicates whether any image slot is pending (i.e., whether a test swap will

0 commit comments

Comments
 (0)