diff options
author | Dale Rahn <drahn@cvs.openbsd.org> | 2007-06-13 02:17:33 +0000 |
---|---|---|
committer | Dale Rahn <drahn@cvs.openbsd.org> | 2007-06-13 02:17:33 +0000 |
commit | b80ad0b3ac0ae856697de4144f0b147863887fce (patch) | |
tree | 48bf8a762e092a891f152df0817e8f140600cc9d | |
parent | b6beaff152c22af1b998cf05c5a1fa0c8d9f3e0b (diff) |
Switch macppc to the interactive bootloader in stand/boot.
Much more useable on serial console systems.
-rw-r--r-- | sys/arch/macppc/stand/Locore.c | 125 | ||||
-rw-r--r-- | sys/arch/macppc/stand/boot.mac/Makefile | 12 | ||||
-rw-r--r-- | sys/arch/macppc/stand/conf.c | 37 | ||||
-rw-r--r-- | sys/arch/macppc/stand/libsa.h | 21 | ||||
-rw-r--r-- | sys/arch/macppc/stand/main.c (renamed from sys/arch/macppc/stand/boot.c) | 130 | ||||
-rw-r--r-- | sys/arch/macppc/stand/ofdev.c | 94 | ||||
-rw-r--r-- | sys/arch/macppc/stand/ofwboot/Makefile | 10 | ||||
-rw-r--r-- | sys/stand/boot/boot.c | 4 | ||||
-rw-r--r-- | sys/stand/boot/cmd.h | 5 |
9 files changed, 274 insertions, 164 deletions
diff --git a/sys/arch/macppc/stand/Locore.c b/sys/arch/macppc/stand/Locore.c index 0ba69b57d03..bcec257ed36 100644 --- a/sys/arch/macppc/stand/Locore.c +++ b/sys/arch/macppc/stand/Locore.c @@ -1,4 +1,4 @@ -/* $OpenBSD: Locore.c,v 1.11 2006/12/05 20:30:26 gwk Exp $ */ +/* $OpenBSD: Locore.c,v 1.12 2007/06/13 02:17:32 drahn Exp $ */ /* $NetBSD: Locore.c,v 1.1 1997/04/16 20:29:11 thorpej Exp $ */ /* @@ -34,6 +34,8 @@ #include <lib/libsa/stand.h> #include <macppc/stand/openfirm.h> +#include <dev/cons.h> + /* #include "machine/cpu.h" @@ -215,35 +217,6 @@ OF_getprop(int handle, char *prop, void *buf, int buflen) return args.size; } -#ifdef __notyet__ /* Has a bug on FirePower */ -int -OF_setprop(int handle, char *prop, void *buf, int len) -{ - static struct { - char *name; - int nargs; - int nreturns; - int phandle; - char *prop; - void *buf; - int len; - int size; - } args = { - "setprop", - 4, - 1, - }; - - args.phandle = handle; - args.prop = prop; - args.buf = buf; - args.len = len; - if (openfirmware(&args) == -1) - return -1; - return args.size; -} -#endif - int OF_open(char *dname) { @@ -375,16 +348,6 @@ OF_claim(void *virt, u_int size, u_int align) 1, }; -/* -#ifdef FIRMWORKSBUGS -*/ -#if 0 - /* - * Bug with Firmworks OFW - */ - if (virt) - return virt; -#endif args.virt = virt; args.size = size; args.align = align; @@ -537,7 +500,13 @@ void putchar(int c) { char ch = c; - + if (c == '\177') { + ch = '\b'; + OF_write(stdout, &ch, 1); + ch = ' '; + OF_write(stdout, &ch, 1); + ch = '\b'; + } if (c == '\n') putchar('\r'); OF_write(stdout, &ch, 1); @@ -546,11 +515,81 @@ putchar(int c) int getchar() { - unsigned char ch = '\0'; + int c = cngetc(); + + if (c == '\r') + c = '\n'; + + if ((c < ' ' && c != '\n') || c == '\177') + return(c); + + putchar(c); + + return(c); +} + +void +ofc_probe(struct consdev *cn) +{ + cn->cn_pri = CN_NORMAL; + cn->cn_dev = makedev(0,0); /* WTF */ +} + + +void +ofc_init(struct consdev *cn) +{ +} + +char buffered_char; +int +ofc_getc(dev_t dev) +{ + u_int8_t ch; int l; + if (dev & 0x80) { + if (buffered_char != 0) + return 1; + + l = OF_read(stdin, &ch, 1); + if (l == 1) { + buffered_char = ch; + return 1; + } + return 0; + } + + if (buffered_char != 0) { + ch = buffered_char; + buffered_char = 0; + return ch; + } + while ((l = OF_read(stdin, &ch, 1)) != 1) if (l != -2 && l != 0) - return -1; + return 0; return ch; + +} + +void +ofc_putc(dev_t dev, int c) +{ + char ch; + + ch = 'a'; + OF_write(stdout, &ch, 1); + ch = c; + if (c == '\177' && c == '\b') { + ch = 'A'; + } + OF_write(stdout, &ch, 1); +} + + +void +machdep() +{ + cninit(); } diff --git a/sys/arch/macppc/stand/boot.mac/Makefile b/sys/arch/macppc/stand/boot.mac/Makefile index 6242827aa92..524e13c334b 100644 --- a/sys/arch/macppc/stand/boot.mac/Makefile +++ b/sys/arch/macppc/stand/boot.mac/Makefile @@ -1,12 +1,15 @@ -# $OpenBSD: Makefile,v 1.2 2006/12/05 20:30:26 gwk Exp $ +# $OpenBSD: Makefile,v 1.3 2007/06/13 02:17:32 drahn Exp $ # $NetBSD: Makefile,v 1.1 1996/09/30 16:35:05 ws Exp $ +S= ${.CURDIR}/../../../.. R= .. .PATH: $(.CURDIR)/$(R) RELOC= E00000 ENTRY= _entry PROG= boot.mac -SRCS= Locore.c boot.c ofdev.c net.c netif_of.c alloc.c cache.c hfs.c +SRCS= Locore.c main.c ofdev.c net.c netif_of.c alloc.c cache.c hfs.c +SRCS+= boot.c conf.c cmd.c vars.c ctime.c strtol.c + NOMAN= INSTALL_STRIP= BINDIR= /usr/mdec @@ -14,8 +17,11 @@ OBJCOPY?= objcopy OBJCOPY_ARGS= -O aixcoff-rs6000 -R .comment -R .note LDFLAGS= -X -Ttext ${RELOC} -e $(ENTRY) -T ${.CURDIR}/elf32_powerpc_merge.x -Bstatic +.PATH: ${S}/stand/boot +.PATH: ${S}/lib/libsa + CPPFLAGS+= -I. -I${.CURDIR}/../../.. -I${.CURDIR}/../../../.. -CPPFLAGS+= -DRELOC=0x${RELOC} +CPPFLAGS+= -DRELOC=0x${RELOC} -DCONSPEED=57600 CPPFLAGS+= -DXCOFF_GLUE # for booting PCI Powermacs LIBS!= cd $(.CURDIR)/$(R); $(MAKE) libdep diff --git a/sys/arch/macppc/stand/conf.c b/sys/arch/macppc/stand/conf.c new file mode 100644 index 00000000000..db2a9896685 --- /dev/null +++ b/sys/arch/macppc/stand/conf.c @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2007 Dale Rahn <drahn@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ +#include <sys/param.h> + +#include <dev/cons.h> + +#include <lib/libsa/stand.h> + + +const char version[] = "1.0"; +int debug = 0; + +void ofc_probe(struct consdev *); +void ofc_init(struct consdev *); +int ofc_getc(dev_t); +void ofc_putc(dev_t, int); + + +struct consdev *cn_tab; + +struct consdev constab[] = { + { ofc_probe, ofc_init, ofc_getc, ofc_putc }, + { NULL } +}; diff --git a/sys/arch/macppc/stand/libsa.h b/sys/arch/macppc/stand/libsa.h new file mode 100644 index 00000000000..749785978ad --- /dev/null +++ b/sys/arch/macppc/stand/libsa.h @@ -0,0 +1,21 @@ +/* $OpenBSD: libsa.h,v 1.1 2007/06/13 02:17:32 drahn Exp $ */ + +/* + * Copyright (c) 2006 Mark Kettenis + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <lib/libsa/stand.h> + +#define DEFAULT_KERNEL_ADDRESS 0 diff --git a/sys/arch/macppc/stand/boot.c b/sys/arch/macppc/stand/main.c index 6995ed7a1a1..71bc0df57d7 100644 --- a/sys/arch/macppc/stand/boot.c +++ b/sys/arch/macppc/stand/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: boot.c,v 1.13 2005/12/24 01:05:17 kettenis Exp $ */ +/* $OpenBSD: main.c,v 1.1 2007/06/13 02:17:32 drahn Exp $ */ /* $NetBSD: boot.c,v 1.1 1997/04/16 20:29:17 thorpej Exp $ */ /* @@ -54,6 +54,7 @@ #include <lib/libkern/libkern.h> #include <lib/libsa/stand.h> #include <lib/libsa/loadfile.h> +#include <stand/boot/cmd.h> #include <machine/cpu.h> @@ -62,10 +63,13 @@ #include <macppc/stand/openfirm.h> char bootdev[128]; -char bootfile[128]; int boothowto; int debug; + +void +get_alt_bootdev(char *, size_t, char *, size_t); + static void prom2boot(char *dev) { @@ -164,18 +168,16 @@ chain(void (*entry)(), char *args, void *ssym, void *esym) */ #define CLAIM_LIMIT 0x00c00000 +char bootline[512]; + +extern const char *bootfile; int main() { int chosen; - char bootline[512]; /* Should check size? */ - char *cp; u_long marks[MARK_MAX]; - u_int32_t entry; - void *ssym, *esym; int fd; - printf("\n>> OpenBSD/macppc Boot\n"); /* * Get the boot arguments from Openfirmware @@ -187,49 +189,67 @@ main() exit(); } prom2boot(bootdev); - parseargs(bootline, &boothowto); - for (;;) { - if (boothowto & RB_ASKNAME) { - printf("Boot (or \"exit\"): "); - gets(bootline); - parseargs(bootline, &boothowto); - } - OF_claim((void *)0x00100000, CLAIM_LIMIT, 0); /* XXX */ - marks[MARK_START] = 0; - if (loadfile(bootline, marks, LOAD_ALL) >= 0) - break; - if (errno) - printf("open %s: %s\n", opened_name, strerror(errno)); - boothowto |= RB_ASKNAME; - } -#ifdef __notyet__ - OF_setprop(chosen, "bootpath", opened_name, strlen(opened_name) + 1); - cp = bootline; -#else + printf("bootline [%s]\n", bootline); + get_alt_bootdev(bootdev, sizeof(bootdev), bootline, sizeof(bootline)); + if (bootline[0] != '\0') + bootfile = bootline; + + OF_claim((void *)0x00100000, CLAIM_LIMIT, 0); /* XXX */ + boot(0); + return 0; +} + +void +get_alt_bootdev(char *dev, size_t devsz, char *line, size_t linesz) +{ + char *p; + int len; + /* + * if the kernel image specified contains a ':' it is + * [device]:[kernel], so seperate the two fields. + */ + p = strrchr(line, ':'); + if (p == NULL) + return; + /* user specified boot device for kernel */ + len = p - line + 1; /* str len plus nil */ + strlcpy(dev, line, len > devsz ? devsz : len); + + strlcpy(line, p+1, linesz); /* rest of string ater ':' */ +} + + +void +devboot(dev_t dev, char *p) +{ + printf("bootdev [%s]\n", bootdev); + strlcpy(p, bootdev, BOOTDEVLEN); +} + +run_loadfile(u_long *marks, int howto) +{ + char bootline[512]; /* Should check size? */ + u_int32_t entry; + char *cp; + void *ssym, *esym; + strlcpy(bootline, opened_name, sizeof bootline); cp = bootline + strlen(bootline); *cp++ = ' '; -#endif - *cp = '-'; - if (boothowto & RB_ASKNAME) - *++cp = 'a'; - if (boothowto & RB_CONFIG) - *++cp = 'c'; - if (boothowto & RB_SINGLE) - *++cp = 's'; - if (boothowto & RB_KDB) - *++cp = 'd'; - if (*cp == '-') -#ifdef __notyet__ - *cp = 0; -#else + *cp = '-'; + if (howto & RB_ASKNAME) + *++cp = 'a'; + if (howto & RB_CONFIG) + *++cp = 'c'; + if (howto & RB_SINGLE) + *++cp = 's'; + if (howto & RB_KDB) + *++cp = 'd'; + if (*cp == '-') *--cp = 0; -#endif else *++cp = 0; -#ifdef __notyet__ - OF_setprop(chosen, "bootargs", bootline, strlen(bootline) + 1); -#endif + entry = marks[MARK_ENTRY]; ssym = (void *)marks[MARK_SYM]; esym = (void *)marks[MARK_END]; @@ -243,4 +263,26 @@ main() _rtt(); return 0; + +} + +int +cnspeed(dev_t dev, int sp) +{ + return CONSPEED; +} + +char ttyname_buf[8]; + +char * +ttyname(int fd) +{ + snprintf(ttyname_buf, sizeof ttyname_buf, "ofc0"); + +} + +dev_t +ttydev(char *name) +{ + return makedev(0,0); } diff --git a/sys/arch/macppc/stand/ofdev.c b/sys/arch/macppc/stand/ofdev.c index 6130b465c17..0438ad52030 100644 --- a/sys/arch/macppc/stand/ofdev.c +++ b/sys/arch/macppc/stand/ofdev.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ofdev.c,v 1.12 2007/06/06 17:15:12 deraadt Exp $ */ +/* $OpenBSD: ofdev.c,v 1.13 2007/06/13 02:17:32 drahn Exp $ */ /* $NetBSD: ofdev.c,v 1.1 1997/04/16 20:29:20 thorpej Exp $ */ /* @@ -48,53 +48,26 @@ extern char bootdev[]; +/* + * this function is passed [device specifier]:[kernel] + * however a device specifier may contain a ':' + */ +char namebuf[256]; static char * -filename(char *str, char *ppart) +filename(char *str) { char *cp, *lp; char savec; int dhandle; - char devtype[16]; - - lp = str; - devtype[0] = 0; - *ppart = 0; - for (cp = str; *cp; lp = cp) { - /* For each component of the path name... */ - while (*++cp && *cp != '/') - ; - savec = *cp; - *cp = 0; - /* ...look whether there is a device with this name */ - dhandle = OF_finddevice(str); - *cp = savec; - if (dhandle == -1) { - /* - * if not, lp is the delimiter between device and path - */ - - /* if the last component was a block device... */ - if (!strcmp(devtype, "block")) { - /* search for arguments */ - for (cp = lp; - --cp >= str && *cp != '/' && *cp != ':';) - ; - if (cp >= str && *cp == ':') { - /* found arguments */ - for (cp = lp; - *--cp != ':' && *cp != ',';) - ; - if (*++cp >= 'a' && - *cp <= 'a' + MAXPARTITIONS) - *ppart = *cp; - } - } - return lp; - } else if (OF_getprop(dhandle, "device_type", devtype, - sizeof devtype) < 0) - devtype[0] = 0; - } - return 0; + + cp = strrchr(str, ':'); + if (cp == NULL) + return NULL; + + savec = *cp; + *cp = 0; + strlcpy(namebuf, cp+1, sizeof namebuf); + return namebuf; } static int @@ -225,7 +198,6 @@ read_mac_label(struct of_dev *devp, char *buf, struct disklabel *lp) if (0 == strcmp(part->pmPartType, PART_TYPE_OPENBSD)) { /* FOUND OUR PARTITION!!! */ - printf("found OpenBSD DPME partition\n"); if(strategy(devp, F_READ, part->pmPyPartStart, DEV_BSIZE, buf, &read) == 0 && read == DEV_BSIZE) @@ -311,8 +283,8 @@ int devopen(struct open_file *of, const char *name, char **file) { char *cp; - char partition; char fname[256]; + char devname[256]; char buf[DEV_BSIZE]; struct disklabel label; int handle, part; @@ -323,27 +295,21 @@ devopen(struct open_file *of, const char *name, char **file) panic("devopen"); if (of->f_flags != F_READ) return EPERM; + strlcpy(fname, name, sizeof fname); - cp = filename(fname, &partition); - if (cp) { - strlcpy(buf, cp, sizeof buf); - *cp = 0; - } - if (!cp || !*buf) - strlcpy(buf, DEFAULT_KERNEL, sizeof buf); - if (!*fname) - strlcpy(fname, bootdev, sizeof fname); + cp = filename(fname); + if (cp == NULL) + return ENOENT; + strlcpy(buf, cp, sizeof buf); strlcpy(opened_name, fname, sizeof opened_name); - if (partition) { - cp = opened_name + strlen(opened_name); - *cp++ = ':'; - *cp++ = partition; - *cp = 0; - } + + strlcat(opened_name, ":", sizeof opened_name); if (*buf != '/') strlcat(opened_name, "/", sizeof opened_name); + strlcat(opened_name, buf, sizeof opened_name); *file = opened_name + strlen(fname) + 1; + if ((handle = OF_finddevice(fname)) == -1) return ENOENT; if (OF_getprop(handle, "name", buf, sizeof buf) < 0) @@ -380,16 +346,10 @@ devopen(struct open_file *of, const char *name, char **file) } if (error == ERDLAB) { - if (partition) - /* - * User specified a partition, - * but there is none - */ - goto bad; /* No label, just use complete disk */ ofdev.partoff = 0; } else { - part = partition ? partition - 'a' : 0; + part = 0; /* how to pass this parameter */ ofdev.partoff = label.d_partitions[part].p_offset; } diff --git a/sys/arch/macppc/stand/ofwboot/Makefile b/sys/arch/macppc/stand/ofwboot/Makefile index 46b5221d160..fb3d67ef14f 100644 --- a/sys/arch/macppc/stand/ofwboot/Makefile +++ b/sys/arch/macppc/stand/ofwboot/Makefile @@ -1,11 +1,12 @@ -# $OpenBSD: Makefile,v 1.3 2006/12/05 20:30:27 gwk Exp $ +# $OpenBSD: Makefile,v 1.4 2007/06/13 02:17:32 drahn Exp $ # $NetBSD: Makefile,v 1.2 1997/04/17 07:46:24 thorpej Exp $ S= ${.CURDIR}/../../../.. R=../ PROG= ofwboot -SRCS= Locore.c boot.c ofdev.c net.c netif_of.c alloc.c cache.c hfs.c +SRCS= Locore.c main.c ofdev.c net.c netif_of.c alloc.c cache.c hfs.c +SRCS+= boot.c conf.c cmd.c vars.c ctime.c strtol.c .PATH: ${S}/arch/macppc/stand SRCS+= ofwmagic.S #CFLAGS+= -DDEBUG -DNETIF_DEBUG @@ -16,6 +17,9 @@ OBJCOPY?= objcopy SAREL= BINDIR= /usr/mdec +.PATH: ${S}/stand/boot +.PATH: ${S}/lib/libsa + NEWVERSWHAT= "OpenFirmware Boot" # For now... @@ -24,7 +28,7 @@ RELOC= 20000 ENTRY= _start CPPFLAGS+= -I. -I${.CURDIR}/../../.. -I${.CURDIR}/../../../.. -CPPFLAGS+= -DRELOC=0x${RELOC} +CPPFLAGS+= -DRELOC=0x${RELOC} -DCONSPEED=57600 LIBS!= cd $(.CURDIR)/$(R); $(MAKE) libdep diff --git a/sys/stand/boot/boot.c b/sys/stand/boot/boot.c index 402537771de..d36189d983b 100644 --- a/sys/stand/boot/boot.c +++ b/sys/stand/boot/boot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: boot.c,v 1.33 2007/05/29 00:03:13 deraadt Exp $ */ +/* $OpenBSD: boot.c,v 1.34 2007/06/13 02:17:32 drahn Exp $ */ /* * Copyright (c) 2003 Dale Rahn @@ -49,11 +49,11 @@ struct cmd_state cmd; /* bootprompt can be set by MD code to avoid prompt first time round */ int bootprompt = 1; +const char *bootfile = KERNEL; void boot(dev_t bootdev) { - const char *bootfile = KERNEL; int try = 0, st; u_long marks[MARK_MAX]; diff --git a/sys/stand/boot/cmd.h b/sys/stand/boot/cmd.h index d123530964c..610607f03ee 100644 --- a/sys/stand/boot/cmd.h +++ b/sys/stand/boot/cmd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.h,v 1.15 2004/06/24 22:10:18 tom Exp $ */ +/* $OpenBSD: cmd.h,v 1.16 2007/06/13 02:17:32 drahn Exp $ */ /* * Copyright (c) 1997 Michael Shalayeff @@ -28,6 +28,7 @@ */ #define CMD_BUFF_SIZE 133 +#define BOOTDEVLEN 1024 struct cmd_table { char *cmd_name; @@ -40,7 +41,7 @@ struct cmd_table { }; struct cmd_state { - char bootdev[16]; /* device */ + char bootdev[BOOTDEVLEN]; /* device */ char image[MAXPATHLEN - 16]; /* image */ int boothowto; /* howto */ char *conf; /* /etc/boot.conf normally */ |