Skip to contentSkip to conversation

menu: fix the logic checking whether ESC key is pressed

PATCH In review Weijie Gao 3 participants 4 messages Oct 18, 2024 – Oct 21, 2024

lore
Share & tools
lore

Weijie Gao

author
#0 lore raw

PATCH 1/1 menu: fix the logic checking whether ESC key is pressed

It's observed that the bootmenu on a serial console sometimes incorrectly quitted with superfluous characters filled to command line input:

Quoted 10 lines

*** U-Boot Boot Menu ***

1. Startup system (Default)
2. Upgrade firmware
3. Upgrade ATF BL2
4. Upgrade ATF FIP
5. Load image
0. U-Boot console

Quoted 2 lines

Press UP/DOWN to move, ENTER to select, ESC to quit
MT7988> [B

Analysis shows it was caused by the wrong logic of bootmenu_loop:

At first the bootmenu_loop received the first ESC char correctly.

However, during the second call to bootmenu_loop, there's no data in the UART Rx FIFO. Due to the low baudrate, the second char of the down array key sequence hasn't be fully received.

But bootmenu_loop just did a mdelay(10), and then treated it as a single ESC key press event. It didn't even try tstc() again after the 10ms timeout.

This patch fixes this issue by letting bootmenu_loop check tstc() twice.

---
 common/menu.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
common/menu.c +3 -2
index 5fd705039fc..bd2ac3e0ed9 100644
@@ -566,7 +566,7 @@ enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu,
 				struct cli_ch_state *cch)
 {
 	enum bootmenu_key key;
-	int c;
+	int c, errchar = 0;
 	int choice;
 
 	c = cli_ch_process(cch, 0);
@@ -574,7 +574,8 @@ enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu,
 		while (!c && !tstc()) {
 			schedule();
 			mdelay(10);
-			c = cli_ch_process(cch, -ETIMEDOUT);
+			c = cli_ch_process(cch, errchar);
+			errchar = -ETIMEDOUT;
 		}
 		if (!c) {
 			c = getchar();
Signature · 1 line
2.34.1
#1 lore raw

Hi Weijie,

Quoted 62 lines · Weijie Gao

It's observed that the bootmenu on a serial console sometimes incorrectly quitted with superfluous characters filled to command line input:

Quoted 10 lines

*** U-Boot Boot Menu ***

1. Startup system (Default)
2. Upgrade firmware
3. Upgrade ATF BL2
4. Upgrade ATF FIP
5. Load image
0. U-Boot console

Quoted 2 lines

Press UP/DOWN to move, ENTER to select, ESC to quit
MT7988> [B

Analysis shows it was caused by the wrong logic of bootmenu_loop:

At first the bootmenu_loop received the first ESC char correctly.

However, during the second call to bootmenu_loop, there's no data in the UART Rx FIFO. Due to the low baudrate, the second char of the down array key sequence hasn't be fully received.

But bootmenu_loop just did a mdelay(10), and then treated it as a single ESC key press event. It didn't even try tstc() again after the 10ms timeout.

This patch fixes this issue by letting bootmenu_loop check tstc() twice.

---
 common/menu.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
common/menu.c +3 -3
index 5fd705039fc..bd2ac3e0ed9 100644
@@ -566,7 +566,7 @@ enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu,
                                struct cli_ch_state *cch)
 {
        enum bootmenu_key key;
-       int c;
+       int c, errchar = 0;
        int choice;
 
        c = cli_ch_process(cch, 0);
@@ -574,7 +574,8 @@ enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu,
                while (!c && !tstc()) {
                        schedule();
                        mdelay(10);
-                       c = cli_ch_process(cch, -ETIMEDOUT);
+                       c = cli_ch_process(cch, errchar);
+                       errchar = -ETIMEDOUT;
                }
                if (!c) {
                        c = getchar();
--
Quoted 2 lines

2.34.1

This looks reasonable from a first glance, but please can you rebase on -master ?

Regards,
Simon

Tested-by
#2 lore raw

Hi,

Quoted 72 lines · Simon Glass

Hi Weijie,

Quoted 62 lines · Weijie Gao

It's observed that the bootmenu on a serial console sometimes incorrectly quitted with superfluous characters filled to command line input:

Quoted 10 lines

*** U-Boot Boot Menu ***

1. Startup system (Default)
2. Upgrade firmware
3. Upgrade ATF BL2
4. Upgrade ATF FIP
5. Load image
0. U-Boot console

Quoted 2 lines

Press UP/DOWN to move, ENTER to select, ESC to quit
MT7988> [B

Analysis shows it was caused by the wrong logic of bootmenu_loop:

At first the bootmenu_loop received the first ESC char correctly.

However, during the second call to bootmenu_loop, there's no data in the UART Rx FIFO. Due to the low baudrate, the second char of the down array key sequence hasn't be fully received.

But bootmenu_loop just did a mdelay(10), and then treated it as a single ESC key press event. It didn't even try tstc() again after the 10ms timeout.

This patch fixes this issue by letting bootmenu_loop check tstc() twice.

---
 common/menu.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
common/menu.c +3 -3
index 5fd705039fc..bd2ac3e0ed9 100644
@@ -566,7 +566,7 @@ enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu,
                                struct cli_ch_state *cch)
 {
        enum bootmenu_key key;
-       int c;
+       int c, errchar = 0;
        int choice;
 
        c = cli_ch_process(cch, 0);
@@ -574,7 +574,8 @@ enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu,
                while (!c && !tstc()) {
                        schedule();
                        mdelay(10);
-                       c = cli_ch_process(cch, -ETIMEDOUT);
+                       c = cli_ch_process(cch, errchar);
+                       errchar = -ETIMEDOUT;
                }
                if (!c) {
                        c = getchar();
--
Quoted 2 lines

2.34.1

This looks reasonable from a first glance, but please can you rebase on -master ?

Quoted 2 lines

Regards,
Simon

Does this affect eficonfig menu ? I was having some intermittent trouble about the eficonfig menu quitting suddenly before this patch. With this fix applied it's no worse but maybe better, I tried for some minutes to reproduce the previous behaviour and was not able to make the glitch happen.

#3 lore raw
Quoted 83 lines · E Shattow

Hi,

Quoted 4 lines · Simon Glass

Hi Weijie,

On Fri, 18 Oct 2024 at 02:38, Weijie Gao <[email protected]>

Quoted 38 lines · wrote:
Quoted 38 lines

It's observed that the bootmenu on a serial console sometimes incorrectly quitted with superfluous characters filled to command line input:

Quoted 10 lines

*** U-Boot Boot Menu ***

1. Startup system (Default)
2. Upgrade firmware
3. Upgrade ATF BL2
4. Upgrade ATF FIP
5. Load image
0. U-Boot console

Quoted 2 lines

Press UP/DOWN to move, ENTER to select, ESC to quit
MT7988> [B

Analysis shows it was caused by the wrong logic of bootmenu_loop:

At first the bootmenu_loop received the first ESC char correctly.

However, during the second call to bootmenu_loop, there's no data in the UART Rx FIFO. Due to the low baudrate, the second char of the down array key sequence hasn't be fully received.

But bootmenu_loop just did a mdelay(10), and then treated it as a single ESC key press event. It didn't even try tstc() again after the 10ms timeout.

This patch fixes this issue by letting bootmenu_loop check tstc() twice.

---
 common/menu.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Quoted 5 lines

common/menu.c enum bootmenu_key bootmenu_loop(struct

Quoted 5 lines
common/menu.c +0 -0
index 5fd705039fc..bd2ac3e0ed9 100644
@@ -566,7 +566,7 @@ enum bootmenu_key bootmenu_loop(struct

bootmenu_data *menu,

Quoted 9 lines

common/menu.c enum bootmenu_key bootmenu_loop(struct

Quoted 9 lines
common/menu.c +1 -1
                                struct cli_ch_state *cch)
 {
        enum bootmenu_key key;
-       int c;
+       int c, errchar = 0;
        int choice;
 
        c = cli_ch_process(cch, 0);
@@ -574,7 +574,8 @@ enum bootmenu_key bootmenu_loop(struct

bootmenu_data *menu,

Quoted 13 lines
Quoted 10 lines
common/menu.c +2 -2
                while (!c && !tstc()) {
                        schedule();
                        mdelay(10);
-                       c = cli_ch_process(cch, -ETIMEDOUT);
+                       c = cli_ch_process(cch, errchar);
+                       errchar = -ETIMEDOUT;
                }
                if (!c) {
                        c = getchar();
--
Quoted 2 lines

2.34.1

Quoted 1 line

This looks reasonable from a first glance, but please can you

rebase

Quoted 4 lines

on -master ?

Regards,
Simon

Quoted 6 lines

Does this affect eficonfig menu ? I was having some intermittent trouble about the eficonfig menu quitting suddenly before this patch. With this fix applied it's no worse but maybe better, I tried for some
minutes to reproduce the previous behaviour and was not able to make the glitch happen.

I don't have efi environment to test. But I do see this function be called in eficonfig.c (eficonfig_choice_change_boot_order). So I believe this will affect eficonfig menu.

Quoted 2 lines