boot_serial: zephyr: Add optional timeout to enter serial recovery
This PR adds the possibility to only enter the bootloader's
serial recovery mode when a mcumgr command is received within a
given timeout.
Signed-off-by: Wouter Cappelle <wouter.cappelle@crodeon.com>
diff --git a/boot/zephyr/main.c b/boot/zephyr/main.c
index cc726c5..cee7505 100644
--- a/boot/zephyr/main.c
+++ b/boot/zephyr/main.c
@@ -506,7 +506,28 @@
}
#endif
+#ifdef CONFIG_BOOT_SERIAL_WAIT_FOR_DFU
+ /* 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
+ * initial mcumgr command(s) into our buffers
+ */
+ rc = boot_console_init();
+ int timeout_in_ms = CONFIG_BOOT_SERIAL_WAIT_FOR_DFU_TIMEOUT;
+ uint32_t start = k_uptime_get_32();
+#endif
+
FIH_CALL(boot_go, fih_rc, &rsp);
+
+#ifdef CONFIG_BOOT_SERIAL_WAIT_FOR_DFU
+ timeout_in_ms -= (k_uptime_get_32() - start);
+ if( timeout_in_ms <= 0 ) {
+ /* at least one check if time was expired */
+ timeout_in_ms = 1;
+ }
+ boot_serial_check_start(&boot_funcs,timeout_in_ms);
+#endif
+
if (fih_not_eq(fih_rc, FIH_SUCCESS)) {
BOOT_LOG_ERR("Unable to find bootable image");
FIH_PANIC;