]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
autoboot: Fix inconsistent countdown output
authorSam Protsenko <semen.protsenko@linaro.org>
Mon, 27 Oct 2025 00:24:58 +0000 (19:24 -0500)
committerTom Rini <trini@konsulko.com>
Fri, 5 Dec 2025 22:23:54 +0000 (16:23 -0600)
Commit 5f70be08b015 ("Fix autoboot countdown printing wrong") introduces
inconsistency in how the countdown is displayed. For example, in case
when BOOTDELAY=5, the next output is observed during the boot:

    Hit any key to stop autoboot:  5
    Hit any key to stop autoboot: 4
    Hit any key to stop autoboot: 3

That happens due to different printf format (%2d vs %1d). Moreover, the
mentioned commit fails to handle the case when the user is holding some
key before the countdown is shown. E.g. if BOOTDELAY=101, the next
malformed output is being produced:

    Hit any key to stop autoboot: 1 0

That's because the fast path code wasn't modified accordingly, and still
tries to erase the number using '\b\b\b' format.

Fix both issues by introducing a dedicated routine for printing the
whole countdown line.

Fixes: 5f70be08b015 ("Fix autoboot countdown printing wrong")
Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: David Zang <davidzangcs@gmail.com>
common/autoboot.c

index e39f4a32f9572602a99ea79ee5a737f319ee11c2..1783ef92c94cbf6c0fd26c7bd73e3381fcf6ac0b 100644 (file)
@@ -5,6 +5,7 @@
  */
 
 #include <config.h>
+#include <ansi.h>
 #include <autoboot.h>
 #include <bootretry.h>
 #include <cli.h>
@@ -376,19 +377,24 @@ static int abortboot_key_sequence(int bootdelay)
        return abort;
 }
 
+static void print_boot_delay(int bootdelay)
+{
+       printf(ANSI_CLEAR_LINE "\rHit any key to stop autoboot: %d", bootdelay);
+}
+
 static int abortboot_single_key(int bootdelay)
 {
        int abort = 0;
        unsigned long ts;
 
-       printf("Hit any key to stop autoboot: %2d ", bootdelay);
+       print_boot_delay(bootdelay);
 
        /*
         * Check if key already pressed
         */
        if (tstc()) {   /* we got a key press   */
                getchar();      /* consume input        */
-               puts("\b\b\b 0");
+               print_boot_delay(0);
                abort = 1;      /* don't auto boot      */
        }
 
@@ -410,7 +416,7 @@ static int abortboot_single_key(int bootdelay)
                        udelay(10000);
                } while (!abort && get_timer(ts) < 1000);
 
-               printf("\rHit any key to stop autoboot: %1d\033[K", bootdelay);
+               print_boot_delay(bootdelay);
        }
 
        putc('\n');