]> git.baikalelectronics.ru Git - uboot.git/commitdiff
serial: smh: Initialize serial only if semihosting is enabled
authorSean Anderson <sean.anderson@seco.com>
Tue, 22 Mar 2022 20:59:32 +0000 (16:59 -0400)
committerTom Rini <trini@konsulko.com>
Fri, 1 Apr 2022 20:56:53 +0000 (16:56 -0400)
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>
drivers/serial/serial_semihosting.c

index 7c7c5d945588cbfb1d55ffe36f9bb943d5e14e8b..62b1b2241b3fe2063a8fe21fd8250c385efd98fa 100644 (file)
@@ -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)