From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 6/6] serial: add semihosting console
Date: Tue, 11 Jun 2024 08:59:23 +0200 [thread overview]
Message-ID: <20240611065923.2900168-7-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20240611065923.2900168-1-a.fatoum@pengutronix.de>
There is no way to implement a proper tstc() with the semihosting
console, so for now, let's add it as output-only console.
Currently, the console is only usable when not running as EFI payload to
avoid duplicate output when it's exposed over regular EFI protocol.
In the future, we could make it opt-in by providing a way to create the
semihosting device from shell.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/serial/Kconfig | 8 ++++++
drivers/serial/Makefile | 1 +
drivers/serial/serial_semihosting.c | 44 +++++++++++++++++++++++++++++
3 files changed, 53 insertions(+)
create mode 100644 drivers/serial/serial_semihosting.c
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index 60b0e5f1dc1f..20fe26439048 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -151,4 +151,12 @@ config SERIAL_SBI
Select this option if you are building barebox for a RISCV platform
that implements a serial over SBI.
+config SERIAL_SEMIHOSTING
+ bool "Semihosting console"
+ depends on SEMIHOSTING
+ help
+ Select this option if you want barebox to be able to output to
+ the semihosting console implemented by a debugger or emulator.
+ This console can not be read from.
+
endmenu
diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile
index 4887e24ee1c1..f4ccb249003a 100644
--- a/drivers/serial/Makefile
+++ b/drivers/serial/Makefile
@@ -25,3 +25,4 @@ obj-$(CONFIG_VIRTIO_CONSOLE) += virtio_console.o
obj-$(CONFIG_SERIAL_SIFIVE) += serial_sifive.o
obj-$(CONFIG_SERIAL_SBI) += serial_sbi.o
obj-$(CONFIG_SOC_LITEX) += serial_litex.o
+obj-$(CONFIG_SERIAL_SEMIHOSTING) += serial_semihosting.o
diff --git a/drivers/serial/serial_semihosting.c b/drivers/serial/serial_semihosting.c
new file mode 100644
index 000000000000..d495b07f11ca
--- /dev/null
+++ b/drivers/serial/serial_semihosting.c
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+#include <console.h>
+#include <asm/semihosting.h>
+#include <efi/efi-mode.h>
+
+static void smh_serial_putc(struct console_device *cdev, char ch)
+{
+ semihosting_writec(ch);
+}
+
+static int smh_serial_probe(struct device *dev)
+{
+ struct console_device *cdev;
+
+ cdev = xzalloc(sizeof(*cdev));
+
+ cdev->dev = dev;
+ cdev->putc = smh_serial_putc;
+
+ return console_register(cdev);
+}
+
+static struct driver serial_semihosting_driver = {
+ .name = "serial_semihosting",
+ .probe = smh_serial_probe,
+};
+
+static int __init serial_semihosting_register(void)
+{
+ if (!efi_is_payload()) {
+ struct device *dev;
+ int ret;
+
+ dev = device_alloc("serial_semihosting", 0);
+
+ ret = platform_device_register(dev);
+ if (ret)
+ return ret;
+ }
+
+ return platform_driver_register(&serial_semihosting_driver);
+}
+console_initcall(serial_semihosting_register);
--
2.39.2
next prev parent reply other threads:[~2024-06-11 7:00 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-11 6:59 [PATCH 0/6] semihosting: extend support for ARM64, console Ahmad Fatoum
2024-06-11 6:59 ` [PATCH 1/6] ARM: lib32: semihosting: prepare for more general use Ahmad Fatoum
2024-06-11 6:59 ` [PATCH 2/6] firmware: semihosting: add ARMv8-A semihosting support Ahmad Fatoum
2024-06-11 6:59 ` [PATCH 3/6] firmware: semihosting: don't return error code from writec/write0 Ahmad Fatoum
2024-06-11 6:59 ` [PATCH 4/6] firmware: semihosting: translate return values in wrappers Ahmad Fatoum
2024-06-11 6:59 ` [PATCH 5/6] ARM: semihosting: add DEBUG_LL implementation Ahmad Fatoum
2024-06-11 6:59 ` Ahmad Fatoum [this message]
2024-06-13 7:18 ` [PATCH 0/6] semihosting: extend support for ARM64, console Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240611065923.2900168-7-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox