Use boot_parse_* to parse command line args and retire cut-n-paste

code that was substantially identical.

Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D16205
This commit is contained in:
Warner Losh 2018-07-13 16:43:17 +00:00
parent 52379d36a9
commit eed42ff1d5
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=336245
7 changed files with 14 additions and 257 deletions

View File

@ -184,44 +184,6 @@ ofw_reg_to_paddr(phandle_t dev, int regno, bus_addr_t *paddr,
return (0);
}
/* Parse cmd line args as env - copied from xlp_machdep. */
/* XXX-BZ this should really be centrally provided for all (boot) code. */
static void
_parse_bootargs(char *cmdline)
{
char *n, *v;
while ((v = strsep(&cmdline, " \n")) != NULL) {
if (*v == '\0')
continue;
if (*v == '-') {
while (*v != '\0') {
v++;
switch (*v) {
case 'a': boothowto |= RB_ASKNAME; break;
/* Someone should simulate that ;-) */
case 'C': boothowto |= RB_CDROM; break;
case 'd': boothowto |= RB_KDB; break;
case 'D': boothowto |= RB_MULTIPLE; break;
case 'm': boothowto |= RB_MUTE; break;
case 'g': boothowto |= RB_GDB; break;
case 'h': boothowto |= RB_SERIAL; break;
case 'p': boothowto |= RB_PAUSE; break;
case 'r': boothowto |= RB_DFLTROOT; break;
case 's': boothowto |= RB_SINGLE; break;
case 'v': boothowto |= RB_VERBOSE; break;
}
}
} else {
n = strsep(&v, "=");
if (v == NULL)
kern_setenv(n, "1");
else
kern_setenv(n, v);
}
}
}
/*
* This is intended to be called early on, right after the OF system is
* initialized, so pmap may not be up yet.
@ -238,7 +200,7 @@ ofw_parse_bootargs(void)
return (chosen);
if ((err = OF_getprop(chosen, "bootargs", buf, sizeof(buf))) != -1) {
_parse_bootargs(buf);
boothowto |= boot_parse_cmdline(buf);
return (0);
}

View File

@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$");
#include <sys/cons.h>
#include <sys/kdb.h>
#include <sys/reboot.h>
#include <sys/boot.h>
#include <vm/vm.h>
#include <vm/vm_page.h>
@ -65,39 +66,6 @@ uint32_t ar711_base_mac[ETHER_ADDR_LEN];
the dynamic kenv is setup */
char boot1_env[4096];
/*
* We get a string in from Redboot with the all the arguments together,
* "foo=bar bar=baz". Split them up and save in kenv.
*/
static void
parse_argv(char *str)
{
char *n, *v;
while ((v = strsep(&str, " ")) != NULL) {
if (*v == '\0')
continue;
if (*v == '-') {
while (*v != '\0') {
v++;
switch (*v) {
case 'a': boothowto |= RB_ASKNAME; break;
case 'd': boothowto |= RB_KDB; break;
case 'g': boothowto |= RB_GDB; break;
case 's': boothowto |= RB_SINGLE; break;
case 'v': boothowto |= RB_VERBOSE; break;
}
}
} else {
n = strsep(&v, "=");
if (v == NULL)
kern_setenv(n, "1");
else
kern_setenv(n, v);
}
}
}
void
platform_cpu_init()
{
@ -299,7 +267,7 @@ platform_start(__register_t a0 __unused, __register_t a1 __unused,
if (MIPS_IS_VALID_PTR(argv)) {
for (i = 0; i < argc; i++) {
printf(" %s", argv[i]);
parse_argv(argv[i]);
boothowto |= boot_parse_arg(argv[i]);
}
}
else

View File

@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$");
#include <sys/bus.h>
#include <sys/cons.h>
#include <sys/kdb.h>
#include <sys/boot.h>
#include <sys/reboot.h>
#include <vm/vm.h>
@ -66,39 +67,6 @@ extern char edata[], end[];
the dynamic kenv is setup */
char boot1_env[4096];
/*
* We get a string in from Redboot with the all the arguments together,
* "foo=bar bar=baz". Split them up and save in kenv.
*/
static void
parse_argv(char *str)
{
char *n, *v;
while ((v = strsep(&str, " ")) != NULL) {
if (*v == '\0')
continue;
if (*v == '-') {
while (*v != '\0') {
v++;
switch (*v) {
case 'a': boothowto |= RB_ASKNAME; break;
case 'd': boothowto |= RB_KDB; break;
case 'g': boothowto |= RB_GDB; break;
case 's': boothowto |= RB_SINGLE; break;
case 'v': boothowto |= RB_VERBOSE; break;
}
}
} else {
n = strsep(&v, "=");
if (v == NULL)
kern_setenv(n, "1");
else
kern_setenv(n, v);
}
}
}
void
platform_cpu_init()
{
@ -428,7 +396,7 @@ platform_start(__register_t a0 __unused, __register_t a1 __unused,
if (MIPS_IS_VALID_PTR(argv)) {
for (i = 0; i < argc; i++) {
printf(" %s", argv[i]);
parse_argv(argv[i]);
boothowto |= boot_parse_arg(argv[i]);
}
}
else

View File

@ -664,30 +664,6 @@ octeon_boot_params_init(register_t ptr)
}
/* impEND: This stuff should move back into the Cavium SDK */
static void
boothowto_parse(const char *v)
{
if ((v == NULL) || (*v != '-'))
return;
while (*v != '\0') {
v++;
switch (*v) {
case 'a': boothowto |= RB_ASKNAME; break;
case 'C': boothowto |= RB_CDROM; break;
case 'd': boothowto |= RB_KDB; break;
case 'D': boothowto |= RB_MULTIPLE; break;
case 'm': boothowto |= RB_MUTE; break;
case 'g': boothowto |= RB_GDB; break;
case 'h': boothowto |= RB_SERIAL; break;
case 'p': boothowto |= RB_PAUSE; break;
case 'r': boothowto |= RB_DFLTROOT; break;
case 's': boothowto |= RB_SINGLE; break;
case 'v': boothowto |= RB_VERBOSE; break;
}
}
}
/*
* The boot loader command line may specify kernel environment variables or
* applicable boot flags of boot(8).
@ -709,7 +685,7 @@ octeon_init_kenv(register_t ptr)
if (v == NULL)
continue;
if (*v == '-') {
boothowto_parse(v);
boothowto |= boot_parse_arg(v);
continue;
}
n = strsep(&v, "=");

View File

@ -173,50 +173,7 @@ mips_init(void)
#endif
}
static void
_parse_bootarg(char *v)
{
char *n;
if (*v == '-') {
while (*v != '\0') {
v++;
switch (*v) {
case 'a': boothowto |= RB_ASKNAME; break;
/* Someone should simulate that ;-) */
case 'C': boothowto |= RB_CDROM; break;
case 'd': boothowto |= RB_KDB; break;
case 'D': boothowto |= RB_MULTIPLE; break;
case 'm': boothowto |= RB_MUTE; break;
case 'g': boothowto |= RB_GDB; break;
case 'h': boothowto |= RB_SERIAL; break;
case 'p': boothowto |= RB_PAUSE; break;
case 'r': boothowto |= RB_DFLTROOT; break;
case 's': boothowto |= RB_SINGLE; break;
case 'v': boothowto |= RB_VERBOSE; break;
}
}
} else {
n = strsep(&v, "=");
if (v == NULL)
kern_setenv(n, "1");
else
kern_setenv(n, v);
}
}
static void
_parse_cmdline(int argc, char *argv[])
{
int i;
for (i = 1; i < argc; i++)
_parse_bootarg(argv[i]);
}
#ifdef FDT
/* Parse cmd line args as env - copied from xlp_machdep. */
/* XXX-BZ this should really be centrally provided for all (boot) code. */
static void
_parse_bootargs(char *cmdline)
{
@ -225,7 +182,7 @@ _parse_bootargs(char *cmdline)
while ((v = strsep(&cmdline, " \n")) != NULL) {
if (*v == '\0')
continue;
_parse_bootarg(v);
boothowto |= boot_parse_arg(v);
}
}
#endif
@ -285,12 +242,12 @@ platform_start(__register_t a0, __register_t a1,
*/
chosen = OF_finddevice("/chosen");
if (OF_getprop(chosen, "bootargs", buf, sizeof(buf)) != -1)
_parse_bootargs(buf);
boothowto |= boot_parse_cmdline(buf);
#endif
/* Parse cmdline from U-Boot */
argc = a0;
argv = (char **)a1;
_parse_cmdline(argc, argv);
boothowto |= boot_parse_cmdline(argc, argv);
mips_init();
}

