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 <jamie.mccrae@nordicsemi.no>
diff --git a/boot/boot_serial/src/boot_serial.c b/boot/boot_serial/src/boot_serial.c
index edfff79..c32a24f 100644
--- a/boot/boot_serial/src/boot_serial.c
+++ b/boot/boot_serial/src/boot_serial.c
@@ -1189,6 +1189,10 @@
     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 @@
          * 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 @@
 #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;