Skip to content

Commit f305f87

Browse files
committed
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 bd9bc00 commit f305f87

File tree

4 files changed

+44
-11
lines changed

4 files changed

+44
-11
lines changed

modules/mcuboot/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ endmenu
7676

7777
config NRF_MCUBOOT_BOOT_REQUEST
7878
bool "MCUboot bootloader requests"
79+
imply MCUMGR_GRP_IMG_NRF
7980
help
8081
Handle bootloader requests.
8182

samples/dfu/ab/prj.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ CONFIG_STATS_NAMES=y
3030
CONFIG_FLASH=y
3131
CONFIG_IMG_MANAGER=y
3232
CONFIG_MCUMGR_GRP_IMG=y
33+
CONFIG_MCUMGR_GRP_IMG_NRF=y
3334
CONFIG_MCUMGR_GRP_OS=y
3435
CONFIG_MCUMGR_GRP_STAT=y
3536

@@ -60,7 +61,6 @@ CONFIG_BT_PERIPHERAL=y
6061
CONFIG_BT_L2CAP_TX_MTU=498
6162
CONFIG_BT_BUF_ACL_RX_SIZE=502
6263
CONFIG_BT_BUF_ACL_TX_SIZE=502
63-
CONFIG_BT_CTLR_DATA_LENGTH_MAX=251
6464

6565
# Enable the Bluetooth mcumgr transport (unauthenticated).
6666
CONFIG_MCUMGR_TRANSPORT_BT=y

samples/zephyr/subsys/mgmt/mcumgr/smp_svr/prj_requests.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ CONFIG_STATS_NAMES=y
3030
CONFIG_FLASH=y
3131
CONFIG_IMG_MANAGER=y
3232
CONFIG_MCUMGR_GRP_IMG=y
33+
CONFIG_MCUMGR_GRP_IMG_NRF=y
3334
CONFIG_MCUMGR_GRP_OS=y
3435
CONFIG_MCUMGR_GRP_STAT=y
3536

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

Lines changed: 41 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) == 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

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

Comments
 (0)