autoboot: Fix inconsistent countdown output
PATCH 1/1 autoboot: Fix inconsistent countdown output
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.
--- common/autoboot.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
common/autoboot.c +9 -3
@@ -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' );
base-commit: fd976ff3a233ae7c6a9f5bec790b02bbbf57bb24
Signature · 1 line
2.39.5
Quoted 19 lines · Sam Protsenko
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: 3That 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.
Quoted 6 lines
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 <[email protected]>---
Just for the context: I also tried experimenting with only erasing the countdown number, to avoid printing the whole line to the serial port each second (as I/O is usually quite slow). The code is below, for the reference. Maybe it works faster, I don't know, but the code is more bulky and it grows the binary by +50 bytes:
e850-96 : all +50 rodata -38 text +88
u-boot: add: 1/0, grow: 1/0 bytes: 88/0 (88)
function old new delta
erase_int - 72 +72
autoboot_command 304 320 +16
The patch I submitted reduces the footprint by 45 bytes:
e850-96 : all -45 rodata -41 text -4
u-boot: add: 0/0, grow: 0/-1 bytes: 0/-4 (-4)
function old new delta
autoboot_command 304 300 -4
So all in all I think the patch I submitted is more elegant than the code below. But FWIW:
8<-------------------------------------------------------------------------->8
common/autoboot.c +20 -3
@@ -5,6 +5,7 @@*/ #include <config.h> +#include <ansi.h> #include <autoboot.h> #include <bootretry.h> #include <cli.h>
@@ -376,19 +377,33 @@ static int abortboot_key_sequence(int bootdelay)return abort; } +static void erase_int (int val) +{ +while (val >9 ) { + val /=10 ; +putc ('\b' ); + } + +putc ('\b' ); +puts (ANSI_CLEAR_LINE_TO_END ); +} +static int abortboot_single_key (int bootdelay) {int abort =0 ;unsigned long ts; +int cur_bootdelay;/* currently printed boot delay */ -printf ("Hit any key to stop autoboot: %2d " , bootdelay); +printf ("Hit any key to stop autoboot: %d" , bootdelay); + cur_bootdelay = bootdelay;/* * Check if key already pressed */ if (tstc ()) {/* we got a key press */ getchar ();/* consume input */ -puts ("\b\b\b 0" ); +erase_int (cur_bootdelay); +putc ('0' ); abort =1 ;/* don't auto boot */ }
@@ -410,7 +425,9 @@ 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); +erase_int (cur_bootdelay); +printf ("%d" , bootdelay); + cur_bootdelay = bootdelay; }putc ('\n' );
Signature · 3 lines
2.39.5 8<-------------------------------------------------------------------------->8
Quoted 22 lines · Sam Protsenko
Quoted 19 lines · Sam Protsenko
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: 3That 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.
Quoted 7 lines
Quoted 6 lines
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 <[email protected]>---
+ Heinrich, Simon
Also, I remember when I suggested using ANSI escape codes back in 2018, Wolfgang wasn't very happy about that [1]. But I noticed those being used in cmd/bootmenu.c and common/menu.c nowadays. What's our stance on this matter currently?
Just a thought: if we don't want to use ANSI escape codes, we can simply get back to using \b and add more spaces in the end of the line to account for large possible countdown values like 100 or 1000. Any thoughts?
Thanks!
Quoted 15 lines · Sam Protsenko
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: 3That 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
Quoted 8 lines
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 <[email protected]>
This seems the reasonable path, given everything in the following parts of the thread, thanks.
Signature · 1 line
Tom
Hi Tom,
Quoted 24 lines · Tom Rini
Quoted 21 lines · Sam Protsenko
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: 3That 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.
Quoted 8 lines
Quoted 2 lines
Fixes 5f70be08b015 ("Fix autoboot countdown printing wrong")Signed-off-by Sam Protsenko <[email protected]>This seems the reasonable path, given everything in the following parts of the thread, thanks.
Reviewed-by Tom Rini <[email protected]>
Since there are no new or outstanding comments for this patch, can you please pull it for the next release?
Thanks!
Quoted 2 lines
--
Tom
Quoted 30 lines · Sam Protsenko
Hi Tom,
Quoted 27 lines · Tom Rini
Quoted 23 lines · Sam Protsenko
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: 3That 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 <[email protected]>
Quoted 8 lines
Quoted 5 lines
This seems the reasonable path, given everything in the following parts of the thread, thanks.
Reviewed-by Tom Rini <[email protected]>Since there are no new or outstanding comments for this patch, can you please pull it for the next release?
I'm going to take this for -next rather than master, soon, as it's just cleaning up some output. Thanks.
Signature · 1 line
Tom
David Zang
Acked-byThank you Sam for the fix.
Quoted 50 lines · Tom Rini
Quoted 7 lines · Sam Protsenko
Hi Tom,
Quoted 4 lines · Tom Rini
Quoted 1 line · Sam Protsenko
Commit
5f70be08b015("Fix autoboot countdown printing wrong")introduces
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
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: 3That happens due to different printf format (%2d vs %1d). Moreover,
the
Quoted 1 line
Quoted 1 line
Quoted 1 line
mentioned commit fails to handle the case when the user is holding
some
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
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
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
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 <[email protected]>Quoted 8 lines
Quoted 5 lines
This seems the reasonable path, given everything in the following parts of the thread, thanks.
Reviewed-by Tom Rini <[email protected]>Since there are no new or outstanding comments for this patch, can you please pull it for the next release?
I'm going to take this for -next rather than master, soon, as it's just cleaning up some output. Thanks.
--
Tom
Quoted 9 lines · Sam Protsenko
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[...]
Applied to u-boot/next, thanks!
[1/1] autoboot: Fix inconsistent countdown output
commit: af38567cadcaa4842d85af179254886a50c93fc9
Signature · 1 line
Tom