Remove the unused "hardcode the blocks of /boot" versions /boot and

i386-MD installboot.
They haven't been enabled for a while, keeping them here is just
confusing, and they're still going to be in the CVS repo attic...
This commit is contained in:
lukem 2003-10-08 04:43:28 +00:00
parent 1c33b4e6a4
commit 8ff09e8ecf
18 changed files with 0 additions and 1815 deletions

View File

@ -1,78 +0,0 @@
# $NetBSD: Makefile,v 1.43 2003/04/01 21:25:34 mycroft Exp $
S= ${.CURDIR}/../../../../
BASE?= biosboot
PROG= ${BASE}.sym
NOMAN= # defined
NEWVERSWHAT= "BIOS Boot"
STARTFILE= ${BSSTART}
RELOC= 0x0
.if (${BASE} != "biosboot")
.PATH.c: ${.CURDIR}/../biosboot/
.endif
SRCS= main.c devopen.c conf.c exec.c
CPPFLAGS+= -DSLOW # for libz
CPPFLAGS+= -DCOMPAT_386BSD_MBRPART -DSUPPORT_PS2
.if (${BASE} == "biosboot")
# Various serial line configurations
CPPFLAGS+= -DSUPPORT_SERIAL=CONSDEV_PC -DDIRECT_SERIAL
# or
#CPPFLAGS+= -DSUPPORT_SERIAL=CONSDEV_COM0KBD
# or
#CPPFLAGS+= -DSUPPORT_SERIAL=CONSDEV_AUTO
# and maybe
#CPPFLAGS+= -DDIRECT_SERIAL -DCOMCONS_KEYPRESS -DCONSPEED=57600
.endif
.if (${BASE} == "biosboot_com0")
CPPFLAGS+= -DSUPPORT_SERIAL=CONSDEV_COM0 -DDIRECT_SERIAL
.endif
.if (${BASE} == "biosboot_resetvideo")
CPPFLAGS+= -DRESET_VIDEO
CPPFLAGS+= -DSUPPORT_SERIAL=CONSDEV_PC -DDIRECT_SERIAL
.endif
.if defined(BIOSBOOT_CONSPEED)
BASE:= ${BASE}_${BIOSBOOT_CONSPEED}
CPPFLAGS+= -DCONSPEED=${BIOSBOOT_CONSPEED}
.endif
CPPFLAGS+= -DSUPPORT_USTARFS
#CPPFLAGS+= -DSUPPORT_DOSFS
CPPFLAGS+= -DPASS_BIOSGEOM
CPPFLAGS+= -DPASS_MEMMAP
#CPPFLAGS+= -DBOOTPASSWD
#uncomment if there are problems with memory detection
#CPPFLAGS+= -DCONSERVATIVE_MEMDETECT
#increase MAXFLENTRIES if "installboot" complains about
# "not enough fragment space in bootcode" (default: 20)
#CPPFLAGS+= -DMAXFLENTRIES=30
#set PRIM_LOADSZ to <=9 to make a 720k boot floppy (default: 15)
#CPPFLAGS+= -DPRIM_LOADSZ=9
#CFLAGS= -O2 -fomit-frame-pointer -fno-defer-pop
CFLAGS+= -Wall -Wmissing-prototypes -Wstrict-prototypes -Wno-main
# The biosboot code is linked to 'virtual' address of zero and is
# loaded at physical address 0x10000.
# With these values there is 128kb for code, data and stack.
# XXX The values should be determined from _end.
CPPFLAGS+= -DSTACK_START=0x10000
SAMISCCPPFLAGS+= -DHEAP_START=0x20000 -DHEAP_LIMIT=0x50000
SAMISCMAKEFLAGS+= SA_USE_CREAD=yes # Read compressed kernels
SAMISCMAKEFLAGS+= SA_INCLUDE_NET=no # Netboot via TFTP, NFS
.if (${BASE} == "biosboot")
VERSIONFILE= ${.CURDIR}/version
.else
VERSIONFILE= ${.CURDIR}/../biosboot/version
.endif
.include "../Makefile.booters"

View File

@ -1,66 +0,0 @@
/* $NetBSD: conf.c,v 1.7 2003/04/11 11:36:28 dsl Exp $ */
/*
* Copyright (c) 1997
* Matthias Drochner. All rights reserved.
*
* 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 for the NetBSD Project
* by Matthias Drochner.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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/types.h>
#include <lib/libsa/stand.h>
#include <lib/libsa/ufs.h>
#include <lib/libsa/lfs.h>
#ifdef SUPPORT_USTARFS
#include <lib/libsa/ustarfs.h>
#endif
#ifdef SUPPORT_DOSFS
#include <lib/libsa/dosfs.h>
#endif
#include <biosdisk.h>
struct devsw devsw[] = {
{"disk", biosdiskstrategy, biosdiskopen, biosdiskclose, biosdiskioctl},
};
int ndevs = sizeof(devsw) / sizeof(struct devsw);
struct fs_ops file_system[] = {
#ifdef SUPPORT_USTARFS
FS_OPS(ustarfs),
#endif
FS_OPS(ffsv2),
FS_OPS(ffsv1),
FS_OPS(lfsv1),
FS_OPS(lfsv2),
#ifdef SUPPORT_DOSFS
FS_OPS(dosfs),
#endif
};
int nfsys = sizeof(file_system) / sizeof(struct fs_ops);

View File

@ -1,115 +0,0 @@
/* $NetBSD: devopen.c,v 1.13 2003/04/01 21:10:45 mycroft Exp $ */
/*
* Copyright (c) 1996, 1997
* Matthias Drochner. All rights reserved.
*
* 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 for the NetBSD Project
* by Matthias Drochner.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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/types.h>
#include <lib/libsa/stand.h>
#include <lib/libkern/libkern.h>
#include <libi386.h>
#include <biosdisk.h>
#include "devopen.h"
#ifdef _STANDALONE
#include <bootinfo.h>
#endif
#ifdef SUPPORT_PS2
#include <biosmca.h>
#endif
static __inline int dev2bios __P((char *, unsigned int, int *));
static __inline int
dev2bios(devname, unit, biosdev)
char *devname;
unsigned int unit;
int *biosdev;
{
if (strcmp(devname, "hd") == 0)
*biosdev = 0x80 + unit;
else if (strcmp(devname, "fd") == 0)
*biosdev = 0x00 + unit;
else
return (ENXIO);
return (0);
}
int
bios2dev(int biosdev, char **devname, u_int *unit, u_int sector, u_int *ptnp)
{
if (biosdev & 0x80)
*devname = "hd";
else
*devname = "fd";
*unit = biosdev & 0x7f;
*ptnp = biosdiskfindptn(biosdev, sector);
return 0;
}
#ifdef _STANDALONE
struct btinfo_bootpath bibp;
#endif
/*
* Open the BIOS disk device
*/
int
devopen(f, fname, file)
struct open_file *f;
const char *fname;
char **file;
{
char *fsname, *devname;
unsigned int unit, partition;
int biosdev;
int error;
const struct devsw *dp;
if ((error = parsebootfile(fname, &fsname, &devname,
&unit, &partition, (const char **) file))
|| (error = dev2bios(devname, unit, &biosdev)))
return (error);
dp = &devsw[0]; /* must be biosdisk */
f->f_dev = dp;
#ifdef _STANDALONE
strncpy(bibp.bootpath, *file, sizeof(bibp.bootpath));
BI_ADD(&bibp, BTINFO_BOOTPATH, sizeof(bibp));
#endif
return (biosdiskopen(f, biosdev, partition));
}

