Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/installboot bootblock.h:



details:   https://anonhg.NetBSD.org/src/rev/a8ce743fa883
branches:  trunk
changeset: 526982:a8ce743fa883
user:      lukem <lukem%NetBSD.org@localhost>
date:      Wed May 15 09:56:59 2002 +0000

description:
bootblock.h:
- unify sparc_bbinfo (1064 bytes, with 256 block entries)
  and sun68k_bbinfo (296 byte, with 64 block entries)
  into shared_bbinfo (512 bytes, with 118 block entries),
  which will be also shared by future bbinfo-using platforms
  (including macppc)
- add datestamp to *_BBINFO_MAGIC strings, to prevent installboot vs
  bootxx version skew.
- add macppc support

*/bootxx.c:
- migrate to new shared_bbinfo structure

installboot:
- add macppc support (still needs applepartmap support and testing)
- improve and add some more warnings & errors to installboot
- implement shared_bbinfo_clearboot() and shared_bbinfo_setboot(), which
  perform the majority of the work for bbinfo-using back-ends
  (rather than replicating that across multiple back-ends).

diffstat:

 usr.sbin/installboot/arch/macppc.c |   92 ++++++++++++
 usr.sbin/installboot/bbinfo.c      |  283 +++++++++++++++++++++++++++++++++++++
 2 files changed, 375 insertions(+), 0 deletions(-)

diffs (truncated from 383 to 300 lines):

