Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 13 Jul 2018 16:43:17 +0000 (UTC)
From:      Warner Losh <imp@FreeBSD.org>
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
Message-ID:  <201807131643.w6DGhHVl088897@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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 <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 
 	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 <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 
 	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 <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 
 	 */
 	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 <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 @@ 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);
 	}
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201807131643.w6DGhHVl088897>