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 next68k support to installboot



details:   https://anonhg.NetBSD.org/src/rev/36a9528387f8
branches:  trunk
changeset: 554383:36a9528387f8
user:      cl <cl%NetBSD.org@localhost>
date:      Mon Oct 27 16:51:05 2003 +0000

description:
add next68k support to installboot

diffstat:

 usr.sbin/installboot/Makefile       |    4 +-
 usr.sbin/installboot/arch/next68k.c |  269 ++++++++++++++++++++++++++++++++++++
 usr.sbin/installboot/installboot.8  |   30 +++-
 usr.sbin/installboot/installboot.h  |    3 +-
 usr.sbin/installboot/machines.c     |    6 +-
 5 files changed, 306 insertions(+), 6 deletions(-)

diffs (truncated from 414 to 300 lines):

diff -r 7724ec044c4a -r 36a9528387f8 usr.sbin/installboot/Makefile
--- a/usr.sbin/installboot/Makefile     Mon Oct 27 16:48:08 2003 +0000
+++ b/usr.sbin/installboot/Makefile     Mon Oct 27 16:51:05 2003 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.24 2003/05/18 07:57:39 lukem Exp $
+#      $NetBSD: Makefile,v 1.25 2003/10/27 16:51:05 cl Exp $
 #
 
 .include <bsd.own.mk>
@@ -6,7 +6,7 @@
 PROG=  installboot
 SRCS=  installboot.c sum.c machines.c fstypes.c \
        ffs.c ffs_bswap.c bbinfo.c \
-       alpha.c amiga.c i386.c macppc.c news.c pmax.c \
+       alpha.c amiga.c i386.c macppc.c news.c next68k.c pmax.c \
        sparc.c sparc64.c sun68k.c vax.c x68k.c
 MAN=   installboot.8
 
diff -r 7724ec044c4a -r 36a9528387f8 usr.sbin/installboot/arch/next68k.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/installboot/arch/next68k.c       Mon Oct 27 16:51:05 2003 +0000
@@ -0,0 +1,269 @@
+/* $NetBSD: next68k.c,v 1.1 2003/10/27 16:51:06 cl Exp $ */
+
+/*-
+ * Copyright (c) 2003 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by David Laight and Christian Limpach.
+ *
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+#if defined(__RCSID) && !defined(__lint)
+__RCSID("$NetBSD: next68k.c,v 1.1 2003/10/27 16:51:06 cl Exp $");
+#endif /* __RCSID && !__lint */
+
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
+#include <sys/param.h>
+
+#include <assert.h>
+#include <err.h>
+#include <md5.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "installboot.h"
+
+#define        SECTOR_SIZE     DEV_BSIZE
+
+static uint16_t nextstep_checksum(const void *, const void *);
+
+static uint16_t
+nextstep_checksum(const void *vbuf, const void *vlimit)
+{
+       const uint16_t *buf = vbuf;
+       const uint16_t *limit = vlimit;
+       uint sum = 0;
+
+       while (buf < limit) {
+               sum += be16toh(*buf++);
+       }
+       sum += (sum >> 16);
+       return (sum & 0xffff);
+}
+
+int
+next68k_setboot(ib_params *params)
+{
+       int retval, labelupdated;
+       uint8_t *bootbuf;
+       uint bootsize;
+       ssize_t rv;
+       uint32_t cd_secsize;
+       int sec_netonb_mult;
+       struct next68k_disklabel *next68klabel;
+       uint16_t *checksum;
+       uint32_t fp, b0, b1;
+
+       assert(params != NULL);
+       assert(params->fsfd != -1);
+       assert(params->filesystem != NULL);
+       assert(params->s1fd != -1);
+       assert(params->stage1 != NULL);
+
+       retval = 0;
+       labelupdated = 0;
+       bootbuf = NULL;
+
+       next68klabel = malloc(NEXT68K_LABEL_SIZE);
+       if (next68klabel == NULL) {
+               warnx("malloc");
+               goto done;
+       }
+
+       /*
+        * Read in the next68k disklabel
+        */
+       rv = pread(params->fsfd, next68klabel, NEXT68K_LABEL_SIZE,
+           NEXT68K_LABEL_SECTOR * SECTOR_SIZE + NEXT68K_LABEL_OFFSET);
+       if (rv == -1) {
+               warn("Reading `%s'", params->filesystem);
+               goto done;
+       }
+       if (rv != NEXT68K_LABEL_SIZE) {
+               warnx("Reading `%s': short read", params->filesystem);
+               goto done;
+       }
+       if (be32toh(next68klabel->cd_version) == NEXT68K_LABEL_CD_V3) {
+               checksum = &next68klabel->NEXT68K_LABEL_cd_v3_checksum;
+       } else {
+               checksum = &next68klabel->cd_checksum;
+       }
+       if (nextstep_checksum (next68klabel, checksum) !=
+           be16toh(*checksum)) {
+               warn("disklabel checksum invalid on `%s'",
+                   params->filesystem);
+               goto done;
+       }
+
+       cd_secsize = be32toh(next68klabel->cd_secsize);
+       sec_netonb_mult = (cd_secsize / SECTOR_SIZE);
+
+       /*
+        * Allocate a buffer, with space to round up the input file
+        * to the next block size boundary, and with space for the boot
+        * block.
+        */
+       bootsize = roundup(params->s1stat.st_size, cd_secsize);
+
+       bootbuf = malloc(bootsize);
+       if (bootbuf == NULL) {
+               warn("malloc");
+               goto done;
+       }
+       memset(bootbuf, 0, bootsize);
+
+       /*
+        * Read the file into the buffer.
+        */
+       rv = pread(params->s1fd, bootbuf, params->s1stat.st_size, 0);
+       if (rv == -1) {
+               warn("Reading `%s'", params->stage1);
+               goto done;
+       } else if (rv != params->s1stat.st_size) {
+               warnx("Reading `%s': short read", params->stage1);
+               goto done;
+       }
+
+       if (bootsize > be16toh(next68klabel->cd_front) * cd_secsize - 
+           NEXT68K_LABEL_SIZE) {
+               warnx("Boot program is larger than front porch space");
+               goto done;
+       }
+
+       fp = be16toh(next68klabel->cd_front);
+       b0 = be32toh(next68klabel->cd_boot_blkno[0]);
+       b1 = be32toh(next68klabel->cd_boot_blkno[1]);
+
+       if (b0 > fp)
+               b0 = fp;
+       if (b1 > fp)
+               b1 = fp;
+       if (((bootsize / cd_secsize) > b1 - b0) ||
+           ((bootsize / cd_secsize) > fp - b1)) {
+               if (2 * bootsize > (fp * cd_secsize - NEXT68K_LABEL_SIZE))
+                       /* can only fit one copy */
+                       b0 = b1 = NEXT68K_LABEL_SIZE / cd_secsize;
+               else {
+                       if (2 * bootsize > (fp * cd_secsize - 
+                               NEXT68K_LABEL_DEFAULTBOOT0_1 * SECTOR_SIZE))
+                               /* can fit two copies starting after label */
+                               b0 = NEXT68K_LABEL_SIZE / cd_secsize;
+                       else
+                               /* can fit two copies starting at default 1 */
+                               b0 = NEXT68K_LABEL_DEFAULTBOOT0_1 /
+                                       sec_netonb_mult;
+                       /* try to fit 2nd copy at default 2 */
+                       b1 = NEXT68K_LABEL_DEFAULTBOOT0_2 / sec_netonb_mult;
+                       if (fp < b1)
+                               b1 = fp;
+                       if (bootsize / cd_secsize > (fp - b1))
+                               /* fit 2nd copy before front porch */
+                               b1 = fp - bootsize / cd_secsize;
+               }
+       }
+       if (next68klabel->cd_boot_blkno[0] != htobe32(b0)) {
+               next68klabel->cd_boot_blkno[0] = htobe32(b0);
+               labelupdated = 1;
+       }
+       if (next68klabel->cd_boot_blkno[1] != htobe32(b1)) {
+               next68klabel->cd_boot_blkno[1] = htobe32(b1);
+               labelupdated = 1;
+       }
+       if (params->flags & IB_VERBOSE)
+               printf("Boot programm locations%s: %d %d\n",
+                   labelupdated ? " updated" : "", b0 * sec_netonb_mult,
+                   b1 * sec_netonb_mult);
+
+       if (params->flags & IB_NOWRITE) {
+               retval = 1;
+               goto done;
+       }
+
+       /*
+        * Write the updated next68k disklabel
+        */
+       if (labelupdated) {
+               if (params->flags & IB_VERBOSE)
+                       printf ("Writing updated label\n");
+               *checksum = htobe16(nextstep_checksum (next68klabel,
+                                       checksum));
+               rv = pwrite(params->fsfd, next68klabel, NEXT68K_LABEL_SIZE,
+                   NEXT68K_LABEL_SECTOR * SECTOR_SIZE + NEXT68K_LABEL_OFFSET);
+               if (rv == -1) {
+                       warn("Writing `%s'", params->filesystem);
+                       goto done;
+               }
+               if (rv != NEXT68K_LABEL_SIZE) {
+                       warnx("Writing `%s': short write", params->filesystem);
+                       goto done;
+               }
+       }
+       
+       b0 *= sec_netonb_mult;
+       b1 *= sec_netonb_mult;
+
+       /*
+        * Write boot program to locations b0 and b1 (if different).
+        */
+       for (;;) {
+               if (params->flags & IB_VERBOSE)
+                       printf ("Writing boot program at %d\n", b0);
+               rv = pwrite(params->fsfd, bootbuf, bootsize, b0 * SECTOR_SIZE);
+               if (rv == -1) {
+                       warn("Writing `%s' at %d", params->filesystem, b0);
+                       goto done;
+               }
+               if (rv != bootsize) {
+                       warnx("Writing `%s' at %d: short write", 
+                           params->filesystem, b0);
+                       goto done;
+               }
+               if (b0 == b1)
+                       break;
+               b0 = b1;
+       }
+
+       retval = 1;
+
+ done:
+       if (bootbuf)
+               free(bootbuf);
+       if (next68klabel)
+               free(next68klabel);
+       return retval;
+}
diff -r 7724ec044c4a -r 36a9528387f8 usr.sbin/installboot/installboot.8
--- a/usr.sbin/installboot/installboot.8        Mon Oct 27 16:48:08 2003 +0000
+++ b/usr.sbin/installboot/installboot.8        Mon Oct 27 16:51:05 2003 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: installboot.8,v 1.31 2003/10/08 04:25:46 lukem Exp $
+.\"    $NetBSD: installboot.8,v 1.32 2003/10/27 16:51:05 cl Exp $
 .\"
 .\" Copyright (c) 2002-2003 The NetBSD Foundation, Inc.
 .\" All rights reserved.



Home | Main Index | Thread Index | Old Index