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
2 changes: 1 addition & 1 deletion boot/bootutil/include/bootutil/boot_hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,6 @@ int flash_area_get_device_id_hook(const struct flash_area *fa,
* @return 0 if a slot was requested;
* BOOT_HOOK_REGULAR follow the normal execution path.
*/
int boot_find_next_slot_hook(struct boot_loader_state *state, uint8_t image, uint32_t *active_slot);
int boot_find_next_slot_hook(struct boot_loader_state *state, uint8_t image, enum boot_slot *active_slot);

#endif /*H_BOOTUTIL_HOOKS*/
11 changes: 6 additions & 5 deletions boot/bootutil/include/bootutil/boot_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ extern "C" {

#include <stdint.h>
#include <stdbool.h>
#include <bootutil/bootutil_public.h>

/** Special value, indicating that there is no preferred slot. */
#define BOOT_REQUEST_NO_PREFERRED_SLOT UINT32_MAX
Expand All @@ -25,7 +26,7 @@ extern "C" {
*
* @return 0 if requested, negative error code otherwise.
*/
int boot_request_confirm_slot(uint8_t image, uint32_t slot);
int boot_request_confirm_slot(uint8_t image, enum boot_slot slot);

/**
* @brief Request a bootloader to boot the specified slot of an image.
Expand All @@ -35,7 +36,7 @@ int boot_request_confirm_slot(uint8_t image, uint32_t slot);
*
* @return 0 if requested, negative error code otherwise.
*/
int boot_request_set_preferred_slot(uint8_t image, uint32_t slot);
int boot_request_set_preferred_slot(uint8_t image, enum boot_slot slot);

/**
* @brief Request a bootloader to boot recovery image.
Expand All @@ -59,16 +60,16 @@ int boot_request_enter_firmware_loader(void);
*
* @return true if requested, false otherwise.
*/
bool boot_request_check_confirmed_slot(uint8_t image, uint32_t slot);
bool boot_request_check_confirmed_slot(uint8_t image, enum boot_slot slot);

/**
* @brief Find if there is a request to boot certain slot of the specified image.
*
* @param[in] image Image number.
*
* @return slot number if requested, BOOT_REQUEST_NO_PREFERRED_SLOT otherwise.
* @return slot number if requested, BOOT_SLOT_NONE otherwise.
*/
uint32_t boot_request_get_preferred_slot(uint8_t image);
enum boot_slot boot_request_get_preferred_slot(uint8_t image);

/**
* @brief Check if there is a request to boot recovery image.
Expand Down
2 changes: 1 addition & 1 deletion boot/bootutil/src/bootutil_public.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ boot_write_copy_done(const struct flash_area *fap)
#ifdef SEND_BOOT_REQUEST
static int
send_boot_request(uint8_t magic, uint8_t image_ok, bool confirm, int image_id,
uint32_t slot_id)
enum boot_slot slot_id)
{
int rc = BOOT_EBADIMAGE;

Expand Down
30 changes: 15 additions & 15 deletions boot/bootutil/zephyr/src/boot_request_retention.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ int boot_request_clear(void)
return retention_clear(bootloader_request_dev);
}

int boot_request_confirm_slot(uint8_t image, uint32_t slot)
int boot_request_confirm_slot(uint8_t image, enum boot_slot slot)
{
uint8_t value = BOOT_REQUEST_SLOT_INVALID;
size_t req_entry;
Expand All @@ -167,10 +167,10 @@ int boot_request_confirm_slot(uint8_t image, uint32_t slot)
}

switch (slot) {
case 0:
case BOOT_SLOT_PRIMARY:
value = BOOT_REQUEST_SLOT_PRIMARY;
break;
case 1:
case BOOT_SLOT_SECONDARY:
value = BOOT_REQUEST_SLOT_SECONDARY;
break;
default:
Expand All @@ -181,7 +181,7 @@ int boot_request_confirm_slot(uint8_t image, uint32_t slot)
sizeof(value));
}

bool boot_request_check_confirmed_slot(uint8_t image, uint32_t slot)
bool boot_request_check_confirmed_slot(uint8_t image, enum boot_slot slot)
{
uint8_t value = BOOT_REQUEST_SLOT_INVALID;
size_t req_entry;
Expand All @@ -200,17 +200,17 @@ bool boot_request_check_confirmed_slot(uint8_t image, uint32_t slot)

switch (value) {
case BOOT_REQUEST_SLOT_PRIMARY:
return (slot == 0);
return (slot == BOOT_SLOT_PRIMARY);
case BOOT_REQUEST_SLOT_SECONDARY:
return (slot == 1);
return (slot == BOOT_SLOT_SECONDARY);
default:
break;
}

return false;
}

int boot_request_set_preferred_slot(uint8_t image, uint32_t slot)
int boot_request_set_preferred_slot(uint8_t image, enum boot_slot slot)
{
uint8_t value = BOOT_REQUEST_SLOT_INVALID;
size_t req_entry;
Expand All @@ -222,10 +222,10 @@ int boot_request_set_preferred_slot(uint8_t image, uint32_t slot)
}

switch (slot) {
case 0:
case BOOT_SLOT_PRIMARY:
value = BOOT_REQUEST_SLOT_PRIMARY;
break;
case 1:
case BOOT_SLOT_SECONDARY:
value = BOOT_REQUEST_SLOT_SECONDARY;
break;
default:
Expand All @@ -237,33 +237,33 @@ int boot_request_set_preferred_slot(uint8_t image, uint32_t slot)
}

#ifdef CONFIG_FIND_NEXT_SLOT_HOOKS
uint32_t boot_request_get_preferred_slot(uint8_t image)
enum boot_slot boot_request_get_preferred_slot(uint8_t image)
{
uint8_t value = BOOT_REQUEST_SLOT_INVALID;
size_t req_entry;
int ret;

ret = boot_request_entry_find(BOOT_REQUEST_IMG_PREFERENCE, image, &req_entry);
if (ret != 0) {
return BOOT_REQUEST_NO_PREFERRED_SLOT;
return BOOT_SLOT_NONE;
}

ret = retention_read(bootloader_request_dev, req_entry * sizeof(value), (void *)&value,
sizeof(value));
if (ret != 0) {
return BOOT_REQUEST_NO_PREFERRED_SLOT;
return BOOT_SLOT_NONE;
}

switch (value) {
case BOOT_REQUEST_SLOT_PRIMARY:
return 0;
return BOOT_SLOT_PRIMARY;
case BOOT_REQUEST_SLOT_SECONDARY:
return 1;
return BOOT_SLOT_SECONDARY;
default:
break;
}

return BOOT_REQUEST_NO_PREFERRED_SLOT;
return BOOT_SLOT_NONE;
}
#endif /* CONFIG_FIND_NEXT_SLOT_HOOKS */

Expand Down
3 changes: 2 additions & 1 deletion boot/zephyr/hooks_sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ int boot_img_install_stat_hook(int image_index, int slot, int *img_install_stat)
return BOOT_HOOK_REGULAR;
}

int boot_find_next_slot_hook(struct boot_loader_state *state, uint8_t image, uint32_t *active_slot)
int boot_find_next_slot_hook(struct boot_loader_state *state, uint8_t image,
enum boot_slot *active_slot)
{
return BOOT_HOOK_REGULAR;
}
4 changes: 2 additions & 2 deletions boot/zephyr/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ static int boot_prevalidate(void)
{
#ifdef CONFIG_NRF_MCUBOOT_BOOT_REQUEST
uint8_t image_index;
uint32_t slot;
enum boot_slot slot;
uint32_t area_id;
const struct flash_area *fap;
int rc = boot_request_init();
Expand All @@ -626,7 +626,7 @@ static int boot_prevalidate(void)
}

for (image_index = 0; image_index < BOOT_IMAGE_NUMBER; ++image_index) {
for (slot = 0; slot < BOOT_REQUEST_NUM_SLOTS; slot++) {
for (slot = BOOT_SLOT_PRIMARY; slot < BOOT_SLOT_COUNT; slot++) {
if (boot_request_check_confirmed_slot(image_index, slot)) {
BOOT_LOG_DBG("Confirm image: %d slot: %d due to bootloader request.",
image_index, slot);
Expand Down