[PATCH v2 5/6] serial: Call flush() before changing baudrate

Pali Rohár pali at kernel.org
Fri Aug 12 11:00:09 CEST 2022


On Thursday 11 August 2022 18:08:45 Simon Glass wrote:
> Hi Pali,
> 
> On Thu, 11 Aug 2022 at 08:51, Pali Rohár <pali at kernel.org> wrote:
> >
> > On Thursday 11 August 2022 08:47:53 Simon Glass wrote:
> > > On Thu, 11 Aug 2022 at 06:39, Pali Rohár <pali at kernel.org> wrote:
> > > >
> > > > Changing baudrate is sensitive operation. To ensure that U-Boot messages
> > >
> > > is a sensitive
> > >
> > > > printed before changing baudrate are not lost, call new U-Boot console
> > > > flush() function.
> > > >
> > > > Signed-off-by: Pali Rohár <pali at kernel.org>
> > > > ---
> > > >  cmd/load.c                     | 5 +++++
> > > >  drivers/serial/serial-uclass.c | 1 +
> > > >  drivers/serial/serial.c        | 1 +
> > > >  3 files changed, 7 insertions(+)
> > > >
> > > > diff --git a/cmd/load.c b/cmd/load.c
> > > > index e44ae0d56b75..5c4f34781d45 100644
> > > > --- a/cmd/load.c
> > > > +++ b/cmd/load.c
> > > > @@ -83,6 +83,7 @@ static int do_load_serial(struct cmd_tbl *cmdtp, int flag, int argc,
> > > >                 printf("## Switch baudrate to %d bps and press ENTER ...\n",
> > > >                         load_baudrate);
> > > >                 udelay(50000);
> > > > +               flush();
> > > >                 gd->baudrate = load_baudrate;
> > > >                 serial_setbrg();
> > > >                 udelay(50000);
> > > > @@ -126,6 +127,7 @@ static int do_load_serial(struct cmd_tbl *cmdtp, int flag, int argc,
> > > >                 printf("## Switch baudrate to %d bps and press ESC ...\n",
> > > >                         current_baudrate);
> > > >                 udelay(50000);
> > > > +               flush();
> > > >                 gd->baudrate = current_baudrate;
> > > >                 serial_setbrg();
> > > >                 udelay(50000);
> > > > @@ -317,6 +319,7 @@ int do_save_serial(struct cmd_tbl *cmdtp, int flag, int argc,
> > > >                 printf("## Switch baudrate to %d bps and press ESC ...\n",
> > > >                         (int)current_baudrate);
> > > >                 udelay(50000);
> > > > +               flush();
> > > >                 gd->baudrate = current_baudrate;
> > > >                 serial_setbrg();
> > > >                 udelay(50000);
> > > > @@ -471,6 +474,7 @@ static int do_load_serial_bin(struct cmd_tbl *cmdtp, int flag, int argc,
> > > >                 printf("## Switch baudrate to %d bps and press ENTER ...\n",
> > > >                         load_baudrate);
> > > >                 udelay(50000);
> > > > +               flush();
> > > >                 gd->baudrate = load_baudrate;
> > > >                 serial_setbrg();
> > > >                 udelay(50000);
> > > > @@ -533,6 +537,7 @@ static int do_load_serial_bin(struct cmd_tbl *cmdtp, int flag, int argc,
> > > >                 printf("## Switch baudrate to %d bps and press ESC ...\n",
> > > >                         current_baudrate);
> > > >                 udelay(50000);
> > > > +               flush();
> > > >                 gd->baudrate = current_baudrate;
> > > >                 serial_setbrg();
> > > >                 udelay(50000);
> > > > diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c
> > > > index 4e32270d4660..0f6860d9100e 100644
> > > > --- a/drivers/serial/serial-uclass.c
> > > > +++ b/drivers/serial/serial-uclass.c
> > > > @@ -527,6 +527,7 @@ static int on_baudrate(const char *name, const char *value, enum env_op op,
> > > >                         printf("## Switch baudrate to %d bps and press ENTER ...\n",
> > > >                                baudrate);
> > > >                         udelay(50000);
> > > > +                       flush();
> > > >                 }
> > > >
> > > >                 gd->baudrate = baudrate;
> > > > diff --git a/drivers/serial/serial.c b/drivers/serial/serial.c
> > > > index 6cdbb89841c1..4b525b644928 100644
> > > > --- a/drivers/serial/serial.c
> > > > +++ b/drivers/serial/serial.c
> > > > @@ -81,6 +81,7 @@ static int on_baudrate(const char *name, const char *value, enum env_op op,
> > > >                         printf("## Switch baudrate to %d"
> > > >                                 " bps and press ENTER ...\n", baudrate);
> > > >                         udelay(50000);
> > > > +                       flush();
> > >
> > > Please don't implement new features in legacy code.
> >
> > Sorry, I do not know what is the legacy code in this spaghetti monster.
> 
> This file is legacy...you only need to change the uclass.

Ok

> >
> > > >                 }
> > > >
> > > >                 gd->baudrate = baudrate;
> > > > --
> > > > 2.20.1
> > > >
> > >
> > > Regards,
> > > SImon
> 
> Regards,
> Simon


More information about the U-Boot mailing list