From 867c0643d415b25960cffc049e532446a8a8d008 Mon Sep 17 00:00:00 2001 From: kevans Date: Wed, 20 Feb 2019 19:19:24 +0000 Subject: [PATCH] MFC r336244, r336246-r336247: Standardize boot arg parsing r336244: Create helper functions for parsing boot args. boot_parse_arg to parse a single arg boot_parse_cmdline to parse a command line string boot_parse_args to parse all the args in a vector boot_howto_to_env Convert howto bits to env vars boot_env_to_howto Return howto mask mased on what's set in the environment. All these routines return an int that's the bitmask of the args translated to RB_* flags. As a special case, the 'S' flag sets the comconsole_speed env var. Any arg that looks like a=b will set the env key 'a' to value 'b'. If =b is omitted, 'a' is set to '1'. This should help us reduce the number of redundant copies of these routines in the tree. It should also give a more uniform experience between platforms. Also, invent a new flag RB_PROBE that's set when 'P' is parsed. On x86 + BIOS, this means 'probe for the keyboard, and if it's not there set both RB_MULTIPLE and RB_SERIAL (which means show the output on both video and serial consoles, but make serial primary). Others it may be some similar concept of probing, but it's loader dependent what, exactly, it means. These routines are suitable for /boot/loader and/or the kernel, though they may not be suitable for the tightly hand-rolled-for-space environments like boot2. r336246: Eliminate boot loader copies of boot arg parsing. Eliminate 4 of the copies of the arg parsing in /boot/laoder by using boot_parse_cmdline. r336247: Transition to boot_env_to_howto and boot_howto_to_env in the boot loader. --- stand/common/boot.c | 24 ---- stand/common/bootstrap.h | 2 - stand/common/metadata.c | 56 +------- stand/efi/loader/bootinfo.c | 25 +--- stand/efi/loader/main.c | 81 +---------- stand/i386/libi386/bootinfo.c | 58 +------- stand/libsa/Makefile | 4 + stand/userboot/userboot/bootinfo.c | 62 +------- sys/arm/arm/machdep_boot.c | 36 ++--- sys/conf/files | 1 + sys/kern/subr_boot.c | 223 +++++++++++++++++++++++++++++ sys/sys/boot.h | 29 +--- sys/sys/reboot.h | 1 + sys/x86/xen/pv.c | 17 +-- 14 files changed, 274 insertions(+), 345 deletions(-) create mode 100644 sys/kern/subr_boot.c diff --git a/stand/common/boot.c b/stand/common/boot.c index 2781778b462..f965dedb3bc 100644 --- a/stand/common/boot.c +++ b/stand/common/boot.c @@ -160,30 +160,6 @@ autoboot_maybe() autoboot(-1, NULL); /* try to boot automatically */ } -int -bootenv_flags() -{ - int i, howto; - char *val; - - for (howto = 0, i = 0; howto_names[i].ev != NULL; i++) { - val = getenv(howto_names[i].ev); - if (val != NULL && strcasecmp(val, "no") != 0) - howto |= howto_names[i].mask; - } - return (howto); -} - -void -bootenv_set(int howto) -{ - int i; - - for (i = 0; howto_names[i].ev != NULL; i++) - if (howto & howto_names[i].mask) - setenv(howto_names[i].ev, "YES", 1); -} - static int autoboot(int timeout, char *prompt) { diff --git a/stand/common/bootstrap.h b/stand/common/bootstrap.h index 5a7a84f6398..41037b999c5 100644 --- a/stand/common/bootstrap.h +++ b/stand/common/bootstrap.h @@ -63,8 +63,6 @@ int parse(int *argc, char ***argv, const char *str); /* boot.c */ void autoboot_maybe(void); int getrootmount(char *rootdev); -int bootenv_flags(void); -void bootenv_set(int); /* misc.c */ char *unargv(int argc, char *argv[]); diff --git a/stand/common/metadata.c b/stand/common/metadata.c index 94b7518bd7c..96fad5b662a 100644 --- a/stand/common/metadata.c +++ b/stand/common/metadata.c @@ -32,6 +32,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #if defined(LOADER_FDT_SUPPORT) #include @@ -96,62 +97,11 @@ md_bootserial(void) static int md_getboothowto(char *kargs) { - char *cp; int howto; - int active; /* Parse kargs */ - howto = 0; - if (kargs != NULL) { - cp = kargs; - active = 0; - while (*cp != 0) { - if (!active && (*cp == '-')) { - active = 1; - } else if (active) - switch (*cp) { - case 'a': - howto |= RB_ASKNAME; - break; - case 'C': - howto |= RB_CDROM; - break; - case 'd': - howto |= RB_KDB; - break; - case 'D': - howto |= RB_MULTIPLE; - break; - case 'm': - howto |= RB_MUTE; - break; - case 'g': - howto |= RB_GDB; - break; - case 'h': - howto |= RB_SERIAL; - break; - case 'p': - howto |= RB_PAUSE; - break; - case 'r': - howto |= RB_DFLTROOT; - break; - case 's': - howto |= RB_SINGLE; - break; - case 'v': - howto |= RB_VERBOSE; - break; - default: - active = 0; - break; - } - cp++; - } - } - - howto |= bootenv_flags(); + howto = boot_parse_cmdline(kargs); + howto |= boot_env_to_howto(); #if defined(__sparc64__) if (md_bootserial() != -1) howto |= RB_SERIAL; diff --git a/stand/efi/loader/bootinfo.c b/stand/efi/loader/bootinfo.c index 19821e8c1df..15a6a60293b 100644 --- a/stand/efi/loader/bootinfo.c +++ b/stand/efi/loader/bootinfo.c @@ -34,6 +34,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -59,12 +60,6 @@ int bi_load(char *args, vm_offset_t *modulep, vm_offset_t *kernendp); extern EFI_SYSTEM_TABLE *ST; -static const char howto_switches[] = "aCdrgDmphsv"; -static int howto_masks[] = { - RB_ASKNAME, RB_CDROM, RB_KDB, RB_DFLTROOT, RB_GDB, RB_MULTIPLE, - RB_MUTE, RB_PAUSE, RB_SERIAL, RB_SINGLE, RB_VERBOSE -}; - static int bi_getboothowto(char *kargs) { @@ -73,7 +68,8 @@ bi_getboothowto(char *kargs) char *console; int howto; - howto = bootenv_flags(); + howto = boot_parse_cmdline(kargs); + howto |= boot_env_to_howto(); console = getenv("console"); if (console != NULL) { @@ -83,21 +79,6 @@ bi_getboothowto(char *kargs) howto |= RB_MUTE; } - /* Parse kargs */ - if (kargs == NULL) - return (howto); - - opts = strchr(kargs, '-'); - while (opts != NULL) { - while (*(++opts) != '\0') { - sw = strchr(howto_switches, *opts); - if (sw == NULL) - break; - howto |= howto_masks[sw - howto_switches]; - } - opts = strchr(opts, '-'); - } - return (howto); } diff --git a/stand/efi/loader/main.c b/stand/efi/loader/main.c index a8d07dbec4d..5de99d7948c 100644 --- a/stand/efi/loader/main.c +++ b/stand/efi/loader/main.c @@ -28,11 +28,13 @@ #include __FBSDID("$FreeBSD$"); +#include + #include #include #include +#include #include -#include #include #include #include @@ -420,79 +422,10 @@ parse_args(int argc, CHAR16 *argv[], bool has_kbd) */ howto = 0; for (i = 1; i < argc; i++) { - if (argv[i][0] == '-') { - for (j = 1; argv[i][j] != 0; j++) { - int ch; - - ch = argv[i][j]; - switch (ch) { - case 'a': - howto |= RB_ASKNAME; - break; - case 'd': - howto |= RB_KDB; - break; - case 'D': - howto |= RB_MULTIPLE; - break; - case 'h': - howto |= RB_SERIAL; - break; - case 'm': - howto |= RB_MUTE; - break; - case 'p': - howto |= RB_PAUSE; - break; - case 'P': - if (!has_kbd) - howto |= RB_SERIAL | RB_MULTIPLE; - break; - case 'r': - howto |= RB_DFLTROOT; - break; - case 's': - howto |= RB_SINGLE; - break; - case 'S': - if (argv[i][j + 1] == 0) { - if (i + 1 == argc) { - setenv("comconsole_speed", "115200", 1); - } else { - cpy16to8(&argv[i + 1][0], var, - sizeof(var)); - setenv("comconsole_speed", var, 1); - } - i++; - break; - } else { - cpy16to8(&argv[i][j + 1], var, - sizeof(var)); - setenv("comconsole_speed", var, 1); - break; - } - case 'v': - howto |= RB_VERBOSE; - break; - } - } - } else { - vargood = false; - for (j = 0; argv[i][j] != 0; j++) { - if (j == sizeof(var)) { - vargood = false; - break; - } - if (j > 0 && argv[i][j] == '=') - vargood = true; - var[j] = (char)argv[i][j]; - } - if (vargood) { - var[j] = 0; - putenv(var); - } - } + cpy16to8(argv[i], var, sizeof(var)); + howto |= boot_parse_arg(var); } + return (howto); } @@ -550,7 +483,7 @@ main(int argc, CHAR16 *argv[]) howto = parse_args(argc, argv, has_kbd); - bootenv_set(howto); + boot_howto_to_env(howto); /* * XXX we need fallback to this stuff after looking at the ConIn, ConOut and ConErr variables diff --git a/stand/i386/libi386/bootinfo.c b/stand/i386/libi386/bootinfo.c index 0b69a9a21ec..41901e5f928 100644 --- a/stand/i386/libi386/bootinfo.c +++ b/stand/i386/libi386/bootinfo.c @@ -30,6 +30,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include "bootstrap.h" #include "libi386.h" @@ -38,63 +39,12 @@ __FBSDID("$FreeBSD$"); int bi_getboothowto(char *kargs) { - char *cp; char *curpos, *next, *string; int howto; - int active; int vidconsole; - /* Parse kargs */ - howto = 0; - if (kargs != NULL) { - cp = kargs; - active = 0; - while (*cp != 0) { - if (!active && (*cp == '-')) { - active = 1; - } else if (active) - switch (*cp) { - case 'a': - howto |= RB_ASKNAME; - break; - case 'C': - howto |= RB_CDROM; - break; - case 'd': - howto |= RB_KDB; - break; - case 'D': - howto |= RB_MULTIPLE; - break; - case 'm': - howto |= RB_MUTE; - break; - case 'g': - howto |= RB_GDB; - break; - case 'h': - howto |= RB_SERIAL; - break; - case 'p': - howto |= RB_PAUSE; - break; - case 'r': - howto |= RB_DFLTROOT; - break; - case 's': - howto |= RB_SINGLE; - break; - case 'v': - howto |= RB_VERBOSE; - break; - default: - active = 0; - break; - } - cp++; - } - } - howto |= bootenv_flags(); + howto = boot_parse_cmdline(kargs); + howto |= boot_env_to_howto(); /* Enable selected consoles */ string = next = strdup(getenv("console")); @@ -130,7 +80,7 @@ void bi_setboothowto(int howto) { - bootenv_set(howto); + boot_howto_to_env(howto); } /* diff --git a/stand/libsa/Makefile b/stand/libsa/Makefile index 4b6ac44e6ae..5734fd4884d 100644 --- a/stand/libsa/Makefile +++ b/stand/libsa/Makefile @@ -37,6 +37,10 @@ SRCS+= bcmp.c bcopy.c bzero.c ffs.c fls.c \ .PATH: ${LIBC_SRC}/stdlib SRCS+= abs.c strtol.c strtoll.c strtoul.c strtoull.c +# common boot code +.PATH: ${SYSDIR}/kern +SRCS+= subr_boot.c + .if ${MACHINE_CPUARCH} == "arm" .PATH: ${LIBC_SRC}/arm/gen diff --git a/stand/userboot/userboot/bootinfo.c b/stand/userboot/userboot/bootinfo.c index 29a94af1752..43088e2a7c0 100644 --- a/stand/userboot/userboot/bootinfo.c +++ b/stand/userboot/userboot/bootinfo.c @@ -30,6 +30,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include "bootstrap.h" @@ -38,64 +39,12 @@ __FBSDID("$FreeBSD$"); int bi_getboothowto(char *kargs) { - char *cp; char *curpos, *next, *string; int howto; - int active; int vidconsole; - /* Parse kargs */ - howto = 0; - if (kargs != NULL) { - cp = kargs; - active = 0; - while (*cp != 0) { - if (!active && (*cp == '-')) { - active = 1; - } else if (active) - switch (*cp) { - case 'a': - howto |= RB_ASKNAME; - break; - case 'C': - howto |= RB_CDROM; - break; - case 'd': - howto |= RB_KDB; - break; - case 'D': - howto |= RB_MULTIPLE; - break; - case 'm': - howto |= RB_MUTE; - break; - case 'g': - howto |= RB_GDB; - break; - case 'h': - howto |= RB_SERIAL; - break; - case 'p': - howto |= RB_PAUSE; - break; - case 'r': - howto |= RB_DFLTROOT; - break; - case 's': - howto |= RB_SINGLE; - break; - case 'v': - howto |= RB_VERBOSE; - break; - default: - active = 0; - break; - } - cp++; - } - } - - howto |= bootenv_flags(); + howto = boot_parse_cmdline(kargs); + howto |= boot_env_to_howto(); /* Enable selected consoles */ string = next = strdup(getenv("console")); @@ -117,7 +66,8 @@ bi_getboothowto(char *kargs) /* * XXX: Note that until the kernel is ready to respect multiple consoles - * for the boot messages, the first named console is the primary console + * for the messages from /etc/rc, the first named console is the primary + * console */ if (!strcmp(string, "vidconsole")) howto &= ~RB_SERIAL; @@ -131,7 +81,7 @@ void bi_setboothowto(int howto) { - bootenv_set(howto); + boot_howto_to_env(howto); } /* diff --git a/sys/arm/arm/machdep_boot.c b/sys/arm/arm/machdep_boot.c index eb53967527e..b478268a0c0 100644 --- a/sys/arm/arm/machdep_boot.c +++ b/sys/arm/arm/machdep_boot.c @@ -68,6 +68,8 @@ __FBSDID("$FreeBSD$"); #define debugf(fmt, args...) #endif +static char static_kenv[4096]; + extern int *end; static uint32_t board_revision; @@ -146,9 +148,8 @@ arm_print_kenv(void) static void cmdline_set_env(char *cmdline, const char *guard) { - char *cmdline_next, *env; + char *cmdline_next; size_t size, guard_len; - int i; size = strlen(cmdline); /* Skip leading spaces. */ @@ -164,37 +165,27 @@ cmdline_set_env(char *cmdline, const char *guard) size -= guard_len; } - /* Skip leading spaces. */ - for (; isspace(*cmdline) && (size > 0); cmdline++) - size--; - - /* Replace ',' with '\0'. */ - /* TODO: implement escaping for ',' character. */ - cmdline_next = cmdline; - while(strsep(&cmdline_next, ",") != NULL) - ; - init_static_kenv(cmdline, 0); - /* Parse boothowto. */ - for (i = 0; howto_names[i].ev != NULL; i++) { - env = kern_getenv(howto_names[i].ev); - if (env != NULL) { - if (strtoul(env, NULL, 10) != 0) - boothowto |= howto_names[i].mask; - freeenv(env); - } - } + boothowto |= boot_parse_cmdline(); } +/* + * Called for armv6 and newer. + */ void arm_parse_fdt_bootargs(void) { #ifdef FDT if (loader_envp == NULL && fdt_get_chosen_bootargs(linux_command_line, - LBABI_MAX_COMMAND_LINE) == 0) + LBABI_MAX_COMMAND_LINE) == 0) { + init_static_kenv(static_kenv, sizeof(static_kenv)); cmdline_set_env(linux_command_line, CMDLINE_GUARD); + } #endif } +/* + * Called for armv[45]. + */ static vm_offset_t linux_parse_boot_param(struct arm_boot_params *abp) { @@ -271,6 +262,7 @@ linux_parse_boot_param(struct arm_boot_params *abp) (char *)walker - (char *)atag_list + ATAG_SIZE(walker)); lastaddr = fake_preload_metadata(abp, NULL, 0); + init_static_kenv(static_kenv, sizeof(static_kenv)); cmdline_set_env(linux_command_line, CMDLINE_GUARD); return lastaddr; } diff --git a/sys/conf/files b/sys/conf/files index 40245446735..5075bfcf37a 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -3675,6 +3675,7 @@ kern/subr_acl_nfs4.c optional ufs_acl | zfs kern/subr_acl_posix1e.c optional ufs_acl kern/subr_autoconf.c standard kern/subr_blist.c standard +kern/subr_boot.c standard kern/subr_bus.c standard kern/subr_bus_dma.c standard kern/subr_bufring.c standard diff --git a/sys/kern/subr_boot.c b/sys/kern/subr_boot.c new file mode 100644 index 00000000000..00890c3150d --- /dev/null +++ b/sys/kern/subr_boot.c @@ -0,0 +1,223 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 1998 Michael Smith + * All Rights Reserved. + * Copyright (c) 1998 Robert Nordier + * All Rights Reserved. + * Copyright (c) 2009, Oleksandr Tymoshenko + * All rights reserved. + * Copyright (c) 2014 Roger Pau Monné + * All Rights Reserved. + * Copyright (c) 2018 Kyle Evans + * Copyright (c) 2018 Netflix + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +/* Note: This is compiled in both the kernel and boot loader contexts */ + +#include +#ifdef _KERNEL +#include +#else +#include +#endif +#include +#include + +#ifdef _KERNEL +#define SETENV(k, v) kern_setenv(k, v) +#define GETENV(k) kern_getenv(k) +#define FREE(v) freeenv(v) +#else /* Boot loader */ +#define SETENV(k, v) setenv(k, v, 1) +#define GETENV(k) getenv(k) +#define FREE(v) +#endif + +static struct +{ + const char *ev; + int mask; +} howto_names[] = { + { "boot_askname", RB_ASKNAME}, + { "boot_cdrom", RB_CDROM}, + { "boot_ddb", RB_KDB}, + { "boot_dfltroot", RB_DFLTROOT}, + { "boot_gdb", RB_GDB}, + { "boot_multicons", RB_MULTIPLE}, + { "boot_mute", RB_MUTE}, + { "boot_pause", RB_PAUSE}, + { "boot_serial", RB_SERIAL}, + { "boot_single", RB_SINGLE}, + { "boot_verbose", RB_VERBOSE}, + { NULL, 0} +}; + +/* + * In the boot environment, we often parse a command line and have to throw away + * its contents. As we do so, we set environment variables that correspond to + * the flags we encounter. Later, to get a howto mask, we grovel through these + * to reconstruct it. This also allows users in their loader.conf to set them + * and have the kernel see them. + */ + +/** + * @brief convert the env vars in howto_names into a howto mask + */ +int +boot_env_to_howto(void) +{ + int i, howto; + char *val; + + for (howto = 0, i = 0; howto_names[i].ev != NULL; i++) { + val = GETENV(howto_names[i].ev); + if (val != NULL && strcasecmp(val, "no") != 0) + howto |= howto_names[i].mask; + FREE(val); + } + return (howto); +} + +/** + * @brief Set env vars from howto_names based on howto passed in + */ +void +boot_howto_to_env(int howto) +{ + int i; + + for (i = 0; howto_names[i].ev != NULL; i++) + if (howto & howto_names[i].mask) + SETENV(howto_names[i].ev, "YES"); +} + +/** + * @brief Helper routine to parse a single arg and return its mask + * + * Parse all the - options to create a mask (or a serial speed in the + * case of -S). If the arg doesn't start with '-' assume it's an env + * variable and set that instead. + */ +int +boot_parse_arg(char *v) +{ + char *n; + int howto; + +#if 0 +/* Need to see if this is better or worse than the meat of the #else */ +static const char howto_switches[] = "aCdrgDmphsv"; +static int howto_masks[] = { + RB_ASKNAME, RB_CDROM, RB_KDB, RB_DFLTROOT, RB_GDB, RB_MULTIPLE, + RB_MUTE, RB_PAUSE, RB_SERIAL, RB_SINGLE, RB_VERBOSE +}; + + opts = strchr(kargs, '-'); + while (opts != NULL) { + while (*(++opts) != '\0') { + sw = strchr(howto_switches, *opts); + if (sw == NULL) + break; + howto |= howto_masks[sw - howto_switches]; + } + opts = strchr(opts, '-'); + } +#else + howto = 0; + if (*v == '-') { + while (*v != '\0') { + v++; + switch (*v) { + case 'a': howto |= RB_ASKNAME; break; + case 'C': howto |= RB_CDROM; break; + case 'd': howto |= RB_KDB; break; + case 'D': howto |= RB_MULTIPLE; break; + case 'm': howto |= RB_MUTE; break; + case 'g': howto |= RB_GDB; break; + case 'h': howto |= RB_SERIAL; break; + case 'p': howto |= RB_PAUSE; break; + case 'P': howto |= RB_PROBE; break; + case 'r': howto |= RB_DFLTROOT; break; + case 's': howto |= RB_SINGLE; break; + case 'S': SETENV("comconsole_speed", v + 1); v += strlen(v); break; + case 'v': howto |= RB_VERBOSE; break; + } + } + } else { + n = strsep(&v, "="); + if (v == NULL) + SETENV(n, "1"); + else + SETENV(n, v); + } +#endif + return (howto); +} + +/** + * @brief breakup the command line into args, and pass to boot_parse_arg + */ +int +boot_parse_cmdline_delim(char *cmdline, const char *delim) +{ + char *v; + int howto; + + howto = 0; + while ((v = strsep(&cmdline, delim)) != NULL) { + if (*v == '\0') + continue; + howto |= boot_parse_arg(v); + } + return (howto); +} + +/** + * @brief Simplified interface for common 'space separated' args + */ +int +boot_parse_cmdline(char *cmdline) +{ + + return (boot_parse_cmdline_delim(cmdline, " \n")); +} + +/** + * @brief Pass a vector of strings to boot_parse_arg + */ +int +boot_parse_args(int argc, char *argv[]) +{ + int i, howto; + + howto = 0; + for (i = 1; i < argc; i++) + howto |= boot_parse_arg(argv[i]); + return (howto); +} diff --git a/sys/sys/boot.h b/sys/sys/boot.h index 4a2fa930935..4fc9579fb4d 100644 --- a/sys/sys/boot.h +++ b/sys/sys/boot.h @@ -1,4 +1,5 @@ /*- + * Copyright (c) 2018 Netflix * Copyright (c) 2014 Roger Pau Monné * All rights reserved. * @@ -29,27 +30,11 @@ #ifndef _SYS_BOOT_H_ #define _SYS_BOOT_H_ -/* - * Return a 'boothowto' value corresponding to the kernel arguments in - * (kargs) and any relevant environment variables. - */ -static struct -{ - const char *ev; - int mask; -} howto_names[] = { - { "boot_askname", RB_ASKNAME}, - { "boot_cdrom", RB_CDROM}, - { "boot_ddb", RB_KDB}, - { "boot_dfltroot", RB_DFLTROOT}, - { "boot_gdb", RB_GDB}, - { "boot_multicons", RB_MULTIPLE}, - { "boot_mute", RB_MUTE}, - { "boot_pause", RB_PAUSE}, - { "boot_serial", RB_SERIAL}, - { "boot_single", RB_SINGLE}, - { "boot_verbose", RB_VERBOSE}, - { NULL, 0} -}; +int boot_env_to_howto(void); +void boot_howto_to_env(int howto); +int boot_parse_arg(char *v); +int boot_parse_cmdline_delim(char *cmdline, const char *delim); +int boot_parse_cmdline(char *cmdline); +int boot_parse_args(int argc, char *argv[]); #endif /* !_SYS_BOOT_H_ */ diff --git a/sys/sys/reboot.h b/sys/sys/reboot.h index ebe688e869f..596450b1085 100644 --- a/sys/sys/reboot.h +++ b/sys/sys/reboot.h @@ -60,6 +60,7 @@ #define RB_RESERVED2 0x80000 /* reserved for internal use of boot blocks */ #define RB_PAUSE 0x100000 /* pause after each output line during probe */ #define RB_REROOT 0x200000 /* unmount the rootfs and mount it again */ +#define RB_PROBE 0x10000000 /* Probe multiple consoles */ #define RB_MULTIPLE 0x20000000 /* use multiple consoles */ #define RB_BOOTINFO 0x80000000 /* have `struct bootinfo *' arg */ diff --git a/sys/x86/xen/pv.c b/sys/x86/xen/pv.c index f4b68f08d67..dfd5af83c34 100644 --- a/sys/x86/xen/pv.c +++ b/sys/x86/xen/pv.c @@ -300,21 +300,6 @@ xen_pv_set_env(void) init_static_kenv(cmd_line, 0); } -static void -xen_pv_set_boothowto(void) -{ - int i; - char *env; - - /* get equivalents from the environment */ - for (i = 0; howto_names[i].ev != NULL; i++) { - if ((env = kern_getenv(howto_names[i].ev)) != NULL) { - boothowto |= howto_names[i].mask; - freeenv(env); - } - } -} - #ifdef DDB /* * The way Xen loads the symtab is different from the native boot loader, @@ -413,7 +398,7 @@ xen_pv_parse_preload_data(u_int64_t modulep) } else { /* Parse the extra boot information given by Xen */ xen_pv_set_env(); - xen_pv_set_boothowto(); + boothowto |= boot_env_to_howto(); kmdp = NULL; } -- 2.45.0