Commit 35941fea authored by Jamie McCrae's avatar Jamie McCrae Committed by Dominik Ermel
Browse files

boot: zephyr: Add pin reset serial recovery entrance method



Adds an optional method for entering serial recovery mode by use
of a pin reset.

Signed-off-by: default avatarJamie McCrae <jamie.mccrae@nordicsemi.no>
parent fd79db3a
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -191,6 +191,13 @@ config BOOT_SERIAL_NO_APPLICATION
	  Allows for entering serial recovery mode if there is no bootable
	  application that the bootloader can jump to.

config BOOT_SERIAL_PIN_RESET
	bool "Check for device reset by pin"
	select HWINFO
	help
	  Checks if the module reset was caused by the reset pin and will
	  remain in bootloader serial recovery mode if it was.

endmenu

config BOOT_SERIAL_IMG_GRP_HASH
+29 −1
Original line number Diff line number Diff line
@@ -64,6 +64,10 @@ const struct boot_uart_funcs boot_funcs = {
#include <arm_cleanup.h>
#endif

#ifdef CONFIG_BOOT_SERIAL_PIN_RESET
#include <zephyr/drivers/hwinfo.h>
#endif

/* CONFIG_LOG_MINIMAL is the legacy Kconfig property,
 * replaced by CONFIG_LOG_MODE_MINIMAL.
 */
@@ -129,7 +133,8 @@ BOOT_LOG_MODULE_REGISTER(mcuboot);
#if !defined(CONFIG_BOOT_SERIAL_ENTRANCE_GPIO) && \
    !defined(CONFIG_BOOT_SERIAL_WAIT_FOR_DFU) && \
    !defined(CONFIG_BOOT_SERIAL_BOOT_MODE) && \
    !defined(CONFIG_BOOT_SERIAL_NO_APPLICATION)
    !defined(CONFIG_BOOT_SERIAL_NO_APPLICATION) && \
    !defined(CONFIG_BOOT_SERIAL_PIN_RESET)
#error "Serial recovery selected without an entrance mode set"
#endif
#endif
@@ -481,6 +486,10 @@ void main(void)
    int32_t boot_mode;
#endif

#ifdef CONFIG_BOOT_SERIAL_PIN_RESET
    uint32_t reset_cause;
#endif

    MCUBOOT_WATCHDOG_FEED();

#if !defined(MCUBOOT_DIRECT_XIP)
@@ -519,6 +528,25 @@ void main(void)
    }
#endif

#ifdef CONFIG_BOOT_SERIAL_PIN_RESET
    rc = hwinfo_get_reset_cause(&reset_cause);

    if (rc == 0 && reset_cause == RESET_PIN) {
#ifdef CONFIG_MCUBOOT_INDICATION_LED
        gpio_pin_set_dt(&led0, 1);
#endif

        mcuboot_status_change(MCUBOOT_STATUS_SERIAL_DFU_ENTERED);
        (void)hwinfo_clear_reset_cause();

        BOOT_LOG_INF("Enter the serial recovery mode");
        rc = boot_console_init();
        __ASSERT(rc == 0, "Error initializing boot console.\n");
        boot_serial_start(&boot_funcs);
        __ASSERT(0, "Bootloader serial process was terminated unexpectedly.\n");
    }
#endif

#if defined(CONFIG_BOOT_USB_DFU_GPIO)
    if (detect_pin()) {
#ifdef CONFIG_MCUBOOT_INDICATION_LED