Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/i386/stand Two changes for the i386 boot loader rel...



details:   https://anonhg.NetBSD.org/src/rev/544f9bc128fd
branches:  trunk
changeset: 788906:544f9bc128fd
user:      he <he%NetBSD.org@localhost>
date:      Sun Jul 28 08:50:09 2013 +0000

description:
Two changes for the i386 boot loader related to the boot menu which
can be defined in boot.cfg:

 * Add a "menu" command which re-displays the menu and initiates
   the timed countdown
 * Use any default command defined in boot.cfg as default args
   if the user runs "boot" with no arguments

This is useful in circumstances where you e.g. need to interrupt
the normal boot process to switch to serial console, and where
simply "boot netbsd" is no longer sufficient (e.g. as with install
media which needs the miniroot kernel module loaded).

diffstat:

 sys/arch/i386/stand/boot/boot2.c   |  30 ++++++++++++++-
 sys/arch/i386/stand/lib/bootmenu.c |  74 ++++++++++++++++++++++++++-----------
 sys/arch/i386/stand/lib/bootmenu.h |   3 +-
 3 files changed, 82 insertions(+), 25 deletions(-)

diffs (195 lines):

diff -r e91be02d7e1b -r 544f9bc128fd sys/arch/i386/stand/boot/boot2.c
--- a/sys/arch/i386/stand/boot/boot2.c  Sun Jul 28 06:12:45 2013 +0000
+++ b/sys/arch/i386/stand/boot/boot2.c  Sun Jul 28 08:50:09 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: boot2.c,v 1.58 2012/08/04 03:51:27 riastradh Exp $     */
+/*     $NetBSD: boot2.c,v 1.59 2013/07/28 08:50:09 he Exp $    */
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -120,6 +120,9 @@
 void   command_boot(char *);
 void   command_dev(char *);
 void   command_consdev(char *);
+#ifndef SMALL
+void   command_menu(char *);
+#endif
 void   command_modules(char *);
 void   command_multiboot(char *);
 
@@ -131,6 +134,9 @@
        { "boot",       command_boot },
        { "dev",        command_dev },
        { "consdev",    command_consdev },
+#ifndef SMALL
+       { "menu",       command_menu },
+#endif
        { "modules",    command_modules },
        { "load",       module_add },
        { "multiboot",  command_multiboot },
@@ -394,6 +400,9 @@
               "dev xd[N[x]]:\n"
               "consdev {pc|com[0123]|com[0123]kbd|auto}\n"
               "vesa {modenum|on|off|enabled|disabled|list}\n"
+#ifndef SMALL
+              "menu (reenters boot menu, if defined in boot.cfg)\n"
+#endif
               "modules {on|off|enabled|disabled}\n"
               "load {path_to_module}\n"
               "multiboot [xdNx:][filename] [<args>]\n"
