Date: Wed, 20 Feb 2019 19:19:24 +0000 (UTC) From: Kyle Evans <kevans@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r344378 - in stable/11: stand/common stand/efi/loader stand/i386/libi386 stand/libsa stand/userboot/userboot sys/arm/arm sys/conf sys/kern sys/sys sys/x86/xen Message-ID: <201902201919.x1KJJOij023189@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kevans Date: Wed Feb 20 19:19:24 2019 New Revision: 344378 URL: https://svnweb.freebsd.org/changeset/base/344378 Log: 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. Added: stable/11/sys/kern/subr_boot.c - copied unchanged from r336244, head/sys/kern/subr_boot.c Modified: stable/11/stand/common/boot.c stable/11/stand/common/bootstrap.h stable/11/stand/common/metadata.c stable/11/stand/efi/loader/bootinfo.c stable/11/stand/efi/loader/main.c stable/11/stand/i386/libi386/bootinfo.c stable/11/stand/libsa/Makefile stable/11/stand/userboot/userboot/bootinfo.c stable/11/sys/arm/arm/machdep_boot.c stable/11/sys/conf/files stable/11/sys/sys/boot.h stable/11/sys/sys/reboot.h stable/11/sys/x86/xen/pv.c Directory Properties: stable/11/ (props changed) Modified: stable/11/stand/common/boot.c ============================================================================== --- stable/11/stand/common/boot.c Wed Feb 20 19:13:09 2019 (r344377) +++ stable/11/stand/common/boot.c Wed Feb 20 19:19:24 2019 (r344378) @@ -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) { Modified: stable/11/stand/common/bootstrap.h ============================================================================== --- stable/11/stand/common/bootstrap.h Wed Feb 20 19:13:09 2019 (r344377) +++ stable/11/stand/common/bootstrap.h Wed Feb 20 19:19:24 2019 (r344378) @@ -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[]); Modified: stable/11/stand/common/metadata.c ============================================================================== --- stable/11/stand/common/metadata.c Wed Feb 20 19:13:09 2019 (r344377) +++ stable/11/stand/common/metadata.c Wed Feb 20 19:19:24 2019 (r344378) @@ -32,6 +32,7 @@ __FBSDID("$FreeBSD$"); #include <stand.h> #include <sys/param.h> #include <sys/linker.h> +#include <sys/boot.h> #include <sys/reboot.h> #if defined(LOADER_FDT_SUPPORT) #include <fdt_platform.h> @@ -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; Modified: stable/11/stand/efi/loader/bootinfo.c ============================================================================== --- stable/11/stand/efi/loader/bootinfo.c Wed Feb 20 19:13:09 2019 (r344377) +++ stable/11/stand/efi/loader/bootinfo.c Wed Feb 20 19:19:24 2019 (r344378) @@ -34,6 +34,7 @@ __FBSDID("$FreeBSD$"); #include <sys/param.h> #include <sys/linker.h> #include <sys/reboot.h> +#include <sys/boot.h> #include <machine/cpufunc.h> #include <machine/elf.h> #include <machine/metadata.h> @@ -59,12 +60,6 @@ int bi_load(char *args, vm_offset_t *modulep, vm_offse 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) { @@ -81,21 +77,6 @@ bi_getboothowto(char *kargs) howto |= RB_SERIAL; if (strcmp(console, "nullconsole") == 0) 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); Modified: stable/11/stand/efi/loader/main.c ============================================================================== --- stable/11/stand/efi/loader/main.c Wed Feb 20 19:13:09 2019 (r344377) +++ stable/11/stand/efi/loader/main.c Wed Feb 20 19:19:24 2019 (r344378) @@ -28,11 +28,13 @@ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); +#include <stand.h> + #include <sys/disk.h> #include <sys/param.h> #include <sys/reboot.h> +#include <sys/boot.h> #include <stdint.h> -#include <stand.h> #include <string.h> #include <setjmp.h> #include <disk.h> @@ -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 Modified: stable/11/stand/i386/libi386/bootinfo.c ============================================================================== --- stable/11/stand/i386/libi386/bootinfo.c Wed Feb 20 19:13:09 2019 (r344377) +++ stable/11/stand/i386/libi386/bootinfo.c Wed Feb 20 19:19:24 2019 (r344378) @@ -30,6 +30,7 @@ __FBSDID("$FreeBSD$"); #include <stand.h> #include <sys/param.h> #include <sys/reboot.h> +#include <sys/boot.h> #include <sys/linker.h> #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); } /* Modified: stable/11/stand/libsa/Makefile ============================================================================== --- stable/11/stand/libsa/Makefile Wed Feb 20 19:13:09 2019 (r344377) +++ stable/11/stand/libsa/Makefile Wed Feb 20 19:19:24 2019 (r344378) @@ -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 Modified: stable/11/stand/userboot/userboot/bootinfo.c ============================================================================== --- stable/11/stand/userboot/userboot/bootinfo.c Wed Feb 20 19:13:09 2019 (r344377) +++ stable/11/stand/userboot/userboot/bootinfo.c Wed Feb 20 19:19:24 2019 (r344378) @@ -30,6 +30,7 @@ __FBSDID("$FreeBSD$"); #include <stand.h> #include <sys/param.h> #include <sys/reboot.h> +#include <sys/boot.h> #include <sys/linker.h> #include "bootstrap.h" @@ -38,65 +39,13 @@ __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 = boot_parse_cmdline(kargs); + howto |= boot_env_to_howto(); - howto |= bootenv_flags(); - /* Enable selected consoles */ string = next = strdup(getenv("console")); vidconsole = 0; @@ -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); } /* Modified: stable/11/sys/arm/arm/machdep_boot.c ============================================================================== --- stable/11/sys/arm/arm/machdep_boot.c Wed Feb 20 19:13:09 2019 (r344377) +++ stable/11/sys/arm/arm/machdep_boot.c Wed Feb 20 19:19:24 2019 (r344378) @@ -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; } Modified: stable/11/sys/conf/files ============================================================================== --- stable/11/sys/conf/files Wed Feb 20 19:13:09 2019 (r344377) +++ stable/11/sys/conf/files Wed Feb 20 19:19:24 2019 (r344378) @@ -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 Copied: stable/11/sys/kern/subr_boot.c (from r336244, head/sys/kern/subr_boot.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/11/sys/kern/subr_boot.c Wed Feb 20 19:19:24 2019 (r344378, copy of r336244, head/sys/kern/subr_boot.c) @@ -0,0 +1,223 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 1998 Michael Smith <msmith@freebsd.org> + * All Rights Reserved. + * Copyright (c) 1998 Robert Nordier + * All Rights Reserved. + * Copyright (c) 2009, Oleksandr Tymoshenko <gonzo@FreeBSD.org> + * All rights reserved. + * Copyright (c) 2014 Roger Pau Monné <roger.pau@citrix.com> + * All Rights Reserved. + * Copyright (c) 2018 Kyle Evans <kevans@FreeBSD.org> + * 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 <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +/* Note: This is compiled in both the kernel and boot loader contexts */ + +#include <sys/param.h> +#ifdef _KERNEL +#include <sys/systm.h> +#else +#include <stand.h> +#endif +#include <sys/reboot.h> +#include <sys/boot.h> + +#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); +} Modified: stable/11/sys/sys/boot.h ============================================================================== --- stable/11/sys/sys/boot.h Wed Feb 20 19:13:09 2019 (r344377) +++ stable/11/sys/sys/boot.h Wed Feb 20 19:19:24 2019 (r344378) @@ -1,4 +1,5 @@ /*- + * Copyright (c) 2018 Netflix * Copyright (c) 2014 Roger Pau Monné <roger.pau@citrix.com> * 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_ */ Modified: stable/11/sys/sys/reboot.h ============================================================================== --- stable/11/sys/sys/reboot.h Wed Feb 20 19:13:09 2019 (r344377) +++ stable/11/sys/sys/reboot.h Wed Feb 20 19:19:24 2019 (r344378) @@ -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 */ Modified: stable/11/sys/x86/xen/pv.c ============================================================================== --- stable/11/sys/x86/xen/pv.c Wed Feb 20 19:13:09 2019 (r344377) +++ stable/11/sys/x86/xen/pv.c Wed Feb 20 19:19:24 2019 (r344378) @@ -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; }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201902201919.x1KJJOij023189>