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+
3539LOG_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 ) == query_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,27 @@ int img_mgmt_get_next_boot_slot(int image, enum img_mgmt_next_boot_type *type)
316337
317338out :
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 ;
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+ }
358+ #ifdef CONFIG_NRF_MCUBOOT_BOOT_REQUEST
329359 }
360+ #endif /* CONFIG_NRF_MCUBOOT_BOOT_REQUEST */
330361#endif /* defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT) */
331362
332363 if (type != NULL ) {
@@ -643,7 +674,7 @@ static int img_mgmt_set_next_boot_slot_common(int slot, int active_slot, bool co
643674 rc = boot_set_next (fa , slot == active_slot , confirm );
644675 if (rc != 0 ) {
645676 /* Failed to set next slot for boot as desired */
646- LOG_ERR ("Faled boot_set_next with code %d, for slot %d,"
677+ LOG_ERR ("Failed boot_set_next with code %d, for slot %d,"
647678 " with active slot %d and confirm %d" ,
648679 rc , slot , active_slot , confirm );
649680
0 commit comments