@@ -439,6 +448,10 @@
                bootit(filename, howto, tell);
        } else {
                int i;
+
+#ifndef SMALL
+               bootdefault();
+#endif
                for (i = 0; i < NUMNAMES; i++) {
                        bootit(names[i][0], howto, tell);
                        bootit(names[i][1], howto, tell);
@@ -504,6 +517,21 @@
        printf("invalid console device.\n");
 }
 
+#ifndef SMALL
+/* ARGSUSED */
+void
+command_menu(char *arg)
+{
+
+       if (bootconf.nummenu > 0) {
+               /* Does not return */
+               doboottypemenu();
+       } else {
+               printf("No menu defined in boot.cfg\n");
+       }
+}
+#endif /* !SMALL */
+
 void
 command_modules(char *arg)
 {
diff -r e91be02d7e1b -r 544f9bc128fd sys/arch/i386/stand/lib/bootmenu.c
--- a/sys/arch/i386/stand/lib/bootmenu.c        Sun Jul 28 06:12:45 2013 +0000
+++ b/sys/arch/i386/stand/lib/bootmenu.c        Sun Jul 28 08:50:09 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bootmenu.c,v 1.10 2011/08/18 13:20:04 christos Exp $   */
+/*     $NetBSD: bootmenu.c,v 1.11 2013/07/28 08:50:09 he Exp $ */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -41,6 +41,8 @@
 
 #define isnum(c) ((c) >= '0' && (c) <= '9')
 
+static void docommandchoice(int);
+
 extern struct x86_boot_params boot_params;
 extern const char bootprog_name[], bootprog_rev[], bootprog_kernrev[];
 
@@ -297,11 +299,57 @@
        return choice;
 }
 
+static void
+docommandchoice(int choice)
+{
+       char input[80], *ic, *oc;
+
+       ic = bootconf.command[choice];
+       /* Split command string at ; into separate commands */
+       do {
+               oc = input;
+               /* Look for ; separator */
+               for (; *ic && *ic != COMMAND_SEPARATOR; ic++)
+                       *oc++ = *ic;
+               if (*input == '\0')
+                       continue;
+               /* Strip out any trailing spaces */
+               oc--;
+               for (; *oc == ' ' && oc > input; oc--);
+               *++oc = '\0';
+               if (*ic == COMMAND_SEPARATOR)
+                       ic++;
+               /* Stop silly command strings like ;;; */
+               if (*input != '\0')
+                       docommand(input);
+               /* Skip leading spaces */
+               for (; *ic == ' '; ic++);
+       } while (*ic);
+}
+
+void
+bootdefault(void)
+{
+       int choice;
+       static int entered;
+
+       if (bootconf.nummenu > 0) {
+               if (entered) {
+                       printf("default boot twice, skipping...\n");
+                       return;
+               }
+               entered = 1;
+               choice = bootconf.def;
+               printf("command(s): %s\n", bootconf.command[choice]);
+               docommandchoice(choice);
+       }
+}
+
 void
 doboottypemenu(void)
 {
        int choice;
-       char input[80], *ic, *oc;
+       char input[80];
 
        printf("\n");
        /* Display menu */
@@ -357,27 +405,7 @@
                        printf("type \"?\" or \"help\" for help.\n");
                        bootmenu(); /* does not return */
                } else {
-                       ic = bootconf.command[choice];
-                       /* Split command string at ; into separate commands */
-                       do {
-                               oc = input;
-                               /* Look for ; separator */
-                               for (; *ic && *ic != COMMAND_SEPARATOR; ic++)
-                                       *oc++ = *ic;
-                               if (*input == '\0')
-                                       continue;
-                               /* Strip out any trailing spaces */
-                               oc--;
-                               for (; *oc == ' ' && oc > input; oc--);
-                               *++oc = '\0';
-                               if (*ic == COMMAND_SEPARATOR)
-                                       ic++;
-                               /* Stop silly command strings like ;;; */
-                               if (*input != '\0')
-                                       docommand(input);
-                               /* Skip leading spaces */
-                               for (; *ic == ' '; ic++);
-                       } while (*ic);
+                       docommandchoice(choice);
                }
 
        }
diff -r e91be02d7e1b -r 544f9bc128fd sys/arch/i386/stand/lib/bootmenu.h
--- a/sys/arch/i386/stand/lib/bootmenu.h        Sun Jul 28 06:12:45 2013 +0000
+++ b/sys/arch/i386/stand/lib/bootmenu.h        Sun Jul 28 08:50:09 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bootmenu.h,v 1.2 2008/12/13 23:30:54 christos Exp $    */
+/*     $NetBSD: bootmenu.h,v 1.3 2013/07/28 08:50:09 he Exp $  */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -36,6 +36,7 @@
 
 void parsebootconf(const char *);
 void doboottypemenu(void);
+void bootdefault(void);
 int atoi(const char *);
 
 struct bootconf_def {



Home | Main Index | Thread Index | Old Index