View File

@ -1,3 +0,0 @@
/* $NetBSD: devopen.h,v 1.2 2003/02/01 14:48:17 dsl Exp $ */
int bios2dev(int, char **, u_int *, u_int, u_int *);

View File

@ -1,391 +0,0 @@
/* $NetBSD: main.c,v 1.31 2003/05/09 00:16:55 fvdl Exp $ */
/*
* Copyright (c) 1996, 1997, 1999
* Matthias Drochner. All rights reserved.
* Copyright (c) 1996, 1997
* Perry E. Metzger. All rights reserved.
* Copyright (c) 1997
* Jason R. Thorpe. All rights reserved
*
* 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 acknowledgements:
* This product includes software developed for the NetBSD Project
* by Matthias Drochner.
* This product includes software developed for the NetBSD Project
* by Perry E. Metzger.
* 4. The names of the authors may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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/reboot.h>
#include <lib/libsa/stand.h>
#include <lib/libsa/ufs.h>
#include <lib/libkern/libkern.h>
#include <libi386.h>
#include "devopen.h"
#ifdef SUPPORT_PS2
#include <biosmca.h>
#endif
int errno;
extern int boot_biosdev;
extern int boot_biossector; /* may be wrong... */
extern const char bootprog_name[], bootprog_rev[], bootprog_date[],
bootprog_maker[];
static const char * const names[] = {
"netbsd", "netbsd.gz",
"netbsd.old", "netbsd.old.gz",
"onetbsd", "onetbsd.gz",
#ifdef notyet
"netbsd.el", "netbsd.el.gz",
#endif /*notyet*/
};
#define NUMNAMES (sizeof(names)/sizeof(char *))
#define DEFFILENAME names[0]
#define MAXDEVNAME 16
#define TIMEOUT 5
int boottimeout = TIMEOUT; /* patchable */
static char *default_devname;
static int default_unit, default_partition;
static const char *default_filename;
char *sprint_bootsel __P((const char *));
void bootit __P((const char *, int, int));
void print_banner __P((void));
void main __P((void));
void command_help(char *);
void command_ls(char *);
void command_quit(char *);
void command_boot(char *);
void command_dev(char *);
void command_consdev(char *);
const struct bootblk_command commands[] = {
{ "help", command_help },
{ "?", command_help },
{ "ls", command_ls },
{ "quit", command_quit },
{ "boot", command_boot },
{ "dev", command_dev },
#ifdef SUPPORT_SERIAL
{ "consdev", command_consdev },
#endif
{ NULL, NULL },
};
int
parsebootfile(const char *fname, char **fsname, char **devname,
u_int *unit, u_int *partition, const char **file)
{
const char *col;
*fsname = "ufs";
*devname = default_devname;
*unit = default_unit;
*partition = default_partition;
*file = default_filename;
if (fname == NULL)
return(0);
if((col = strchr(fname, ':'))) { /* device given */
static char savedevname[MAXDEVNAME+1];
int devlen;
unsigned int u = 0, p = 0;
int i = 0;
devlen = col - fname;
if (devlen > MAXDEVNAME)
return(EINVAL);
#define isvalidname(c) ((c) >= 'a' && (c) <= 'z')
if (!isvalidname(fname[i]))
return(EINVAL);
do {
savedevname[i] = fname[i];
i++;
} while (isvalidname(fname[i]));
savedevname[i] = '\0';
#define isnum(c) ((c) >= '0' && (c) <= '9')
if (i < devlen) {
if (!isnum(fname[i]))
return(EUNIT);
do {
u *= 10;
u += fname[i++] - '0';
} while (isnum(fname[i]));
}
#define isvalidpart(c) ((c) >= 'a' && (c) <= 'z')
if (i < devlen) {
if (!isvalidpart(fname[i]))
return(EPART);
p = fname[i++] - 'a';
}
if (i != devlen)
return(ENXIO);
*devname = savedevname;
*unit = u;
*partition = p;
fname = col + 1;
}
if (*fname)
*file = fname;
return(0);
}
char *
sprint_bootsel(const char *filename)
{
char *fsname, *devname;
int unit, partition;
const char *file;
static char buf[80];
if (parsebootfile(filename, &fsname, &devname, &unit,
&partition, &file) == 0) {
sprintf(buf, "%s%d%c:%s", devname, unit, 'a' + partition, file);
return(buf);
}
return("(invalid)");
}
void
bootit(const char *filename, int howto, int tell)
{
if (tell) {
printf("booting %s", sprint_bootsel(filename));
if (howto)
printf(" (howto 0x%x)", howto);
printf("\n");
}
if (exec_netbsd(filename, 0, howto) < 0)
printf("boot: %s: %s\n", sprint_bootsel(filename),
strerror(errno));
else
printf("boot returned\n");
}
void
print_banner(void)
{
printf("\n");
printf(">> %s, Revision %s\n", bootprog_name, bootprog_rev);
printf(">> (%s, %s)\n", bootprog_maker, bootprog_date);
printf(">> Memory: %d/%d k\n", getbasemem(), getextmem());
}
/*
* note: normally, void main() wouldn't be legal, but this isn't a
* hosted environment...
*/
void
main(void)
{
int currname;
char c;
#ifdef SUPPORT_SERIAL
initio(SUPPORT_SERIAL);
#else
initio(CONSDEV_PC);
#endif
#ifdef SUPPORT_PS2
biosmca();
#endif
gateA20();
#ifdef RESET_VIDEO
biosvideomode();
#endif
print_banner();
/* try to set default device to what BIOS tells us */
bios2dev(boot_biosdev, &default_devname, &default_unit,
boot_biossector, &default_partition);
/* if the user types "boot" without filename */
default_filename = DEFFILENAME;
printf("Press return to boot now, any other key for boot menu\n");
currname = 0;
for (;;) {
printf("booting %s - starting in ",
sprint_bootsel(names[currname]));
c = awaitkey(boottimeout, 1);
if ((c != '\r') && (c != '\n') && (c != '\0')
#ifdef BOOTPASSWD
&& checkpasswd()
#endif
) {
printf("type \"?\" or \"help\" for help.\n");
bootmenu(); /* does not return */
}
/*
* try pairs of names[] entries, foo and foo.gz
*/
/* don't print "booting..." again */
bootit(names[currname], 0, 0);
/* since it failed, try switching bootfile. */
currname = (currname + 1) % NUMNAMES;
/* now try the second of a pair, presumably the .gz
version. */
/* XXX duped code sucks. */
bootit(names[currname], 0, 1);
/* since it failed, try switching bootfile. */
currname = (currname + 1) % NUMNAMES;
}
}
/* ARGSUSED */
void
command_help(char *arg)
{
printf("commands are:\n"
"boot [xdNx:][filename] [-acdqsv]\n"
" (ex. \"hd0a:netbsd.old -s\"\n"
"ls [path]\n"
"dev xd[N[x]]:\n"
#ifdef SUPPORT_SERIAL
"consdev {pc|com[0123]|com[0123]kbd|auto}\n"
#endif
"help|?\n"
"quit\n");
}
void
command_ls(char *arg)
{
const char *save = default_filename;
default_filename = "/";
ufs_ls(arg);
default_filename = save;
}
/* ARGSUSED */
void
command_quit(char *arg)
{
printf("Exiting...\n");
delay(1000000);
reboot();
/* Note: we shouldn't get to this point! */
panic("Could not reboot!");
exit(0);
}
void
command_boot(char *arg)
{
char *filename;
int howto;
if (parseboot(arg, &filename, &howto))
bootit(filename, howto, 1);
}
void
command_dev(char *arg)
{
static char savedevname[MAXDEVNAME + 1];
char *fsname, *devname;
const char *file; /* dummy */
if (*arg == '\0') {
printf("%s%d%c:\n", default_devname, default_unit,
'a' + default_partition);
return;
}
if (!strchr(arg, ':') ||
parsebootfile(arg, &fsname, &devname, &default_unit,
&default_partition, &file)) {
command_help(NULL);
return;
}
/* put to own static storage */
strncpy(savedevname, devname, MAXDEVNAME + 1);
default_devname = savedevname;
}
#ifdef SUPPORT_SERIAL
static const struct cons_devs {
const char *name;
u_int tag;
} cons_devs[] = {
{ "pc", CONSDEV_PC },
{ "com0", CONSDEV_COM0 },
{ "com1", CONSDEV_COM1 },
{ "com2", CONSDEV_COM2 },
{ "com3", CONSDEV_COM3 },
{ "com0kbd", CONSDEV_COM0KBD },
{ "com1kbd", CONSDEV_COM1KBD },
{ "com2kbd", CONSDEV_COM2KBD },
{ "com3kbd", CONSDEV_COM3KBD },
{ "auto", CONSDEV_AUTO },
{ 0, 0 } };
void
command_consdev(char *arg)
{
const struct cons_devs *cdp;
for (cdp = cons_devs; cdp->name; cdp++) {
if (!strcmp(arg, cdp->name)) {
initio(cdp->tag);
print_banner();
return;
}
}
printf("invalid console device.\n");
}
#endif

