Skip to contentSkip to conversation

nokia_nx51: Attempts to debug keyboard

PATCH In review Simon Glass 3 participants 15 messages Jun 17, 2023 – Jul 10, 2023

lore
Share & tools
lore
#0 lore raw

cover nokia_nx51: Attempts to debug keyboard

This series is an attempt to get the keyboard working properly with bootmenu.

It fixes the board's tstc() function, which should be in drivers/input

It also adjusts stopping of the menu autodelay - it should only stop when a whole escape sequence is received, not when the first escape character is received. That is pretty minor, so we could drop that patch.

This series also adds some debugging output. This seems to make things work correctly, suggesting that there is some other problem.

I also see this message fairly often:

cyclic function rx51_watchdog took too long: 10000us vs 1000us max

Simon Glass (6):
menu: Re-enable the ANSI codes
nokia_rx51: Correct tstc() implementation
bootmenu: Cancel delay only when a real key is pressed
boobtmenu: Add debugging
getch: debugging
menu: Add debugging

 board/nokia/rx51/rx51.c |  3 +++
 cmd/bootmenu.c          | 19 ++++++++++++-------
 common/cli_getch.c      | 23 ++++++++++++++++++++---
 common/menu.c           |  7 ++++++-
 4 files changed, 41 insertions(+), 11 deletions(-)
Signature · 1 line
2.41.0.162.gfafddb0af9-goog
#1 lore raw

PATCH 1/6 menu: Re-enable the ANSI codes

The intent here was to allow ANSI codes to be disabled, since it was proving impoosible to test operation of the menu code when it kept moving the cursor. Unfortunately this ended up in the patch.

Correct this by enabling ANSI again.

Fixes 32bab0eae51b ("menu: Make use of CLI character processing")

---

 common/menu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
common/menu.c +1 -1
index 94514177e4e9..b55cf7b99967 100644
@@ -15,7 +15,7 @@
 
 #include "menu.h"
 
-#define ansi 0
+#define ansi 1
 
 /*
  * Internally, each item in a menu is represented by a struct menu_item.
Signature · 1 line
2.41.0.162.gfafddb0af9-goog
#2 lore raw

Re: [PATCH 1/6] menu: Re-enable the ANSI codes

Quoted 6 lines · Simon Glass

The intent here was to allow ANSI codes to be disabled, since it was proving impoosible to test operation of the menu code when it kept moving the cursor. Unfortunately this ended up in the patch.

Correct this by enabling ANSI again.

Quoted 7 lines
Fixes 32bab0eae51b ("menu: Make use of CLI character processing")

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#3 lore raw

PATCH 2/6 nokia_rx51: Correct tstc() implementation

In reply to Simon Glass

This returns false even when there are keys in the buffer. Fix it.

---

 board/nokia/rx51/rx51.c | 3 +++
 1 file changed, 3 insertions(+)
board/nokia/rx51/rx51.c +3 -0
index 238b9637badd..138f5a811eb6 100644
@@ -668,6 +668,9 @@ static int rx51_kp_tstc(struct udevice *dev)
 	u8 intr;
 	u8 mods;
 
+	if ((KEYBUF_SIZE + keybuf_tail - keybuf_head) % KEYBUF_SIZE)
+		return 1;
+
 	/* localy lock twl4030 i2c bus */
 	if (test_and_set_bit(0, &twl_i2c_lock))
 		return 0;
Signature · 1 line
2.41.0.162.gfafddb0af9-goog
#4 lore raw

Re: [PATCH 2/6] nokia_rx51: Correct tstc() implementation

Quoted 1 line · On Saturday 17 June 2023 11:49:49 Simon Glass wrote:

This returns false even when there are keys in the buffer.

This is not truth. After scanning HW buffer it returns the correct information if some key is in SW buffer, even when function did not read anything from HW buffer.

So, NAK.

Quoted 25 lines

Fix it.

---

 board/nokia/rx51/rx51.c | 3 +++
 1 file changed, 3 insertions(+)
