- support optional secondary bootstrap arg for install (unused by

existing backends, but future ones need it)
- use "bootstrap" instead of "boot block" in various messages where appropriate
- rename some members of ib_params
This commit is contained in:
lukem 2002-04-12 06:50:41 +00:00
parent a56dc0602f
commit d280442683
7 changed files with 88 additions and 79 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: alpha.c,v 1.4 2002/04/11 08:02:27 lukem Exp $ */
/* $NetBSD: alpha.c,v 1.5 2002/04/12 06:50:41 lukem 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.4 2002/04/11 08:02:27 lukem Exp $");
__RCSID("$NetBSD: alpha.c,v 1.5 2002/04/12 06:50:41 lukem Exp $");
#endif /* !__lint */
#include <sys/param.h>
@ -175,11 +175,11 @@ alpha_clearboot(ib_params *params)
}
if (params->flags & IB_VERBOSE) {
printf("Old boot block start sector: %#llx\n",
printf("Old bootstrap start sector: %#llx\n",
(unsigned long long)le64toh(bb.bb_secstart));
printf("Old boot block size: %#llx\n",
printf("Old bootstrap size: %#llx\n",
(unsigned long long)le64toh(bb.bb_secsize));
printf("Old boot block checksum: %#llx\n",
printf("Old bootstrap checksum: %#llx\n",
(unsigned long long)bb.bb_cksum);
}
@ -189,11 +189,11 @@ alpha_clearboot(ib_params *params)
if (params->flags & IB_SUNSUM)
sun_bootstrap(params, &bb);
printf("New boot block start sector: %#llx\n",
printf("New bootstrap start sector: %#llx\n",
(unsigned long long)le64toh(bb.bb_secstart));
printf("New boot block size: %#llx\n",
printf("New bootstrap size: %#llx\n",
(unsigned long long)le64toh(bb.bb_secsize));
printf("New boot block checksum: %#llx\n",
printf("New bootstrap checksum: %#llx\n",
(unsigned long long)bb.bb_cksum);
if (params->flags & IB_VERBOSE)
@ -228,8 +228,8 @@ alpha_setboot(ib_params *params)
assert(params != NULL);
assert(params->fsfd != -1);
assert(params->filesystem != NULL);
assert(params->bbfd != -1);
assert(params->bootblock != NULL);
assert(params->s1fd != -1);
assert(params->stage1 != NULL);
assert(sizeof(struct alpha_boot_block) == ALPHA_BOOT_BLOCK_BLOCKSIZE);
retval = 0;
@ -241,12 +241,12 @@ alpha_setboot(ib_params *params)
goto done;
}
if (fstat(params->bbfd, &bootstrapsb) == -1) {
warn("Examining `%s'", params->bootblock);
if (fstat(params->s1fd, &bootstrapsb) == -1) {
warn("Examining `%s'", params->stage1);
goto done;
}
if (!S_ISREG(bootstrapsb.st_mode)) {
warnx("`%s' must be a regular file", params->bootblock);
warnx("`%s' must be a regular file", params->stage1);
goto done;
}
/*
@ -265,12 +265,12 @@ alpha_setboot(ib_params *params)
memset(bootstrapbuf, 0, bootstrapsize);
/* read the file into the buffer */
rv = pread(params->bbfd, bootstrapbuf, bootstrapsb.st_size, 0);
rv = pread(params->s1fd, bootstrapbuf, bootstrapsb.st_size, 0);
if (rv == -1) {
warn("Reading `%s'", params->bootblock);
warn("Reading `%s'", params->stage1);
return (0);
} else if (rv != bootstrapsb.st_size) {
warnx("Reading `%s': short read", params->bootblock);
warnx("Reading `%s': short read", params->stage1);
return (0);
}
@ -286,7 +286,7 @@ alpha_setboot(ib_params *params)
if (params->flags & IB_SUNSUM)
check_sparc(&bb, "Initial");
/* fill in the updated boot block fields */
/* fill in the updated bootstrap fields */
if (params->flags & IB_APPEND) {
struct stat filesyssb;
@ -296,7 +296,7 @@ alpha_setboot(ib_params *params)
}
if (!S_ISREG(filesyssb.st_mode)) {
warnx(
"`%s' must be a regular file to append a boot block",
"`%s' must be a regular file to append a bootstrap",
params->filesystem);
goto done;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: pmax.c,v 1.2 2002/04/09 02:06:29 thorpej Exp $ */
/* $NetBSD: pmax.c,v 1.3 2002/04/12 06:50:41 lukem 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.2 2002/04/09 02:06:29 thorpej Exp $");
__RCSID("$NetBSD: pmax.c,v 1.3 2002/04/12 06:50:41 lukem Exp $");
#endif /* !__lint */
#include <sys/param.h>
@ -211,8 +211,8 @@ pmax_setboot(ib_params *params)
assert(params != NULL);
assert(params->fsfd != -1);
assert(params->filesystem != NULL);
assert(params->bbfd != -1);
assert(params->bootblock != NULL);
assert(params->s1fd != -1);
assert(params->stage1 != NULL);
assert(sizeof(struct pmax_boot_block) == PMAX_BOOT_BLOCK_BLOCKSIZE);
retval = 0;
@ -224,12 +224,12 @@ pmax_setboot(ib_params *params)
goto done;
}
if (fstat(params->bbfd, &bootstrapsb) == -1) {
warn("Examining `%s'", params->bootblock);
if (fstat(params->s1fd, &bootstrapsb) == -1) {
warn("Examining `%s'", params->stage1);
goto done;
}
if (!S_ISREG(bootstrapsb.st_mode)) {
warnx("`%s' must be a regular file", params->bootblock);
warnx("`%s' must be a regular file", params->stage1);
goto done;
}
if (! load_bootstrap(params, &bootstrapbuf, &bootstrapload,
@ -255,7 +255,7 @@ pmax_setboot(ib_params *params)
}
if (!S_ISREG(filesyssb.st_mode)) {
warnx(
"`%s' must be a regular file to append a boot block",
"`%s' must be a regular file to append a bootstrap",
params->filesystem);
goto done;
}
@ -348,13 +348,13 @@ load_bootstrap(ib_params *params, char **data,
Elf32_Phdr phdr;
struct seglist seglist[MAX_SEGMENTS];
if ((pread(params->bbfd, &ehdr, sizeof(ehdr), 0)) != sizeof(ehdr)) {
warn("Reading `%s'", params->bootblock);
if ((pread(params->s1fd, &ehdr, sizeof(ehdr), 0)) != sizeof(ehdr)) {
warn("Reading `%s'", params->stage1);
return (0);
}
if ((memcmp(ehdr.e_ident, ELFMAG, SELFMAG) != 0) ||
(ehdr.e_ident[EI_CLASS] != ELFCLASS32)) {
warnx("No ELF header in `%s'", params->bootblock);
warnx("No ELF header in `%s'", params->stage1);
return (0);
}
@ -362,10 +362,10 @@ load_bootstrap(ib_params *params, char **data,
lowaddr = (u_int32_t) ULONG_MAX;
for (i = 0; i < le16toh(ehdr.e_phnum); i++) {
if (pread(params->bbfd, &phdr, sizeof(phdr),
if (pread(params->s1fd, &phdr, sizeof(phdr),
(off_t) le32toh(ehdr.e_phoff) + i * sizeof(phdr))
!= sizeof(phdr)) {
warn("Reading `%s'", params->bootblock);
warn("Reading `%s'", params->stage1);
return (0);
}
if (le32toh(phdr.p_type) != PT_LOAD)
@ -393,10 +393,10 @@ load_bootstrap(ib_params *params, char **data,
/* Now load the bootstrap into memory */
for (i = 0; i < nsegs; i++) {
if (pread(params->bbfd, *data + seglist[i].addr - lowaddr,
if (pread(params->s1fd, *data + seglist[i].addr - lowaddr,
seglist[i].f_size, (off_t)seglist[i].f_offset)
!= seglist[i].f_size) {
warn("Reading `%s'", params->bootblock);
warn("Reading `%s'", params->stage1);
return (0);
}
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: sparc64.c,v 1.5 2002/04/11 07:56:14 lukem Exp $ */
/* $NetBSD: sparc64.c,v 1.6 2002/04/12 06:50:41 lukem Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -66,7 +66,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(__lint)
__RCSID("$NetBSD: sparc64.c,v 1.5 2002/04/11 07:56:14 lukem Exp $");
__RCSID("$NetBSD: sparc64.c,v 1.6 2002/04/12 06:50:41 lukem Exp $");
#endif /* !__lint */
#include <sys/param.h>
@ -145,22 +145,22 @@ sparc64_setboot(ib_params *params)
assert(params != NULL);
assert(params->fsfd != -1);
assert(params->filesystem != NULL);
assert(params->bbfd != -1);
assert(params->bootblock != NULL);
assert(params->s1fd != -1);
assert(params->stage1 != NULL);
retval = 0;
if (fstat(params->bbfd, &bootstrapsb) == -1) {
warn("Examining `%s'", params->bootblock);
if (fstat(params->s1fd, &bootstrapsb) == -1) {
warn("Examining `%s'", params->stage1);
goto done;
}
if (!S_ISREG(bootstrapsb.st_mode)) {
warnx("`%s' must be a regular file", params->bootblock);
warnx("`%s' must be a regular file", params->stage1);
goto done;
}
memset(&bb, 0, SPARC64_BOOT_BLOCK_MAX_SIZE);
rv = read(params->bbfd, &bb, sizeof bb);
rv = read(params->s1fd, &bb, sizeof bb);
if (rv == -1) {
warn("Reading `%s'", params->filesystem);
goto done;

View File

@ -1,4 +1,4 @@
/* $NetBSD: vax.c,v 1.1 2002/04/03 09:09:04 lukem Exp $ */
/* $NetBSD: vax.c,v 1.2 2002/04/12 06:50:41 lukem 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.1 2002/04/03 09:09:04 lukem Exp $");
__RCSID("$NetBSD: vax.c,v 1.2 2002/04/12 06:50:41 lukem Exp $");
#endif /* !__lint */
#include <sys/param.h>
@ -182,8 +182,8 @@ vax_setboot(ib_params *params)
assert(params != NULL);
assert(params->fsfd != -1);
assert(params->filesystem != NULL);
assert(params->bbfd != -1);
assert(params->bootblock != NULL);
assert(params->s1fd != -1);
assert(params->stage1 != NULL);
assert(sizeof(struct vax_boot_block) == VAX_BOOT_BLOCK_BLOCKSIZE);
retval = 0;
@ -195,12 +195,12 @@ vax_setboot(ib_params *params)
goto done;
}
if (fstat(params->bbfd, &bootstrapsb) == -1) {
warn("Examining `%s'", params->bootblock);
if (fstat(params->s1fd, &bootstrapsb) == -1) {
warn("Examining `%s'", params->stage1);
goto done;
}
if (!S_ISREG(bootstrapsb.st_mode)) {
warnx("`%s' must be a regular file", params->bootblock);
warnx("`%s' must be a regular file", params->stage1);
goto done;
}
if (! load_bootstrap(params, &bootstrapbuf, &bootstrapload,
@ -226,7 +226,7 @@ vax_setboot(ib_params *params)
}
if (!S_ISREG(filesyssb.st_mode)) {
warnx(
"`%s' must be a regular file to append a boot block",
"`%s' must be a regular file to append a bootstrap",
params->filesystem);
goto done;
}
@ -322,13 +322,13 @@ load_bootstrap(ib_params *params, char **data,
return (0);
}
cc = pread(params->bbfd, *data, buflen, 0);
cc = pread(params->s1fd, *data, buflen, 0);
if (cc <= 0) {
warn("Reading `%s'", params->bootblock);
warn("Reading `%s'", params->stage1);
return (0);
}
if (cc > 512 * VAX_BOOT_SIZE) {
warnx("`%s': too large", params->bootblock);
warnx("`%s': too large", params->stage1);
return (0);
}

View File

@ -1,4 +1,4 @@
.\" $NetBSD: installboot.8,v 1.7 2002/04/04 13:45:25 lukem Exp $
.\" $NetBSD: installboot.8,v 1.8 2002/04/12 06:50:41 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 April 4, 2002
.Dd April 12, 2002
.Dt INSTALLBOOT 8
.Os
.Sh NAME
@ -57,7 +57,8 @@
.Op Fl b Ar bno
.Ek
.Ar filesystem
.Ar bootstrap
.Ar primary
.Op Ar secondary
.Nm ""
.Fl c
.Op Fl nv
@ -80,7 +81,7 @@ utility installs and removes
disk bootstrap software into a file system.
.Nm
can install
.Ar bootstrap
.Ar primary
into
.Ar filesystem ,
or disable an existing bootstrap in
@ -148,7 +149,7 @@ are as follows:
.
.It Fl b Ar bno
Install
.Ar bootstrap
.Ar primary
at block number
.Ar bno
instead of the default location for the machine and file system type.
@ -197,7 +198,7 @@ This is the default for
.Em [ pmax ,
.Em vax ]
Append
.Ar bootstrap
.Ar primary
to the end of
.Ar filesystem ,
which must be a regular file in this case.

View File

@ -1,4 +1,4 @@
/* $NetBSD: installboot.c,v 1.4 2002/04/12 03:15:20 lukem Exp $ */
/* $NetBSD: installboot.c,v 1.5 2002/04/12 06:50:41 lukem 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.4 2002/04/12 03:15:20 lukem Exp $");
__RCSID("$NetBSD: installboot.c,v 1.5 2002/04/12 06:50:41 lukem Exp $");
#endif /* !__lint */
#include <sys/utsname.h>
@ -136,7 +136,7 @@ main(int argc, char *argv[])
argv += optind;
if (((params->flags & IB_CLEAR) != 0 && argc != 1) ||
((params->flags & IB_CLEAR) == 0 && argc != 2))
((params->flags & IB_CLEAR) == 0 && (argc < 2 || argc > 3)))
usage();
/* set missing defaults */
@ -160,19 +160,25 @@ main(int argc, char *argv[])
err(1, "Opening file system `%s' read-%s",
params->filesystem, op);
if (argc == 2) {
params->bootblock = argv[1];
if ((params->bbfd = open(params->bootblock, O_RDONLY, 0600))
if (argc >= 2) {
params->stage1 = argv[1];
if ((params->s1fd = open(params->stage1, O_RDONLY, 0600))
== -1)
err(1, "Opening boot block `%s'", params->bootblock);
err(1, "Opening primary bootstrap `%s'",
params->stage1);
}
if (argc == 3) {
params->stage2 = argv[2];
}
assert(params->machine != NULL);
if (params->flags & IB_VERBOSE) {
printf("File system: %s\n", params->filesystem);
printf("Boot block: %s\n",
printf("Primary bootstrap: %s\n",
(params->flags & IB_CLEAR) ? "(to be cleared)"
: params->bootblock);
: params->stage1);
if (params->stage2 != NULL)
printf("Secondary bootstrap: %s\n", params->stage2);
}
if (params->flags & IB_CLEAR) {
@ -183,15 +189,16 @@ main(int argc, char *argv[])
rv = params->machine->setboot(params);
}
if (rv == 0)
errx(1, "%s boot block operation failed", op);
errx(1, "%s bootstrap operation failed", op);
if (fsync(params->fsfd) == -1)
err(1, "Synchronising file system `%s'", params->filesystem);
if (close(params->fsfd) == -1)
err(1, "Closing file system `%s'", params->filesystem);
if (argc == 2)
if (close(params->bbfd) == -1)
err(1, "Closing boot block `%s'", params->bootblock);
if (close(params->s1fd) == -1)
err(1, "Closing primary bootstrap `%s'",
params->stage1);
exit(0);
/* NOTREACHED */
@ -238,8 +245,8 @@ int
no_setboot(ib_params *params)
{
/* boot block installation is not supported */
warnx("%s: boot block installation is not supported",
/* bootstrap installation is not supported */
warnx("%s: bootstrap installation is not supported",
params->machine->name);
return (0);
}
@ -248,8 +255,8 @@ int
no_clearboot(ib_params *params)
{
/* boot block removal is not supported */
warnx("%s: boot block removal is not supported",
/* bootstrap removal is not supported */
warnx("%s: bootstrap removal is not supported",
params->machine->name);
return (0);
}
@ -291,7 +298,7 @@ usage(void)
prog = getprogname();
fprintf(stderr,
"Usage: %s [-nv] [-m machine] [-o options] [-t fstype]\n"
"\t\t [-b block] filesystem bootstrap\n"
"\t\t [-b block] filesystem primary [secondary]\n"
"Usage: %s -c [-nv] [-m machine] [-o options] [-t fstype] filesystem\n",
prog, prog);
exit(1);

View File

@ -1,4 +1,4 @@
/* $NetBSD: installboot.h,v 1.3 2002/04/11 07:56:13 lukem Exp $ */
/* $NetBSD: installboot.h,v 1.4 2002/04/12 06:50:41 lukem Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -62,8 +62,9 @@ typedef struct {
const char *fstype; // XXX replace with struct *?
const char *filesystem;
int fsfd;
const char *bootblock;
int bbfd;
const char *stage1;
int s1fd;
const char *stage2;
long startblock;
} ib_params;