diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2007-05-04 03:44:46 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2007-05-04 03:44:46 +0000 |
commit | ec952e9183677d6369513031c05b09bd06afbea5 (patch) | |
tree | c876489f480abe0543e72709f1f25e73f920e72a /sys/arch/zaurus | |
parent | af9c38d3cda06154a0cbd5dbfa54d94871c5bd39 (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/zaurus')
-rw-r--r-- | sys/arch/zaurus/conf/GENERIC | 6 | ||||
-rw-r--r-- | sys/arch/zaurus/zaurus/autoconf.c | 372 |
2 files changed, 52 insertions, 326 deletions
diff --git a/sys/arch/zaurus/conf/GENERIC b/sys/arch/zaurus/conf/GENERIC index 835e7c120a9..891edae7496 100644 --- a/sys/arch/zaurus/conf/GENERIC +++ b/sys/arch/zaurus/conf/GENERIC @@ -1,4 +1,4 @@ -# $OpenBSD: GENERIC,v 1.62 2007/03/18 20:53:10 uwe Exp $ +# $OpenBSD: GENERIC,v 1.63 2007/05/04 03:44:44 deraadt Exp $ # # For further information on compiling OpenBSD kernels, see the config(8) # man page. @@ -35,8 +35,8 @@ option WSDISPLAY_COMPAT_PCVT # emulate some ioctls; needed for X11 option USBVERBOSE -#config bsd swap generic -config bsd root on wd0a +config bsd swap generic +#config bsd root on wd0a # The main bus device mainbus0 at root diff --git a/sys/arch/zaurus/zaurus/autoconf.c b/sys/arch/zaurus/zaurus/autoconf.c index 5533bbf6292..d41e95edcf8 100644 --- a/sys/arch/zaurus/zaurus/autoconf.c +++ b/sys/arch/zaurus/zaurus/autoconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: autoconf.c,v 1.7 2007/03/26 20:18:10 deraadt Exp $ */ +/* $OpenBSD: autoconf.c,v 1.8 2007/05/04 03:44:44 deraadt Exp $ */ /* $NetBSD: autoconf.c,v 1.2 2001/09/05 16:17:36 matt Exp $ */ /* @@ -50,125 +50,18 @@ #include <sys/kernel.h> #include <sys/timeout.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; -struct genericconf { - char *gc_name; - dev_t gc_major; -} genericconf[] = { - { "wd", 16 }, - { "sd", 24 }, - { "cd", 26 }, - { "rd", 18 }, - { "raid", 71 }, - { 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:"); - 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 @@ -179,7 +72,9 @@ void diskconf() { extern struct timeout scoop_checkdisk; + dev_t tmpdev; +#if 0 /* * Configure root, swap, and dump area. This is * currently done by running the same checksum @@ -187,11 +82,22 @@ diskconf() * /boot. Then we basically fixup the *dev vars * from the info we gleaned from this. */ -#if 0 dkcsumattach(); - #endif - rootconf(); + + /* + * XXX + * zaurus bootblocks currently pass in "bsd" instead of + * "device:bsd", or any such thing, making this a real pain. + */ + if (bootdv == NULL) + bootdv = parsedisk("wd0a", strlen("wd0a"), 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 @@ -232,216 +138,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) { - bootdv = parsedisk(boot_file, strlen(boot_file), 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; - } - } - 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 */ |