From eed42ff1d5fcb63a9492db2e9572058fe843fb78 Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Fri, 13 Jul 2018 16:43:17 +0000 Subject: [PATCH] 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 --- sys/dev/ofw/ofw_subr.c | 40 +------------------ sys/mips/atheros/ar531x/ar5315_machdep.c | 36 +---------------- sys/mips/atheros/ar71xx_machdep.c | 36 +---------------- sys/mips/cavium/octeon_machdep.c | 26 +------------ sys/mips/ingenic/jz4780_machdep.c | 49 ++---------------------- sys/mips/mediatek/mtk_machdep.c | 49 +----------------------- sys/mips/nlm/xlp_machdep.c | 35 ++--------------- 7 files changed, 14 insertions(+), 257 deletions(-) diff --git a/sys/dev/ofw/ofw_subr.c b/sys/dev/ofw/ofw_subr.c index e7cfd972cbd4..8047315fb29a 100644 --- a/sys/dev/ofw/ofw_subr.c +++ b/sys/dev/ofw/ofw_subr.c @@ -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); } diff --git a/sys/mips/atheros/ar531x/ar5315_machdep.c b/sys/mips/atheros/ar531x/ar5315_machdep.c index 7fedf83bf5b4..541d9da4e54e 100644 --- a/sys/mips/atheros/ar531x/ar5315_machdep.c +++ b/sys/mips/atheros/ar531x/ar5315_machdep.c @@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -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 diff --git a/sys/mips/atheros/ar71xx_machdep.c b/sys/mips/atheros/ar71xx_machdep.c index 2d124928679b..c4ab2c1aaf77 100644 --- a/sys/mips/atheros/ar71xx_machdep.c +++ b/sys/mips/atheros/ar71xx_machdep.c @@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -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 diff --git a/sys/mips/cavium/octeon_machdep.c b/sys/mips/cavium/octeon_machdep.c index 336d2eb51d7f..a38b7429f9e2 100644 --- a/sys/mips/cavium/octeon_machdep.c +++ b/sys/mips/cavium/octeon_machdep.c @@ -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, "="); diff --git a/sys/mips/ingenic/jz4780_machdep.c b/sys/mips/ingenic/jz4780_machdep.c index b125b53acabb..ebfa04c890fc 100644 --- a/sys/mips/ingenic/jz4780_machdep.c +++ b/sys/mips/ingenic/jz4780_machdep.c @@ -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(); } diff --git a/sys/mips/mediatek/mtk_machdep.c b/sys/mips/mediatek/mtk_machdep.c index 652dfa27d718..2f9eddce4f25 100644 --- a/sys/mips/mediatek/mtk_machdep.c +++ b/sys/mips/mediatek/mtk_machdep.c @@ -46,6 +46,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -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); diff --git a/sys/mips/nlm/xlp_machdep.c b/sys/mips/nlm/xlp_machdep.c index 2e9f214fdcf5..a8c7a5756590 100644 --- a/sys/mips/nlm/xlp_machdep.c +++ b/sys/mips/nlm/xlp_machdep.c @@ -49,6 +49,7 @@ __FBSDID("$FreeBSD$"); #include /* cinit() */ #include +#include #include #include #include @@ -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); } }