Update to <sys/bootblock.h>'s shared_bbinfo.
From Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>.
This commit is contained in:
parent
f3b8388799
commit
f35d18a7da
@ -1,5 +1,5 @@
|
||||
# $NetBSD: Makefile,v 1.1 1999/12/09 14:53:20 tsutsui Exp $
|
||||
# $NetBSD: Makefile,v 1.2 2002/05/20 14:05:22 lukem Exp $
|
||||
|
||||
SUBDIR= common boot bootxx installboot
|
||||
SUBDIR= common boot bootxx
|
||||
|
||||
.include <bsd.subdir.mk>
|
||||
|
@ -1,4 +1,4 @@
|
||||
# $NetBSD: Makefile,v 1.9 2001/12/12 12:24:25 lukem Exp $
|
||||
# $NetBSD: Makefile,v 1.10 2002/05/20 14:05:22 lukem Exp $
|
||||
|
||||
NOMAN= # defined
|
||||
|
||||
@ -16,6 +16,7 @@ STRIPFLAG=
|
||||
BINMODE= 444
|
||||
|
||||
SIZE?= size
|
||||
OBJCOPY?= objcopy
|
||||
|
||||
S= ${.CURDIR}/../../../..
|
||||
|
||||
@ -26,7 +27,7 @@ CPPFLAGS+= -D_STANDALONE # -DBOOTXX_DEBUG
|
||||
CPPFLAGS+= -nostdinc -I${.OBJDIR} -I${S}
|
||||
AFLAGS= -D_LOCORE
|
||||
|
||||
CLEANFILES+= machine m68k
|
||||
CLEANFILES+= machine m68k ${PROG}.sym
|
||||
|
||||
L= ${COMMONOBJ}/lib
|
||||
LIBS= ${L}/sa/libsa.a ${L}/kern/libkern.a
|
||||
@ -44,7 +45,8 @@ m68k::
|
||||
ln -s ${S}/arch/m68k/include $@
|
||||
|
||||
${PROG}: ${OBJS} machine m68k
|
||||
${LD} ${LDFLAGS} -o ${PROG} ${OBJS} ${LIBS}
|
||||
${SIZE} ${PROG}
|
||||
${LD} ${LDFLAGS} -o ${.TARGET}.sym ${OBJS} ${LIBS}
|
||||
${SIZE} ${.TARGET}.sym
|
||||
${OBJCOPY} -O binary ${.TARGET}.sym ${.TARGET}
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: bootxx.c,v 1.3 2002/04/30 01:07:27 tsutsui Exp $ */
|
||||
/* $NetBSD: bootxx.c,v 1.4 2002/05/20 14:05:22 lukem Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (C) 1999 Izumi Tsutsui. All rights reserved.
|
||||
@ -30,16 +30,22 @@
|
||||
#include <lib/libkern/libkern.h>
|
||||
#include <lib/libsa/stand.h>
|
||||
#include <machine/romcall.h>
|
||||
#include <machine/bbinfo.h>
|
||||
|
||||
struct bbinfo bbinfo = {
|
||||
{ BBINFO_MAGIC }, /* bbi_magic[] */
|
||||
0, /* bbi_block_size */
|
||||
MAXBLOCKNUM, /* bbi_block_count */
|
||||
{ 0 }, /* bbi_block_table[] */
|
||||
0x3e0000 /* bbi_entry_point */
|
||||
#include <sys/bootblock.h>
|
||||
|
||||
struct shared_bbinfo bbinfo = {
|
||||
{ NEWS68K_BBINFO_MAGIC }, /* bbi_magic[] */
|
||||
0, /* bbi_block_size */
|
||||
SHARED_BBINFO_MAXBLOCKS, /* bbi_block_count */
|
||||
{ 0 }, /* bbi_block_table[] */
|
||||
};
|
||||
|
||||
#ifndef DEFAULT_ENTRY_POINT
|
||||
#define DEFAULT_ENTRY_POINT 0x003e0000
|
||||
#endif
|
||||
void (*entry_point)(u_int32_t, u_int32_t, u_int32_t, u_int32_t) =
|
||||
(void *)DEFAULT_ENTRY_POINT;
|
||||
|
||||
#ifdef BOOTXX_DEBUG
|
||||
# define DPRINTF(x) printf x
|
||||
#else
|
||||
@ -57,7 +63,6 @@ bootxx(d4, d5, d6, d7)
|
||||
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");
|
||||
@ -70,7 +75,7 @@ bootxx(d4, d5, d6, d7)
|
||||
|
||||
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));
|
||||
DPRINTF(("entry_point = %p\n", entry_point));
|
||||
|
||||
/* sd(ctlr, lun, part, bus?, host) */
|
||||
|
||||
@ -92,7 +97,6 @@ bootxx(d4, d5, d6, d7)
|
||||
return;
|
||||
}
|
||||
|
||||
entry_point = (void *)bbinfo.bbi_entry_point;
|
||||
addr = (char *)entry_point;
|
||||
bs = bbinfo.bbi_block_size;
|
||||
DPRINTF(("reading block:"));
|
||||
|
@ -1,31 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.6 2001/12/12 01:49:48 tv Exp $
|
||||
|
||||
PROG= installboot
|
||||
SRCS= installboot.c byteorder.c loadfile.c loadfile_aout.c loadfile_elf32.c
|
||||
NOMAN= # defined
|
||||
WARNS?= 1
|
||||
|
||||
S= ${.CURDIR}/../../../..
|
||||
LIBSA=${S}/lib/libsa
|
||||
|
||||
.PATH.c: ${LIBSA}
|
||||
|
||||
CPPFLAGS+= -I${.OBJDIR} -I${LIBSA}
|
||||
LDSTATIC?= -static
|
||||
|
||||
# for machine/loadfile_machdep.h
|
||||
CLEANFILES+= machine m68k
|
||||
|
||||
.BEGIN: machine m68k
|
||||
.NOPATH: machine m68k
|
||||
realdepend realall: machine m68k
|
||||
|
||||
machine::
|
||||
-rm -f $@
|
||||
ln -s ${S}/arch/${MACHINE}/include $@
|
||||
|
||||
m68k::
|
||||
-rm -f $@
|
||||
ln -s ${S}/arch/m68k/include $@
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,344 +0,0 @@
|
||||
/* $NetBSD: installboot.c,v 1.5 2002/04/27 10:19:59 tsutsui Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1998 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Paul Kranenburg.
|
||||
*
|
||||
* 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/param.h>
|
||||
#include <sys/mount.h>
|
||||
#include <ufs/ufs/dinode.h>
|
||||
#include <ufs/ffs/fs.h>
|
||||
#include <err.h>
|
||||
#include <a.out.h>
|
||||
#include <fcntl.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;
|
||||
|
||||
struct bbinfo *bbinfo_p;
|
||||
int32_t max_block_count;
|
||||
|
||||
char *loadprotoblocks __P((char *, size_t *));
|
||||
int loadblocknums __P((char *, int));
|
||||
static void devread __P((int, void *, daddr_t, size_t, char *));
|
||||
static void usage __P((void));
|
||||
int main __P((int, char *[]));
|
||||
|
||||
static void
|
||||
usage()
|
||||
{
|
||||
fprintf(stderr,
|
||||
"usage: installboot [-n] [-v] <boot> <proto> <device>\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
int c;
|
||||
int devfd;
|
||||
char *protostore;
|
||||
size_t protosize;
|
||||
uint32_t boot00[BOOTSECTOR_OFFSET / sizeof(uint32_t)];
|
||||
|
||||
while ((c = getopt(argc, argv, "vn")) != EOF) {
|
||||
switch (c) {
|
||||
|
||||
case 'n':
|
||||
/* Do not actually write the bootblock to disk */
|
||||
nowrite = 1;
|
||||
break;
|
||||
case 'v':
|
||||
/* Chat */
|
||||
verbose = 1;
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
}
|
||||
|
||||
if (argc - optind < 3) {
|
||||
usage();
|
||||
}
|
||||
|
||||
boot = argv[optind];
|
||||
proto = argv[optind + 1];
|
||||
dev = argv[optind + 2];
|
||||
|
||||
if (verbose) {
|
||||
printf("boot: %s\n", boot);
|
||||
printf("proto: %s\n", proto);
|
||||
printf("device: %s\n", dev);
|
||||
}
|
||||
|
||||
/* Load proto blocks into core */
|
||||
if ((protostore = loadprotoblocks(proto, &protosize)) == NULL)
|
||||
exit(1);
|
||||
|
||||
/* Open and check raw disk device */
|
||||
if ((devfd = open(dev, O_RDONLY, 0)) < 0)
|
||||
err(1, "open: %s", dev);
|
||||
|
||||
/* Extract and load block numbers */
|
||||
if (loadblocknums(boot, devfd) != 0)
|
||||
exit(1);
|
||||
|
||||
(void)close(devfd);
|
||||
|
||||
if (nowrite)
|
||||
return 0;
|
||||
|
||||
/* Write patched proto bootblocks into the superblock */
|
||||
if (protosize > SBSIZE - DEV_BSIZE)
|
||||
errx(1, "proto bootblocks too big");
|
||||
|
||||
if ((devfd = open(dev, O_RDWR, 0)) < 0)
|
||||
err(1, "open: %s", dev);
|
||||
|
||||
if (lseek(devfd, BOOTSECTOR_OFFSET, SEEK_SET) != BOOTSECTOR_OFFSET)
|
||||
err(1, "lseek bootstrap");
|
||||
|
||||
/* Sync filesystems (to clean in-memory superblock?) */
|
||||
sync(); sync(); sync();
|
||||
|
||||
if (write(devfd, protostore + BOOTSECTOR_OFFSET,
|
||||
protosize - BOOTSECTOR_OFFSET) != protosize - BOOTSECTOR_OFFSET)
|
||||
err(1, "write bootstrap");
|
||||
|
||||
/* Write boot00 */
|
||||
if (lseek(devfd, 0, SEEK_SET) != 0)
|
||||
err(1, "lseek 0a");
|
||||
if (read(devfd, boot00, sizeof(boot00)) != sizeof(boot00))
|
||||
err(1, "read boot00");
|
||||
|
||||
memcpy(boot00, protostore, LABELOFFSET);
|
||||
if (lseek(devfd, 0, SEEK_SET) != 0)
|
||||
err(1, "lseek 0b");
|
||||
if (write(devfd, boot00, sizeof(boot00)) != sizeof(boot00))
|
||||
err(1, "write boot00");
|
||||
|
||||
(void)close(devfd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *
|
||||
loadprotoblocks(fname, size)
|
||||
char *fname;
|
||||
size_t *size;
|
||||
{
|
||||
int fd, sz;
|
||||
u_long ap, bp, st, bbi;
|
||||
u_long marks[MARK_MAX];
|
||||
|
||||
marks[MARK_START] = 0;
|
||||
if ((fd = loadfile(fname, marks, COUNT_TEXT|COUNT_DATA)) == -1)
|
||||
return NULL;
|
||||
(void)close(fd);
|
||||
|
||||
sz = (marks[MARK_END] - marks[MARK_START]);
|
||||
sz = roundup(sz, DEV_BSIZE);
|
||||
st = marks[MARK_START];
|
||||
|
||||
if ((ap = (u_long)malloc(sz)) == NULL) {
|
||||
warn("malloc: %s", "");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bp = ap;
|
||||
marks[MARK_START] = bp - st;
|
||||
if ((fd = loadfile(fname, marks, LOAD_TEXT|LOAD_DATA)) == -1)
|
||||
return NULL;
|
||||
(void)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;
|
||||
}
|
||||
|
||||
max_block_count = sa_be32toh(bbinfo_p->bbi_block_count);
|
||||
|
||||
if (verbose) {
|
||||
printf("proto bootblock size: %d\n", sz);
|
||||
}
|
||||
|
||||
*size = sz;
|
||||
return (char *)ap;
|
||||
}
|
||||
|
||||
static void
|
||||
devread(fd, buf, blk, size, msg)
|
||||
int fd;
|
||||
void *buf;
|
||||
daddr_t blk;
|
||||
size_t size;
|
||||
char *msg;
|
||||
{
|
||||
if (lseek(fd, dbtob(blk), SEEK_SET) != dbtob(blk))
|
||||
err(1, "%s: devread: lseek", msg);
|
||||
|
||||
if (read(fd, buf, size) != size)
|
||||
err(1, "%s: devread: read", msg);
|
||||
}
|
||||
|
||||
static char sblock[SBSIZE];
|
||||
|
||||
int
|
||||
loadblocknums(boot, devfd)
|
||||
char *boot;
|
||||
int devfd;
|
||||
{
|
||||
int i, fd;
|
||||
struct stat statbuf;
|
||||
struct statfs statfsbuf;
|
||||
struct fs *fs;
|
||||
char *buf;
|
||||
daddr_t blk, *ap;
|
||||
struct dinode *ip;
|
||||
int ndb;
|
||||
|
||||
/*
|
||||
* Open 2nd-level boot program and record the block numbers
|
||||
* it occupies on the filesystem represented by `devfd'.
|
||||
*/
|
||||
if ((fd = open(boot, O_RDONLY)) < 0)
|
||||
err(1, "open: %s", boot);
|
||||
|
||||
if (fstatfs(fd, &statfsbuf) != 0)
|
||||
err(1, "statfs: %s", boot);
|
||||
|
||||
if (strncmp(statfsbuf.f_fstypename, "ffs", MFSNAMELEN) &&
|
||||
strncmp(statfsbuf.f_fstypename, "ufs", MFSNAMELEN)) {
|
||||
errx(1, "%s: must be on an FFS filesystem", boot);
|
||||
}
|
||||
|
||||
if (fsync(fd) != 0)
|
||||
err(1, "fsync: %s", boot);
|
||||
|
||||
if (fstat(fd, &statbuf) != 0)
|
||||
err(1, "fstat: %s", boot);
|
||||
|
||||
close(fd);
|
||||
|
||||
/* Read superblock */
|
||||
devread(devfd, sblock, btodb(SBOFF), SBSIZE, "superblock");
|
||||
fs = (struct fs *)sblock;
|
||||
|
||||
/* Read inode */
|
||||
if ((buf = malloc(fs->fs_bsize)) == NULL)
|
||||
errx(1, "No memory for filesystem block");
|
||||
|
||||
blk = fsbtodb(fs, ino_to_fsba(fs, statbuf.st_ino));
|
||||
devread(devfd, buf, blk, fs->fs_bsize, "inode");
|
||||
ip = (struct dinode *)(buf) + ino_to_fsbo(fs, statbuf.st_ino);
|
||||
|
||||
/*
|
||||
* Register filesystem block size.
|
||||
*/
|
||||
bbinfo_p->bbi_block_size = sa_htobe32(fs->fs_bsize);
|
||||
|
||||
/*
|
||||
* Get the block numbers; we don't handle fragments
|
||||
*/
|
||||
ndb = howmany(ip->di_size, fs->fs_bsize);
|
||||
if (ndb > max_block_count)
|
||||
errx(1, "%s: Too many blocks", boot);
|
||||
|
||||
if (verbose)
|
||||
printf("entry point: 0x%08x\n",
|
||||
sa_be32toh(bbinfo_p->bbi_entry_point));
|
||||
|
||||
/*
|
||||
* Register block count.
|
||||
*/
|
||||
bbinfo_p->bbi_block_count = sa_htobe32(ndb);
|
||||
|
||||
if (verbose)
|
||||
printf("%s: block numbers: ", boot);
|
||||
ap = ip->di_db;
|
||||
for (i = 0; i < NDADDR && *ap && ndb; i++, ap++, ndb--) {
|
||||
blk = fsbtodb(fs, *ap);
|
||||
bbinfo_p->bbi_block_table[i] = sa_htobe32(blk);
|
||||
if (verbose)
|
||||
printf("%d ", blk);
|
||||
}
|
||||
if (verbose)
|
||||
printf("\n");
|
||||
|
||||
if (ndb == 0)
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* Just one level of indirections; there isn't much room
|
||||
* for more in the 1st-level bootblocks anyway.
|
||||
*/
|
||||
if (verbose)
|
||||
printf("%s: block numbers (indirect): ", boot);
|
||||
blk = ip->di_ib[0];
|
||||
devread(devfd, buf, blk, fs->fs_bsize, "indirect block");
|
||||
ap = (daddr_t *)buf;
|
||||
for (; i < NINDIR(fs) && *ap && ndb; i++, ap++, ndb--) {
|
||||
blk = fsbtodb(fs, *ap);
|
||||
bbinfo_p->bbi_block_table[i] = sa_htobe32(blk);
|
||||
if (verbose)
|
||||
printf("%d ", blk);
|
||||
}
|
||||
if (verbose)
|
||||
printf("\n");
|
||||
|
||||
if (ndb)
|
||||
errx(1, "%s: Too many blocks", boot);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user