Skip to content

Commit 1d2df6d

Browse files
a3fsaschahauer
authored andcommitted
serial: add semihosting console
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 <[email protected]> Link: https://lore.barebox.org/[email protected] Signed-off-by: Sascha Hauer <[email protected]>
1 parent 0e87c40 commit 1d2df6d

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

drivers/serial/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,12 @@ config SERIAL_SBI
151151
Select this option if you are building barebox for a RISCV platform
152152
that implements a serial over SBI.
153153

154+
config SERIAL_SEMIHOSTING
155+
bool "Semihosting console"
156+
depends on SEMIHOSTING
157+
help
158+
Select this option if you want barebox to be able to output to
159+
the semihosting console implemented by a debugger or emulator.
160+
This console can not be read from.
161+
154162
endmenu

drivers/serial/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ obj-$(CONFIG_VIRTIO_CONSOLE) += virtio_console.o
2525
obj-$(CONFIG_SERIAL_SIFIVE) += serial_sifive.o
2626
obj-$(CONFIG_SERIAL_SBI) += serial_sbi.o
2727
obj-$(CONFIG_SOC_LITEX) += serial_litex.o
28+
obj-$(CONFIG_SERIAL_SEMIHOSTING) += serial_semihosting.o

drivers/serial/serial_semihosting.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// SPDX-License-Identifier: GPL-2.0+
2+
3+
#include <console.h>
4+
#include <asm/semihosting.h>
5+
#include <efi/efi-mode.h>
6+
7+
static void smh_serial_putc(struct console_device *cdev, char ch)
8+
{
9+
semihosting_writec(ch);
10+
}
11+
12+
static int smh_serial_probe(struct device *dev)
13+
{
14+
struct console_device *cdev;
15+
16+
cdev = xzalloc(sizeof(*cdev));
17+
18+
cdev->dev = dev;
19+
cdev->putc = smh_serial_putc;
20+
21+
return console_register(cdev);
22+
}
23+
24+
static struct driver serial_semihosting_driver = {
25+
.name = "serial_semihosting",
26+
.probe = smh_serial_probe,
27+
};
28+
29+
static int __init serial_semihosting_register(void)
30+
{
31+
if (!efi_is_payload()) {
32+
struct device *dev;
33+
int ret;
34+
35+
dev = device_alloc("serial_semihosting", 0);
36+
37+
ret = platform_device_register(dev);
38+
if (ret)
39+
return ret;
40+
}
41+
42+
return platform_driver_register(&serial_semihosting_driver);
43+
}
44+
console_initcall(serial_semihosting_register);

0 commit comments

Comments
 (0)