Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 50 additions & 41 deletions boot/bootutil/src/bootutil_public.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,59 @@ boot_write_image_ok(const struct flash_area *fap)
return boot_write_trailer_flag(fap, off, BOOT_FLAG_SET);
}

#if defined(SEND_BOOT_REQUEST) || (!defined(MCUBOOT_BOOTUTIL_LIB_FOR_DIRECT_XIP))
static int flash_area_to_image_slot(const struct flash_area *fa, uint32_t *slot)
{
int id = flash_area_get_id(fa);
#if BOOT_IMAGE_NUMBER > 1
uint8_t i = 0;

for (i = 0; i < BOOT_IMAGE_NUMBER; i++) {
if (FLASH_AREA_IMAGE_PRIMARY(i) == id) {
if (slot != NULL) {
*slot = 0;
}
return i;
} else if (FLASH_AREA_IMAGE_SECONDARY(i) == id) {
if (slot != NULL) {
*slot = 1;
}
return i;
}
}

/* Image not found */
*slot = UINT32_MAX;
#else
(void)fa;
if (slot != NULL) {
if (FLASH_AREA_IMAGE_PRIMARY(0) == id) {
*slot = 0;
} else if (FLASH_AREA_IMAGE_SECONDARY(0) == id) {
*slot = 1;
} else {
*slot = UINT32_MAX;
}
}
#endif
return 0;
}
#endif /* SEND_BOOT_REQUEST || !MCUBOOT_BOOTUTIL_LIB_FOR_DIRECT_XIP */

int
boot_read_image_ok(const struct flash_area *fap, uint8_t *image_ok)
{
#ifdef SEND_BOOT_REQUEST
enum boot_slot slot_id = BOOT_SLOT_NONE;
int image_id = flash_area_to_image_slot(fap, &slot_id);
bool confirm_pending = boot_request_check_confirmed_slot(image_id, slot_id);

if (confirm_pending) {
BOOT_LOG_DBG("Image confirmation pending for image %d slot %d", image_id, slot_id);
*image_ok = BOOT_FLAG_SET;
return 0;
}
#endif /* SEND_BOOT_REQUEST */
return boot_read_flag(fap, image_ok, boot_image_ok_off(fap));
}

Expand Down Expand Up @@ -541,47 +591,6 @@ send_boot_request(uint8_t magic, uint8_t image_ok, bool confirm, int image_id,
}
#endif /* SEND_BOOT_REQUEST */

#if defined(SEND_BOOT_REQUEST) || (!defined(MCUBOOT_BOOTUTIL_LIB_FOR_DIRECT_XIP))
static int flash_area_to_image_slot(const struct flash_area *fa, uint32_t *slot)
{
int id = flash_area_get_id(fa);
#if BOOT_IMAGE_NUMBER > 1
uint8_t i = 0;

while (i < BOOT_IMAGE_NUMBER) {
if (FLASH_AREA_IMAGE_PRIMARY(i) == id) {
if (slot != NULL) {
*slot = 0;
}
return i;
} else if (FLASH_AREA_IMAGE_SECONDARY(i) == id) {
if (slot != NULL) {
*slot = 1;
}
return i;
}

++i;
}

/* Image not found */
*slot = UINT32_MAX;
#else
(void)fa;
if (slot != NULL) {
if (FLASH_AREA_IMAGE_PRIMARY(0) == id) {
*slot = 0;
} else if (FLASH_AREA_IMAGE_SECONDARY(0) == id) {
*slot = 1;
} else {
*slot = UINT32_MAX;
}
}
#endif
return 0;
}
#endif /* defined(SEND_BOOT_REQUEST) || (!defined(MCUBOOT_BOOTUTIL_LIB_FOR_DIRECT_XIP)) */

#ifndef MCUBOOT_BOOTUTIL_LIB_FOR_DIRECT_XIP
int
boot_set_next(const struct flash_area *fa, bool active, bool confirm)
Expand Down
2 changes: 0 additions & 2 deletions boot/bootutil/zephyr/src/boot_request_retention.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ int boot_request_set_preferred_slot(uint8_t image, enum boot_slot slot)
sizeof(value));
}

#ifdef CONFIG_FIND_NEXT_SLOT_HOOKS
enum boot_slot boot_request_get_preferred_slot(uint8_t image)
{
uint8_t value = BOOT_REQUEST_SLOT_INVALID;
Expand Down Expand Up @@ -265,7 +264,6 @@ enum boot_slot boot_request_get_preferred_slot(uint8_t image)

return BOOT_SLOT_NONE;
}
#endif /* CONFIG_FIND_NEXT_SLOT_HOOKS */

int boot_request_enter_recovery(void)
{
Expand Down
11 changes: 0 additions & 11 deletions boot/zephyr/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1441,15 +1441,4 @@ config NCS_MCUBOOT_IMG_VALIDATE_ATTEMPT_WAIT_MS
Time between image validation attempts, in milliseconds.
Allows for recovery from transient bit flips or similar situations.

config NCS_MCUBOOT_BOOT_REQUEST_TEST_SETS_BOOT_PREFERENCE
bool "Set boot preference if a slot is marked for test"
help
This option allows to verify boot preference requests through issuing
the image test.
Using this option is not recommended in production systems, because
it will boot any newly transferred image, even if it has a lower
version than the current one.
The rollback protection (using security counters) will still be
effective.

source "Kconfig.zephyr"