board/nokia/rx51/rx51.c +3 -0
index 238b9637badd..138f5a811eb6 100644
@@ -668,6 +668,9 @@ static int rx51_kp_tstc(struct udevice *dev)
 	u8 intr;
 	u8 mods;
 
+	if ((KEYBUF_SIZE + keybuf_tail - keybuf_head) % KEYBUF_SIZE)
+		return 1;
+
 	/* localy lock twl4030 i2c bus */
 	if (test_and_set_bit(0, &twl_i2c_lock))
 		return 0;
Signature · 1 line
2.41.0.162.gfafddb0af9-goog
#5 lore raw

Re: [PATCH 2/6] nokia_rx51: Correct tstc() implementation

Hi Pali,

Quoted 9 lines · Pali Rohár
Quoted 1 line · On Saturday 17 June 2023 11:49:49 Simon Glass wrote:

This returns false even when there are keys in the buffer.

This is not truth. After scanning HW buffer it returns the correct information if some key is in SW buffer, even when function did not read anything from HW buffer.

So, NAK.

Why is is reading new chars when it still has some in the buffer?

Do you see i2c errors?

Regards,
Simon

Quoted 26 lines
Quoted 26 lines

Fix it.

---

 board/nokia/rx51/rx51.c | 3 +++
 1 file changed, 3 insertions(+)
board/nokia/rx51/rx51.c +3 -1
index 238b9637badd..138f5a811eb6 100644
@@ -668,6 +668,9 @@ static int rx51_kp_tstc(struct udevice *dev)
      u8 intr;
      u8 mods;
 
+     if ((KEYBUF_SIZE + keybuf_tail - keybuf_head) % KEYBUF_SIZE)
+             return 1;
+
      /* localy lock twl4030 i2c bus */
      if (test_and_set_bit(0, &twl_i2c_lock))
              return 0;
--

2.41.0.162.gfafddb0af9-goog

#6 lore raw

PATCH 3/6 bootmenu: Cancel delay only when a real key is pressed

In reply to Simon Glass

We need to decode the input character before deciding if it is a real key, or just part of an escape sequence. Check this.

---

 common/menu.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
common/menu.c +4 -1
index b55cf7b99967..c81494b3d1f3 100644
@@ -446,11 +446,14 @@ enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu,
 				continue;
 			}
 
-			menu->delay = -1;
 			c = getchar();
 
 			ichar = cli_ch_process(cch, c);
 
+			if (!ichar)
+				continue;
+			menu->delay = -1;
+
 			switch (ichar) {
 			case '\0':
 				key = BKEY_NONE;
Signature · 1 line
2.41.0.162.gfafddb0af9-goog
#7 lore raw

PATCH 4/6 boobtmenu: Add debugging

In reply to Simon Glass

---

 cmd/bootmenu.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
cmd/bootmenu.c +12 -7
index 6baeedc69f91..b2fb119e70f9 100644
@@ -18,6 +18,8 @@
 #include <linux/delay.h>
 #include <linux/string.h>
 
+#define ansi 0
+
 /* maximum bootmenu entries */
 #define MAX_COUNT	99
 
@@ -101,6 +103,7 @@ static char *bootmenu_choice_entry(void *data)
 			/* Some key was pressed, so autoboot was stopped */
 			key = bootmenu_loop(menu, cch);
 		}
