From 6ba46c0b826dc43cb37f2b02c4540642daae29b0 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Fri, 15 Sep 2023 10:33:44 +0100 Subject: [PATCH] boot_serial: Fix issue with queued commands Fixes an issue whereby multiple commands are received and some are still being processed. This generally arises when a response takes a long time (e.g. when image decryption is required), duplicate commands will now send multiple responses but avoids the bug of future commands being sent to which previous responses are received. Signed-off-by: Jamie McCrae --- boot/boot_serial/src/boot_serial.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/boot/boot_serial/src/boot_serial.c b/boot/boot_serial/src/boot_serial.c index edfff7910..c32a24fb3 100644 --- a/boot/boot_serial/src/boot_serial.c +++ b/boot/boot_serial/src/boot_serial.c @@ -1189,6 +1189,10 @@ boot_serial_read_console(const struct boot_uart_funcs *f,int timeout_in_ms) int max_input; int elapsed_in_ms = 0; +#ifndef MCUBOOT_SERIAL_WAIT_FOR_DFU + bool allow_idle = true; +#endif + boot_uf = f; max_input = sizeof(in_buf); @@ -1200,7 +1204,10 @@ boot_serial_read_console(const struct boot_uart_funcs *f,int timeout_in_ms) * from serial console (if single-thread mode is used). */ #ifndef MCUBOOT_SERIAL_WAIT_FOR_DFU - MCUBOOT_CPU_IDLE(); + if (allow_idle == true) { + MCUBOOT_CPU_IDLE(); + allow_idle = false; + } #endif MCUBOOT_WATCHDOG_FEED(); #ifdef MCUBOOT_SERIAL_WAIT_FOR_DFU @@ -1208,6 +1215,9 @@ boot_serial_read_console(const struct boot_uart_funcs *f,int timeout_in_ms) #endif rc = f->read(in_buf + off, sizeof(in_buf) - off, &full_line); if (rc <= 0 && !full_line) { +#ifndef MCUBOOT_SERIAL_WAIT_FOR_DFU + allow_idle = true; +#endif goto check_timeout; } off += rc;