diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2014-11-22 15:02:29 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2014-11-22 15:02:29 +0000 |
commit | 47c2b13e3db1dddf60c0fa55619807fdae1be902 (patch) | |
tree | 3c83a4bc40fcaba99cb948661ad147ef9bdd38ee /sys/arch/sparc64/stand | |
parent | 42d22829e9dfff96689f835534500cc76e42f350 (diff) |
Switch to using MI installboot, after a conversation with stsp. He will
need this soon.
install tested by jsg
Diffstat (limited to 'sys/arch/sparc64/stand')
-rw-r--r-- | sys/arch/sparc64/stand/Makefile | 4 | ||||
-rw-r--r-- | sys/arch/sparc64/stand/installboot/Makefile | 23 | ||||
-rw-r--r-- | sys/arch/sparc64/stand/installboot/installboot.8 | 105 | ||||
-rw-r--r-- | sys/arch/sparc64/stand/installboot/installboot.c | 281 |
4 files changed, 1 insertions, 412 deletions
diff --git a/sys/arch/sparc64/stand/Makefile b/sys/arch/sparc64/stand/Makefile index bd51f1a6f1c..0ee171da59b 100644 --- a/sys/arch/sparc64/stand/Makefile +++ b/sys/arch/sparc64/stand/Makefile @@ -1,10 +1,8 @@ -# $OpenBSD: Makefile,v 1.5 2007/11/25 18:25:33 deraadt Exp $ +# $OpenBSD: Makefile,v 1.6 2014/11/22 15:02:28 deraadt Exp $ .if ${MACHINE} == "sparc64" SUBDIR= bootblk libsa libz ofwboot ofwboot.net .endif -SUBDIR+= installboot - .include <bsd.subdir.mk> diff --git a/sys/arch/sparc64/stand/installboot/Makefile b/sys/arch/sparc64/stand/installboot/Makefile deleted file mode 100644 index c33955d04db..00000000000 --- a/sys/arch/sparc64/stand/installboot/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -# $OpenBSD: Makefile,v 1.9 2014/07/06 12:13:18 miod Exp $ -# $NetBSD: Makefile,v 1.13 2000/08/16 08:24:01 mrg Exp $ - -.include <bsd.own.mk> - -MAN= installboot.8 -MANSUBDIR=sparc64 - -.if ${MACHINE} == "sparc64" -PROG= installboot -SRCS= installboot.c -LDADD= -lutil -DPADD= ${LIBUTIL} -CFLAGS+= -Wall -.else -NOPROG= -.endif - -LDSTATIC?= -static - -STANDALONE= - -.include <bsd.prog.mk> diff --git a/sys/arch/sparc64/stand/installboot/installboot.8 b/sys/arch/sparc64/stand/installboot/installboot.8 deleted file mode 100644 index d08ab774d88..00000000000 --- a/sys/arch/sparc64/stand/installboot/installboot.8 +++ /dev/null @@ -1,105 +0,0 @@ -.\" $OpenBSD: installboot.8,v 1.12 2013/09/29 21:30:50 jmc Exp $ -.\" $NetBSD: installboot.8,v 1.1 1995/09/30 21:32:14 pk Exp $ -.\" -.\" Copyright (c) 1995 Paul Kranenburg -.\" 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 Paul Kranenburg. -.\" 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 $Mdocdate: September 29 2013 $ -.Dt INSTALLBOOT 8 sparc64 -.Os -.Sh NAME -.Nm installboot -.Nd install a bootstrap on an FFS filesystem partition -.Sh SYNOPSIS -.Nm installboot -.Op Fl nv -.Ar bootblk -.Ar device -.Sh DESCRIPTION -.Nm installboot -prepares an FFS filesystem partition for boot-strapping from the PROM. -The sparc64 boot process is split into two parts: a small first-stage bootblock -that is written into the superblock area of a partition -.Po -and hence is limited in size to SBSIZE - DEV_BSIZE bytes -.Pc , -and a second-stage boot program that resides in the filesystem proper. -The first-stage bootblock is loaded into memory by the PROM. -After it receives control, it loads the second-stage boot program -.Ar ofwboot -from the filesystem. -The second-stage boot program uses the device driver interface to -the PROM and the stand-alone filesystem code in -.Dq libsa.a -to locate and load the kernel. -The first-stage bootblock and second-stage boot program can be found in -.Pa /usr/mdec/bootblk -and -.Pa /usr/mdec/ofwboot -respectively. -The second-stage boot program commonly resides in the root directory as -.Pa /ofwboot . -.Pp -The options are as follows: -.Bl -tag -width flag -.It Fl n -Do not actually write anything on the disk. -.It Fl v -Verbose mode. -.El -.Pp -The arguments are: -.Bl -tag -width bootblk -.It Ar bootblk -The name of the file containing the first-stage bootblock. -.It Ar device -The name of the raw device in which the first-stage boot program -is to be installed. -This should correspond to the block device on which the file system containing -.Ar ofwboot -is mounted. -.El -.Sh EXAMPLES -The following commands will install the first-stage bootblock in the -root filesystem -.Pq assumed to be mounted on Dq sd0a -using the file -.Pa /ofwboot -as the second-stage boot program: -.Bd -literal -offset indent -# cp /usr/mdec/ofwboot /ofwboot -# /usr/mdec/installboot /usr/mdec/bootblk sd0a -.Ed -.Sh SEE ALSO -.Xr disklabel 8 , -.Xr init 8 -.Sh HISTORY -The -.Nm installboot -first appeared in -.Nx 1.1 . diff --git a/sys/arch/sparc64/stand/installboot/installboot.c b/sys/arch/sparc64/stand/installboot/installboot.c deleted file mode 100644 index 43170522c88..00000000000 --- a/sys/arch/sparc64/stand/installboot/installboot.c +++ /dev/null @@ -1,281 +0,0 @@ -/* $OpenBSD: installboot.c,v 1.18 2014/07/06 12:13:18 miod Exp $ */ -/* $NetBSD: installboot.c,v 1.8 2001/02/19 22:48:59 cgd Exp $ */ - -/*- - * Copyright (c) 2012 Joel Sing <jsing@openbsd.org> - * Copyright (c) 1998 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Paul Kranenburg. - * - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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. - */ - -#include <sys/param.h> -#include <sys/disklabel.h> -#include <sys/dkio.h> -#include <sys/ioctl.h> -#include <sys/mman.h> -#include <sys/stat.h> -#include <sys/time.h> - -#include <dev/biovar.h> -#include <dev/softraidvar.h> - -#include <ufs/ffs/fs.h> - -#include <err.h> -#include <fcntl.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <util.h> - -int verbose, nowrite; -char *dev, *blkstore; -size_t blksize; - -static void usage(void); -int main(int, char *[]); -static void write_bootblk(int); - -static int sr_volume(int, int *, int *); -static void sr_installboot(int); -static void sr_install_bootblk(int, int, int); - -static void -usage(void) -{ - extern char *__progname; - - fprintf(stderr, "usage: %s [-nv] bootblk device\n", __progname); - exit(1); -} - -int -main(int argc, char *argv[]) -{ - char *blkfile, *realdev; - int vol = -1, ndisks = 0, disk; - int c, devfd, blkfd; - struct stat sb; - - while ((c = getopt(argc, argv, "nv")) != -1) { - switch (c) { - case 'n': - /* Do not actually write the bootblock to disk. */ - nowrite = 1; - break; - case 'v': - /* Chat */ - verbose = 1; - break; - default: - usage(); - } - } - - if (argc - optind < 2) - usage(); - - blkfile = argv[optind++]; - dev = argv[optind]; - - if (verbose) - printf("bootblk: %s\n", blkfile); - - if ((blkfd = open(blkfile, O_RDONLY)) < 0) - err(1, "open: %s", blkfile); - - if (fstat(blkfd, &sb) == -1) - err(1, "fstat: %s", blkfile); - if (sb.st_size == 0) - errx(1, "%s is empty", blkfile); - - blksize = howmany(sb.st_size, DEV_BSIZE) * DEV_BSIZE; - if (blksize > SBSIZE - DEV_BSIZE) - errx(1, "boot blocks too big"); - if ((blkstore = malloc(blksize)) == NULL) - err(1, "malloc: %s", blkfile); - bzero(blkstore, blksize); - if (read(blkfd, blkstore, sb.st_size) != sb.st_size) - err(1, "read: %s", blkfile); - - if ((devfd = opendev(dev, (nowrite ? O_RDONLY : O_RDWR), - OPENDEV_PART, &realdev)) < 0) - err(1, "open: %s", realdev); - if (verbose) - printf("device: %s\n", realdev); - - if (sr_volume(devfd, &vol, &ndisks)) { - - /* Install boot loader in softraid volume. */ - sr_installboot(devfd); - - /* Install bootblk on each disk that is part of this volume. */ - for (disk = 0; disk < ndisks; disk++) - sr_install_bootblk(devfd, vol, disk); - - } else { - - /* Write boot blocks to device. */ - write_bootblk(devfd); - - } - - close(devfd); - - return 0; -} - -static void -write_bootblk(int devfd) -{ - /* - * Write bootblock into the superblock. - */ - - if (nowrite) - return; - - if (lseek(devfd, DEV_BSIZE, SEEK_SET) != DEV_BSIZE) - err(1, "lseek boot block"); - - /* Sync filesystems (to clean in-memory superblock?) */ - sync(); - - if (write(devfd, blkstore, blksize) != blksize) - err(1, "write boot block"); -} - -static int -sr_volume(int devfd, int *vol, int *disks) -{ - struct bioc_inq bi; - struct bioc_vol bv; - int rv, i; - - /* Get volume information. */ - memset(&bi, 0, sizeof(bi)); - rv = ioctl(devfd, BIOCINQ, &bi); - if (rv == -1) - return 0; - - /* XXX - softraid volumes will always have a "softraid0" controller. */ - if (strncmp(bi.bi_dev, "softraid0", sizeof("softraid0"))) - return 0; - - /* Locate specific softraid volume. */ - for (i = 0; i < bi.bi_novol; i++) { - - memset(&bv, 0, sizeof(bv)); - bv.bv_volid = i; - rv = ioctl(devfd, BIOCVOL, &bv); - if (rv == -1) - err(1, "BIOCVOL"); - - if (strncmp(dev, bv.bv_dev, sizeof(bv.bv_dev)) == 0) { - *vol = i; - *disks = bv.bv_nodisk; - break; - } - - } - - if (verbose) - fprintf(stderr, "%s: softraid volume with %i disk(s)\n", - dev, *disks); - - return 1; -} - -static void -sr_installboot(int devfd) -{ - struct bioc_installboot bb; - int rv; - - /* - * Install boot loader into softraid boot loader storage area. - */ - bb.bb_bootldr = "XXX"; - bb.bb_bootldr_size = sizeof("XXX"); - bb.bb_bootblk = blkstore; - bb.bb_bootblk_size = blksize; - strncpy(bb.bb_dev, dev, sizeof(bb.bb_dev)); - if (!nowrite) { - if (verbose) - fprintf(stderr, "%s: installing boot loader on " - "softraid volume\n", dev); - rv = ioctl(devfd, BIOCINSTALLBOOT, &bb); - if (rv != 0) - errx(1, "softraid installboot failed"); - } -} - -static void -sr_install_bootblk(int devfd, int vol, int disk) -{ - struct bioc_disk bd; - char *realdev; - char part; - int diskfd; - int rv; - - /* Get device name for this disk/chunk. */ - memset(&bd, 0, sizeof(bd)); - bd.bd_volid = vol; - bd.bd_diskid = disk; - rv = ioctl(devfd, BIOCDISK, &bd); - if (rv == -1) - err(1, "BIOCDISK"); - - /* Check disk status. */ - if (bd.bd_status != BIOC_SDONLINE && bd.bd_status != BIOC_SDREBUILD) { - fprintf(stderr, "softraid chunk %u not online - skipping...\n", - disk); - return; - } - - if (strlen(bd.bd_vendor) < 1) - errx(1, "invalid disk name"); - part = bd.bd_vendor[strlen(bd.bd_vendor) - 1]; - if (part < 'a' || part >= 'a' + MAXPARTITIONS) - errx(1, "invalid partition %c\n", part); - bd.bd_vendor[strlen(bd.bd_vendor) - 1] = '\0'; - - /* Open device. */ - if ((diskfd = opendev(bd.bd_vendor, (nowrite ? O_RDONLY : O_RDWR), - OPENDEV_PART, &realdev)) < 0) - err(1, "open: %s", realdev); - - if (verbose) - fprintf(stderr, "%s%c: installing boot blocks on %s\n", - bd.bd_vendor, part, realdev); - - /* Write boot blocks to device. */ - write_bootblk(diskfd); - - close(diskfd); -} |