Source-Changes-HG archive

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

[src/trunk]: src patch posted to tech-kern@ 2014/06/25 for review with minor ...



details:   https://anonhg.NetBSD.org/src/rev/6c43487b765f
branches:  trunk
changeset: 796948:6c43487b765f
user:      rtr <rtr%NetBSD.org@localhost>
date:      Sat Jun 28 09:16:18 2014 +0000

description:
patch posted to tech-kern@ 2014/06/25 for review with minor changes
resulting from feedback.

move multiple copies of code for parsing boot.cfg file from sparc, i386
and zaurus into libsa/bootcfg.{h,c}. largely retained i386 parsing logic
in addition to keeping sparc dispatch function while remaining consistent
with boot.cfg(5).

previous sparc64 file format has been obsoleted but only used by boot
CDs distrib/sparc64/bootfs/boot.cfg has been updated to compensate.

exported names have been prefixed with either BOOTCFG_ or bootcfg_ as per
feedback from christos@

tested on amd64 & sparc64 but not zaurus.

diffstat:

 distrib/sparc64/bootfs/boot.cfg         |    2 +-
 sys/arch/i386/stand/boot/boot2.c        |   27 +-
 sys/arch/i386/stand/lib/bootmenu.c      |  267 ++++------------------------
 sys/arch/i386/stand/lib/bootmenu.h      |   17 +-
 sys/arch/i386/stand/pxeboot/main.c      |   17 +-
 sys/arch/sparc/stand/ofwboot/boot.c     |   73 +-------
 sys/arch/zaurus/stand/zboot/boot.c      |   13 +-
 sys/arch/zaurus/stand/zboot/boot.h      |    3 +-
 sys/arch/zaurus/stand/zboot/bootmenu.c  |  219 ++---------------------
 sys/arch/zaurus/stand/zboot/bootmenu.h  |   16 +-
 sys/arch/zaurus/stand/zboot/pathnames.h |    3 +-
 sys/lib/libsa/Makefile                  |    4 +-
 sys/lib/libsa/bootcfg.c                 |  292 ++++++++++++++++++++++++++++++++
 sys/lib/libsa/bootcfg.h                 |   56 ++++++
 14 files changed, 461 insertions(+), 548 deletions(-)

diffs (truncated from 1447 to 300 lines):

diff -r dd752a96c17e -r 6c43487b765f distrib/sparc64/bootfs/boot.cfg
--- a/distrib/sparc64/bootfs/boot.cfg   Sat Jun 28 08:02:09 2014 +0000
+++ b/distrib/sparc64/bootfs/boot.cfg   Sat Jun 28 09:16:18 2014 +0000
@@ -1,1 +1,1 @@
-bootpartition  :a
+bootpartition=:a
diff -r dd752a96c17e -r 6c43487b765f sys/arch/i386/stand/boot/boot2.c
--- a/sys/arch/i386/stand/boot/boot2.c  Sat Jun 28 08:02:09 2014 +0000
+++ b/sys/arch/i386/stand/boot/boot2.c  Sat Jun 28 09:16:18 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: boot2.c,v 1.62 2014/03/26 17:58:57 christos Exp $      */
+/*     $NetBSD: boot2.c,v 1.63 2014/06/28 09:16:18 rtr Exp $   */
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -72,6 +72,7 @@
 #include <sys/bootblock.h>
 
 #include <lib/libsa/stand.h>
+#include <lib/libsa/bootcfg.h>
 #include <lib/libsa/ufs.h>
 #include <lib/libkern/libkern.h>
 
@@ -239,7 +240,7 @@
 clearit(void)
 {
 
-       if (bootconf.clear)
+       if (bootcfg_info.clear)
                clear_pc_screen();
 }
 
@@ -268,9 +269,10 @@
        clearit();
 #ifndef SMALL
        int n;
