diff mbox series

[v3,27/29] serial: sandbox: Implement puts

Message ID 20220322205938.1721846-28-sean.anderson@seco.com
State Awaiting Upstream
Delegated to: Tom Rini
Headers show
Series arm: semihosting: Cleanups and new features | expand

Commit Message

Sean Anderson March 22, 2022, 8:59 p.m. UTC
This implements puts for sandbox. It is fairly straightforward, except
that we break out the shared color printing functionality into its own
function.

Signed-off-by: Sean Anderson <sean.anderson@seco.com>
---

(no changes since v2)

Changes in v2:
- New

 drivers/serial/Kconfig   |  1 +
 drivers/serial/sandbox.c | 21 ++++++++++++++++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

Comments

Simon Glass March 28, 2022, 6:35 a.m. UTC | #1
On Tue, 22 Mar 2022 at 15:00, Sean Anderson <sean.anderson@seco.com> wrote:
>
> This implements puts for sandbox. It is fairly straightforward, except
> that we break out the shared color printing functionality into its own
> function.
>
> Signed-off-by: Sean Anderson <sean.anderson@seco.com>
> ---
>
> (no changes since v2)
>
> Changes in v2:
> - New
>
>  drivers/serial/Kconfig   |  1 +
>  drivers/serial/sandbox.c | 21 ++++++++++++++++++++-
>  2 files changed, 21 insertions(+), 1 deletion(-)

Reviewed-by: Simon Glass <sjg@chromium.org>
Tom Rini April 1, 2022, 10:39 p.m. UTC | #2
On Tue, Mar 22, 2022 at 04:59:35PM -0400, Sean Anderson wrote:

> This implements puts for sandbox. It is fairly straightforward, except
> that we break out the shared color printing functionality into its own
> function.
> 
> Signed-off-by: Sean Anderson <sean.anderson@seco.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>

This breaks the "handoff" test at least, and perhaps others, on
sandbox*.
Sean Anderson April 4, 2022, 6:26 p.m. UTC | #3
On 4/1/22 6:39 PM, Tom Rini wrote:
> On Tue, Mar 22, 2022 at 04:59:35PM -0400, Sean Anderson wrote:
> 
>> This implements puts for sandbox. It is fairly straightforward, except
>> that we break out the shared color printing functionality into its own
>> function.
>> 
>> Signed-off-by: Sean Anderson <sean.anderson@seco.com>
>> Reviewed-by: Simon Glass <sjg@chromium.org>
> 
> This breaks the "handoff" test at least, and perhaps others, on
> sandbox*.
> 

Should be fixed by

https://lore.kernel.org/u-boot/20220404181800.2258698-1-sean.anderson@seco.com/T/#md171932d553f842e611679213383138846ebec48
diff mbox series

Patch

diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index 1a109b2411..86c4c6d5a0 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -775,6 +775,7 @@  config S5P_SERIAL
 config SANDBOX_SERIAL
 	bool "Sandbox UART support"
 	depends on SANDBOX
+	imply SERIAL_PUTS
 	help
 	  Select this to enable a seral UART for sandbox. This is required to
 	  operate correctly, otherwise you will see no serial output from
diff --git a/drivers/serial/sandbox.c b/drivers/serial/sandbox.c
index 0b1756f5c0..50cf2c74a7 100644
--- a/drivers/serial/sandbox.c
+++ b/drivers/serial/sandbox.c
@@ -67,7 +67,7 @@  static int sandbox_serial_remove(struct udevice *dev)
 	return 0;
 }
 
-static int sandbox_serial_putc(struct udevice *dev, const char ch)
+static void sandbox_print_color(struct udevice *dev)
 {
 	struct sandbox_serial_priv *priv = dev_get_priv(dev);
 	struct sandbox_serial_plat *plat = dev_get_plat(dev);
@@ -78,7 +78,13 @@  static int sandbox_serial_putc(struct udevice *dev, const char ch)
 		priv->start_of_line = false;
 		output_ansi_colour(plat->colour);
 	}
+}
 
+static int sandbox_serial_putc(struct udevice *dev, const char ch)
+{
+	struct sandbox_serial_priv *priv = dev_get_priv(dev);
+
+	sandbox_print_color(dev);
 	os_write(1, &ch, 1);
 	if (ch == '\n')
 		priv->start_of_line = true;
@@ -86,6 +92,18 @@  static int sandbox_serial_putc(struct udevice *dev, const char ch)
 	return 0;
 }
 
+static ssize_t sandbox_serial_puts(struct udevice *dev, const char *s,
+				   size_t len)
+{
+	struct sandbox_serial_priv *priv = dev_get_priv(dev);
+
+	sandbox_print_color(dev);
+	if (s[len - 1] == '\n')
+		priv->start_of_line = true;
+
+	return os_write(1, s, len);
+}
+
 static int sandbox_serial_pending(struct udevice *dev, bool input)
 {
 	struct sandbox_serial_priv *priv = dev_get_priv(dev);
@@ -212,6 +230,7 @@  static int sandbox_serial_of_to_plat(struct udevice *dev)
 
 static const struct dm_serial_ops sandbox_serial_ops = {
 	.putc = sandbox_serial_putc,
+	.puts = sandbox_serial_puts,
 	.pending = sandbox_serial_pending,
 	.getc = sandbox_serial_getc,
 	.getconfig = sandbox_serial_getconfig,