Skip to contentSkip to conversation

early printk and boot console fixups.

PATCH In review Gerd Hoffmann 4 participants 10 messages Feb 16, 2007 – May 17, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 early printk and boot console fixups.

Hi,

The console subsystem already has an idea of a boot console, using the CON_BOOT flag. The implementation has some flaws though. The major problem is that presence of a boot console makes register_console() ignore any other console devices (unless explicitly specified on the kernel command line).

This patch fixes the console selection code to *not* consider a boot console a full-featured one, so the first "normal" console registering will become the default boot console instead. This way the unregister call for the boot console in register_console() actually triggers and the handover from the boot console to the real console device works smoothly.

The patch also changes the x86 early_printk code to use this. The early console is simply tagged as boot console, the disable_early_printk() call is gone as it isn't needed any more.

cheers,
Gerd

Signature · 1 line
Gerd Hoffmann <[email protected]>
---
 arch/x86_64/kernel/early_printk.c |   20 +++++---------------
 drivers/char/tty_io.c             |    5 -----
 kernel/printk.c                   |   26 ++++++++++++++++----------
 3 files changed, 21 insertions(+), 30 deletions(-)
arch/x86_64/kernel/early_printk.c +5 -15
Index: paravirt-2.6.20-hg770/arch/x86_64/kernel/early_printk.c
===================================================================
@@ -244,22 +244,12 @@ static int __init setup_early_printk(cha
  		early_console = &simnow_console;
  		keep_early = 1;
 	}
+
+	if (keep_early)
+		early_console->flags &= ~CON_BOOT;
+	else
+		early_console->flags |= CON_BOOT;
 	register_console(early_console);
 	return 0;
 }
-
 early_param("earlyprintk", setup_early_printk);
