From 7bf1141d3c600f2efc9097168ffb5adf31fd09c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Monda?= Date: Thu, 22 Feb 2024 21:44:59 +0100 Subject: [PATCH] Add BOOT_SERIAL_WAIT_FOR_DFU_ALWAYS Zephyr Kconfig option. --- boot/zephyr/Kconfig.serial_recovery | 10 +++++++++- boot/zephyr/main.c | 8 ++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/boot/zephyr/Kconfig.serial_recovery b/boot/zephyr/Kconfig.serial_recovery index 74bced750..88006cede 100644 --- a/boot/zephyr/Kconfig.serial_recovery +++ b/boot/zephyr/Kconfig.serial_recovery @@ -150,13 +150,21 @@ config BOOT_SERIAL_DETECT_DELAY the one used to place the device in bootloader mode. menuconfig BOOT_SERIAL_WAIT_FOR_DFU - bool "Wait a prescribed duration to see if DFU is invoked by receiving a MCUmgr comand" + bool "Wait a prescribed duration to see if DFU is invoked by receiving a MCUmgr command" depends on BOOT_SERIAL_UART || BOOT_SERIAL_CDC_ACM help If y, MCUboot waits for a prescribed duration of time to allow for DFU to be invoked. The serial recovery can be entered by receiving any mcumgr command. +config BOOT_SERIAL_WAIT_FOR_DFU_ALWAYS + bool "Always enter serial recovery mode upon startup" + depends on BOOT_SERIAL_WAIT_FOR_DFU + help + If y, MCUboot always enters serial recovery mode upon startup for the + duration of BOOT_SERIAL_WAIT_FOR_DFU_TIMEOUT. Otherwise, MCUboot only + enters serial recovery mode if the board was physically reset. + config BOOT_SERIAL_WAIT_FOR_DFU_TIMEOUT int "Duration to wait for the serial DFU timeout in ms" default 500 diff --git a/boot/zephyr/main.c b/boot/zephyr/main.c index c6a0f74ae..3032a8e4b 100644 --- a/boot/zephyr/main.c +++ b/boot/zephyr/main.c @@ -385,8 +385,12 @@ static void boot_serial_enter() BOOT_LOG_INF("Enter the serial recovery mode"); rc = boot_console_init(); __ASSERT(rc == 0, "Error initializing boot console.\n"); +#ifdef CONFIG_BOOT_SERIAL_WAIT_FOR_DFU + boot_serial_check_start(&boot_funcs, CONFIG_BOOT_SERIAL_WAIT_FOR_DFU_TIMEOUT); +#else boot_serial_start(&boot_funcs); __ASSERT(0, "Bootloader serial process was terminated unexpectedly.\n"); +#endif } #endif @@ -464,7 +468,7 @@ int main(void) } #endif -#ifdef CONFIG_BOOT_SERIAL_WAIT_FOR_DFU +#ifdef CONFIG_BOOT_SERIAL_WAIT_FOR_DFU_ALWAYS /* Initialize the boot console, so we can already fill up our buffers while * waiting for the boot image check to finish. This image check, can take * some time, so it's better to reuse thistime to already receive the @@ -490,7 +494,7 @@ int main(void) } #endif -#ifdef CONFIG_BOOT_SERIAL_WAIT_FOR_DFU +#ifdef CONFIG_BOOT_SERIAL_WAIT_FOR_DFU_ALWAYS timeout_in_ms -= (k_uptime_get_32() - start); if( timeout_in_ms <= 0 ) { /* at least one check if time was expired */