Working "config generic" support; from Theo. trunk
authorpk <pk@NetBSD.org>
Thu, 16 Feb 1995 21:42:50 +0000
branchtrunk
changeset 12180 d2ac778490c7
parent 12179 f53f3bba1784
child 12181 792180b59729
Working "config generic" support; from Theo.
sys/arch/sparc/dev/cgsix.c
sys/arch/sparc/dev/if_ie.c
sys/arch/sparc/dev/if_le.c
sys/arch/sparc/sparc/autoconf.c
sys/arch/sparc/sparc/swapgeneric.c
sys/nfs/nfs_boot.c
--- a/sys/arch/sparc/dev/cgsix.c	Thu Feb 16 20:39:17 1995 +0000
+++ b/sys/arch/sparc/dev/cgsix.c	Thu Feb 16 21:42:50 1995 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: cgsix.c,v 1.11 1994/11/23 07:02:05 deraadt Exp $ */
+/*	$NetBSD: cgsix.c,v 1.12 1995/02/16 21:50:41 pk Exp $ */
 
 /*
  * Copyright (c) 1993
@@ -244,7 +244,7 @@
 	sc->sc_thc->thc_misc |= THC_MISC_VIDEN;
 
 	printf("\n");
-	if (ca->ca_bustype == BUS_SBUS)
+	if (sbus)
 		sbus_establish(&sc->sc_sd, &sc->sc_dev);
 	if (node == fbnode)
 		fb_attach(&sc->sc_fb);
--- a/sys/arch/sparc/dev/if_ie.c	Thu Feb 16 20:39:17 1995 +0000
+++ b/sys/arch/sparc/dev/if_ie.c	Thu Feb 16 21:42:50 1995 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ie.c,v 1.11 1995/01/27 09:49:57 pk Exp $	*/
+/*	$NetBSD: if_ie.c,v 1.12 1995/02/16 21:50:43 pk Exp $	*/
 
 /*-
  * Copyright (c) 1993, 1994, 1995 Charles Hannum.
@@ -390,6 +390,8 @@
 
 	if (strcmp(cf->cf_driver->cd_name, ra->ra_name))	/* correct name? */
 		return (0);
+	if (ca->ca_bustype == BUS_SBUS)
+		return (0);
 
 	if (cputyp == CPU_SUN4) {
 		/*
@@ -483,6 +485,7 @@
 	struct confargs *ca = aux;
 	struct ifnet *ifp = &sc->sc_arpcom.ac_if;
 	extern void myetheraddr(u_char *);	/* should be elsewhere */
+	register struct bootpath *bp;
 	int     pri = ca->ca_ra.ra_intr[0].int_pri;
 
 	/*
@@ -647,10 +650,7 @@
 #endif
 
 	switch (ca->ca_bustype) {
-	case BUS_SBUS:
-		panic("ie configured on the sbus?");	/* XXX */
-		break;		/* shouldn't happen, no sbus ie's XXX */
-#ifdef SUN4
+#if defined(SUN4)
 	case BUS_OBIO:
 		sc->sc_ih.ih_fun = ieintr;
 		sc->sc_ih.ih_arg = sc;
@@ -661,10 +661,15 @@
 		sc->sc_ih.ih_fun = ieintr;
 		sc->sc_ih.ih_arg = sc;
 		vmeintr_establish(ca->ca_ra.ra_intr[0].int_vec, pri,
-		    &(sc->sc_ih));
+		    &sc->sc_ih);
 		break;
 #endif /* SUN4 */
 	}
+
+	bp = ca->ca_ra.ra_bp;
+	if (bp != NULL && strcmp(bp->name, "ie") == 0 &&
+	    sc->sc_dev.dv_unit == bp->val[1])
+		bootdv = &sc->sc_dev;
 }
 
 
