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 | |
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')
27 files changed, 1087 insertions, 7637 deletions
diff --git a/sys/arch/alpha/alpha/autoconf.c b/sys/arch/alpha/alpha/autoconf.c index 5ed8cfad53d..0642034ee20 100644 --- a/sys/arch/alpha/alpha/autoconf.c +++ b/sys/arch/alpha/alpha/autoconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: autoconf.c,v 1.28 2007/04/30 17:35:23 deraadt Exp $ */ +/* $OpenBSD: autoconf.c,v 1.29 2007/05/04 03:44:41 deraadt Exp $ */ /* $NetBSD: autoconf.c,v 1.16 1996/11/13 21:13:04 cgd Exp $ */ /* @@ -49,6 +49,8 @@ #include <sys/reboot.h> #include <sys/device.h> +#include <uvm/uvm_extern.h> + #include <machine/autoconf.h> #include <machine/rpb.h> #include <machine/prom.h> @@ -66,15 +68,6 @@ char boot_dev[128]; void parse_prom_bootdev(void); int atoi(char *); -void setroot(void); - -static struct device *parsedisk(char *str, int len, int defpart, - dev_t *devp); -static struct device *getdisk(char *str, int len, int defpart, - dev_t *devp); -int findblkmajor(struct device *dv); -char *findblkname(int); -static int getstr(char *cp, int size); /* * cpu_configure: @@ -83,6 +76,9 @@ static int getstr(char *cp, int size); void cpu_configure() { + struct device *bootdv; + int bootpartition; + parse_prom_bootdev(); softintr_init(); @@ -102,421 +98,12 @@ cpu_configure() if (booted_device == NULL) printf("WARNING: can't figure what device matches \"%s\"\n", boot_dev); - setroot(); - dumpconf(); - cold = 0; -} - -struct nam2blk { - char *name; - int maj; -} nam2blk[] = { -#include "st.h" -#if NST > 0 - { "st", 2 }, -#endif -#include "cd.h" -#if NCD > 0 - { "cd", 3 }, -#endif -#include "fd.h" -#if NFD > 0 - { "fd", 4 }, -#endif -#include "rd.h" -#if NRD > 0 - { "rd", 6 }, -#endif - { "sd", 8 }, - { "wd", 0 }, -#include "raid.h" -#if NRAID > 0 - { "raid", 16 }, -#endif -}; - -#ifdef RAMDISK_HOOKS -static struct device fakerdrootdev = { DV_DISK, {}, NULL, 0, "rd0", NULL }; -#endif - -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 (maj == nam2blk[i].maj) - return (nam2blk[i].name); - return (NULL); -} - -static struct device * -getdisk(str, len, defpart, devp) - char *str; - int len, defpart; - dev_t *devp; -{ - register 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); -} - -static struct device * -parsedisk(str, len, defpart, devp) - char *str; - int len, defpart; - dev_t *devp; -{ - register struct device *dv; - register char *cp, c; - int majdev, part; - - if (len == 0) - return (NULL); - - if (len == 4 && !strcmp(str, "exit")) - boot(RB_USERREQ); - - cp = str + len - 1; - c = *cp; - if (c >= 'a' && c <= ('a' + MAXPARTITIONS - 1)) { - 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); - 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); -} - -/* - * 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() -{ - struct swdevt *swp; - struct device *dv; - int len, majdev, unit, part; - dev_t nrootdev, nswapdev = NODEV; - char buf[128], *rootdevname; - dev_t temp; - struct device *bootdv, *rootdv, *swapdv; - int bootpartition; -#if defined(NFSCLIENT) - extern char *nfsbootdevname; -#endif - -#ifdef RAMDISK_HOOKS - bootdv = &fakerdrootdev; - bootpartition = 0; -#else bootdv = booted_device; bootpartition = booted_partition; -#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 root 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", bootdv->dv_xname); - if (bootdv->dv_class == DV_DISK) - printf("%c", bootpartition + 'a'); - printf(")"); - } - printf(": "); - len = getstr(buf, sizeof(buf)); - if (len == 0 && bootdv != NULL) { - strlcpy(buf, bootdv->dv_xname, sizeof buf); - len = strlen(buf); - } - if (len == 4 && !strcmp(buf, "exit")) - boot(RB_USERREQ); - if (len > 0 && buf[len - 1] == '*') { - buf[--len] = '\0'; - dv = getdisk(buf, len, 1, &nrootdev); - if (dv != NULL) { - rootdv = swapdv = dv; - nswapdev = nrootdev; - goto gotswap; - } - } - dv = getdisk(buf, len, bootpartition, &nrootdev); - if (dv != NULL) { - rootdv = dv; - break; - } - } - - /* - * because swap must be on same device type as root, for - * network devices this is easy. - */ - if (rootdv->dv_class == DV_IFNET) { - swapdv = NULL; - goto gotswap; - } - for (;;) { - printf("swap device"); - printf(" (default %s", rootdv->dv_xname); - if (rootdv->dv_class == DV_DISK) - printf("b"); - printf(")"); - printf(": "); - len = getstr(buf, sizeof(buf)); - if (len == 0) { - switch (rootdv->dv_class) { - case DV_IFNET: - nswapdev = NODEV; - break; - case DV_DISK: - nswapdev = MAKEDISKDEV(major(nrootdev), - DISKUNIT(nrootdev), 1); - break; - default: - break; - } - swapdv = rootdv; - break; - } - if (len == 4 && !strcmp(buf, "exit")) - boot(RB_USERREQ); - dv = getdisk(buf, len, 1, &nswapdev); - if (dv) { - if (dv->dv_class == DV_IFNET) - nswapdev = NODEV; - swapdv = dv; - break; - } - } -gotswap: - rootdev = nrootdev; - dumpdev = nswapdev; - swdevt[0].sw_dev = nswapdev; - swdevt[1].sw_dev = NODEV; - } else if (mountroot == NULL) { - - /* - * "swap generic" - */ - majdev = findblkmajor(bootdv); - if (majdev >= 0) { - /* - * Root and swap are on a disk. - */ - rootdv = swapdv = bootdv; - rootdev = MAKEDISKDEV(majdev, bootdv->dv_unit, - bootpartition); - nswapdev = dumpdev = - MAKEDISKDEV(majdev, bootdv->dv_unit, 1); - } else { - /* - * Root and swap are on a net. - */ - rootdv = swapdv = bootdv; - nswapdev = dumpdev = NODEV; - } - swdevt[0].sw_dev = nswapdev; - swdevt[1].sw_dev = NODEV; - } else { - /* - * `root DEV swap DEV': honor rootdev/swdevt. - * rootdev/swdevt/mountroot already properly set. - */ - - rootdevname = findblkname(major(rootdev)); - if (rootdevname == NULL) { - /* Root on NFS or unknown device. */ - strlcpy(root_device, "??", sizeof root_device); - } else { - /* Root on known block device. */ - snprintf(root_device, sizeof root_device, - "%s%d%c", rootdevname, - DISKUNIT(rootdev), DISKPART(rootdev) + 'a'); - } - - return; - } - - switch (rootdv->dv_class) { -#if defined(NFSCLIENT) - case DV_IFNET: - strlcpy(root_device, "??", sizeof root_device); - mountroot = nfs_mountroot; - nfsbootdevname = rootdv->dv_xname; - return; -#endif - case DV_DISK: - mountroot = dk_mountroot; - snprintf(root_device, sizeof root_device, - "%s%c", rootdv->dv_xname, - DISKPART(rootdev) + 'a'); - printf("root on %s", root_device); - if (nswapdev != NODEV) - printf(" swap on %s%c", swapdv->dv_xname, - DISKPART(nswapdev) + 'a'); - printf("\n"); - 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 (major(rootdev) == major(swp->sw_dev) && - DISKUNIT(rootdev) == 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; - - /* - * 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; -} - -static int -getstr(cp, size) - register char *cp; - register int size; -{ - register char *lp; - register int c; - register 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, bootpartition, RB_USERREQ); + dumpconf(); + cold = 0; } void @@ -618,3 +205,39 @@ device_register(dev, aux) if (platform.device_register) (*platform.device_register)(dev, aux); } + +static struct { + char *name; + int maj; +} nam2blk[] = { + { "st", 2 }, + { "cd", 3 }, + { "fd", 4 }, + { "rd", 6 }, + { "sd", 8 }, + { "wd", 0 }, + { "raid", 16 } +}; + +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); +} diff --git a/sys/arch/amd64/amd64/autoconf.c b/sys/arch/amd64/amd64/autoconf.c index 3529e012656..4ac99b91f70 100644 --- a/sys/arch/amd64/amd64/autoconf.c +++ b/sys/arch/amd64/amd64/autoconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: autoconf.c,v 1.18 2007/05/01 17:41:36 deraadt Exp $ */ +/* $OpenBSD: autoconf.c,v 1.19 2007/05/04 03:44:44 deraadt Exp $ */ /* $NetBSD: autoconf.c,v 1.1 2003/04/26 18:39:26 fvdl Exp $ */ /*- @@ -81,12 +81,7 @@ #include <machine/i82489var.h> #endif -void setroot(void); -void rootconf(void); void diskconf(void); -int findblkmajor(struct device *); -char *findblkname(int); -struct device * parsedisk(char *, int, int, dev_t *); #if 0 #include "bios32.h" @@ -100,10 +95,6 @@ struct device *booted_device; int booted_partition; extern dev_t bootdev; -#ifdef RAMDISK_HOOKS -static struct device fakerdrootdev = { DV_DISK, {}, NULL, 0, "rd0", NULL }; -#endif - /* * Determine i/o configuration for a machine. */ @@ -139,132 +130,39 @@ cpu_configure(void) md_diskconf = diskconf; } -void -diskconf(void) -{ - /* Checksum disks, same as /boot did, then fixup *dev vars */ - dkcsumattach(); - - rootconf(); - dumpconf(); -} - -struct device * -parsedisk(char *str, int len, int 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); -} - -/* XXX */ -static struct nam2blk { - char *name; - int maj; -} nam2blk[] = { - { "wd", 0 }, /* 0 = wd */ - { "sd", 4 }, /* 2 = sd */ - { "rd", 17 }, /* 17 = rd */ - { "raid", 19 }, /* 19 = raid */ -}; - -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)) == 0) - 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); -} - -/* Code from here to handle "bsd swap generic" */ - -dev_t argdev = NODEV; - /* - * 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. + * Now that we are fully operational, we can checksum the + * disks, and using some heuristics, hopefully are able to + * always determine the correct root disk. */ void -setroot(void) +diskconf(void) { - int majdev, mindev, unit, part, adaptor; - dev_t orootdev; + int majdev, unit, part = 0; + struct device *bootdv = NULL; + dev_t tmpdev; + char buf[128]; #if defined(NFSCLIENT) extern bios_bootmac_t *bios_bootmac; #endif -#ifdef DOSWAP - dev_t temp = 0; - struct swdevt *swp; -#endif + + dkcsumattach(); + + if ((bootdev & B_MAGICMASK) == (u_int)B_DEVMAGIC) { + majdev = B_TYPE(bootdev); + unit = B_UNIT(bootdev); + part = B_PARTITION(bootdev); + snprintf(buf, sizeof buf, "%s%d%c", findblkname(majdev), + unit, part + 'a'); + bootdv = parsedisk(buf, strlen(buf), part, &tmpdev); + } #if defined(NFSCLIENT) if (bios_bootmac) { - extern char *nfsbootdevname; struct ifnet *ifp; - mountroot = nfs_mountroot; - printf("PXE boot MAC address %s, ", ether_sprintf(bios_bootmac->mac)); - for (ifp = TAILQ_FIRST(&ifnet); ifp != NULL; ifp = TAILQ_NEXT(ifp, if_list)) { if ((ifp->if_type == IFT_ETHER || @@ -275,223 +173,49 @@ setroot(void) break; } if (ifp) { - nfsbootdevname = ifp->if_xname; - printf("interface %s\n", nfsbootdevname); + printf("interface %s\n", ifp->if_xname); + mountroot = nfs_mountroot; /* potentially */ + bootdv = parsedisk(ifp->if_xname, strlen(ifp->if_xname), + 0, &tmpdev); + part = 0; } else - printf("no interface selected\n"); - return; + printf("unknown interface\n"); } #endif - if (boothowto & RB_DFLTROOT || - (bootdev & B_MAGICMASK) != (u_long)B_DEVMAGIC) - return; - - majdev = B_TYPE(bootdev); - if (findblkname(majdev) == NULL) - return; - adaptor = B_ADAPTOR(bootdev); - part = B_PARTITION(bootdev); - unit = B_UNIT(bootdev); - mindev = (unit * MAXPARTITIONS) + part; - orootdev = rootdev; - rootdev = makedev(majdev, mindev); - mountroot = dk_mountroot; - - /* - * If the original rootdev is the same as the one - * just calculated, don't need to adjust the swap configuration. - */ - printf("root on %s%d%c\n", findblkname(majdev), unit, part + 'a'); - if (rootdev == orootdev) - return; - -#ifdef DOSWAP - for (swp = swdevt; swp->sw_dev != NODEV; swp++) { - if (majdev == major(swp->sw_dev) && - mindev/MAXPARTITIONS == minor(swp->sw_dev)/MAXPARTITIONS) { - temp = swdevt[0].sw_dev; - swdevt[0].sw_dev = swp->sw_dev; - swp->sw_dev = temp; - break; - } - } - if (swp->sw_dev == NODEV) - return; - - /* - * 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; -#endif -} -#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 -#include "mcd.h" -#if NMCD > 0 -extern struct cfdriver mcd_cd; -#endif -#include "fd.h" -#if NFD > 0 -extern struct cfdriver fd_cd; -#endif -#include "rd.h" -#if NRD > 0 -extern struct cfdriver rd_cd; -#endif -#include "raid.h" -#if NRAID > 0 -extern struct cfdriver raid_cd; -#endif + setroot(bootdv, part, RB_USERREQ); + dumpconf(); +} -struct genericconf { - struct cfdriver *gc_driver; - char *gc_name; - dev_t gc_major; -} genericconf[] = { -#if NWD > 0 - { &wd_cd, "wd", 0 }, -#endif -#if NFD > 0 - { &fd_cd, "fd", 2 }, -#endif -#if NSD > 0 - { &sd_cd, "sd", 4 }, -#endif -#if NCD > 0 - { &cd_cd, "cd", 6 }, -#endif -#if NMCD > 0 - { &mcd_cd, "mcd", 7 }, -#endif -#if NRD > 0 - { &rd_cd, "rd", 17 }, -#endif -#if NRAID > 0 - { &raid_cd, "raid", 19 }, -#endif - { 0 } +static struct { + char *name; + int maj; +} nam2blk[] = { + { "wd", 0 }, + { "sd", 4 }, + { "rd", 17 }, + { "raid", 19 }, }; -void -rootconf(void) +int +findblkmajor(struct device *dv) { - struct genericconf *gc; - int unit, part = 0; -#if defined(NFSCLIENT) - struct ifnet *ifp; -#endif - char name[128]; - char *num; - - if (boothowto & RB_ASKNAME) { - while (1) { - printf("root device? "); - cnpollc(TRUE); - getsn(name, sizeof name); - cnpollc(FALSE); - if (*name == '\0') - break; - if (strcmp(name, "exit") == 0) - boot(RB_USERREQ); - for (gc = genericconf; gc->gc_driver; gc++) - if (gc->gc_driver->cd_ndevs && - strncmp(gc->gc_name, name, - strlen(gc->gc_name)) == 0) - break; - if (gc->gc_driver) { - num = &name[strlen(gc->gc_name)]; - - unit = -2; - do { - if (unit != -2 && *num >= 'a' && - *num <= 'a'+MAXPARTITIONS-1 && - num[1] == '\0') { - part = *num++ - 'a'; - break; - } - if (unit == -2) - unit = 0; - unit = (unit * 10) + *num - '0'; - if (*num < '0' || *num > '9') - unit = -1; - } while (unit != -1 && *++num); - - if (unit < 0) { - printf("%s: not a unit number\n", - &name[strlen(gc->gc_name)]); - } else if (unit >= gc->gc_driver->cd_ndevs || - gc->gc_driver->cd_devs[unit] == NULL) { - printf("%d: no such unit\n", unit); - } else { - rootdev = makedev(gc->gc_major, - unit * MAXPARTITIONS + part); - mountroot = dk_mountroot; - break; - } -#if defined(NFSCLIENT) - } else { - ifp = ifunit(name); - if (ifp && (ifp->if_flags & IFF_BROADCAST)) { - extern char *nfsbootdevname; - - mountroot = nfs_mountroot; - nfsbootdevname = ifp->if_xname; - return; - } -#endif - } - - printf("use one of: exit"); - for (gc = genericconf; gc->gc_driver; gc++) { - for (unit=0; unit < gc->gc_driver->cd_ndevs; unit++) { - if (gc->gc_driver->cd_devs[unit]) - printf(" %s%d[a-%c]", gc->gc_name, - unit, 'a'+MAXPARTITIONS-1); - } - } -#if defined(NFSCLIENT) - for (ifp = TAILQ_FIRST(&ifnet); ifp != NULL; - ifp = TAILQ_NEXT(ifp, if_list)) { - if ((ifp->if_flags & IFF_BROADCAST)) - printf(" %s", ifp->if_xname); - } -#endif - printf("\n"); - } - } + char *name = dv->dv_xname; + int i; - if (mountroot == NULL) { - /* `swap generic' */ - setroot(); -#if defined(NFSCLIENT) - } else if (mountroot == nfs_mountroot) { - ; -#endif - } else { - /* preconfigured on disk */ - int majdev, unit, part; - - majdev = major(rootdev); - if (findblkname(majdev) == NULL) - return; - part = minor(rootdev) % MAXPARTITIONS; - unit = minor(rootdev) / MAXPARTITIONS; - printf("root on %s%d%c\n", findblkname(majdev), unit, part + 'a'); - } - if (mountroot == dk_mountroot) - swdevt[0].sw_dev = argdev = dumpdev = - MAKEDISKDEV(major(rootdev), DISKUNIT(rootdev), 1); + 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); } 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 */ diff --git a/sys/arch/aviion/aviion/autoconf.c b/sys/arch/aviion/aviion/autoconf.c index da6c587f05a..0c2a9d20701 100644 --- a/sys/arch/aviion/aviion/autoconf.c +++ b/sys/arch/aviion/aviion/autoconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: autoconf.c,v 1.1 2006/05/08 16:26:21 miod Exp $ */ +/* $OpenBSD: autoconf.c,v 1.2 2007/05/04 03:44:44 deraadt Exp $ */ /* * Copyright (c) 1998 Steve Murphree, Jr. * Copyright (c) 1996 Nivas Madhur @@ -59,10 +59,6 @@ */ void dumpconf(void); -int findblkmajor(struct device *); -struct device *getdisk(char *, int, int, dev_t *); -struct device *parsedisk(char *, int, int, dev_t *); -void setroot(void); int cold = 1; /* 1 if still booting */ @@ -95,283 +91,13 @@ cpu_configure() set_psr(get_psr() & ~PSR_IND); spl0(); - setroot(); - dumpconf(); - - cold = 0; -} - -struct nam2blk { - char *name; - int maj; -} nam2blk[] = { - { "sd", 4 }, - { "cd", 6 }, - { "rd", 7 }, -}; - -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[0].name)) == 0) - return (nam2blk[i].maj); - return (-1); -} - -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:"); - 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; - - TAILQ_FOREACH(dv, &alldevs, dv_list) { - if (dv->dv_class == DV_DISK && - strcmp(str, dv->dv_xname) == 0) { - 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); -} - -/* - * 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() -{ - struct swdevt *swp; - struct device *dv; - int len, majdev, unit; - dev_t nrootdev, nswapdev = NODEV; - char buf[128]; - dev_t temp; -#if defined(NFSCLIENT) - extern char *nfsbootdevname; -#endif - extern u_int bootpart; - printf("boot device: %s\n", (bootdv) ? bootdv->dv_xname : "<unknown>"); - /* - * If 'swap generic' and we could not determine the 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 ? 'a' : ' '); - printf(": "); - len = getsn(buf, sizeof(buf)); - 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) { - bootdv = dv; - nswapdev = nrootdev; - goto gotswap; - } - } - dv = getdisk(buf, len, 0, &nrootdev); - if (dv) { - 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 = getsn(buf, sizeof(buf)); - 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 a disk. - * val[2] of the boot device is the partition number. - * Assume swap is on partition b. - */ - unit = bootdv->dv_unit; - rootdev = MAKEDISKDEV(majdev, unit, bootpart); - 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. - */ - return; - } - - switch (bootdv->dv_class) { -#if defined(NFSCLIENT) - case DV_IFNET: - mountroot = nfs_mountroot; - nfsbootdevname = bootdv->dv_xname; - return; -#endif -#if defined(FFS) - case DV_DISK: - mountroot = dk_mountroot; - majdev = major(rootdev); - unit = DISKUNIT(rootdev); - printf("root on %s%c\n", bootdv->dv_xname, - DISKPART(rootdev) + 'a'); - break; -#endif - 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) - return; + setroot(bootdv, bootpart, RB_USERREQ); + dumpconf(); - /* - * 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; + cold = 0; } /* @@ -456,3 +182,35 @@ device_register(struct device *dev, void *aux) break; } } + +static struct { + char *name; + int maj; +} nam2blk[] = { + { "sd", 4 }, + { "cd", 6 }, + { "rd", 7 }, +}; + +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); +} diff --git a/sys/arch/cats/cats/autoconf.c b/sys/arch/cats/cats/autoconf.c index 5fdeee95905..908ef9b6ab8 100644 --- a/sys/arch/cats/cats/autoconf.c +++ b/sys/arch/cats/cats/autoconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: autoconf.c,v 1.8 2006/03/18 21:27:21 miod Exp $ */ +/* $OpenBSD: autoconf.c,v 1.9 2007/05/04 03:44:44 deraadt Exp $ */ /* $NetBSD: autoconf.c,v 1.2 2001/09/05 16:17:36 matt Exp $ */ /* @@ -58,118 +58,12 @@ struct device *booted_device; int booted_partition; - -void isa_intr_init(void); - 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; -const struct genericconf { - char *gc_name; - dev_t gc_major; -} genericconf[] = { - { "wd", 16 }, - { "sd", 24 }, - { "cd", 26 }, - { "rd", 18 }, - { "raid", 71 }, - { NULL, 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:"); - 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(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; - - TAILQ_FOREACH(dv, &alldevs, dv_list) { - 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 isa_intr_init(void); +void diskconf(void); /* * Now that we are fully operational, we can checksum the @@ -179,6 +73,7 @@ parsedisk(char *str, int len, int defpart, dev_t *devp) void diskconf() { +#if 0 /* * Configure root, swap, and dump area. This is * currently done by running the same checksum @@ -186,11 +81,11 @@ diskconf() * /boot. Then we basically fixup the *dev vars * from the info we gleaned from this. */ -#if 0 dkcsumattach(); - #endif - rootconf(); + + printf("boot_file: '%s'\n", boot_file); + setroot(bootdv, 0, RB_USERREQ); #if 0 dumpconf(); #endif @@ -230,219 +125,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 - - printf("boot_file: '%s'\n", boot_file); - - 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 */ diff --git a/sys/arch/hp300/hp300/autoconf.c b/sys/arch/hp300/hp300/autoconf.c index 21729c6d812..df4ec06cd4f 100644 --- a/sys/arch/hp300/hp300/autoconf.c +++ b/sys/arch/hp300/hp300/autoconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: autoconf.c,v 1.40 2007/01/07 15:14:32 miod Exp $ */ +/* $OpenBSD: autoconf.c,v 1.41 2007/05/04 03:44:44 deraadt Exp $ */ /* $NetBSD: autoconf.c,v 1.45 1999/04/10 17:31:02 kleink Exp $ */ /* @@ -107,7 +107,7 @@ extern caddr_t internalhpib; extern char *extiobase; /* The boot device. */ -struct device *booted_device; +struct device *bootdv; /* The device we mount as root. */ struct device *root_device; @@ -161,7 +161,6 @@ ddlist_t dev_data_list_hpib; /* hpib controller dev_datas */ ddlist_t dev_data_list_scsi; /* scsi controller dev_datas */ void diskconf(void); -void setroot(void); void findbootdev(void); void findbootdev_slave(ddlist_t *, int, int, int); void setbootdev(void); @@ -169,13 +168,6 @@ void setbootdev(void); static struct dev_data *dev_data_lookup(struct device *); static void dev_data_insert(struct dev_data *, ddlist_t *); -static struct device *parsedisk(char *str, int len, int defpart, - dev_t *devp); -static struct device *getdisk(char *str, int len, int defpart, - dev_t *devp); -static int findblkmajor(struct device *dv); -static char *findblkname(int); -static int getstr(char *cp, int size); static int device_match(const char *, const char *); int mainbusmatch(struct device *, void *, void *); @@ -257,7 +249,7 @@ cpu_configure() printf("Please update your boot program.\n"); } else { findbootdev(); - if (booted_device == NULL) { + if (bootdv == NULL) { printf("WARNING: can't find match for bootdev:\n"); printf( "type = %d, ctlr = %d, slave = %d, punit = %d, part = %d\n", @@ -266,7 +258,7 @@ cpu_configure() B_PARTITION(bootdev)); bootdev = 0; /* invalidate bootdev */ } else { - printf("boot device: %s\n", booted_device->dv_xname); + printf("boot device: %s\n", bootdv->dv_xname); } } @@ -278,8 +270,23 @@ cpu_configure() void diskconf() { + int bootpartition = 0; + + /* + * If bootdev is bogus, ask the user anyhow. + */ + if (bootdev == 0) + boothowto |= RB_ASKNAME; + else + bootpartition = B_PARTITION(bootdev); + + /* + * If we booted from tape, ask the user. + */ + if (bootdv != NULL && bootdv->dv_class == DV_TAPE) + boothowto |= RB_ASKNAME; - setroot(); + setroot(bootdv, bootpartition, RB_USERREQ); dumpconf(); /* @@ -399,402 +406,6 @@ device_register(dev, aux) } } -struct nam2blk { - char *name; - int maj; -} nam2blk[] = { - { "ct", 0 }, - { "hd", 2 }, - { "sd", 4 }, - { "st", 7 }, - { "rd", 8 }, - { "cd", 9 }, -}; - -static int -findblkmajor(dv) - struct device *dv; -{ - char *name = dv->dv_xname; - register int 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); -} - -static char * -findblkname(maj) - int maj; -{ - register int i; - - for (i = 0; i < sizeof(nam2blk) / sizeof(nam2blk[0]); ++i) - if (maj == nam2blk[i].maj) - return (nam2blk[i].name); - return (NULL); -} - -static struct device * -getdisk(str, len, defpart, devp) - char *str; - int len, defpart; - dev_t *devp; -{ - register struct device *dv; - - if ((dv = parsedisk(str, len, defpart, devp)) == NULL) { - printf("use one of:"); - 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(" halt\n"); - } - return (dv); -} - -static struct device * -parsedisk(str, len, defpart, devp) - char *str; - int len, defpart; - dev_t *devp; -{ - register struct device *dv; - register char *cp, c; - int majdev, part; - - if (len == 0) - return (NULL); - - if (len == 4 && !strcmp(str, "halt")) - boot(RB_HALT); - - cp = str + len - 1; - c = *cp; - if (c >= 'a' && c <= ('a' + MAXPARTITIONS - 1)) { - part = c - 'a'; - *cp = '\0'; - } else - part = defpart; - - TAILQ_FOREACH(dv, &alldevs, dv_list) { - 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); -} - -/* - * 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() -{ - struct swdevt *swp; - struct device *dv; - register int len; - dev_t nrootdev, nswapdev = NODEV; - char buf[128], *rootdevname; - dev_t temp; - struct device *bootdv, *rootdv, *swapdv; - int bootpartition = 0; -#ifdef NFSCLIENT - extern char *nfsbootdevname; -#endif - - bootdv = booted_device; - - /* - * If 'swap generic' and we couldn't determine root device, - * ask the user. - */ - if (mountroot == NULL && bootdv == NULL) - boothowto |= RB_ASKNAME; - - /* - * If bootdev is bogus, ask the user anyhow. - */ - if (bootdev == 0) - boothowto |= RB_ASKNAME; - else - bootpartition = B_PARTITION(bootdev); - - /* - * If we booted from tape, ask the user. - */ - if (bootdv != NULL && bootdv->dv_class == DV_TAPE) - boothowto |= RB_ASKNAME; - - if (boothowto & RB_ASKNAME) { - for (;;) { - printf("root device"); - if (bootdv != NULL) { - printf(" (default %s", bootdv->dv_xname); - if (bootdv->dv_class == DV_DISK) - printf("%c", bootpartition + 'a'); - printf(")"); - } - printf(": "); - len = getstr(buf, sizeof(buf)); - 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) { - rootdv = dv; - nswapdev = nrootdev; - goto gotswap; - } - } - dv = getdisk(buf, len, bootpartition, &nrootdev); - if (dv != NULL) { - rootdv = dv; - break; - } - } - - /* - * Because swap must be on the same device type as root, - * for network devices this is easy. - */ - if (rootdv->dv_class == DV_IFNET) { - swapdv = NULL; - goto gotswap; - } - for (;;) { - printf("swap device"); - printf(" (default %s", rootdv->dv_xname); - if (rootdv->dv_class == DV_DISK) - printf("b"); - printf(")"); - printf(": "); - len = getstr(buf, sizeof(buf)); - if (len == 0) { - switch (rootdv->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; - } - swapdv = rootdv; - break; - } - dv = getdisk(buf, len, 1, &nswapdev); - if (dv) { - if (dv->dv_class == DV_IFNET) - nswapdev = NODEV; - swapdv = dv; - break; - } - } - gotswap: - rootdev = nrootdev; - dumpdev = nswapdev; - swdevt[0].sw_dev = nswapdev; - swdevt[1].sw_dev = NODEV; - } else if (mountroot == NULL) { - int majdev; - - /* - * "swap generic" - */ - majdev = findblkmajor(bootdv); - if (majdev >= 0) { - /* - * Root and swap are on a disk. - */ - rootdv = swapdv = bootdv; - rootdev = MAKEDISKDEV(majdev, bootdv->dv_unit, - bootpartition); - nswapdev = dumpdev = - MAKEDISKDEV(majdev, bootdv->dv_unit, 1); - } else { - /* - * Root and swap are on a net. - */ - rootdv = swapdv = bootdv; - nswapdev = dumpdev = NODEV; - } - swdevt[0].sw_dev = nswapdev; - swdevt[1].sw_dev = NODEV; - } else { - /* - * `root DEV swap DEV': honor rootdev/swdevt. - * rootdev/swdevt/mountroot already properly set. - */ - -#ifdef NFSCLIENT - if (mountroot == nfs_mountroot) { - struct dev_data *dd; - /* - * `root on nfs'. Find the first network - * interface. - */ - LIST_FOREACH(dd, &dev_data_list, dd_list) { - if (dd->dd_dev->dv_class == DV_IFNET) { - /* Got it! */ - break; - } - } - if (dd == NULL) { - printf("no network interface for NFS root"); - panic("setroot"); - } - root_device = dd->dd_dev; - return; - } -#endif - rootdevname = findblkname(major(rootdev)); - if (rootdevname == NULL) { - root_device = NULL; /* no device */ - return; - } - bzero(buf, sizeof(buf)); - snprintf(buf, sizeof buf, "%s%d", rootdevname, - DISKUNIT(rootdev)); - - TAILQ_FOREACH(dv, &alldevs, dv_list) { - if (strcmp(buf, dv->dv_xname) == 0) { - root_device = dv; - break; - } - } - root_device = dv; /* NULL is fine. */ - return; - } - - root_device = rootdv; - switch (rootdv->dv_class) { -#ifdef NFSCLIENT - case DV_IFNET: - mountroot = nfs_mountroot; - nfsbootdevname = rootdv->dv_xname; - return; -#endif - case DV_DISK: - mountroot = dk_mountroot; - printf("root on %s%c", rootdv->dv_xname, - DISKPART(rootdev) + 'a'); - if (nswapdev != NODEV) - printf(" swap on %s%c", swapdv->dv_xname, - DISKPART(nswapdev) + 'a'); - printf("\n"); - 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 (major(rootdev) == major(swp->sw_dev) && - DISKUNIT(rootdev) == 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; - - /* - * 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; - -} - -static int -getstr(cp, size) - register char *cp; - register int size; -{ - register char *lp; - register int c; - register 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; - } - } -} - void findbootdev() { @@ -802,7 +413,7 @@ findbootdev() int scsiboot, hpibboot, netboot; struct dev_data *dd; - booted_device = NULL; + bootdv = NULL; if ((bootdev & B_MAGICMASK) != B_DEVMAGIC) return; @@ -831,7 +442,7 @@ findbootdev() /* * Found it! */ - booted_device = dd->dd_dev; + bootdv = dd->dd_dev; break; } } @@ -844,7 +455,7 @@ findbootdev() if (hpibboot) { findbootdev_slave(&dev_data_list_hpib, ctlr, slave, punit); - if (booted_device == NULL) + if (bootdv == NULL) return; #ifdef DIAGNOSTIC @@ -852,13 +463,13 @@ findbootdev() * Sanity check. */ if ((type == 0 && - device_match(booted_device->dv_xname, "ct")) || + device_match(bootdv->dv_xname, "ct")) || (type == 2 && - device_match(booted_device->dv_xname, "hd"))) { + device_match(bootdv->dv_xname, "hd"))) { printf("WARNING: boot device/type mismatch!\n"); printf("device = %s, type = %d\n", - booted_device->dv_xname, type); - booted_device = NULL; + bootdv->dv_xname, type); + bootdv = NULL; } #endif return; @@ -870,20 +481,20 @@ findbootdev() if (scsiboot) { findbootdev_slave(&dev_data_list_scsi, ctlr, slave, punit); - if (booted_device == NULL) + if (bootdv == NULL) return; #ifdef DIAGNOSTIC /* * Sanity check. */ - if (device_match(booted_device->dv_xname, "cd") != 0 && - device_match(booted_device->dv_xname, "sd") != 0 && - device_match(booted_device->dv_xname, "st") != 0) { + if (device_match(bootdv->dv_xname, "cd") != 0 && + device_match(bootdv->dv_xname, "sd") != 0 && + device_match(bootdv->dv_xname, "st") != 0) { printf("WARNING: boot device/type mismatch!\n"); printf("device = %s, type = %d\n", - booted_device->dv_xname, type); - booted_device = NULL; + bootdv->dv_xname, type); + bootdv = NULL; } #endif return; @@ -930,7 +541,7 @@ findbootdev_slave(ddlist, ctlr, slave, punit) /* * Found it! */ - booted_device = dd->dd_dev; + bootdv = dd->dd_dev; break; } } @@ -1256,3 +867,38 @@ iounmap(va, size) printf("iounmap: extent_free failed\n"); #endif } + +struct nam2blk { + char *name; + int maj; +} nam2blk[] = { + { "ct", 0 }, + { "hd", 2 }, + { "sd", 4 }, + { "st", 7 }, + { "rd", 8 }, + { "cd", 9 }, +}; + +int +findblkmajor(struct device *dv) +{ + char *name = dv->dv_xname; + register int i; + + for (i = 0; i < sizeof(nam2blk) / sizeof(nam2blk[0]); i++) + if (!strncmp(name, nam2blk[i].name, strlen(nam2blk[0].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); +} diff --git a/sys/arch/hppa/hppa/autoconf.c b/sys/arch/hppa/hppa/autoconf.c index feba7c42f2f..3b61ecf330c 100644 --- a/sys/arch/hppa/hppa/autoconf.c +++ b/sys/arch/hppa/hppa/autoconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: autoconf.c,v 1.45 2006/11/28 16:56:50 dlg Exp $ */ +/* $OpenBSD: autoconf.c,v 1.46 2007/05/04 03:44:44 deraadt Exp $ */ /* * Copyright (c) 1998-2003 Michael Shalayeff @@ -52,6 +52,8 @@ #include <sys/device.h> #include <sys/timeout.h> +#include <uvm/uvm_extern.h> + #include <machine/iomod.h> #include <machine/autoconf.h> @@ -64,20 +66,12 @@ #include <dev/pci/pcireg.h> #endif -void setroot(void); +/* device we booted from */ +struct device *bootdv; void dumpconf(void); -int findblkmajor(struct device *dv); -const char *findblkname(int maj); -struct device *parsedisk(char *str, int len, int defpart, dev_t *devp); -struct device *getdisk(char *str, int len, int defpart, dev_t *devp); -int getstr(char *cp, int size); - void (*cold_hook)(int); /* see below */ -/* device we booted from */ -struct device *bootdv; - /* * LED blinking thing */ @@ -97,32 +91,6 @@ void heartbeat(void *); #include <scsi/scsiconf.h> #endif -/* - * cpu_configure: - * called at boot time, configure all devices on system - */ -void -cpu_configure(void) -{ - splhigh(); - if (config_rootfound("mainbus", "mainbus") == NULL) - panic("no mainbus found"); - - cpu_intr_init(); - spl0(); - - setroot(); - dumpconf(); - if (cold_hook) - (*cold_hook)(HPPA_COLD_HOT); - -#ifdef USELEDS - timeout_set(&heartbeat_tmo, heartbeat, NULL); - heartbeat(NULL); -#endif - cold = 0; -} - #ifdef USELEDS /* * turn the heartbeat alive. @@ -214,130 +182,6 @@ bad: return; } -const struct nam2blk { - char name[4]; - int maj; -} nam2blk[] = { - { "rd", 3 }, - { "sd", 4 }, - { "st", 5 }, - { "cd", 6 }, -#if 0 - { "wd", ? }, - { "fd", 7 }, -#endif -}; - -#ifdef RAMDISK_HOOKS -struct device fakerdrootdev = { DV_DISK, {}, NULL, 0, "rd0", NULL }; -#endif - -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[0].name))) - return (nam2blk[i].maj); - return (-1); -} - -const char * -findblkname(maj) - int maj; -{ - int i; - - for (i = 0; i < sizeof(nam2blk) / sizeof(nam2blk[0]); ++i) - if (maj == nam2blk[i].maj) - return (nam2blk[i].name); - return (NULL); -} - -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:"); -#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(" halt\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, part; - - if (len == 0) - return (NULL); - - if (len == 4 && !strcmp(str, "halt")) - boot(RB_HALT); - - cp = str + len - 1; - c = *cp; - if (c >= 'a' && c <= ('a' + MAXPARTITIONS - 1)) { - 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); - 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 print_devpath(const char *label, struct pz_device *pz) { @@ -357,248 +201,6 @@ print_devpath(const char *label, struct pz_device *pz) pz->pz_flags, PZF_BITS, pz->pz_hpa, pz->pz_spa, pz->pz_iodc_io); } -/* - * 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(void) -{ - struct swdevt *swp; - struct device *dv; - int len, majdev, part; - dev_t nrootdev, nswapdev = NODEV; - char buf[128]; - dev_t temp; - const char *rootdevname; - struct device *rootdv, *swapdv; -#ifdef NFSCLIENT - extern char *nfsbootdevname; -#endif - -#ifdef RAMDISK_HOOKS - bootdv = &fakerdrootdev; -#endif - part = 0; - - print_devpath("boot path", &PAGE0->mem_boot); - - /* - * 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", bootdv->dv_xname); - if (bootdv->dv_class == DV_DISK) - printf("%c", part + 'a'); - printf(")"); - } - printf(": "); - len = getstr(buf, sizeof(buf)); - 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) { - rootdv = swapdv = dv; - nswapdev = nrootdev; - goto gotswap; - } - } - dv = getdisk(buf, len, part, &nrootdev); - if (dv != NULL) { - rootdv = dv; - break; - } - } - - /* - * because swap must be on same device type as root, for - * network devices this is easy. - */ - if (rootdv->dv_class == DV_IFNET) { - swapdv = NULL; - goto gotswap; - } - for (;;) { - printf("swap device (default %s", rootdv->dv_xname); - if (rootdv->dv_class == DV_DISK) - printf("b"); - printf("): "); - len = getstr(buf, sizeof(buf)); - if (len == 0) { - switch (rootdv->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; - } - swapdv = rootdv; - break; - } - dv = getdisk(buf, len, 1, &nswapdev); - if (dv) { - if (dv->dv_class == DV_IFNET) - nswapdev = NODEV; - swapdv = dv; - break; - } - } -gotswap: - majdev = major(nrootdev); - 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. - * Assume swap is on partition b. - */ - rootdv = swapdv = bootdv; - rootdev = MAKEDISKDEV(majdev, bootdv->dv_unit, part); - nswapdev = dumpdev = - MAKEDISKDEV(majdev, bootdv->dv_unit, 1); - } else { - /* - * Root and swap are on a net. - */ - rootdv = swapdv = bootdv; - 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. - */ - - rootdevname = findblkname(major(rootdev)); - return; - } - - switch (rootdv->dv_class) { -#ifdef NFSCLIENT - case DV_IFNET: - mountroot = nfs_mountroot; - nfsbootdevname = rootdv->dv_xname; - return; -#endif -#ifndef DISKLESS - case DV_DISK: - mountroot = dk_mountroot; - printf("root on %s%c", rootdv->dv_xname, - DISKPART(rootdev) + 'a'); - if (nswapdev != NODEV) - printf(" swap on %s%c", swapdv->dv_xname, - DISKPART(nswapdev) + 'a'); - printf("\n"); - break; -#endif - 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) && - DISKUNIT(rootdev) == 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; - - /* - * 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; -} - -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; - } - } -} - struct pdc_memmap pdc_memmap PDC_ALIGNMENT; struct pdc_sysmap_find pdc_find PDC_ALIGNMENT; struct pdc_sysmap_addrs pdc_addr PDC_ALIGNMENT; @@ -848,3 +450,68 @@ device_register(struct device *dev, void *aux) } #endif } + +/* + * cpu_configure: + * called at boot time, configure all devices on system + */ +void +cpu_configure(void) +{ + splhigh(); + if (config_rootfound("mainbus", "mainbus") == NULL) + panic("no mainbus found"); + + cpu_intr_init(); + spl0(); + + print_devpath("bootpath", &PAGE0->mem_boot); + + setroot(bootdv, 0, RB_USERREQ); + dumpconf(); + if (cold_hook) + (*cold_hook)(HPPA_COLD_HOT); + +#ifdef USELEDS + timeout_set(&heartbeat_tmo, heartbeat, NULL); + heartbeat(NULL); +#endif + cold = 0; +} + +static struct { + char *name; + int maj; +} nam2blk[] = { + { "rd", 3 }, + { "sd", 4 }, + { "st", 5 }, + { "cd", 6 } +#if 0 + { "wd", ? }, + { "fd", 7 }, +#endif +}; + +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); +} diff --git a/sys/arch/hppa64/hppa64/autoconf.c b/sys/arch/hppa64/hppa64/autoconf.c index 96d405eadcd..8b13e37fa89 100644 --- a/sys/arch/hppa64/hppa64/autoconf.c +++ b/sys/arch/hppa64/hppa64/autoconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: autoconf.c,v 1.5 2006/11/28 16:56:50 dlg Exp $ */ +/* $OpenBSD: autoconf.c,v 1.6 2007/05/04 03:44:44 deraadt Exp $ */ /* * Copyright (c) 1998-2005 Michael Shalayeff @@ -66,15 +66,8 @@ #include <dev/pci/pcireg.h> #endif -void setroot(void); void dumpconf(void); -int findblkmajor(struct device *dv); -const char *findblkname(int maj); -struct device *parsedisk(char *str, int len, int defpart, dev_t *devp); -struct device *getdisk(char *str, int len, int defpart, dev_t *devp); -int getstr(char *cp, int size); - void (*cold_hook)(int); /* see below */ /* device we booted from */ @@ -116,7 +109,8 @@ cpu_configure(void) mtctl(0xffffffffffffffffULL, CR_EIEM); spl0(); - setroot(); + print_devpath("boot path", &PAGE0->mem_boot); + setroot(bootdv, 0, RB_USERREQ); dumpconf(); if (cold_hook) (*cold_hook)(HPPA_COLD_HOT); @@ -219,130 +213,6 @@ bad: return; } -const struct nam2blk { - char name[4]; - int maj; -} nam2blk[] = { - { "rd", 3 }, - { "sd", 4 }, - { "st", 5 }, - { "cd", 6 }, -#if 0 - { "wd", ? }, - { "fd", 7 }, -#endif -}; - -#ifdef RAMDISK_HOOKS -struct device fakerdrootdev = { DV_DISK, {}, NULL, 0, "rd0", NULL }; -#endif - -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[0].name))) - return (nam2blk[i].maj); - return (-1); -} - -const char * -findblkname(maj) - int maj; -{ - int i; - - for (i = 0; i < sizeof(nam2blk) / sizeof(nam2blk[0]); ++i) - if (maj == nam2blk[i].maj) - return (nam2blk[i].name); - return (NULL); -} - -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:"); -#ifdef RAMDISK_HOOKS - printf(" %s[a-p]", fakerdrootdev.dv_xname); -#endif - 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(" halt\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, part; - - if (len == 0) - return (NULL); - - if (len == 4 && !strcmp(str, "halt")) - boot(RB_HALT); - - cp = str + len - 1; - c = *cp; - if (c >= 'a' && c <= ('a' + MAXPARTITIONS - 1)) { - part = c - 'a'; - *cp = '\0'; - } else - part = defpart; - -#ifdef RAMDISK_HOOKS - if (strcmp(str, fakerdrootdev.dv_xname) == 0) { - dv = &fakerdrootdev; - goto gotdisk; - } -#endif - 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) { -#ifdef RAMDISK_HOOKS -gotdisk: -#endif - 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 print_devpath(const char *label, struct pz_device *pz) @@ -363,248 +233,6 @@ print_devpath(const char *label, struct pz_device *pz) pz->pz_flags, PZF_BITS, pz->pz_hpa, pz->pz_spa, pz->pz_iodc_io); } -/* - * 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(void) -{ - struct swdevt *swp; - struct device *dv; - int len, majdev, part; - dev_t nrootdev, nswapdev = NODEV; - char buf[128]; - dev_t temp; - const char *rootdevname; - struct device *rootdv, *swapdv; -#ifdef NFSCLIENT - extern char *nfsbootdevname; -#endif - -#ifdef RAMDISK_HOOKS - bootdv = &fakerdrootdev; -#endif - part = 0; - - print_devpath("boot path", &PAGE0->mem_boot); - - /* - * 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", bootdv->dv_xname); - if (bootdv->dv_class == DV_DISK) - printf("%c", part + 'a'); - printf(")"); - } - printf(": "); - len = getstr(buf, sizeof(buf)); - 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) { - rootdv = swapdv = dv; - nswapdev = nrootdev; - goto gotswap; - } - } - dv = getdisk(buf, len, part, &nrootdev); - if (dv != NULL) { - rootdv = dv; - break; - } - } - - /* - * because swap must be on same device type as root, for - * network devices this is easy. - */ - if (rootdv->dv_class == DV_IFNET) { - swapdv = NULL; - goto gotswap; - } - for (;;) { - printf("swap device (default %s", rootdv->dv_xname); - if (rootdv->dv_class == DV_DISK) - printf("b"); - printf("): "); - len = getstr(buf, sizeof(buf)); - if (len == 0) { - switch (rootdv->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; - } - swapdv = rootdv; - break; - } - dv = getdisk(buf, len, 1, &nswapdev); - if (dv) { - if (dv->dv_class == DV_IFNET) - nswapdev = NODEV; - swapdv = dv; - break; - } - } -gotswap: - majdev = major(nrootdev); - 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. - * Assume swap is on partition b. - */ - rootdv = swapdv = bootdv; - rootdev = MAKEDISKDEV(majdev, bootdv->dv_unit, part); - nswapdev = dumpdev = - MAKEDISKDEV(majdev, bootdv->dv_unit, 1); - } else { - /* - * Root and swap are on a net. - */ - rootdv = swapdv = bootdv; - 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. - */ - - rootdevname = findblkname(major(rootdev)); - return; - } - - switch (rootdv->dv_class) { -#ifdef NFSCLIENT - case DV_IFNET: - mountroot = nfs_mountroot; - nfsbootdevname = rootdv->dv_xname; - return; -#endif -#ifndef DISKLESS - case DV_DISK: - mountroot = dk_mountroot; - printf("root on %s%c", rootdv->dv_xname, - DISKPART(rootdev) + 'a'); - if (nswapdev != NODEV) - printf(" swap on %s%c", swapdv->dv_xname, - DISKPART(nswapdev) + 'a'); - printf("\n"); - break; -#endif - 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) && - DISKUNIT(rootdev) == 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; - - /* - * 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; -} - -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; - } - } -} - u_int32_t pdc_rt[16 / 4 * sizeof(struct pdc_pat_pci_rt)] PDC_ALIGNMENT; struct pdc_sysmap_find pdc_find PDC_ALIGNMENT; struct pdc_iodc_read pdc_iodc_read PDC_ALIGNMENT; @@ -907,3 +535,40 @@ device_register(struct device *dev, void *aux) } #endif } + +static struct { + char name[4]; + int maj; +} nam2blk[] = { + { "rd", 3 }, + { "sd", 4 }, + { "st", 5 }, + { "cd", 6 }, +#if 0 + { "wd", ? }, + { "fd", 7 }, +#endif +}; + +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); +} + +const char * +findblkname(int maj) +{ + int i; + + for (i = 0; i < sizeof(nam2blk) / sizeof(nam2blk[0]); ++i) + if (maj == nam2blk[i].maj) + return (nam2blk[i].name); + return (NULL); +} diff --git a/sys/arch/i386/i386/autoconf.c b/sys/arch/i386/i386/autoconf.c index f62b3e8bd37..f74e9ee9bd7 100644 --- a/sys/arch/i386/i386/autoconf.c +++ b/sys/arch/i386/i386/autoconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: autoconf.c,v 1.71 2007/05/01 17:35:56 deraadt Exp $ */ +/* $OpenBSD: autoconf.c,v 1.72 2007/05/04 03:44:44 deraadt Exp $ */ /* $NetBSD: autoconf.c,v 1.20 1996/05/03 19:41:56 christos Exp $ */ /*- @@ -76,11 +76,6 @@ #include <machine/i82093var.h> #endif -int findblkmajor(struct device *dv); -char *findblkname(int); - -void rootconf(void); -void setroot(void); void diskconf(void); /* @@ -181,91 +176,31 @@ cpu_configure(void) void diskconf(void) { - /* - * Configure root, swap, and dump area. This is - * currently done by running the same checksum - * algorithm over all known disks, as was done in - * /boot. Then we basically fixup the *dev vars - * from the info we gleaned from this. - */ - dkcsumattach(); - - rootconf(); - dumpconf(); -} - -#define DOSWAP /* change swdevt and dumpdev */ - -static struct { - char *name; - int maj; -} nam2blk[] = { - { "wd", 0 }, - { "sw", 1 }, - { "fd", 2 }, - { "wt", 3 }, - { "sd", 4 }, - { "cd", 6 }, - { "mcd", 7 }, - { "rd", 17 }, - { "raid", 19 } -}; - -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)) - == 0) - return (nam2blk[i].maj); - return (-1); -} - -char * -findblkname(int maj) -{ - int i; - - for (i = 0; i < sizeof(nam2blk)/sizeof(nam2blk[0]); ++i) - if (maj == nam2blk[i].maj) - return (nam2blk[i].name); - return (NULL); -} - -dev_t argdev = NODEV; -int nswap; - -/* - * 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 -setroot(void) -{ - int majdev, mindev, unit, part, adaptor; - struct swdevt *swp; - dev_t orootdev; + int majdev, unit, part = 0; + struct device *bootdv = NULL; + dev_t tmpdev; + char buf[128]; #if defined(NFSCLIENT) extern bios_bootmac_t *bios_bootmac; #endif -#ifdef DOSWAP - dev_t temp = 0; -#endif + + dkcsumattach(); + + if ((bootdev & B_MAGICMASK) == (u_int)B_DEVMAGIC) { + majdev = B_TYPE(bootdev); + unit = B_UNIT(bootdev); + part = B_PARTITION(bootdev); + snprintf(buf, sizeof buf, "%s%d%c", findblkname(majdev), + unit, part + 'a'); + bootdv = parsedisk(buf, strlen(buf), part, &tmpdev); + } #if defined(NFSCLIENT) if (bios_bootmac) { - extern char *nfsbootdevname; struct ifnet *ifp; - - mountroot = nfs_mountroot; printf("PXE boot MAC address %s, ", ether_sprintf(bios_bootmac->mac)); - for (ifp = TAILQ_FIRST(&ifnet); ifp != NULL; ifp = TAILQ_NEXT(ifp, if_list)) { if ((ifp->if_type == IFT_ETHER || @@ -276,224 +211,52 @@ setroot(void) break; } if (ifp) { - nfsbootdevname = ifp->if_xname; - printf("interface %s\n", nfsbootdevname); + printf("interface %s\n", ifp->if_xname); + mountroot = nfs_mountroot; /* potentially */ + bootdv = parsedisk(ifp->if_xname, strlen(ifp->if_xname), + 0, &tmpdev); + part = 0; } else - printf("no interface selected\n"); - return; + printf("unknown interface\n"); } #endif - if (boothowto & RB_DFLTROOT || - (bootdev & B_MAGICMASK) != (u_long)B_DEVMAGIC) - return; - - majdev = B_TYPE(bootdev); - if (findblkname(majdev) == NULL) - return; - adaptor = B_ADAPTOR(bootdev); - part = B_PARTITION(bootdev); - unit = B_UNIT(bootdev); - mindev = (unit * MAXPARTITIONS) + part; - orootdev = rootdev; - rootdev = makedev(majdev, mindev); - mountroot = dk_mountroot; - - /* - * If the original rootdev is the same as the one - * just calculated, don't need to adjust the swap configuration. - */ - printf("root on %s%d%c\n", findblkname(majdev), unit, part + 'a'); - if (rootdev == orootdev) - return; - -#ifdef DOSWAP - for (swp = swdevt; swp->sw_dev != NODEV; swp++) { - if (majdev == major(swp->sw_dev) && - mindev/MAXPARTITIONS == minor(swp->sw_dev)/MAXPARTITIONS) { - temp = swdevt[0].sw_dev; - swdevt[0].sw_dev = swp->sw_dev; - swp->sw_dev = temp; - break; - } - } - if (swp->sw_dev == NODEV) - return; - - /* - * 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; -#endif + setroot(bootdv, part, RB_USERREQ); + dumpconf(); } -#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 -#include "mcd.h" -#if NMCD > 0 -extern struct cfdriver mcd_cd; -#endif -#include "fd.h" -#if NFD > 0 -extern struct cfdriver fd_cd; -#endif -#include "rd.h" -#if NRD > 0 -extern struct cfdriver rd_cd; -#endif -#include "raid.h" -#if NRAID > 0 -extern struct cfdriver raid_cd; -#endif - -struct genericconf { - struct cfdriver *gc_driver; - char *gc_name; - dev_t gc_major; -} genericconf[] = { -#if NWD > 0 - { &wd_cd, "wd", 0 }, -#endif -#if NFD > 0 - { &fd_cd, "fd", 2 }, -#endif -#if NSD > 0 - { &sd_cd, "sd", 4 }, -#endif -#if NCD > 0 - { &cd_cd, "cd", 6 }, -#endif -#if NMCD > 0 - { &mcd_cd, "mcd", 7 }, -#endif -#if NRD > 0 - { &rd_cd, "rd", 17 }, -#endif -#if NRAID > 0 - { &raid_cd, "raid", 19 }, -#endif - { 0 } +static struct { + char *name; + int maj; +} nam2blk[] = { + { "wd", 0 }, + { "fd", 2 }, + { "sd", 4 }, + { "cd", 6 }, + { "mcd", 7 }, + { "rd", 17 }, + { "raid", 19 } }; -void -rootconf(void) +int +findblkmajor(struct device *dv) { - struct genericconf *gc; - int unit, part = 0; -#if defined(NFSCLIENT) - struct ifnet *ifp; -#endif - char name[128]; - char *num; - - if (boothowto & RB_ASKNAME) { - while (1) { - printf("root device? "); - cnpollc(TRUE); - getsn(name, sizeof name); - cnpollc(FALSE); - if (*name == '\0') - break; - if (strcmp(name, "exit") == 0) - boot(RB_USERREQ); - for (gc = genericconf; gc->gc_driver; gc++) - if (gc->gc_driver->cd_ndevs && - strncmp(gc->gc_name, name, - strlen(gc->gc_name)) == 0) - break; - if (gc->gc_driver) { - num = &name[strlen(gc->gc_name)]; - - unit = -2; - do { - if (unit != -2 && *num >= 'a' && - *num <= 'a'+MAXPARTITIONS-1 && - num[1] == '\0') { - part = *num++ - 'a'; - break; - } - if (unit == -2) - unit = 0; - unit = (unit * 10) + *num - '0'; - if (*num < '0' || *num > '9') - unit = -1; - } while (unit != -1 && *++num); - - if (unit < 0) { - printf("%s: not a unit number\n", - &name[strlen(gc->gc_name)]); - } else if (unit >= gc->gc_driver->cd_ndevs || - gc->gc_driver->cd_devs[unit] == NULL) { - printf("%d: no such unit\n", unit); - } else { - rootdev = makedev(gc->gc_major, - unit * MAXPARTITIONS + part); - mountroot = dk_mountroot; - break; - } -#if defined(NFSCLIENT) - } else { - ifp = ifunit(name); - if (ifp && (ifp->if_flags & IFF_BROADCAST)) { - extern char *nfsbootdevname; - - mountroot = nfs_mountroot; - nfsbootdevname = ifp->if_xname; - return; - } -#endif - } - - printf("use one of: exit"); - for (gc = genericconf; gc->gc_driver; gc++) { - for (unit=0; unit < gc->gc_driver->cd_ndevs; unit++) { - if (gc->gc_driver->cd_devs[unit]) - printf(" %s%d[a-%c]", gc->gc_name, - unit, 'a'+MAXPARTITIONS-1); - } - } -#if defined(NFSCLIENT) - for (ifp = TAILQ_FIRST(&ifnet); ifp != NULL; - ifp = TAILQ_NEXT(ifp, if_list)) { - if ((ifp->if_flags & IFF_BROADCAST)) - printf(" %s", ifp->if_xname); - } -#endif - printf("\n"); - } - } + char *name = dv->dv_xname; + int i; - if (mountroot == NULL) { - /* `swap generic' */ - setroot(); -#if defined(NFSCLIENT) - } else if (mountroot == nfs_mountroot) { - ; -#endif - } else { - /* preconfigured for disk */ - int majdev, unit, part; - - majdev = major(rootdev); - if (findblkname(majdev) == NULL) - return; - part = minor(rootdev) % MAXPARTITIONS; - unit = minor(rootdev) / MAXPARTITIONS; - printf("root on %s%d%c\n", findblkname(majdev), unit, part + 'a'); - } - if (mountroot == dk_mountroot) - swdevt[0].sw_dev = argdev = dumpdev = - MAKEDISKDEV(major(rootdev), DISKUNIT(rootdev), 1); + 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); } diff --git a/sys/arch/landisk/landisk/autoconf.c b/sys/arch/landisk/landisk/autoconf.c index 7facbd1c6fc..1cd0c493478 100644 --- a/sys/arch/landisk/landisk/autoconf.c +++ b/sys/arch/landisk/landisk/autoconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: autoconf.c,v 1.5 2007/03/03 21:37:27 miod Exp $ */ +/* $OpenBSD: autoconf.c,v 1.6 2007/05/04 03:44:44 deraadt Exp $ */ /* $NetBSD: autoconf.c,v 1.1 2006/09/01 21:26:18 uwe Exp $ */ /*- @@ -48,15 +48,7 @@ int cold = 1; -struct device *booted_device; -struct device *root_device; - void diskconf(void); -struct device *parsedisk(char *, int, int, dev_t *); -void setroot(void); -int findblkmajor(struct device *); -char *findblkname(int); -struct device *getdisk(char *, int, int, dev_t *); void cpu_configure(void) @@ -80,19 +72,21 @@ cpu_configure(void) void diskconf(void) { - printf("boot device: %s\n", - booted_device ? booted_device->dv_xname : "<unknown>"); - setroot(); + struct device *dv; + dev_t tmpdev; + + dv = parsedisk("wd0a", strlen("wd0a"), 0, &tmpdev); + setroot(dv, 0, RB_USERREQ); dumpconf(); } -static struct nam2blk { - char *name; - int maj; +static struct { + char *name; + int maj; } nam2blk[] = { - { "wd", 16 }, - { "rd", 18 }, - { "sd", 24 } + { "wd", 16 }, + { "rd", 18 }, + { "sd", 24 } }; int @@ -101,9 +95,8 @@ 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)) == - 0) + 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); } @@ -116,262 +109,5 @@ findblkname(int maj) for (i = 0; i < sizeof(nam2blk)/sizeof(nam2blk[0]); i++) if (nam2blk[i].maj == maj) return (nam2blk[i].name); - return (NULL); -} - -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:"); - 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(" halt\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); - - if (len == 4 && strcmp(str, "halt") == 0) - boot(RB_HALT); - - cp = str + len - 1; - c = *cp; - if (c >= 'a' && (c - 'a') < MAXPARTITIONS) { - part = c - 'a'; - *cp = '\0'; - } else - part = defpart; - - TAILQ_FOREACH(dv, &alldevs, dv_list) { - if (dv->dv_class == DV_DISK && - strcmp(str, dv->dv_xname) == 0) { - majdev = findblkmajor(dv); - if (majdev < 0) { - printf("%s is not a valid boot device\n", str); - dv = NULL; - break; - } - *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); -} - -/* - * 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 -setroot() -{ - 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 */ - - if (booted_device == NULL && rootdev == NULL) { - boothowto |= RB_ASKNAME; /* Don't Panic :-) */ - /* boothowto |= RB_SINGLE; */ - } - - if (boothowto & RB_ASKNAME) { - for (;;) { - printf("root device"); - if (booted_device != NULL) { - printf(" (default %s", - booted_device->dv_xname); - if (booted_device->dv_class == DV_DISK) - printf("a"); - printf(")"); - } - printf(": "); - s = splhigh(); - cnpollc(1); - len = getsn(buf, sizeof(buf)); - cnpollc(0); - splx(s); - if (len == 0 && booted_device != NULL) { - strlcpy(buf, booted_device->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) { - booted_device = dv; - nswapdev = nrootdev; - goto gotswap; - } - } - dv = getdisk(buf, len, 0, &nrootdev); - if (dv != NULL) { - booted_device = dv; - break; - } - } - - /* - * because swap must be on same device as root, for - * network devices this is easy. - */ - if (booted_device->dv_class == DV_IFNET) - goto gotswap; - - for (;;) { - printf("swap device"); - if (booted_device != NULL) { - printf(" (default %s", - booted_device->dv_xname); - if (booted_device->dv_class == DV_DISK) - printf("b"); - printf(")"); - } - printf(": "); - s = splhigh(); - cnpollc(1); - len = getsn(buf, sizeof(buf)); - cnpollc(0); - splx(s); - if (len == 0 && booted_device != NULL) { - switch (booted_device->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' - */ - majdev = findblkmajor(booted_device); - if (majdev >= 0) { - /* - * Root and Swap are on disk. - * Boot is always from partition 0. - */ - rootdev = MAKEDISKDEV(majdev, booted_device->dv_unit, 0); - nswapdev = dumpdev = - MAKEDISKDEV(majdev, booted_device->dv_unit, 1); - } else { - /* - * Root and Swap are on 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. - */ - return; - } - - switch (booted_device->dv_class) { -#if defined(NFSCLIENT) - case DV_IFNET: - mountroot = nfs_mountroot; - nfsbootdevname = booted_device->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", booted_device->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) - return; - - /* - * 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; + return (NULL); } diff --git a/sys/arch/luna88k/luna88k/autoconf.c b/sys/arch/luna88k/luna88k/autoconf.c index 62f05b20a47..895a04bf6d1 100644 --- a/sys/arch/luna88k/luna88k/autoconf.c +++ b/sys/arch/luna88k/luna88k/autoconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: autoconf.c,v 1.8 2006/11/28 16:56:50 dlg Exp $ */ +/* $OpenBSD: autoconf.c,v 1.9 2007/05/04 03:44:44 deraadt Exp $ */ /* * Copyright (c) 1998 Steve Murphree, Jr. * Copyright (c) 1996 Nivas Madhur @@ -58,12 +58,8 @@ * the machine. */ -struct device *parsedisk(char *, int, int, dev_t *); -void setroot(void); void dumpconf(void); -int findblkmajor(struct device *); void get_autoboot_device(void); -struct device *getdisk(char *, int, int, dev_t *); int cold = 1; /* 1 if still booting */ @@ -89,282 +85,14 @@ cpu_configure() */ set_psr(get_psr() & ~PSR_IND); spl0(); - setroot(); - dumpconf(); - - cold = 0; -} - -struct nam2blk { - char *name; - int maj; -} nam2blk[] = { - { "sd", 4 }, - { "st", 5 }, - { "rd", 7 }, -}; - -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[0].name)) == 0) - return (nam2blk[i].maj); - return (-1); -} - -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:"); - 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; - - TAILQ_FOREACH(dv, &alldevs, dv_list) { - if (dv->dv_class == DV_DISK && - strcmp(str, dv->dv_xname) == 0) { - 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); -} - -/* - * 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() -{ - struct swdevt *swp; - struct device *dv; - int len, majdev, unit; - dev_t nrootdev, nswapdev = NODEV; - char buf[128]; - dev_t temp; -#if defined(NFSCLIENT) - extern char *nfsbootdevname; -#endif printf("boot device: %s\n", (bootdv) ? bootdv->dv_xname : "<unknown>"); + setroot(bootdv, 0, RB_USERREQ); - /* - * If 'swap generic' and we could not determine the 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 ? 'a' : ' '); - printf(": "); - len = getsn(buf, sizeof(buf)); - 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) { - bootdv = dv; - nswapdev = nrootdev; - goto gotswap; - } - } - dv = getdisk(buf, len, 0, &nrootdev); - if (dv) { - 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 = getsn(buf, sizeof(buf)); - 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 a disk. - * val[2] of the boot device is the partition number. - * Assume swap is on partition b. - */ - unit = bootdv->dv_unit; - rootdev = MAKEDISKDEV(majdev, unit, bootpart); - 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. - */ - return; - } - - switch (bootdv->dv_class) { -#if defined(NFSCLIENT) - case DV_IFNET: - mountroot = nfs_mountroot; - nfsbootdevname = bootdv->dv_xname; - return; -#endif -#if defined(FFS) - case DV_DISK: - mountroot = dk_mountroot; - majdev = major(rootdev); - unit = DISKUNIT(rootdev); - printf("root on %s%c\n", bootdv->dv_xname, - DISKPART(rootdev) + 'a'); - break; -#endif - 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) - return; + dumpconf(); - /* - * 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; + cold = 0; } /* @@ -440,3 +168,35 @@ device_register(struct device *dev, void *aux) } } } + +static struct { + char *name; + int maj; +} nam2blk[] = { + { "sd", 4 }, + { "st", 5 }, + { "rd", 7 }, +}; + +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); +} diff --git a/sys/arch/mac68k/mac68k/autoconf.c b/sys/arch/mac68k/mac68k/autoconf.c index 37c8900c0a8..f6a7f034382 100644 --- a/sys/arch/mac68k/mac68k/autoconf.c +++ b/sys/arch/mac68k/mac68k/autoconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: autoconf.c,v 1.26 2006/03/19 21:58:53 miod Exp $ */ +/* $OpenBSD: autoconf.c,v 1.27 2007/05/04 03:44:44 deraadt Exp $ */ /* $NetBSD: autoconf.c,v 1.38 1996/12/18 05:46:09 scottr Exp $ */ /* @@ -66,389 +66,12 @@ #include <scsi/scsi_all.h> #include <scsi/scsiconf.h> -struct device *booted_device; -int booted_partition; - -struct device *parsedisk(char *, int, int, dev_t *); -struct device *getdisk(char *, int, int, dev_t *); -int findblkmajor(struct device *); -int getstr(char *, int); -void findbootdev(void); int target_to_unit(u_long, u_long, u_long); - void diskconf(void); -void setroot(void); - -#ifdef RAMDISK_HOOKS -static struct device fakerdrootdev = { DV_DISK, {}, NULL, 0, "rd0", NULL }; -#endif - -void -cpu_configure() -{ - startrtclock(); - - if (config_rootfound("mainbus", "mainbus") == NULL) - panic("No mainbus found!"); - spl0(); - - findbootdev(); - md_diskconf = diskconf; - cold = 0; -} - -void -diskconf() -{ - setroot(); - dumpconf(); -} - -struct nam2blk { - char *name; - int maj; -} nam2blk[] = { - { "sd", 4 }, - { "cd", 6 }, - { "rd", 13 }, -}; - -int -findblkmajor(dv) - struct device *dv; -{ - char *name = dv->dv_xname; - register int i; - - for (i = 0; i < sizeof(nam2blk)/sizeof(nam2blk[0]); ++i) - if (!strncmp(name, nam2blk[i].name, strlen(nam2blk[0].name))) - return (nam2blk[i].maj); - return (-1); -} - -struct device * -getdisk(str, len, defpart, devp) - char *str; - int len, defpart; - dev_t *devp; -{ - register struct device *dv; - - if ((dv = parsedisk(str, len, defpart, devp)) == NULL) { - printf("use one of:"); -#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; -{ - register struct device *dv; - register char *cp, c; - int majdev, part; - - if (len == 0) - return (NULL); - cp = str + len - 1; - c = *cp; - if (c >= 'a' && c <= ('a' + MAXPARTITIONS - 1)) { - 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); - 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); -} - -/* - * 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(void) -{ - register struct swdevt *swp; - register struct device *dv; - register int len; - dev_t nrootdev, nswapdev = NODEV; - char buf[128]; - dev_t temp; - struct device *bootdv, *rootdv, *swapdv; - int bootpartition; -#if defined(NFSCLIENT) - extern char *nfsbootdevname; -#endif - -#ifdef RAMDISK_HOOKS - bootdv = &fakerdrootdev; -#else - bootdv = booted_device; -#endif - bootpartition = booted_partition; - rootdv = swapdv = NULL; /* XXX work around gcc warning */ - - /* - * 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 ? '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 && !strcmp(buf, "halt")) - boot(RB_HALT); - if (len > 0 && buf[len - 1] == '*') { - buf[--len] = '\0'; - dv = getdisk(buf, len, 1, &nrootdev); - if (dv != NULL) { - rootdv = dv; - nswapdev = nrootdev; - goto gotswap; - } - } - dv = getdisk(buf, len, bootpartition, &nrootdev); - if (dv != NULL) { - rootdv = dv; - break; - } - } - - /* - * Because swap must be on same device as root, for - * network devices this is easy. - */ - if (rootdv->dv_class == DV_IFNET) { - swapdv = NULL; - goto gotswap; - } - for (;;) { - printf("swap device"); - if (rootdv != NULL) - printf(" (default %s%c)", rootdv->dv_xname, - rootdv->dv_class == DV_DISK ? 'b' : ' '); - printf(": "); - len = getstr(buf, sizeof(buf)); - if (len == 0) { - switch (rootdv->dv_class) { - case DV_IFNET: - nswapdev = NODEV; - break; - case DV_DISK: - nswapdev = MAKEDISKDEV(major(nrootdev), - DISKUNIT(minor(nrootdev)), 1); - break; - case DV_TAPE: - case DV_TTY: - case DV_DULL: - case DV_CPU: - break; - } - swapdv = rootdv; - break; - } - if (len == 4 && !strcmp(buf, "halt")) - boot(RB_HALT); - dv = getdisk(buf, len, 1, &nswapdev); - if (dv) { - if (dv->dv_class == DV_IFNET) - nswapdev = NODEV; - swapdv = dv; - break; - } - } -gotswap: - rootdev = nrootdev; - dumpdev = nswapdev; - swdevt[0].sw_dev = nswapdev; - swdevt[1].sw_dev = NODEV; - - } else if (mountroot == NULL) { - int majdev; - - /* - * "swap generic" - */ - majdev = findblkmajor(bootdv); - if (majdev >= 0) { - /* - * Root and swap are on a disk. - */ - rootdv = swapdv = bootdv; - rootdev = - MAKEDISKDEV(majdev, bootdv->dv_unit, bootpartition); - nswapdev = dumpdev = - MAKEDISKDEV(majdev, bootdv->dv_unit, 1); - } else { - /* - * Root and swap are on a net. - */ - rootdv = swapdv = bootdv; - 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. - */ - return; - } - - switch (rootdv->dv_class) { -#ifdef NFSCLIENT - case DV_IFNET: - mountroot = nfs_mountroot; - nfsbootdevname = rootdv->dv_xname; - return; -#endif - case DV_DISK: - mountroot = dk_mountroot; - printf("root on %s%c", rootdv->dv_xname, - DISKPART(rootdev) + 'a'); - if (nswapdev != NODEV) - printf(" swap on %s%c", swapdv->dv_xname, - DISKPART(nswapdev) + 'a'); - printf("\n"); - 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 (major(rootdev) == major(swp->sw_dev) && - DISKUNIT(rootdev) == DISKUNIT(minor(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; - - /* - * 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; -} - -int -getstr(cp, size) - register char *cp; - register int size; -{ - register char *lp; - register int c; - register 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; - } - } -} - +void findbootdev(void); +struct device *booted_device; +int booted_partition; dev_t bootdev; /* @@ -485,6 +108,27 @@ findbootdev() } } +void +cpu_configure() +{ + startrtclock(); + + if (config_rootfound("mainbus", "mainbus") == NULL) + panic("No mainbus found!"); + spl0(); + + findbootdev(); + md_diskconf = diskconf; + cold = 0; +} + +void +diskconf() +{ + setroot(booted_device, booted_partition, RB_USERREQ); + dumpconf(); +} + /* * Map a SCSI bus, target, lun to a device number. * This could be tape, disk, CD. The calling routine, though, @@ -497,7 +141,7 @@ target_to_unit(bus, target, lun) struct scsibus_softc *scsi; struct scsi_link *sc_link; struct device *sc_dev; -extern struct cfdriver scsibus_cd; + extern struct cfdriver scsibus_cd; if (target < 0 || target > 7 || lun < 0 || lun > 7) { printf("scsi target to unit, target (%ld) or lun (%ld)" @@ -534,3 +178,35 @@ extern struct cfdriver scsibus_cd; } return -1; } + +static struct { + char *name; + int maj; +} nam2blk[] = { + { "sd", 4 }, + { "cd", 6 }, + { "rd", 13 }, +}; + +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); +} diff --git a/sys/arch/macppc/macppc/autoconf.c b/sys/arch/macppc/macppc/autoconf.c index 0c8e441df69..c9e66479e8d 100644 --- a/sys/arch/macppc/macppc/autoconf.c +++ b/sys/arch/macppc/macppc/autoconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: autoconf.c,v 1.25 2007/04/16 12:00:25 dlg Exp $ */ +/* $OpenBSD: autoconf.c,v 1.26 2007/05/04 03:44:44 deraadt Exp $ */ /* * Copyright (c) 1996, 1997 Per Fogelstrom * Copyright (c) 1995 Theo de Raadt @@ -37,7 +37,7 @@ * from: Utah Hdr: autoconf.c 1.31 91/01/21 * * from: @(#)autoconf.c 8.1 (Berkeley) 6/10/93 - * $Id: autoconf.c,v 1.25 2007/04/16 12:00:25 dlg Exp $ + * $Id: autoconf.c,v 1.26 2007/05/04 03:44:44 deraadt Exp $ */ /* @@ -66,14 +66,9 @@ #include <scsi/scsiconf.h> #include <scsi/sdvar.h> -struct device *parsedisk(char *, int, int, dev_t *); -void setroot(void); void dumpconf(void); -int findblkmajor(struct device *); -char *findblkname(int); -static struct device * getdisk(char *, int, int, dev_t *); -struct device * getdevunit(char *, int); -static struct devmap * findtype(char **); +struct device *getdevunit(char *, int); +static struct devmap *findtype(char **); void makebootdev(char *cp); int getpno(char **); void diskconf(void); @@ -100,7 +95,7 @@ cpu_configure() (void)splhigh(); /* To be really sure.. */ calc_delayconst(); - if(config_rootfound("mainbus", "mainbus") == 0) + if (config_rootfound("mainbus", "mainbus") == 0) panic("no mainbus found"); (void)spl0(); @@ -111,370 +106,6 @@ cpu_configure() md_diskconf = diskconf; cold = 0; } -/* - * Now that we are fully operational, we can checksum the - * disks, and using some heuristics, hopefully are able to - * always determine the correct root disk. - */ -void -diskconf() -{ - /* - * Configure root, swap, and dump area. This is - * currently done by running the same checksum - * algorithm over all known disks, as was done in - * /boot. Then we basically fixup the *dev vars - * from the info we gleaned from this. - dkcsumattach(); - * - XXX - */ - -#if 0 - rootconf(); -#endif - setroot(); - dumpconf(); -} - -/* - * Crash dump handling. - */ - -static struct nam2blk { - char *name; - int maj; -} nam2blk[] = { - { "wd", 0 }, /* 0 = wd */ - { "sd", 2 }, /* 2 = sd */ - { "ofdisk", 4 }, /* 4 = ofdisk */ - { "raid", 19 }, /* 19 = raid */ -}; - -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)) == - 0) - 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); -} - -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:"); - 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(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; - - TAILQ_FOREACH(dv, &alldevs, dv_list) { - 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); -} - -/* - * 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 -setroot() -{ - 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 - - printf("bootpath: '%s'\n", bootpath); - - makebootdev(bootpath); - 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("setroot: 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(bootdev, strlen(bootdev), 0, &temp); - } - if (bootdv == NULL) { - printf("boot device: lookup '%s' failed.\n", bootdev); - 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(TRUE); - len = getsn(buf, sizeof(buf)); - - cnpollc(FALSE); - 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(TRUE); - len = getsn(buf, sizeof(buf)); - cnpollc(FALSE); - 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 { - - /* - * `root DEV swap DEV': honour rootdev/swdevt. - * rootdev/swdevt/mountroot already properly set. - */ - 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); - 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; - } - - /* - * 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; - - /* - * 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; -} - -/* - * find a device matching "name" and unit number - */ -struct device * -getdevunit(char *name, int unit) -{ - struct device *dev = TAILQ_FIRST(&alldevs); - char num[10], fullname[16]; - int lunit; - - /* compute length of name and decimal expansion of unit number */ - snprintf(num, sizeof num, "%d", unit); - lunit = strlen(num); - if (strlen(name) + lunit >= sizeof(fullname) - 1) - panic("config_attach: device name too long"); - - strlcpy(fullname, name, sizeof fullname); - strlcat(fullname, num, sizeof fullname); - - while (strcmp(dev->dv_xname, fullname) != 0) - if ((dev = TAILQ_NEXT(dev, dv_list)) == NULL) - return NULL; - - return dev; -} struct devmap { char *att; @@ -587,7 +218,6 @@ makebootdev(char *bp) return; } printf("Warning: boot device unrecognized: %s\n", bp); - return; } int @@ -609,3 +239,89 @@ getpno(char **cp) *cp = cx; return (val); } + + +/* + * find a device matching "name" and unit number + */ +struct device * +getdevunit(char *name, int unit) +{ + struct device *dev = TAILQ_FIRST(&alldevs); + char num[10], fullname[16]; + int lunit; + + /* compute length of name and decimal expansion of unit number */ + snprintf(num, sizeof num, "%d", unit); + lunit = strlen(num); + if (strlen(name) + lunit >= sizeof(fullname) - 1) + panic("config_attach: device name too long"); + + strlcpy(fullname, name, sizeof fullname); + strlcat(fullname, num, sizeof fullname); + + while (strcmp(dev->dv_xname, fullname) != 0) + if ((dev = TAILQ_NEXT(dev, dv_list)) == NULL) + return NULL; + + return dev; +} + +/* + * Now that we are fully operational, we can checksum the + * disks, and using some heuristics, hopefully are able to + * always determine the correct root disk. + */ +void +diskconf(void) +{ + dev_t temp; + int part; + + printf("bootpath: %s\n", bootpath); + makebootdev(bootpath); + + /* Lookup boot device from boot if not set by configuration */ + bootdv = parsedisk(bootdev, strlen(bootdev), 0, &temp); + if (bootdv == NULL) { + printf("boot device: lookup '%s' failed.\n", bootdev); + boothowto |= RB_ASKNAME; /* Don't Panic :-) */ + } else + printf("boot device: %s\n", bootdv->dv_xname); + + setroot(bootdv, part, RB_USERREQ); + dumpconf(); +} + +static struct { + char *name; + int maj; +} nam2blk[] = { + { "wd", 0 }, + { "sd", 2 }, + { "ofdisk", 4 }, + { "raid", 19 }, +}; + +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); +} diff --git a/sys/arch/mvme68k/mvme68k/autoconf.c b/sys/arch/mvme68k/mvme68k/autoconf.c index ee6d6ea4d72..2f3a77fee74 100644 --- a/sys/arch/mvme68k/mvme68k/autoconf.c +++ b/sys/arch/mvme68k/mvme68k/autoconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: autoconf.c,v 1.36 2006/11/28 16:56:50 dlg Exp $ */ +/* $OpenBSD: autoconf.c,v 1.37 2007/05/04 03:44:44 deraadt Exp $ */ /* * Copyright (c) 1995 Theo de Raadt @@ -90,13 +90,10 @@ #include <scsi/scsi_all.h> #include <scsi/scsiconf.h> +#include <dev/cons.h> -void setroot(void); int mainbus_print(void *, const char *); int mainbus_scan(struct device *, void *, void *); -int findblkmajor(struct device *); -struct device *getdisk(char *, int, int, dev_t *); -struct device *parsedisk(char *, int, int, dev_t *); extern void init_intrs(void); extern void dumpconf(void); @@ -189,8 +186,6 @@ mainbus_attach(parent, self, args) void cpu_configure() { - bootdv = NULL; /* set by device drivers (if found) */ - init_intrs(); extio = extent_create("extio", @@ -200,7 +195,10 @@ cpu_configure() if (config_rootfound("mainbus", NULL) == NULL) panic("autoconfig failed, no root"); - setroot(); + printf("boot device: %s\n", + (bootdv) ? bootdv->dv_xname : "<unknown>"); + + setroot(bootdv, bootpart, RB_USERREQ); dumpconf(); cold = 0; } @@ -267,283 +265,6 @@ unmapiodev(kva, size) #endif } -/* - * the rest of this file was adapted from Theo de Raadt's code in the - * sparc port to nuke the "options GENERIC" stuff. - */ - -struct nam2blk { - char *name; - int maj; -} nam2blk[] = { - { "sd", 4 }, - { "st", 7 }, - { "rd", 9 }, -}; - -int -findblkmajor(dv) - struct device *dv; -{ - char *name = dv->dv_xname; - register int 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); -} - -struct device * -getdisk(str, len, defpart, devp) - char *str; - int len, defpart; - dev_t *devp; -{ - register struct device *dv; - - if ((dv = parsedisk(str, len, defpart, devp)) == NULL) { - printf("use one of:"); - 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; -{ - register struct device *dv; - register 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; - - TAILQ_FOREACH(dv, &alldevs, dv_list) { - if (dv->dv_class == DV_DISK && - strcmp(str, dv->dv_xname) == 0) { - 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); -} - -/* - * 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, unit; - dev_t nrootdev, nswapdev = NODEV; - char buf[128]; - dev_t temp; -#if defined(NFSCLIENT) - extern char *nfsbootdevname; -#endif - - printf("boot device: %s\n", - (bootdv) ? bootdv->dv_xname : "<unknown>"); - - /* - * If 'swap generic' and we could not determine the 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 ? 'a' : ' '); - printf(": "); - len = getsn(buf, sizeof(buf)); - 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) { - bootdv = dv; - nswapdev = nrootdev; - goto gotswap; - } - } - dv = getdisk(buf, len, 0, &nrootdev); - if (dv) { - 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 = getsn(buf, sizeof(buf)); - 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 a disk. - * val[2] of the boot device is the partition number. - * Assume swap is on partition b. - */ - unit = bootdv->dv_unit; - rootdev = MAKEDISKDEV(majdev, unit, bootpart); - 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. - */ - return; - } - - switch (bootdv->dv_class) { -#if defined(NFSCLIENT) - case DV_IFNET: - mountroot = nfs_mountroot; - nfsbootdevname = bootdv->dv_xname; - return; -#endif -#if defined(FFS) - case DV_DISK: - mountroot = dk_mountroot; - majdev = major(rootdev); - unit = DISKUNIT(rootdev); - printf("root on %s%c\n", bootdv->dv_xname, - DISKPART(rootdev) + 'a'); - break; -#endif - 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) - return; - - /* - * 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; -} - void device_register(struct device *dev, void *aux) { @@ -592,3 +313,35 @@ device_register(struct device *dev, void *aux) } } } + +static struct { + char *name; + int maj; +} nam2blk[] = { + { "sd", 4 }, + { "st", 7 }, + { "rd", 9 }, +}; + +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); +} diff --git a/sys/arch/mvme88k/mvme88k/autoconf.c b/sys/arch/mvme88k/mvme88k/autoconf.c index 6c6a779f47e..5f41f436a6b 100644 --- a/sys/arch/mvme88k/mvme88k/autoconf.c +++ b/sys/arch/mvme88k/mvme88k/autoconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: autoconf.c,v 1.35 2006/11/28 16:56:50 dlg Exp $ */ +/* $OpenBSD: autoconf.c,v 1.36 2007/05/04 03:44:44 deraadt Exp $ */ /* * Copyright (c) 1998 Steve Murphree, Jr. * Copyright (c) 1996 Nivas Madhur @@ -58,11 +58,7 @@ * the machine. */ -struct device *parsedisk(char *, int, int, dev_t *); -void setroot(void); void dumpconf(void); -int findblkmajor(struct device *); -struct device *getdisk(char *, int, int, dev_t *); int get_target(int *, int *, int *); int cold = 1; /* 1 if still booting */ @@ -77,7 +73,6 @@ struct device *bootdv; /* set by device drivers (if found) */ void cpu_configure() { - if (config_rootfound("mainbus", "mainbus") == 0) panic("no mainbus found"); @@ -89,7 +84,11 @@ cpu_configure() */ set_psr(get_psr() & ~PSR_IND); spl0(); - setroot(); + + printf("boot device: %s\n", + (bootdv) ? bootdv->dv_xname : "<unknown>"); + + setroot(bootdv, bootpart, RB_USERREQ); dumpconf(); /* @@ -102,278 +101,6 @@ cpu_configure() cold = 0; } -struct nam2blk { - char *name; - int maj; -} nam2blk[] = { - { "sd", 4 }, - { "cd", 6 }, - { "rd", 7 }, -}; - -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[0].name)) == 0) - return (nam2blk[i].maj); - return (-1); -} - -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:"); - 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; - - TAILQ_FOREACH(dv, &alldevs, dv_list) { - if (dv->dv_class == DV_DISK && - strcmp(str, dv->dv_xname) == 0) { - 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); -} - -/* - * 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() -{ - struct swdevt *swp; - struct device *dv; - int len, majdev, unit; - dev_t nrootdev, nswapdev = NODEV; - char buf[128]; - dev_t temp; -#if defined(NFSCLIENT) - extern char *nfsbootdevname; -#endif - - printf("boot device: %s\n", - (bootdv) ? bootdv->dv_xname : "<unknown>"); - - /* - * If 'swap generic' and we could not determine the 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 ? 'a' : ' '); - printf(": "); - len = getsn(buf, sizeof(buf)); - 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) { - bootdv = dv; - nswapdev = nrootdev; - goto gotswap; - } - } - dv = getdisk(buf, len, 0, &nrootdev); - if (dv) { - 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 = getsn(buf, sizeof(buf)); - 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 a disk. - * val[2] of the boot device is the partition number. - * Assume swap is on partition b. - */ - unit = bootdv->dv_unit; - rootdev = MAKEDISKDEV(majdev, unit, bootpart); - 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. - */ - return; - } - - switch (bootdv->dv_class) { -#if defined(NFSCLIENT) - case DV_IFNET: - mountroot = nfs_mountroot; - nfsbootdevname = bootdv->dv_xname; - return; -#endif -#if defined(FFS) - case DV_DISK: - mountroot = dk_mountroot; - majdev = major(rootdev); - unit = DISKUNIT(rootdev); - printf("root on %s%c\n", bootdv->dv_xname, - DISKPART(rootdev) + 'a'); - break; -#endif - 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) - return; - - /* - * 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; -} - void device_register(struct device *dev, void *aux) { @@ -451,3 +178,35 @@ get_target(int *target, int *bus, int *lun) return (ENODEV); } } + +static struct { + char *name; + int maj; +} nam2blk[] = { + { "sd", 4 }, + { "cd", 6 }, + { "rd", 7 }, +}; + +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); +} diff --git a/sys/arch/mvmeppc/mvmeppc/autoconf.c b/sys/arch/mvmeppc/mvmeppc/autoconf.c index 9ecee0cc060..67d655b3c48 100644 --- a/sys/arch/mvmeppc/mvmeppc/autoconf.c +++ b/sys/arch/mvmeppc/mvmeppc/autoconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: autoconf.c,v 1.14 2005/12/27 18:31:10 miod Exp $ */ +/* $OpenBSD: autoconf.c,v 1.15 2007/05/04 03:44:44 deraadt Exp $ */ /* * Copyright (c) 1996, 1997 Per Fogelstrom * Copyright (c) 1995 Theo de Raadt @@ -37,7 +37,7 @@ * from: Utah Hdr: autoconf.c 1.31 91/01/21 * * from: @(#)autoconf.c 8.1 (Berkeley) 6/10/93 - * $Id: autoconf.c,v 1.14 2005/12/27 18:31:10 miod Exp $ + * $Id: autoconf.c,v 1.15 2007/05/04 03:44:44 deraadt Exp $ */ /* @@ -59,12 +59,7 @@ #include <machine/autoconf.h> #include <machine/bugio.h> -struct device *parsedisk(char *, int, int, dev_t *); -void setroot(void); extern void dumpconf(void); -int findblkmajor(struct device *); -char *findblkname(int); -struct device *getdisk(char *, int, int, dev_t *); struct device *getdevunit(char *, int); void diskconf(void); void calc_delayconst(void); /* clock.c */ @@ -107,7 +102,9 @@ cpu_configure() void diskconf() { - setroot(); + printf("boot device: %s\n", + (bootdv != NULL) ? bootdv->dv_xname : "<unknown>"); + setroot(bootdv, 0, RB_USERREQ); #if 0 dumpconf(); #endif @@ -159,306 +156,6 @@ dumpconf() } #endif -const struct nam2blk { - char *name; - int maj; -} nam2blk[] = { - { "wd", 0 }, /* 0 = wd */ - { "sd", 2 }, /* 2 = sd */ - { "ofdisk", 4 }, /* 4 = ofdisk */ - { "raid", 19 }, /* 19 = raid */ -}; - -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); -} - -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:"); - 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(" halt\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, part; - - if (len == 0) - return (NULL); - - if (len == 4 && strcmp(str, "halt") == 0) - boot(RB_HALT); - - cp = str + len - 1; - c = *cp; - if (c >= 'a' && (c - 'a') < MAXPARTITIONS) { - part = c - 'a'; - *cp = '\0'; - } else - part = defpart; - - TAILQ_FOREACH(dv, &alldevs, dv_list) { - 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); -} - -/* - * 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 -setroot() -{ - int majdev, unit, part, len; - dev_t temp; - struct swdevt *swp; - struct device *dv; - dev_t nrootdev, nswapdev = NODEV; - char buf[128]; -#if defined(NFSCLIENT) - extern char *nfsbootdevname; -#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); - } - - printf("boot device: %s\n", - (bootdv != NULL) ? bootdv->dv_xname : "<unknown>"); - - /* - * If 'swap generic' and we couldn't determine the 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 ? 'a' : ' '); - printf(": "); - len = getsn(buf, sizeof(buf)); - 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(": "); - len = getsn(buf, sizeof(buf)); - 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 { - /* - * `root DEV swap DEV': honour rootdev/swdevt. - * rootdev/swdevt/mountroot already properly set. - */ - return; - } - - switch (bootdv->dv_class) { -#if defined(NFSCLIENT) - case DV_IFNET: - mountroot = nfs_mountroot; - nfsbootdevname = bootdv->dv_xname; - return; -#endif -#if defined(FFS) - case DV_DISK: - mountroot = dk_mountroot; - majdev = major(rootdev); - unit = DISKUNIT(rootdev); - printf("root on %s%c\n", bootdv->dv_xname, - DISKPART(rootdev) + 'a'); - break; -#endif - 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) - return; - - /* - * 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; -} - /* * find a device matching "name" and unit number */ @@ -486,3 +183,36 @@ getdevunit(name, unit) } return dev; } + +const struct { + char *name; + int maj; +} nam2blk[] = { + { "wd", 0 }, + { "sd", 2 }, + { "ofdisk", 4 }, + { "raid", 19 }, +}; + +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); +} diff --git a/sys/arch/sgi/sgi/autoconf.c b/sys/arch/sgi/sgi/autoconf.c index 09cdd9c32d5..91c855fac46 100644 --- a/sys/arch/sgi/sgi/autoconf.c +++ b/sys/arch/sgi/sgi/autoconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: autoconf.c,v 1.11 2005/12/27 18:31:10 miod Exp $ */ +/* $OpenBSD: autoconf.c,v 1.12 2007/05/04 03:44:44 deraadt Exp $ */ /* * Copyright (c) 1996 Per Fogelstrom * Copyright (c) 1995 Theo de Raadt @@ -55,15 +55,14 @@ #include <sys/reboot.h> #include <sys/device.h> +#include <uvm/uvm_extern.h> + +#include <dev/cons.h> #include <machine/autoconf.h> #include <mips64/archtype.h> -struct device *parsedisk(char *, int, int, dev_t *); -void disk_configure(void); -void rootconf(void); +void diskconf(void); extern void dumpconf(void); -int findblkmajor(struct device *); -struct device * getdisk(char *, int, int, dev_t *); struct device *getdevunit(char *, int); const struct devmap *boot_findtype(char *); int makebootdev(const char *, int); @@ -94,7 +93,7 @@ struct device *bootdv = NULL; * This is done at boot time. */ void -cpu_configure() +cpu_configure(void) { (void)splhigh(); /* Set mask to what we intend. */ if (config_rootfound("mainbus", "mainbus") == 0) { @@ -103,300 +102,25 @@ cpu_configure() splinit(); /* Initialized, fire up interrupt system */ - md_diskconf = disk_configure; + md_diskconf = diskconf; cold = 0; } void -disk_configure() -{ - rootconf(); - dumpconf(); -} - -/* - * the rest of this file was influenced/copied from Theo de Raadt's - * code in the sparc port to nuke the "options GENERIC" stuff. - */ - -const struct nam2blk { - const char *name; - int maj; -} nam2blk[] = { - { "sd", 0 }, /* 0 = sd */ - { "wd", 4 }, /* 4 = wd */ -}; - -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[0].name)) == 0) - return (nam2blk[i].maj); - return (-1); -} - -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:"); - 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, 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; - - TAILQ_FOREACH(dv, &alldevs, dv_list) { - 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); -} - -/* - * 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() +diskconf(void) { - int majdev, mindev, unit, part, len; - dev_t temp; - struct swdevt *swp; - struct device *dv; - dev_t nrootdev, nswapdev = NODEV; - char buf[128]; - -#if defined(NFSCLIENT) - extern char *nfsbootdevname; -#endif - - if (boothowto & RB_DFLTROOT) - return; /* Boot compiled in */ + dev_t tmpdev; /* Lookup boot device from boot if not set by configuration */ - if (bootdv == NULL) { - bootdv = parsedisk(bootdev, strlen(bootdev), 0, &temp); - } - if (bootdv == NULL) { + if (bootdv == NULL) + bootdv = parsedisk(bootdev, strlen(bootdev), 0, &tmpdev); + if (bootdv == NULL) printf("boot device: lookup '%s' failed.\n", bootdev); - boothowto |= RB_ASKNAME; /* Don't Panic :-) */ - } - 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(": "); - len = getsn(buf, sizeof(buf)); -#ifdef DDB - if (len && strcmp(buf, "ddb") == 0) { - Debugger(); - continue; - } -#endif - 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(": "); - len = getsn(buf, sizeof(buf)); - 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 { - - /* - * `root DEV swap DEV': honour rootdev/swdevt. - * rootdev/swdevt/mountroot already properly set. - */ - 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); - 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; - } + else + printf("boot device: %s\n", bootdv->dv_xname); - /* - * 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; - - /* - * 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; + setroot(bootdv, 0, RB_USERREQ); + dumpconf(); } /* @@ -543,3 +267,34 @@ boot_getnr(const char *p, int *no) *no = *no * 10 + *p++ - '0'; return p; } + +static struct { + char *name; + int maj; +} nam2blk[] = { + { "sd", 0 }, /* 0 = sd */ + { "wd", 4 }, /* 4 = wd */ +}; + +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); +} diff --git a/sys/arch/solbourne/solbourne/autoconf.c b/sys/arch/solbourne/solbourne/autoconf.c index 5b979f5ac61..aa18aba42ba 100644 --- a/sys/arch/solbourne/solbourne/autoconf.c +++ b/sys/arch/solbourne/solbourne/autoconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: autoconf.c,v 1.5 2006/04/15 17:36:14 miod Exp $ */ +/* $OpenBSD: autoconf.c,v 1.6 2007/05/04 03:44:44 deraadt Exp $ */ /* OpenBSD: autoconf.c,v 1.64 2005/03/23 17:10:24 miod Exp */ /* @@ -94,11 +94,6 @@ int fbnode; /* node ID of ROM's console frame buffer */ extern int kgdb_debug_panic; #endif -void setroot(void); -static int getstr(char *, int); -int findblkmajor(struct device *); -char *findblkname(int); -static struct device *getdisk(char *, int, int, dev_t *); static int mbprint(void *, const char *); void sync_crash(void); int mainbus_match(struct device *, void *, void *); @@ -114,10 +109,6 @@ char **prom_argv; char **prom_environ; vaddr_t prom_data; -#ifdef RAMDISK_HOOKS -static struct device fakerdrootdev = { DV_DISK, {}, NULL, 0, "rd0", NULL }; -#endif - /* * locore.s code calls bootstrap() just before calling main(), after double * mapping the kernel to high memory and setting up the trap base register. @@ -251,7 +242,6 @@ bootpath_build() } } - /* * save or read a bootpath pointer from the boothpath store. * @@ -287,6 +277,8 @@ cpu_configure() struct confargs oca; register int node = 0; register char *cp; + struct bootpath *bp; + struct device *bootdv; int s; extern struct user *proc0paddr; @@ -317,7 +309,10 @@ cpu_configure() * Configure swap area and related system * parameter based on device(s) used. */ - setroot(); + bp = nbootpath == 0 ? NULL : &bootpath[nbootpath-1]; + bootdv = (bp == NULL) ? NULL : bp->dev; + + setroot(bootdv, bp->val[2], RB_USERREQ | RB_HALT); dumpconf(); cold = 0; @@ -563,382 +558,6 @@ callrom() #endif } -struct nam2blk { - char *name; - int maj; -} nam2blk[] = { - { "sd", 7 }, - { "st", 11 }, - { "fd", 16 }, - { "rd", 17 }, - { "cd", 18 }, -}; - -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; -{ - register struct device *dv; - - if ((dv = parsedisk(str, len, defpart, devp)) == NULL) { - printf("use one of:"); -#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; -{ - register struct device *dv; - register 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); -} - -/* - * 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, 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 - - 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 > 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 == 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; - } -} - -static int -getstr(cp, size) - register char *cp; - register int size; -{ - register char *lp; - register int c; - register 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; - } - } -} - - /* * find a device matching "name" and unit number */ @@ -971,3 +590,37 @@ void device_register(struct device *dev, void *aux) { } + +struct nam2blk { + char *name; + int maj; +} nam2blk[] = { + { "sd", 7 }, + { "st", 11 }, + { "fd", 16 }, + { "rd", 17 }, + { "cd", 18 }, +}; + +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)) == 0) + 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); +} diff --git a/sys/arch/sparc/include/autoconf.h b/sys/arch/sparc/include/autoconf.h index a7aefd81e28..7e2a690d1af 100644 --- a/sys/arch/sparc/include/autoconf.h +++ b/sys/arch/sparc/include/autoconf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: autoconf.h,v 1.15 2005/07/08 12:42:57 miod Exp $ */ +/* $OpenBSD: autoconf.h,v 1.16 2007/05/04 03:44:44 deraadt Exp $ */ /* $NetBSD: autoconf.h,v 1.20 1997/05/24 20:03:03 pk Exp $ */ /* @@ -190,9 +190,6 @@ struct bootpath { struct bootpath *bootpath_store(int, struct bootpath *); int sd_crazymap(int); -/* Parse a disk string into a dev_t, return device struct pointer */ -struct device *parsedisk(char *, int, int, dev_t *); - void bootstrap(void); int firstchild(int); int nextsibling(int); diff --git a/sys/arch/sparc/sparc/autoconf.c b/sys/arch/sparc/sparc/autoconf.c index 5e1b2c5b2e8..f21afa87351 100644 --- a/sys/arch/sparc/sparc/autoconf.c +++ b/sys/arch/sparc/sparc/autoconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: autoconf.c,v 1.76 2007/04/30 18:37:00 deraadt Exp $ */ +/* $OpenBSD: autoconf.c,v 1.77 2007/05/04 03:44:44 deraadt Exp $ */ /* $NetBSD: autoconf.c,v 1.73 1997/07/29 09:41:53 fair Exp $ */ /* @@ -102,12 +102,7 @@ extern int kgdb_debug_panic; #endif static int rootnode; -void setroot(void); static char *str2hex(char *, int *); -static int getstr(char *, int); -int findblkmajor(struct device *); -char *findblkname(int); -static struct device *getdisk(char *, int, int, dev_t *); static int mbprint(void *, const char *); static void crazymap(char *, int *); void sync_crash(void); @@ -122,10 +117,6 @@ static void bootpath_print(struct bootpath *); int search_prom(int, char *); char mainbus_model[30]; -#ifdef RAMDISK_HOOKS -static struct device fakerdrootdev = { DV_DISK, {}, NULL, 0, "rd0", NULL }; -#endif - /* Translate SBus interrupt level to processor IPL */ int intr_sbus2ipl_4c[] = { 0, 1, 2, 3, 5, 7, 8, 9 @@ -372,8 +363,6 @@ bootpath_build() if (cp != NULL) bootpath_fake(bp, cp); - bootpath_print(bootpath); - /* Setup pointer to boot flags */ cp = (*promvec->pv_v0bootargs)->ba_argv[1]; if (cp == NULL || *cp != '-') @@ -418,8 +407,6 @@ bootpath_build() } bp->name[0] = 0; - bootpath_print(bootpath); - /* Setup pointer to boot flags */ cp = *promvec->pv_v2bootargs.v2_bootargs; if (cp == NULL) @@ -762,6 +749,8 @@ cpu_configure() struct confargs oca; register int node = 0; register char *cp; + struct bootpath *bp; + struct device *bootdv; int s; extern struct user *proc0paddr; @@ -852,7 +841,12 @@ cpu_configure() * Configure swap area and related system * parameter based on device(s) used. */ - setroot(); + bootpath_print(bootpath); + + bp = nbootpath == 0 ? NULL : &bootpath[nbootpath-1]; + bootdv = (bp == NULL) ? NULL : bp->dev; + + setroot(bootdv, bp->val[2], RB_USERREQ | RB_HALT); dumpconf(); cold = 0; @@ -1743,423 +1737,6 @@ callrom() promvec->pv_abort(); } -#if 0 /* Unused */ -dev_t bootdev; -#endif - -struct nam2blk { - char *name; - int maj; -} nam2blk[] = { - { "xy", 3 }, - { "sd", 7 }, - { "xd", 10 }, - { "st", 11 }, - { "fd", 16 }, - { "rd", 17 }, - { "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; -{ - register 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; -{ - register struct device *dv; - register 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); -} - -/* - * 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, 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 - - 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"); - - if (len == 4 && strncmp(buf, "exit", 4) == 0) - boot(RB_USERREQ | RB_HALT); - 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; - } -} - -static int -getstr(cp, size) - register char *cp; - register int size; -{ - register char *lp; - register int c; - register 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; - } - } -} - - -/* - * find a device matching "name" and unit number - */ -struct device * -getdevunit(name, unit) - char *name; - int unit; -{ - struct device *dev = TAILQ_FIRST(&alldevs); - char num[10], fullname[16]; - int lunit; - - /* compute length of name and decimal expansion of unit number */ - snprintf(num, sizeof num, "%d", unit); - lunit = strlen(num); - if (strlen(name) + lunit >= sizeof(fullname) - 1) - panic("config_attach: device name too long"); - - strlcpy(fullname, name, sizeof fullname); - strlcat(fullname, num, sizeof fullname); - - while (strcmp(dev->dv_xname, fullname) != 0) { - if ((dev = TAILQ_NEXT(dev, dv_list)) == NULL) - return NULL; - } - return dev; -} - /* * find the boot device (if it was a disk). we must check to see if * unit info in saved bootpath structure matches unit info in our softc. @@ -2224,3 +1801,68 @@ device_register(struct device *dev, void *aux) } } } + +/* + * find a device matching "name" and unit number + */ +struct device * +getdevunit(name, unit) + char *name; + int unit; +{ + struct device *dev = TAILQ_FIRST(&alldevs); + char num[10], fullname[16]; + int lunit; + + /* compute length of name and decimal expansion of unit number */ + snprintf(num, sizeof num, "%d", unit); + lunit = strlen(num); + if (strlen(name) + lunit >= sizeof(fullname) - 1) + panic("config_attach: device name too long"); + + strlcpy(fullname, name, sizeof fullname); + strlcat(fullname, num, sizeof fullname); + + while (strcmp(dev->dv_xname, fullname) != 0) { + if ((dev = TAILQ_NEXT(dev, dv_list)) == NULL) + return NULL; + } + return dev; +} + +static struct { + char *name; + int maj; +} nam2blk[] = { + { "xy", 3 }, + { "sd", 7 }, + { "xd", 10 }, + { "st", 11 }, + { "fd", 16 }, + { "rd", 17 }, + { "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); +} 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); +} diff --git a/sys/arch/vax/conf/files.vax b/sys/arch/vax/conf/files.vax index 2d25be43466..a54336d5e95 100644 --- a/sys/arch/vax/conf/files.vax +++ b/sys/arch/vax/conf/files.vax @@ -1,4 +1,4 @@ -# $OpenBSD: files.vax,v 1.41 2007/02/05 05:46:13 miod Exp $ +# $OpenBSD: files.vax,v 1.42 2007/05/04 03:44:44 deraadt Exp $ # $NetBSD: files.vax,v 1.60 1999/08/27 20:04:32 ragge Exp $ # # new style config file for vax architecture @@ -376,7 +376,6 @@ file arch/vax/vax/sgmap.c file arch/vax/vax/vm_machdep.c file arch/vax/vax/findcpu.c file arch/vax/vax/random.s -file arch/vax/vax/rootfil.c file arch/vax/vax/autoconf.c file arch/vax/vax/mutex.c file arch/vax/vax/in_cksum.c inet diff --git a/sys/arch/vax/vax/autoconf.c b/sys/arch/vax/vax/autoconf.c index 8741725e6af..86b2915c717 100644 --- a/sys/arch/vax/vax/autoconf.c +++ b/sys/arch/vax/vax/autoconf.c @@ -1,7 +1,9 @@ -/* $OpenBSD: autoconf.c,v 1.24 2006/11/28 16:56:50 dlg Exp $ */ +/* $OpenBSD: autoconf.c,v 1.25 2007/05/04 03:44:44 deraadt Exp $ */ /* $NetBSD: autoconf.c,v 1.45 1999/10/23 14:56:05 ragge Exp $ */ /* + * Copyright (c) 1988 University of Utah. + * Copyright (c) 1982, 1986, 1990 The Regents of the University of California. * Copyright (c) 1994 Ludd, University of Lule}, Sweden. * All rights reserved. * @@ -36,6 +38,7 @@ #include <sys/systm.h> #include <sys/device.h> #include <sys/reboot.h> +#include <sys/disklabel.h> #include <sys/conf.h> #include <uvm/uvm_extern.h> @@ -52,6 +55,8 @@ #include <machine/clock.h> #include <machine/rpb.h> +#include <dev/cons.h> + #include "led.h" #include <vax/vax/gencons.h> @@ -60,20 +65,25 @@ void cpu_dumpconf(void); /* machdep.c */ void gencnslask(void); -void setroot(void); /* rootfil.c */ +void diskconf(void); struct cpu_dep *dep_call; -extern struct device *bootdv; int mastercpu; /* chief of the system */ +struct device *bootdv; +int booted_partition; /* defaults to 0 (aka 'a' partition */ + void cpu_configure() { if (config_rootfound("mainbus", NULL) == NULL) panic("mainbus not configured"); - setroot(); + printf("boot device: %s\n", + bootdv ? bootdv->dv_xname : "<unknown>"); + + setroot(bootdv, booted_partition, RB_USERREQ); cpu_dumpconf(); /* @@ -438,3 +448,45 @@ booted_hd(struct device *dev, void *aux) return 1; } #endif + +struct ngcconf { + struct cfdriver *ng_cf; + dev_t ng_root; +}; + +struct nam2blk { + char *name; + int maj; +} nam2blk[] = { + { "ra", 9 }, + { "rx", 12 }, + { "rl", 14 }, + { "hd", 19 }, + { "sd", 20 }, + { "rd", 23 }, + { "raid", 25 }, + { "cd", 61 }, +}; + +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); +} diff --git a/sys/arch/vax/vax/rootfil.c b/sys/arch/vax/vax/rootfil.c deleted file mode 100644 index 69e3a0392c7..00000000000 --- a/sys/arch/vax/vax/rootfil.c +++ /dev/null @@ -1,411 +0,0 @@ -/* $OpenBSD: rootfil.c,v 1.19 2006/11/06 20:28:23 miod Exp $ */ -/* $NetBSD: rootfil.c,v 1.14 1996/10/13 03:35:58 christos Exp $ */ - -/* - * Copyright (c) 1988 University of Utah. - * Copyright (c) 1982, 1986, 1990 The Regents of the University of California. - * Copyright (c) 1994 Ludd, University of Lule}, Sweden. - * All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * from: Utah Hdr: machdep.c 1.63 91/04/24 - * - * @(#)machdep.c 7.16 (Berkeley) 6/3/91 - */ - /* All bugs are subject to removal without further notice */ - -#include <sys/param.h> -#include <sys/systm.h> -#include <sys/buf.h> -#include <sys/mbuf.h> -#include <sys/reboot.h> -#include <sys/conf.h> -#include <sys/device.h> -#include <sys/disklabel.h> - -#include <dev/cons.h> - -#include <machine/macros.h> -#include <machine/nexus.h> -#include <machine/sid.h> -#include <machine/disklabel.h> -#include <machine/pte.h> -#include <machine/cpu.h> -#include <machine/rpb.h> - -#include "hp.h" -#include "ra.h" -#include "sd.h" -#include "asc.h" - -void setroot(void); -void diskconf(void); -static int getstr(char *, int); -struct device *parsedisk(char *, int, int, dev_t *); -static struct device *getdisk(char *, int, int, dev_t *); -int findblkmajor(struct device *); -char *findblkname(int); - -struct ngcconf { - struct cfdriver *ng_cf; - dev_t ng_root; -}; - -int findblkmajor(struct device *); - -struct device *bootdv = NULL; -int booted_partition; /* defaults to 0 (aka 'a' partition */ - -extern dev_t rootdev, dumpdev; - -#ifdef RAMDISK_HOOKS -static struct device fakerdrootdev = { DV_DISK, {}, NULL, 0, "rd0", NULL }; -#endif - -/* - * 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 -setroot() -{ - struct swdevt *swp; - int len, majdev, unit, part = 0; - dev_t nrootdev, nswapdev, temp; - extern int boothowto; - struct device *dv; - char buf[128]; -#if defined(NFSCLIENT) - extern char *nfsbootdevname; -#endif - - if (rpb.rpb_base != (void *)-1) { -#if DEBUG - printf("booted from type %d unit %d csr 0x%lx adapter %lx slave %d\n", - rpb.devtyp, rpb.unit, rpb.csrphy, rpb.adpphy, rpb.slave); -#endif - bootdev = MAKEBOOTDEV(rpb.devtyp, 0, 0, rpb.unit, 0); - } - -#ifdef RAMDISK_HOOKS - bootdv = &fakerdrootdev; -#endif - - printf("booted from device: %s\n", - bootdv ? bootdv->dv_xname : "<unknown>"); - - if (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 - ? booted_partition + 'a' : ' '); - printf(": "); - len = getstr(buf, sizeof(buf)); - 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, booted_partition, &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 == 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 = booted_partition; - 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[] = { - { "ra", 9 }, - { "rx", 12 }, - { "rl", 14 }, - { "hd", 19 }, - { "sd", 20 }, - { "rd", 23 }, - { "raid", 25 }, - { "cd", 61 }, -}; - -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:"); -#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(char *buf, int size) { - int len; - cnpollc(1); - len = getsn(buf, size); - cnpollc(0); - return (len); -} 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 */ |