Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/alpha/stand add mkbootimage, a program to make a bo...
details: https://anonhg.NetBSD.org/src/rev/27a1f28c2a87
branches: trunk
changeset: 471484:27a1f28c2a87
user: cgd <cgd%NetBSD.org@localhost>
date: Fri Apr 02 08:40:23 1999 +0000
description:
add mkbootimage, a program to make a bootable image (i.e. prepend a boot
block, pad to a block boundary) from a console program (i.e. a boot
block, firmware upgrade executable, etc.)
diffstat:
sys/arch/alpha/stand/Makefile | 4 +-
sys/arch/alpha/stand/mkbootimage/Makefile | 17 ++
sys/arch/alpha/stand/mkbootimage/mkbootimage.c | 166 +++++++++++++++++++++++++
3 files changed, 185 insertions(+), 2 deletions(-)
diffs (203 lines):
diff -r 618c636373c9 -r 27a1f28c2a87 sys/arch/alpha/stand/Makefile
--- a/sys/arch/alpha/stand/Makefile Fri Apr 02 08:25:23 1999 +0000
+++ b/sys/arch/alpha/stand/Makefile Fri Apr 02 08:40:23 1999 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.9 1999/04/02 03:45:12 cgd Exp $
+# $NetBSD: Makefile,v 1.10 1999/04/02 08:40:23 cgd Exp $
-SUBDIR= boot bootxx installboot netboot setnetbootinfo \
+SUBDIR= boot bootxx installboot mkbootimage netboot setnetbootinfo \
bootxx_cd9660 bootxx_ffs
.include <bsd.subdir.mk>
diff -r 618c636373c9 -r 27a1f28c2a87 sys/arch/alpha/stand/mkbootimage/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/alpha/stand/mkbootimage/Makefile Fri Apr 02 08:40:23 1999 +0000
@@ -0,0 +1,17 @@
+# $NetBSD: Makefile,v 1.1 1999/04/02 08:40:26 cgd Exp $
+
+.include <bsd.own.mk>
+
+PROG= mkbootimage
+BINDIR= /usr/mdec
+
+WARNS?= 1
+
+SRCS= mkbootimage.c
+
+MKMAN= no
+
+CFLAGS+= -I${.CURDIR}/../..
+LDSTATIC?= -static
+
+.include <bsd.prog.mk>
diff -r 618c636373c9 -r 27a1f28c2a87 sys/arch/alpha/stand/mkbootimage/mkbootimage.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/alpha/stand/mkbootimage/mkbootimage.c Fri Apr 02 08:40:23 1999 +0000
@@ -0,0 +1,166 @@
+/* $NetBSD: mkbootimage.c,v 1.1 1999/04/02 08:40:27 cgd Exp $ */
+
+/*
+ * Copyright (c) 1999 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 <sys/param.h> /* XXX for roundup, howmany */
+#include <sys/stat.h>
+#include <sys/disklabel.h>
+#include <assert.h>
+#include <err.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+static void usage(void);
+
+extern char *__progname;
+
+static void
+usage()
+{
+ fprintf(stderr,
+ "usage: %s [-n] [-v] inputfile [outputfile]\n", __progname);
+ exit(1);
+}
+
+int
+main(int argc, char **argv)
+{
+ struct stat insb;
+ struct boot_block *bb;
+ const char *infile, *outfile;
+ char *outbuf;
+ size_t outbufsize;
+ ssize_t rv;
+ int c, verbose, nowrite, infd, outfd, i;
+
+ verbose = nowrite = 0;
+
+ while ((c = getopt(argc, argv, "nv")) != -1) {
+ switch (c) {
+ case 'n':
+ /* Do not actually write the boot file */
+ nowrite = 1;
+ break;
+ case 'v':
+ /* Chat */
+ verbose = 1;
+ break;
+ default:
+ usage();
+ }
+ }
+
+ argc -= optind;
+ argv += optind;
+
+ if (argc != 1 && argc != 2) {
+ usage();
+ }
+
+ infile = argv[0];
+ outfile = argv[1];
+
+ if (verbose) {
+ fprintf(stderr, "input file: %s\n", infile);
+ fprintf(stderr, "output file: %s\n",
+ outfile != NULL ? outfile : "<stdout>");
+ }
+ if (sizeof (struct boot_block) != BOOT_BLOCK_BLOCKSIZE)
+ errx(1, "boot_block structure badly sized (build error)");
+
+ /* Open the input file and check it out */
+ if ((infd = open(infile, O_RDONLY)) == -1)
+ err(1, "open %s", infile);
+ if (fstat(infd, &insb) == -1)
+ err(1, "fstat %s", infile);
+ if (!S_ISREG(insb.st_mode))
+ errx(1, "%s must be a regular file", infile);
+
+ /*
+ * Allocate a buffer, with space to round up the input file
+ * to the next block size boundary, and with space for the boot
+ * block.
+ */
+ outbufsize = roundup(insb.st_size, BOOT_BLOCK_BLOCKSIZE);
+ outbufsize += sizeof (struct boot_block);
+
+ outbuf = malloc(outbufsize);
+ if (outbuf == NULL)
+ err(1, "allocating output buffer");
+ memset(outbuf, 0, outbufsize);
+
+ /* read the file into the buffer, leaving room for the boot block */
+ rv = read(infd, outbuf + sizeof (struct boot_block), insb.st_size);
+ if (rv == -1)
+ err(1, "read %s", infile);
+ else if (rv != insb.st_size)
+ errx(1, "read %s: short read", infile);
+ (void)close(infd);
+
+ /* fill in the boot block fields, and checksum the boot block */
+ bb = (struct boot_block *)outbuf;
+ bb->bb_secsize = howmany(insb.st_size, BOOT_BLOCK_BLOCKSIZE);
+ bb->bb_secstart = 1;
+ for (i = 0; i < 63; i++) /* XXX use something better */
+ bb->bb_cksum += ((u_int64_t *)bb)[i];
+
+ if (verbose) {
+ fprintf(stderr, "starting sector: %qu\n",
+ (unsigned long long)bb->bb_secstart);
+ fprintf(stderr, "sector count: %qu\n",
+ (unsigned long long)bb->bb_secsize);
+ fprintf(stderr, "checksum: %#qx\n",
+ (unsigned long long)bb->bb_cksum);
+ }
+
+ if (nowrite)
+ exit(0);
+
+ /* set up the output file descriptor */
+ if (outfile == NULL) {
+ outfd = STDOUT_FILENO;
+ outfile = "<stdout>";
+ } else if ((outfd = open(outfile, O_WRONLY|O_CREAT, 0666)) == -1)
+ err(1, "open %s", outfile);
+
+ /* write the data */
+ rv = write(outfd, outbuf, outbufsize);
+ if (rv == -1)
+ err(1, "write %s", outfile);
+ else if (rv != outbufsize)
+ errx(1, "write %s: short write", outfile);
+ (void)close(outfd);
+
+ exit(0);
+}
Home |
Main Index |
Thread Index |
Old Index