Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/installboot Add support for alpha, based on {vax, pm...



details:   https://anonhg.NetBSD.org/src/rev/721054a29664
branches:  trunk
changeset: 524998:721054a29664
user:      lukem <lukem%NetBSD.org@localhost>
date:      Wed Apr 03 10:21:01 2002 +0000

description:
Add support for alpha, based on {vax,pmax}.c and
sys/arch/alpha/stand/installboot.
XXX: not fully tested yet.

diffstat:

 usr.sbin/installboot/Makefile      |    4 +-
 usr.sbin/installboot/arch/alpha.c  |  477 +++++++++++++++++++++++++++++++++++++
 usr.sbin/installboot/installboot.8 |   11 +-
 usr.sbin/installboot/machines.c    |    6 +-
 4 files changed, 493 insertions(+), 5 deletions(-)

diffs (truncated from 557 to 300 lines):

diff -r 1ea0862dc1fb -r 721054a29664 usr.sbin/installboot/Makefile
--- a/usr.sbin/installboot/Makefile     Wed Apr 03 10:17:01 2002 +0000
+++ b/usr.sbin/installboot/Makefile     Wed Apr 03 10:21:01 2002 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.4 2002/04/03 09:09:01 lukem Exp $
+#      $NetBSD: Makefile,v 1.5 2002/04/03 10:21:01 lukem Exp $
 #
 
 PROG=  installboot
@@ -12,7 +12,7 @@
 
 # list of MACHINEs to build this version of installboot for.
 #
-IB_MACHINES?=  pmax vax
+IB_MACHINES?=  alpha pmax vax
 
 SRCS+=         ${IB_MACHINES:S/$/.c/}
 
diff -r 1ea0862dc1fb -r 721054a29664 usr.sbin/installboot/arch/alpha.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/installboot/arch/alpha.c Wed Apr 03 10:21:01 2002 +0000
@@ -0,0 +1,477 @@
+/*     $NetBSD: alpha.c,v 1.1 2002/04/03 10:21:03 lukem Exp $  */
+
+/*-
+ * Copyright (c) 2002 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Luke Mewburn of Wasabi Systems.
+ *
+ * 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 the NetBSD
+ *     Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * 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.
+ */
+
+/*
+ * Copyright (c) 1999 Ross Harvey.  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 Ross Harvey
+ *     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.
+ */
+
+/*
+ * 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/cdefs.h>
+#if defined(__RCSID) && !defined(__lint)
+__RCSID("$NetBSD: alpha.c,v 1.1 2002/04/03 10:21:03 lukem Exp $");
+#endif /* !__lint */
+
+#include <sys/param.h>
+#include <sys/stat.h>
+
+#include <assert.h>
+#include <err.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <dev/dec/dec_boot.h>
+#include <dev/sun/disklabel.h>         // XXX: for SUN_DKMAGIC
+
+#include "installboot.h"
+
+int            alpha_parseopt(ib_params *, const char *);
+int            alpha_setboot(ib_params *);
+int            alpha_clearboot(ib_params *);
+static void    resum(ib_params *, struct alpha_boot_block * const bb,
+                       u_int16_t *bb16);
+static void    sun_bootstrap(ib_params *, struct alpha_boot_block * const);
+static void    check_sparc(const struct alpha_boot_block * const,
+                           const char *);
+
+
+int
+alpha_parseopt(ib_params *params, const char *option)
+{
+
+       if (parseoptionflag(params, option,
+           IB_ALPHASUM | IB_APPEND | IB_SUNSUM))
+               return (1);
+
+       warnx("Unknown -o option `%s'", option);
+       return (0);
+}
+
+int
+alpha_clearboot(ib_params *params)
+{
+       struct alpha_boot_block bb;
+       u_int64_t               cksum;
+       ssize_t                 rv;
+
+       assert(params != NULL);
+       assert(params->fsfd != -1);
+       assert(params->filesystem != NULL);
+       assert(sizeof(struct alpha_boot_block) == ALPHA_BOOT_BLOCK_BLOCKSIZE);
+
+       if (params->flags & (IB_STARTBLOCK | IB_APPEND)) {
+               warnx("Can't use `-b bno' or `-o append' with `-c'");
+               return (0);
+       }
+       rv = pread(params->fsfd, &bb, sizeof(bb), ALPHA_BOOT_BLOCK_OFFSET);
+       if (rv == -1) {
+               warn("Reading `%s'", params->filesystem);
+               return (0);
+       } else if (rv != sizeof(bb)) {
+               warnx("Reading `%s': short read", params->filesystem);
+               return (0);
+       }
+       ALPHA_BOOT_BLOCK_CKSUM(&bb, &cksum);
+       if (cksum != bb.bb_cksum) {             // XXX check bb_cksum endian?
+               warnx(
+           "Old boot block checksum invalid (was %#llx, calculated %#llx)",
+                   (unsigned long long)bb.bb_cksum,
+                   (unsigned long long)cksum);
+               warnx("Boot block invalid\n");
+               return (0);
+       }
+
+       if (params->flags & IB_VERBOSE) {
+               printf("Old boot block start sector: %#llx\n",
+                   (unsigned long long)le64toh(bb.bb_secstart));
+               printf("Old boot block size:         %#llx\n",
+                   (unsigned long long)le64toh(bb.bb_secsize));
+               printf("Old boot block checksum:     %#llx\n",
+                   (unsigned long long)bb.bb_cksum);
+       }
+
+       bb.bb_secstart = bb.bb_secsize = bb.bb_flags = 0;
+
+       ALPHA_BOOT_BLOCK_CKSUM(&bb, &bb.bb_cksum);
+       if (params->flags & IB_SUNSUM)
+               sun_bootstrap(params, &bb);
+
+       printf("New boot block start sector: %#llx\n",
+           (unsigned long long)le64toh(bb.bb_secstart));
+       printf("New boot block size:         %#llx\n",
+           (unsigned long long)le64toh(bb.bb_secsize));
+       printf("New boot block checksum:     %#llx\n",
+           (unsigned long long)bb.bb_cksum);
+
+       if (params->flags & IB_VERBOSE)
+               printf("%slearing boot block\n",
+                   (params->flags & IB_NOWRITE) ? "Not c" : "C");
+       if (params->flags & IB_NOWRITE)
+               return (1);
+
+       rv = pwrite(params->fsfd, &bb, sizeof(bb), ALPHA_BOOT_BLOCK_OFFSET);
+       if (rv == -1) {
+               warn("Writing `%s'", params->filesystem);
+               return (0);
+       } else if (rv != sizeof(bb)) {
+               warnx("Writing `%s': short write", params->filesystem);
+               return (0);
+       }
+
+       return (1);
+}
+
+int
+alpha_setboot(ib_params *params)
+{
+       struct stat             bootstrapsb;
+       struct alpha_boot_block bb;
+       u_int64_t               startblock;
+       int                     retval;
+       char                    *bootstrapbuf;
+       size_t                  bootstrapsize;
+       ssize_t                 rv;
+
+       assert(params != NULL);
+       assert(params->fsfd != -1);
+       assert(params->filesystem != NULL);
+       assert(params->bbfd != -1);
+       assert(params->bootblock != NULL);
+       assert(sizeof(struct alpha_boot_block) == ALPHA_BOOT_BLOCK_BLOCKSIZE);
+
+       retval = 0;
+       bootstrapbuf = NULL;
+
+       if ((params->flags & IB_STARTBLOCK) &&
+           (params->flags & IB_APPEND)) {
+               warnx("Can't use `-b bno' with `-o append'");
+               goto done;
+       }
+
+       if (fstat(params->bbfd, &bootstrapsb) == -1) {
+               warn("Examining `%s'", params->bootblock);
+               goto done;
+       }
+       if (!S_ISREG(bootstrapsb.st_mode)) {
+               warnx("`%s' must be a regular file", params->bootblock);
+               goto done;
+       }
+       /*
+        * Allocate a buffer, with space to round up the input file
+        * to the next block size boundary, and with space for the boot
+        * block.
+        */
+       bootstrapsize = roundup(bootstrapsb.st_size,
+           ALPHA_BOOT_BLOCK_BLOCKSIZE);
+
+       bootstrapbuf = malloc(bootstrapsize);
+       if (bootstrapbuf == NULL) {
+               warn("Allocating %lu bytes", (unsigned long) bootstrapsize);
+               goto done;
+       }
+       memset(bootstrapbuf, 0, bootstrapsize);
+
+       /* read the file into the buffer */
+       rv = pread(params->bbfd, bootstrapbuf, bootstrapsb.st_size, 0);
+       if (rv == -1) {
+               warn("Reading `%s'", params->bootblock);
+               return (0);
+       } else if (rv != sizeof(bb)) {
+               warnx("Reading `%s': short read", params->bootblock);
+               return (0);
+       }
+
+       rv = pread(params->fsfd, &bb, sizeof(bb), ALPHA_BOOT_BLOCK_OFFSET);
+       if (rv == -1) {
+               warn("Reading `%s'", params->filesystem);
+               goto done;



Home | Main Index | Thread Index | Old Index