+		printf("[got bkey %d]\n", key);
 
 		switch (key) {
 		case BKEY_UP:
@@ -521,9 +524,11 @@ static enum bootmenu_ret bootmenu_show(int delay)
 	/* Default menu entry is always first */
 	menu_default_set(menu, "0");
 
-	puts(ANSI_CURSOR_HIDE);
-	puts(ANSI_CLEAR_CONSOLE);
-	printf(ANSI_CURSOR_POSITION, 1, 1);
+	if (ansi) {
+// 		puts(ANSI_CURSOR_HIDE);
+// 		puts(ANSI_CLEAR_CONSOLE);
+// 		printf(ANSI_CURSOR_POSITION, 1, 1);
+	}
 
 	init = 1;
 
@@ -566,10 +571,10 @@ cleanup:
 	menu_destroy(menu);
 	bootmenu_destroy(bootmenu);
 
-	if (init) {
-		puts(ANSI_CURSOR_SHOW);
-		puts(ANSI_CLEAR_CONSOLE);
-		printf(ANSI_CURSOR_POSITION, 1, 1);
+	if (init && ansi) {
+// 		puts(ANSI_CURSOR_SHOW);
+// 		puts(ANSI_CLEAR_CONSOLE);
+// 		printf(ANSI_CURSOR_POSITION, 1, 1);
 	}
 
 	if (title && command) {
Signature · 1 line
2.41.0.162.gfafddb0af9-goog
#8 lore raw

PATCH 5/6 getch: debugging

In reply to Simon Glass

---

 common/cli_getch.c | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)
common/cli_getch.c +20 -3
index 61d4cb261b81..cd44415a9f67 100644
@@ -6,8 +6,11 @@
  * Copyright 2022 Google LLC
  */
 
+#define LOG_CATEGORY LOGC_CORE
+
 #include <common.h>
 #include <cli.h>
+#include <log.h>
 
 /**
  * enum cli_esc_state_t - indicates what to do with an escape character
@@ -134,6 +137,8 @@ static int cli_ch_esc(struct cli_ch_state *cch, int ichar,
 
 int cli_ch_process(struct cli_ch_state *cch, int ichar)
 {
+	log_debug(" [ichar=%x, esc_len=%d] ", ichar, cch->esc_len);
+
 	/*
 	 * ichar=0x0 when error occurs in U-Boot getchar() or when the caller
 	 * wants to check if there are more characters saved in the escape
@@ -141,12 +146,18 @@ int cli_ch_process(struct cli_ch_state *cch, int ichar)
 	 */
 	if (!ichar) {
 		if (cch->emitting) {
-			if (cch->emit_upto < cch->esc_len)
-				return cch->esc_save[cch->emit_upto++];
+			if (cch->emit_upto < cch->esc_len) {
+				int ch;
+
+				ch = cch->esc_save[cch->emit_upto++];
+				log_debug(" [->%x] ", ch);
+				return ch;
+			}
 			cch->emit_upto = 0;
 			cch->emitting = false;
 			cch->esc_len = 0;
 		}
+		log_debug(" [->0] ");
 		return 0;
 	} else if (ichar == -ETIMEDOUT) {
 		/*
@@ -156,15 +167,19 @@ int cli_ch_process(struct cli_ch_state *cch, int ichar)
 		 */
 		if (cch->esc_len) {
 			cch->esc_len = 0;
+			log_debug(" [->esc] ");
 			return '\e';
 		}
 
 		/* Otherwise there is nothing to return */
+		log_debug(" [->0] ");
 		return 0;
 	}
 
-	if (ichar == '\n' || ichar == '\r')
+	if (ichar == '\n' || ichar == '\r') {
+		log_debug(" [->nl] ");
 		return '\n';
+	}
 
 	/* handle standard linux xterm esc sequences for arrow key, etc. */
 	if (cch->esc_len != 0) {
@@ -186,6 +201,7 @@ int cli_ch_process(struct cli_ch_state *cch, int ichar)
 			cch->esc_save[cch->esc_len++] = ichar;
 			ichar = cch->esc_save[cch->emit_upto++];
 			cch->emitting = true;
+			log_debug(" [->reject %x] ", ichar);
 			return ichar;
 		case ESC_CONVERTED:
 			/* valid escape sequence, return the resulting char */
@@ -205,5 +221,6 @@ int cli_ch_process(struct cli_ch_state *cch, int ichar)
 		return 0;
 	}
 
+	log_debug(" [->%x] ", ichar);
 	return ichar;
 }
Signature · 1 line
2.41.0.162.gfafddb0af9-goog
#9 lore raw

PATCH 6/6 menu: Add debugging

In reply to Simon Glass

---

 common/menu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
common/menu.c +3 -1
index c81494b3d1f3..fe27262ebdd0 100644
@@ -15,7 +15,7 @@
 
 #include "menu.h"
 
-#define ansi 1
+#define ansi 0
 
 /*
  * Internally, each item in a menu is represented by a struct menu_item.
@@ -447,8 +447,10 @@ enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu,
 			}
 
 			c = getchar();
+			printf("\n [c=%x] \n", c);
 
 			ichar = cli_ch_process(cch, c);
+			printf("\n [i=%x %d] \n", ichar, cch->esc_len);
 
 			if (!ichar)
 				continue;
Signature · 1 line
2.41.0.162.gfafddb0af9-goog
#10 lore raw
In reply to Simon Glass
Quoted 25 lines · On Saturday 17 June 2023 11:49:47 Simon Glass wrote:

This series is an attempt to get the keyboard working properly with bootmenu.

It fixes the board's tstc() function, which should be in drivers/input

It also adjusts stopping of the menu autodelay - it should only stop when a whole escape sequence is received, not when the first escape character is received. That is pretty minor, so we could drop that patch.

This series also adds some debugging output. This seems to make things work correctly, suggesting that there is some other problem.

I also see this message fairly often:

cyclic function rx51_watchdog took too long: 10000us vs 1000us max

Simon Glass (6):
menu: Re-enable the ANSI codes
nokia_rx51: Correct tstc() implementation
bootmenu: Cancel delay only when a real key is pressed
boobtmenu: Add debugging
getch: debugging
menu: Add debugging

Quoted 9 lines
 board/nokia/rx51/rx51.c |  3 +++
 cmd/bootmenu.c          | 19 ++++++++++++-------
 common/cli_getch.c      | 23 ++++++++++++++++++++---
 common/menu.c           |  7 ++++++-
 4 files changed, 41 insertions(+), 11 deletions(-)
Signature · 1 line
2.41.0.162.gfafddb0af9-goog

Hello, it looks like that this patch series is not finish yet (contains some commented code, etc.). Anyway, I have tested it and it makes it even worse. For example PAGE DOWN key in bootmenu on emulated UART terminal completely stopped working and do nothing. So this patch series still does not fix this problem.

#11 lore raw

Hi Pali,

Quoted 37 lines · Pali Rohár
Quoted 25 lines · On Saturday 17 June 2023 11:49:47 Simon Glass wrote:

This series is an attempt to get the keyboard working properly with bootmenu.

It fixes the board's tstc() function, which should be in drivers/input

It also adjusts stopping of the menu autodelay - it should only stop when a whole escape sequence is received, not when the first escape character is received. That is pretty minor, so we could drop that patch.

This series also adds some debugging output. This seems to make things work correctly, suggesting that there is some other problem.

I also see this message fairly often:

cyclic function rx51_watchdog took too long: 10000us vs 1000us max

Simon Glass (6):
menu: Re-enable the ANSI codes
nokia_rx51: Correct tstc() implementation
bootmenu: Cancel delay only when a real key is pressed
boobtmenu: Add debugging
getch: debugging
menu: Add debugging

Quoted 9 lines
 board/nokia/rx51/rx51.c |  3 +++
 cmd/bootmenu.c          | 19 ++++++++++++-------
 common/cli_getch.c      | 23 ++++++++++++++++++++---
 common/menu.c           |  7 ++++++-
 4 files changed, 41 insertions(+), 11 deletions(-)

--
2.41.0.162.gfafddb0af9-goog

Quoted 5 lines

Hello, it looks like that this patch series is not finish yet (contains some commented code, etc.). Anyway, I have tested it and it makes it even worse. For example PAGE DOWN key in bootmenu on emulated UART terminal completely stopped working and do nothing. So this patch series still does not fix this problem.

Indeed, but I was hoping it would help you to find the problem.

The keyboard driver is currently returning 0 from tst() even when characters are available (i.e. a call to getc() will return valid chars but tstc() returns 0. I attempted to fix this, but perhaps you can do a proper fix? With that bug in place, it cannot work properly with the menu.

See the docs for tstc:

/**
* tstc() - check if a key is available
*
* @dev: Device to check
* @return 0 if no key is available, 1 if a key is available, -ve on
* error
*/
int (*tstc)(struct udevice *dev);

Regards,
Simon

#12 lore raw
Quoted 46 lines · On Monday 26 June 2023 10:07:35 Simon Glass wrote:

Hi Pali,

Quoted 37 lines · Pali Rohár
Quoted 25 lines · On Saturday 17 June 2023 11:49:47 Simon Glass wrote:

This series is an attempt to get the keyboard working properly with bootmenu.

It fixes the board's tstc() function, which should be in drivers/input

It also adjusts stopping of the menu autodelay - it should only stop when a whole escape sequence is received, not when the first escape character is received. That is pretty minor, so we could drop that patch.

This series also adds some debugging output. This seems to make things work correctly, suggesting that there is some other problem.

I also see this message fairly often:

cyclic function rx51_watchdog took too long: 10000us vs 1000us max

Simon Glass (6):
menu: Re-enable the ANSI codes
nokia_rx51: Correct tstc() implementation
bootmenu: Cancel delay only when a real key is pressed
boobtmenu: Add debugging
getch: debugging
menu: Add debugging

Quoted 9 lines
 board/nokia/rx51/rx51.c |  3 +++
 cmd/bootmenu.c          | 19 ++++++++++++-------
 common/cli_getch.c      | 23 ++++++++++++++++++++---
 common/menu.c           |  7 ++++++-
 4 files changed, 41 insertions(+), 11 deletions(-)

--
2.41.0.162.gfafddb0af9-goog

Quoted 5 lines

Hello, it looks like that this patch series is not finish yet (contains some commented code, etc.). Anyway, I have tested it and it makes it even worse. For example PAGE DOWN key in bootmenu on emulated UART terminal completely stopped working and do nothing. So this patch series still does not fix this problem.

Quoted 5 lines

Indeed, but I was hoping it would help you to find the problem.

The keyboard driver is currently returning 0 from tst() even when characters are available (i.e. a call to getc() will return valid chars but tstc() returns 0.

No, look again, rx51 tstc is returning 1 if there is something in SW buffer.

Quoted 15 lines

I attempted to fix this, but perhaps you
can do a proper fix? With that bug in place, it cannot work properly with the menu.

See the docs for tstc:

/**
* tstc() - check if a key is available
*
* @dev: Device to check
* @return 0 if no key is available, 1 if a key is available, -ve on
* error
*/
int (*tstc)(struct udevice *dev);

Quoted 2 lines

Regards,
Simon

I think it matches doc; I do not see issue here.

#13 lore raw
In reply to Simon Glass

With this patch series applied, pressing DOWN key on UART prints this "garbage" on the UART:

[c=1b]

[i=0 1] P/DOWN to move, ENTER to select, ESC to quit

[c=5b]

[i=0 2]

[c=42]

[i=e 0]
[got bkey 0]

And nothing happens.

Pressing it second time prints this "garbage":

[c=1b]

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

[c=5b]

[i=0 2]

[c=42]

[i=e 0]
[got bkey 0]
[got bkey 0]
[got bkey 0]
[got bkey 2]

And now moves cursor down.

#14 lore raw

Hi Pali,

Quoted 10 lines · Pali Rohár

With this patch series applied, pressing DOWN key on UART prints this "garbage" on the UART:

[c=1b]

[i=0 1] P/DOWN to move, ENTER to select, ESC to quit

[c=5b]

Quoted 8 lines

[i=0 2]

[c=42]

[i=e 0]
[got bkey 0]

And nothing happens.

When I tested it I got an i2c error and saw the tstc function returning ESC followed by \0. Do you see that?

Quoted 13 lines

Pressing it second time prints this "garbage":

[c=1b]

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

[c=5b]

[i=0 2]

[c=42]

Quoted 7 lines

[i=e 0]
[got bkey 0]
[got bkey 0]
[got bkey 0]
[got bkey 2]

And now moves cursor down.

So has the bug changed in this series? I thought before that it exited?

Regards,
Simon