diff options
author | Jason Downs <downsj@cvs.openbsd.org> | 1999-08-16 09:43:12 +0000 |
---|---|---|
committer | Jason Downs <downsj@cvs.openbsd.org> | 1999-08-16 09:43:12 +0000 |
commit | d179eff9bd4cb760c09a5931364ce2c6dac77ecf (patch) | |
tree | 202b2b77f440ffbf0d160763f8993756a1e7153e /sys/arch/hp300/stand/cdboot | |
parent | ac1b38ac019548d858278911a2672d18a25d17f5 (diff) |
Implement real CD booting, aka SYS_CDBOOT, the LIF file small enough to
fit in the begining of an ISO9660 image...
Diffstat (limited to 'sys/arch/hp300/stand/cdboot')
-rw-r--r-- | sys/arch/hp300/stand/cdboot/Makefile | 37 | ||||
-rw-r--r-- | sys/arch/hp300/stand/cdboot/cdboot.c | 99 | ||||
-rw-r--r-- | sys/arch/hp300/stand/cdboot/conf.c | 117 | ||||
-rw-r--r-- | sys/arch/hp300/stand/cdboot/cons.c | 92 | ||||
-rw-r--r-- | sys/arch/hp300/stand/cdboot/devopen.c | 254 |
5 files changed, 599 insertions, 0 deletions
diff --git a/sys/arch/hp300/stand/cdboot/Makefile b/sys/arch/hp300/stand/cdboot/Makefile new file mode 100644 index 00000000000..684f16f8ed6 --- /dev/null +++ b/sys/arch/hp300/stand/cdboot/Makefile @@ -0,0 +1,37 @@ +# $OpenBSD: Makefile,v 1.1 1999/08/16 09:43:08 downsj Exp $ + +PROG= cdboot + +NOMAN= + +.PATH: ${.CURDIR}/../uboot + +CFLAGS= -O2 -msoft-float -I${.CURDIR}/../include \ + -I${.CURDIR}/../libsa -I${.CURDIR}/../.. -I${.CURDIR}/../../.. \ + -I${.CURDIR}/../../../.. + +AFLAGS= -x assembler-with-cpp -traditional-cpp -I${.CURDIR}/../include \ + -I${.CURDIR}/../libsa -I${.CURDIR}/../.. -I${.CURDIR}/../../.. \ + -I${.CURDIR}/../../../.. + +SRCS= srt0.S cdboot.c clock.c conf.c cons.c devopen.c + +LIBS= ${LIBCOMMON} ${LIBSA} ${LIBZ} ${LIBKERN} + +${OBJS}: ${.CURDIR}/../Makefile.inc + +CLEANFILES+= cdboot.lif + +cdboot.lif: cdboot + ${MKBOOT_PROG} cdboot $@ + +cdboot: ${OBJS} ${LIBS} + ${LD} -N -T ${RELOC} -e begin ${OBJS} ${LIBS} -o $@ + @size $@ + @echo $@ total size may not exceed 30000 bytes + +install: cdboot.lif cdboot.raw ${MKBOOT_PROG} + ${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m 444 cdboot.lif \ + ${DESTDIR}/usr/mdec + +.include <bsd.prog.mk> diff --git a/sys/arch/hp300/stand/cdboot/cdboot.c b/sys/arch/hp300/stand/cdboot/cdboot.c new file mode 100644 index 00000000000..a8aa63ccefe --- /dev/null +++ b/sys/arch/hp300/stand/cdboot/cdboot.c @@ -0,0 +1,99 @@ +/* $OpenBSD: cdboot.c,v 1.1 1999/08/16 09:43:08 downsj Exp $ */ +/* $NetBSD: uboot.c,v 1.3 1997/04/27 21:17:13 thorpej Exp $ */ + +/*- + * Copyright (c) 1982, 1986, 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. 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. + * + * @(#)boot.c 8.1 (Berkeley) 6/10/93 + */ + +#include <sys/param.h> +#include <sys/reboot.h> +#include <machine/exec.h> +#include <a.out.h> + +#include <lib/libsa/stand.h> + +#include "samachdep.h" + +/* + * Boot program... bits in `howto' determine whether boot stops to + * ask for system name. Boot device is derived from ROM provided + * information. + */ + +char line[100]; + +extern u_int opendev; +extern char *lowram; +extern int noconsole; + +extern const char version[]; + +/* + * XXX UFS accepts a /, NFS doesn't. + */ +char *name; +char *names[] = { + "bsd.rd", "bsd", "obsd", "bsd.old" +}; +#define NUMNAMES (sizeof(names) / sizeof(char *)) + +static int bdev, badapt, bctlr, bunit, bpart; + +main() +{ + int currname = 0; + + printf("\n>> OpenBSD [%dKB] CDROM BOOT %s HP9000/%s CPU\n", + (__LDPGSZ / 1024), version, getmachineid()); + printf(">> Enter \"reset\" to reset system.\n"); + + bdev = B_TYPE(bootdev); + badapt = B_ADAPTOR(bootdev); + bctlr = B_CONTROLLER(bootdev); + bunit = B_UNIT(bootdev); + bpart = B_PARTITION(bootdev); + + for (;;) { + name = names[currname++]; + if (currname == NUMNAMES) + currname = 0; + + howto = RB_SINGLE; + + printf(": %s\n", name); + + exec(name, lowram, howto); + printf("boot: %s\n", strerror(errno)); + } +} diff --git a/sys/arch/hp300/stand/cdboot/conf.c b/sys/arch/hp300/stand/cdboot/conf.c new file mode 100644 index 00000000000..8dc30a69698 --- /dev/null +++ b/sys/arch/hp300/stand/cdboot/conf.c @@ -0,0 +1,117 @@ +/* $OpenBSD: conf.c,v 1.1 1999/08/16 09:43:08 downsj Exp $ */ +/* $NetBSD: conf.c,v 1.12 1996/10/14 07:29:15 thorpej Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. 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. + * + * @(#)conf.c 8.1 (Berkeley) 6/10/93 + */ + +#include <sys/param.h> + +#include <lib/libsa/stand.h> + +#include "samachdep.h" + +#include <lib/libsa/cd9660.h> + +int debug = 0; /* XXX */ + +/* + * Device configuration + */ +int sdstrategy __P((void *, int, daddr_t, size_t, void *, size_t *)); +int sdopen __P((struct open_file *, ...)); +int sdclose __P((struct open_file *)); +#define sdioctl noioctl + +#define xxstrategy \ + (int (*) __P((void *, int, daddr_t, size_t, void *, size_t *)))nullsys +#define xxopen (int (*) __P((struct open_file *, ...)))nodev +#define xxclose (int (*) __P((struct open_file *)))nullsys + +struct devsw devsw[] = { + { "??", xxstrategy, xxopen, xxclose, noioctl }, /*0*/ + { "??", xxstrategy, xxopen, xxclose, noioctl }, /*1*/ + { "??", xxstrategy, xxopen, xxclose, noioctl }, /*2*/ + { "??", xxstrategy, xxopen, xxclose, noioctl }, /*3*/ + { "sd", sdstrategy, sdopen, sdclose, sdioctl }, /*4*/ +}; +int ndevs = (sizeof(devsw) / sizeof(devsw[0])); + +/* + * Physical unit/lun detection. + */ +int punitzero __P((int, int, int *)); + +int +punitzero(ctlr, slave, punit) + int ctlr, slave, *punit; +{ + + *punit = 0; + return (0); +} + +#define xxpunit punitzero +#define sdpunit punitzero + +struct punitsw punitsw[] = { + { xxpunit }, + { xxpunit }, + { xxpunit }, + { xxpunit }, + { sdpunit }, +}; +int npunit = (sizeof(punitsw) / sizeof(punitsw[0])); + +/* + * Filesystem configuration + */ +struct fs_ops file_system_cd9660[] = { + { cd9660_open, cd9660_close, cd9660_read, cd9660_write, cd9660_seek, + cd9660_stat }, +}; + +struct fs_ops file_system[2]; +int nfsys = 1; /* default; changed per device type. */ + + +/* + * Inititalize controllers + * + * XXX this should be a table + */ +void ctlrinit() +{ + scsiinit(); +} diff --git a/sys/arch/hp300/stand/cdboot/cons.c b/sys/arch/hp300/stand/cdboot/cons.c new file mode 100644 index 00000000000..944daf3c5e2 --- /dev/null +++ b/sys/arch/hp300/stand/cdboot/cons.c @@ -0,0 +1,92 @@ +/* $OpenBSD: cons.c,v 1.1 1999/08/16 09:43:08 downsj Exp $ */ +/* $NetBSD: cons.c,v 1.2 1997/05/12 07:44:53 thorpej Exp $ */ + +/* + * Copyright (c) 1988 University of Utah. + * Copyright (c) 1990, 1993 + * The Regents of the University of California. 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. 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: cons.c 1.7 92/02/28 + * + * @(#)cons.c 8.1 (Berkeley) 6/10/93 + */ + +#include <sys/param.h> +#include <dev/cons.h> + +#include "samachdep.h" + + +int curcons_scode; /* select code of device currently being probed */ +int cons_scode; /* final select code of console device */ + +struct consdev *cn_tab; +int noconsole; +extern int userom; +extern int donottwiddle; /* from libsa */ + +void +cninit() +{ + cn_tab = NULL; + noconsole = 1; + cons_scode = 256; /* larger than last valid select code */ + userom = 1; + donottwiddle = 1; +} + +int +cngetc() +{ + return(0); +} + +int +cnputc(c) + int c; +{ + romputchar(c); + return(0); +} + +int +putchar(c) + int c; +{ + cnputc(c); + if (c == '\n') + cnputc('\r'); + return(0); +} diff --git a/sys/arch/hp300/stand/cdboot/devopen.c b/sys/arch/hp300/stand/cdboot/devopen.c new file mode 100644 index 00000000000..3a93b1bf9b9 --- /dev/null +++ b/sys/arch/hp300/stand/cdboot/devopen.c @@ -0,0 +1,254 @@ +/* $OpenBSD: devopen.c,v 1.1 1999/08/16 09:43:08 downsj Exp $ */ +/* $NetBSD: devopen.c,v 1.7 1996/10/14 07:31:47 thorpej Exp $ */ + +/*- + * Copyright (c) 1996 Jason R. Thorpe. All rights reserved. + * Copyright (c) 1993 John Brezak + * All rights reserved. + * + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `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 AUTHOR 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. + */ + +#include <sys/param.h> +#include <sys/reboot.h> + +#include <lib/libsa/stand.h> + +#include "samachdep.h" + +u_int opendev; + +#define ispart(c) ((c) >= 'a' && (c) <= 'h') + +atoi(char *cp) +{ + int val = 0; + while(isdigit(*cp)) + val = val * 10 + (*cp++ - '0'); + return(val); +} + +usage() +{ + printf("\ +Usage: device(adaptor, controller, drive, partition)file\n\ + <device><unit><partitionletter>:file\n\ +"); +} + +devlookup(d, len) + const char *d; + int len; +{ + struct devsw *dp = devsw; + int i; + + for (i = 0; i < ndevs; i++, dp++) { + if (dp->dv_name && strncmp(dp->dv_name, d, len) == 0) { + /* + * Set the filesystem and startup up according to the device + * being opened. + */ + switch (i) { + case 4: /* sd - only supports cd9660 */ + bcopy(file_system_cd9660, file_system, sizeof(struct fs_ops)); + break; + + case 0: /* ct - not supported */ + case 2: /* hd - not supported */ + case 6: /* le - not supported */ + default: + /* Agh! What happened?! */ + goto bad; + } + return(i); + } + } + + bad: + printf("No such device - Configured devices are:\n"); + for (dp = devsw, i = 0; i < ndevs; i++, dp++) + if (dp->dv_name) + printf(" %s", dp->dv_name); + printf("\n"); + errno = ENODEV; + return(-1); +} + +/* + * Parse a device spec in one of two forms. + * + * dev(adapt, ctlr, unit, part)file + * [A-Za-z]*[0-9]*[A-Za-z]:file + * dev unit part + */ +devparse(fname, dev, adapt, ctlr, unit, part, file) + const char *fname; + int *dev, *adapt, *ctlr, *unit, *part; + char **file; +{ + int *argp, i; + char *s, *args[4]; + + /* get device name and make lower case */ + for (s = (char *)fname; *s && *s != '/' && *s != ':' && *s != '('; s++) + if (isupper(*s)) *s = tolower(*s); + + /* first form */ + if (*s == '(') { + /* lookup device and get index */ + if ((*dev = devlookup(fname, s - fname)) < 0) + goto baddev; + + /* tokenize device ident */ + args[0] = ++s; + for (args[0] = s, i = 1; *s && *s != ')'; s++) { + if (*s == ',') + args[i++] = ++s; + } + switch(i) { + case 4: + *adapt = atoi(args[0]); + *ctlr = atoi(args[1]); + *unit = atoi(args[2]); + *part = atoi(args[3]); + break; + case 3: + *ctlr = atoi(args[0]); + *unit = atoi(args[1]); + *part = atoi(args[2]); + break; + case 2: + *unit = atoi(args[0]); + *part = atoi(args[1]); + break; + case 1: + *part = atoi(args[0]); + break; + case 0: + break; + } + *file = ++s; + } + + /* second form */ + else if (*s == ':') { + int temp; + + /* isolate device */ + for (s = (char *)fname; *s != ':' && !isdigit(*s); s++); + + /* lookup device and get index */ + if ((*dev = devlookup(fname, s - fname)) < 0) + goto baddev; + + /* isolate unit */ + if ((temp = atoi(s)) > 255) + goto bad; + *adapt = temp / 8; + *ctlr = temp % 8; + for (; isdigit(*s); s++); + + /* translate partition */ + if (!ispart(*s)) + goto bad; + + *part = *s++ - 'a'; + if (*s != ':') + goto bad; + *file = ++s; + } + + /* no device present */ + else + *file = (char *)fname; + + /* return the remaining unparsed part as the file to boot */ + return(0); + + bad: + usage(); + + baddev: + return(-1); +} + + +devopen(f, fname, file) + struct open_file *f; + const char *fname; + char **file; +{ + int n, error; + int dev, adapt, ctlr, unit, part; + struct devsw *dp = &devsw[0]; + + dev = B_TYPE(bootdev); + adapt = B_ADAPTOR(bootdev); + ctlr = B_CONTROLLER(bootdev); + unit = B_UNIT(bootdev); + part = B_PARTITION(bootdev); + + if (error = devparse(fname, &dev, &adapt, &ctlr, &unit, &part, file)) + return(error); + + /* + * Set up filesystem type based on what device we're opening. + */ + switch (dev) { + case 4: /* sd - only supports cd9660 */ + bcopy(file_system_cd9660, file_system, sizeof(struct fs_ops)); + break; + + case 0: /* ct - not supported */ + case 2: /* hd - not supported */ + case 6: /* le - not supported */ + default: + /* XXX what else should we do here? */ + printf("WARNING: BOGUS BOOT DEV TYPE 0x%x!\n", dev); + return (EIO); + } + + dp = &devsw[dev]; + + if (!dp->dv_open) + return(ENODEV); + + f->f_dev = dp; + + if ((error = (*dp->dv_open)(f, adapt, ctlr, part)) == 0) { + if ((error = + (*punitsw[dev].p_punit)(adapt, ctlr, &unit)) != 0) { + goto bad; + } + opendev = MAKEBOOTDEV(dev, adapt, ctlr, unit, part); + return(0); + } + + bad: + printf("%s(%d,%d,%d,%d): %s\n", devsw[dev].dv_name, + adapt, ctlr, unit, part, strerror(error)); + + return(error); +} |