Commit 7c4ec9ab authored by Tomasz Chyrowicz's avatar Tomasz Chyrowicz Committed by Dominik Ermel
Browse files

loader: Add boot hook for slot selection



Add a bootloader hook to alter the logic of the active slot selection in
Direct XIP modes.

Signed-off-by: default avatarTomasz Chyrowicz <tomasz.chyrowicz@nordicsemi.no>
parent 94d85f91
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -82,6 +82,18 @@

#endif /* MCUBOOT_BOOT_GO_HOOKS  */

#ifdef MCUBOOT_FIND_NEXT_SLOT_HOOKS

#define BOOT_HOOK_FIND_SLOT_CALL(f, ret_default, ...) \
    DO_HOOK_CALL(f, ret_default, __VA_ARGS__)

#else

#define BOOT_HOOK_FIND_SLOT_CALL(f, ret_default, ...) \
    HOOK_CALL_NOP(f, ret_default, __VA_ARGS__)

#endif /* MCUBOOT_FIND_NEXT_SLOT_HOOKS */

#ifdef MCUBOOT_FLASH_AREA_HOOKS

#define BOOT_HOOK_FLASH_AREA_CALL(f, ret_default, ...) \
@@ -260,4 +272,16 @@ int flash_area_get_device_id_hook(const struct flash_area *fa,
#define BOOT_RESET_REQUEST_HOOK_CHECK_FAILED	3
#define BOOT_RESET_REQUEST_HOOK_INTERNAL_ERROR	4

/**
 * Finds the preferred slot containing the image.
 *
 * @param[in]   state        Boot loader status information.
 * @param[in]   image        Image, for which the slot should be found.
 * @param[out]  active_slot  Number of the preferred slot.
 *
 * @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);

#endif /*H_BOOTUTIL_HOOKS*/
+12 −2
Original line number Diff line number Diff line
@@ -2818,7 +2818,12 @@ boot_load_and_validate_images(struct boot_loader_state *state)
                break;
            }

            rc = BOOT_HOOK_FIND_SLOT_CALL(boot_find_next_slot_hook, BOOT_HOOK_REGULAR,
                                          state, BOOT_CURR_IMG(state), &active_slot);
            if (rc == BOOT_HOOK_REGULAR) {
                active_slot = find_slot_with_highest_version(state);
            }

            if (active_slot == NO_ACTIVE_SLOT) {
                BOOT_LOG_INF("No slot to load for image %d",
                             BOOT_CURR_IMG(state));
@@ -2865,7 +2870,12 @@ boot_load_and_validate_images(struct boot_loader_state *state)
                break;
            }

            rc = BOOT_HOOK_FIND_SLOT_CALL(boot_find_next_slot_hook, BOOT_HOOK_REGULAR,
                                          state, BOOT_CURR_IMG(state), &active_slot);
            if (rc == BOOT_HOOK_REGULAR) {
                active_slot = find_slot_with_highest_version(state);
            }

            if (active_slot == NO_ACTIVE_SLOT) {
                BOOT_LOG_INF("No slot to load for image %d",
                             BOOT_CURR_IMG(state));