Skip to content

Commit 237e9cf

Browse files
committed
[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 237e9cf

File tree

2 files changed

+52
-43
lines changed

2 files changed

+52
-43
lines changed

boot/bootutil/src/bootutil_public.c

Lines changed: 52 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,61 @@ 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+
while (i < BOOT_IMAGE_NUMBER) {
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+
++i;
422+
}
423+
424+
/* Image not found */
425+
*slot = UINT32_MAX;
426+
#else
427+
(void)fa;
428+
if (slot != NULL) {
429+
if (FLASH_AREA_IMAGE_PRIMARY(0) == id) {
430+
*slot = 0;
431+
} else if (FLASH_AREA_IMAGE_SECONDARY(0) == id) {
432+
*slot = 1;
433+
} else {
434+
*slot = UINT32_MAX;
435+
}
436+
}
437+
#endif
438+
return 0;
439+
}
440+
#endif /* SEND_BOOT_REQUEST || !MCUBOOT_BOOTUTIL_LIB_FOR_DIRECT_XIP */
441+
401442
int
402443
boot_read_image_ok(const struct flash_area *fap, uint8_t *image_ok)
403444
{
445+
#ifdef SEND_BOOT_REQUEST
446+
enum boot_slot slot_id = BOOT_SLOT_NONE;
447+
int image_id = flash_area_to_image_slot(fap, &slot_id);
448+
bool confirm_pending = boot_request_check_confirmed_slot(image_id, slot_id);
449+
450+
if (confirm_pending) {
451+
BOOT_LOG_DBG("Image confirmation pending for image %d slot %d", image_id, slot_id);
452+
*image_ok = BOOT_FLAG_SET;
453+
return 0;
454+
}
455+
#endif /* SEND_BOOT_REQUEST */
404456
return boot_read_flag(fap, image_ok, boot_image_ok_off(fap));
405457
}
406458

@@ -541,47 +593,6 @@ send_boot_request(uint8_t magic, uint8_t image_ok, bool confirm, int image_id,
541593
}
542594
#endif /* SEND_BOOT_REQUEST */
543595

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-
585596
#ifndef MCUBOOT_BOOTUTIL_LIB_FOR_DIRECT_XIP
586597
int
587598
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
{

0 commit comments

Comments
 (0)