Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/sys/arch/i386/stand/boot/boot2.c,v rcsdiff: /ftp/cvs/cvsroot/src/sys/arch/i386/stand/boot/boot2.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.38 retrieving revision 1.38.4.3 diff -u -p -r1.38 -r1.38.4.3 --- src/sys/arch/i386/stand/boot/boot2.c 2008/10/11 11:06:19 1.38 +++ src/sys/arch/i386/stand/boot/boot2.c 2013/09/07 17:23:39 1.38.4.3 @@ -1,4 +1,4 @@ -/* $NetBSD: boot2.c,v 1.38 2008/10/11 11:06:19 joerg Exp $ */ +/* $NetBSD: boot2.c,v 1.38.4.3 2013/09/07 17:23:39 bouyer Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -131,9 +131,16 @@ 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_load(char *); void command_multiboot(char *); +#ifndef SMALL +void bootdefault(void); +void docommandchoice(int); +#endif const struct bootblk_command commands[] = { { "help", command_help }, @@ -143,6 +150,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", command_load }, { "multiboot", command_multiboot }, @@ -482,11 +492,15 @@ parsebootconf(const char *conf) static int getchoicefrominput(char *input, int def) { - int choice; + int choice, usedef; + choice = -1; - if (*input == '\0' || *input == '\r' || *input == '\n') + usedef = 0; + + if (*input == '\0' || *input == '\r' || *input == '\n') { choice = def; - else if (*input >= 'A' && *input < bootconf.nummenu + 'A') + usedef = 1; + } else if (*input >= 'A' && *input < bootconf.nummenu + 'A') choice = (*input) - 'A'; else if (*input >= 'a' && *input < bootconf.nummenu + 'a') choice = (*input) - 'a'; @@ -495,14 +509,67 @@ static int getchoicefrominput(char *inpu if (choice < 0 || choice >= bootconf.nummenu) choice = -1; } + + if (bootconf.menuformat != MENUFORMAT_LETTER && + !isnum(*input) && !usedef) + choice = -1; + return choice; } 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 */ @@ -558,27 +625,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); } } @@ -655,11 +702,23 @@ boot2(int biosdev, u_int biossector) #else c = awaitkey((bootconf.timeout < 0) ? 0 : bootconf.timeout, 1); #endif - if ((c != '\r') && (c != '\n') && (c != '\0') && - ((boot_params.bp_flags & X86_BP_FLAGS_PASSWORD) == 0 - || check_password(boot_params.bp_password))) { - printf("type \"?\" or \"help\" for help.\n"); + if ((c != '\r') && (c != '\n') && (c != '\0')) { + if ((boot_params.bp_flags & X86_BP_FLAGS_PASSWORD) == 0) { + /* do NOT ask for password */ bootmenu(); /* does not return */ + } else { + /* DO ask for password */ + if (check_password(boot_params.bp_password)) { + /* password ok */ + printf("type \"?\" or \"help\" for help.\n"); + bootmenu(); /* does not return */ + } else { + /* bad password */ + printf("Wrong password.\n"); + currname = 0; + continue; + } + } } /* @@ -686,6 +745,9 @@ command_help(char *arg) "dev xd[N[x]]:\n" "consdev {pc|com[0123]|com[0123]kbd|auto}\n" "modules {enabled|disabled}\n" +#ifndef SMALL + "menu (reenters boot menu, if defined in boot.cfg)\n" +#endif "load {path_to_module}\n" "multiboot [xdNx:][filename] []\n" "help|?\n" @@ -719,10 +781,25 @@ void command_boot(char *arg) { char *filename; - int howto; + int howto, tell; - if (parseboot(arg, &filename, &howto)) - bootit(filename, howto, 1); + if (!parseboot(arg, &filename, &howto)) + return; + + tell = ((howto & AB_VERBOSE) != 0); + if (filename != NULL) { + 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); + } + } } void @@ -782,6 +859,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) {