Skip to content
Open
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
37 changes: 34 additions & 3 deletions subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,20 @@
*/
if (image == img_mgmt_active_image() && query_slot == active_slot) {
flags = IMG_MGMT_STATE_F_ACTIVE;
#ifdef CONFIG_NRF_MCUBOOT_BOOT_REQUEST
} else if (boot_request_get_preferred_slot(image) == active_slot) {
/* Active slot is preferred. All updates are postponed. */
} else if (boot_request_get_preferred_slot(image) == other_slot) {
flags = IMG_MGMT_STATE_F_PENDING | IMG_MGMT_STATE_F_PERMANENT;
#endif /* CONFIG_NRF_MCUBOOT_BOOT_REQUEST */
} else {
struct image_version sver;
struct image_version aver;
int rcs = img_mgmt_read_info(query_slot, &sver, NULL, NULL);
int rca = img_mgmt_read_info(active_slot, &aver, NULL, NULL);

if (rcs == 0 && rca == 0 && img_mgmt_vercmp(&aver, &sver) < 0) {
if (rcs == 0 && rca == 0 && (img_mgmt_vercmp(&aver, &sver) < 0) ||
(img_mgmt_vercmp(&aver, &sver) == 0 && (active_slot > query_slot))) {
flags = IMG_MGMT_STATE_F_PENDING | IMG_MGMT_STATE_F_PERMANENT;
}
}
Expand Down Expand Up @@ -233,6 +240,10 @@
}
#endif /* defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT) */

#ifdef CONFIG_NRF_MCUBOOT_BOOT_REQUEST
#include <bootutil/boot_request.h>
#endif /* CONFIG_NRF_MCUBOOT_BOOT_REQUEST */

#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)
Expand Down Expand Up @@ -285,7 +296,19 @@
if (active_slot_state == DIRECT_XIP_BOOT_ONCE) {
lt = NEXT_BOOT_TYPE_TEST;
}
} else if (img_mgmt_vercmp(&aver, &over) < 0) {
#ifdef CONFIG_NRF_MCUBOOT_BOOT_REQUEST
} else if (boot_request_get_preferred_slot(image) == active_slot) {
/* Active slot is preferred. All updates are postponed. */
} else if (boot_request_get_preferred_slot(image) == other_slot) {
if (other_slot_state == DIRECT_XIP_BOOT_FOREVER) {
return_slot = other_slot;
} else if (other_slot_state == DIRECT_XIP_BOOT_ONCE) {
lt = NEXT_BOOT_TYPE_TEST;
return_slot = other_slot;
}
#endif /* CONFIG_NRF_MCUBOOT_BOOT_REQUEST */
} else if ((img_mgmt_vercmp(&aver, &over) < 0) ||
((img_mgmt_vercmp(&aver, &over) == 0) && (active_slot > other_slot))) {
if (other_slot_state == DIRECT_XIP_BOOT_FOREVER) {
return_slot = other_slot;
} else if (other_slot_state == DIRECT_XIP_BOOT_ONCE) {
Expand All @@ -296,10 +319,18 @@

out:
#else
if (rcs == 0 && rca == 0 && img_mgmt_vercmp(&aver, &over) < 0) {
#ifdef CONFIG_NRF_MCUBOOT_BOOT_REQUEST
if (boot_request_get_preferred_slot(image) == active_slot) {

Check warning on line 323 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)

BRACES

subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c:323 braces {} must be used on all arms of this statement
/* Active slot is preferred. All updates are postponed. */
} else if (boot_request_get_preferred_slot(image) == other_slot) {
return_slot = other_slot;
} else

Check warning on line 327 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)

SUSPECT_CODE_INDENT

subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c:327 suspect code indent for conditional statements (8, 8)
#endif /* CONFIG_NRF_MCUBOOT_BOOT_REQUEST */
if (rcs == 0 && rca == 0 && ((img_mgmt_vercmp(&aver, &over) < 0) ||
((img_mgmt_vercmp(&aver, &over) == 0) && (active_slot > other_slot)))) {
return_slot = other_slot;
}
#endif /* defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT) */

Check notice on line 333 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:333 - if (rcs == 0 && rca == 0 && ((img_mgmt_vercmp(&aver, &over) < 0) || - ((img_mgmt_vercmp(&aver, &over) == 0) && (active_slot > other_slot)))) { - return_slot = other_slot; - } + if (rcs == 0 && rca == 0 && + ((img_mgmt_vercmp(&aver, &over) < 0) || + ((img_mgmt_vercmp(&aver, &over) == 0) && (active_slot > other_slot)))) { + return_slot = other_slot; + }

if (type != NULL) {
*type = lt;
Expand Down
Loading