Skip to content

Commit 2158297

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 db0f94f commit 2158297

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.
@@ -316,17 +337,24 @@ int img_mgmt_get_next_boot_slot(int image, enum img_mgmt_next_boot_type *type)
316337

317338
out:
318339
#else
319-
if (rcs == 0 && rca == 0 &&
320-
((img_mgmt_vercmp(&aver, &over) < 0) ||
321-
((img_mgmt_vercmp(&aver, &over) == 0) && (active_slot > other_slot)))) {
322-
/* Check if MCUboot will select the non-active slot during the next boot.
323-
* The logic is as follows:
324-
* - If both slots are valid, a slot with higher version is preferred.
325-
* - If both slots are valid and the versions are equal, a slot with lower number
326-
* is preferred.
327-
*/
340+
#ifdef CONFIG_NRF_MCUBOOT_BOOT_REQUEST
341+
if (boot_request_get_preferred_slot(image) == active_slot) {
342+
/* Active slot is preferred. All updates are postponed. */
343+
} else if (boot_request_get_preferred_slot(image) == other_slot) {
328344
return_slot = other_slot;
329-
}
345+
} else
346+
#endif /* CONFIG_NRF_MCUBOOT_BOOT_REQUEST */
347+
if (rcs == 0 && rca == 0 &&
348+
((img_mgmt_vercmp(&aver, &over) < 0) ||
349+
((img_mgmt_vercmp(&aver, &over) == 0) && (active_slot > other_slot)))) {
350+
/* Check if MCUboot will select the non-active slot during the next boot.
351+
* The logic is as follows:
352+
* - If both slots are valid, a slot with higher version is preferred.
353+
* - If both slots are valid and the versions are equal, a slot with lower
354+
* number is preferred.
355+
*/
356+
return_slot = other_slot;
357+
}
330358
#endif /* defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT) */
331359

332360
if (type != NULL) {

0 commit comments

Comments
 (0)