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.

Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D16205
This commit is contained in:
Warner Losh 2018-07-13 16:43:23 +00:00
parent eed42ff1d5
commit 4569e91328
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=336246
4 changed files with 11 additions and 230 deletions

View file

@ -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,61 +97,10 @@ 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 = boot_parse_cmdline(kargs);
howto |= bootenv_flags();
#if defined(__sparc64__)
if (md_bootserial() != -1)

View file

@ -420,79 +420,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);
}

View file

@ -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,62 +39,11 @@ __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 |= bootenv_flags();
/* Enable selected consoles */

View file

@ -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,63 +39,11 @@ __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 |= bootenv_flags();
/* Enable selected consoles */
@ -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;