diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1997-05-05 06:02:04 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1997-05-05 06:02:04 +0000 |
commit | 3d10bc794d2e03421fd174136259f42a03004bca (patch) | |
tree | d1b03f69e85167322eb9804fa9e85237ce45b7f1 /sys/arch/alpha/stand/setnetbootinfo | |
parent | 53e6b51c98a2cae3f0e7c41c03a85f76fcd17341 (diff) |
Updates from NetBSD (cgd):
- seriously clean up makefiles. use libsa/libkern/libz as appropriate,
and don't build the various sources into objs locally by specifying
them directly in the Makefiles.
- move the secondary bootstrap down (to 0x20004000), and add a HEAP_LIMIT
so that we don't exhaust our bootstrap address space (when using the new,
not yet checked in, memory allocator).
- clean up installboot, deal with secondary bootstrap programs not on
'a' partition or 'a' partition not starting at 0.
- add padding to structures in bbinfo.h for future expansion. Add a
netbbinfo structure to allow netboot information to be hard-coded in
network boot blocks, so that they can be made to work even on systems
with firmware which doesn't support the new "ethernet address in boot
device" convention.
- move the sync() calls to the correct place in installboot.c
- remove a kludge in disk.c which was breaking multiple opens/closes
of the disk
- allow netboot ethernet address to be hard-coded into binary so that
machines with old firmware which doesn't pass it in the boot device
can work. Assume that if the ethernet address isn't passed in, it
uses the old (dain-bramaged) 'read' interface works on my 3000/300LX.
- Add setnetbootinfo, a program to hard code an ethernet address into
a network boot.
- move an 'int debug;' into boot.c (it was the only diff between boot.c and
netboot.c), and nuke netboot.c (using boot.c instead for net boot blocks).
- add cd9660 file system ops to the file system ops table in filesystem.c
- if a file name is given (i.e. BOOTED_FILE) is set, boot only that file,
but if not then try to boot "bsd", "bsd.bak", "bsd.old", and
"obsd" (in that order) until one is found or until the list of names
is exhausted.
- add support for reading gzipped kernels.
- use strerror() to print errors, rather than just printing error numbers
- if no disk label exists, fake one up
- slightly relax the block size checks in bootxx.c; they were a bit to paranoid
And local changes:
- don't build a copy of libsa/libkern/libz for each boot prog,
just build a single copy and use it for everything.
Diffstat (limited to 'sys/arch/alpha/stand/setnetbootinfo')
-rw-r--r-- | sys/arch/alpha/stand/setnetbootinfo/Makefile | 15 | ||||
-rw-r--r-- | sys/arch/alpha/stand/setnetbootinfo/setnetbootinfo.8 | 128 | ||||
-rw-r--r-- | sys/arch/alpha/stand/setnetbootinfo/setnetbootinfo.c | 249 |
3 files changed, 392 insertions, 0 deletions
diff --git a/sys/arch/alpha/stand/setnetbootinfo/Makefile b/sys/arch/alpha/stand/setnetbootinfo/Makefile new file mode 100644 index 00000000000..293399e1da8 --- /dev/null +++ b/sys/arch/alpha/stand/setnetbootinfo/Makefile @@ -0,0 +1,15 @@ +# $OpenBSD: Makefile,v 1.1 1997/05/05 06:02:02 millert Exp $ +# $NetBSD: Makefile,v 1.4 1997/04/06 08:41:36 cgd Exp $ + +.PATH: ${.CURDIR}/.. + +PROG= setnetbootinfo +BINDIR= /usr/mdec + +MAN= setnetbootinfo.8 +MANSUBDIR=/alpha + +CFLAGS+= -I${.CURDIR}/.. +LDSTATIC=-static + +.include <bsd.prog.mk> diff --git a/sys/arch/alpha/stand/setnetbootinfo/setnetbootinfo.8 b/sys/arch/alpha/stand/setnetbootinfo/setnetbootinfo.8 new file mode 100644 index 00000000000..6821b040d60 --- /dev/null +++ b/sys/arch/alpha/stand/setnetbootinfo/setnetbootinfo.8 @@ -0,0 +1,128 @@ +.\" $OpenBSD: setnetbootinfo.8,v 1.1 1997/05/05 06:02:03 millert Exp $ +.\" $NetBSD: setnetbootinfo.8,v 1.2 1997/04/06 08:41:36 cgd Exp $ +.\" +.\" Copyright (c) 1997 Christopher G. Demetriou. 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 Christopher G. Demetriou +.\" for the NetBSD Project. +.\" 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. +.\" +.Dd January 20, 1997 +.Dt SETNETBOOTINFO 8 +.Os +.Sh NAME +.Nm setnetbootinfo +.Nd configure network bootstrap program +.Sh SYNOPSIS +.Nm setnetbootinfo +.Op Fl vf +.Op Fl o Ar infile +.Oo +.Fl a Ar ether-address | Fl h Ar ether-host +.Oc +.Ar netboot +.Nm setnetbootinfo +.Op Fl v +.Fl u o Ar outfile Ar infile +.Sh DESCRIPTION +The +.Nm setnetbootinfo +utility configures the OpenBSD/alpha network bootstrap program so +that it can be used to bootstrap systems with old firmware revisions. +.Pp +The OpenBSD/alpha network bootstrap program needs to have the ethernet +address of the interface being used to boot the system available when +querying other hosts on the network for bootstrapping information. +Alpha systems with old firmware revisions provide no way for +network bootstrap programs to determine the ethernet address of +the interface that they are booting from, and so the OpenBSD/alpha +network bootstrap program must find that information in another way. +(Newer firmware revisions include the ethernet address in the name of +the device that is being booted from.) +The +.Nm +utility encodes an ethernet address (and other information) directly +into the network bootstrap program. +.Pp +The options recognized by +.Nm +are as follows: +.Bl -tag -width flag +.It Fl a Ar ether-address +Encode the given ethernet address into the network bootstrap program. +(This option and the +.Fl h +option are mutually exclusive.) +.It Fl f +Force the address information being encoded in the bootstrap +program to be used regardless of whether or not the bootstrap +program can get address information from the booting system's +firmware. +.It Fl h Ar ether-host +Encode the ethernet address of the specified host into the network +bootstrap program. The host's name is translated to an ethernet +address using the +.Xr ether_hostton 3 +function. +(This option and the +.Fl a +option are mutually exclusive.) +.It Fl o Ar outfile +Output the resulting bootstrap program into the file named by +.Ar outfile , +replacing it if it already exists. If the +.Fl o +flag is not specified, the output file name will be +the name of the input bootstrap program concatenated with a +period and the digits of the ethernet address being encoded. +For instance, if the input file is named +.Pa /usr/mdec/netboot +and is being configured to encode the ethernet address +.Li 08:00:2b:bd:5d:fd , +then the default output file name would be +.Pa /usr/mdec/netboot.08002bbd5dfd . +It is safe to set the output file name to be the same as the +input file name; the input file is read in its entirety before +the output file is modified. +.It Fl u +Remove configuration information from the specified network +bootstrap program. If this option is used, an output file name must be +specified with the +.Fl o +option, and neither the +.Fl a +or the +.Fl h +options may be specified. +.It Fl v +Verbose mode. +.El +.Sh "SEE ALSO" +.Xr bootpd 8 +.Sh HISTORY +The alpha +.Nm +command first appeared in +.Nx 1.2b . diff --git a/sys/arch/alpha/stand/setnetbootinfo/setnetbootinfo.c b/sys/arch/alpha/stand/setnetbootinfo/setnetbootinfo.c new file mode 100644 index 00000000000..114a7556f11 --- /dev/null +++ b/sys/arch/alpha/stand/setnetbootinfo/setnetbootinfo.c @@ -0,0 +1,249 @@ +/* $OpenBSD: setnetbootinfo.c,v 1.1 1997/05/05 06:02:03 millert Exp $ */ +/* $NetBSD: setnetbootinfo.c,v 1.5 1997/04/06 08:41:37 cgd Exp $ */ + +/* + * Copyright (c) 1997 Christopher G. Demetriou + * 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 Christopher G. Demetriou + * for the NetBSD Project. + * 4. 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 <err.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <sys/fcntl.h> +#include <sys/stat.h> +#include <sys/socket.h> /* XXX */ +#include <net/if.h> /* XXX */ +#include <netinet/in.h> +#include <netinet/if_ether.h> + +#include "bbinfo.h" + +int verbose, force, unset; +char *netboot, *outfile, *addr, *host; + +char *outfilename; + +struct ether_addr *ether_addr, _ether_addr; + +static void +usage() +{ + + (void)fprintf(stderr, "usage:\n"); + (void)fprintf(stderr, "\tsetnetboot [-v] [-f] [-o outfile] \\\n"); + (void)fprintf(stderr, "\t [-a ether-address | -h ether-host] infile\n"); + (void)fprintf(stderr, "\tsetnetboot [-v] -u -o outfile infile\n"); + exit(1); +} + +int +main(argc, argv) + int argc; + char *argv[]; +{ + struct netbbinfo *netbbinfop; + struct stat sb; + u_int64_t *qp, csum; + char *netbb; + int c, fd, i; + + while ((c = getopt(argc, argv, "a:fh:o:uv")) != -1) { + switch (c) { + case 'a': + /* use the argument as an ethernet address */ + addr = optarg; + break; + case 'f': + /* set force flag in network boot block */ + force = 1; + break; + case 'h': + /* use the argument as a host to find in /etc/ethers */ + host = optarg; + break; + case 'o': + /* use the argument as the output file name */ + outfile = optarg; + break; + case 'u': + /* remove configuration information */ + unset = 1; + break; + case 'v': + /* Chat */ + verbose = 1; + break; + default: + usage(); + } + } + + if ((argc - optind) != 1) + usage(); + netboot = argv[optind]; + + if (unset && (force || host != NULL || addr != NULL)) + errx(1, "-u can't be used with -f, -h, or -a"); + + if (unset) { + if (force || host != NULL || addr != NULL) + errx(1, "-u can't be used with -f, -h, or -a"); + if (outfile == NULL) + errx(1, "-u cannot be used without -o"); + } else { + if ((host == NULL && addr == NULL) || + (host != NULL && addr != NULL)) + usage(); + + if (host != NULL) { + if (ether_hostton(host, &_ether_addr) == -1) + errx(1, "ethernet address couldn't be found for \"%s\"", + host); + ether_addr = &_ether_addr; + } else { /* addr != NULL */ + ether_addr = ether_aton(addr); + if (ether_addr == NULL) + errx(1, "ethernet address \"%s\" is invalid", + addr); + } + } + + if (outfile != NULL) + outfilename = outfile; + else { + /* name + 12 for enet addr + '.' before enet addr + NUL */ + outfilename = malloc(strlen(netboot) + 14); + if (outfilename == NULL) + err(1, "malloc of output file name failed"); + sprintf(outfilename, "%s.%02x%02x%02x%02x%02x%02x", netboot, + ether_addr->ether_addr_octet[0], + ether_addr->ether_addr_octet[1], + ether_addr->ether_addr_octet[2], + ether_addr->ether_addr_octet[3], + ether_addr->ether_addr_octet[4], + ether_addr->ether_addr_octet[5]); + } + + if (verbose) { + printf("netboot: %s\n", netboot); + if (unset) + printf("unsetting configuration\n"); + else + printf("ethernet address: %s (%s), force = %d\n", + ether_ntoa(ether_addr), host ? host : addr, force); + printf("output netboot: %s\n", outfilename); + } + + + if (verbose) + printf("opening %s...\n", netboot); + if ((fd = open(netboot, O_RDONLY, 0)) == -1) + err(1, "open: %s", netboot); + if (fstat(fd, &sb) == -1) + err(1, "fstat: %s", netboot); + if (!S_ISREG(sb.st_mode)) + errx(1, "%s must be a regular file", netboot); + + if (verbose) + printf("reading %s...\n", netboot); + netbb = malloc(sb.st_size); + if (netbb == NULL) + err(1, "malloc of %lu for %s failed", + (unsigned long)sb.st_size, netboot); + if (read(fd, netbb, sb.st_size) != sb.st_size) + err(1, "read of %lu from %s failed", + (unsigned long)sb.st_size, netboot); + + if (verbose) + printf("closing %s...\n", netboot); + close(fd); + + if (verbose) + printf("looking for netbbinfo...\n"); + netbbinfop = NULL; + for (qp = (u_int64_t *)netbb; qp < (u_int64_t *)(netbb + sb.st_size); + qp++) { + if (((struct netbbinfo *)qp)->magic1 == 0xfeedbabedeadbeef && + ((struct netbbinfo *)qp)->magic2 == 0xfeedbeefdeadbabe) { + netbbinfop = (struct netbbinfo *)qp; + break; + } + } + if (netbbinfop == NULL) + errx(1, "netboot information structure not found in %s", + netboot); + if (verbose) + printf("found netbbinfo structure at offset 0x%lx.\n", + (unsigned long)((char *)netbbinfop - netbb)); + + if (verbose) + printf("setting netbbinfo structure...\n"); + bzero(netbbinfop, sizeof *netbbinfop); + netbbinfop->magic1 = 0xfeedbabedeadbeef; + netbbinfop->magic2 = 0xfeedbeefdeadbabe; + netbbinfop->set = unset ? 0 : 1; + if (netbbinfop->set) { + for (i = 0; i < 6; i++) + netbbinfop->ether_addr[i] = + ether_addr->ether_addr_octet[i]; + netbbinfop->force = force; + } + netbbinfop->cksum = 0; + + if (verbose) + printf("setting netbbinfo checksum...\n"); + csum = 0; + for (i = 0, qp = (u_int64_t *)netbbinfop; + i < (sizeof *netbbinfop / sizeof (u_int64_t)); i++, qp++) + csum += *qp; + netbbinfop->cksum = -csum; + + if (verbose) + printf("opening %s...\n", outfilename); + if ((fd = open(outfilename, O_WRONLY | O_CREAT, 0666)) == -1) + err(1, "open: %s", outfilename); + + if (verbose) + printf("writing %s...\n", outfilename); + if (write(fd, netbb, sb.st_size) != sb.st_size) + err(1, "write of %lu to %s failed", + (unsigned long)sb.st_size, outfilename); + + if (verbose) + printf("closing %s...\n", outfilename); + close(fd); + + free(netbb); + if (outfile == NULL) + free(outfilename); + + exit (0); +} |