Skip to content

Commit a1ba101

Browse files
committed
[nrf fromlist] mgmt: mcumgr: grp: img_mgmt: Show firmware loader slot info
Allows returning image information for the firmware loader image slot, showing version of the application and flags Upstream PR #: 93875 Signed-off-by: Jamie McCrae <[email protected]>
1 parent 8b8c463 commit a1ba101

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

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

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ LOG_MODULE_DECLARE(mcumgr_img_grp, CONFIG_MCUMGR_GRP_IMG_LOG_LEVEL);
5858
#define DIRECT_XIP_BOOT_FOREVER 3
5959
#endif
6060

61+
#if defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER) && \
62+
CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER > 1
63+
#warning "MCUmgr img mgmt only supports 1 image"
64+
#endif
65+
6166
/**
6267
* Collects information about the specified image slot.
6368
*/
@@ -196,7 +201,6 @@ int img_mgmt_get_next_boot_slot(int image, enum img_mgmt_next_boot_type *type)
196201
#else
197202

198203
#if defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT)
199-
200204
static int read_directxip_state(int slot)
201205
{
202206
struct boot_swap_state bss;
@@ -229,6 +233,8 @@ static int read_directxip_state(int slot)
229233
}
230234
#endif /* defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT) */
231235

236+
#if defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP) || \
237+
defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT)
232238
int img_mgmt_get_next_boot_slot(int image, enum img_mgmt_next_boot_type *type)
233239
{
234240
struct image_version aver;
@@ -301,12 +307,14 @@ int img_mgmt_get_next_boot_slot(int image, enum img_mgmt_next_boot_type *type)
301307

302308
return return_slot;
303309
}
310+
#endif /* defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP) || \
311+
* defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT)
312+
*/
304313
#endif /* !defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP) && \
305314
* !defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT) && \
306315
* !defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER)
307316
*/
308317

309-
310318
/**
311319
* Indicates whether any image slot is pending (i.e., whether a test swap will
312320
* happen on the next reboot.
@@ -494,6 +502,7 @@ static bool img_mgmt_state_encode_slot(struct smp_streamer *ctxt, uint32_t slot,
494502
/**
495503
* Command handler: image state read
496504
*/
505+
#if !defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER)
497506
int
498507
img_mgmt_state_read(struct smp_streamer *ctxt)
499508
{
@@ -551,6 +560,43 @@ img_mgmt_state_read(struct smp_streamer *ctxt)
551560

552561
return ok ? MGMT_ERR_EOK : MGMT_ERR_EMSGSIZE;
553562
}
563+
#else
564+
int
565+
img_mgmt_state_read(struct smp_streamer *ctxt)
566+
{
567+
zcbor_state_t *zse = ctxt->writer->zs;
568+
uint32_t i;
569+
bool ok;
570+
571+
ok = zcbor_tstr_put_lit(zse, "images") &&
572+
zcbor_list_start_encode(zse, 2);
573+
574+
img_mgmt_take_lock();
575+
576+
for (i = 0; ok && i < CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER; i++) {
577+
/* _a is active slot, _o is opposite slot */
578+
int slot_a = img_mgmt_active_slot(i);
579+
int slot_o = img_mgmt_get_opposite_slot(slot_a);
580+
int flags_a = REPORT_SLOT_ACTIVE;
581+
int flags_o = REPORT_SLOT_CONFIRMED;
582+
583+
ok = img_mgmt_state_encode_slot(ctxt, slot_o, flags_o) &&
584+
img_mgmt_state_encode_slot(ctxt, slot_a, flags_a);
585+
}
586+
587+
/* Ending list encoding for two slots per image */
588+
ok = ok && zcbor_list_end_encode(zse, 2);
589+
/* splitStatus is always 0 so in frugal list it is not present at all */
590+
if (!IS_ENABLED(CONFIG_MCUMGR_GRP_IMG_FRUGAL_LIST) && ok) {
591+
ok = zcbor_tstr_put_lit(zse, "splitStatus") &&
592+
zcbor_int32_put(zse, 0);
593+
}
594+
595+
img_mgmt_release_lock();
596+
597+
return ok ? MGMT_ERR_EOK : MGMT_ERR_EMSGSIZE;
598+
}
599+
#endif /* !defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER) */
554600

555601
static int img_mgmt_set_next_boot_slot_common(int slot, int active_slot, bool confirm)
556602
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ img_mgmt_flash_area_id(int slot)
140140
fa_id = FIXED_PARTITION_ID(SLOT0_PARTITION);
141141
break;
142142

143-
#if !defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER)
144143
case 1:
145144
fa_id = FIXED_PARTITION_ID(SLOT1_PARTITION);
146145
break;
147146

147+
#if !defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER)
148148
#if FIXED_PARTITION_EXISTS(SLOT2_PARTITION)
149149
case 2:
150150
fa_id = FIXED_PARTITION_ID(SLOT2_PARTITION);

0 commit comments

Comments
 (0)