Commit b3ed5cc6 authored by Ederson de Souza's avatar Ederson de Souza Committed by Jamie
Browse files

boot: New boot_go hook



This new hook allows external modules to override the choice of which
image to boot - it can be used, for instance, to load an image based on
some GPIO state.

If the hook returns FIH_BOOT_HOOK_REGULAR, then normal platform
boot_go() will be run to choose image to boot.

This hook is shielded by a different configuration than other hooks -
MCUBOOT_BOOT_GO_HOOKS, so that it can be enabled independently from
other available hooks.

Support for this new hook was added to Zephyr port.

Signed-off-by: default avatarEderson de Souza <ederson.desouza@intel.com>
parent c9aa7fd9
Loading
Loading
Loading
Loading
+50 −8
Original line number Diff line number Diff line
@@ -34,25 +34,54 @@
#ifndef H_BOOTUTIL_HOOKS
#define H_BOOTUTIL_HOOKS

#ifdef MCUBOOT_IMAGE_ACCESS_HOOKS
#include "bootutil/bootutil.h"
#include "bootutil/fault_injection_hardening.h"

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

#define BOOT_HOOK_CALL_FIH(f, fih_ret_default, fih_rc, ...) \
#define DO_HOOK_CALL_FIH(f, fih_ret_default, fih_rc, ...) \
    do { \
        FIH_CALL(f, fih_rc, __VA_ARGS__); \
    } while(0);

#else

#define BOOT_HOOK_CALL(f, ret_default, ...) ret_default
#define HOOK_CALL_NOP(f, ret_default, ...) ret_default

#define BOOT_HOOK_CALL_FIH(f, fih_ret_default, fih_rc, ...) \
#define HOOK_CALL_FIH_NOP(f, fih_ret_default, fih_rc, ...) \
    do { \
        fih_rc = fih_ret_default; \
    } while(0);

#endif
#ifdef MCUBOOT_IMAGE_ACCESS_HOOKS

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

#define BOOT_HOOK_CALL_FIH(f, fih_ret_default, fih_rc, ...) \
    DO_HOOK_CALL_FIH(f, fih_ret_default, fih_rc, __VA_ARGS__)

#else

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

#define BOOT_HOOK_CALL_FIH(f, fih_ret_default, fih_rc, ...) \
    HOOK_CALL_FIH_NOP(f, fih_ret_default, fih_rc, __VA_ARGS__)

#endif /* MCUBOOT_IMAGE_ACCESS_HOOKS */

#ifdef MCUBOOT_BOOT_GO_HOOKS

#define BOOT_HOOK_GO_CALL_FIH(f, fih_ret_default, fih_rc, ...) \
    DO_HOOK_CALL_FIH(f, fih_ret_default, fih_rc, __VA_ARGS__);

#else

#define BOOT_HOOK_GO_CALL_FIH(f, fih_ret_default, fih_rc, ...) \
    HOOK_CALL_FIH_NOP(f, fih_ret_default, fih_rc, __VA_ARGS__)

#endif /* MCUBOOT_BOOT_GO_HOOKS  */


/** Hook for provide image header data.
 *
@@ -173,6 +202,19 @@ int boot_img_install_stat_hook(int image_index, int slot,
 */
int boot_reset_request_hook(bool force);

/**
 * Hook to implement custom action before boot_go() function.
 *
 * @param rsp boot response structure.
 *
 * @retval FIH_SUCCESS: boot_go() should be skipped, boot response is already
 *         filled.
 *         FIH_FAILURE: boot_go() should be skipped, boot response is already
 *         filled with error.
 *         FIH_BOOT_HOOK_REGULAR: follow the normal execution path.
 */
fih_ret boot_go_hook(struct boot_rsp *rsp);

#define BOOT_RESET_REQUEST_HOOK_BUSY		1
#define BOOT_RESET_REQUEST_HOOK_TIMEOUT		2
#define BOOT_RESET_REQUEST_HOOK_CHECK_FAILED	3
+7 −0
Original line number Diff line number Diff line
@@ -855,6 +855,13 @@ config BOOT_IMAGE_ACCESS_HOOKS
	  update. It is up to the project customization to add required source
	  files to the build.

config BOOT_GO_HOOKS
	bool "Enable hooks for overriding MCUBOOT's boot_go routine"
	help
	  Allow to provide procedures for override or extend native
	  MCUboot's boot_go routine. It is up to the project customization to
	  add required source files to the build.

config MCUBOOT_ACTION_HOOKS
	bool "Enable hooks for responding to MCUboot status changes"
	help
+4 −0
Original line number Diff line number Diff line
@@ -242,6 +242,10 @@
#define MCUBOOT_IMAGE_ACCESS_HOOKS
#endif

#ifdef CONFIG_BOOT_GO_HOOKS
#define MCUBOOT_BOOT_GO_HOOKS
#endif

#ifdef CONFIG_MCUBOOT_VERIFY_IMG_ADDRESS
#define MCUBOOT_VERIFY_IMG_ADDRESS
#endif
+5 −1
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@
#include "bootutil/bootutil_log.h"
#include "bootutil/image.h"
#include "bootutil/bootutil.h"
#include "bootutil/boot_hooks.h"
#include "bootutil/fault_injection_hardening.h"
#include "bootutil/mcuboot_status.h"
#include "flash_map_backend/flash_map_backend.h"
@@ -525,7 +526,10 @@ int main(void)
#endif
#endif

    BOOT_HOOK_GO_CALL_FIH(boot_go_hook, FIH_BOOT_HOOK_REGULAR, fih_rc, &rsp);
    if (FIH_EQ(fih_rc, FIH_BOOT_HOOK_REGULAR)) {
        FIH_CALL(boot_go, fih_rc, &rsp);
    }

#ifdef CONFIG_BOOT_SERIAL_BOOT_MODE
    if (io_detect_boot_mode()) {