Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 48 additions & 2 deletions subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@
#define DIRECT_XIP_BOOT_FOREVER 3
#endif

#if defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER) && \
CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER > 1

Check notice on line 62 in subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c:62 -#if defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER) && \ +#if defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER) && \
#warning "MCUmgr img mgmt only supports 1 image"
#endif

/**
* Collects information about the specified image slot.
*/
Expand Down Expand Up @@ -196,7 +201,6 @@
#else

#if defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT)

static int read_directxip_state(int slot)
{
struct boot_swap_state bss;
Expand Down Expand Up @@ -229,6 +233,8 @@
}
#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)

Check notice on line 237 in subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c:237 -#if defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP) || \ +#if defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP) || \
int img_mgmt_get_next_boot_slot(int image, enum img_mgmt_next_boot_type *type)
{
struct image_version aver;
Expand Down Expand Up @@ -301,12 +307,14 @@

return return_slot;
}
#endif /* defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP) || \
* defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT)
*/

Check notice on line 312 in subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c:312 -#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) \
#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.
Expand Down Expand Up @@ -494,6 +502,7 @@
/**
* Command handler: image state read
*/
#if !defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER)
int
img_mgmt_state_read(struct smp_streamer *ctxt)
{
Expand Down Expand Up @@ -551,6 +560,43 @@

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);

Check notice on line 573 in subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c:573 -int -img_mgmt_state_read(struct smp_streamer *ctxt) +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); + 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);
}

Check notice on line 593 in subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c:593 - ok = zcbor_tstr_put_lit(zse, "splitStatus") && - zcbor_int32_put(zse, 0); + 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)
{
Expand Down
2 changes: 1 addition & 1 deletion subsys/mgmt/mcumgr/grp/img_mgmt/src/zephyr_img_mgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading