From owner-svn-src-head@freebsd.org Fri Jul 13 16:43:19 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6360610437FA; Fri, 13 Jul 2018 16:43:19 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 129188E296; Fri, 13 Jul 2018 16:43:19 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id E926012D05; Fri, 13 Jul 2018 16:43:18 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w6DGhIpx088904; Fri, 13 Jul 2018 16:43:18 GMT (envelope-from imp@FreeBSD.org) Received: (from imp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w6DGhHVl088897; Fri, 13 Jul 2018 16:43:17 GMT (envelope-from imp@FreeBSD.org) Message-Id: <201807131643.w6DGhHVl088897@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: imp set sender to imp@FreeBSD.org using -f From: Warner Losh Date: Fri, 13 Jul 2018 16:43:17 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r336245 - in head/sys: dev/ofw mips/atheros mips/atheros/ar531x mips/cavium mips/ingenic mips/mediatek mips/nlm X-SVN-Group: head X-SVN-Commit-Author: imp X-SVN-Commit-Paths: in head/sys: dev/ofw mips/atheros mips/atheros/ar531x mips/cavium mips/ingenic mips/mediatek mips/nlm X-SVN-Commit-Revision: 336245 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Jul 2018 16:43:19 -0000 Author: imp Date: Fri Jul 13 16:43:17 2018 New Revision: 336245 URL: https://svnweb.freebsd.org/changeset/base/336245 Log: 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 Modified: head/sys/dev/ofw/ofw_subr.c head/sys/mips/atheros/ar531x/ar5315_machdep.c head/sys/mips/atheros/ar71xx_machdep.c head/sys/mips/cavium/octeon_machdep.c head/sys/mips/ingenic/jz4780_machdep.c head/sys/mips/mediatek/mtk_machdep.c head/sys/mips/nlm/xlp_machdep.c Modified: head/sys/dev/ofw/ofw_subr.c ============================================================================== --- head/sys/dev/ofw/ofw_subr.c Fri Jul 13 16:43:05 2018 (r336244) +++ head/sys/dev/ofw/ofw_subr.c Fri Jul 13 16:43:17 2018 (r336245) @@ -184,44 +184,6 @@ ofw_reg_to_paddr(phandle_t dev, int regno, bus_addr_t 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); } Modified: head/sys/mips/atheros/ar531x/ar5315_machdep.c ============================================================================== --- head/sys/mips/atheros/ar531x/ar5315_machdep.c Fri Jul 13 16:43:05 2018 (r336244) +++ head/sys/mips/atheros/ar531x/ar5315_machdep.c Fri Jul 13 16:43:17 2018 (r336245) @@ -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 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 Modified: head/sys/mips/atheros/ar71xx_machdep.c ============================================================================== --- head/sys/mips/atheros/ar71xx_machdep.c Fri Jul 13 16:43:05 2018 (r336244) +++ head/sys/mips/atheros/ar71xx_machdep.c Fri Jul 13 16:43:17 2018 (r336245) @@ -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 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 Modified: head/sys/mips/cavium/octeon_machdep.c ============================================================================== --- head/sys/mips/cavium/octeon_machdep.c Fri Jul 13 16:43:05 2018 (r336244) +++ head/sys/mips/cavium/octeon_machdep.c Fri Jul 13 16:43:17 2018 (r336245) @@ -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, "="); Modified: head/sys/mips/ingenic/jz4780_machdep.c ============================================================================== --- head/sys/mips/ingenic/jz4780_machdep.c Fri Jul 13 16:43:05 2018 (r336244) +++ head/sys/mips/ingenic/jz4780_machdep.c Fri Jul 13 16:43:17 2018 (r336245) @@ -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(); } Modified: head/sys/mips/mediatek/mtk_machdep.c ============================================================================== --- head/sys/mips/mediatek/mtk_machdep.c Fri Jul 13 16:43:05 2018 (r336244) +++ head/sys/mips/mediatek/mtk_machdep.c Fri Jul 13 16:43:17 2018 (r336245) @@ -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 */ 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); Modified: head/sys/mips/nlm/xlp_machdep.c ============================================================================== --- head/sys/mips/nlm/xlp_machdep.c Fri Jul 13 16:43:05 2018 (r336244) +++ head/sys/mips/nlm/xlp_machdep.c Fri Jul 13 16:43:17 2018 (r336245) @@ -49,6 +49,7 @@ __FBSDID("$FreeBSD$"); #include /* cinit() */ #include +#include #include #include #include @@ -261,36 +262,6 @@ unsupp: 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); } }