View File

@ -1,32 +0,0 @@
$NetBSD: version,v 1.16 2003/02/01 14:48:17 dsl Exp $
NOTE ANY CHANGES YOU MAKE TO THE BOOTBLOCKS HERE. The format of this
file is important - make sure the entries are appended on end, last item
is taken as the current.
2.0: Change over to Matthias Drochner's two-stage boot system.
All code is completely new.
2.1: New welcoming banner.
2.2: Use common menu / parsing functions with other bootloaders.
New framework to pass information to the kernel.
2.3: Switch to new NetBSD MBR partition ID.
2.4: Support BIOS Int13-Extensions.
2.5: Support ustarfs boot.
2.6: Support ELF boot.
2.7: Support on-the-fly switching of console devices.
2.8: Support verbose/quiet boot.
2.9: Recognize PS/2 L40 at runtime and use appropriate gate A20
initialization (rather than using a compile flag).
Recognize ESDI disks and identify them as ed(4) for COMPAT_OLDBOOT.
2.10: g/c COMPAT_OLDBOOT
2.11: loadfile() update: ELF symbols no longer need backward seeks.
2.12: loadfile() update to avoid backwards seeks for ELF Program Headers.
2.13: Support boot from 1.44MB floppies in 2.88MB floppy drives.
2.14: Add a quirk for BIOSes which report extended memory size
in slightly nonstandard way in int15, function 0xE801
2.15: Use int15/0xc7 to get memory information on machines which support
it, like later IBM PS/2 machines
2.16: Move 16bit %ss to allow >64k for code, data and stack
Default partition to that passed in by mbr code
Support limited filename globbing in 'ls' command
Use .code16 and .code32 directives

