server: allow setting baud rate on host tty
The Nuvoton NPCM7xx series BMCs have a real UART which receives output
from the host serial console, rather than a virtual UART as on Aspeed
parts. This means we have to set the baud rate of the tty to match the
host console.
This change adds the "baud" config option. If it is present in the
config file and has a valid value, the host console tty's baud rate will
be set to that value.
Change-Id: If2156c2032e7527709713f13654ce8bca9bf4c1d
Signed-off-by: Benjamin Fair <benjaminfair@google.com>
diff --git a/console-server.c b/console-server.c
index fb84e19..22e6094 100644
--- a/console-server.c
+++ b/console-server.c
@@ -44,6 +44,7 @@
char *tty_dev;
int tty_sirq;
int tty_lpc_addr;
+ speed_t tty_baud;
int tty_fd;
struct ringbuffer *rb;
@@ -187,8 +188,7 @@
}
/**
- * Set console to raw mode: we don't want any processing to occur on
- * the underlying terminal input/output.
+ * Set termios attributes on the console tty.
*/
static void tty_init_termios(struct console *console)
{
@@ -201,10 +201,19 @@
return;
}
+ if (console->tty_baud) {
+ if (cfsetspeed(&termios, console->tty_baud) < 0)
+ warn("Couldn't set speeds for %s", console->tty_kname);
+ }
+
+ /* Set console to raw mode: we don't want any processing to occur on
+ * the underlying terminal input/output.
+ */
cfmakeraw(&termios);
+
rc = tcsetattr(console->tty_fd, TCSANOW, &termios);
if (rc)
- warn("Can't set terminal raw mode for tty");
+ warn("Can't set terminal options for %s", console->tty_kname);
}
/**
@@ -259,6 +268,12 @@
warn("Invalid sirq: '%s'", val);
}
+ val = config_get_value(config, "baud");
+ if (val) {
+ if (config_parse_baud(&console->tty_baud, val))
+ warnx("Invalid baud rate: '%s'", val);
+ }
+
if (!console->tty_kname) {
warnx("Error: No TTY device specified");
return -1;
diff --git a/obmc-console.conf.sample b/obmc-console.conf.sample
index 647e3c7..56d69fe 100644
--- a/obmc-console.conf.sample
+++ b/obmc-console.conf.sample
@@ -2,5 +2,8 @@
lpc-address = 0x3f8
sirq = 4
+# For real UART devices, we can specify the baud rate
+# baud = 115200
+
# To mirror to a local tty device (typically a hardware UART), set local-tty
# local-tty = ttyS0