diff mbox series

[v3,4/6] serial: Implement serial_flush() function for console flush() fallback

Message ID 20220905093121.11630-5-pali@kernel.org
State Accepted
Delegated to: Tom Rini
Headers show
Series console: Implement flush() function | expand

Commit Message

Pali Rohár Sept. 5, 2022, 9:31 a.m. UTC
Like in all other console functions, implement also serial_flush() function
as a fallback int console flush() function.

Flush support is available only when config option CONSOLE_FLUSH_SUPPORT is
enabled. So when it is disabled then provides just empty static inline
function serial_flush().

Signed-off-by: Pali Rohár <pali@kernel.org>
---
 common/console.c               |  3 +++
 common/stdio.c                 |  8 ++++++++
 drivers/serial/serial-uclass.c | 10 ++++++++++
 include/serial.h               |  5 +++++
 4 files changed, 26 insertions(+)

Comments

Simon Glass Sept. 7, 2022, 9:10 p.m. UTC | #1
On Mon, 5 Sept 2022 at 03:31, Pali Rohár <pali@kernel.org> wrote:
>
> Like in all other console functions, implement also serial_flush() function
> as a fallback int console flush() function.
>
> Flush support is available only when config option CONSOLE_FLUSH_SUPPORT is
> enabled. So when it is disabled then provides just empty static inline
> function serial_flush().
>
> Signed-off-by: Pali Rohár <pali@kernel.org>
> ---
>  common/console.c               |  3 +++
>  common/stdio.c                 |  8 ++++++++
>  drivers/serial/serial-uclass.c | 10 ++++++++++
>  include/serial.h               |  5 +++++
>  4 files changed, 26 insertions(+)

Reviewed-by: Simon Glass <sjg@chromium.org>
Tom Rini Sept. 20, 2022, 9:40 p.m. UTC | #2
On Mon, Sep 05, 2022 at 11:31:19AM +0200, Pali Rohár wrote:

> Like in all other console functions, implement also serial_flush() function
> as a fallback int console flush() function.
> 
> Flush support is available only when config option CONSOLE_FLUSH_SUPPORT is
> enabled. So when it is disabled then provides just empty static inline
> function serial_flush().
> 
> Signed-off-by: Pali Rohár <pali@kernel.org>
> Reviewed-by: Simon Glass <sjg@chromium.org>

This breaks building on a number of platforms such as ds109 probably due
to DM_SERIAL not being enabled.
Pali Rohár Sept. 20, 2022, 10:18 p.m. UTC | #3
On Tuesday 20 September 2022 17:40:39 Tom Rini wrote:
> On Mon, Sep 05, 2022 at 11:31:19AM +0200, Pali Rohár wrote:
> 
> > Like in all other console functions, implement also serial_flush() function
> > as a fallback int console flush() function.
> > 
> > Flush support is available only when config option CONSOLE_FLUSH_SUPPORT is
> > enabled. So when it is disabled then provides just empty static inline
> > function serial_flush().
> > 
> > Signed-off-by: Pali Rohár <pali@kernel.org>
> > Reviewed-by: Simon Glass <sjg@chromium.org>
> 
> This breaks building on a number of platforms such as ds109 probably due
> to DM_SERIAL not being enabled.

ds109 is failing on error:

  LD      u-boot
arm-linux-gnueabihf-ld.bfd: common/console.o: in function `flush':
/tmp/u-boot/common/console.c:802: undefined reference to `serial_flush'
arm-linux-gnueabihf-ld.bfd: common/stdio.o: in function `stdio_serial_flush':
/tmp/u-boot/common/stdio.c:93: undefined reference to `serial_flush'
make: *** [Makefile:1782: u-boot] Error 1

And serial_flush() is implemented only in serial-uclass.c (which is
DM_SERIAL code).

So could you try to add this additional guard (into this 4/6 patch)?