-
-void __init disable_early_printk(void)
-{
-	if (!early_console_initialized || !early_console)
-		return;
-	if (!keep_early) {
-		printk("disabling early console\n");
-		unregister_console(early_console);
-		early_console_initialized = 0;
-	} else {
-		printk("keeping early console\n");
-	}
-}
-
kernel/printk.c +16 -10
Index: paravirt-2.6.20-hg770/kernel/printk.c
===================================================================
@@ -931,8 +931,16 @@ void register_console(struct console *co
 {
 	int i;
 	unsigned long flags;
+	struct console *bootconsole = NULL;
 
-	if (preferred_console < 0)
+	if (console_drivers) {
+		if (console->flags & CON_BOOT)
+			return;
+		if (console_drivers->flags & CON_BOOT)
+			bootconsole = console_drivers;
+	}
+
+	if (preferred_console < 0 || bootconsole || !console_drivers)
 		preferred_console = selected_console;
 
 	/*
@@ -978,8 +986,11 @@ void register_console(struct console *co
 	if (!(console->flags & CON_ENABLED))
 		return;
 
-	if (console_drivers && (console_drivers->flags & CON_BOOT)) {
-		unregister_console(console_drivers);
+	if (bootconsole) {
+		printk(KERN_INFO "console handover: boot [%s%d] -> real [%s%d]\n",
+		       bootconsole->name, bootconsole->index,
+		       console->name, console->index);
+		unregister_console(bootconsole);
 		console->flags &= ~CON_PRINTBUFFER;
 	}
 
@@ -1030,16 +1041,11 @@ int unregister_console(struct console *c
 		}
 	}
 
-	/* If last console is removed, we re-enable picking the first
-	 * one that gets registered. Without that, pmac early boot console
-	 * would prevent fbcon from taking over.
-	 *
+	/*
 	 * If this isn't the last console and it has CON_CONSDEV set, we
 	 * need to set it on the next preferred console.
 	 */
-	if (console_drivers == NULL)
-		preferred_console = selected_console;
-	else if (console->flags & CON_CONSDEV)
+	if (console_drivers != NULL && console->flags & CON_CONSDEV)
 		console_drivers->flags |= CON_CONSDEV;
 
 	release_console_sem();
drivers/char/tty_io.c +0 -5
Index: paravirt-2.6.20-hg770/drivers/char/tty_io.c
===================================================================
@@ -141,8 +141,6 @@ static DECLARE_MUTEX(allocated_ptys_lock
 static int ptmx_open(struct inode *, struct file *);
 #endif
 
-extern void disable_early_printk(void);
-
 static void initialize_tty_struct(struct tty_struct *tty);
 
 static ssize_t tty_read(struct file *, char __user *, size_t, loff_t *);
@@ -3881,9 +3879,6 @@ void __init console_init(void)
 	 * set up the console device so that later boot sequences can 
 	 * inform about problems etc..
 	 */
-#ifdef CONFIG_EARLY_PRINTK
-	disable_early_printk();
-#endif
 	call = __con_initcall_start;
 	while (call < __con_initcall_end) {
 		(*call)();
#1 lore raw
Quoted 13 lines · Gerd Hoffmann

The console subsystem already has an idea of a boot console, using the CON_BOOT flag. The implementation has some flaws though. The major problem is that presence of a boot console makes register_console() ignore any other console devices (unless explicitly specified on the kernel command line).

This patch fixes the console selection code to *not* consider a boot console a full-featured one, so the first "normal" console registering will become the default boot console instead. This way the unregister call for the boot console in register_console() actually triggers and the handover from the boot console to the real console device works smoothly.

Quoted 3 lines

The patch also changes the x86 early_printk code to use this. The early console is simply tagged as boot console, the disable_early_printk() call is gone as it isn't needed any more.

just notice console handover patch got into mainline 5/8.

for early_uart_console, I have some ideas:
1. merged that into early_serial_console in arch/x86_64/kernel/early_printk.c, and
move early_printk.c to kernel/, --- make it understand

    earlyprintk=uart,io,0x3f8,9600n8
    earlyprintk=uart,mmio,0xff5e0000,115200n8

in addition to vga, ttyS, serial

2. or make early_uart_console to be another CON_BOOT, and get rid of late_initcall(early_uart_console_switch).
actually with late_initcall early_uart_console_switch instead of console handover, we will lose char output from serial drv init to late_initcall stage.
in this case, we need to EARLY_SERIAL_CONSOLE to select early_serial_console or early_uart_console for x86_64 platform.

YH

#2 lore raw
Quoted 7 lines · Yinghai Lu

for early_uart_console, I have some ideas:
1. merged that into early_serial_console in arch/x86_64/kernel/early_printk.c, and
move early_printk.c to kernel/, --- make it understand

     earlyprintk=uart,io,0x3f8,9600n8
     earlyprintk=uart,mmio,0xff5e0000,115200n8

in addition to vga, ttyS, serial

I would rather try to merge 8250_early and early_printk. "console=uart,io,0x3f8" is already pretty similar to "earlyprintk=serial", and it would be nice to have only one.

"console=uart" does have the disadvantage that you have to know the port address. But it has the advantage that it doesn't depend on compiled-in legacy serial port names. If you need early console output, you're probably a developer and can come up with the address.

I think it would be nice to have a "console=vga". That could use the current "earlyprintk=vga" implementation, and automatically hand off to tty0.

Then we could remove "earlyprintk=" and always use "console=uart" or "console=vga".

Bjorn

#3 lore raw
Quoted 18 lines · Bjorn Helgaas
Quoted 7 lines · Yinghai Lu

for early_uart_console, I have some ideas:
1. merged that into early_serial_console in arch/x86_64/kernel/early_printk.c, and
move early_printk.c to kernel/, --- make it understand

     earlyprintk=uart,io,0x3f8,9600n8
     earlyprintk=uart,mmio,0xff5e0000,115200n8

in addition to vga, ttyS, serial

I would rather try to merge 8250_early and early_printk. "console=uart,io,0x3f8" is already pretty similar to "earlyprintk=serial", and it would be nice to have only one.

"console=uart" does have the disadvantage that you have to know the port address. But it has the advantage that it doesn't depend on compiled-in legacy serial port names. If you need early console output, you're probably a developer and can come up with the address.

Quoted 6 lines

I think it would be nice to have a "console=vga". That could use the current "earlyprintk=vga" implementation, and automatically hand off to tty0.

Then we could remove "earlyprintk=" and always use "console=uart" or "console=vga".

earlyprintk= is needed for seeting bootconsole, or setting CON_BOOT, and it is could be loaded earlier with early_param than console_init.

in the console_init (via register_console), the console is handed over from bootconsole to normal console.

also console_init could be moved to quite late than current, and till some subsystem is initialized like pci and usb.

YH

#4 lore raw
Quoted 23 lines · Yinghai Lu
Quoted 22 lines · Bjorn Helgaas
Quoted 7 lines · Yinghai Lu

for early_uart_console, I have some ideas:
1. merged that into early_serial_console in arch/x86_64/kernel/early_printk.c, and
move early_printk.c to kernel/, --- make it understand

     earlyprintk=uart,io,0x3f8,9600n8
     earlyprintk=uart,mmio,0xff5e0000,115200n8

in addition to vga, ttyS, serial

I would rather try to merge 8250_early and early_printk. "console=uart,io,0x3f8" is already pretty similar to "earlyprintk=serial", and it would be nice to have only one.

"console=uart" does have the disadvantage that you have to know the port address. But it has the advantage that it doesn't depend on compiled-in legacy serial port names. If you need early console output, you're probably a developer and can come up with the address.

I think it would be nice to have a "console=vga". That could use the current "earlyprintk=vga" implementation, and automatically hand off to tty0.

Quoted 5 lines
Quoted 2 lines

Then we could remove "earlyprintk=" and always use "console=uart" or "console=vga".

earlyprintk= is needed for seeting bootconsole, or setting CON_BOOT, and it is could be loaded earlier with early_param than console_init.

8250_early.c does basically the same thing as the serial part of early_printk.c, so we should be able to make it work just as early. I don't remember why I didn't use early_param() for 8250_early; I probably should have. On ia64, it doesn't matter because we call early_serial_console_init() explicitly at about the time of parse_early_param().

8250_early and early_printk are so similar, I just don't see the need for both.

Bjorn

#5 lore raw
In reply to Bjorn Helgaas
Quoted 8 lines · Bjorn Helgaas
Quoted 7 lines

for early_uart_console, I have some ideas:
1. merged that into early_serial_console in arch/x86_64/kernel/early_printk.c, and
move early_printk.c to kernel/, --- make it understand

     earlyprintk=uart,io,0x3f8,9600n8
     earlyprintk=uart,mmio,0xff5e0000,115200n8

in addition to vga, ttyS, serial

Quoted 8 lines

I would rather try to merge 8250_early and early_printk. "console=uart,io,0x3f8" is already pretty similar to "earlyprintk=serial", and it would be nice to have only one.

"console=uart" does have the disadvantage that you have to know the port address. But it has the advantage that it doesn't depend on compiled-in legacy serial port names. If you need early console output, you're probably a developer and can come up with the address.

Given the generic name of "uart" I am assuming this will work with any
UART driver making use of the serial_core.c core -- am I correct?

Maciej

#6 lore raw
Quoted 14 lines · Maciej W. Rozycki
Quoted 12 lines · Bjorn Helgaas
Quoted 7 lines

for early_uart_console, I have some ideas:
1. merged that into early_serial_console in arch/x86_64/kernel/early_printk.c, and
move early_printk.c to kernel/, --- make it understand

     earlyprintk=uart,io,0x3f8,9600n8
     earlyprintk=uart,mmio,0xff5e0000,115200n8

in addition to vga, ttyS, serial

I would rather try to merge 8250_early and early_printk. "console=uart,io,0x3f8" is already pretty similar to "earlyprintk=serial", and it would be nice to have only one.

Quoted 7 lines
Quoted 4 lines

"console=uart" does have the disadvantage that you have to know the port address. But it has the advantage that it doesn't depend on compiled-in legacy serial port names. If you need early console output, you're probably a developer and can come up with the address.

Given the generic name of "uart" I am assuming this will work with any
UART driver making use of the serial_core.c core -- am I correct?

I knew somebody would ask that eventually :-)

Unfortunately, the answer is "no." "console=uart" only works with 8250-compatible devices.

#7 lore raw
Quoted 7 lines · Bjorn Helgaas
Quoted 2 lines

Given the generic name of "uart" I am assuming this will work with any
UART driver making use of the serial_core.c core -- am I correct?

I knew somebody would ask that eventually :-)

Unfortunately, the answer is "no." "console=uart" only works with 8250-compatible devices.

But is it a design limitation or is it just that other UART drivers have
to be modified to work with this option? My point is if the former, then the option should be something like "console=8250" (the right-hand side being the name of the driver involved; others may want to add support for other drivers). If the latter, then it's fine as is as other UART drivers may be wired to this code as a need arises.

Maciej

#8 lore raw
Quoted 10 lines · Maciej W. Rozycki
Quoted 7 lines · Bjorn Helgaas
Quoted 2 lines

Given the generic name of "uart" I am assuming this will work with any
UART driver making use of the serial_core.c core -- am I correct?

I knew somebody would ask that eventually :-)

Unfortunately, the answer is "no." "console=uart" only works with 8250-compatible devices.

Quoted 9 lines

But is it a design limitation or is it just that other UART drivers have
to be modified to work with this option? My point is if the former, then the option should be something like "console=8250" (the right-hand side being the name of the driver involved; others may want to add support for other drivers). If the latter, then it's fine as is as other UART drivers may be wired to this code as a need arises.

Maciej

Actually that early_uart is not real early one.
it is called via console_initcall.

for IA64, Bjom is calling that directly in setup_arch.

Please check my patch to make it to be called via early_param, that will be good to other platform.

also you may extend to support other early_uart.

YH

[PATCH] serial: make early_uart to use early_prarm instead of console_initcall

Make early_uart to use early_param, so uart console can be used earlier. Make it to be bootconsole with CON_BOOT flag, so can use console handover feature.
new command line will be
earlycon=uart,io,0x3f8,9600n8 console=ttyS0,9600
it will print in very early stage
Early serial console at I/O port 0x3f8 (options '9600n8') later for console it will print
console handover: boot [uart0] -> real [ttyS0]

Signed-off-by <[email protected]>
drivers/serial/8250.c +0 -33
index 48e259a..2a76618 100644
@@ -2533,39 +2538,6 @@ static int __init serial8250_console_init(void)
 }
 console_initcall(serial8250_console_init);
 
