]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
dm: serial: Add a REQUIRE_SERIAL_CONSOLE option for boards with no serial port
authorHans de Goede <hdegoede@redhat.com>
Sat, 8 Aug 2015 15:45:18 +0000 (17:45 +0200)
committerLothar Waßmann <LW@KARO-electronics.de>
Thu, 10 Sep 2015 06:17:40 +0000 (08:17 +0200)
Currently the serial code assumes that there is always at least one serial
port (and panics / crashes due to null pointer dereferences when there is
none).

This makes it impossible to use u-boot on boards where there is no (debug)
serial port, because e.g. all uart pins are muxed to another function.

This commit adds a CONFIG_REQUIRE_SERIAL_CONSOLE Kconfig option, which
defaults to y (preserving existing behavior), which can be set to n on
such boards to make them work.

This commit only implements this for CONFIG_DM_SERIAL=y configs, as allowing
running without a serial port for CONFIG_DM_SERIAL=n configs is non trivial,
and is not necessary at this moment.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Simon Glass <sjg@chromium.org>
drivers/serial/Kconfig
drivers/serial/serial-uclass.c

index fd126a825f29b8abedfb70de752a327e1bf516cb..a880eacfaf7149b8149bf7d8db006d7b4adfea56 100644 (file)
@@ -1,3 +1,14 @@
+config REQUIRE_SERIAL_CONSOLE
+       bool "Require a serial port for console"
+       # Running without a serial console is not supported by the
+       # non-dm serial code
+       depends on DM_SERIAL
+       default y
+       help
+         Require a serial port for the console, and panic if none is found
+         during serial port initialization (default y). Set this to n on
+         boards which have no debug serial port whatsoever.
+
 config DM_SERIAL
        bool "Enable Driver Model for serial drivers"
        depends on DM
index bbc366b32283d9b29320a714063705de934c8db6..2a496979bcdf7f93c40c91064eba7a34004eb414 100644 (file)
@@ -78,7 +78,9 @@ static void serial_find_console_or_panic(void)
 #undef INDEX
        }
 
+#ifdef CONFIG_REQUIRE_SERIAL_CONSOLE
        panic_str("No serial driver found");
+#endif
 }
 
 /* Called prior to relocation */
@@ -140,28 +142,40 @@ static int _serial_tstc(struct udevice *dev)
 
 void serial_putc(char ch)
 {
-       _serial_putc(gd->cur_serial_dev, ch);
+       if (gd->cur_serial_dev)
+               _serial_putc(gd->cur_serial_dev, ch);
 }
 
 void serial_puts(const char *str)
 {
-       _serial_puts(gd->cur_serial_dev, str);
+       if (gd->cur_serial_dev)
+               _serial_puts(gd->cur_serial_dev, str);
 }
 
 int serial_getc(void)
 {
+       if (!gd->cur_serial_dev)
+               return 0;
+
        return _serial_getc(gd->cur_serial_dev);
 }
 
 int serial_tstc(void)
 {
+       if (!gd->cur_serial_dev)
+               return 0;
+
        return _serial_tstc(gd->cur_serial_dev);
 }
 
 void serial_setbrg(void)
 {
-       struct dm_serial_ops *ops = serial_get_ops(gd->cur_serial_dev);
+       struct dm_serial_ops *ops;
+
+       if (!gd->cur_serial_dev)
+               return;
 
+       ops = serial_get_ops(gd->cur_serial_dev);
        if (ops->setbrg)
                ops->setbrg(gd->cur_serial_dev, gd->baudrate);
 }