Change the way -o options are parsed, now done in MI code with a check after

all the options have been processed that they are supported my the
specific system.
Add i386 MD options (console, password, speed and timeout)
(Approved by christos and lukem)
This commit is contained in:
dsl 2003-04-15 14:22:13 +00:00
parent f4965045a0
commit ed45ba76c7
14 changed files with 347 additions and 298 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: alpha.c,v 1.13 2002/07/20 08:40:17 grant Exp $ */
/* $NetBSD: alpha.c,v 1.14 2003/04/15 14:22:13 dsl Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -98,7 +98,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(__lint)
__RCSID("$NetBSD: alpha.c,v 1.13 2002/07/20 08:40:17 grant Exp $");
__RCSID("$NetBSD: alpha.c,v 1.14 2003/04/15 14:22:13 dsl Exp $");
#endif /* !__lint */
#if HAVE_CONFIG_H
@ -126,18 +126,6 @@ static void check_sparc(const struct alpha_boot_block * const,
const char *);
int
alpha_parseopt(ib_params *params, const char *option)
{
if (parseoptionflag(params, option,
IB_ALPHASUM | IB_APPEND | IB_SUNSUM))
return (1);
warnx("Unknown -o option `%s'", option);
return (0);
}
int
alpha_clearboot(ib_params *params)
{
@ -154,11 +142,6 @@ alpha_clearboot(ib_params *params)
warnx("Can't use `-b bno' or `-o append' with `-c'");
return (0);
}
if (params->flags & IB_STAGE2START) {
warnx("`-B bno' is not supported for %s",
params->machine->name);
return (0);
}
rv = pread(params->fsfd, &bb, sizeof(bb), ALPHA_BOOT_BLOCK_OFFSET);
if (rv == -1) {
@ -238,17 +221,6 @@ alpha_setboot(ib_params *params)
retval = 0;
bootstrapbuf = NULL;
if ((params->flags & IB_STAGE1START) &&
(params->flags & IB_APPEND)) {
warnx("Can't use `-b bno' with `-o append'");
goto done;
}
if (params->flags & IB_STAGE2START) {
warnx("`-B bno' is not supported for %s",
params->machine->name);
goto done;
}
/*
* Allocate a buffer, with space to round up the input file
* to the next block size boundary, and with space for the boot

View File

@ -1,4 +1,4 @@
/* $NetBSD: amiga.c,v 1.1 2003/01/15 06:33:13 mhitch Exp $ */
/* $NetBSD: amiga.c,v 1.2 2003/04/15 14:22:14 dsl Exp $ */
/*-
* Copyright (c) 1999, 2002 The NetBSD Foundation, Inc.
@ -41,7 +41,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(__lint)
__RCSID("$NetBSD: amiga.c,v 1.1 2003/01/15 06:33:13 mhitch Exp $");
__RCSID("$NetBSD: amiga.c,v 1.2 2003/04/15 14:22:14 dsl Exp $");
#endif /* !__lint */
#include <sys/param.h>
@ -61,30 +61,13 @@ __RCSID("$NetBSD: amiga.c,v 1.1 2003/01/15 06:33:13 mhitch Exp $");
#define CMDLN_LOC 0x10
#define CMDLN_LEN 0x20
char command[CMDLN_LEN];
#define CHKSUMOFFS 1
u_int32_t chksum(u_int32_t *, int);
int amiga_parseopt(ib_params *, const char *);
int amiga_setboot(ib_params *);
int amiga_clearboot(ib_params *);
int
amiga_parseopt(ib_params *params, const char *option)
{
if (strncmp("command=", option, strlen("command=")) == 0) {
strncpy(command, option + strlen("command="), CMDLN_LEN);
params->flags |= IB_COMMAND;
return (1);
}
warnx("Unknown -o option `%s'", option);
return (0);
}
int
amiga_clearboot(ib_params *params)
{
@ -146,7 +129,7 @@ amiga_setboot(ib_params *params)
if (strcmp(dline, "netbsd -ASn2") != 0) {
errx(1, "Old bootblock version? Can't change command line.");
}
(void)strncpy(dline, command, CMDLN_LEN-1);
(void)strncpy(dline, params->command, CMDLN_LEN-1);
block[1] = 0;
block[1] = 0xffffffff - chksum(block, sumlen);

View File

@ -1,4 +1,4 @@
/* $NetBSD: i386.c,v 1.1 2003/04/09 22:14:27 dsl Exp $ */
/* $NetBSD: i386.c,v 1.2 2003/04/15 14:22:14 dsl Exp $ */
/*-
* Copyright (c) 2003 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: i386.c,v 1.1 2003/04/09 22:14:27 dsl Exp $");
__RCSID("$NetBSD: i386.c,v 1.2 2003/04/15 14:22:14 dsl Exp $");
#if HAVE_CONFIG_H
#include "config.h"
@ -52,12 +52,10 @@ __RCSID("$NetBSD: i386.c,v 1.1 2003/04/09 22:14:27 dsl Exp $");
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/md5.h>
#include "installboot.h"
/* Magic number also known by sys/arch/i386/stand/bootxx/Makefile.bootxx */
#define BOOT_MAGIC_1 ('x' << 24 | 0x86b << 12 | 'm' << 4 | 1)
int
i386_setboot(ib_params *params)
{
@ -66,6 +64,8 @@ i386_setboot(ib_params *params)
uint bootstrapsize;
ssize_t rv;
uint32_t magic;
struct i386_boot_params *bp;
int i;
assert(params != NULL);
assert(params->fsfd != -1);
@ -76,17 +76,15 @@ i386_setboot(ib_params *params)
retval = 0;
bootstrapbuf = NULL;
if (params->flags & IB_STAGE1START) {
warnx("`-b bno' is not supported for %s",
params->machine->name);
goto done;
/*
* There is only 8k of space in a UFSv1 partition (and ustarfs)
* so ensure we don't splat over anything important.
*/
if (params->s1stat.st_size > 8192) {
warnx("stage1 bootstrap `%s' is larger than 8192 bytes",
params->stage1);
return 0;
}
if (params->flags & IB_STAGE2START) {
warnx("`-B bno' is not supported for %s",
params->machine->name);
goto done;
}
/*
* Allocate a buffer, with space to round up the input file
* to the next block size boundary, and with space for the boot
@ -112,12 +110,51 @@ i386_setboot(ib_params *params)
}
magic = *(uint32_t *)(bootstrapbuf + 512 * 2 + 4);
if (magic != BOOT_MAGIC_1) {
if (magic != X86_BOOT_MAGIC_1) {
warnx("Invalid magic in stage1 boostrap %x != %x",
magic, BOOT_MAGIC_1);
magic, X86_BOOT_MAGIC_1);
goto done;
}
/* Fill in any user-specified options */
bp = (void *)(bootstrapbuf + 512 * 2 + 8);
if (bp->bp_length < sizeof *bp) {
warnx("Patch area in stage1 bootstrap is too small");
goto done;
}
if (params->flags & IB_TIMEOUT)
bp->bp_timeout = params->timeout;
if (params->flags & IB_RESETVIDEO)
bp->bp_flags |= BP_RESET_VIDEO;
if (params->flags & IB_CONSPEED)
bp->bp_conspeed = params->conspeed;
if (params->flags & IB_CONSOLE) {
static const char *names[] = {
"pc", "com0", "com1", "com2", "com3",
"com0kbd", "com1kbd", "com2kbd", "com3kbd",
NULL };
for (i = 0; ; i++) {
if (names[i] == NULL) {
warnx("invalid console name, valid names are:");
fprintf(stderr, "\t%s", names[0]);
for (i = 1; names[i] != NULL; i++)
fprintf(stderr, ", %s", names[i]);
fprintf(stderr, "\n", names[0]);
goto done;
}
if (strcmp(names[i], params->console) == 0)
break;
}
bp->bp_consdev = i;
}
if (params->flags & IB_PASSWORD) {
MD5_CTX md5ctx;
MD5Init(&md5ctx);
MD5Update(&md5ctx, params->password, strlen(params->password));
MD5Final(bp->bp_password, &md5ctx);
bp->bp_flags |= BP_PASSWORD;
}
if (params->flags & IB_NOWRITE) {
retval = 1;
goto done;

View File

@ -1,4 +1,4 @@
/* $NetBSD: macppc.c,v 1.5 2002/05/20 16:05:27 lukem Exp $ */
/* $NetBSD: macppc.c,v 1.6 2003/04/15 14:22:14 dsl 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.5 2002/05/20 16:05:27 lukem Exp $");
__RCSID("$NetBSD: macppc.c,v 1.6 2003/04/15 14:22:14 dsl Exp $");
#endif /* !__lint */
#if HAVE_CONFIG_H
@ -73,11 +73,6 @@ 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);
}
/* XXX: maybe clear the apple partition map too? */
return (shared_bbinfo_clearboot(params, &bbparams, NULL));
}
@ -88,11 +83,6 @@ 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

@ -1,4 +1,4 @@
/* $NetBSD: news.c,v 1.3 2002/05/21 14:59:38 tsutsui Exp $ */
/* $NetBSD: news.c,v 1.4 2003/04/15 14:22:14 dsl Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(__lint)
__RCSID("$NetBSD: news.c,v 1.3 2002/05/21 14:59:38 tsutsui Exp $");
__RCSID("$NetBSD: news.c,v 1.4 2003/04/15 14:22:14 dsl Exp $");
#endif /* !__lint */
#if HAVE_CONFIG_H
@ -79,11 +79,6 @@ 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_copydisklabel));
}
@ -94,11 +89,6 @@ 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_copydisklabel));
}
@ -123,11 +113,6 @@ 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_copydisklabel));
}
@ -138,11 +123,6 @@ 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_copydisklabel));
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: pmax.c,v 1.9 2002/05/15 02:18:23 lukem Exp $ */
/* $NetBSD: pmax.c,v 1.10 2003/04/15 14:22:14 dsl Exp $ */
/*-
* Copyright (c) 1999, 2002 The NetBSD Foundation, Inc.
@ -101,7 +101,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(__lint)
__RCSID("$NetBSD: pmax.c,v 1.9 2002/05/15 02:18:23 lukem Exp $");
__RCSID("$NetBSD: pmax.c,v 1.10 2003/04/15 14:22:14 dsl Exp $");
#endif /* !__lint */
#if HAVE_CONFIG_H
@ -126,17 +126,6 @@ static int load_bootstrap(ib_params *, char **,
uint32_t *, uint32_t *, size_t *);
int
pmax_parseopt(ib_params *params, const char *option)
{
if (parseoptionflag(params, option, IB_APPEND | IB_SUNSUM))
return (1);
warnx("Unknown -o option `%s'", option);
return (0);
}
int
pmax_clearboot(ib_params *params)
{
@ -148,16 +137,6 @@ pmax_clearboot(ib_params *params)
assert(params->filesystem != NULL);
assert(sizeof(struct pmax_boot_block) == PMAX_BOOT_BLOCK_BLOCKSIZE);
if (params->flags & (IB_STAGE1START | IB_APPEND)) {
warnx("Can't use `-b bno' or `-o append' with `-c'");
return (0);
}
if (params->flags & IB_STAGE2START) {
warnx("`-B bno' is not supported for %s",
params->machine->name);
return (0);
}
rv = pread(params->fsfd, &bb, sizeof(bb), PMAX_BOOT_BLOCK_OFFSET);
if (rv == -1) {
warn("Reading `%s'", params->filesystem);
@ -223,17 +202,6 @@ pmax_setboot(ib_params *params)
retval = 0;
bootstrapbuf = NULL;
if ((params->flags & IB_STAGE1START) &&
(params->flags & IB_APPEND)) {
warnx("Can't use `-b bno' with `-o append'");
goto done;
}
if (params->flags & IB_STAGE2START) {
warnx("`-B bno' is not supported for %s",
params->machine->name);
goto done;
}
if (! load_bootstrap(params, &bootstrapbuf, &bootstrapload,
&bootstrapexec, &bootstrapsize))
goto done;

View File

@ -1,4 +1,4 @@
/* $NetBSD: sparc.c,v 1.7 2002/05/20 16:05:27 lukem Exp $ */
/* $NetBSD: sparc.c,v 1.8 2003/04/15 14:22:14 dsl 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.7 2002/05/20 16:05:27 lukem Exp $");
__RCSID("$NetBSD: sparc.c,v 1.8 2003/04/15 14:22:14 dsl Exp $");
#endif /* !__lint */
#if HAVE_CONFIG_H
@ -75,11 +75,6 @@ sparc_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, sparc_clearheader));
}
@ -88,11 +83,6 @@ 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));
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: sun68k.c,v 1.17 2002/05/20 16:05:27 lukem Exp $ */
/* $NetBSD: sun68k.c,v 1.18 2003/04/15 14:22:14 dsl 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.17 2002/05/20 16:05:27 lukem Exp $");
__RCSID("$NetBSD: sun68k.c,v 1.18 2003/04/15 14:22:14 dsl Exp $");
#endif /* !__lint */
#if HAVE_CONFIG_H
@ -68,11 +68,6 @@ sun68k_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, NULL));
}
@ -82,10 +77,5 @@ sun68k_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));
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: vax.c,v 1.8 2002/05/15 02:18:24 lukem Exp $ */
/* $NetBSD: vax.c,v 1.9 2003/04/15 14:22:14 dsl Exp $ */
/*-
* Copyright (c) 1999, 2002 The NetBSD Foundation, Inc.
@ -71,7 +71,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(__lint)
__RCSID("$NetBSD: vax.c,v 1.8 2002/05/15 02:18:24 lukem Exp $");
__RCSID("$NetBSD: vax.c,v 1.9 2003/04/15 14:22:14 dsl Exp $");
#endif /* !__lint */
#if HAVE_CONFIG_H
@ -92,18 +92,6 @@ __RCSID("$NetBSD: vax.c,v 1.8 2002/05/15 02:18:24 lukem Exp $");
static int load_bootstrap(ib_params *, char **,
uint32_t *, uint32_t *, size_t *);
int
vax_parseopt(ib_params *params, const char *option)
{
if (parseoptionflag(params, option, IB_APPEND | IB_SUNSUM))
return (1);
warnx("Unknown -o option `%s'", option);
return (0);
}
int
vax_clearboot(ib_params *params)
{
@ -115,16 +103,6 @@ vax_clearboot(ib_params *params)
assert(params->filesystem != NULL);
assert(sizeof(struct vax_boot_block) == VAX_BOOT_BLOCK_BLOCKSIZE);
if (params->flags & (IB_STAGE1START | IB_APPEND)) {
warnx("Can't use `-b bno' or `-o append' with `-c'");
return (0);
}
if (params->flags & IB_STAGE2START) {
warnx("`-B bno' is not supported for %s",
params->machine->name);
return (0);
}
rv = pread(params->fsfd, &bb, sizeof(bb), VAX_BOOT_BLOCK_OFFSET);
if (rv == -1) {
warn("Reading `%s'", params->filesystem);
@ -194,17 +172,6 @@ vax_setboot(ib_params *params)
retval = 0;
bootstrapbuf = NULL;
if ((params->flags & IB_STAGE1START) &&
(params->flags & IB_APPEND)) {
warnx("Can't use `-b bno' with `-o append'");
goto done;
}
if (params->flags & IB_STAGE2START) {
warnx("`-B bno' is not supported for %s",
params->machine->name);
goto done;
}
if (fstat(params->s1fd, &bootstrapsb) == -1) {
warn("Examining `%s'", params->stage1);
goto done;

View File

@ -1,4 +1,4 @@
/* $NetBSD: bbinfo.c,v 1.7 2003/04/02 10:39:48 fvdl Exp $ */
/* $NetBSD: bbinfo.c,v 1.8 2003/04/15 14:22:13 dsl 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.7 2003/04/02 10:39:48 fvdl Exp $");
__RCSID("$NetBSD: bbinfo.c,v 1.8 2003/04/15 14:22:13 dsl Exp $");
#endif /* !__lint */
#if HAVE_CONFIG_H
@ -78,11 +78,6 @@ shared_bbinfo_clearboot(ib_params *params, struct bbinfo_params *bbparams,
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) {

View File

@ -1,4 +1,4 @@
.\" $NetBSD: installboot.8,v 1.25 2003/02/25 10:36:09 wiz Exp $
.\" $NetBSD: installboot.8,v 1.26 2003/04/15 14:22:13 dsl Exp $
.\"
.\" Copyright (c) 2002 The NetBSD Foundation, Inc.
.\" All rights reserved.
@ -151,6 +151,7 @@ The following platforms do not require this step if the primary bootstrap
already exists and the secondary bootstrap file is just being updated:
.Sy alpha ,
.Sy amiga ,
.Sy i386 ,
.Sy pmax ,
.Sy sparc64 ,
and
@ -208,6 +209,7 @@ The following machines are currently supported by
.Bd -ragged -offset indent
.Sy alpha ,
.Sy amiga ,
.Sy i386 ,
.Sy macppc ,
.Sy news68k ,
.Sy newsmips ,
@ -254,6 +256,23 @@ which must be a regular file in this case.
.Sy [ amiga ]
Modify the default boot command line.
.
.It Sy console=<console name>
.Sy [ i386 ]
Set the console device, <console name> must be one of:
pc, com0, com1, com2, com3, com0kbd, com1kbd, com2kbd or com3kbd.
.
.It Sy password=<password>
.Sy [ i386 ]
Set the password which must be entered before the boot menu can be accessed.
.
.It Sy resetvideo
.Sy [ i386 ]
Reset the video before booting.
.
.It Sy speed=<baud rate>
.Sy [ i386 ]
Set the baud rate for the serial console.
.
.It Sy sunsum
.Sy [ alpha ,
.Sy pmax ,
@ -265,6 +284,10 @@ compatible checksum.
The existing
.Nx Ns Tn /sparc
disklabel should use no more than 4 partitions.
.
.It Sy timeout=<seconds>
.Sy [ i386 ]
Set the timeout before the automatic boot begins to the given number of seconds.
.El
.
.It Fl t Ar fstype
@ -455,6 +478,7 @@ Matthew Fredette (sun2, sun3),
Matthew Green (sparc64),
Ross Harvey (alpha),
Paul Kranenburg (sparc),
David Laight (i386),
Luke Mewburn (macppc),
Matt Thomas (vax),
Izumi Tsutsui (news68k, newsmips),
@ -477,6 +501,11 @@ The size of primary bootstrap programs is restricted to 7.5KB, even
though some file systems (e.g. ISO 9660) are able to accommodate larger
ones.
.
.Ss NetBSD/i386
The size of primary bootstrap programs is restricted to 8KB, even
though some file systems (e.g. ISO 9660) are able to accommodate larger
ones.
.
.Ss NetBSD/pmax
The
.Nx Ns Tn /pmax

View File

@ -1,4 +1,4 @@
/* $NetBSD: installboot.c,v 1.10 2002/05/20 14:38:38 lukem Exp $ */
/* $NetBSD: installboot.c,v 1.11 2003/04/15 14:22:13 dsl Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(__lint)
__RCSID("$NetBSD: installboot.c,v 1.10 2002/05/20 14:38:38 lukem Exp $");
__RCSID("$NetBSD: installboot.c,v 1.11 2003/04/15 14:22:13 dsl Exp $");
#endif /* !__lint */
#include <sys/utsname.h>
@ -49,18 +49,49 @@ __RCSID("$NetBSD: installboot.c,v 1.10 2002/05/20 14:38:38 lukem Exp $");
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <unistd.h>
#include "installboot.h"
int main(int, char *[]);
static int getmachine(ib_params *, const char *, const char *);
static int getfstype(ib_params *, const char *, const char *);
static void getmachine(ib_params *, const char *, const char *);
static void getfstype(ib_params *, const char *, const char *);
static void parseoptions(ib_params *, const char *);
static void usage(void);
static void options_usage(void);
static void machine_usage(void);
static void fstype_usage(void);
static ib_params installboot_params;
#define OFFSET(field) offsetof(ib_params, field)
const struct option {
const char *name; /* Name of option */
ib_flags flag; /* Corresponding IB_xxx flag */
enum { /* Type of option value... */
OPT_BOOL, /* no value */
OPT_INT, /* numeric value */
OPT_WORD, /* space/tab/, terminated */
OPT_STRING /* null terminated */
} type;
int offset; /* of field in ib_params */
} options[] = {
{ "alphasum", IB_ALPHASUM, OPT_BOOL },
{ "append", IB_APPEND, OPT_BOOL },
{ "command", IB_COMMAND, OPT_STRING, OFFSET(command) },
{ "console", IB_CONSOLE, OPT_WORD, OFFSET(console) },
{ "password", IB_PASSWORD, OPT_WORD, OFFSET(password) },
{ "resetvideo", IB_RESETVIDEO, OPT_BOOL },
{ "speed", IB_CONSPEED, OPT_INT, OFFSET(conspeed) },
{ "sunsum", IB_SUNSUM, OPT_BOOL },
{ "timeout", IB_TIMEOUT, OPT_INT, OFFSET(timeout) },
{ NULL },
};
#undef OFFSET
#define OPTION(params, type, opt) (*(type *)((char *)(params) + (opt)->offset))
int
main(int argc, char *argv[])
{
@ -70,6 +101,7 @@ main(int argc, char *argv[])
int ch, rv, mode;
char *p;
const char *op;
ib_flags unsupported_flags;
setprogname(argv[0]);
params = &installboot_params;
@ -77,8 +109,7 @@ main(int argc, char *argv[])
params->fsfd = -1;
params->s1fd = -1;
if ((p = getenv("MACHINE")) != NULL)
if (! getmachine(params, p, "$MACHINE"))
exit(1);
getmachine(params, p, "$MACHINE");
while ((ch = getopt(argc, argv, "b:B:cm:no:t:v")) != -1) {
switch (ch) {
@ -106,8 +137,7 @@ main(int argc, char *argv[])
break;
case 'm':
if (! getmachine(params, optarg, "-m"))
exit(1);
getmachine(params, optarg, "-m");
break;
case 'n':
@ -115,20 +145,11 @@ main(int argc, char *argv[])
break;
case 'o':
if (params->machine == NULL)
errx(1,
"Machine needs to be specified before -o");
while ((p = strsep(&optarg, ",")) != NULL) {
if (*p == '\0')
errx(1, "Empty `-o' option");
if (! params->machine->parseopt(params, p))
exit(1);
}
parseoptions(params, optarg);
break;
case 't':
if (! getfstype(params, optarg, "-t"))
exit(1);
getfstype(params, optarg, "-t");
break;
case 'v':
@ -153,8 +174,36 @@ main(int argc, char *argv[])
if (params->machine == NULL) {
if (uname(&utsname) == -1)
err(1, "Determine uname");
if (! getmachine(params, utsname.machine, "uname()"))
exit(1);
getmachine(params, utsname.machine, "uname()");
}
/* Check that options are supported by this system */
unsupported_flags = params->flags & ~params->machine->valid_flags;
unsupported_flags &= ~(IB_VERBOSE | IB_NOWRITE |IB_CLEAR);
if (unsupported_flags != 0) {
int ndx;
for (ndx = 0; options[ndx].name != NULL; ndx++) {
if (unsupported_flags & options[ndx].flag)
warnx("`-o %s' is not supported for %s",
options[ndx].name, params->machine->name);
}
if (unsupported_flags & IB_STAGE1START)
warnx("`-b bno' is not supported for %s",
params->machine->name);
if (unsupported_flags & IB_STAGE2START)
warnx("`-B bno' is not supported for %s",
params->machine->name);
exit(1);
}
/* and some illegal combinations */
if (params->flags & IB_STAGE1START && params->flags & IB_APPEND) {
warnx("Can't use `-b bno' with `-o append'");
exit(1);
}
if (params->flags & IB_CLEAR &&
params->flags & (IB_STAGE1START | IB_STAGE2START | IB_APPEND)) {
warnx("Can't use `-b bno', `-B bno' or `-o append' with `-c'");
exit(1);
}
params->filesystem = argv[0];
@ -242,44 +291,105 @@ main(int argc, char *argv[])
/* NOTREACHED */
}
int
parseoptionflag(ib_params *params, const char *option, ib_flags wantflags)
static void
parseoptions(ib_params *params, const char *option)
{
struct {
const char *name;
ib_flags flag;
} flags[] = {
{ "alphasum", IB_ALPHASUM },
{ "append", IB_APPEND },
{ "sunsum", IB_SUNSUM },
{ NULL, 0 },
};
int i;
char *cp;
const struct option *opt;
int len;
ulong val;
assert(params != NULL);
assert(option != NULL);
for (i = 0; flags[i].name != NULL; i++) {
if ((strcmp(flags[i].name, option) == 0) &&
(wantflags & flags[i].flag)) {
params->flags |= flags[i].flag;
return (1);
for (;; option += len) {
option += strspn(option, ", \t");
if (*option == 0)
return;
len = strcspn(option, "=,");
for (opt = options; opt->name != NULL; opt++) {
if (memcmp(option, opt->name, len) == 0
&& opt->name[len] == 0)
break;
}
if (opt->name == NULL) {
len = strcspn(option, ",");
warnx("Unknown option `-o %.*s'", len, option);
break;
}
params->flags |= opt->flag;
if (opt->type == OPT_BOOL) {
if (option[len] != '=')
continue;
warnx("Option `%s' must not have a value", opt->name);
break;
}
if (option[len] != '=') {
warnx("Option `%s' must have a value", opt->name);
break;
}
option += len + 1;
len = strcspn(option, ",");
switch (opt->type) {
case OPT_STRING:
len = strlen(option);
/* FALLTHROUGH */
case OPT_WORD:
cp = strdup(option);
if (cp == NULL)
err(1, "strdup");
cp[len] = 0;
OPTION(params, char *, opt) = cp;
continue;
case OPT_INT:
val = strtoul(option, &cp, 0);
if (cp > option + len || (*cp != 0 && *cp != ','))
break;
OPTION(params, int, opt) = val;
if (OPTION(params, int, opt) != val)
/* value got truncated on int convertion */
break;
continue;
default:
errx(1, "Internal error: option `%s' has invalid type",
opt->name, opt->type);
}
warnx("Invalid option value `%s=%.*s'", opt->name, len, option);
break;
}
return (0);
options_usage();
exit(1);
}
int
no_parseopt(ib_params *params, const char *option)
static void
options_usage(void)
{
int ndx;
const char *pfx;
assert(params != NULL);
assert(option != NULL);
/* all options are unsupported */
warnx("Unsupported -o option `%s'", option);
return (0);
warnx("Valid options are:");
pfx = "\t";
for (ndx = 0; options[ndx].name != 0; ndx++) {
fprintf(stderr, "%s%s", pfx, options[ndx].name);
switch (options[ndx].type) {
case OPT_INT:
fprintf(stderr, "=number");
break;
case OPT_WORD:
fprintf(stderr, "=word");
break;
case OPT_STRING:
fprintf(stderr, "=string");
break;
default:
break;
}
if ((ndx % 5) == 4)
pfx = ",\n\t";
else
pfx = ", ";
}
fprintf(stderr, "\n");
}
int
@ -307,21 +417,32 @@ no_clearboot(ib_params *params)
}
static int
static void
getmachine(ib_params *param, const char *mach, const char *provider)
{
int i;
assert(param != NULL);
assert(mach != NULL);
assert(provider != NULL);
for (i = 0; machines[i].name != NULL; i++) {
if (strcmp(machines[i].name, mach) == 0) {
param->machine = &machines[i];
return;
}
}
warnx("Invalid machine `%s' from %s", mach, provider);
machine_usage();
exit(1);
}
static void
machine_usage(void)
{
const char *prefix;
int i;
if (param != NULL && mach != NULL && provider != NULL) {
for (i = 0; machines[i].name != NULL; i++) {
if (strcmp(machines[i].name, mach) == 0) {
param->machine = &machines[i];
return (1);
}
}
warnx("Invalid machine `%s' from %s", mach, provider);
}
warnx("Supported machines are:");
#define MACHS_PER_LINE 9
prefix="";
@ -335,25 +456,34 @@ getmachine(ib_params *param, const char *mach, const char *provider)
fprintf(stderr, "%s%s", prefix, machines[i].name);
}
fputs("\n", stderr);
return (0);
}
static int
static void
getfstype(ib_params *param, const char *fstype, const char *provider)
{
int i;
assert(param != NULL);
assert(fstype != NULL);
assert(provider != NULL);
for (i = 0; fstypes[i].name != NULL; i++) {
if (strcmp(fstypes[i].name, fstype) == 0) {
param->fstype = &fstypes[i];
return;
}
}
warnx("Invalid file system type `%s' from %s", fstype, provider);
fstype_usage();
exit(1);
}
static void
fstype_usage(void)
{
const char *prefix;
int i;
if (param != NULL && fstype != NULL && provider != NULL) {
for (i = 0; fstypes[i].name != NULL; i++) {
if (strcmp(fstypes[i].name, fstype) == 0) {
param->fstype = &fstypes[i];
return (1);
}
}
warnx("Invalid file system type `%s' from %s",
fstype, provider);
}
warnx("Supported file system types are:");
#define FSTYPES_PER_LINE 9
prefix="";
@ -367,7 +497,6 @@ getfstype(ib_params *param, const char *fstype, const char *provider)
fprintf(stderr, "%s%s", prefix, fstypes[i].name);
}
fputs("\n", stderr);
return (0);
}
static void
@ -381,7 +510,8 @@ usage(void)
"\t\t [-b s1start] [-B s2start] filesystem primary [secondary]\n"
"Usage: %s -c [-nv] [-m machine] [-o options] [-t fstype] filesystem\n",
prog, prog);
getmachine(NULL, NULL, NULL);
getfstype(NULL, NULL, NULL);
machine_usage();
fstype_usage();
options_usage();
exit(1);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: installboot.h,v 1.18 2003/04/09 22:30:59 dsl Exp $ */
/* $NetBSD: installboot.h,v 1.19 2003/04/15 14:22:13 dsl Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -62,6 +62,11 @@ typedef enum {
IB_STAGE1START= 1<<11, /* start block for stage 1 provided */
IB_STAGE2START= 1<<12, /* start block for stage 2 provided */
IB_COMMAND = 1<<13, /* Amiga commandline option */
IB_RESETVIDEO = 1<<14, /* i386 reset video */
IB_CONSOLE = 1<<15, /* i386 console */
IB_CONSPEED = 1<<16, /* i386 console baud rate */
IB_TIMEOUT = 1<<17, /* i386 boot timeout */
IB_PASSWORD = 1<<18, /* i386 boot password */
} ib_flags;
typedef struct {
@ -77,6 +82,12 @@ typedef struct {
uint64_t s1start; /* start block of stage1 */
const char *stage2; /* name of stage2 bootstrap */
uint64_t s2start; /* start block of stage2 */
/* parsed -o option=value data */
const char *command; /* name of command string */
const char *console; /* name of console */
int conspeed; /* console baud rate */
const char *password; /* boot password */
int timeout; /* interactive boot timeout */
} ib_params;
typedef struct {
@ -86,9 +97,9 @@ typedef struct {
struct ib_mach {
const char *name;
int (*parseopt) (ib_params *, const char *);
int (*setboot) (ib_params *);
int (*clearboot) (ib_params *);
ib_flags valid_flags;
};
struct ib_fs {
@ -123,10 +134,8 @@ extern struct ib_mach machines[];
extern struct ib_fs fstypes[];
/* installboot.c */
int parseoptionflag(ib_params *, const char *, ib_flags);
uint16_t compute_sunsum(const uint16_t *);
int set_sunsum(ib_params *, uint16_t *, uint16_t);
int no_parseopt(ib_params *, const char *);
int no_setboot(ib_params *);
int no_clearboot(ib_params *);
@ -144,10 +153,8 @@ int raw_match(ib_params *);
int raw_findstage2(ib_params *, uint32_t *, ib_block *);
/* machines.c */
int alpha_parseopt(ib_params *, const char *);
int alpha_setboot(ib_params *);
int alpha_clearboot(ib_params *);
int amiga_parseopt(ib_params *, const char *);
int amiga_setboot(ib_params *);
int i386_setboot(ib_params *);
int macppc_setboot(ib_params *);
@ -156,7 +163,6 @@ 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 *);
int sparc_setboot(ib_params *);
@ -165,7 +171,6 @@ int sparc64_setboot(ib_params *);
int sparc64_clearboot(ib_params *);
int sun68k_setboot(ib_params *);
int sun68k_clearboot(ib_params *);
int vax_parseopt(ib_params *, const char *);
int vax_setboot(ib_params *);
int vax_clearboot(ib_params *);
int x68k_setboot(ib_params *);

View File

@ -1,4 +1,4 @@
/* $NetBSD: machines.c,v 1.14 2003/04/09 22:30:59 dsl Exp $ */
/* $NetBSD: machines.c,v 1.15 2003/04/15 14:22:13 dsl Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -40,19 +40,32 @@
#include "installboot.h"
struct ib_mach machines[] = {
{ "alpha", alpha_parseopt, alpha_setboot, alpha_clearboot },
{ "amiga", amiga_parseopt, amiga_setboot, no_clearboot },
{ "i386", no_parseopt, i386_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 },
{ "sparc64", no_parseopt, sparc64_setboot, sparc64_clearboot },
{ "sun2", no_parseopt, sun68k_setboot, sun68k_clearboot },
{ "sun3", no_parseopt, sun68k_setboot, sun68k_clearboot },
{ "vax", vax_parseopt, vax_setboot, vax_clearboot },
{ "x68k", no_parseopt, x68k_setboot, x68k_clearboot },
{ "alpha", alpha_setboot, alpha_clearboot,
IB_STAGE1START | IB_ALPHASUM | IB_APPEND | IB_SUNSUM },
{ "amiga", amiga_setboot, no_clearboot,
IB_STAGE1START | IB_STAGE2START | IB_COMMAND },
{ "i386", i386_setboot, no_clearboot,
IB_RESETVIDEO | IB_CONSOLE | IB_CONSPEED |
IB_PASSWORD | IB_TIMEOUT },
{ "macppc", macppc_setboot, macppc_clearboot,
IB_STAGE2START },
{ "news68k", news68k_setboot, news68k_clearboot,
IB_STAGE2START },
{ "newsmips", newsmips_setboot, newsmips_clearboot,
IB_STAGE2START },
{ "pmax", pmax_setboot, pmax_clearboot,
IB_STAGE1START | IB_APPEND | IB_SUNSUM },
{ "shark", no_setboot, no_clearboot, },
{ "sparc", sparc_setboot, sparc_clearboot,
IB_STAGE2START },
{ "sparc64", sparc64_setboot, sparc64_clearboot },
{ "sun2", sun68k_setboot, sun68k_clearboot,
IB_STAGE2START },
{ "sun3", sun68k_setboot, sun68k_clearboot,
IB_STAGE2START },
{ "vax", vax_setboot, vax_clearboot,
IB_STAGE1START | IB_APPEND | IB_SUNSUM },
{ "x68k", x68k_setboot, x68k_clearboot,
IB_STAGE1START | IB_STAGE2START },
{ 0, 0, 0, 0 },
};