diff --git a/boot/zephyr/Kconfig.serial_recovery b/boot/zephyr/Kconfig.serial_recovery index ddde2c6f..c73573bb 100644 --- a/boot/zephyr/Kconfig.serial_recovery +++ b/boot/zephyr/Kconfig.serial_recovery @@ -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 diff --git a/boot/zephyr/main.c b/boot/zephyr/main.c index 4a672fd1..3f6a87bb 100644 --- a/boot/zephyr/main.c +++ b/boot/zephyr/main.c @@ -64,6 +64,10 @@ const struct boot_uart_funcs boot_funcs = { #include #endif +#ifdef CONFIG_BOOT_SERIAL_PIN_RESET +#include +#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