First cut of hp300 installboot, seems to DTRT on i386.
Maybe this code ought to know how to add a file to the LIF filesystem.
This commit is contained in:
parent
1fafd3e354
commit
6bf8729bd1
|
@ -1,4 +1,4 @@
|
|||
# $NetBSD: Makefile,v 1.26 2003/10/28 08:21:26 mrg Exp $
|
||||
# $NetBSD: Makefile,v 1.27 2003/11/08 16:44:35 dsl 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 amiga.c i386.c macppc.c news.c next68k.c pmax.c \
|
||||
alpha.c amiga.c hp300.c i386.c macppc.c news.c next68k.c pmax.c \
|
||||
sparc.c sparc64.c sun68k.c vax.c x68k.c
|
||||
MAN= installboot.8
|
||||
|
||||
|
|
|
@ -0,0 +1,203 @@
|
|||
/* $NetBSD: hp300.c,v 1.1 2003/11/08 16:44:35 dsl Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2003 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by David Laight.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if !defined(__lint)
|
||||
__RCSID("$NetBSD: hp300.c,v 1.1 2003/11/08 16:44:35 dsl Exp $");
|
||||
#endif /* !__lint */
|
||||
|
||||
#include <sys/disklabel.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
#include <md5.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "installboot.h"
|
||||
#include "hp300_volhdr.h"
|
||||
|
||||
#define nelem(x) (sizeof (x)/sizeof *(x))
|
||||
|
||||
int
|
||||
hp300_setboot(ib_params *params)
|
||||
{
|
||||
int retval;
|
||||
uint8_t *bootstrap;
|
||||
ssize_t rv;
|
||||
struct disklabel label;
|
||||
struct partition *boot;
|
||||
struct hp300_lifdir *lifdir;
|
||||
char ch, *cp;
|
||||
int bootfd = -1;
|
||||
int offset;
|
||||
int max_ptn;
|
||||
int i;
|
||||
struct stat sb;
|
||||
|
||||
assert(params != NULL);
|
||||
assert(params->fsfd != -1);
|
||||
assert(params->filesystem != NULL);
|
||||
assert(params->s1fd != -1);
|
||||
assert(params->stage1 != NULL);
|
||||
|
||||
retval = 0;
|
||||
bootstrap = MAP_FAILED;
|
||||
|
||||
/* The bootstrap can be well over 8k, and must go into a BOOT ptn. */
|
||||
if (ioctl(params->fsfd, DIOCGDINFO, &label) != 0) {
|
||||
warn("reading disklabel");
|
||||
goto done;
|
||||
}
|
||||
|
||||
max_ptn = label.d_npartitions;
|
||||
if (max_ptn > nelem(label.d_partitions))
|
||||
max_ptn = nelem(label.d_partitions);
|
||||
for (boot = label.d_partitions; ; boot++) {
|
||||
if (--max_ptn < 0) {
|
||||
warnx("No BOOT partition");
|
||||
goto done;
|
||||
}
|
||||
if (boot->p_fstype == FS_BOOT)
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* We put the entire LIF file into the BOOT partition even when
|
||||
* it doesn't start at the beginning of the disk.
|
||||
*
|
||||
* Maybe we ought to be able to take a binary file and add
|
||||
* it to the LIF filesystem.
|
||||
*/
|
||||
if (boot->p_size * label.d_secsize < params->s1stat.st_size) {
|
||||
warn("BOOT partition too small (%d < %" PRId64 ")",
|
||||
boot->p_size * label.d_secsize,
|
||||
params->s1stat.st_size);
|
||||
goto done;
|
||||
}
|
||||
|
||||
bootstrap = mmap(NULL, params->s1stat.st_size, PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE, params->s1fd, 0);
|
||||
if (bootstrap == MAP_FAILED) {
|
||||
warn("mmaping `%s'", params->stage1);
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Relocate files, sanity check LIF directory on the way */
|
||||
lifdir = (void *)(bootstrap + HP300_SECTSIZE * 2);
|
||||
for (i = 0; i < 8; lifdir++, i++) {
|
||||
int addr = be32toh(lifdir->dir_addr);
|
||||
int limit = (params->s1stat.st_size - 1) / HP300_SECTSIZE + 1;
|
||||
if (addr + be32toh(lifdir->dir_length) > limit) {
|
||||
warnx("LIF entry %d larger (%d %d) than LIF file",
|
||||
i, addr + be32toh(lifdir->dir_length), limit);
|
||||
goto done;
|
||||
}
|
||||
if (addr != 0 && boot->p_offset != 0)
|
||||
lifdir->dir_addr = htobe32(addr + boot->p_offset
|
||||
* (label.d_secsize / HP300_SECTSIZE));
|
||||
}
|
||||
|
||||
/* Open boot partition itself */
|
||||
cp = strchr(params->filesystem, 0) - 1;
|
||||
ch = *cp;
|
||||
*cp = 'a' + (boot - label.d_partitions);
|
||||
bootfd = open(params->filesystem,
|
||||
params->flags & IB_NOWRITE ? O_RDONLY : O_RDWR, 0);
|
||||
if (bootfd == -1) {
|
||||
warn("Cannot open BOOT partition %s", params->filesystem);
|
||||
*cp = ch;
|
||||
goto done;
|
||||
}
|
||||
*cp = ch;
|
||||
|
||||
/* stat as a slight sanity check */
|
||||
if (fstat(bootfd, &sb) == -1
|
||||
|| sb.st_size != boot->p_size * label.d_secsize) {
|
||||
warnx("Opened BOOT partition size doesn't match disklabel");
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (params->flags & IB_NOWRITE) {
|
||||
retval = 1;
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Write LIF volume header and directory to sectors 0 and 1 */
|
||||
rv = pwrite(params->fsfd, bootstrap, 1024, 0);
|
||||
if (rv != 1024) {
|
||||
if (rv == -1)
|
||||
warn("Writing `%s'", params->filesystem);
|
||||
else
|
||||
warnx("Writing `%s': short write", params->filesystem);
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Write files to BOOT partition */
|
||||
offset = boot->p_offset <= HP300_SECTSIZE * 16 / label.d_secsize
|
||||
? HP300_SECTSIZE * 16 : 0;
|
||||
rv = pwrite(bootfd, bootstrap + offset, params->s1stat.st_size - offset, offset);
|
||||
if (rv != params->s1stat.st_size - offset) {
|
||||
if (rv == -1)
|
||||
warn("Writing boot filesystem of `%s'",
|
||||
params->filesystem);
|
||||
else
|
||||
warnx("Writing boot filesystem of `%s': short write", params->filesystem);
|
||||
goto done;
|
||||
}
|
||||
|
||||
retval = 1;
|
||||
|
||||
done:
|
||||
if (bootstrap != MAP_FAILED)
|
||||
munmap(bootstrap, params->s1stat.st_size);
|
||||
if (bootfd != -1)
|
||||
close(bootfd);
|
||||
return retval;
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
/* $NetBSD: hp300_volhdr.h,v 1.1 2003/11/08 16:44:35 dsl Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* the Systems Programming Group of the University of Utah Computer
|
||||
* Science Department.
|
||||
*
|
||||
* 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. Neither the name of the University 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 REGENTS 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 REGENTS 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.
|
||||
*
|
||||
* @(#)volhdr.h 8.1 (Berkeley) 6/10/93
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 1988 University of Utah.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* the Systems Programming Group of the University of Utah Computer
|
||||
* Science Department.
|
||||
*
|
||||
* 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 University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
|
||||
*
|
||||
* @(#)volhdr.h 8.1 (Berkeley) 6/10/93
|
||||
*/
|
||||
|
||||
/*
|
||||
* vohldr.h: volume header for "LIF" format volumes
|
||||
*/
|
||||
|
||||
struct hp300_lifvol {
|
||||
int16_t vol_id;
|
||||
char vol_label[6];
|
||||
int32_t vol_addr;
|
||||
int16_t vol_oct;
|
||||
int16_t vol_dummy;
|
||||
int32_t vol_dirsize;
|
||||
int16_t vol_version;
|
||||
int16_t vol_zero;
|
||||
int32_t vol_huh1;
|
||||
int32_t vol_huh2;
|
||||
int32_t vol_length;
|
||||
};
|
||||
|
||||
struct hp300_lifdir {
|
||||
char dir_name[10];
|
||||
int16_t dir_type;
|
||||
int32_t dir_addr;
|
||||
int32_t dir_length;
|
||||
char dir_toc[6];
|
||||
int16_t dir_flag;
|
||||
int32_t dir_exec;
|
||||
};
|
||||
|
||||
/* load header for boot rom */
|
||||
struct hp300_load {
|
||||
int32_t address;
|
||||
int32_t count;
|
||||
};
|
||||
|
||||
#define HP300_VOL_ID -32768
|
||||
#define HP300_VOL_OCT 4096
|
||||
#define HP300_DIR_TYPE -5822
|
||||
#define HP300_DIR_FLAG 0x8001 /* dont ask me! */
|
||||
#define HP300_SECTSIZE 256
|
|
@ -1,4 +1,4 @@
|
|||
.\" $NetBSD: installboot.8,v 1.34 2003/11/02 16:04:31 perry Exp $
|
||||
.\" $NetBSD: installboot.8,v 1.35 2003/11/08 16:44:35 dsl Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2002-2003 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 October 28, 2003
|
||||
.Dd November 8, 2003
|
||||
.Dt INSTALLBOOT 8
|
||||
.Os
|
||||
.Sh NAME
|
||||
|
@ -194,7 +194,9 @@ The following machines are currently supported by
|
|||
.Nm :
|
||||
.Bd -ragged -offset indent
|
||||
.Sy alpha ,
|
||||
.Sy amd64 ,
|
||||
.Sy amiga ,
|
||||
.Sy hp300 ,
|
||||
.Sy i386 ,
|
||||
.Sy macppc ,
|
||||
.Sy news68k ,
|
||||
|
@ -615,7 +617,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
|
||||
.Ss NetBSD/hp300
|
||||
The disk must have a boot partition large enough to hold the bootstrap code.
|
||||
Currently the primary bootstrap must be a LIF format file.
|
||||
.
|
||||
.Ss NetBSD/i386 and NetBSD/amd64
|
||||
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.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: installboot.h,v 1.22 2003/10/27 16:51:05 cl Exp $ */
|
||||
/* $NetBSD: installboot.h,v 1.23 2003/11/08 16:44:35 dsl Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2002 The NetBSD Foundation, Inc.
|
||||
|
@ -157,6 +157,7 @@ int raw_findstage2(ib_params *, uint32_t *, ib_block *);
|
|||
int alpha_setboot(ib_params *);
|
||||
int alpha_clearboot(ib_params *);
|
||||
int amiga_setboot(ib_params *);
|
||||
int hp300_setboot(ib_params *);
|
||||
int i386_setboot(ib_params *);
|
||||
int macppc_setboot(ib_params *);
|
||||
int macppc_clearboot(ib_params *);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: machines.c,v 1.18 2003/10/27 16:51:05 cl Exp $ */
|
||||
/* $NetBSD: machines.c,v 1.19 2003/11/08 16:44:35 dsl Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2002 The NetBSD Foundation, Inc.
|
||||
|
@ -38,7 +38,7 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID) && !defined(__lint)
|
||||
__RCSID("$NetBSD: machines.c,v 1.18 2003/10/27 16:51:05 cl Exp $");
|
||||
__RCSID("$NetBSD: machines.c,v 1.19 2003/11/08 16:44:35 dsl Exp $");
|
||||
#endif /* !__lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
|
@ -47,22 +47,24 @@ __RCSID("$NetBSD: machines.c,v 1.18 2003/10/27 16:51:05 cl Exp $");
|
|||
struct ib_mach machines[] = {
|
||||
{ "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,
|
||||
{ "amd64", i386_setboot, no_clearboot,
|
||||
IB_RESETVIDEO | IB_CONSOLE | IB_CONSPEED |
|
||||
IB_PASSWORD | IB_TIMEOUT },
|
||||
{ "amd64", i386_setboot, no_clearboot,
|
||||
{ "amiga", amiga_setboot, no_clearboot,
|
||||
IB_STAGE1START | IB_STAGE2START | IB_COMMAND },
|
||||
{ "hp300", hp300_setboot, no_clearboot,
|
||||
0 },
|
||||
{ "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 },
|
||||
{ "next68k", next68k_setboot, no_clearboot,
|
||||
0 },
|
||||
{ "newsmips", newsmips_setboot, newsmips_clearboot,
|
||||
IB_STAGE2START },
|
||||
{ "next68k", next68k_setboot, no_clearboot,
|
||||
0 },
|
||||
{ "pmax", pmax_setboot, pmax_clearboot,
|
||||
IB_STAGE1START | IB_APPEND | IB_SUNSUM },
|
||||
{ "shark", no_setboot, no_clearboot, },
|
||||
|
|
Loading…
Reference in New Issue