Skip to content

Commit 4292905

Browse files
tomchynordicjm
authored andcommitted
[nrf noup] boot: Improve bootloader request handling
nrf-squash! [nrf noup] bootloader: Add bootloader requests Improve logic that handles sending bootloader requests as a result of issuing the MCUmgr commands. Signed-off-by: Tomasz Chyrowicz <[email protected]>
1 parent 9b60560 commit 4292905

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

boot/bootutil/src/bootutil_public.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -510,18 +510,25 @@ boot_write_copy_done(const struct flash_area *fap)
510510

511511
#ifdef SEND_BOOT_REQUEST
512512
static int
513-
send_boot_request(uint8_t magic, bool confirm, int image_id, uint32_t slot_id)
513+
send_boot_request(uint8_t magic, uint8_t image_ok, bool confirm, int image_id,
514+
uint32_t slot_id)
514515
{
515516
int rc = BOOT_EBADIMAGE;
516517

517518
/* Handle write-protected active image. */
518519
if ((magic == BOOT_MAGIC_GOOD) || (magic == BOOT_MAGIC_UNSET)) {
519520
if (confirm) {
520521
BOOT_LOG_DBG("Confirm image: %d, %d", image_id, slot_id);
521-
rc = boot_request_confirm_slot(image_id, slot_id);
522+
if ((image_ok != BOOT_FLAG_SET) || (magic != BOOT_MAGIC_GOOD)) {
523+
rc = boot_request_confirm_slot(image_id, slot_id);
524+
} else {
525+
rc = 0;
526+
}
527+
#ifdef CONFIG_NCS_MCUBOOT_BOOT_REQUEST_TEST_SETS_BOOT_PREFERENCE
522528
} else {
523529
BOOT_LOG_DBG("Set image preference: %d, %d", image_id, slot_id);
524530
rc = boot_request_set_preferred_slot(image_id, slot_id);
531+
#endif /* CONFIG_NCS_MCUBOOT_BOOT_REQUEST_TEST_SETS_BOOT_PREFERENCE */
525532
}
526533
if (rc != 0) {
527534
rc = BOOT_EBADIMAGE;
@@ -594,7 +601,8 @@ boot_set_next(const struct flash_area *fa, bool active, bool confirm)
594601
image_id = flash_area_to_image_slot(fa, &slot_id);
595602

596603
#ifdef SEND_BOOT_REQUEST
597-
rc = send_boot_request(slot_state.magic, confirm, image_id, slot_id);
604+
rc = send_boot_request(slot_state.magic, slot_state.image_ok, confirm,
605+
image_id, slot_id);
598606
if ((rc != 0) || active) {
599607
return rc;
600608
}
@@ -686,7 +694,8 @@ boot_set_next(const struct flash_area *fa, bool active, bool confirm)
686694
#ifdef SEND_BOOT_REQUEST
687695
image_id = flash_area_to_image_slot(fa, &slot_id);
688696

689-
rc = send_boot_request(slot_state.magic, confirm, image_id, slot_id);
697+
rc = send_boot_request(slot_state.magic, slot_state.image_ok, confirm,
698+
image_id, slot_id);
690699
if ((rc != 0) || active) {
691700
return rc;
692701
}

boot/zephyr/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,4 +1372,15 @@ config NCS_MCUBOOT_IMG_VALIDATE_ATTEMPT_WAIT_MS
13721372
Time between image validation attempts, in milliseconds.
13731373
Allows for recovery from transient bit flips or similar situations.
13741374

1375+
config NCS_MCUBOOT_BOOT_REQUEST_TEST_SETS_BOOT_PREFERENCE
1376+
bool "Set boot preference if a slot is marked for test"
1377+
help
1378+
This option allows to verify boot preference requests through issuing
1379+
the image test.
1380+
Using this option is not recommended in production systems, because
1381+
it will boot any newly transferred image, even if it has a lower
1382+
version than the current one.
1383+
The rollback protection (using security counters) will still be
1384+
effective.
1385+
13751386
source "Kconfig.zephyr"

0 commit comments

Comments
 (0)