- use uint8_t instead of char for boot block blobs

- bbinfo_params:
	- replace "int littleendian" with "bbinfo_endian endian"
	- add comments
- shared_bbinfo_clearboot():
	- add callback method to shared_bbinfo_clearboot()
	- don't clear from 0..headeroffset; use a callback to do that
- add news68k and newsmips support.
  From Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>, with a rework by me to
  take advantage of the new shared_bbinfo_clearboot() callback.
  (XXX: untested yet)
This commit is contained in:
lukem 2002-05-20 16:05:26 +00:00
parent 44024682c7
commit d22f5cff9c
9 changed files with 302 additions and 69 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.19 2002/05/15 09:44:55 lukem Exp $
# $NetBSD: Makefile,v 1.20 2002/05/20 16:05:26 lukem 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 macppc.c pmax.c sparc.c sparc64.c sun68k.c vax.c
alpha.c macppc.c news.c pmax.c sparc.c sparc64.c sun68k.c vax.c
MAN= installboot.8
WARNS?= 3

View File

@ -1,4 +1,4 @@
/* $NetBSD: macppc.c,v 1.4 2002/05/16 01:35:44 lukem Exp $ */
/* $NetBSD: macppc.c,v 1.5 2002/05/20 16:05:27 lukem Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(__lint)
__RCSID("$NetBSD: macppc.c,v 1.4 2002/05/16 01:35:44 lukem Exp $");
__RCSID("$NetBSD: macppc.c,v 1.5 2002/05/20 16:05:27 lukem Exp $");
#endif /* !__lint */
#if HAVE_CONFIG_H
@ -61,10 +61,10 @@ static struct bbinfo_params bbparams = {
MACPPC_BOOT_BLOCK_BLOCKSIZE,
MACPPC_BOOT_BLOCK_MAX_SIZE,
0,
0,
BBINFO_BIG_ENDIAN,
};
static int writeapplepartmap(ib_params *, struct bbinfo_params *, char *);
static int writeapplepartmap(ib_params *, struct bbinfo_params *, uint8_t *);
int
@ -79,11 +79,27 @@ macppc_clearboot(ib_params *params)
return (0);
}
/* XXX: maybe clear the apple partition map too? */
return (shared_bbinfo_clearboot(params, &bbparams));
return (shared_bbinfo_clearboot(params, &bbparams, NULL));
}
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, writeapplepartmap));
}
static int
writeapplepartmap(ib_params *params, struct bbinfo_params *bb_params, char *bb)
writeapplepartmap(ib_params *params, struct bbinfo_params *bb_params,
uint8_t *bb)
{
struct apple_drvr_map dm;
struct apple_part_map_entry pme;
@ -150,17 +166,3 @@ writeapplepartmap(ib_params *params, struct bbinfo_params *bb_params, char *bb)
return (1);
}
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, writeapplepartmap));
}

View File

@ -0,0 +1,192 @@
/* $NetBSD: news.c,v 1.1 2002/05/20 16:05:27 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 and Izumi Tsutsui.
*
* 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: news.c,v 1.1 2002/05/20 16:05:27 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"
static int news_clearboot(ib_params *, struct bbinfo_params *, uint8_t *);
static int news_setboot(ib_params *, struct bbinfo_params *, uint8_t *);
/*
* news68k specific support
*/
static struct bbinfo_params news68k_bbparams = {
NEWS68K_BBINFO_MAGIC,
0, /* write all 8K (including disklabel) */
NEWS_BOOT_BLOCK_BLOCKSIZE,
NEWS_BOOT_BLOCK_MAX_SIZE,
NEWS_BOOT_BLOCK_OFFSET, /* but load bootxx here */
BBINFO_BIG_ENDIAN,
};
int
news68k_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, &news68k_bbparams,
news_clearboot));
}
int
news68k_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, &news68k_bbparams, news_setboot));
}
/*
* newsmips specific support
*/
static struct bbinfo_params newsmips_bbparams = {
NEWSMIPS_BBINFO_MAGIC,
0, /* write all 8K (including disklabel) */
NEWS_BOOT_BLOCK_BLOCKSIZE,
NEWS_BOOT_BLOCK_MAX_SIZE,
NEWS_BOOT_BLOCK_OFFSET, /* but load bootxx here */
BBINFO_BIG_ENDIAN,
};
int
newsmips_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, &newsmips_bbparams,
news_clearboot));
}
int
newsmips_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, &newsmips_bbparams,
news_setboot));
}
/*
* news common code
*/
static int
news_clearboot(ib_params *params, struct bbinfo_params *bbparams, uint8_t *bb)
{
assert(params != NULL);
assert(bbparams != NULL);
assert(bb != NULL);
/* Clear out first sector to disklabel */
memset(bb, 0, NEWS_BOOT_BLOCK_LABELOFFSET);
return (1);
}
static int
news_setboot(ib_params *params, struct bbinfo_params *bbparams, uint8_t *bb)
{
uint8_t boot00[NEWS_BOOT_BLOCK_OFFSET];
ssize_t rv;
assert(params != NULL);
assert(params->fsfd != -1);
assert(bbparams != NULL);
assert(bb != NULL);
/* Read label sector to overwrite jump instruction */
memset(boot00, 0, sizeof(boot00));
rv = pread(params->fsfd, boot00, sizeof(boot00), 0);
if (rv == -1) {
warn("Reading label sector from `%s'", params->filesystem);
return (0);
}
/* Copy disklabel */
memcpy(bb + NEWS_BOOT_BLOCK_LABELOFFSET,
boot00 + NEWS_BOOT_BLOCK_LABELOFFSET,
sizeof(boot00) - NEWS_BOOT_BLOCK_LABELOFFSET);
return (1);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: sparc.c,v 1.6 2002/05/15 09:58:19 lukem Exp $ */
/* $NetBSD: sparc.c,v 1.7 2002/05/20 16:05:27 lukem Exp $ */
/*-
* Copyright (c) 1998, 2002 The NetBSD Foundation, Inc.
@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(__lint)
__RCSID("$NetBSD: sparc.c,v 1.6 2002/05/15 09:58:19 lukem Exp $");
__RCSID("$NetBSD: sparc.c,v 1.7 2002/05/20 16:05:27 lukem Exp $");
#endif /* !__lint */
#if HAVE_CONFIG_H
@ -63,11 +63,11 @@ static struct bbinfo_params bbparams = {
SPARC_BOOT_BLOCK_BLOCKSIZE,
SPARC_BOOT_BLOCK_MAX_SIZE,
32, /* leave room for a.out header */
0,
BBINFO_BIG_ENDIAN,
};
static int sparc_frobheader(ib_params *, struct bbinfo_params *, char *);
static int sparc_clearheader(ib_params *, struct bbinfo_params *, uint8_t *);
static int sparc_setheader(ib_params *, struct bbinfo_params *, uint8_t *);
int
sparc_clearboot(ib_params *params)
@ -80,11 +80,38 @@ sparc_clearboot(ib_params *params)
params->machine->name);
return (0);
}
return (shared_bbinfo_clearboot(params, &bbparams));
return (shared_bbinfo_clearboot(params, &bbparams, sparc_clearheader));
}
int
sparc_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, sparc_setheader));
}
static int
sparc_clearheader(ib_params *params, struct bbinfo_params *bb_params,
uint8_t *bb)
{
assert(params != NULL);
assert(bb_params != NULL);
assert(bb != NULL);
memset(bb, 0, bb_params->headeroffset);
return (1);
}
static int
sparc_frobheader(ib_params *params, struct bbinfo_params *bb_params, char *bb)
sparc_setheader(ib_params *params, struct bbinfo_params *bb_params, uint8_t *bb)
{
assert(params != NULL);
@ -109,16 +136,3 @@ sparc_frobheader(ib_params *params, struct bbinfo_params *bb_params, char *bb)
return (1);
}
int
sparc_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, sparc_frobheader));
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: sun68k.c,v 1.16 2002/05/15 09:44:55 lukem Exp $ */
/* $NetBSD: sun68k.c,v 1.17 2002/05/20 16:05:27 lukem Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(__lint)
__RCSID("$NetBSD: sun68k.c,v 1.16 2002/05/15 09:44:55 lukem Exp $");
__RCSID("$NetBSD: sun68k.c,v 1.17 2002/05/20 16:05:27 lukem Exp $");
#endif /* !__lint */
#if HAVE_CONFIG_H
@ -59,7 +59,7 @@ static struct bbinfo_params bbparams = {
SUN68K_BOOT_BLOCK_BLOCKSIZE,
SUN68K_BOOT_BLOCK_MAX_SIZE,
0,
0,
BBINFO_BIG_ENDIAN,
};
int
@ -73,7 +73,7 @@ sun68k_clearboot(ib_params *params)
params->machine->name);
return (0);
}
return (shared_bbinfo_clearboot(params, &bbparams));
return (shared_bbinfo_clearboot(params, &bbparams, NULL));
}
int

View File

@ -1,4 +1,4 @@
/* $NetBSD: bbinfo.c,v 1.4 2002/05/20 15:04:25 lukem Exp $ */
/* $NetBSD: bbinfo.c,v 1.5 2002/05/20 16:05:26 lukem Exp $ */
/*-
* Copyright (c) 1998, 2002 The NetBSD Foundation, Inc.
@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(__lint)
__RCSID("$NetBSD: bbinfo.c,v 1.4 2002/05/20 15:04:25 lukem Exp $");
__RCSID("$NetBSD: bbinfo.c,v 1.5 2002/05/20 16:05:26 lukem Exp $");
#endif /* !__lint */
#if HAVE_CONFIG_H
@ -58,9 +58,10 @@ __RCSID("$NetBSD: bbinfo.c,v 1.4 2002/05/20 15:04:25 lukem Exp $");
#include "installboot.h"
int
shared_bbinfo_clearboot(ib_params *params, struct bbinfo_params *bbparams)
shared_bbinfo_clearboot(ib_params *params, struct bbinfo_params *bbparams,
int (*callback)(ib_params *, struct bbinfo_params *, uint8_t *))
{
char *bb;
uint8_t *bb;
ssize_t rv;
int retval;
@ -92,8 +93,11 @@ shared_bbinfo_clearboot(ib_params *params, struct bbinfo_params *bbparams)
goto done;
}
/* Now clear it out to nothing */
memset(bb, 0, bbparams->maxsize);
/* Now clear out (past the header offset) */
memset(bb + bbparams->headeroffset, 0,
bbparams->maxsize - bbparams->headeroffset);
if (callback != NULL && ! (*callback)(params, bbparams, bb))
goto done;
if (params->flags & IB_VERBOSE)
printf("%slearing boot block\n",
@ -121,9 +125,9 @@ shared_bbinfo_clearboot(ib_params *params, struct bbinfo_params *bbparams)
int
shared_bbinfo_setboot(ib_params *params, struct bbinfo_params *bbparams,
int (*callback)(ib_params *, struct bbinfo_params *, char *))
int (*callback)(ib_params *, struct bbinfo_params *, uint8_t *))
{
char *bb;
uint8_t *bb;
int retval;
ssize_t rv;
size_t bbi;
@ -180,11 +184,12 @@ shared_bbinfo_setboot(ib_params *params, struct bbinfo_params *bbparams,
goto done;
}
#define HOSTTOTARGET32(x) (bbparams->littleendian ? le32toh((x)) : be32toh((x)))
#define HOSTTOTARGET32(x) ((bbparams->endian == BBINFO_LITTLE_ENDIAN) \
? le32toh((x)) : be32toh((x)))
/* Look for the bbinfo structure. */
for (bbi = 0; bbi < bbparams->maxsize; bbi += sizeof(uint32_t)) {
bbinfop = (void *) (bb + bbi);
bbinfop = (void *) (bb + bbparams->headeroffset + bbi);
if (memcmp(bbinfop->bbi_magic, bbparams->magic,
sizeof(bbinfop->bbi_magic)) == 0)
break;

View File

@ -1,4 +1,4 @@
.\" $NetBSD: installboot.8,v 1.16 2002/05/17 17:42:36 lukem Exp $
.\" $NetBSD: installboot.8,v 1.17 2002/05/20 16:05:26 lukem Exp $
.\"
.\" Copyright (c) 2002 The NetBSD Foundation, Inc.
.\" All rights reserved.
@ -34,7 +34,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd May 18, 2002
.Dd May 21, 2002
.Dt INSTALLBOOT 8
.Os
.Sh NAME
@ -121,6 +121,8 @@ These are:
.Bl -column "Platform" "File systems" -offset indent
.It Sy "Platform" Ta Sy "File systems"
.It macppc Ta ffs, raw
.It news68k Ta ffs, raw
.It newsmips Ta ffs, raw
.It sparc Ta ffs, raw
.It sun2 Ta ffs, raw
.It sun3 Ta ffs, raw
@ -214,6 +216,8 @@ The following machines are currently supported by
.Bd -ragged -offset indent
.Sy alpha ,
.Sy macppc ,
.Sy news68k ,
.Sy newsmips ,
.Sy pmax ,
.Sy sparc ,
.Sy sparc64 ,
@ -418,8 +422,9 @@ Matthew Green (sparc64),
Ross Harvey (alpha),
Paul Kranenburg (sparc),
Luke Mewburn (macppc),
Matt Thomas (vax),
and
Matt Thomas (vax).
Izumi Tsutsui (news68k, newsmips).
.
.Sh BUGS
There are not currently primary bootstraps to support all file systems

View File

@ -1,4 +1,4 @@
/* $NetBSD: installboot.h,v 1.12 2002/05/15 09:44:55 lukem Exp $ */
/* $NetBSD: installboot.h,v 1.13 2002/05/20 16:05:26 lukem Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -100,13 +100,21 @@ struct ib_fs {
uint32_t needswap;
};
typedef enum {
BBINFO_BIG_ENDIAN = 0,
BBINFO_LITTLE_ENDIAN = 1,
} bbinfo_endian;
struct bbinfo_params {
const char *magic;
uint32_t offset;
uint32_t blocksize;
uint32_t maxsize;
uint32_t headeroffset;
int littleendian;
const char *magic; /* magic string to look for */
uint32_t offset; /* offset to write start of stage1 */
uint32_t blocksize; /* blocksize of stage1 */
uint32_t maxsize; /* max size of stage1 */
uint32_t headeroffset; /*
* header offset (relative to offset)
* to read stage1 into
*/
bbinfo_endian endian;
};
extern struct ib_mach machines[];
@ -121,9 +129,10 @@ int no_setboot(ib_params *);
int no_clearboot(ib_params *);
/* bbinfo.c */
int shared_bbinfo_clearboot(ib_params *, struct bbinfo_params *);
int shared_bbinfo_clearboot(ib_params *, struct bbinfo_params *,
int (*)(ib_params *, struct bbinfo_params *, uint8_t *));
int shared_bbinfo_setboot(ib_params *, struct bbinfo_params *,
int (*)(ib_params *, struct bbinfo_params *, char *));
int (*)(ib_params *, struct bbinfo_params *, uint8_t *));
/* fstypes.c */
int hardcode_stage2(ib_params *, uint32_t *, ib_block *);
@ -138,6 +147,10 @@ int alpha_setboot(ib_params *);
int alpha_clearboot(ib_params *);
int macppc_setboot(ib_params *);
int macppc_clearboot(ib_params *);
int news68k_setboot(ib_params *);
int news68k_clearboot(ib_params *);
int newsmips_setboot(ib_params *);
int newsmips_clearboot(ib_params *);
int pmax_parseopt(ib_params *, const char *);
int pmax_setboot(ib_params *);
int pmax_clearboot(ib_params *);

View File

@ -1,4 +1,4 @@
/* $NetBSD: machines.c,v 1.10 2002/05/17 17:42:36 lukem Exp $ */
/* $NetBSD: machines.c,v 1.11 2002/05/20 16:05:26 lukem Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -43,6 +43,8 @@ struct ib_mach machines[] = {
{ "alpha", alpha_parseopt, alpha_setboot, alpha_clearboot },
{ "i386", no_parseopt, no_setboot, no_clearboot },
{ "macppc", no_parseopt, macppc_setboot, macppc_clearboot },
{ "news68k", no_parseopt, news68k_setboot, news68k_clearboot },
{ "newsmips", no_parseopt, newsmips_setboot, newsmips_clearboot },
{ "pmax", pmax_parseopt, pmax_setboot, pmax_clearboot },
{ "shark", no_parseopt, no_setboot, no_clearboot },
{ "sparc", no_parseopt, sparc_setboot, sparc_clearboot },