View File

@ -1,5 +0,0 @@
# $NetBSD: Makefile,v 1.1 1999/07/11 01:23:53 kim Exp $
BASE= biosboot_com0
.include "../biosboot/Makefile"

View File

@ -1,6 +0,0 @@
# $NetBSD: Makefile,v 1.1 2003/01/14 23:53:31 thorpej Exp $
BASE= biosboot_com0
BIOSBOOT_CONSPEED=115200
.include "../biosboot/Makefile"

View File

@ -1,6 +0,0 @@
# $NetBSD: Makefile,v 1.1 2003/01/14 23:53:31 thorpej Exp $
BASE= biosboot_com0
BIOSBOOT_CONSPEED=38400
.include "../biosboot/Makefile"

View File

@ -1,6 +0,0 @@
# $NetBSD: Makefile,v 1.1 2003/01/14 23:53:32 thorpej Exp $
BASE= biosboot_com0
BIOSBOOT_CONSPEED=57600
.include "../biosboot/Makefile"

View File

@ -1,6 +0,0 @@
# $NetBSD: Makefile,v 1.1 2003/01/14 23:53:32 thorpej Exp $
BASE= biosboot_com0
BIOSBOOT_CONSPEED=9600
.include "../biosboot/Makefile"

View File

@ -1,5 +0,0 @@
# $NetBSD: Makefile,v 1.1 2000/04/23 19:57:14 tsarna Exp $
BASE= biosboot_resetvideo
.include "../biosboot/Makefile"

View File

@ -1,43 +0,0 @@
# $NetBSD: Makefile,v 1.10 2003/02/02 21:05:15 dsl Exp $
S= ${.CURDIR}/../../../../
BASE= biosboot_ser
PROG= ${BASE}.sym
NOMAN= # defined
NEWVERSWHAT= "BIOS Boot"
STARTFILE= ${BSSTART}
RELOC= 0x0
.PATH: ${.CURDIR}/../biosboot/
SRCS= main.c devopen.c conf.c exec.c
CPPFLAGS+= -DCOMPAT_386BSD_MBRPART -DDEBUG
#Sample use of serial line debugger
#CPPFLAGS+= -DSUPPORT_SERIAL=CONSDEV_COM0KBD
# or
CPPFLAGS+= -DSUPPORT_SERIAL=CONSDEV_AUTO -DDIRECT_SERIAL
# and maybe
#CPPFLAGS+= -DDIRECT_SERIAL -DCOMCONS_KEYPRESS -DCONSPEED=57600
CPPFLAGS+= -DPASS_BIOSGEOM
CPPFLAGS+= -DPASS_MEMMAP
#uncomment if there are problems with memory detection
#CPPFLAGS+= -DCONSERVATIVE_MEMDETECT
#increase MAXFLENTRIES if "installboot" complains about
# "not enough fragment space in bootcode" (default: 20)
#CPPFLAGS+= -DMAXFLENTRIES=30
#set PRIM_LOADSZ to <=9 to make a 720k boot floppy (default: 15)
#CPPFLAGS+= -DPRIM_LOADSZ=9
#CFLAGS= -O2 -fomit-frame-pointer -fno-defer-pop
CFLAGS+= -Wall -Wmissing-prototypes -Wstrict-prototypes -Wno-main
SAMISCCPPFLAGS+= -DHEAP_START=0x10000 -DHEAP_LIMIT=0x40000
SAMISCMAKEFLAGS= SA_USE_CREAD=yes # Read compressed kernels
SAMISCMAKEFLAGS= SA_INCLUDE_NET=no # Support netboot
VERSIONFILE= ${.CURDIR}/../biosboot/version
.include "../Makefile.booters"

View File

@ -1,34 +0,0 @@
# $NetBSD: Makefile,v 1.26 2003/05/09 00:11:26 fvdl Exp $
NOMAN= # defined
# XXX: bsd.own.mk included so LDSTATIC can be overwridden
.include <bsd.own.mk>
PROG= installboot
LIBSA=${.CURDIR}/../../../../lib/libsa
.PATH.c: ${LIBSA}
SRCS= installboot.c bootblks.c getmount.c byteorder.c loadfile.c \
loadfile_aout.c loadfile_elf32.c
.if ${MACHINE_ARCH} == "x86_64"
SRCS+= loadfile_elf64.c
.endif
CPPFLAGS+= -I${.CURDIR}/../lib/crt/bootsect
CPPFLAGS+= -I${LIBSA} -I.
CFLAGS+= -Wall -Wmissing-prototypes -Wstrict-prototypes
LDSTATIC=-static
.BEGIN: machine
.NOPATH: machine
${SRCS} realdepend realall: machine
CLEANFILES+= machine
machine::
-rm -f $@
ln -s ${.CURDIR}/../../../${MACHINE}/include $@
.include <bsd.prog.mk>

View File

@ -1,147 +0,0 @@
/* $NetBSD: bootblks.c,v 1.4 1999/09/10 16:41:10 drochner Exp $ */
/*
* Copyright (c) 1996
* Matthias Drochner. All rights reserved.
*
* 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 for the NetBSD Project
* by Matthias Drochner.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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/stat.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <err.h>
#include "installboot.h"
static char bootblkpath[MAXPATHLEN];
static char backuppath[MAXPATHLEN];
static char backupext[] = ".bak";
static int havebackup;
ino_t
createfileondev(diskdev, bootblkname, bp, size)
char *diskdev, *bootblkname;
char *bp;
unsigned int size;
{
char *mntpoint;
int fd = -1;
struct stat statbuf;
int allok = 0;
if ((mntpoint = getmountpoint(diskdev)) == NULL)
return ((ino_t) - 1);
/*
* create file in fs root for bootloader data
* try to rename existing file before
*/
havebackup = 0;
(void) sprintf(bootblkpath, "%s/%s", mntpoint, bootblkname);
(void) sprintf(backuppath, "%s%s", bootblkpath, backupext);
if (rename(bootblkpath, backuppath) == -1) {
if (errno != ENOENT) {
warn("rename old %s", bootblkpath);
goto out;
}
} else {
if (verbose)
(void) fprintf(stderr, "renamed %s -> %s\n",
bootblkpath, backuppath);
havebackup = 1;
}
fd = open(bootblkpath, O_RDWR | O_CREAT | O_EXCL, 0400);
if (fd < 0) {
warn("open %s", bootblkpath);
goto out;
}
/*
* do the write, flush, get inode number
*/
if (write(fd, bp, size) < 0) {
warn("write %s", bootblkpath);
goto out;
}
if (fsync(fd) != 0) {
warn("fsync: %s", bootblkpath);
goto out;
}
if (fstat(fd, &statbuf) != 0) {
warn("fstat: %s", bootblkpath);
goto out;
}
allok = 1;
out:
if (fd != -1) {
(void) close(fd);
if (!allok)
(void) unlink(bootblkpath);
}
if (!allok && havebackup)
(void) rename(backuppath, bootblkpath);
cleanupmount(mntpoint);
return (allok ? statbuf.st_ino : (ino_t) - 1);
}
void
cleanupfileondev(diskdev, bootblkname, recover)
char *diskdev, *bootblkname;
int recover;
{
char *mntpoint;
/* save some work if nothing to do */
if (!(recover || havebackup))
return;
if ((mntpoint = getmountpoint(diskdev)) == NULL)
return;
(void) sprintf(bootblkpath, "%s/%s", mntpoint, bootblkname);
(void) sprintf(backuppath, "%s%s", bootblkpath, backupext);
if (recover) {
(void) unlink(bootblkpath);
if (havebackup) {
(void) fprintf(stderr, "renaming %s -> %s\n",
backuppath, bootblkpath);
(void) rename(backuppath, bootblkpath);
}
} else if (havebackup) {
if (verbose)
(void) fprintf(stderr, "deleting %s\n", backuppath);
(void) unlink(backuppath);
}
cleanupmount(mntpoint);
}

View File

@ -1,157 +0,0 @@
/* $NetBSD: getmount.c,v 1.6 2001/07/07 22:57:57 perry Exp $ */
/*
* Copyright (c) 1996
* Matthias Drochner. All rights reserved.
*
* 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 for the NetBSD Project
* by Matthias Drochner.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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/ufsmount.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <err.h>
#include "installboot.h"
static int tempmounted = 0;
static char *getbdev __P((char *));
static char *dotempmount __P((char *));
/* make block device name from character device name */
static char *
getbdev(dev)
char *dev;
{
static char bdiskdev[MAXPATHLEN];
if (strncmp(dev, "/dev/r", 6)) {
warnx("bad device name %s", dev);
return (0);
}
(void) sprintf(bdiskdev, "/dev/%s", dev + 6);
return (bdiskdev);
}
/*
* create mountpoint and mount given block device there, return
* mountpoint
*/
static char *
dotempmount(bdiskdev)
char *bdiskdev;
{
static char dirtmpl[] = "/tmp/installbootXXXXXX";
char *dir;
struct ufs_args data;
if ((dir = mkdtemp(dirtmpl)) == NULL) {
warnx("mkdtemp failed");
return (0);
}
memset(&data, 0, sizeof(data));
data.fspec = bdiskdev;
/* this code if FFS only */
if (mount(MOUNT_FFS, dir, 0, &data) == -1) {
warn("mount %s->%s failed", bdiskdev, dir);
(void) rmdir(dir);
return (0);
}
if (verbose)
(void) fprintf(stderr, "mounted %s at %s\n", bdiskdev, dir);
tempmounted = 1;
return (dir);
}
/*
* Find out if given character device is already mounted. If not, mount it
* temporarily.
*/
char *
getmountpoint(diskdev)
char *diskdev;
{
char *bdiskdev;
struct statfs *buf;
int num, i;
bdiskdev = getbdev(diskdev);
if (bdiskdev == NULL)
return (0);
num = getmntinfo(&buf, MNT_WAIT);
if (num == 0) {
warn("getmntinfo");
return (0);
}
for (i = 0; i < num; i++)
if (strncmp(bdiskdev, buf[i].f_mntfromname, MNAMELEN) == 0) {
int j;
/* Device is mounted. If there are more devices mounted
at the same point, the fs could be hidden. Don't think
too much about layering order - simply refuse. */
for (j = 0; j < num; j++)
if ((i != j) && (strncmp(buf[i].f_mntonname,
buf[j].f_mntonname,
MNAMELEN) == 0)) {
warnx("there is more than 1 mount at %s",
buf[i].f_mntonname);
return (0);
}
/* this code is FFS only */
if (strncmp(buf[i].f_fstypename, MOUNT_FFS, MFSNAMELEN)) {
warnx("%s: must be a FFS filesystem", bdiskdev);
return (0);
}
return (buf[i].f_mntonname);
}
if (verbose)
(void) fprintf(stderr, "%s is not mounted\n", bdiskdev);
return (dotempmount(bdiskdev));
}
void
cleanupmount(dir)
char *dir;
{
if (tempmounted) {
if (verbose)
(void) fprintf(stderr, "unmounting\n");
(void) unmount(dir, 0);
(void) rmdir(dir);
tempmounted = 0;
}
}

View File

@ -1,706 +0,0 @@
/* $NetBSD: installboot.c,v 1.18 2003/04/02 10:39:32 fvdl Exp $ */
/*
* Copyright (c) 1994 Paul Kranenburg
* All rights reserved.
* Copyright (c) 1996, 1997
* Matthias Drochner. All rights reserved.
* Copyright (c) 1996, 1997
* Perry E. Metzger. All rights reserved.
*
* 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 Paul Kranenburg.
* This product includes software developed for the NetBSD Project
* by Matthias Drochner.
* This product includes software developed for the NetBSD Project
* by Perry E. Metzger.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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/disklabel.h>
#include <sys/dkio.h>
#include <ufs/ufs/dinode.h>
#include <ufs/ufs/dir.h>
#include <ufs/ffs/fs.h>
#include <err.h>
#include <a.out.h>
#include <errno.h>
#include <fcntl.h>
#include <nlist.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <md5.h>
#include <sys/ioctl.h>
#include "loadfile.h"
#include "installboot.h"
#include "bbinfo.h"
#define DEFBBLKNAME "boot"
char *loadprotoblocks __P((char *, size_t *));
static int devread __P((int, void *, daddr_t, size_t, char *));
static int add_fsblk __P((struct fs *, daddr_t, int));
int setup_ffs_blks __P((char *, ino_t));
int setup_contig_blocks __P((char *, int, char *, unsigned int));
int save_contig_sec_boot __P((char *, int, char *, unsigned int));
ino_t save_ffs __P((char *, char *, char *, unsigned int));
ino_t save_passthru __P((char *, char *, char *, unsigned int));
static void usage __P((void));
int main __P((int, char **));
struct ofraglist *ofraglist;
struct fraglist *fraglist;
struct nlist nl[] = {
#define X_fraglist 0
#define X_boottimeout 1
#define X_bootpasswd 2
#define X_fraglist64 3
#ifdef __ELF__
{{"fraglist"}},
{{"boottimeout"}},
{{"bootpasswd"}},
{{"fraglist64"}},
#else
{{"_fraglist"}},
{{"_boottimeout"}},
{{"_bootpasswd"}},
{{"_fraglist64"}},
#endif
{{NULL}}
};
int verbose = 0;
int conblockmode, conblockstart;
char *
loadprotoblocks(fname, size)
char *fname;
size_t *size;
{
int fd;
u_long marks[MARK_MAX], bp, value;
int maxentries;
fd = -1;
/* Locate block number array in proto file */
if (nlist(fname, nl) < 0) {
warn("nlist: %s", fname);
return NULL;
}
if (nl[X_fraglist].n_value == 0 &&
nl[X_fraglist64].n_value == 0) {
/* fraglist is mandatory, other stuff is optional */
warnx("nlist: no fraglist");
return NULL;
}
marks[MARK_START] = 0;
if ((fd = loadfile(fname, marks, COUNT_TEXT|COUNT_DATA)) == -1)
return NULL;
(void)close(fd);
*size = roundup(marks[MARK_END], DEV_BSIZE);
bp = marks[MARK_START] = (u_long)malloc(*size);
if ((fd = loadfile(fname, marks, LOAD_TEXT|LOAD_DATA)) == -1)
return NULL;
(void)close(fd);
if (nl[X_fraglist64].n_value != 0) {
/* NOSTRICT */
value = nl[X_fraglist64].n_value;
fraglist = (struct fraglist *)(bp + value);
if (fraglist->magic != FRAGLISTMAGIC) {
warnx("invalid bootblock version");
goto bad;
}
maxentries = fraglist->maxentries;
} else {
/* NOSTRICT */
value = nl[X_fraglist].n_value;
ofraglist = (struct ofraglist *) (bp + value);
if (ofraglist->magic != OFRAGLISTMAGIC) {
warnx("invalid bootblock version");
goto bad;
}
maxentries = ofraglist->maxentries;
}
if (verbose) {
(void) fprintf(stderr, "%s: entry point %#lx\n", fname,
marks[MARK_ENTRY]);
(void) fprintf(stderr, "proto bootblock size %ld\n",
(long)*size);
(void) fprintf(stderr, "room for %d filesystem blocks"
" at %#lx\n", maxentries, value);
}
return (char *) bp;
bad:
if (bp)
free((void *)bp);
return NULL;
}
static int
devread(fd, buf, blk, size, msg)
int fd;
void *buf;
daddr_t blk;
size_t size;
char *msg;
{
if (lseek(fd, (off_t)dbtob(blk), SEEK_SET) != dbtob(blk)) {
warn("%s: devread: lseek", msg);
return (1);
}
if (read(fd, buf, size) != size) {
warn("%s: devread: read", msg);
return (1);
}
return (0);
}
/* add file system blocks to fraglist */
static int
add_fsblk(fs, blk, blcnt)
struct fs *fs;
daddr_t blk;
int blcnt;
{
int nblk;
/* convert to disk blocks */
blk = fsbtodb(fs, blk);
nblk = fs->fs_bsize / DEV_BSIZE;
if (nblk > blcnt)
nblk = blcnt;
if (verbose)
(void) fprintf(stderr, "dblk: %lld, num: %lld\n",
(long long)blk, (long long)nblk);
/*
* Can only handle 32 bits worth in the old format.
*/
if (fraglist == NULL && blk > 0xffffffff)
errx(1, "block %lld out of range", (long long)blk);
if (fraglist != NULL) {
/* start new entry or append to previous? */
if (!fraglist->numentries ||
(fraglist->entries[fraglist->numentries - 1].offset
+ fraglist->entries[fraglist->numentries - 1].num != blk)){
/* need new entry */
if (fraglist->numentries > fraglist->maxentries - 1) {
errx(1, "not enough fragment space in bootcode");
return (-1);
}
fraglist->entries[fraglist->numentries].offset = blk;
fraglist->entries[fraglist->numentries++].num = 0;
}
fraglist->entries[fraglist->numentries - 1].num += nblk;
} else {
/* start new entry or append to previous? */
if (!ofraglist->numentries ||
(ofraglist->entries[ofraglist->numentries - 1].offset
+ofraglist->entries[ofraglist->numentries - 1].num != blk)){
/* need new entry */
if (ofraglist->numentries > ofraglist->maxentries - 1) {
errx(1, "not enough fragment space in bootcode");
return (-1);
}
ofraglist->entries[ofraglist->numentries].offset = blk;
ofraglist->entries[ofraglist->numentries++].num = 0;
}
ofraglist->entries[ofraglist->numentries - 1].num += nblk;
}
return (blcnt - nblk);
}
static union {
char c[SBLOCKSIZE];
struct fs s;
} sblock;
const daddr_t sblock_try[] = SBLOCKSEARCH;
int
setup_ffs_blks(diskdev, inode)
char *diskdev;
ino_t inode;
{
int devfd = -1;
struct fs *fs;
char *buf = 0;
daddr_t blk;
int32_t *ap32;
int64_t *ap64;
struct ufs1_dinode *ip1;
struct ufs2_dinode *ip2;
int i, ndb;
int allok = 0, is_ufs2 = 0;
fs = NULL;
ip1 = NULL;
ip2 = NULL;
devfd = open(diskdev, O_RDONLY, 0);
if (devfd < 0) {
warn("open raw partition");
return (1);
}
/* Read superblock */
for (i = 0; sblock_try[i] != -1; i++) {
if (devread(devfd, &sblock, sblock_try[i] / DEV_BSIZE,
SBLOCKSIZE, "superblock"))
continue;
fs = &sblock.s;
if (fs->fs_magic == FS_UFS1_MAGIC)
break;
if (fs->fs_magic == FS_UFS2_MAGIC) {
is_ufs2 = 1;
break;
}
}
if (sblock_try[i] == -1) {
warnx("invalid super block");
goto out;
}
/* Read inode */
if ((buf = malloc((size_t)fs->fs_bsize)) == NULL) {
warnx("No memory for filesystem block");
goto out;
}
blk = fsbtodb(fs, ino_to_fsba(fs, inode));
if (devread(devfd, buf, blk, (size_t)fs->fs_bsize, "inode"))
goto out;
if (is_ufs2) {
ip2 = (struct ufs2_dinode *)buf + ino_to_fsbo(fs, inode);
ndb = (int)(ip2->di_size / DEV_BSIZE); /* size is rounded! */
} else {
ip1 = (struct ufs1_dinode *)buf + ino_to_fsbo(fs, inode);
ndb = (int)(ip1->di_size / DEV_BSIZE); /* size is rounded! */
}
/*
* Have the inode. Figure out how many blocks we need.
*/
if (verbose)
(void) fprintf(stderr, "Will load %d blocks.\n", ndb);
if (is_ufs2) {
/*
* Get the block numbers, first direct blocks
*/
ap64 = ip2->di_db;
for (i = 0; i < NDADDR && *ap64 && ndb > 0; i++, ap64++)
ndb = add_fsblk(fs, *ap64, ndb);
if (ndb > 0) {
/*
* Just one level of indirections; there isn't much room
* for more in the 1st-level bootblocks anyway.
*/
blk = fsbtodb(fs, ip2->di_ib[0]);
if (devread(devfd, buf, blk, (size_t)fs->fs_bsize,
"indirect block"))
goto out;
ap64 = (int64_t *) buf;
for (; i < NINDIR(fs) && *ap64 && ndb > 0; i++, ap64++){
ndb = add_fsblk(fs, *ap64, ndb);
}
}
} else {
/*
* Get the block numbers, first direct blocks
*/
ap32 = ip1->di_db;
for (i = 0; i < NDADDR && *ap32 && ndb > 0; i++, ap32++)
ndb = add_fsblk(fs, *ap32, ndb);
if (ndb > 0) {
/*
* Just one level of indirections; there isn't much room
* for more in the 1st-level bootblocks anyway.
*/
blk = fsbtodb(fs, ip1->di_ib[0]);
if (devread(devfd, buf, blk, (size_t)fs->fs_bsize,
"indirect block"))
goto out;
ap32 = (int32_t *) buf;
for (; i < NINDIR(fs) && *ap32 && ndb > 0; i++, ap32++){
ndb = add_fsblk(fs, *ap32, ndb);
}
}
}
if (!ndb)
allok = 1;
else {
if (ndb > 0)
warnx("too many fs blocks");
/* else, ie ndb < 0, add_fsblk returned error */
goto out;
}
out:
if (buf)
free(buf);
if (devfd >= 0)
(void) close(devfd);
return (!allok);
}
ino_t
save_ffs(diskdev, bootblkname, bp, size)
char *diskdev, *bootblkname, *bp;
unsigned int size;
{
ino_t inode = -2;
int loadsz;
loadsz = fraglist != NULL ? fraglist->loadsz : ofraglist->loadsz;
/* do we need the fraglist? */
if (size > loadsz * DEV_BSIZE) {
inode = createfileondev(diskdev, bootblkname, bp, size);
if (inode == (ino_t)-1)
return inode;
/* paranoia */
sync();
(void) sleep(3);
if (setup_ffs_blks(diskdev, inode))
return (ino_t)(-1);
}
return inode;
}
int
setup_contig_blocks(diskdev, blkno, bp, size)
char *diskdev, *bp;
int blkno;
unsigned int size;
{
int i, ndb, rdb, db;
int tableblksize = 8;
int maxentries;
ndb = howmany(size, tableblksize * DEV_BSIZE);
rdb = howmany(size, DEV_BSIZE);
maxentries = fraglist != NULL ? fraglist->maxentries :
ofraglist->maxentries;
if (verbose)
printf("%s: block number %d, size %u table blocks: %d/%d\n",
diskdev, blkno, size, ndb, maxentries);
if (ndb > maxentries) {
errx(1, "not enough fragment space in bootcode");
return (-1);
}
if (verbose)
printf("%s: block numbers:", diskdev);
for (i = 0; i < ndb; i++) {
db = tableblksize;
if (rdb < tableblksize)
db = rdb;
rdb -= tableblksize;
if (fraglist != NULL) {
fraglist->numentries = i+1;
fraglist->entries[i].offset = blkno;
fraglist->entries[i].num = db;
} else {
ofraglist->numentries = i+1;
ofraglist->entries[i].offset = blkno;
ofraglist->entries[i].num = db;
}
if (verbose)
printf(" %d", blkno);
blkno += tableblksize;
}
if (verbose)
printf("\n");
return 0;
}
int
save_contig_sec_boot(diskdev, off, bp, size)
char *diskdev, *bp;
unsigned int size;
int off;
{
int fd;
fd = open(diskdev, O_RDWR, 0444);
if (fd < 0) {
warn("open %s", diskdev);
return (-1);
}
if (lseek(fd, (off_t)off, SEEK_SET) == (off_t)-1) {
warn("lseek %s", diskdev);
return (-1);
}
if (write(fd, bp, size) < 0) {
warn("write %s", diskdev);
return (-1);
}
if (fsync(fd) != 0) {
warn("fsync: %s", diskdev);
return -1;
}
(void) close(fd);
return 0;
}
ino_t
save_passthru(diskdev, bootblkname, bp, size)
char *diskdev, *bootblkname, *bp;
unsigned int size;
{
if (save_contig_sec_boot(diskdev,
conblockstart * DEV_BSIZE,
bp, size) != 0)
return (ino_t)(-1);
if (setup_contig_blocks(diskdev, conblockstart, bp, size) != 0)
return (ino_t)(-1);
return (ino_t)(-2);
}
static void
usage()
{
(void) fprintf(stderr,
"usage: installboot [-b bno] [-n] [-v] [-f] <boot> <device>\n");
exit(1);
}
int
main(argc, argv)
int argc;
char *argv[];
{
int c;
char *bp = 0;
size_t size;
ino_t inode = (ino_t) -1;
int devfd = -1;
struct disklabel dl;
int bsdoffs;
int i, res;
int forceifnolabel = 0;
char *bootblkname = DEFBBLKNAME;
int nowrite = 0;
int allok = 0;
int timeout = -1;
char *bootpasswd = 0;
ino_t (*save_func) __P((char *, char *, char *, unsigned int));
int loadsz;
while ((c = getopt(argc, argv, "b:vnft:p:")) != -1) {
switch (c) {
case 'b':
/* generic override, supply starting block # */
conblockmode = 1;
conblockstart = atoi(optarg);
break;
case 't':
/* boot timeout */
timeout = atoi(optarg);
break;
case 'p':
/* boot password */
bootpasswd = optarg;
break;
case 'n':
/* Do not actually write the bootblock to disk */
nowrite = 1;
break;
case 'v':
/* Chat */
verbose = 1;
break;
case 'f':
/* assume zero offset if no disklabel */
forceifnolabel = 1;
break;
default:
usage();
}
}
if (argc - optind != 2) {
usage();
}
bp = loadprotoblocks(argv[optind], &size);
if (!bp)
errx(1, "error reading bootblocks");
if (timeout >= 0) {
if (nl[X_boottimeout].n_value != 0)
*((int *)(bp + nl[X_boottimeout].n_value)) = timeout;
else {
warnx("no timeout support in bootblock");
goto out;
}
}
if (bootpasswd) {
if (nl[X_bootpasswd].n_value != 0) {
MD5_CTX md5ctx;
MD5Init(&md5ctx);
MD5Update(&md5ctx, bootpasswd, strlen(bootpasswd));
MD5Final(bp + nl[X_bootpasswd].n_value, &md5ctx);
} else {
warnx("no password support in bootblock");
goto out;
}
}
if (fraglist != NULL) {
fraglist->numentries = 0;
loadsz = fraglist->loadsz;
} else {
ofraglist->numentries = 0;
loadsz = ofraglist->loadsz;
}
if (conblockmode)
save_func = save_passthru;
else
save_func = save_ffs;
if ((inode = (*save_func)(argv[optind + 1],
bootblkname,
bp + loadsz * DEV_BSIZE,
size - loadsz * DEV_BSIZE))
== (ino_t)-1)
goto out;
size = loadsz * DEV_BSIZE;
/* size to be written to bootsect */
devfd = open(argv[optind + 1], O_RDWR, 0);
if (devfd < 0) {
warn("open raw partition RW");
goto out;
}
if (ioctl(devfd, DIOCGDINFO, &dl) < 0) {
if ((errno == EINVAL) || (errno == ENOTTY)) {
if (forceifnolabel)
bsdoffs = 0;
else {
warnx("no disklabel, use -f to install anyway");
goto out;
}
} else {
warn("get disklabel");
goto out;
}
} else {
char p = argv[optind + 1][strlen(argv[optind + 1]) - 1];
#define isvalidpart(c) ((c) >= 'a' && (c) <= 'z')
if (!isvalidpart(p) || (p - 'a') >= dl.d_npartitions) {
warnx("invalid partition");
goto out;
}
bsdoffs = dl.d_partitions[p - 'a'].p_offset;
}
if (verbose)
(void) fprintf(stderr, "BSD partition starts at sector %d\n",
bsdoffs);
/*
* add offset of BSD partition to fraglist entries
*/
if (fraglist != NULL) {
for (i = 0; i < fraglist->numentries; i++)
fraglist->entries[i].offset += bsdoffs;
} else {
for (i = 0; i < ofraglist->numentries; i++)
ofraglist->entries[i].offset += bsdoffs;
}
if (!nowrite) {
/*
* write first blocks (max loadsz) to start of BSD partition,
* skip disklabel (in second disk block)
*/
(void) lseek(devfd, (off_t)0, SEEK_SET);
res = write(devfd, bp, DEV_BSIZE);
if (res < 0) {
warn("final write1");
goto out;
}
(void) lseek(devfd, (off_t)(2 * DEV_BSIZE), SEEK_SET);
res = write(devfd, bp + 2 * DEV_BSIZE, size - 2 * DEV_BSIZE);
if (res < 0) {
warn("final write2");
goto out;
}
}
allok = 1;
out:
if (devfd >= 0)
(void) close(devfd);
if (bp)
free(bp);
if (inode != (ino_t)-1 && /* failed? */
inode != (ino_t)-2 && /* small boot, no FS blocks? */
!conblockmode) { /* contiguous blocks? */
cleanupfileondev(argv[optind + 1], bootblkname, !allok || nowrite);
}
return (!allok);
}

View File

@ -1,9 +0,0 @@
/* $NetBSD: installboot.h,v 1.4 1998/07/28 20:10:54 drochner Exp $ */
ino_t createfileondev __P((char *, char *, char *, unsigned int));
void cleanupfileondev __P((char *, char *, int));
char *getmountpoint __P((char *));
void cleanupmount __P((char *));
extern int verbose;