printk() messages over a serial console

Paul Gortmaker (paul@rasty.anu.edu.au)
Sat, 22 Mar 1997 16:10:17 +1000 (EST)


[Sent this earlier in the week, but it seems to have vanished.]

> Subject: printk() messages over a serial console
> To: linux-kernel@vger.rutgers.edu
> Date: Tue, 18 Mar 1997 21:53:31 +1000 (EST)

I am not sure why CONFIG_SERIAL_ECHO is only available on the AXP's
config.in since it only assumes hardware equivalent to std. PC boxes.
I have been using it for a while on ix86, and am very happy with it.

To make it a bit more user friendly, the user should be able to specify one
of the four std. serial ports (0x3f8,0x2f8,0x3e8,0x2e8) via a boot arg
for the echo to use, and I've added this in the following patch (v2.1.29)

Paul.

-----------------------

diff -ur /tmp/linux/arch/i386/config.in linux/arch/i386/config.in
--- /tmp/linux/arch/i386/config.in Thu Jan 16 13:46:06 1997
+++ linux/arch/i386/config.in Tue Mar 18 09:37:22 1997
@@ -21,6 +21,7 @@
mainmenu_option next_comment
comment 'General setup'

+bool 'Echo kernel messages on a serial port' CONFIG_SERIAL_ECHO
bool 'Kernel math emulation' CONFIG_MATH_EMULATION
bool 'Networking support' CONFIG_NET
bool 'PCI bios support' CONFIG_PCI
diff -ur /tmp/linux/drivers/char/console.c linux/drivers/char/console.c
--- /tmp/linux/drivers/char/console.c Mon Feb 3 00:52:22 1997
+++ linux/drivers/char/console.c Tue Mar 18 11:08:32 1997
@@ -194,15 +194,14 @@

#include <linux/serial_reg.h>

-extern int serial_echo_init (int base);
+extern int serial_echo_init (void);
extern int serial_echo_print (const char *s);

/*
- * this defines the address for the port to which printk echoing is done
- * when CONFIG_SERIAL_ECHO is defined
+ * This defines the address for the port to which printk echoing is done
+ * when CONFIG_SERIAL_ECHO is defined. Use "echoport=N" at boot, where N is
+ * one of {1, 2, 3, 4} for COM1 -> COM4, or {0x3f8, 0x2f8, 0x3e8, 0x2e8}.
*/
-#define SERIAL_ECHO_PORT 0x3f8 /* COM1 */
-
static int serial_echo_port = 0;

#define serial_echo_outb(v,a) outb((v),(a)+serial_echo_port)
@@ -262,18 +261,27 @@
return (0);
}

+void
+serial_echo_setup(char *str, int *ints)
+{
+ int base, i;
+ unsigned int portlist[] = {0x3f8, 0x2f8, 0x3e8, 0x2e8, 0};
+
+ if (ints[0] > 0)
+ base = ints[1];
+ else
+ return;
+
+ for (i = 0; portlist[i]; i++)
+ if (base == portlist[i] || base == (i+1))
+ serial_echo_port = portlist[i];
+}

int
-serial_echo_init(int base)
+serial_echo_init()
{
int comstat, hi, lo;

- if (base != 0x2f8 && base != 0x3f8) {
- serial_echo_port = 0;
- return (0);
- } else
- serial_echo_port = base;
-
/*
* read the Divisor Latch
*/
@@ -2130,7 +2138,9 @@
video_scan_lines = video_font_height * video_num_lines;

#ifdef CONFIG_SERIAL_ECHO
- serial_echo_init(SERIAL_ECHO_PORT);
+ serial_echo_init();
+ if (serial_echo_port != 0)
+ printk("Console: Echoing kernel messages on serial port at %#x.\n", serial_echo_port);
#endif /* CONFIG_SERIAL_ECHO */

printk("Console: %ld point font, %ld scans\n",
diff -ur /tmp/linux/init/main.c linux/init/main.c
--- /tmp/linux/init/main.c Sat Mar 8 07:51:45 1997
+++ linux/init/main.c Tue Mar 18 10:55:17 1997
@@ -73,6 +73,7 @@

extern void smp_setup(char *str, int *ints);
extern void no_scroll(char *str, int *ints);
+extern void serial_echo_setup(char *str, int *ints);
extern void swap_setup(char *str, int *ints);
extern void buff_setup(char *str, int *ints);
extern void panic_setup(char *str, int *ints);
@@ -298,6 +299,9 @@
{ "buff=", buff_setup },
{ "panic=", panic_setup },
{ "no-scroll", no_scroll },
+#ifdef CONFIG_SERIAL_ECHO
+ { "echoport=", serial_echo_setup },
+#endif
#ifdef CONFIG_BUGi386
{ "no-hlt", no_halt },
{ "no387", no_387 },