summaryrefslogtreecommitdiff
path: root/sys/arch/armish
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/armish
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/armish')
-rw-r--r--sys/arch/armish/armish/autoconf.c420
1 files changed, 55 insertions, 365 deletions
diff --git a/sys/arch/armish/armish/autoconf.c b/sys/arch/armish/armish/autoconf.c
index 28c77062a26..7cf951d39b1 100644
--- a/sys/arch/armish/armish/autoconf.c
+++ b/sys/arch/armish/armish/autoconf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: autoconf.c,v 1.4 2006/07/30 23:16:52 deraadt Exp $ */
+/* $OpenBSD: autoconf.c,v 1.5 2007/05/04 03:44:44 deraadt Exp $ */
/* $NetBSD: autoconf.c,v 1.2 2001/09/05 16:17:36 matt Exp $ */
/*
@@ -49,155 +49,19 @@
#include <sys/conf.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
+
+#include <uvm/uvm_extern.h>
+
#include <machine/bootconfig.h>
#include <machine/intr.h>
-
#include <dev/cons.h>
-
struct device *booted_device;
int booted_partition;
-
struct device *bootdv = NULL;
-
-int findblkmajor(struct device *dv);
-char *findblkname(int maj);
-
-void rootconf(void);
-void diskconf(void);
-
-static struct device * getdisk(char *str, int len, int defpart, dev_t *devp);
-struct device *parsedisk(char *, int, int, dev_t *);
extern char *boot_file;
-#include "wd.h"
-#if NWD > 0
-extern struct cfdriver wd_cd;
-#endif
-#include "sd.h"
-#if NSD > 0
-extern struct cfdriver sd_cd;
-#endif
-#include "cd.h"
-#if NCD > 0
-extern struct cfdriver cd_cd;
-#endif
-#if NRD > 0
-extern struct cfdriver rd_cd;
-#endif
-#include "raid.h"
-#if NRAID > 0
-extern struct cfdriver raid_cd;
-#endif
-
-struct genericconf {
- char *gc_name;
- dev_t gc_major;
-} genericconf[] = {
-#if NWD > 0
- { "wd", 16 },
-#endif
-#if NSD > 0
- { "sd", 24 },
-#endif
-#if NCD > 0
- { "cd", 26 },
-#endif
-#if NRD > 0
- { "rd", 18 },
-#endif
-#if NRAID > 0
- { "raid", 71 },
-#endif
- { 0 }
-};
-
-int
-findblkmajor(dv)
- struct device *dv;
-{
- char *name = dv->dv_xname;
- int i;
-
- for (i = 0; i < sizeof(genericconf)/sizeof(genericconf[0]); ++i)
- if (strncmp(name, genericconf[i].gc_name,
- strlen(genericconf[i].gc_name)) == 0)
- return (genericconf[i].gc_major);
- return (-1);
-}
-
-char *
-findblkname(maj)
- int maj;
-{
- int i;
-
- for (i = 0; i < sizeof(genericconf)/sizeof(genericconf[0]); ++i)
- if (maj == genericconf[i].gc_major)
- return (genericconf[i].gc_name);
- return (NULL);
-}
-
-static struct device *
-getdisk(char *str, int len, int defpart, dev_t *devp)
-{
- struct device *dv;
-
- if ((dv = parsedisk(str, len, defpart, devp)) == NULL) {
- printf("use one of: reboot");
- for (dv = alldevs.tqh_first; dv != NULL;
- dv = dv->dv_list.tqe_next) {
- 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(char *str, int len, int defpart, dev_t *devp)
-{
- struct device *dv;
- char *cp, c;
- int majdev, 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;
-
- for (dv = alldevs.tqh_first; dv != NULL; dv = dv->dv_list.tqe_next) {
- if (dv->dv_class == DV_DISK &&
- strcmp(str, dv->dv_xname) == 0) {
- majdev = findblkmajor(dv);
- if (majdev < 0)
- panic("parsedisk");
- *devp = MAKEDISKDEV(majdev, dv->dv_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);
-}
-
+void diskconf(void);
/*
* Now that we are fully operational, we can checksum the
@@ -207,6 +71,9 @@ parsedisk(char *str, int len, int defpart, dev_t *devp)
void
diskconf()
{
+ dev_t tmpdev;
+
+#if 0
/*
* Configure root, swap, and dump area. This is
* currently done by running the same checksum
@@ -214,11 +81,27 @@ diskconf()
* /boot. Then we basically fixup the *dev vars
* from the info we gleaned from this.
*/
-#if 0
dkcsumattach();
-
#endif
- rootconf();
+
+ /* Lookup boot device from boot if not set by configuration */
+ if (bootdv == NULL) {
+ int len;
+ char *p;
+
+ /* boot_file is of the form wd0a:/bsd, we want 'wd0a' */
+ if ((p = strchr(boot_file, ':')) != NULL)
+ len = p - boot_file;
+ else
+ len = strlen(boot_file);
+
+ bootdv = parsedisk(boot_file, len, 0, &tmpdev);
+ }
+ if (bootdv == NULL)
+ printf("boot device: lookup '%s' failed.\n", boot_file);
+ else
+ printf("boot device: %s\n", bootdv->dv_xname);
+ setroot(bootdv, 0, RB_USERREQ);
#if 0
dumpconf();
#endif
@@ -257,229 +140,36 @@ cpu_configure(void)
}
-/*
- * 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.
- */
-void
-rootconf()
-{
- int majdev, mindev, unit, part, len;
- dev_t temp;
- struct swdevt *swp;
- struct device *dv;
- dev_t nrootdev, nswapdev = NODEV;
- char buf[128];
- int s;
-
-#if defined(NFSCLIENT)
- extern char *nfsbootdevname;
-#endif
-
- if (boothowto & RB_DFLTROOT)
- return; /* Boot compiled in */
-
- /*
- * (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("rootconf: device name too long");
-
- bootdv = getdisk(buf, len, part, &rootdev);
- }
-
- /* Lookup boot device from boot if not set by configuration */
- if (bootdv == NULL) {
- int len;
- char *p;
-
- /* boot_file is of the form wd0a:/bsd, we want 'wd0a' */
- if ((p = strchr(boot_file, ':')) != NULL)
- len = p - boot_file;
- else
- len = strlen(boot_file);
-
- bootdv = parsedisk(boot_file, len, 0, &temp);
- }
- if (bootdv == NULL) {
- printf("boot device: lookup '%s' failed.\n", boot_file);
- boothowto |= RB_ASKNAME; /* Don't Panic :-) */
- /* boothowto |= RB_SINGLE; */
- } else
- printf("boot device: %s.\n", bootdv->dv_xname);
-
- if (boothowto & RB_ASKNAME) {
- for (;;) {
- printf("root device ");
- if (bootdv != NULL)
- printf("(default %s%c)",
- bootdv->dv_xname,
- bootdv->dv_class == DV_DISK
- ? 'a' : ' ');
- printf(": ");
- s = splhigh();
- cnpollc(1);
- len = getsn(buf, sizeof(buf));
-
- cnpollc(0);
- splx(s);
- if (len == 0 && bootdv != NULL) {
- strlcpy(buf, bootdv->dv_xname, sizeof buf);
- len = strlen(buf);
- }
- if (len > 0 && buf[len - 1] == '*') {
- buf[--len] = '\0';
- dv = getdisk(buf, len, 1, &nrootdev);
- if (dv != NULL) {
- bootdv = dv;
- nswapdev = nrootdev;
- goto gotswap;
- }
- }
-
- if ((len == 6) && strncmp(buf, "reboot", 6) == 0)
- boot(RB_USERREQ);
-
- 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 ");
- if (bootdv != NULL)
- printf("(default %s%c)",
- bootdv->dv_xname,
- bootdv->dv_class == DV_DISK?'b':' ');
- printf(": ");
- s = splhigh();
- cnpollc(1);
- len = getsn(buf, sizeof(buf));
- cnpollc(0);
- splx(s);
- 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.
- */
- if (bootdv == NULL)
- panic("boot device not known");
-
- majdev = findblkmajor(bootdv);
-
- if (majdev >= 0) {
- /*
- * Root and Swap are on disk.
- * Boot is always from partition 0.
- */
- rootdev = MAKEDISKDEV(majdev, bootdv->dv_unit, 0);
- nswapdev = MAKEDISKDEV(majdev, bootdv->dv_unit, 1);
- dumpdev = nswapdev;
- } else {
- /*
- * Root and Swap are on net.
- */
- nswapdev = dumpdev = NODEV;
- }
- swdevt[0].sw_dev = nswapdev;
- swdevt[1].sw_dev = NODEV;
-
- } else {
+static struct {
+ char *name;
+ int maj;
+} nam2blk[] = {
+ { "wd", 16 },
+ { "sd", 24 },
+ { "cd", 26 },
+ { "rd", 18 },
+ { "raid", 71 }
+};
- /*
- * `root DEV swap DEV': honour rootdev/swdevt.
- * rootdev/swdevt/mountroot already properly set.
- */
- return;
- }
+int
+findblkmajor(struct device *dv)
+{
+ char *name = dv->dv_xname;
+ int i;
- 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);
- mindev = minor(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;
- }
+ 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);
+}
- /*
- * XXX: What is this doing?
- */
- 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)
- return;
+char *
+findblkname(int maj)
+{
+ int i;
- /*
- * 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;
+ for (i = 0; i < sizeof(nam2blk)/sizeof(nam2blk[0]); i++)
+ if (nam2blk[i].maj == maj)
+ return (nam2blk[i].name);
+ return (NULL);
}
-/* End of autoconf.c */