Skip to content

Commit 484a6f3

Browse files
tomchynordicjm
authored andcommitted
[nrf noup] Handle pending confirm requests
fixup! [nrf noup] bootloader: Add bootloader requests Interpret pending bootloader requests while investigating the confirm flag. Signed-off-by: Tomasz Chyrowicz <[email protected]>
1 parent a8161d7 commit 484a6f3

File tree

3 files changed

+50
-54
lines changed

3 files changed

+50
-54
lines changed

boot/bootutil/src/bootutil_public.c

Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,59 @@ boot_write_image_ok(const struct flash_area *fap)
398398
return boot_write_trailer_flag(fap, off, BOOT_FLAG_SET);
399399
}
400400

401+
#if defined(SEND_BOOT_REQUEST) || (!defined(MCUBOOT_BOOTUTIL_LIB_FOR_DIRECT_XIP))
402+
static int flash_area_to_image_slot(const struct flash_area *fa, uint32_t *slot)
403+
{
404+
int id = flash_area_get_id(fa);
405+
#if BOOT_IMAGE_NUMBER > 1
406+
uint8_t i = 0;
407+
408+
for (i = 0; i < BOOT_IMAGE_NUMBER; i++) {
409+
if (FLASH_AREA_IMAGE_PRIMARY(i) == id) {
410+
if (slot != NULL) {
411+
*slot = 0;
412+
}
413+
return i;
414+
} else if (FLASH_AREA_IMAGE_SECONDARY(i) == id) {
415+
if (slot != NULL) {
416+
*slot = 1;
417+
}
418+
return i;
419+
}
420+
}
421+
422+
/* Image not found */
423+
*slot = UINT32_MAX;
424+
#else
425+
(void)fa;
426+
if (slot != NULL) {
427+
if (FLASH_AREA_IMAGE_PRIMARY(0) == id) {
428+
*slot = 0;
429+
} else if (FLASH_AREA_IMAGE_SECONDARY(0) == id) {
430+
*slot = 1;
431+
} else {
432+
*slot = UINT32_MAX;
433+
}
434+
}
435+
#endif
436+
return 0;
437+
}
438+
#endif /* SEND_BOOT_REQUEST || !MCUBOOT_BOOTUTIL_LIB_FOR_DIRECT_XIP */
439+
401440
int
402441
boot_read_image_ok(const struct flash_area *fap, uint8_t *image_ok)
403442
{
443+
#ifdef SEND_BOOT_REQUEST
444+
enum boot_slot slot_id = BOOT_SLOT_NONE;
445+
int image_id = flash_area_to_image_slot(fap, &slot_id);
446+
bool confirm_pending = boot_request_check_confirmed_slot(image_id, slot_id);
447+
448+
if (confirm_pending) {
449+
BOOT_LOG_DBG("Image confirmation pending for image %d slot %d", image_id, slot_id);
450+
*image_ok = BOOT_FLAG_SET;
451+
return 0;
452+
}
453+
#endif /* SEND_BOOT_REQUEST */
404454
return boot_read_flag(fap, image_ok, boot_image_ok_off(fap));
405455
}
406456

@@ -541,47 +591,6 @@ send_boot_request(uint8_t magic, uint8_t image_ok, bool confirm, int image_id,
541591
}
542592
#endif /* SEND_BOOT_REQUEST */
543593

544-
#if defined(SEND_BOOT_REQUEST) || (!defined(MCUBOOT_BOOTUTIL_LIB_FOR_DIRECT_XIP))
545-
static int flash_area_to_image_slot(const struct flash_area *fa, uint32_t *slot)
546-
{
547-
int id = flash_area_get_id(fa);
548-
#if BOOT_IMAGE_NUMBER > 1
549-
uint8_t i = 0;
550-
551-
while (i < BOOT_IMAGE_NUMBER) {
552-
if (FLASH_AREA_IMAGE_PRIMARY(i) == id) {
553-
if (slot != NULL) {
554-
*slot = 0;
555-
}
556-
return i;
557-
} else if (FLASH_AREA_IMAGE_SECONDARY(i) == id) {
558-
if (slot != NULL) {
559-
*slot = 1;
560-
}
561-
return i;
562-
}
563-
564-
++i;
565-
}
566-
567-
/* Image not found */
568-
*slot = UINT32_MAX;
569-
#else
570-
(void)fa;
571-
if (slot != NULL) {
572-
if (FLASH_AREA_IMAGE_PRIMARY(0) == id) {
573-
*slot = 0;
574-
} else if (FLASH_AREA_IMAGE_SECONDARY(0) == id) {
575-
*slot = 1;
576-
} else {
577-
*slot = UINT32_MAX;
578-
}
579-
}
580-
#endif
581-
return 0;
582-
}
583-
#endif /* defined(SEND_BOOT_REQUEST) || (!defined(MCUBOOT_BOOTUTIL_LIB_FOR_DIRECT_XIP)) */
584-
585594
#ifndef MCUBOOT_BOOTUTIL_LIB_FOR_DIRECT_XIP
586595
int
587596
boot_set_next(const struct flash_area *fa, bool active, bool confirm)

boot/bootutil/zephyr/src/boot_request_retention.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,6 @@ int boot_request_set_preferred_slot(uint8_t image, enum boot_slot slot)
236236
sizeof(value));
237237
}
238238

239-
#ifdef CONFIG_FIND_NEXT_SLOT_HOOKS
240239
enum boot_slot boot_request_get_preferred_slot(uint8_t image)
241240
{
242241
uint8_t value = BOOT_REQUEST_SLOT_INVALID;
@@ -265,7 +264,6 @@ enum boot_slot boot_request_get_preferred_slot(uint8_t image)
265264

266265
return BOOT_SLOT_NONE;
267266
}
268-
#endif /* CONFIG_FIND_NEXT_SLOT_HOOKS */
269267

270268
int boot_request_enter_recovery(void)
271269
{

boot/zephyr/Kconfig

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

1444-
config NCS_MCUBOOT_BOOT_REQUEST_TEST_SETS_BOOT_PREFERENCE
1445-
bool "Set boot preference if a slot is marked for test"
1446-
help
1447-
This option allows to verify boot preference requests through issuing
1448-
the image test.
1449-
Using this option is not recommended in production systems, because
1450-
it will boot any newly transferred image, even if it has a lower
1451-
version than the current one.
1452-
The rollback protection (using security counters) will still be
1453-
effective.
1454-
14551444
source "Kconfig.zephyr"

0 commit comments

Comments
 (0)