diff -r a5168695d54f -r a8ce743fa883 usr.sbin/installboot/arch/macppc.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/installboot/arch/macppc.c        Wed May 15 09:56:59 2002 +0000
@@ -0,0 +1,92 @@
+/*     $NetBSD: macppc.c,v 1.1 2002/05/15 09:56:59 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.
+ *
+ * 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: macppc.c,v 1.1 2002/05/15 09:56:59 lukem Exp $");
+#endif /* !__lint */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+
+#include <assert.h>
+#include <err.h>
+#include <stdio.h>
+
+#include "installboot.h"
+
+static struct bbinfo_params bbparams = {
+       MACPPC_BBINFO_MAGIC,
+       MACPPC_BOOT_BLOCK_OFFSET,
+       MACPPC_BOOT_BLOCK_BLOCKSIZE,
+       MACPPC_BOOT_BLOCK_MAX_SIZE,
+       0,
+       0,
+};
+
+
+int
+macppc_clearboot(ib_params *params)
+{
+
+       assert(params != NULL);
+
+       if (params->flags & IB_STAGE1START) {
+               warnx("`-b bno' is not supported for %s",
+                   params->machine->name);
+               return (0);
+       }
+       return (shared_bbinfo_clearboot(params, &bbparams));
+}
+
+int
+macppc_setboot(ib_params *params)
+{
+
+       assert(params != NULL);
+
+       if (params->flags & IB_STAGE1START) {
+               warnx("`-b bno' is not supported for %s",
+                   params->machine->name);
+               return (0);
+       }
+       return (shared_bbinfo_setboot(params, &bbparams, NULL));
+}
diff -r a5168695d54f -r a8ce743fa883 usr.sbin/installboot/bbinfo.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/installboot/bbinfo.c     Wed May 15 09:56:59 2002 +0000
@@ -0,0 +1,283 @@
+/*     $NetBSD: bbinfo.c,v 1.1 2002/05/15 09:56:59 lukem Exp $ */
+
+/*-
+ * Copyright (c) 1998, 2002 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Matt Fredette, Paul Kranenburg, and Luke Mewburn.
+ *
+ * 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: bbinfo.c,v 1.1 2002/05/15 09:56:59 lukem Exp $");
+#endif /* !__lint */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+
+#include <assert.h>
+#include <err.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "installboot.h"
+
+int
+shared_bbinfo_clearboot(ib_params *params, struct bbinfo_params *bbparams)
+{
+       char    *bb;
+       ssize_t rv;
+       int     retval;
+
+       assert(params != NULL);
+       assert(params->fsfd != -1);
+       assert(params->filesystem != NULL);
+       assert(bbparams != NULL);
+       assert((strlen(bbparams->magic) + 1) == 32);
+
+       retval = 0;
+       if ((bb = malloc(bbparams->maxsize)) == NULL) {
+               warn("Allocating %lu bytes for bbinfo", 
+                   (unsigned long) bbparams->maxsize);
+               goto done;
+       }
+
+       if (params->flags & IB_STAGE2START) {
+               warnx("Can't use `-B bno' with `-c'");
+               goto done;
+       }
+
+               /* first check that it _could_ exist here */
+       rv = pread(params->fsfd, bb, bbparams->maxsize, bbparams->offset);
+       if (rv == -1) {
+               warn("Reading `%s'", params->filesystem);
+               goto done;
+       } else if (rv != bbparams->maxsize) {
+               warnx("Reading `%s': short read", params->filesystem);
+               goto done;
+       }
+
+               /* now clear it out to nothing */
+       memset(bb, 0, bbparams->maxsize);
+
+       if (params->flags & IB_VERBOSE)
+               printf("%slearing boot block\n",
+                   (params->flags & IB_NOWRITE) ? "Not c" : "C");
+       if (params->flags & IB_NOWRITE) {
+               retval = 1;
+               goto done;
+       }
+
+       rv = pwrite(params->fsfd, bb, bbparams->maxsize, bbparams->offset);
+       if (rv == -1) {
+               warn("Writing `%s'", params->filesystem);
+               goto done;
+       } else if (rv != bbparams->maxsize) {
+               warnx("Writing `%s': short write", params->filesystem);
+               goto done;
+       } else
+               retval = 1;
+
+ done:
+       if (bb != NULL)
+               free(bb);
+       return (retval);
+}
+
+int
+shared_bbinfo_setboot(ib_params *params, struct bbinfo_params *bbparams,
+       int (*callback)(ib_params *, struct bbinfo_params *, char *))
+{
+       char            *bb;
+       int             retval;
+       ssize_t         rv;
+       size_t          bbi;
+       struct shared_bbinfo    *bbinfop;       /* bbinfo in prototype image */
+       uint32_t        maxblk, nblk, blk_i;
+       ib_block        *blocks;
+
+       assert(params != NULL);
+       assert(params->fsfd != -1);
+       assert(params->filesystem != NULL);
+       assert(params->fstype != NULL);
+       assert(params->s1fd != -1);
+       assert(params->stage1 != NULL);
+       assert(bbparams != NULL);
+       assert((strlen(bbparams->magic) + 1) == 32);
+
+       retval = 0;
+       blocks = NULL;
+       if ((bb = malloc(bbparams->maxsize)) == NULL) {
+               warn("Allocating %lu bytes for bbinfo", 
+                   (unsigned long) bbparams->maxsize);
+               goto done;
+       }
+
+       if (params->stage2 == NULL) {
+               warnx("Name of secondary bootstrap not provided");
+               goto done;
+       }
+
+       if (params->s1stat.st_size >
+           bbparams->maxsize - bbparams->headeroffset) {
+               warnx("`%s' cannot be larger than %lu bytes",
+                   params->stage1, (unsigned long)(bbparams->maxsize -
+                       bbparams->headeroffset));
+               goto done;
+       }
+
+       memset(bb, 0, bbparams->maxsize);
+       rv = read(params->s1fd, bb + bbparams->headeroffset,
+           bbparams->maxsize - bbparams->headeroffset);
+       if (rv == -1) {
+               warn("Reading `%s'", params->stage1);
+               goto done;
+       }
+
+       /*
+        * Quick sanity check that the bootstrap given
+        * is *not* an ELF executable.
+        */
+       if (memcmp(bb + bbparams->headeroffset + 1, "ELF", strlen("ELF"))
+           == 0) {
+               warnx("`%s' is an ELF executable; need raw binary", 
+                   params->stage1);
+               goto done;
+       }
+
+#define HOSTTOTARGET32(x) (bbparams->littleendian ? le32toh((x)) : be32toh((x)))
+
+       /* Look for the bbinfo structure. */
+       for (bbi = 0; bbi < bbparams->maxsize; bbi += sizeof(uint32_t)) {
+               bbinfop = (void *) (bb + bbi);
+               if (memcmp(bbinfop->bbi_magic, bbparams->magic,
+                           sizeof(bbinfop->bbi_magic)) == 0)
+                       break;
+       }
+       if (bbi >= bbparams->maxsize) {
+               warnx("%s bbinfo structure not found in `%s'", 
+                   params->machine->name, params->stage1);
+               goto done;
+       }
+       maxblk = HOSTTOTARGET32(bbinfop->bbi_block_count);
+       if (maxblk == 0 || maxblk > (bbparams->maxsize / sizeof(uint32_t))) {
+               warnx("%s bbinfo structure in `%s' has preposterous size `%u'",
+                   params->machine->name, params->stage1, maxblk);



Home | Main Index | Thread Index | Old Index