summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Sing <jsing@cvs.openbsd.org>2012-01-01 16:11:14 +0000
committerJoel Sing <jsing@cvs.openbsd.org>2012-01-01 16:11:14 +0000
commitc3676f5d34217ca3028330c0890c1b6f97f5cbd5 (patch)
tree5e2b12c0a6d79564dfc6d25a690585d27b2cd816
parentaeec66b169404c4af2c887766a6170a11a879b94 (diff)
Improve/clean up sparc64 installboot:
- Use opendev() like we do for installboot on many other archs. - Use the term bootblock rather than prototype for the first-stage, since we install it verbatim. - Read the bootblock into a zeroed buffer rather than messing around with mmap() and zeroing the end of the space. - Make man page consistent with respect to the first-stage bootblock and second-stage boot program. ok kettenis@ jmc@ (for the man part)
-rw-r--r--sys/arch/sparc64/stand/installboot/Makefile4
-rw-r--r--sys/arch/sparc64/stand/installboot/installboot.831
-rw-r--r--sys/arch/sparc64/stand/installboot/installboot.c72
3 files changed, 52 insertions, 55 deletions
diff --git a/sys/arch/sparc64/stand/installboot/Makefile b/sys/arch/sparc64/stand/installboot/Makefile
index 5d7f15e52c1..d28164fa28d 100644
--- a/sys/arch/sparc64/stand/installboot/Makefile
+++ b/sys/arch/sparc64/stand/installboot/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.6 2004/01/10 09:35:42 pvalchev Exp $
+# $OpenBSD: Makefile,v 1.7 2012/01/01 16:11:13 jsing Exp $
# $NetBSD: Makefile,v 1.13 2000/08/16 08:24:01 mrg Exp $
.include <bsd.own.mk>
@@ -9,6 +9,8 @@ MANSUBDIR=sparc64
.if ${MACHINE} == "sparc64"
PROG= installboot
SRCS= installboot.c loadfile.c
+LDADD= -lutil
+DPADD= ${LIBUTIL}
.else
NOPROG=
.endif
diff --git a/sys/arch/sparc64/stand/installboot/installboot.8 b/sys/arch/sparc64/stand/installboot/installboot.8
index 4cc48faf6df..4996efcb050 100644
--- a/sys/arch/sparc64/stand/installboot/installboot.8
+++ b/sys/arch/sparc64/stand/installboot/installboot.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: installboot.8,v 1.10 2010/04/06 06:33:50 jmc Exp $
+.\" $OpenBSD: installboot.8,v 1.11 2012/01/01 16:11:13 jsing Exp $
.\" $NetBSD: installboot.8,v 1.1 1995/09/30 21:32:14 pk Exp $
.\"
.\" Copyright (c) 1995 Paul Kranenburg
@@ -29,7 +29,7 @@
.\" (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: April 6 2010 $
+.Dd $Mdocdate: January 1 2012 $
.Dt INSTALLBOOT 8 sparc64
.Os
.Sh NAME
@@ -43,27 +43,26 @@
.Sh DESCRIPTION
.Nm installboot
prepares an FFS filesystem partition for boot-strapping from the PROM.
-The sparc bootblocks are split into two parts: a small first-stage program that
-is written into the superblock area in a partition
+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 program that resides in the filesystem proper.
-The first-stage program is loaded into memory by the PROM.
-After it receives control, it loads the second stage program
+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 second-stage boot program and the prototype code for the
-first-stage bootprogram can be found in
-.Pa /usr/mdec/ofwboot
-and
+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 program commonly resides in the root directory as
+The second-stage boot program commonly resides in the root directory as
.Pa /ofwboot .
.Pp
The options are as follows:
@@ -77,7 +76,7 @@ Verbose mode.
The arguments are:
.Bl -tag -width ofwboot
.It Ar bootblk
-the name of the prototype file for the first stage boot program.
+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.
@@ -86,15 +85,15 @@ This should correspond to the block device on which the file system containing
is mounted.
.El
.Sh EXAMPLES
-The following commands will install the first-stage bootblocks in the
+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-level boot program:
+as the second-stage boot program:
.Bd -literal -offset indent
# cp /usr/mdec/ofwboot /ofwboot
-# /usr/mdec/installboot /usr/mdec/bootblk /dev/rsd0c
+# /usr/mdec/installboot /usr/mdec/bootblk sd0a
.Ed
.Sh SEE ALSO
.Xr disklabel 8 ,
diff --git a/sys/arch/sparc64/stand/installboot/installboot.c b/sys/arch/sparc64/stand/installboot/installboot.c
index 3ec518760a3..9c43443c325 100644
--- a/sys/arch/sparc64/stand/installboot/installboot.c
+++ b/sys/arch/sparc64/stand/installboot/installboot.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: installboot.c,v 1.12 2011/12/28 13:53:23 jsing Exp $ */
+/* $OpenBSD: installboot.c,v 1.13 2012/01/01 16:11:13 jsing Exp $ */
/* $NetBSD: installboot.c,v 1.8 2001/02/19 22:48:59 cgd Exp $ */
/*-
@@ -41,9 +41,10 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
+#include <util.h>
int verbose, nowrite;
-char *boot, *proto, *dev;
+char *dev, *blkstore;
static void usage(void);
int main(int, char *[]);
@@ -60,16 +61,15 @@ usage(void)
int
main(int argc, char *argv[])
{
- int c, devfd, protofd;
- char *protostore;
- size_t protosize;
- size_t blanklen;
- struct stat sb;
+ char *blkfile, *realdev;
+ int c, devfd, blkfd;
+ size_t blksize;
+ struct stat sb;
while ((c = getopt(argc, argv, "nv")) != -1) {
switch (c) {
case 'n':
- /* Do not actually write the bootblock to disk */
+ /* Do not actually write the bootblock to disk. */
nowrite = 1;
break;
case 'v':
@@ -84,50 +84,46 @@ main(int argc, char *argv[])
if (argc - optind < 2)
usage();
- proto = argv[optind++];
+ blkfile = argv[optind++];
dev = argv[optind];
- if (verbose) {
- printf("proto: %s\n", proto);
- printf("device: %s\n", dev);
- }
+ if (verbose)
+ printf("bootblk: %s\n", blkfile);
- if ((protofd = open(proto, O_RDONLY)) < 0)
- err(1, "open: %s", proto);
+ if ((blkfd = open(blkfile, O_RDONLY)) < 0)
+ err(1, "open: %s", blkfile);
- if (fstat(protofd, &sb) == -1)
- err(1, "fstat: %s", proto);
+ if (fstat(blkfd, &sb) == -1)
+ err(1, "fstat: %s", blkfile);
if (sb.st_size == 0)
- errx(1, "%s is empty", proto);
-
- /* there must be a better way */
- blanklen = DEV_BSIZE - ((sb.st_size + DEV_BSIZE) & (DEV_BSIZE - 1));
- protosize = sb.st_size + blanklen;
- if ((protostore = mmap(0, protosize, PROT_READ|PROT_WRITE, MAP_PRIVATE,
- protofd, 0)) == MAP_FAILED)
- err(1, "mmap: %s", proto);
- /* and provide the rest of the block */
- if (blanklen)
- memset(protostore + sb.st_size, 0, blanklen);
+ 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 (nowrite)
return 0;
- /* Write patched proto bootblocks into the superblock */
- if (protosize > SBSIZE - DEV_BSIZE)
- errx(1, "proto bootblocks too big");
-
- if ((devfd = open(dev, O_RDWR, 0)) < 0)
- err(1, "open: %s", dev);
-
+ /* Write boot blocks into the superblock. */
+ 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 (lseek(devfd, DEV_BSIZE, SEEK_SET) != DEV_BSIZE)
- err(1, "lseek bootstrap");
+ err(1, "lseek boot block");
/* Sync filesystems (to clean in-memory superblock?) */
sync();
- if (write(devfd, protostore, protosize) != protosize)
- err(1, "write bootstrap");
+ if (write(devfd, blkstore, blksize) != blksize)
+ err(1, "write boot block");
close(devfd);