--- a/sys/arch/sparc/dev/if_le.c	Thu Feb 16 20:39:17 1995 +0000
+++ b/sys/arch/sparc/dev/if_le.c	Thu Feb 16 21:42:50 1995 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_le.c,v 1.17 1994/11/23 07:02:15 deraadt Exp $ */
+/*	$NetBSD: if_le.c,v 1.18 1995/02/16 21:50:45 pk Exp $ */
 
 /*-
  * Copyright (c) 1982, 1992, 1993
@@ -284,11 +284,13 @@
 	bp = ca->ca_ra.ra_bp;
 	switch (ca->ca_bustype) {
 	case BUS_SBUS:
-		if (bp != NULL && strcmp(bp->name, "le") == 0 && SAME_LANCE(bp, ca))
+		if (bp != NULL && strcmp(bp->name, "le") == 0 &&
+		    SAME_LANCE(bp, ca))
 			bootdv = &sc->sc_dev;
 		break;
 	default:
-		if (bp != NULL && strcmp(bp->name, "le") == 0)
+		if (bp != NULL && strcmp(bp->name, "le") == 0 &&
+		    sc->sc_dev.dv_unit == bp->val[1])
 			bootdv = &sc->sc_dev;
 		break;
 	}
--- a/sys/arch/sparc/sparc/autoconf.c	Thu Feb 16 20:39:17 1995 +0000
+++ b/sys/arch/sparc/sparc/autoconf.c	Thu Feb 16 21:42:50 1995 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: autoconf.c,v 1.22 1995/02/16 20:39:17 pk Exp $ */
+/*	$NetBSD: autoconf.c,v 1.23 1995/02/16 21:42:50 pk Exp $ */
 
 /*
  * Copyright (c) 1992, 1993
@@ -87,7 +87,7 @@
 int	findroot __P((void));
 void	setroot __P((void));
 static	int getstr __P((char *, int));
-static	int findblkmajor __P((struct dkdevice *));
+static	int findblkmajor __P((struct device *));
 static	struct device *getdisk __P((char *, int, int, dev_t *));
 
 struct	bootpath bootpath[8];
@@ -269,31 +269,39 @@
 			    *(pp = str2hex(++pp, &v0val[1])) == ',')
 				(void)str2hex(++pp, &v0val[2]);
 
-			/* Assume sbus0 */
+			/* XXX: unwisely assume sbus0 */
 			strcpy(bp->name, "sbus");
 			bp->val[0] = 0;
 			++bp;
 
-			if (cp[0] == 'l' && cp[1] == 'e') {
-				/* le */
-				strcpy(bp->name, "le");
-				bp->val[0] = -1;
-				bp->val[1] = v0val[0];
-			} else {
-				/* sd or maybe st; assume espN */
+			if (cp[0] == 's' &&
+			    (cp[1] == 'd' || cp[1] == 't' || cp[1] == 'r')) {
+				/*
+				 * XXX: unwisely assume that the scsi disk is
+				 * hooked up to an esp
+				 */
 				strcpy(bp->name, "esp");
 				bp->val[0] = -1;
 				bp->val[1] = v0val[0];
 
+				++bp;
+				/* exact device */
+				bp->name[0] = cp[0];
+				bp->name[1] = cp[1];
+				bp->name[2] = '\0';
+
 /* XXX map target 0 to 3, 3 to 0. Should really see how the prom is configed */
 #define CRAZYMAP(v) ((v) == 3 ? 0 : (v) == 0 ? 3 : (v))
 
-				++bp;
+				bp->val[0] = CRAZYMAP(v0val[1]);
+				bp->val[1] = v0val[2];
+			} else {
+				/* some other device like ie, le, etc. */
 				bp->name[0] = cp[0];
 				bp->name[1] = cp[1];
 				bp->name[2] = '\0';
-				bp->val[0] = CRAZYMAP(v0val[1]);
-				bp->val[1] = v0val[2];
+				bp->val[0] = -1;
+				bp->val[1] = v0val[0];
 			}
 		}
 
@@ -312,12 +320,15 @@
 			while (*cp != '@' && *cp != '/' && *cp != '\0')
 				*pp++ = *cp++;
 			*pp = '\0';
-
 			if (*cp == '@') {
 				cp = str2hex(++cp, &bp->val[0]);
 				if (*cp == ',')
 					cp = str2hex(++cp, &bp->val[1]);
 			}
+#ifdef notyet
+			if (strcmp(bp->name, "iommu") == 0)
+				continue;
+#endif
 			++bp;
 		}
 
@@ -409,12 +420,12 @@
 	if (!config_rootfound(cp, (void *)&oca))
 		panic("mainbus not configured");
 	(void)spl0();
-	if (bootdv)
-		printf("Found boot device %s\n", bootdv->dv_xname);
+
 	/*
 	 * Configure swap area and related system
 	 * parameter based on device(s) used.
 	 */
+	setroot();
 	swapconf();
 	cold = 0;
 }
@@ -1047,23 +1058,30 @@
 	dumpconf();
 }
 
-#define	DOSWAP			/* Change swdevt and dumpdev too */
 u_long	bootdev;		/* should be dev_t, but not until 32 bits */
 
 #define	PARTITIONMASK	0x7
 #define	PARTITIONSHIFT	3
 
+struct nam2blk {
+	char *name;
+	int maj;
+} nam2blk[] = {
+	{ "sd",		7 },
+	{ "st",		11 },
+	{ "cd",		18 },
+};
+
 static int
 findblkmajor(dv)
-	register struct dkdevice *dv;
+	struct device *dv;
 {
+	char *name = dv->dv_xname;
 	register int i;
 
-	for (i = 0; i < nblkdev; ++i)
-		if ((void (*)(struct buf *))bdevsw[i].d_strategy ==
-		    dv->dk_driver->d_strategy)
-			return (i);
-
+	for (i = 0; i < sizeof(nam2blk)/sizeof(nam2blk[0]); ++i)
+		if (strncmp(name, nam2blk[i].name, strlen(nam2blk[0].name)) == 0)
+			return (nam2blk[i].maj);
 	return (-1);
 }
 
@@ -1077,9 +1095,14 @@
 
 	if ((dv = parsedisk(str, len, defpart, devp)) == NULL) {
 		printf("use one of:");
-		for (dv = alldevs; dv != NULL; dv = dv->dv_next)
+		for (dv = alldevs; dv != NULL; dv = dv->dv_next) {
 			if (dv->dv_class == DV_DISK)
 				printf(" %s[a-h]", dv->dv_xname);
+#ifdef NFSCLIENT
+			if (dv->dv_class == DV_IFNET)
+				printf(" %s", dv->dv_xname);
+#endif
+		}
 		printf("\n");
 	}
 	return (dv);
@@ -1108,13 +1131,20 @@
 	for (dv = alldevs; dv != NULL; dv = dv->dv_next) {
 		if (dv->dv_class == DV_DISK &&
 		    strcmp(str, dv->dv_xname) == 0) {
-			majdev = findblkmajor((struct dkdevice *)dv);
+			majdev = findblkmajor(dv);
 			if (majdev < 0)
 				panic("parsedisk");
 			mindev = (dv->dv_unit << PARTITIONSHIFT) + part;
 			*devp = makedev(majdev, mindev);
 			break;
 		}
+#ifdef NFSCLIENT
+		if (dv->dv_class == DV_IFNET &&
+		    strcmp(str, dv->dv_xname) == 0) {
+			*devp = NODEV;
+			break;
+		}
+#endif
 	}
 
 	*cp = c;
@@ -1125,28 +1155,42 @@
  * Attempt to find the device from which we were booted.
  * If we can do so, and not instructed not to do so,
  * change rootdev to correspond to the load device.
+ * 
+ * XXX Actually, swap and root must be on the same type of device,
+ * (ie. DV_DISK or DV_IFNET) because of how (*mountroot) is written.
+ * That should be fixed.
  */
 void
 setroot()
 {
 	register struct swdevt *swp;
 	register struct device *dv;
-	register int len, majdev, mindev, part;
-	dev_t nrootdev, nswapdev;
+	register int len, majdev, mindev;
+	dev_t nrootdev, nswapdev = NODEV;
 	char buf[128];
 	extern int (*mountroot)();
-#ifdef DOSWAP
 	dev_t temp;
+#if defined(NFSCLIENT)
+	extern char *nfsbootdevname;
+	extern int nfs_mountroot();
 #endif
-#if defined(NFSCLIENT)
-	extern int nfs_mountroot();
+#if defined(FFS)
+	extern int ffs_mountroot();
 #endif
 
 	if (boothowto & RB_ASKNAME) {
 		for (;;) {
-			printf("root device? ");
+			if (bootdv->dv_class == DV_DISK)
+				printf("root device (default %sa)? ",
+					bootdv->dv_xname);
+			else
+				printf("root device (default %s)? ",
+					bootdv->dv_xname);
 			len = getstr(buf, sizeof(buf));
-#ifdef GENERIC
+			if (len == 0) {
+				strcpy(buf, bootdv->dv_xname);
+				len = strlen(buf);
+			}
 			if (len > 0 && buf[len - 1] == '*') {
 				buf[--len] = '\0';
 				dv = getdisk(buf, len, 1, &nrootdev);
@@ -1156,77 +1200,109 @@
 					goto gotswap;
 				}
 			}
-#endif
 			dv = getdisk(buf, len, 0, &nrootdev);
 			if (dv != NULL) {
 				bootdv = dv;
 				break;
 			}
 		}
+
+		/*
+		 * because swap must be on same device as root, for
+		 * network devices this is easy.
+		 */
+		if (bootdv->dv_class == DV_IFNET) {
+			goto gotswap;
+		}
 		for (;;) {
-			printf("swap device (default %sb)? ", bootdv->dv_xname);
+			if (bootdv->dv_class == DV_DISK)
+				printf("swap device (default %sb)? ",
+					bootdv->dv_xname);
+			else
+				printf("swap device (default %s)? ",
+					bootdv->dv_xname);
 			len = getstr(buf, sizeof(buf));
 			if (len == 0) {
-				nswapdev = makedev(major(nrootdev),
-				    (minor(nrootdev) & ~ PARTITIONMASK) | 1);
+				switch (bootdv->dv_class) {
+				case DV_IFNET:
+					nswapdev = NODEV;
+					break;
+				case DV_DISK:
+					nswapdev = makedev(major(nrootdev),
+					    (minor(nrootdev) & ~ PARTITIONMASK) | 1);
+					break;
+				}
+				break;
+			}
+			dv = getdisk(buf, len, 1, &nswapdev);
+			if (dv) {
+				if (dv->dv_class == DV_IFNET)
+					nswapdev = NODEV;
 				break;
 			}
-			if (getdisk(buf, len, 1, &nswapdev) != NULL)
-				break;
 		}
-#ifdef GENERIC
 gotswap:
-#endif
 		rootdev = nrootdev;
-		swapdev = nswapdev;
-		dumpdev = nswapdev;		/* ??? */
+		dumpdev = swapdev = nswapdev;
 		swdevt[0].sw_dev = nswapdev;
 		swdevt[1].sw_dev = NODEV;
+	} else if (mountroot == NULL) {
+		/*
+		 * `swap generic': Use the device the ROM told us to use.
+		 */
+		majdev = findblkmajor(bootdv);
+		if (majdev >= 0) {
+			/*
+			 * Root and swap are on a disk.
+			 * Assume that we are supposed to put root on
+			 * partition a, and swap on partition b.
+			 */
+			mindev = (bootdv->dv_unit << PARTITIONSHIFT) + 0;
+			rootdev = makedev(majdev, mindev);
+			swapdev = dumpdev = makedev(major(rootdev),
+			    (minor(rootdev) & ~ PARTITIONMASK) | 1);
+		} else {
+			/*
+			 * Root and swap are on a net.
+			 */
+			swapdev = dumpdev = NODEV;
+		}
+		swdevt[0].sw_dev = swapdev;
+		swdevt[1].sw_dev = NODEV;
+	} else {
+		/*
+		 * `root DEV swap DEV': honour rootdev/swapdev.
+		 * rootdev/swapdev/mountroot already properly set.
+		 */
 		return;
 	}
 
-	/* XXX currently there's no way to set RB_DFLTROOT... */
-	if (boothowto & RB_DFLTROOT || bootdv == NULL)
-		return;
-
+	if (bootdv == NULL)
+		panic("boot device not known");
 	switch (bootdv->dv_class) {
-
 #if defined(NFSCLIENT)
 	case DV_IFNET:
 		mountroot = nfs_mountroot;
+		nfsbootdevname = bootdv->dv_xname;
 		return;
 #endif
-
-#if defined(FFS) || defined(LFS)
+#if defined(FFS)
 	case DV_DISK:
-		majdev = findblkmajor((struct dkdevice *)bootdv);
-		if (majdev < 0)
-			return;
-		part = 0;
-		mindev = (bootdv->dv_unit << PARTITIONSHIFT) + part;
+		mountroot = ffs_mountroot;
+		majdev = major(rootdev);
+		mindev = minor(rootdev);
+		printf("root on %s%c\n", bootdv->dv_xname,
+		    (mindev & PARTITIONMASK) + 'a');
 		break;
 #endif
-
 	default:
 		printf("can't figure root, hope your kernel is right\n");
 		return;
 	}
 
 	/*
-	 * Form a new rootdev
-	 */
-	nrootdev = makedev(majdev, mindev);
-	/*
-	 * If the original rootdev is the same as the one
-	 * just calculated, don't need to adjust the swap configuration.
+	 * XXX: What is this doing?
 	 */
-	if (rootdev == nrootdev)
-		return;
-
-	rootdev = nrootdev;
-	printf("Changing root device to %s%c\n", bootdv->dv_xname, part + 'a');
-
-#ifdef DOSWAP
 	mindev &= ~PARTITIONMASK;
 	temp = NODEV;
 	for (swp = swdevt; swp->sw_dev != NODEV; swp++) {
@@ -1247,7 +1323,6 @@
 	 */
 	if (temp == dumpdev)
 		dumpdev = swdevt[0].sw_dev;
-#endif
 }
 
 static int
@@ -1258,6 +1333,12 @@
 	register char *lp;
 	register int c;
 	register int len;
+	int saveecho;
+
+#if defined(SUN4)
+	saveecho = *(oldpvec->echo);
+	*(oldpvec->echo) = 0;
+#endif
 
 	lp = cp;
 	len = 0;
@@ -1268,6 +1349,9 @@
 		case '\r':
 			printf("\n");
 			*lp++ = '\0';
+#if defined(SUN4)
+			*(oldpvec->echo) = saveecho;
+#endif
 			return (len);
 		case '\b':
 		case '\177':
@@ -1275,7 +1359,7 @@
 			if (len) {
 				--len;
 				--lp;
-				printf(" \b ");
+				printf("\b \b");
 			}
 			continue;
 		case '@':
--- a/sys/arch/sparc/sparc/swapgeneric.c	Thu Feb 16 20:39:17 1995 +0000
+++ b/sys/arch/sparc/sparc/swapgeneric.c	Thu Feb 16 21:42:50 1995 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: swapgeneric.c,v 1.6 1994/11/20 20:54:39 deraadt Exp $ */
+/*	$NetBSD: swapgeneric.c,v 1.7 1995/02/16 21:42:52 pk Exp $ */
 
 /*-
  * Copyright (c) 1994
@@ -42,8 +42,7 @@
 #include <sys/param.h>
 #include <sys/conf.h>
 
-extern int ffs_mountroot();
-int (*mountroot)() = ffs_mountroot;
+int (*mountroot)() = NULL;	/* tells autoconf.c that we are "generic" */
 
 dev_t	rootdev = NODEV;
 dev_t	dumpdev = NODEV;
--- a/sys/nfs/nfs_boot.c	Thu Feb 16 20:39:17 1995 +0000
+++ b/sys/nfs/nfs_boot.c	Thu Feb 16 21:42:50 1995 +0000
@@ -1,4 +1,4 @@
-/*    $NetBSD: nfs_boot.c,v 1.12 1994/10/29 06:38:11 cgd Exp $ */
+/*    $NetBSD: nfs_boot.c,v 1.13 1995/02/16 21:43:15 pk Exp $ */
 
 /*
  * Copyright (c) 1994 Adam Glass, Gordon Ross
@@ -97,6 +97,8 @@
 static void get_path_and_handle __P((struct sockaddr_in *bpsin,
 	char *key, struct nfs_dlmount *ndmntp));
 
+char	*nfsbootdevname;
+
 /*
  * Called with an empty nfs_diskless struct to be filled in.
  */
@@ -134,11 +136,14 @@
 
 	/*
 	 * Find a network interface.
-	 * XXX - This should use the specified boot device.
 	 */
-	for (ifp = ifnet; ifp; ifp = ifp->if_next)
-		if ((ifp->if_flags & (IFF_LOOPBACK|IFF_POINTOPOINT)) == 0)
-			break;
+	if (nfsbootdevname)
+		ifp = ifunit(nfsbootdevname);
+	else
+		for (ifp = ifnet; ifp; ifp = ifp->if_next)
+			if ((ifp->if_flags &
+			     (IFF_LOOPBACK|IFF_POINTOPOINT)) == 0)
+				break;
 	if (ifp == NULL)
 		panic("nfs_boot: no suitable interface");
 	sprintf(ireq.ifr_name, "%s%d", ifp->if_name, ifp->if_unit);