-       if (bootconf.banner[0]) {
-               for (n = 0; bootconf.banner[n] && n < MAXBANNER; n++) 
-                       printf("%s\n", bootconf.banner[n]);
+       if (bootcfg_info.banner[0]) {
+               for (n = 0; bootcfg_info.banner[n]
+                   && n < BOOTCFG_MAXBANNER; n++) 
+                       printf("%s\n", bootcfg_info.banner[n]);
        } else {
 #endif /* !SMALL */
                printf("\n"
@@ -326,9 +328,9 @@
 
 #ifndef SMALL
        if (!(boot_params.bp_flags & X86_BP_FLAGS_NOBOOTCONF)) {
-               parsebootconf(BOOTCONF);
+               parsebootconf(BOOTCFG_FILENAME);
        } else {
-               bootconf.timeout = boot_params.bp_timeout;
+               bootcfg_info.timeout = boot_params.bp_timeout;
        }
        
 
@@ -336,14 +338,14 @@
         * If console set in boot.cfg, switch to it.
         * This will print the banner, so we don't need to explicitly do it
         */
-       if (bootconf.consdev)
-               command_consdev(bootconf.consdev);
+       if (bootcfg_info.consdev)
+               command_consdev(bootcfg_info.consdev);
        else 
                print_banner();
 
        /* Display the menu, if applicable */
        twiddle_toggle = 0;
-       if (bootconf.nummenu > 0) {
+       if (bootcfg_info.nummenu > 0) {
                /* Does not return */
                doboottypemenu();
        }
@@ -361,7 +363,8 @@
 #ifdef SMALL
                c = awaitkey(boot_params.bp_timeout, 1);
 #else
-               c = awaitkey((bootconf.timeout < 0) ? 0 : bootconf.timeout, 1);
+               c = awaitkey((bootcfg_info.timeout < 0) ? 0
+                   : bootcfg_info.timeout, 1);
 #endif
                if ((c != '\r') && (c != '\n') && (c != '\0')) {
                    if ((boot_params.bp_flags & X86_BP_FLAGS_PASSWORD) == 0) {
@@ -533,7 +536,7 @@
 command_menu(char *arg)
 {
 
-       if (bootconf.nummenu > 0) {
+       if (bootcfg_info.nummenu > 0) {
                /* Does not return */
                doboottypemenu();
        } else {
diff -r dd752a96c17e -r 6c43487b765f sys/arch/i386/stand/lib/bootmenu.c
--- a/sys/arch/i386/stand/lib/bootmenu.c        Sat Jun 28 08:02:09 2014 +0000
+++ b/sys/arch/i386/stand/lib/bootmenu.c        Sat Jun 28 09:16:18 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bootmenu.c,v 1.12 2014/04/06 19:11:26 jakllsch Exp $   */
+/*     $NetBSD: bootmenu.c,v 1.13 2014/06/28 09:16:18 rtr Exp $        */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -33,6 +33,7 @@
 #include <sys/bootblock.h>
 
 #include <lib/libsa/stand.h>
+#include <lib/libsa/bootcfg.h>
 #include <lib/libsa/ufs.h>
 #include <lib/libkern/libkern.h>
 
@@ -50,8 +51,6 @@
 #define MENUFORMAT_NUMBER 1
 #define MENUFORMAT_LETTER 2
 
-struct bootconf_def bootconf;
-
 int
 atoi(const char *in)
 {
@@ -69,203 +68,23 @@
 }
 
 /*
- * This function parses a boot.cfg file in the root of the filesystem
- * (if present) and populates the global boot configuration.
- *
- * The file consists of a number of lines each terminated by \n
- * The lines are in the format keyword=value. There should not be spaces
- * around the = sign.
- *
- * The recognised keywords are:
- * banner: text displayed instead of the normal welcome text
- * menu: Descriptive text:command to use
- * timeout: Timeout in seconds (overrides that set by installboot)
- * default: the default menu option to use if Return is pressed
- * consdev: the console device to use
- * format: how menu choices are displayed: (a)utomatic, (n)umbers or (l)etters
- * clear: whether to clear the screen or not
- *
- * Example boot.cfg file:
- * banner=Welcome to NetBSD
- * banner=Please choose the boot type from the following menu
- * menu=Boot NetBSD:boot netbsd
- * menu=Boot into single user mode:boot netbsd -s
- * menu=:boot hd1a:netbsd -cs
- * menu=Goto boot comand line:prompt
- * timeout=10
- * consdev=com0
- * default=1
-*/
+ * XXX
+ * if module_add, userconf_add are strictly mi they can be folded back
+ * into sys/lib/libsa/bootcfg.c:perform_bootcfg().
+ */
+static void
+do_bootcfg_command(const char *cmd, char *arg)
+{
+       if (strcmp(cmd, BOOTCFG_CMD_LOAD) == 0)
+               module_add(arg);
+       else if (strcmp(cmd, BOOTCFG_CMD_USERCONF) == 0)
+               userconf_add(arg);
+}
+
 void
 parsebootconf(const char *conf)
 {
-       char *bc, *c;
-       int cmenu, cbanner, len;
-       int fd, err, off;
-       struct stat st;
-       char *next, *key, *value, *v2;
-
-       /* Clear bootconf structure */
-       memset((void *)&bootconf, 0, sizeof(bootconf));
-
-       /* Set timeout to configured */
-       bootconf.timeout = boot_params.bp_timeout;
-
-       /* automatically switch between letter and numbers on menu */
-       bootconf.menuformat = MENUFORMAT_AUTO;
-
-       fd = open(BOOTCONF, 0);
-       if (fd < 0)
-               return;
-
-       err = fstat(fd, &st);
-       if (err == -1) {
-               close(fd);
-               return;
-       }
-
-       /*
-        * Check the size. A bootconf file is normally only a few
-        * hundred bytes long. If it is much bigger than expected,
-        * don't try to load it. We can't load something big into
-        * an 8086 real mode segment anyway, and in pxeboot this is
-        * probably a case of the loader getting a filename for the
-        * kernel and thinking it is boot.cfg by accident. (The 32k
-        * number is arbitrary but 8086 real mode data segments max
-        * out at 64k.)
-        */
-       if (st.st_size > 32768) {
-               close(fd);
-               return;
-       }
-
-       bc = alloc(st.st_size + 1);
-       if (bc == NULL) {
-               printf("Could not allocate memory for boot configuration\n");
-               return;
-       }
-
-       off = 0;
-       do {
-               len = read(fd, bc + off, 1024);
-               if (len <= 0)
-                       break;
-               off += len;
-       } while (len > 0);
-       bc[off] = '\0';
-
-       close(fd);
-       /* bc now contains the whole boot.cfg file */
-
-       cmenu = 0;
-       cbanner = 0;
-       for (c = bc; *c; c = next) {
-               key = c;
-               /* find end of line */
-               for (; *c && *c != '\n'; c++)
-                       /* zero terminate line on start of comment */
-                       if (*c == '#')
-                               *c = 0;
-               /* zero terminate line */
-               if (*(next = c))
-                       *next++ = 0;
-               /* Look for = separator between key and value */
-               for (c = key; *c && *c != '='; c++)
-                       continue;
-               /* Ignore lines with no key=value pair */
-               if (*c == '\0')
-                       continue;
-
-               /* zero terminate key which points to keyword */
-               *c++ = 0;
-               value = c;
-               /* Look for end of line (or file) and zero terminate value */
-               for (; *c && *c != '\n'; c++)
-                       continue;
-               *c = 0;
-
-               if (!strncmp(key, "menu", 4)) {
-                       /*
-                        * Parse "menu=<description>:<command>".  If the
-                        * description is empty ("menu=:<command>)",
-                        * then re-use the command as the description.
-                        * Note that the command may contain embedded
-                        * colons.
-                        */
-                       if (cmenu >= MAXMENU)
-                               continue;
-                       bootconf.desc[cmenu] = value;
-                       for (v2 = value; *v2 && *v2 != ':'; v2++)
-                               continue;
-                       if (*v2) {
-                               *v2++ = 0;
-                               bootconf.command[cmenu] = v2;
-                               if (! *value)
-                                       bootconf.desc[cmenu] = v2;
-                               cmenu++;
-                       } else {
-                               /* No delimiter means invalid line */
-                               bootconf.desc[cmenu] = NULL;
-                       }
-               } else if (!strncmp(key, "banner", 6)) {
-                       if (cbanner < MAXBANNER)
-                               bootconf.banner[cbanner++] = value;
-               } else if (!strncmp(key, "timeout", 7)) {
-                       if (!isnum(*value))
-                               bootconf.timeout = -1;
-                       else
-                               bootconf.timeout = atoi(value);
-               } else if (!strncmp(key, "default", 7)) {
-                       bootconf.def = atoi(value) - 1;
-               } else if (!strncmp(key, "consdev", 7)) {
-                       bootconf.consdev = value;
-               } else if (!strncmp(key, "load", 4)) {
-                       module_add(value);
-               } else if (!strncmp(key, "format", 6)) {
-                       printf("value:%c\n", *value);
-                       switch (*value) {
-                       case 'a':
-                       case 'A':
-                               bootconf.menuformat = MENUFORMAT_AUTO;
-                               break;
-
-                       case 'n':
-                       case 'N':



Home | Main Index | Thread Index | Old Index