Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/news68k Use a magic structure with a magic number i...
details: https://anonhg.NetBSD.org/src/rev/221f44d1aeb1
branches: trunk
changeset: 526188:221f44d1aeb1
user: tsutsui <tsutsui%NetBSD.org@localhost>
date: Sat Apr 27 10:19:57 2002 +0000
description:
Use a magic structure with a magic number instead of using nlist(3)
for installboot(8) to patch proto bootblocks.
(This is a preparation to migrate MI installboot.)
diffstat:
sys/arch/news68k/include/bbinfo.h | 43 +++++++
sys/arch/news68k/stand/bootxx/bootxx.c | 30 +++--
sys/arch/news68k/stand/installboot/installboot.c | 128 +++++-----------------
3 files changed, 90 insertions(+), 111 deletions(-)
diffs (truncated from 343 to 300 lines):
diff -r e7456e5bbc37 -r 221f44d1aeb1 sys/arch/news68k/include/bbinfo.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/news68k/include/bbinfo.h Sat Apr 27 10:19:57 2002 +0000
@@ -0,0 +1,43 @@
+/* $NetBSD: bbinfo.h,v 1.1 2002/04/27 10:19:57 tsutsui Exp $ */
+
+/*
+ * Copyright (c) 1995, 1996 Carnegie-Mellon University.
+ * All rights reserved.
+ *
+ * Author: Chris G. Demetriou
+ *
+ * Permission to use, copy, modify and distribute this software and
+ * its documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ *
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
+ * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
+ * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * Carnegie Mellon requests users of this software to return to
+ *
+ * Software Distribution Coordinator or Software.Distribution%CS.CMU.EDU@localhost
+ * School of Computer Science
+ * Carnegie Mellon University
+ * Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie the
+ * rights to redistribute these changes.
+ */
+
+#define MAXBLOCKNUM 64 /* enough for a 512k boot program (bs 8K) */
+#define BOOTSECTOR_OFFSET 512
+
+/* Magic string -- 32 bytes long (including the NUL) */
+#define BBINFO_MAGIC "NetBSD/news68k bootxx "
+#define BBINFO_MAGICSIZE sizeof(BBINFO_MAGIC)
+
+struct bbinfo {
+ uint8_t bbi_magic[BBINFO_MAGICSIZE];
+ int32_t bbi_block_size;
+ int32_t bbi_block_count;
+ int32_t bbi_block_table[MAXBLOCKNUM];
+ uint32_t bbi_entry_point;
+};
diff -r e7456e5bbc37 -r 221f44d1aeb1 sys/arch/news68k/stand/bootxx/bootxx.c
--- a/sys/arch/news68k/stand/bootxx/bootxx.c Sat Apr 27 08:11:53 2002 +0000
+++ b/sys/arch/news68k/stand/bootxx/bootxx.c Sat Apr 27 10:19:57 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bootxx.c,v 1.1 1999/12/09 14:53:23 tsutsui Exp $ */
+/* $NetBSD: bootxx.c,v 1.2 2002/04/27 10:19:58 tsutsui Exp $ */
/*-
* Copyright (C) 1999 Izumi Tsutsui. All rights reserved.
@@ -30,13 +30,15 @@
#include <lib/libkern/libkern.h>
#include <lib/libsa/stand.h>
#include <machine/romcall.h>
-
-#define MAXBLOCKNUM 64
+#include <machine/bbinfo.h>
-void (*entry_point)() = (void *)0x3e0000;
-int block_size = 8192;
-int block_count = MAXBLOCKNUM;
-int block_table[MAXBLOCKNUM] = { 0 };
+struct bbinfo bbinfo = {
+ { BBINFO_MAGIC }, /* bbi_magic[] */
+ 0, /* bbi_block_size */
+ MAXBLOCKNUM, /* bbi_block_count */
+ { 0 }, /* bbi_block_table[] */
+ 0x3e0000 /* bbi_entry_point */
+};
#ifdef BOOTXX_DEBUG
# define DPRINTF printf
@@ -55,6 +57,7 @@
int i;
int bootdev = d6;
char *addr;
+ void (*entry_point)(u_int32_t, u_int32_t, u_int32_t, u_int32_t);
char devname[32];
printf("NetBSD/news68k Primary Boot\n");
@@ -65,9 +68,9 @@
DPRINTF("d6 %x\n", d6);
DPRINTF("d7 %x\n", d7);
- DPRINTF("block_size = %d\n", block_size);
- DPRINTF("block_count = %d\n", block_count);
- DPRINTF("entry_point = %x\n", (int)entry_point);
+ DPRINTF("block_size = %d\n", bbinfo.bbi_block_size);
+ DPRINTF("block_count = %d\n", bbinfo.bbi_block_count);
+ DPRINTF("entry_point = %x\n", bbinfo.bbi_entry_point);
/* sd(ctlr, lun, part, bus?, host) */
@@ -89,11 +92,12 @@
return;
}
+ entry_point = (void *)bbinfo.bbi_entry_point;
addr = (char *)entry_point;
- bs = block_size;
+ bs = bbinfo.bbi_block_size;
DPRINTF("reading block:");
- for (i = 0; i < block_count; i++) {
- blk = block_table[i];
+ for (i = 0; i < bbinfo.bbi_block_count; i++) {
+ blk = bbinfo.bbi_block_table[i];
DPRINTF(" %d", blk);
diff -r e7456e5bbc37 -r 221f44d1aeb1 sys/arch/news68k/stand/installboot/installboot.c
--- a/sys/arch/news68k/stand/installboot/installboot.c Sat Apr 27 08:11:53 2002 +0000
+++ b/sys/arch/news68k/stand/installboot/installboot.c Sat Apr 27 10:19:57 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: installboot.c,v 1.4 2001/01/30 14:11:01 tsutsui Exp $ */
+/* $NetBSD: installboot.c,v 1.5 2002/04/27 10:19:59 tsutsui Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -43,47 +43,21 @@
#include <err.h>
#include <a.out.h>
#include <fcntl.h>
-#include <nlist.h>
#include <stdlib.h>
#include <stdio.h>
+#include <stddef.h>
#include <string.h>
#include <unistd.h>
#include "loadfile.h"
+#include "byteorder.h"
+#include "machine/bbinfo.h"
+#include "machine/disklabel.h"
int verbose, nowrite;
char *boot, *proto, *dev;
-#define BOOTSECTOR_OFFSET 512
-#define LABELOFFSET 64
-
-#if 0
-#ifdef __ELF__
-#define SYMNAME(a) a
-#else
-#define SYMNAME(a) __CONCAT("_",a)
-#endif
-#else
-/* XXX: Hack in libc nlist works with both formats */
-#define SYMNAME(a) __CONCAT("_",a)
-#endif
-
-struct nlist nl[] = {
-#define X_BLOCKTABLE 0
- { {SYMNAME("block_table")} },
-#define X_BLOCKCOUNT 1
- { {SYMNAME("block_count")} },
-#define X_BLOCKSIZE 2
- { {SYMNAME("block_size")} },
-#define X_ENTRY_POINT 3
- { {SYMNAME("entry_point")} },
- { {NULL} }
-};
-
-daddr_t *block_table; /* block number array in prototype image */
-int32_t *block_count_p; /* size of this array */
-int32_t *block_size_p; /* filesystem block size */
-int32_t *entry_point_p; /* entry_point */
+struct bbinfo *bbinfo_p;
int32_t max_block_count;
char *loadprotoblocks __P((char *, size_t *));
@@ -109,7 +83,7 @@
int devfd;
char *protostore;
size_t protosize;
- u_int32_t boot00[BOOTSECTOR_OFFSET / sizeof(u_int32_t)];
+ uint32_t boot00[BOOTSECTOR_OFFSET / sizeof(uint32_t)];
while ((c = getopt(argc, argv, "vn")) != EOF) {
switch (c) {
@@ -171,7 +145,8 @@
/* Sync filesystems (to clean in-memory superblock?) */
sync(); sync(); sync();
- if (write(devfd, protostore, protosize) != protosize)
+ if (write(devfd, protostore + BOOTSECTOR_OFFSET,
+ protosize - BOOTSECTOR_OFFSET) != protosize - BOOTSECTOR_OFFSET)
err(1, "write bootstrap");
/* Write boot00 */
@@ -180,9 +155,7 @@
if (read(devfd, boot00, sizeof(boot00)) != sizeof(boot00))
err(1, "read boot00");
- memset(boot00, 0, LABELOFFSET);
- boot00[0] = 0x600001fe; /* jra +0x200 */
- boot00[2] = 0x0;
+ memcpy(boot00, protostore, LABELOFFSET);
if (lseek(devfd, 0, SEEK_SET) != 0)
err(1, "lseek 0b");
if (write(devfd, boot00, sizeof(boot00)) != sizeof(boot00))
@@ -198,31 +171,9 @@
size_t *size;
{
int fd, sz;
- u_long ap, bp, st;
+ u_long ap, bp, st, bbi;
u_long marks[MARK_MAX];
- /* Locate block number array in proto file */
- if (nlist(fname, nl) != 0) {
- warnx("nlist: %s: symbols not found", fname);
- return NULL;
- }
- if (nl[X_BLOCKTABLE].n_type != N_DATA + N_EXT) {
- warnx("nlist: %s: wrong type", nl[X_BLOCKTABLE].n_un.n_name);
- return NULL;
- }
- if (nl[X_BLOCKCOUNT].n_type != N_DATA + N_EXT) {
- warnx("nlist: %s: wrong type", nl[X_BLOCKCOUNT].n_un.n_name);
- return NULL;
- }
- if (nl[X_BLOCKSIZE].n_type != N_DATA + N_EXT) {
- warnx("nlist: %s: wrong type", nl[X_BLOCKSIZE].n_un.n_name);
- return NULL;
- }
- if (nl[X_ENTRY_POINT].n_type != N_DATA + N_EXT) {
- warnx("nlist: %s: wrong type", nl[X_ENTRY_POINT].n_un.n_name);
- return NULL;
- }
-
marks[MARK_START] = 0;
if ((fd = loadfile(fname, marks, COUNT_TEXT|COUNT_DATA)) == -1)
return NULL;
@@ -243,47 +194,27 @@
return NULL;
(void)close(fd);
- block_table = (daddr_t *)(bp + nl[X_BLOCKTABLE].n_value - st);
- block_count_p = (int32_t *)(bp + nl[X_BLOCKCOUNT].n_value - st);
- block_size_p = (int32_t *)(bp + nl[X_BLOCKSIZE].n_value - st);
- entry_point_p = (int32_t *)(bp + nl[X_ENTRY_POINT].n_value - st);
-
- if ((int)block_table & 3) {
- warn("%s: invalid address: block_table = %p",
- fname, block_table);
- free((void *)bp);
- close(fd);
+ /* Look for the bbinfo structure. */
+ for (bbi = bp; bbi < (bp + sz); bbi += sizeof(uint32_t)) {
+ bbinfo_p = (void *)bbi;
+ if (memcmp(bbinfo_p->bbi_magic, BBINFO_MAGIC,
+ BBINFO_MAGICSIZE) == 0)
+ break;
+ }
+ if (bbi >= (bp + sz)) {
+ warn("%s: unable to locate bbinfo structure; "
+ "make sure your bootxx is updated.\n", fname);
+ free((void *)ap);
return NULL;
}
- if ((int)block_count_p & 3) {
- warn("%s: invalid address: block_count_p = %p",
- fname, block_count_p);
- free((void *)bp);
- close(fd);
- return NULL;
- }
- if ((int)block_size_p & 3) {
- warn("%s: invalid address: block_size_p = %p",
- fname, block_size_p);
- free((void *)bp);
- close(fd);
- return NULL;
- }
- if ((int)entry_point_p & 3) {
- warn("%s: invalid address: entry_point_p = %p",
- fname, entry_point_p);
- free((void *)bp);
- close(fd);
- return NULL;
- }
- max_block_count = *block_count_p;
+
+ max_block_count = sa_be32toh(bbinfo_p->bbi_block_count);
if (verbose) {
printf("proto bootblock size: %d\n", sz);
}
*size = sz;
- ap += BOOTSECTOR_OFFSET; /* XXX */
return (char *)ap;
}
Home |
Main Index |
Thread Index |
Old Index