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).
This commit is contained in:
he 2013-07-28 08:50:09 +00:00
parent 148f6d8534
commit 6a91dd3147
3 changed files with 82 additions and 25 deletions

View File

@ -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_quit(char *);
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 @@ const struct bootblk_command commands[] = {
{ "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 @@ command_help(char *arg)
"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 @@ command_boot(char *arg)
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 @@ command_consdev(char *arg)
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)
{

View File

@ -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 @@ getchoicefrominput(char *input, int def)
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 @@ doboottypemenu(void)
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);
}
}

View File

@ -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 {