[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#504721: Possible reason for serial console misdetection



tags 504721 patch
thanks

On Wednesday 26 November 2008, Jérémy Bobbio wrote:
> > So, the problem is that reopen-console gives preference to the value
> > in 'console handover' line, which is incorrect on sparc (refers to a
> > real terminal console even if one is connecting through serial). If
> > it is obvious, that sparc is unique that way, and it works correctly
> > on other arches, the following (untested) patch might do the trick:
> > […]
>
> In order to implement this, I have tried to understand the kernel logic
> by reading at the relevant part of its source code as I have not been
> able to find any relevant documentation about all this.

I've done some testing today on my Sparc Ultra 10 and can simply reproduce 
the problem by booting it with no keyboard connected, which means it will 
default to serial console.

If I do that I get kernel boot messages on serial console, but the D-I 
frontend is shown on the display that is connected to the VGA port as if 
it's running on virtual console.

dmesg shows:
[...]
OF stdout device is: /pci@1f,0/pci@1,1/ebus@1/se@14,400000:a
[...]
Console: colour dummy device 80x25
console handover: boot [earlyprom0] -> real [tty0]
[...]
f0061c64: ttyS0 at MMIO 0x1fff1400000 (irq = 5) is a SAB82532 V3.2
Console: ttyS0 (SAB82532)
console [ttyS0] enabled
f0061c64: ttyS1 at MMIO 0x1fff1400040 (irq = 5) is a SAB82532 V3.2


Replacing /sbin/reopen-console by /bin/cttyhack (which we were using 
previously) in /etc/inittab fixes the problem. Which also means that 
there really is absolutely no reason to just accept this regression for 
Lenny.


So, cttyhack basically does the right thing by checking what type of 
console the initial shell is actually running in. The only real problem 
with it was that it supported nothing else than /dev/ttyS0 for the 
subsequent console stealing. That last part was implemented quite nicely 
in reopen-console, but the first part is missing.

So here is a patch that adds that. The new 'console-type.c' is a very 
basic copy-and-naive-cleanup of cttyhack and does only one thing: 
print "virtual" or "serial" to stdout.

Strange thing is that it seems to work perfectly. Tested only on sparc, 
both with and without keyboard connected, i.e. both for serial and 
virtual console.

Here's a netboot image that includes the patched rootskel; please test!
http://people.debian.org/%7Efjp/tmp/d-i/boot_sparc.img

Someone who can actually write in C please check the code and let me know 
if anything can be removed or is missing. I may well have added unneeded 
includes for example and I have no idea what the original sprintf 
statements were supposed to do.

Disclaimer: this patch was written after having been awake for 25 hours, 
including a visit to the gym; if reading up blows up your mind I cannot 
be held responsible.

Property changes on: .
___________________________________________________________________
Added: svn:ignore
   + console-type
steal-ctty


Index: console-type.c
===================================================================
--- console-type.c	(revision 0)
+++ console-type.c	(revision 0)
@@ -0,0 +1,72 @@
+/* vi: set sw=4 ts=4: */
+/*
+ *
+ * Licensed under GPLv2
+ *
+ * Adapted for Debian Installer by Frans Pop <fjp.debian.org> from
+ * cttyhack from busybox 1.11, which is
+ *
+ * Copyright (c) 2007 Denys Vlasenko <vda.linux@googlemail.com>
+ */
+
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <string.h>
+
+/* From <linux/vt.h> */
+struct vt_stat {
+	unsigned short v_active;        /* active vt */
+	unsigned short v_signal;        /* signal to send */
+	unsigned short v_state;         /* vt bitmask */
+};
+enum { VT_GETSTATE = 0x5603 }; /* get global vt state info */
+
+/* From <linux/serial.h> */
+struct serial_struct {
+	int	type;
+	int	line;
+	unsigned int	port;
+	int	irq;
+	int	flags;
+	int	xmit_fifo_size;
+	int	custom_divisor;
+	int	baud_base;
+	unsigned short	close_delay;
+	char	io_type;
+	char	reserved_char[1];
+	int	hub6;
+	unsigned short	closing_wait;   /* time to wait before closing */
+	unsigned short	closing_wait2;  /* no longer used... */
+	unsigned char	*iomem_base;
+	unsigned short	iomem_reg_shift;
+	unsigned int	port_high;
+	unsigned long	iomap_base;	/* cookie passed into ioremap */
+	int	reserved[1];
+};
+
+int main(int argc, char ** argv)
+{
+	char console[sizeof(int)*3 + 16];
+	union {
+		struct vt_stat vt;
+		struct serial_struct sr;
+		char paranoia[sizeof(struct serial_struct) * 3];
+	} u;
+
+	strcpy(console, "/dev/tty");
+	if (ioctl(0, TIOCGSERIAL, &u.sr) == 0) {
+		/* this is a serial console */
+		printf("serial\n");
+		// sprintf(console + 8, "S%d", u.sr.line);
+	} else if (ioctl(0, VT_GETSTATE, &u.vt) == 0) {
+		/* this is linux virtual tty */
+		printf("virtual\n");
+		// sprintf(console + 8, "S%d" + 1, u.vt.v_active);
+	}
+
+	return 0;
+}
Index: reopen-console
===================================================================
--- reopen-console	(revision 56825)
+++ reopen-console	(working copy)
@@ -6,11 +6,18 @@
 NL="
 "
 
+console=
 if ! [ -f /var/run/console-device ]; then
-	# If the kernel emitted an "handover" message, then it's the one
+	# If the kernel emitted a "handover" message, then it's the one
 	console="$(dmesg -s 65535 |
 		sed -n -e 's/.*\] console handover: boot \[.*\] -> real \[\(.*\)\]$/\1/p')"
 
+	# Except if it is the wrong type...
+	if ["$console" ] && [ "$(console-type)" = serial ] && \
+	   expr "$console" : "tty[0-9]" >/dev/null; then
+		console=
+	fi
+
 	consoles=
 	if [ -z "$console" ]; then
 		# Retrieve all enabled consoles from boot log; ignore those
Index: Makefile
===================================================================
--- Makefile	(revision 56825)
+++ Makefile	(working copy)
@@ -6,14 +6,18 @@
 	shutdown \
 	init \
 	reopen-console \
+	console-type \
 	steal-ctty
 
+console-type: console-type.c
+	gcc -Os -Wall console-type.c -o console-type
+
 steal-ctty: steal-ctty.c
 	gcc -Os -Wall steal-ctty.c -o steal-ctty
 
-build: steal-ctty
+build: console-type steal-ctty
 
 clean:
-	rm -f steal-ctty
+	rm -f console-type steal-ctty
 
 include ../../Makefile.inc

Attachment: signature.asc
Description: This is a digitally signed message part.


Reply to: