summaryrefslogtreecommitdiff
path: root/sys/arch/sparc64
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2007-05-04 03:44:46 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2007-05-04 03:44:46 +0000
commitec952e9183677d6369513031c05b09bd06afbea5 (patch)
treec876489f480abe0543e72709f1f25e73f920e72a /sys/arch/sparc64
parentaf9c38d3cda06154a0cbd5dbfa54d94871c5bd39 (diff)
setroot() was a ugly mix of MI and MD code, with different bugs on different
machines. Instead -- build one solid clean MI version, and thenchange all the architectures to use it. ok various people, tested on almost all cases. (it is a 10094 line diff..)
Diffstat (limited to 'sys/arch/sparc64')
-rw-r--r--sys/arch/sparc64/include/autoconf.h5
-rw-r--r--sys/arch/sparc64/sparc64/autoconf.c418
2 files changed, 41 insertions, 382 deletions
diff --git a/sys/arch/sparc64/include/autoconf.h b/sys/arch/sparc64/include/autoconf.h
index 834bee8b76f..0c5d2e0e7fe 100644
--- a/sys/arch/sparc64/include/autoconf.h
+++ b/sys/arch/sparc64/include/autoconf.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: autoconf.h,v 1.13 2007/04/07 14:20:10 kettenis Exp $ */
+/* $OpenBSD: autoconf.h,v 1.14 2007/05/04 03:44:44 deraadt Exp $ */
/* $NetBSD: autoconf.h,v 1.10 2001/07/24 19:32:11 eeh Exp $ */
/*-
@@ -152,9 +152,6 @@ struct bootpath {
};
struct bootpath *bootpath_store(int, struct bootpath *);
-/* Parse a disk string into a dev_t, return device struct pointer */
-struct device *parsedisk(char *, int, int, dev_t *);
-
/* Establish a mountroot_hook, for benefit of floppy drive, mostly. */
void mountroot_hook_establish(void (*)(struct device *), struct device *);
diff --git a/sys/arch/sparc64/sparc64/autoconf.c b/sys/arch/sparc64/sparc64/autoconf.c
index 6473d310517..56b3b02322a 100644
--- a/sys/arch/sparc64/sparc64/autoconf.c
+++ b/sys/arch/sparc64/sparc64/autoconf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: autoconf.c,v 1.63 2007/04/30 18:37:00 deraadt Exp $ */
+/* $OpenBSD: autoconf.c,v 1.64 2007/05/04 03:44:44 deraadt Exp $ */
/* $NetBSD: autoconf.c,v 1.51 2001/07/24 19:32:11 eeh Exp $ */
/*
@@ -85,7 +85,6 @@
#include <ddb/db_extern.h>
#endif
-
int printspl = 0;
/*
@@ -112,12 +111,7 @@ static int mbprint(void *, const char *);
void sync_crash(void);
int mainbus_match(struct device *, void *, void *);
static void mainbus_attach(struct device *, struct device *, void *);
-static int getstr(char *, int);
-void setroot(void);
void diskconf(void);
-static struct device *getdisk(char *, int, int, dev_t *);
-int findblkmajor(struct device *);
-char *findblkname(int);
struct device *booted_device;
struct bootpath bootpath[8];
@@ -148,9 +142,6 @@ struct intrmap intrmap[] = {
{ NULL, 0 }
};
-#ifdef RAMDISK_HOOKS
-static struct device fakerdrootdev = { DV_DISK, {}, NULL, 0, "rd0", NULL };
-#endif
#ifdef DEBUG
#define ACDB_BOOTDEV 0x1
@@ -345,7 +336,6 @@ bootpath_build()
bp->name[0] = 0;
bootpath_nodes(bootpath, nbootpath);
- bootpath_print(bootpath);
/* Setup pointer to boot flags */
OF_getprop(chosen, "bootargs", buf, sizeof(buf));
@@ -514,378 +504,16 @@ cpu_configure()
void
diskconf(void)
{
- setroot();
- dumpconf();
-}
-
-void
-setroot()
-{
- struct swdevt *swp;
- struct device *dv;
- int len, majdev, unit, part;
- dev_t nrootdev, nswapdev = NODEV;
- char buf[128];
- dev_t temp;
- struct device *bootdv;
struct bootpath *bp;
-#if defined(NFSCLIENT)
- extern char *nfsbootdevname;
-#endif
+ struct device *bootdv;
+
+ bootpath_print(bootpath);
bp = nbootpath == 0 ? NULL : &bootpath[nbootpath-1];
-#ifdef RAMDISK_HOOKS
- bootdv = &fakerdrootdev;
-#else
bootdv = (bp == NULL) ? NULL : bp->dev;
-#endif
-
- /*
- * (raid) device auto-configuration could have returned
- * the root device's id in rootdev. Check this case.
- */
- if (rootdev != NODEV) {
- majdev = major(rootdev);
- unit = DISKUNIT(rootdev);
- part = DISKPART(rootdev);
-
- len = snprintf(buf, sizeof buf, "%s%d", findblkname(majdev),
- unit);
- if (len == -1 || len >= sizeof(buf))
- panic("setroot: device name too long");
-
- bootdv = getdisk(buf, len, part, &rootdev);
- }
-
- /*
- * If `swap generic' and we couldn't determine boot device,
- * ask the user.
- */
- if (mountroot == NULL && bootdv == NULL)
- boothowto |= RB_ASKNAME;
-
- if (boothowto & RB_ASKNAME) {
- for (;;) {
- printf("root device");
- if (bootdv != NULL)
- printf(" (default %s%c)",
- bootdv->dv_xname,
- bootdv->dv_class == DV_DISK
- ? bp->val[2]+'a' : ' ');
- printf(": ");
- len = getstr(buf, sizeof(buf));
- if (len == 0 && bootdv != NULL) {
- strlcpy(buf, bootdv->dv_xname, sizeof buf);
- len = strlen(buf);
- }
- if (len == 4 && strncmp(buf, "exit", 4) == 0)
- boot(RB_USERREQ | RB_HALT);
- if (len > 0 && buf[len - 1] == '*') {
- buf[--len] = '\0';
- dv = getdisk(buf, len, 1, &nrootdev);
- if (dv != NULL) {
- bootdv = dv;
- nswapdev = nrootdev;
- goto gotswap;
- }
- }
- dv = getdisk(buf, len, bp?bp->val[2]: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 ");
- if (bootdv != NULL)
- printf("(default %s%c)",
- bootdv->dv_xname,
- bootdv->dv_class == DV_DISK?'b':' ');
- printf(": ");
- len = getstr(buf, sizeof(buf));
- if (len == 4 && strncmp(buf, "exit", 4) == 0)
- boot(RB_USERREQ | RB_HALT);
- if (len == 0 && bootdv != NULL) {
- switch (bootdv->dv_class) {
- case DV_IFNET:
- nswapdev = NODEV;
- break;
- case DV_DISK:
- nswapdev = MAKEDISKDEV(major(nrootdev),
- DISKUNIT(nrootdev), 1);
- break;
- case DV_TAPE:
- case DV_TTY:
- case DV_DULL:
- case DV_CPU:
- break;
- }
- break;
- }
- dv = getdisk(buf, len, 1, &nswapdev);
- if (dv) {
- if (dv->dv_class == DV_IFNET)
- nswapdev = NODEV;
- break;
- }
- }
-gotswap:
- rootdev = nrootdev;
- dumpdev = 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.
- * val[2] of the boot device is the partition number.
- * Assume swap is on partition b.
- */
- part = bp->val[2];
- unit = bootdv->dv_unit;
- rootdev = MAKEDISKDEV(majdev, unit, part);
- nswapdev = dumpdev = MAKEDISKDEV(major(rootdev),
- DISKUNIT(rootdev), 1);
- } else {
- /*
- * Root and swap are on a net.
- */
- nswapdev = dumpdev = NODEV;
- }
- swdevt[0].sw_dev = nswapdev;
- /* swdevt[1].sw_dev = NODEV; */
-
- } else {
-
- /*
- * `root DEV swap DEV': honour rootdev/swdevt.
- * rootdev/swdevt/mountroot already properly set.
- */
- if (bootdv->dv_class == DV_DISK)
- printf("root on %s%c\n", bootdv->dv_xname,
- part + 'a');
- majdev = major(rootdev);
- unit = DISKUNIT(rootdev);
- part = DISKPART(rootdev);
- return;
- }
-
- switch (bootdv->dv_class) {
-#if defined(NFSCLIENT)
- case DV_IFNET:
- mountroot = nfs_mountroot;
- nfsbootdevname = bootdv->dv_xname;
- return;
-#endif
- case DV_DISK:
- mountroot = dk_mountroot;
- majdev = major(rootdev);
- unit = DISKUNIT(rootdev);
- part = DISKPART(rootdev);
- printf("root on %s%c\n", bootdv->dv_xname,
- part + 'a');
- break;
- default:
- printf("can't figure root, hope your kernel is right\n");
- return;
- }
-
- /*
- * Make the swap partition on the root drive the primary swap.
- */
- temp = NODEV;
- for (swp = swdevt; swp->sw_dev != NODEV; swp++) {
- if (majdev == major(swp->sw_dev) &&
- unit == DISKUNIT(swp->sw_dev)) {
- temp = swdevt[0].sw_dev;
- swdevt[0].sw_dev = swp->sw_dev;
- swp->sw_dev = temp;
- break;
- }
- }
- if (swp->sw_dev != NODEV) {
- /*
- * If dumpdev was the same as the old primary swap device,
- * move it to the new primary swap device.
- */
- if (temp == dumpdev)
- dumpdev = swdevt[0].sw_dev;
- }
-}
-
-struct nam2blk {
- char *name;
- int maj;
-} nam2blk[] = {
- { "sd", 7 },
- { "rd", 5 },
- { "wd", 12 },
- { "cd", 18 },
- { "raid", 25 },
-};
-
-int
-findblkmajor(dv)
- struct device *dv;
-{
- char *name = dv->dv_xname;
- int i;
-
- for (i = 0; i < sizeof(nam2blk)/sizeof(nam2blk[0]); ++i)
- if (strncmp(name, nam2blk[i].name, strlen(nam2blk[i].name)) == 0)
- return (nam2blk[i].maj);
- return (-1);
-}
-
-char *
-findblkname(maj)
- int maj;
-{
- int i;
-
- for (i = 0; i < sizeof(nam2blk)/sizeof(nam2blk[0]); ++i)
- if (nam2blk[i].maj == maj)
- return (nam2blk[i].name);
- return (NULL);
-}
-
-static struct device *
-getdisk(str, len, defpart, devp)
- char *str;
- int len, defpart;
- dev_t *devp;
-{
- struct device *dv;
-
- if ((dv = parsedisk(str, len, defpart, devp)) == NULL) {
- printf("use one of: exit");
-#ifdef RAMDISK_HOOKS
- printf(" %s[a-p]", fakerdrootdev.dv_xname);
-#endif
- TAILQ_FOREACH(dv, &alldevs, dv_list) {
- if (dv->dv_class == DV_DISK)
- printf(" %s[a-p]", dv->dv_xname);
-#ifdef NFSCLIENT
- if (dv->dv_class == DV_IFNET)
- printf(" %s", dv->dv_xname);
-#endif
- }
- printf("\n");
- }
- return (dv);
-}
-
-struct device *
-parsedisk(str, len, defpart, devp)
- char *str;
- int len, defpart;
- dev_t *devp;
-{
- struct device *dv;
- char *cp, c;
- int majdev, unit, part;
-
- if (len == 0)
- return (NULL);
- cp = str + len - 1;
- c = *cp;
- if (c >= 'a' && (c - 'a') < MAXPARTITIONS) {
- part = c - 'a';
- *cp = '\0';
- } else
- part = defpart;
-
-#ifdef RAMDISK_HOOKS
- if (strcmp(str, fakerdrootdev.dv_xname) == 0) {
- dv = &fakerdrootdev;
- goto gotdisk;
- }
-#endif
-
- TAILQ_FOREACH(dv, &alldevs, dv_list) {
- if (dv->dv_class == DV_DISK &&
- strcmp(str, dv->dv_xname) == 0) {
-#ifdef RAMDISK_HOOKS
-gotdisk:
-#endif
- majdev = findblkmajor(dv);
- unit = dv->dv_unit;
- if (majdev < 0)
- panic("parsedisk");
- *devp = MAKEDISKDEV(majdev, unit, part);
- break;
- }
-#ifdef NFSCLIENT
- if (dv->dv_class == DV_IFNET &&
- strcmp(str, dv->dv_xname) == 0) {
- *devp = NODEV;
- break;
- }
-#endif
- }
-
- *cp = c;
- return (dv);
-}
-
-static int
-getstr(cp, size)
- char *cp;
- int size;
-{
- char *lp;
- int c;
- int len;
-
- lp = cp;
- len = 0;
- for (;;) {
- c = cngetc();
- switch (c) {
- case '\n':
- case '\r':
- printf("\n");
- *lp++ = '\0';
- return (len);
- case '\b':
- case '\177':
- case '#':
- if (len) {
- --len;
- --lp;
- printf("\b \b");
- }
- continue;
- case '@':
- case 'u'&037:
- len = 0;
- lp = cp;
- printf("\n");
- continue;
- default:
- if (len + 1 >= size || c < ' ') {
- printf("\007");
- continue;
- }
- printf("%c", c);
- ++len;
- *lp++ = c;
- }
- }
+ setroot(bootdv, bp->val[2], RB_USERREQ | RB_HALT);
+ dumpconf();
}
/*
@@ -1526,3 +1154,37 @@ nail_bootdev(dev, bp)
*/
bootpath_store(1, NULL);
}
+
+struct nam2blk {
+ char *name;
+ int maj;
+} nam2blk[] = {
+ { "sd", 7 },
+ { "rd", 5 },
+ { "wd", 12 },
+ { "cd", 18 },
+ { "raid", 25 },
+};
+
+int
+findblkmajor(struct device *dv)
+{
+ char *name = dv->dv_xname;
+ int i;
+
+ for (i = 0; i < sizeof(nam2blk)/sizeof(nam2blk[0]); i++)
+ if (!strncmp(name, nam2blk[i].name, strlen(nam2blk[i].name)))
+ return (nam2blk[i].maj);
+ return (-1);
+}
+
+char *
+findblkname(int maj)
+{
+ int i;
+
+ for (i = 0; i < sizeof(nam2blk)/sizeof(nam2blk[0]); i++)
+ if (nam2blk[i].maj == maj)
+ return (nam2blk[i].name);
+ return (NULL);
+}