diff mbox series

[v3,24/29] serial: smh: Initialize serial only if semihosting is enabled

Message ID 20220322205938.1721846-25-sean.anderson@seco.com
State Accepted
Commit 2332590c48ac15926d7ec23b0fa17b9ea4e305ed
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
If semihosting is disabled, then the user has no debugger attached, and
will not see any messages. Don't create a serial device in this
instance, to (hopefully) fall back on another working serial device.

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

(no changes since v2)

Changes in v2:
- New

 drivers/serial/serial_semihosting.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

Comments

Tom Rini April 3, 2022, 12:16 a.m. UTC | #1
On Tue, Mar 22, 2022 at 04:59:32PM -0400, Sean Anderson wrote:

> If semihosting is disabled, then the user has no debugger attached, and
> will not see any messages. Don't create a serial device in this
> instance, to (hopefully) fall back on another working serial device.
> 
> Signed-off-by: Sean Anderson <sean.anderson@seco.com>

Applied to u-boot/next, thanks!
diff mbox series

Patch

diff --git a/drivers/serial/serial_semihosting.c b/drivers/serial/serial_semihosting.c
index 7c7c5d9455..62b1b2241b 100644
--- a/drivers/serial/serial_semihosting.c
+++ b/drivers/serial/serial_semihosting.c
@@ -41,6 +41,13 @@  static const struct dm_serial_ops smh_serial_ops = {
 	.getc = smh_serial_getc,
 };
 
+static int smh_serial_bind(struct udevice *dev)
+{
+	if (semihosting_enabled())
+		return 0;
+	return -ENOENT;
+}
+
 static int smh_serial_probe(struct udevice *dev)
 {
 	struct smh_serial_priv *priv = dev_get_priv(dev);
@@ -52,6 +59,7 @@  static int smh_serial_probe(struct udevice *dev)
 U_BOOT_DRIVER(smh_serial) = {
 	.name	= "serial_semihosting",
 	.id	= UCLASS_SERIAL,
+	.bind	= smh_serial_bind,
 	.probe	= smh_serial_probe,
 	.priv_auto = sizeof(struct smh_serial_priv),
 	.ops	= &smh_serial_ops,
@@ -122,7 +130,8 @@  struct serial_device serial_smh_device = {
 
 void smh_serial_initialize(void)
 {
-	serial_register(&serial_smh_device);
+	if (semihosting_enabled())
+		serial_register(&serial_smh_device);
 }
 
 __weak struct serial_device *default_serial_console(void)