Module Name:    src
Committed By:   simonb
Date:           Sat Jun 20 02:27:55 UTC 2020

Modified Files:
        src/sys/arch/evbmips/cavium: autoconf.c machdep.c

Log Message:
Add some rudimentary boot args parsing.  Can handle "root=" as well
normal -1adsqvxz flags.  "root=" is limited to cnmacN devices so far;
should be extended to allow arbitary SD devices (and other devices?).


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/evbmips/cavium/autoconf.c
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/evbmips/cavium/machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/evbmips/cavium/autoconf.c
diff -u src/sys/arch/evbmips/cavium/autoconf.c:1.6 src/sys/arch/evbmips/cavium/autoconf.c:1.7
--- src/sys/arch/evbmips/cavium/autoconf.c:1.6	Wed Jun 10 07:34:19 2020
+++ src/sys/arch/evbmips/cavium/autoconf.c	Sat Jun 20 02:27:55 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: autoconf.c,v 1.6 2020/06/10 07:34:19 simonb Exp $	*/
+/*	$NetBSD: autoconf.c,v 1.7 2020/06/20 02:27:55 simonb Exp $	*/
 
 /*
  * Copyright 2002 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.6 2020/06/10 07:34:19 simonb Exp $");
+__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.7 2020/06/20 02:27:55 simonb Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -72,15 +72,17 @@ cpu_configure(void)
 void
 cpu_rootconf(void)
 {
+
+#ifndef MEMORY_DISK_IS_ROOT
 	findroot();
+#endif
 
 	printf("boot device: %s\n",
-		booted_device ? booted_device->dv_xname : "<unknown>");
+		booted_device ? device_xname(booted_device) : "<unknown>");
 
 	rootconf();
 }
 
-extern char	bootstring[];
 extern int	netboot;
 
 static void
@@ -92,7 +94,23 @@ findroot(void)
 	if (booted_device)
 		return;
 
-	if ((booted_device == NULL) && netboot == 0) {
+	if (rootspec && *rootspec) {
+		/* XXX hard coded "cnmac" for network boot */
+		if (strncmp(rootspec, "cnmac", 5) == 0) {
+			rootfstype = "nfs";
+			netboot = 1;
+			return;
+		}
+		/*
+		 * XXX
+		 * Assume that if the root spec is not a cnmac, it'll
+		 * be a sd. handled below.  Should be fixed to handle
+		 * multiple sd devices.
+		 */
+	}
+
+	if (netboot == 0) {
+		/* if no root device specified, default to a "sd" device */
 		for (dv = deviter_first(&di, DEVITER_F_ROOT_FIRST); dv != NULL;
 		     dv = deviter_next(&di)) {
 			if (device_class(dv) == DV_DISK &&
@@ -174,6 +192,7 @@ prop_set_octeon_gmx(device_t dev)
 void
 device_register(device_t dev, void *aux)
 {
+
 	if ((booted_device == NULL) && (netboot == 1))
 		if (device_class(dev) == DV_IFNET)
 			booted_device = dev;

Index: src/sys/arch/evbmips/cavium/machdep.c
diff -u src/sys/arch/evbmips/cavium/machdep.c:1.15 src/sys/arch/evbmips/cavium/machdep.c:1.16
--- src/sys/arch/evbmips/cavium/machdep.c:1.15	Fri Jun 19 12:38:53 2020
+++ src/sys/arch/evbmips/cavium/machdep.c	Sat Jun 20 02:27:55 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.15 2020/06/19 12:38:53 simonb Exp $	*/
+/*	$NetBSD: machdep.c,v 1.16 2020/06/20 02:27:55 simonb Exp $	*/
 
 /*
  * Copyright 2001, 2002 Wasabi Systems, Inc.
@@ -114,7 +114,7 @@
 #include "opt_multiprocessor.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.15 2020/06/19 12:38:53 simonb Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.16 2020/06/20 02:27:55 simonb Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -157,6 +157,7 @@ static void	mach_init_vector(void);
 static void	mach_init_bus_space(void);
 static void	mach_init_console(void);
 static void	mach_init_memory(void);
+static void	parse_boot_args(void);
 
 #include "com.h"
 #if NCOM > 0
@@ -179,6 +180,7 @@ extern char end[];
 void	mach_init(uint64_t, uint64_t, uint64_t, uint64_t);
 
 struct octeon_config octeon_configuration;
+struct octeon_btdesc octeon_btdesc;
 struct octeon_btinfo octeon_btinfo;
 
 char octeon_nmi_stack[PAGE_SIZE] __section(".data1") __aligned(PAGE_SIZE);
@@ -197,11 +199,18 @@ mach_init(uint64_t arg0, uint64_t arg1, 
 	KASSERT(MIPS_XKPHYS_P(arg3));
 	btinfo_paddr = mips3_ld(arg3 + OCTEON_BTINFO_PADDR_OFFSET);
 
-	/* Should be in first 256MB segment */
-	KASSERT(btinfo_paddr < 256 * 1024 * 1024);
-	memcpy(&octeon_btinfo,
-	    (struct octeon_btinfo *)MIPS_PHYS_TO_KSEG0(btinfo_paddr),
-	    sizeof(octeon_btinfo));
+	/* XXX KASSERT these addresses? */
+	memcpy(&octeon_btdesc, (void *)arg3, sizeof(octeon_btdesc));
+	if ((octeon_btdesc.obt_desc_ver == OCTEON_SUPPORTED_DESCRIPTOR_VERSION) &&
+	    (octeon_btdesc.obt_desc_size == sizeof(octeon_btdesc))) {
+		btinfo_paddr = MIPS_PHYS_TO_XKPHYS(CCA_CACHEABLE,
+		    octeon_btdesc.obt_boot_info_addr);
+	} else {
+		panic("unknown boot descriptor size %u",
+		    octeon_btdesc.obt_desc_size);
+	}
+	memcpy(&octeon_btinfo, (void *)btinfo_paddr, sizeof(octeon_btinfo));
+	parse_boot_args();
 
 	octeon_cal_timer(octeon_btinfo.obt_eclock_hz);
 
@@ -216,6 +225,12 @@ mach_init(uint64_t arg0, uint64_t arg1, 
 
 	mach_init_console();
 
+#ifdef DEBUG
+	/* Show a couple of boot desc/info params for positive feedback */
+	printf(">> boot desc eclock = %d\n", octeon_btdesc.obt_eclock);
+	printf(">> boot info board  = %d\n", octeon_btinfo.obt_board_type);
+#endif /* DEBUG */
+
 	mach_init_memory();
 
 	/*
@@ -223,9 +238,6 @@ mach_init(uint64_t arg0, uint64_t arg1, 
 	 */
 	mips_init_lwp0_uarea();
 
-	boothowto = RB_AUTOBOOT;
-	boothowto |= AB_VERBOSE;
-
 #if 0
 	curcpu()->ci_nmi_stack = octeon_nmi_stack + sizeof(octeon_nmi_stack) - sizeof(struct kernframe);
 	*(uint64_t *)MIPS_PHYS_TO_KSEG0(0x800) = (intptr_t)octeon_reset_vector;
@@ -364,6 +376,49 @@ mach_init_memory(void)
 	pmap_bootstrap();
 }
 
+void
+parse_boot_args(void)
+{
+	int i;
+	char *arg, *p;
+
+	for (i = 0; i < octeon_btdesc.obt_argc; i++) {
+		arg = (char *)MIPS_PHYS_TO_KSEG0(octeon_btdesc.obt_argv[i]);
+		if (*arg == '-') {
+			for (p = arg + 1; *p; p++) {
+				switch (*p) {
+				case '1':
+					boothowto |= RB_MD1;
+					break;
+				case 's':
+					boothowto |= RB_SINGLE;
+					break;
+				case 'd':
+					boothowto |= RB_KDB;
+					break;
+				case 'a':
+					boothowto |= RB_ASKNAME;
+					break;
+				case 'q':
+					boothowto |= AB_QUIET;
+					break;
+				case 'v':
+					boothowto |= AB_VERBOSE;
+					break;
+				case 'x':
+					boothowto |= AB_DEBUG;
+					break;
+				case 'z':
+					boothowto |= AB_SILENT;
+					break;
+				}
+			}
+		}
+		if (strncmp(arg, "root=", 5) == 0)
+			rootspec = strchr(arg, '=') + 1;
+	}
+}
+
 /*
  * cpu_startup
  * cpu_reboot

Reply via email to