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:
parent
52379d36a9
commit
eed42ff1d5
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=336245
@ -184,44 +184,6 @@ ofw_reg_to_paddr(phandle_t dev, int regno, bus_addr_t *paddr,
|
|||||||
return (0);
|
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
|
* This is intended to be called early on, right after the OF system is
|
||||||
* initialized, so pmap may not be up yet.
|
* initialized, so pmap may not be up yet.
|
||||||
@ -238,7 +200,7 @@ ofw_parse_bootargs(void)
|
|||||||
return (chosen);
|
return (chosen);
|
||||||
|
|
||||||
if ((err = OF_getprop(chosen, "bootargs", buf, sizeof(buf))) != -1) {
|
if ((err = OF_getprop(chosen, "bootargs", buf, sizeof(buf))) != -1) {
|
||||||
_parse_bootargs(buf);
|
boothowto |= boot_parse_cmdline(buf);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include <sys/cons.h>
|
#include <sys/cons.h>
|
||||||
#include <sys/kdb.h>
|
#include <sys/kdb.h>
|
||||||
#include <sys/reboot.h>
|
#include <sys/reboot.h>
|
||||||
|
#include <sys/boot.h>
|
||||||
|
|
||||||
#include <vm/vm.h>
|
#include <vm/vm.h>
|
||||||
#include <vm/vm_page.h>
|
#include <vm/vm_page.h>
|
||||||
@ -65,39 +66,6 @@ uint32_t ar711_base_mac[ETHER_ADDR_LEN];
|
|||||||
the dynamic kenv is setup */
|
the dynamic kenv is setup */
|
||||||
char boot1_env[4096];
|
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
|
void
|
||||||
platform_cpu_init()
|
platform_cpu_init()
|
||||||
{
|
{
|
||||||
@ -299,7 +267,7 @@ platform_start(__register_t a0 __unused, __register_t a1 __unused,
|
|||||||
if (MIPS_IS_VALID_PTR(argv)) {
|
if (MIPS_IS_VALID_PTR(argv)) {
|
||||||
for (i = 0; i < argc; i++) {
|
for (i = 0; i < argc; i++) {
|
||||||
printf(" %s", argv[i]);
|
printf(" %s", argv[i]);
|
||||||
parse_argv(argv[i]);
|
boothowto |= boot_parse_arg(argv[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include <sys/bus.h>
|
#include <sys/bus.h>
|
||||||
#include <sys/cons.h>
|
#include <sys/cons.h>
|
||||||
#include <sys/kdb.h>
|
#include <sys/kdb.h>
|
||||||
|
#include <sys/boot.h>
|
||||||
#include <sys/reboot.h>
|
#include <sys/reboot.h>
|
||||||
|
|
||||||
#include <vm/vm.h>
|
#include <vm/vm.h>
|
||||||
@ -66,39 +67,6 @@ extern char edata[], end[];
|
|||||||
the dynamic kenv is setup */
|
the dynamic kenv is setup */
|
||||||
char boot1_env[4096];
|
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
|
void
|
||||||
platform_cpu_init()
|
platform_cpu_init()
|
||||||
{
|
{
|
||||||
@ -428,7 +396,7 @@ platform_start(__register_t a0 __unused, __register_t a1 __unused,
|
|||||||
if (MIPS_IS_VALID_PTR(argv)) {
|
if (MIPS_IS_VALID_PTR(argv)) {
|
||||||
for (i = 0; i < argc; i++) {
|
for (i = 0; i < argc; i++) {
|
||||||
printf(" %s", argv[i]);
|
printf(" %s", argv[i]);
|
||||||
parse_argv(argv[i]);
|
boothowto |= boot_parse_arg(argv[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -664,30 +664,6 @@ octeon_boot_params_init(register_t ptr)
|
|||||||
}
|
}
|
||||||
/* impEND: This stuff should move back into the Cavium SDK */
|
/* 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
|
* The boot loader command line may specify kernel environment variables or
|
||||||
* applicable boot flags of boot(8).
|
* applicable boot flags of boot(8).
|
||||||
@ -709,7 +685,7 @@ octeon_init_kenv(register_t ptr)
|
|||||||
if (v == NULL)
|
if (v == NULL)
|
||||||
continue;
|
continue;
|
||||||
if (*v == '-') {
|
if (*v == '-') {
|
||||||
boothowto_parse(v);
|
boothowto |= boot_parse_arg(v);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
n = strsep(&v, "=");
|
n = strsep(&v, "=");
|
||||||
|
@ -173,50 +173,7 @@ mips_init(void)
|
|||||||
#endif
|
#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
|
#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
|
static void
|
||||||
_parse_bootargs(char *cmdline)
|
_parse_bootargs(char *cmdline)
|
||||||
{
|
{
|
||||||
@ -225,7 +182,7 @@ _parse_bootargs(char *cmdline)
|
|||||||
while ((v = strsep(&cmdline, " \n")) != NULL) {
|
while ((v = strsep(&cmdline, " \n")) != NULL) {
|
||||||
if (*v == '\0')
|
if (*v == '\0')
|
||||||
continue;
|
continue;
|
||||||
_parse_bootarg(v);
|
boothowto |= boot_parse_arg(v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -285,12 +242,12 @@ platform_start(__register_t a0, __register_t a1,
|
|||||||
*/
|
*/
|
||||||
chosen = OF_finddevice("/chosen");
|
chosen = OF_finddevice("/chosen");
|
||||||
if (OF_getprop(chosen, "bootargs", buf, sizeof(buf)) != -1)
|
if (OF_getprop(chosen, "bootargs", buf, sizeof(buf)) != -1)
|
||||||
_parse_bootargs(buf);
|
boothowto |= boot_parse_cmdline(buf);
|
||||||
#endif
|
#endif
|
||||||
/* Parse cmdline from U-Boot */
|
/* Parse cmdline from U-Boot */
|
||||||
argc = a0;
|
argc = a0;
|
||||||
argv = (char **)a1;
|
argv = (char **)a1;
|
||||||
_parse_cmdline(argc, argv);
|
boothowto |= boot_parse_cmdline(argc, argv);
|
||||||
|
|
||||||
mips_init();
|
mips_init();
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include <sys/proc.h>
|
#include <sys/proc.h>
|
||||||
#include <sys/kdb.h>
|
#include <sys/kdb.h>
|
||||||
#include <sys/ptrace.h>
|
#include <sys/ptrace.h>
|
||||||
|
#include <sys/boot.h>
|
||||||
#include <sys/reboot.h>
|
#include <sys/reboot.h>
|
||||||
#include <sys/signalvar.h>
|
#include <sys/signalvar.h>
|
||||||
#include <sys/sysent.h>
|
#include <sys/sysent.h>
|
||||||
@ -196,52 +197,6 @@ mips_init(void)
|
|||||||
#endif
|
#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
|
void
|
||||||
platform_reset(void)
|
platform_reset(void)
|
||||||
{
|
{
|
||||||
@ -295,7 +250,7 @@ platform_start(__register_t a0 __unused, __register_t a1 __unused,
|
|||||||
*/
|
*/
|
||||||
chosen = OF_finddevice("/chosen");
|
chosen = OF_finddevice("/chosen");
|
||||||
if (OF_getprop(chosen, "bsdbootargs", buf, sizeof(buf)) != -1)
|
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);
|
printf("FDT DTB at: 0x%08x\n", (uint32_t)dtbp);
|
||||||
|
|
||||||
|
@ -49,6 +49,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
|
|
||||||
#include <sys/cons.h> /* cinit() */
|
#include <sys/cons.h> /* cinit() */
|
||||||
#include <sys/kdb.h>
|
#include <sys/kdb.h>
|
||||||
|
#include <sys/boot.h>
|
||||||
#include <sys/reboot.h>
|
#include <sys/reboot.h>
|
||||||
#include <sys/queue.h>
|
#include <sys/queue.h>
|
||||||
#include <sys/smp.h>
|
#include <sys/smp.h>
|
||||||
@ -261,36 +262,6 @@ xlp_parse_mmu_options(void)
|
|||||||
return;
|
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
|
#ifdef FDT
|
||||||
static void
|
static void
|
||||||
xlp_bootargs_init(__register_t arg)
|
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)
|
if (OF_getprop(chosen, "bootargs", buf, sizeof(buf)) != -1)
|
||||||
xlp_parse_bootargs(buf);
|
boothowto |= boot_parse_cmdline(buf);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
/*
|
/*
|
||||||
@ -363,7 +334,7 @@ xlp_bootargs_init(__register_t arg)
|
|||||||
v = kern_getenv("bootargs");
|
v = kern_getenv("bootargs");
|
||||||
if (v != NULL) {
|
if (v != NULL) {
|
||||||
strlcpy(buf, v, sizeof(buf));
|
strlcpy(buf, v, sizeof(buf));
|
||||||
xlp_parse_bootargs(buf);
|
boothowto |= boot_parse_cmdline(buf);
|
||||||
freeenv(v);
|
freeenv(v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user