Skip to content

Commit 9fac199

Browse files
committed
[nrf noup] mgmt: Handle pending slot requests
Interpret pending active slot requests while calculating the expected next slot to boot. Signed-off-by: Tomasz Chyrowicz <[email protected]>
1 parent 90a5bbf commit 9fac199

File tree

1 file changed

+38
-10
lines changed

1 file changed

+38
-10
lines changed

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

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
#include <mgmt/mcumgr/transport/smp_internal.h>
3333
#endif
3434

35+
#ifdef CONFIG_NRF_MCUBOOT_BOOT_REQUEST
36+
#include <bootutil/boot_request.h>
37+
#endif /* CONFIG_NRF_MCUBOOT_BOOT_REQUEST */
38+
3539
LOG_MODULE_DECLARE(mcumgr_img_grp, CONFIG_MCUMGR_GRP_IMG_LOG_LEVEL);
3640

3741
#ifndef CONFIG_MCUMGR_GRP_IMG_FRUGAL_LIST
@@ -140,6 +144,12 @@ img_mgmt_state_flags(int query_slot)
140144
if (image == img_mgmt_active_image() && query_slot == active_slot) {
141145
flags = IMG_MGMT_STATE_F_ACTIVE;
142146
#ifdef CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP
147+
#ifdef CONFIG_NRF_MCUBOOT_BOOT_REQUEST
148+
} else if (boot_request_get_preferred_slot(image) == active_slot) {
149+
/* Active slot is preferred. All updates are postponed. */
150+
} else if (boot_request_get_preferred_slot(image) == other_slot) {
151+
flags = IMG_MGMT_STATE_F_PENDING | IMG_MGMT_STATE_F_PERMANENT;
152+
#endif /* CONFIG_NRF_MCUBOOT_BOOT_REQUEST */
143153
} else {
144154
struct image_version sver;
145155
struct image_version aver;
@@ -294,6 +304,17 @@ int img_mgmt_get_next_boot_slot(int image, enum img_mgmt_next_boot_type *type)
294304
if (active_slot_state == DIRECT_XIP_BOOT_ONCE) {
295305
lt = NEXT_BOOT_TYPE_TEST;
296306
}
307+
#ifdef CONFIG_NRF_MCUBOOT_BOOT_REQUEST
308+
} else if (boot_request_get_preferred_slot(image) == active_slot) {
309+
/* Active slot is preferred. All updates are postponed. */
310+
} else if (boot_request_get_preferred_slot(image) == other_slot) {
311+
if (other_slot_state == DIRECT_XIP_BOOT_FOREVER) {
312+
return_slot = other_slot;
313+
} else if (other_slot_state == DIRECT_XIP_BOOT_ONCE) {
314+
lt = NEXT_BOOT_TYPE_TEST;
315+
return_slot = other_slot;
316+
}
317+
#endif /* CONFIG_NRF_MCUBOOT_BOOT_REQUEST */
297318
} else if ((img_mgmt_vercmp(&aver, &over) < 0) ||
298319
((img_mgmt_vercmp(&aver, &over) == 0) && (active_slot > other_slot))) {
299320
/* Check if MCUboot will select the non-active slot during the next boot.
@@ -312,17 +333,24 @@ int img_mgmt_get_next_boot_slot(int image, enum img_mgmt_next_boot_type *type)
312333

313334
out:
314335
#else
315-
if (rcs == 0 && rca == 0 &&
316-
((img_mgmt_vercmp(&aver, &over) < 0) ||
317-
((img_mgmt_vercmp(&aver, &over) == 0) && (active_slot > other_slot)))) {
318-
/* Check if MCUboot will select the non-active slot during the next boot.
319-
* The logic is as follows:
320-
* - If both slots are valid, a slot with higher version is preferred.
321-
* - If both slots are valid and the versions are equal, a slot with lower number
322-
* is preferred.
323-
*/
336+
#ifdef CONFIG_NRF_MCUBOOT_BOOT_REQUEST
337+
if (boot_request_get_preferred_slot(image) == active_slot) {
338+
/* Active slot is preferred. All updates are postponed. */
339+
} else if (boot_request_get_preferred_slot(image) == other_slot) {
324340
return_slot = other_slot;
325-
}
341+
} else
342+
#endif /* CONFIG_NRF_MCUBOOT_BOOT_REQUEST */
343+
if (rcs == 0 && rca == 0 &&
344+
((img_mgmt_vercmp(&aver, &over) < 0) ||
345+
((img_mgmt_vercmp(&aver, &over) == 0) && (active_slot > other_slot)))) {
346+
/* Check if MCUboot will select the non-active slot during the next boot.
347+
* The logic is as follows:
348+
* - If both slots are valid, a slot with higher version is preferred.
349+
* - If both slots are valid and the versions are equal, a slot with lower
350+
* number is preferred.
351+
*/
352+
return_slot = other_slot;
353+
}
326354
#endif /* defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT) */
327355

328356
if (type != NULL) {

0 commit comments

Comments
 (0)