View File

@ -46,6 +46,7 @@ __FBSDID("$FreeBSD$");
#include <sys/proc.h>
#include <sys/kdb.h>
#include <sys/ptrace.h>
#include <sys/boot.h>
#include <sys/reboot.h>
#include <sys/signalvar.h>
#include <sys/sysent.h>
@ -196,52 +197,6 @@ mips_init(void)
#endif
}
static void
_parse_bootarg(char *v)
{
char *n;
if (*v == '-') {
while (*v != '\0') {
v++;
switch (*v) {
case 'a': boothowto |= RB_ASKNAME; break;
/* Someone should simulate that ;-) */
case 'C': boothowto |= RB_CDROM; break;
case 'd': boothowto |= RB_KDB; break;
case 'D': boothowto |= RB_MULTIPLE; break;
case 'm': boothowto |= RB_MUTE; break;
case 'g': boothowto |= RB_GDB; break;
case 'h': boothowto |= RB_SERIAL; break;
case 'p': boothowto |= RB_PAUSE; break;
case 'r': boothowto |= RB_DFLTROOT; break;
case 's': boothowto |= RB_SINGLE; break;
case 'v': boothowto |= RB_VERBOSE; break;
}
}
} else {
n = strsep(&v, "=");
if (v == NULL)
kern_setenv(n, "1");
else
kern_setenv(n, v);
}
}
/* Parse cmd line args as env - copied from xlp_machdep. */
/* XXX-BZ this should really be centrally provided for all (boot) code. */
static void
_parse_bootargs(char *cmdline)
{
char *v;
while ((v = strsep(&cmdline, " \n")) != NULL) {
if (*v == '\0')
continue;
_parse_bootarg(v);
}
}
void
platform_reset(void)
{
@ -295,7 +250,7 @@ platform_start(__register_t a0 __unused, __register_t a1 __unused,
*/
chosen = OF_finddevice("/chosen");
if (OF_getprop(chosen, "bsdbootargs", buf, sizeof(buf)) != -1)
_parse_bootargs(buf);
boothowto |= boot_parse_cmdline(buf);
printf("FDT DTB at: 0x%08x\n", (uint32_t)dtbp);

View File

@ -49,6 +49,7 @@ __FBSDID("$FreeBSD$");
#include <sys/cons.h> /* cinit() */
#include <sys/kdb.h>
#include <sys/boot.h>
#include <sys/reboot.h>
#include <sys/queue.h>
#include <sys/smp.h>
@ -261,36 +262,6 @@ xlp_parse_mmu_options(void)
return;
}
/* Parse cmd line args as env - copied from ar71xx */
static void
xlp_parse_bootargs(char *cmdline)
{
char *n, *v;
while ((v = strsep(&cmdline, " \n")) != NULL) {
if (*v == '\0')
continue;
if (*v == '-') {
while (*v != '\0') {
v++;
switch (*v) {
case 'a': boothowto |= RB_ASKNAME; break;
case 'd': boothowto |= RB_KDB; break;
case 'g': boothowto |= RB_GDB; break;
case 's': boothowto |= RB_SINGLE; break;
case 'v': boothowto |= RB_VERBOSE; break;
}
}
} else {
n = strsep(&v, "=");
if (v == NULL)
kern_setenv(n, "1");
else
kern_setenv(n, v);
}
}
}
#ifdef FDT
static void
xlp_bootargs_init(__register_t arg)
@ -321,7 +292,7 @@ xlp_bootargs_init(__register_t arg)
}
if (OF_getprop(chosen, "bootargs", buf, sizeof(buf)) != -1)
xlp_parse_bootargs(buf);
boothowto |= boot_parse_cmdline(buf);
}
#else
/*
@ -363,7 +334,7 @@ xlp_bootargs_init(__register_t arg)
v = kern_getenv("bootargs");
if (v != NULL) {
strlcpy(buf, v, sizeof(buf));
xlp_parse_bootargs(buf);
boothowto |= boot_parse_cmdline(buf);
freeenv(v);
}
}