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: Jamie McCrae <jamie.mccrae@nordicsemi.no>
This commit is contained in:
Jamie McCrae 2023-03-28 10:04:18 +01:00 committed by Dominik Ermel
parent fd79db3a9f
commit 35941feacd
2 changed files with 36 additions and 1 deletions

View File

@ -191,6 +191,13 @@ config BOOT_SERIAL_NO_APPLICATION
Allows for entering serial recovery mode if there is no bootable Allows for entering serial recovery mode if there is no bootable
application that the bootloader can jump to. 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 endmenu
config BOOT_SERIAL_IMG_GRP_HASH config BOOT_SERIAL_IMG_GRP_HASH

View File

@ -64,6 +64,10 @@ const struct boot_uart_funcs boot_funcs = {
#include <arm_cleanup.h> #include <arm_cleanup.h>
#endif #endif
#ifdef CONFIG_BOOT_SERIAL_PIN_RESET
#include <zephyr/drivers/hwinfo.h>
#endif
/* CONFIG_LOG_MINIMAL is the legacy Kconfig property, /* CONFIG_LOG_MINIMAL is the legacy Kconfig property,
* replaced by CONFIG_LOG_MODE_MINIMAL. * replaced by CONFIG_LOG_MODE_MINIMAL.
*/ */
@ -129,7 +133,8 @@ BOOT_LOG_MODULE_REGISTER(mcuboot);
#if !defined(CONFIG_BOOT_SERIAL_ENTRANCE_GPIO) && \ #if !defined(CONFIG_BOOT_SERIAL_ENTRANCE_GPIO) && \
!defined(CONFIG_BOOT_SERIAL_WAIT_FOR_DFU) && \ !defined(CONFIG_BOOT_SERIAL_WAIT_FOR_DFU) && \
!defined(CONFIG_BOOT_SERIAL_BOOT_MODE) && \ !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" #error "Serial recovery selected without an entrance mode set"
#endif #endif
#endif #endif
@ -481,6 +486,10 @@ void main(void)
int32_t boot_mode; int32_t boot_mode;
#endif #endif
#ifdef CONFIG_BOOT_SERIAL_PIN_RESET
uint32_t reset_cause;
#endif
MCUBOOT_WATCHDOG_FEED(); MCUBOOT_WATCHDOG_FEED();
#if !defined(MCUBOOT_DIRECT_XIP) #if !defined(MCUBOOT_DIRECT_XIP)
@ -519,6 +528,25 @@ void main(void)
} }
#endif #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 defined(CONFIG_BOOT_USB_DFU_GPIO)
if (detect_pin()) { if (detect_pin()) {
#ifdef CONFIG_MCUBOOT_INDICATION_LED #ifdef CONFIG_MCUBOOT_INDICATION_LED