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

Bug#493865: cttyhack does not handle other serial devices than ttySn (was: Bug booting from console)



reassign 493865 busybox-udeb
retitle 493865 cttyhack does not handle other serial devices than ttySn
tags 493865 + d-i patch
severity 493865 important
thanks

On Tue, Aug 05, 2008 at 03:29:29PM +0200, Giuseppe Falsetti wrote:
> I'm trying to install lenny/beta2 on an headless xserveG5.
> The install cd kernel find the serial device Zilog /ttyPZ0-PZ1 but the 
> kernel want only the ttyS0 device as shown below.
> […]
> cttyhack: can't open '/dev/ttyS0': No such device or address

Actually, this is not the kernel, but cttyhack from the busybox suite.

cttyhack currently forces the serial device to be named /dev/ttySn,
which is an issue on plateform where serial devices are named
differently.

The attached patch makes cttyhack scan the kernel command line in
order to get the correct serial device.  This is another hack in the
hack, but it should fixes the issue for d-i.

Cheers,
-- 
Jérémy Bobbio                        .''`. 
lunar@debian.org                    : :Ⓐ  :  # apt-get install anarchism
                                    `. `'` 
                                      `-   
Only in busybox-1.10.2-fix-cttyhack/debian: build
Only in busybox-1.10.2-fix-cttyhack/debian: busybox-udeb
Only in busybox-1.10.2-fix-cttyhack/debian: busybox-udeb.debhelper.log
Only in busybox-1.10.2-fix-cttyhack/debian: busybox-udeb.substvars
Only in busybox-1.10.2-fix-cttyhack/debian: files
Only in busybox-1.10.2-fix-cttyhack/debian: stamps
Only in busybox-1.10.2-fix-cttyhack/shell: .cttyhack.c.swp
diff -ur busybox-1.10.2/shell/cttyhack.c busybox-1.10.2-fix-cttyhack/shell/cttyhack.c
--- busybox-1.10.2/shell/cttyhack.c	2008-04-19 05:50:31.000000000 +0200
+++ busybox-1.10.2-fix-cttyhack/shell/cttyhack.c	2008-08-05 18:41:26.981904513 +0200
@@ -6,6 +6,9 @@
  */
 #include "libbb.h"
 
+#include <asm/setup.h>
+#include <string.h>
+
 /* From <linux/vt.h> */
 struct vt_stat {
 	unsigned short v_active;        /* active vt */
@@ -37,6 +40,36 @@
 	int	reserved[1];
 };
 
+static int get_console_in_cmdline(char * dest)
+{
+	FILE *fcmdline;
+	char buffer[COMMAND_LINE_SIZE];
+	char * p;
+	char * start;
+	size_t len;
+
+	if (NULL == (fcmdline = fopen("/proc/cmdline", "r"))) {
+		return 1;
+	}
+	if (NULL == fgets(buffer, COMMAND_LINE_SIZE, fcmdline)) {
+		return 1;
+	}
+	/* find the last occurence of "console=" */
+	p = strstr(buffer, "console=");
+	while (p != NULL) {
+		start = p;
+		p = strstr(start + 1, "console=");
+	}
+	if (NULL == start) {
+		return 1;
+	}
+	start += 8;
+	len = strcspn(start, ", \n\t");
+	strncpy(dest, start, len);
+	dest[len] = '\0';
+	return 0;
+}
+
 int cttyhack_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int cttyhack_main(int argc ATTRIBUTE_UNUSED, char **argv)
 {
@@ -55,7 +88,10 @@
 	strcpy(console, "/dev/tty");
 	if (ioctl(0, TIOCGSERIAL, &u.sr) == 0) {
 		/* this is a serial console */
-		sprintf(console + 8, "S%d", u.sr.line);
+		if (get_console_in_cmdline(console + 5) != 0) {
+			/* fallback to ttySn */
+			sprintf(console + 8, "S%d", u.sr.line);
+		}
 	} else if (ioctl(0, VT_GETSTATE, &u.vt) == 0) {
 		/* this is linux virtual tty */
 		sprintf(console + 8, "S%d" + 1, u.vt.v_active);

Attachment: signature.asc
Description: Digital signature


Reply to: