diff --git a/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c b/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c index 5ab53dea2df..4ddd741851e 100644 --- a/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c +++ b/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c @@ -58,6 +58,11 @@ LOG_MODULE_DECLARE(mcumgr_img_grp, CONFIG_MCUMGR_GRP_IMG_LOG_LEVEL); #define DIRECT_XIP_BOOT_FOREVER 3 #endif +#if defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER) && \ + CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER > 1 +#warning "MCUmgr img mgmt only supports 1 image" +#endif + /** * Collects information about the specified image slot. */ @@ -196,7 +201,6 @@ int img_mgmt_get_next_boot_slot(int image, enum img_mgmt_next_boot_type *type) #else #if defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT) - static int read_directxip_state(int slot) { struct boot_swap_state bss; @@ -229,6 +233,8 @@ static int read_directxip_state(int slot) } #endif /* defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT) */ +#if defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP) || \ + defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT) int img_mgmt_get_next_boot_slot(int image, enum img_mgmt_next_boot_type *type) { struct image_version aver; @@ -301,12 +307,14 @@ int img_mgmt_get_next_boot_slot(int image, enum img_mgmt_next_boot_type *type) return return_slot; } +#endif /* defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP) || \ + * defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT) + */ #endif /* !defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP) && \ * !defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT) && \ * !defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER) */ - /** * Indicates whether any image slot is pending (i.e., whether a test swap will * happen on the next reboot. @@ -494,6 +502,7 @@ static bool img_mgmt_state_encode_slot(struct smp_streamer *ctxt, uint32_t slot, /** * Command handler: image state read */ +#if !defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER) int img_mgmt_state_read(struct smp_streamer *ctxt) { @@ -551,6 +560,43 @@ img_mgmt_state_read(struct smp_streamer *ctxt) return ok ? MGMT_ERR_EOK : MGMT_ERR_EMSGSIZE; } +#else +int +img_mgmt_state_read(struct smp_streamer *ctxt) +{ + zcbor_state_t *zse = ctxt->writer->zs; + uint32_t i; + bool ok; + + ok = zcbor_tstr_put_lit(zse, "images") && + zcbor_list_start_encode(zse, 2); + + img_mgmt_take_lock(); + + for (i = 0; ok && i < CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER; i++) { + /* _a is active slot, _o is opposite slot */ + int slot_a = img_mgmt_active_slot(i); + int slot_o = img_mgmt_get_opposite_slot(slot_a); + int flags_a = REPORT_SLOT_ACTIVE; + int flags_o = REPORT_SLOT_CONFIRMED; + + ok = img_mgmt_state_encode_slot(ctxt, slot_o, flags_o) && + img_mgmt_state_encode_slot(ctxt, slot_a, flags_a); + } + + /* Ending list encoding for two slots per image */ + ok = ok && zcbor_list_end_encode(zse, 2); + /* splitStatus is always 0 so in frugal list it is not present at all */ + if (!IS_ENABLED(CONFIG_MCUMGR_GRP_IMG_FRUGAL_LIST) && ok) { + ok = zcbor_tstr_put_lit(zse, "splitStatus") && + zcbor_int32_put(zse, 0); + } + + img_mgmt_release_lock(); + + return ok ? MGMT_ERR_EOK : MGMT_ERR_EMSGSIZE; +} +#endif /* !defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER) */ static int img_mgmt_set_next_boot_slot_common(int slot, int active_slot, bool confirm) { diff --git a/subsys/mgmt/mcumgr/grp/img_mgmt/src/zephyr_img_mgmt.c b/subsys/mgmt/mcumgr/grp/img_mgmt/src/zephyr_img_mgmt.c index b43b250ad16..d4972b573cc 100644 --- a/subsys/mgmt/mcumgr/grp/img_mgmt/src/zephyr_img_mgmt.c +++ b/subsys/mgmt/mcumgr/grp/img_mgmt/src/zephyr_img_mgmt.c @@ -140,11 +140,11 @@ img_mgmt_flash_area_id(int slot) fa_id = FIXED_PARTITION_ID(SLOT0_PARTITION); break; -#if !defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER) case 1: fa_id = FIXED_PARTITION_ID(SLOT1_PARTITION); break; +#if !defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER) #if FIXED_PARTITION_EXISTS(SLOT2_PARTITION) case 2: fa_id = FIXED_PARTITION_ID(SLOT2_PARTITION);