[U-Boot] [PATCH 0/4] Solve issue with serial rx buffer when MUX is deactivated

Patrick Delaunay patrick.delaunay at st.com
Fri Aug 3 11:38:41 UTC 2018


When I activate CONFIG_SERIAL_RX_BUFFER on my board without CONSOLE_MUX,
I have a strange behavior in console: a new prompt is displayed
continuously

I check the call stack

cread_line (common/cli_readline.c)
=> getcmd_getch (common/cli_readline.c)
==> fgetc (common/console.c)
===> console_tstc (common/console.c)
====> stdio_devices[file]->get()
=====> _serial_getc() (drivers/serial/serial-uclass.c)
       and the data reads from rx buffer but it is garbage
       as tstc is not called

PS: I have no issue when CONSOLE_MUX is activated because in this
    case the tstc() is always called in fgetc loop.

My first solution to update the rx buffer management,
to avoid the issue:

static int _serial_getc(struct udevice *dev)
{
	struct serial_dev_priv *upriv = dev_get_uclass_priv(dev);
	char val;

	if (upriv->rd_ptr == upriv->wr_ptr)
		__serial_tstc(dev);

	if (upriv->rd_ptr == upriv->wr_ptr)
		return 0; /* error : no data to read */

	val = upriv->buf[upriv->rd_ptr++];
	upriv->rd_ptr %= CONFIG_SERIAL_RX_BUFFER_SIZE;

	return val;
}

With this first patch, I see that that WATCHDOG is not reloaded
and the getc() error value 0x0 wasn't correctly handle in cli;
the issue is alway present and the behavior change (getc function
is no more blocking): the caller needs to handle the error and
reload the watchdog.

To summarize, I see several issues in the current U-Boot code:
- No protection on the rx buffer in _serial_getc():
  the current code assumed that tstc() is alway called but
  it is dangerous
- error for getc() (read value = 0x0) is not handled in cread_line()
- in console.c, tstc() is not called when CONSOLE_MUX is not activated

In this patchset I try to solve all these issues by separate patch
but perhaps only the first correction on the rx buffer is really mandatory.

On my board stm32mp1 ev1 the issue is solved.



Patrick Delaunay (4):
  stm32mp1: activate serial rx buffer
  serial: protect access to serial rx buffer
  console: unify fgetc function when console MUX is deactivated
  cli: handle getch error

 common/cli_readline.c             | 4 ++++
 common/console.c                  | 9 +++++----
 configs/stm32mp15_basic_defconfig | 1 +
 drivers/serial/serial-uclass.c    | 3 +++
 4 files changed, 13 insertions(+), 4 deletions(-)

-- 
2.7.4



More information about the U-Boot mailing list