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

Re: CVS version builds but doesn't run



Erik Andersen wrote:
> On Tue Nov 02, 1999 at 11:47:05AM -0700, Matt Porter wrote:
> > 
> > I will try this on a video console machine since I can't see a lot of error
> > messages on serial console.
> 
> On the subject of serial console... Anybody know if the sparc
> is still broken wrt serial console?  The old busybox init.c
> checks if console==/dev/tty[ab] and then remaps things to
> /dev/ttyS[01].  Is this sort of uglyness still needed?

It's not broken, it's a short hand to force boot on serial console: you can
pass console=ttya to the kernel directly (console=prom is another alternative
to display using OpenPROM monitor instead of Linux framebuffer).
Anyway, under 2.2 kernels, /dev/console is always used and linked to the right
device.
console=tty[ab] was needed by init running on 2.0 kernel to detect serial boot,
after the kernel has started displaying to /dev/ttySN (/dev/cuaN really).  This
syntax is still supported by 2.2 kernels but init don't have to worry about
because /dev/console is always linked to the real backend.  However, since the
code that implements this is really short, could you keep it in init?

> Also, a bunch of the console detection code could be simplified if 
> I can be assured that somebody has done a:
>     rm -f console
>     mknod -m 622 console c 5 1
> 
> Do the boot floppies now have /dev/console as a device instead of
> a symlink?

It's already the case in our current boot-floppies, but I think you missed the
point.
You *should* use the right real console backend for the first terminal instead
of /dev/console because the later is *not* supporting job control.  To figure
out what device is the real backend (serial consoles or linux VT), issue
TIOCGSERIAL & VT_GETSTATE ioctls.  See my patch below.

Moreover, what if there is no VT console, just serial one?  init is then trying
to run a shell in /dev/tty2 everytime even when no such terminal exists.  In
this case, console screen is flooded with these messages:

    Bummer, can't write to log on /dev/tty3!
    modprobe: Can't open dependencies file /lib/modules/2.2.13/modules.dep

The last one is due to the kernel which is wanting to run modprobe asking to
load the vt module :((
Well, even if modprobe find its dep file, it will be run ever and ever because
the vt driver is compiled in kernel but not enabled on serial boot.

The patch to fix all these problems is attached to this email.  It works quite
well on sparc but don't know about other architectures.  Hope it works too...
Could you run some trial?

>  -Erik

Regards.


-- 
 Eric Delaunay                 | "La guerre justifie l'existence des militaires.
 delaunay@lix.polytechnique.fr | En les supprimant." Henri Jeanson (1900-1970)
--- init.c.orig	Fri Nov  5 21:32:31 1999
+++ init.c	Sat Nov  6 22:16:13 1999
@@ -53,7 +53,7 @@
 
 #define LOG             0x1
 #define CONSOLE         0x2
-static char *console = VT_CONSOLE;
+static char console[16] = VT_CONSOLE;
 static char *second_console = VT_SECONDARY;
 static char *log = VT_LOG;
 static int kernel_version = 0;
@@ -88,8 +88,14 @@
 
     /* Take full control of the log tty, and never close it.
      * It's mine, all mine!  Muhahahaha! */
-    if (log_fd==-1) {
-	if ((log_fd = device_open(log, O_RDWR|O_NDELAY)) < 0) {
+    if (log_fd < 0) {
+	if (log == NULL) {
+	    /* don't even try to log, because there is no such console */
+	    log_fd = -2;
+	    /* log to main console instead */
+	    device = CONSOLE;
+	}
+	else if ((log_fd = device_open(log, O_RDWR|O_NDELAY)) < 0) {
 	    log_fd=-1;
 	    fprintf(stderr, "Bummer, can't write to log on %s!\r\n", log);
 	    fflush(stderr);
@@ -97,7 +103,7 @@
 	}
     }
 
-    if ( (device & LOG) && (log_fd != -1) ) {
+    if ( (device & LOG) && (log_fd >= 0) ) {
 	va_start(arguments, fmt);
 	vdprintf(log_fd, fmt, arguments);
 	va_end(arguments);
@@ -181,46 +187,66 @@
     int tried_devcons = 0;
     int tried_vtprimary = 0;
     char *s;
+    struct serial_struct sr;
+    struct vt_stat vt;
 
     if ((s = getenv("CONSOLE")) != NULL) {
-	console = s;
-/* Apparently the sparc does wierd things... */
+	strncpy( console, s, sizeof console );
+    }
 #if defined (__sparc__)
-	if (strncmp( s, "/dev/tty", 8 )==0) {
-	    switch( s[8]) {
-		case 'a':
-		    s=SERIAL_CON0;
-		    break;
-		case 'b':
-		    s=SERIAL_CON1;
-	    }
-	}
+    /* sparc kernel supports console=tty[ab] parameter which is also passed to
+     * init, so catch it here */
+    else if ((s = getenv("console")) != NULL) {
+	/* remap tty[ab] to /dev/ttyS[01] */
+	if (strcmp( s, "ttya" )==0)
+	    strcpy( console, SERIAL_CON0 );
+	else if (strcmp( s, "ttyb" )==0)
+	    strcpy( console, SERIAL_CON1 );
+    }
 #endif
-    } else {
-	console = VT_CONSOLE;
-	tried_devcons++;
+    else {
+	/* 2.2 kernels: identify the real console backend and try to use it */
+	if (ioctl(0,TIOCGSERIAL,&sr) == 0) {
+	    /* this is a serial console */
+	    snprintf( console, sizeof console, "/dev/ttyS%d", sr.line );
+	}
+	else if (ioctl(0, VT_GETSTATE, &vt) == 0) {
+	    /* this is linux virtual tty */
+	    snprintf( console, sizeof console, "/dev/tty%d", vt.v_active );
+	}
+	else {
+	    strcpy( console, VT_CONSOLE );
+	    tried_devcons++;
+	}
     }
 
     while ((fd = open(console, O_RDONLY | O_NONBLOCK)) < 0) {
 	/* Can't open selected console -- try /dev/console */
 	if (!tried_devcons) {
 	    tried_devcons++;
-	    console = VT_CONSOLE;
+	    strcpy( console, VT_CONSOLE );
 	    continue;
 	}
 	/* Can't open selected console -- try vt1 */
 	if (!tried_vtprimary) {
 	    tried_vtprimary++;
-	    console = VT_PRIMARY;
+	    strcpy( console, VT_PRIMARY );
 	    continue;
 	}
 	break;
     }
     if (fd < 0)
 	/* Perhaps we should panic here? */
-	console = "/dev/null";
-    else
+	strcpy( console, "/dev/null" );
+    else {
+	/* check for serial console and disable logging to tty3 & running a
+	 * shell to tty2 */
+	if (ioctl(0,TIOCGSERIAL,&sr) == 0) {
+	    log = NULL;
+	    second_console = NULL;
+	}
 	close(fd);
+    }
     message(LOG, "console=%s\n", console );
 }
 
@@ -472,7 +498,7 @@
 	if (pid1 == 0 && tty0_commands) {
 	    pid1 = run(tty0_commands, console, wait_for_enter);
 	}
-	if (pid2 == 0 && tty1_commands) {
+	if (pid2 == 0 && tty1_commands && second_console) {
 	    pid2 = run(tty1_commands, second_console, TRUE);
 	}
 	wpid = wait(&status);

Reply to: