Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 15 Mar 2002 14:00:27 +0100
From:      Thomas Quinot <thomas@cuivre.fr.eu.org>
To:        Pierre Beyssac <pb@fasterix.frmug.org>
Cc:        Ruslan Ermilov <ru@FreeBSD.org>, cvs-all@freebsd.org
Subject:   Re: cvs commit: src/sys/boot/i386/boot2 boot2.c src/sbin/reboot boot_i386.8
Message-ID:  <20020315140027.A60859@melusine.cuivre.fr.eu.org>
In-Reply-To: <20020315015833.A447@fasterix.frmug.org>; from pb@fasterix.frmug.org on Fri, Mar 15, 2002 at 01:58:33AM %2B0100
References:  <200203131103.g2DB3aD93661@freefall.freebsd.org> <20020315015833.A447@fasterix.frmug.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Le 2002-03-15, Pierre Beyssac écrivait :

> BTW, I am currently testing a set of patches to boot2 written by
> Thomas Quinot after we discussed the matter, adding a '-n' option
> to boot2 to ignore keypresses (and doing some code cleanup at the
> same time).

Actually there are two separate patches: one is only de-obfuscation
of some parts of boot2.c, with strictly no functional changes. The
second adds a -n option to prevent any user interference in the boot
process.

I have already tested both changes here on a -current box; it would be
nice if others could review these changes.

Here are the diffs:

Index: sys/boot/i386/boot2/boot2.c
===================================================================
RCS file: /home/ncvs/src/sys/boot/i386/boot2/boot2.c,v
retrieving revision 1.37
diff -u -r1.37 boot2.c
--- sys/boot/i386/boot2/boot2.c	13 Mar 2002 11:03:36 -0000	1.37
+++ sys/boot/i386/boot2/boot2.c	15 Mar 2002 12:46:54 -0000
@@ -37,6 +37,11 @@
 #include "boot2.h"
 #include "lib.h"
 
+#define IO_KEYBOARD	1
+#define IO_SERIAL	2
+
+#define SECOND		18	/* Circa that many ticks in a second. */
+
 #define RBX_ASKNAME	0x0	/* -a */
 #define RBX_SINGLE	0x1	/* -s */
 #define RBX_DFLTROOT	0x5	/* -r */
@@ -136,7 +141,7 @@
 static struct bootinfo bootinfo;
 static int ls;
 static uint32_t fs_off;
-static uint8_t ioctrl = 0x1;
+static uint8_t ioctrl = IO_KEYBOARD;
 
 void exit(int);
 static void load(const char *);
@@ -279,34 +284,39 @@
     bootinfo.bi_memsizes_valid++;
     for (i = 0; i < N_BIOS_GEOM; i++)
 	bootinfo.bi_bios_geom[i] = drvinfo(i);
-    autoboot = 2;
+
+    /* Process configuration file */
+
+    autoboot = 1;
     readfile(PATH_CONFIG, cmd, sizeof(cmd));
     if (*cmd) {
 	printf("%s: %s", PATH_CONFIG, cmd);
 	if (parse(cmd))
 	    autoboot = 0;
-	*cmd = 0;
     }
-    if (autoboot && !*kname) {
-	if (autoboot == 2) {
-	    memcpy(kname, PATH_BOOT3, sizeof(PATH_BOOT3));
-	    if (!keyhit(0x37)) {
-		load(kname);
-		autoboot = 1;
-	    }
-	}
-	if (autoboot == 1)
+
+    /* Try to exec stage 3 boot loader. If interrupted by a keypress, *
+     * or in case of failure, try to load a kernel directly instaed.  */
+
+    if (autoboot) {
+	memcpy(kname, PATH_BOOT3, sizeof(PATH_BOOT3));
+	if (!keyhit(3 * SECOND)) {
+	    load(kname);
 	    memcpy(kname, PATH_KERNEL, sizeof(PATH_KERNEL));
+	}
     }
+
+    /* Present the user with the boot2 prompt. */
+
     for (;;) {
 	printf(" \n>> FreeBSD/i386 BOOT\n"
 	       "Default: %u:%s(%u,%c)%s\n"
 	       "boot: ",
 	       dsk.drive & DRV_MASK, dev_nm[dsk.type], dsk.unit,
 	       'a' + dsk.part, kname);
-	if (ioctrl & 0x2)
+	if (ioctrl & IO_SERIAL)
 	    sio_flush();
-	if (!autoboot || keyhit(0x5a))
+	if (!autoboot || keyhit(5 * SECOND))
 	    getstr(cmd, sizeof(cmd));
 	else
 	    putchar('\n');
@@ -445,9 +455,9 @@
 		    opts |= 1 << RBX_DUAL | 1 << RBX_SERIAL;
 		opts &= ~(1 << RBX_PROBEKBD);
 	    }
-	    ioctrl = opts & 1 << RBX_DUAL ? 0x3 :
-		     opts & 1 << RBX_SERIAL ? 0x2 : 0x1;
-	    if (ioctrl & 0x2)
+	    ioctrl = opts & 1 << RBX_DUAL ? (IO_SERIAL | IO_KEYBOARD) :
+		     opts & 1 << RBX_SERIAL ? IO_SERIAL : IO_KEYBOARD;
+	    if (ioctrl & IO_SERIAL)
 	        sio_init();
 	} else {
 	    for (q = arg--; *q && *q != '('; q++);
@@ -790,9 +800,9 @@
 static int
 xputc(int c)
 {
-    if (ioctrl & 0x1)
+    if (ioctrl & IO_KEYBOARD)
 	putc(c);
-    if (ioctrl & 0x2)
+    if (ioctrl & IO_SERIAL)
 	sio_putc(c);
     return c;
 }
@@ -801,9 +811,9 @@
 xgetc(int fn)
 {
     for (;;) {
-	if (ioctrl & 0x1 && getc(1))
+	if (ioctrl & IO_KEYBOARD && getc(1))
 	    return fn ? 1 : getc(0);
-	if (ioctrl & 0x2 && sio_ischar())
+	if (ioctrl & IO_SERIAL && sio_ischar())
 	    return fn ? 1 : sio_getc();
 	if (fn)
 	    return 0;

The second patch adds option '-n', which can be used in /boot.config:

--- sys/boot/i386/boot2/boot2.c.orig	Fri Mar 15 00:49:06 2002
+++ sys/boot/i386/boot2/boot2.c.optn	Fri Mar 15 13:45:23 2002
@@ -55,2 +55,3 @@
 #define RBX_PROBEKBD	0x1e	/* -P */
+#define RBX_NOINTR	0x1f	/* -n */
 
@@ -63,3 +64,3 @@
 #define ARGS		0x900
-#define NOPT		13
+#define NOPT		14
 #define NDEV		5
@@ -105,3 +106,3 @@
 
-static const char optstr[NOPT] = "DhaCcdgmPprsv";
+static const char optstr[NOPT] = "DhaCcdgmnPprsv";
 static const unsigned char flags[NOPT] = {
@@ -115,2 +116,3 @@
     RBX_MUTE,
+    RBX_NOINTR,
     RBX_PROBEKBD,
@@ -780,2 +782,4 @@
 
+    if (opts & 1 << RBX_NOINTR)
+	return 0;
     t0 = 0;
@@ -805,2 +809,4 @@
 {
+    if (opts & 1 << RBX_NOINTR)
+	return 0;
     for (;;) {

Thomas.

-- 
    Thomas.Quinot@Cuivre.FR.EU.ORG

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe cvs-all" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020315140027.A60859>