diff --git a/include/serial.h b/include/serial.h
index f9009d4046e3..fe01bcfadb9b 100644
--- a/include/serial.h
+++ b/include/serial.h
@@ -362,7 +362,7 @@ void serial_setbrg(void);
 void serial_putc(const char ch);
 void serial_putc_raw(const char ch);
 void serial_puts(const char *str);
-#ifdef CONFIG_CONSOLE_FLUSH_SUPPORT
+#if defined(CONFIG_CONSOLE_FLUSH_SUPPORT) && CONFIG_IS_ENABLED(DM_SERIAL)
 void serial_flush(void);
 #else
 static inline void serial_flush(void) {}

ds109 with this change compiles fine on my computer.
Tom Rini Sept. 20, 2022, 10:29 p.m. UTC | #4
On Wed, Sep 21, 2022 at 12:18:57AM +0200, Pali Rohár wrote:
> On Tuesday 20 September 2022 17:40:39 Tom Rini wrote:
> > On Mon, Sep 05, 2022 at 11:31:19AM +0200, Pali Rohár wrote:
> > 
> > > Like in all other console functions, implement also serial_flush() function
> > > as a fallback int console flush() function.
> > > 
> > > Flush support is available only when config option CONSOLE_FLUSH_SUPPORT is
> > > enabled. So when it is disabled then provides just empty static inline
> > > function serial_flush().
> > > 
> > > Signed-off-by: Pali Rohár <pali@kernel.org>
> > > Reviewed-by: Simon Glass <sjg@chromium.org>
> > 
> > This breaks building on a number of platforms such as ds109 probably due
> > to DM_SERIAL not being enabled.
> 
> ds109 is failing on error:
> 
>   LD      u-boot
> arm-linux-gnueabihf-ld.bfd: common/console.o: in function `flush':
> /tmp/u-boot/common/console.c:802: undefined reference to `serial_flush'
> arm-linux-gnueabihf-ld.bfd: common/stdio.o: in function `stdio_serial_flush':
> /tmp/u-boot/common/stdio.c:93: undefined reference to `serial_flush'
> make: *** [Makefile:1782: u-boot] Error 1
> 
> And serial_flush() is implemented only in serial-uclass.c (which is
> DM_SERIAL code).
> 
> So could you try to add this additional guard (into this 4/6 patch)?
> 
> diff --git a/include/serial.h b/include/serial.h
> index f9009d4046e3..fe01bcfadb9b 100644
> --- a/include/serial.h
> +++ b/include/serial.h
> @@ -362,7 +362,7 @@ void serial_setbrg(void);
>  void serial_putc(const char ch);
>  void serial_putc_raw(const char ch);
>  void serial_puts(const char *str);
> -#ifdef CONFIG_CONSOLE_FLUSH_SUPPORT
> +#if defined(CONFIG_CONSOLE_FLUSH_SUPPORT) && CONFIG_IS_ENABLED(DM_SERIAL)
>  void serial_flush(void);
>  #else
>  static inline void serial_flush(void) {}
> 
> ds109 with this change compiles fine on my computer.

It should, but that means that CONSOLE_FLUSH_SUPPORT itself should be
depending on DM_SERIAL.
Pali Rohár Sept. 20, 2022, 10:32 p.m. UTC | #5
On Tuesday 20 September 2022 18:29:02 Tom Rini wrote:
> On Wed, Sep 21, 2022 at 12:18:57AM +0200, Pali Rohár wrote:
> > On Tuesday 20 September 2022 17:40:39 Tom Rini wrote:
> > > On Mon, Sep 05, 2022 at 11:31:19AM +0200, Pali Rohár wrote:
> > > 
> > > > Like in all other console functions, implement also serial_flush() function
> > > > as a fallback int console flush() function.
> > > > 
> > > > Flush support is available only when config option CONSOLE_FLUSH_SUPPORT is
> > > > enabled. So when it is disabled then provides just empty static inline
> > > > function serial_flush().
> > > > 
> > > > Signed-off-by: Pali Rohár <pali@kernel.org>
> > > > Reviewed-by: Simon Glass <sjg@chromium.org>
> > > 
> > > This breaks building on a number of platforms such as ds109 probably due
> > > to DM_SERIAL not being enabled.
> > 
> > ds109 is failing on error:
> > 
> >   LD      u-boot
> > arm-linux-gnueabihf-ld.bfd: common/console.o: in function `flush':
> > /tmp/u-boot/common/console.c:802: undefined reference to `serial_flush'
> > arm-linux-gnueabihf-ld.bfd: common/stdio.o: in function `stdio_serial_flush':
> > /tmp/u-boot/common/stdio.c:93: undefined reference to `serial_flush'
> > make: *** [Makefile:1782: u-boot] Error 1
> > 
> > And serial_flush() is implemented only in serial-uclass.c (which is
> > DM_SERIAL code).
> > 
> > So could you try to add this additional guard (into this 4/6 patch)?
> > 
> > diff --git a/include/serial.h b/include/serial.h
> > index f9009d4046e3..fe01bcfadb9b 100644
> > --- a/include/serial.h
> > +++ b/include/serial.h
> > @@ -362,7 +362,7 @@ void serial_setbrg(void);
> >  void serial_putc(const char ch);
> >  void serial_putc_raw(const char ch);
> >  void serial_puts(const char *str);
> > -#ifdef CONFIG_CONSOLE_FLUSH_SUPPORT
> > +#if defined(CONFIG_CONSOLE_FLUSH_SUPPORT) && CONFIG_IS_ENABLED(DM_SERIAL)
> >  void serial_flush(void);
> >  #else
> >  static inline void serial_flush(void) {}
> > 
> > ds109 with this change compiles fine on my computer.
> 
> It should, but that means that CONSOLE_FLUSH_SUPPORT itself should be
> depending on DM_SERIAL.

No. Because CONSOLE_FLUSH_SUPPORT has nothing with serial. You can have
e.g. LCD/VGA or USB tty output console device on platform without serial
console (where would be whole serial subsystem disabled) and still able
to use new flush support.
Tom Rini Sept. 20, 2022, 10:46 p.m. UTC | #6
On Wed, Sep 21, 2022 at 12:32:33AM +0200, Pali Rohár wrote:
> On Tuesday 20 September 2022 18:29:02 Tom Rini wrote:
> > On Wed, Sep 21, 2022 at 12:18:57AM +0200, Pali Rohár wrote:
> > > On Tuesday 20 September 2022 17:40:39 Tom Rini wrote:
> > > > On Mon, Sep 05, 2022 at 11:31:19AM +0200, Pali Rohár wrote:
> > > > 
> > > > > Like in all other console functions, implement also serial_flush() function
> > > > > as a fallback int console flush() function.
> > > > > 
> > > > > Flush support is available only when config option CONSOLE_FLUSH_SUPPORT is
> > > > > enabled. So when it is disabled then provides just empty static inline
> > > > > function serial_flush().
> > > > > 
> > > > > Signed-off-by: Pali Rohár <pali@kernel.org>
> > > > > Reviewed-by: Simon Glass <sjg@chromium.org>
> > > > 
> > > > This breaks building on a number of platforms such as ds109 probably due
> > > > to DM_SERIAL not being enabled.
> > > 
> > > ds109 is failing on error:
> > > 
> > >   LD      u-boot
> > > arm-linux-gnueabihf-ld.bfd: common/console.o: in function `flush':
> > > /tmp/u-boot/common/console.c:802: undefined reference to `serial_flush'
> > > arm-linux-gnueabihf-ld.bfd: common/stdio.o: in function `stdio_serial_flush':
> > > /tmp/u-boot/common/stdio.c:93: undefined reference to `serial_flush'
> > > make: *** [Makefile:1782: u-boot] Error 1
> > > 
> > > And serial_flush() is implemented only in serial-uclass.c (which is
> > > DM_SERIAL code).
> > > 
> > > So could you try to add this additional guard (into this 4/6 patch)?
> > > 
> > > diff --git a/include/serial.h b/include/serial.h
> > > index f9009d4046e3..fe01bcfadb9b 100644
> > > --- a/include/serial.h
> > > +++ b/include/serial.h
> > > @@ -362,7 +362,7 @@ void serial_setbrg(void);
> > >  void serial_putc(const char ch);
> > >  void serial_putc_raw(const char ch);
> > >  void serial_puts(const char *str);
> > > -#ifdef CONFIG_CONSOLE_FLUSH_SUPPORT
> > > +#if defined(CONFIG_CONSOLE_FLUSH_SUPPORT) && CONFIG_IS_ENABLED(DM_SERIAL)
> > >  void serial_flush(void);
> > >  #else
> > >  static inline void serial_flush(void) {}
> > > 
> > > ds109 with this change compiles fine on my computer.
> > 
> > It should, but that means that CONSOLE_FLUSH_SUPPORT itself should be
> > depending on DM_SERIAL.
> 
> No. Because CONSOLE_FLUSH_SUPPORT has nothing with serial. You can have
> e.g. LCD/VGA or USB tty output console device on platform without serial
> console (where would be whole serial subsystem disabled) and still able
> to use new flush support.

Ah, hum. I'll apply the above and look at the before/after for everyone
before I suggest anything further.
diff mbox series

Patch

diff --git a/common/console.c b/common/console.c
index 0abfc224b53b..e4dc1da44a35 100644
--- a/common/console.c
+++ b/common/console.c
@@ -797,6 +797,9 @@  void flush(void)
 	if (gd->flags & GD_FLG_DEVINIT) {
 		/* Send to the standard output */
 		fflush(stdout);
+	} else {
+		/* Send directly to the handler */
+		serial_flush();
 	}
 }
 #endif
diff --git a/common/stdio.c b/common/stdio.c
index 92161a0df87d..13083842cbd9 100644
--- a/common/stdio.c
+++ b/common/stdio.c
@@ -87,6 +87,13 @@  static void stdio_serial_puts(struct stdio_dev *dev, const char *s)
 	serial_puts(s);
 }
 
+#ifdef CONFIG_CONSOLE_FLUSH_SUPPORT
+static void stdio_serial_flush(struct stdio_dev *dev)
+{
+	serial_flush();
+}
+#endif
+
 static int stdio_serial_getc(struct stdio_dev *dev)
 {
 	return serial_getc();
@@ -112,6 +119,7 @@  static void drv_system_init (void)
 	dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT;
 	dev.putc = stdio_serial_putc;
 	dev.puts = stdio_serial_puts;
+	STDIO_DEV_ASSIGN_FLUSH(&dev, stdio_serial_flush);
 	dev.getc = stdio_serial_getc;
 	dev.tstc = stdio_serial_tstc;
 	stdio_register (&dev);
diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c
index be6502f3d24c..f028da0900cd 100644
--- a/drivers/serial/serial-uclass.c
+++ b/drivers/serial/serial-uclass.c
@@ -327,6 +327,16 @@  void serial_puts(const char *str)
 		_serial_puts(gd->cur_serial_dev, str);
 }
 
+#ifdef CONFIG_CONSOLE_FLUSH_SUPPORT
+void serial_flush(void)
+{
+	if (!gd->cur_serial_dev)
+		return;
+
+	_serial_flush(gd->cur_serial_dev);
+}
+#endif
+
 int serial_getc(void)
 {
 	if (!gd->cur_serial_dev)
diff --git a/include/serial.h b/include/serial.h
index 8c2e7adbc321..f9009d4046e3 100644
--- a/include/serial.h
+++ b/include/serial.h
@@ -362,6 +362,11 @@  void serial_setbrg(void);
 void serial_putc(const char ch);
 void serial_putc_raw(const char ch);
 void serial_puts(const char *str);
+#ifdef CONFIG_CONSOLE_FLUSH_SUPPORT
+void serial_flush(void);
+#else
+static inline void serial_flush(void) {}
+#endif
 int serial_getc(void);
 int serial_tstc(void);