-static int __init find_port(struct uart_port *p)
-{
-	int line;
-	struct uart_port *port;
-
-	for (line = 0; line < nr_uarts; line++) {
-		port = &serial8250_ports[line].port;
-		if (uart_match_port(p, port))
-			return line;
-	}
-	return -ENODEV;
-}
-
-int __init serial8250_start_console(struct uart_port *port, char *options)
-{
-	int line;
-
-	line = find_port(port);
-	if (line < 0)
-		return -ENODEV;
-
-	add_preferred_console("ttyS", line, options);
-	printk("Adding console on ttyS%d at %s 0x%lx (options '%s')\n",
-		line, port->iotype == UPIO_MEM ? "MMIO" : "I/O port",
-		port->iotype == UPIO_MEM ? (unsigned long) port->mapbase :
-		    (unsigned long) port->iobase, options);
-	if (!(serial8250_console.flags & CON_ENABLED)) {
-		serial8250_console.flags &= ~CON_PRINTBUFFER;
-		register_console(&serial8250_console);
-	}
-	return line;
-}
-
 #define SERIAL8250_CONSOLE	&serial8250_console
 #else
 #define SERIAL8250_CONSOLE	NULL
drivers/serial/8250_early.c +22 -40

109 lines not on this page · raw message

include/linux/serial.h +0 -6
index 33fc8cb..deb7143 100644
@@ -177,11 +177,5 @@ struct serial_icounter_struct {
 #ifdef __KERNEL__
 #include <linux/compiler.h>
 
-/* Allow architectures to override entries in serial8250_ports[] at run time: */
-struct uart_port;	/* forward declaration */
-extern int early_serial_setup(struct uart_port *port);
-extern int early_serial_console_init(char *options);
-extern int serial8250_start_console(struct uart_port *port, char *options);
-
 #endif /* __KERNEL__ */
 #endif /* _LINUX_SERIAL_H */
#9 lore raw
In reply to Maciej W. Rozycki
Quoted 9 lines · Maciej W. Rozycki
Quoted 7 lines · Bjorn Helgaas
Quoted 2 lines

Given the generic name of "uart" I am assuming this will work with any
UART driver making use of the serial_core.c core -- am I correct?

I knew somebody would ask that eventually :-)

Unfortunately, the answer is "no." "console=uart" only works with 8250-compatible devices.

Quoted 6 lines

But is it a design limitation or is it just that other UART drivers have
to be modified to work with this option? My point is if the former, then the option should be something like "console=8250" (the right-hand side being the name of the driver involved; others may want to add support for other drivers). If the latter, then it's fine as is as other UART drivers may be wired to this code as a need arises.

"console=8250" probably would have been a better choice. I think this could be changed without too much hassle.

It might be possible to extend "console=uart" so one could do "console=uart,io,0x3f8,9600n8,21285" (where "21285" is a non-8250 UART type). But that seems ugly to me. I'd rather have "console=21285", "console=68328", etc.

I just want the "console=<tag>" to explicitly identify the UART type so we don't have to poke at the thing and guess what it is.

Bjorn