Boot program to help load tape kernels.

(You can even choose a tape segment!)
This commit is contained in:
gwr 1995-10-13 21:27:30 +00:00
parent 3b4d7bd966
commit c890f5c659
6 changed files with 356 additions and 0 deletions

View File

@ -0,0 +1,13 @@
# $NetBSD: Makefile,v 1.1.1.1 1995/10/13 21:27:30 gwr Exp $
SA_PROG= tapeboot
SRCS= boot.c conf.c dev_tape.c version.c
all: ${SA_PROG}.bin
.include <bsd.prog.mk>
install: ${SA_PROG}.bin
install ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
${SA_PROG}.bin ${DESTDIR}${MDEC_DIR}/${SA_PROG}

View File

@ -0,0 +1,166 @@
/* $NetBSD: boot.c,v 1.1.1.1 1995/10/13 21:27:30 gwr Exp $ */
/*
* Copyright (c) 1994 Paul Kranenburg
* 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.
* 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.
*/
/*
* This is a generic "first-stage" boot program.
*
* Note that this program has absolutely no filesystem knowledge!
*
* Instead, this uses a table of disk block numbers that are
* filled in by the installboot program such that this program
* can load the "second-stage" boot program.
*/
#include <sys/param.h>
#include <sys/reboot.h>
#include <sys/exec.h>
#include <machine/mon.h>
#include "stand.h"
#include "promboot.h"
/*
* Boot device is derived from ROM provided information.
*/
#define LOADADDR 0x4000
extern int debug;
extern char *version;
char line[80];
int block_size = 512;
main()
{
struct open_file f;
struct bootparam *bp;
void (*entry)();
char *addr;
int n, error;
printf(">> NetBSD tapeboot [%s]\n", version);
prom_get_boot_info();
/*
* Set the tape file number to the next one, because
* the boot program is first, then the kernel.
*/
bp = *romp->bootParam;
bp->partNum += 1;
for (;;) {
if (prom_boothow & RB_ASKNAME) {
printf("tapeboot: segment? [%d] ", bp->partNum);
gets(line);
if (('0' <= line[0]) && (line[0] <= '9')) {
bp->partNum = line[0] - '0';
}
}
printf("tapeboot: opening segment %d\n", bp->partNum);
f.f_flags = F_RAW;
if ((error = devopen(&f, 0, &addr)) != 0) {
printf("tapeboot: open failed, error=%d\n", error);
goto ask;
}
addr = (char*)LOADADDR;
error = loadfile(&f, addr);
printf("tapeboot: close (rewind)...\n");
f.f_dev->dv_close(&f);
if (error == 0)
break;
printf("tapeboot: load failed, error=%d\n", error);
ask:
prom_boothow |= RB_ASKNAME;
}
if (debug) {
printf("Debug mode - enter c to continue...");
/* This will print "\nAbort at ...\n" */
asm(" trap #0");
}
printf("Starting program at 0x%x\n", (long)addr);
entry = (void (*)())addr;
(*entry)();
}
int
loadfile(fp, addr)
struct open_file *fp;
char *addr;
{
char *buf;
int n, blknum;
int error = 0;
/*
* Loading a kernel. It WILL have an a.out header.
* XXX - This assumes OMAGIC format!
*/
addr -= sizeof(struct exec); /* XXX */
/* Need to use a buffer that can be mapped into DVMA space. */
buf = alloc(block_size);
if (!buf)
panic("tapeboot: alloc failed");
printf("tapeboot: loading ... ");
/* limit program size to < 2MB */
for (blknum = 0; blknum < 4096; blknum++) {
error = (fp->f_dev->dv_strategy)(fp->f_devdata, F_READ,
blknum, block_size, buf, &n);
if (error) {
printf("(error=%d)\n", error);
return EIO;
}
if (n == 0)
break; /* end of tape */
if (n != block_size) {
printf(" (short read)\n");
return EIO;
}
bcopy(buf, addr, block_size);
addr += block_size;
}
printf("(%d blocks)\n", blknum);
return 0;
}

View File

@ -0,0 +1,11 @@
/* $NetBSD: conf.c,v 1.1.1.1 1995/10/13 21:27:30 gwr Exp $ */
#include <stand.h>
#include <dev_tape.h>
struct devsw devsw[] = {
{ "tape", tape_strategy, tape_open, tape_close, tape_ioctl },
};
int ndevs = 1;
int debug;

View File

@ -0,0 +1,150 @@
/* $NetBSD: dev_tape.c,v 1.1.1.1 1995/10/13 21:27:30 gwr Exp $ */
/*
* Copyright (c) 1993 Paul Kranenburg
* 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.
* 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.
*/
/*
* This module implements a "raw device" interface suitable for
* use by the stand-alone I/O library UFS file-system code, and
* possibly for direct access (i.e. boot from tape).
*
* The implementation is deceptively simple because it uses the
* drivers provided by the Sun PROM monitor. Note that only the
* PROM driver used to load the boot program is available here.
*/
#include <sys/types.h>
#include <machine/mon.h>
#include <machine/saio.h>
#include "stand.h"
#include "dvma.h"
#include "promdev.h"
/* #include "dev_tape.h" XXX - needs stdarg.h */
struct saioreq tape_ioreq;
int
tape_open(f, devname)
struct open_file *f;
char *devname; /* Device part of file name (or NULL). */
{
struct bootparam *bp;
struct saioreq *si;
int error;
#ifdef DEBUG_PROM
printf("tape_open: %s\n", devname);
#endif
/*
* Setup our part of the saioreq.
* (determines what gets opened)
*/
si = &tape_ioreq;
bzero((caddr_t)si, sizeof(*si));
bp = *romp->bootParam;
si->si_boottab = bp->bootDevice;
si->si_ctlr = bp->ctlrNum;
si->si_unit = bp->unitNum;
si->si_boff = bp->partNum;
if ((error = prom_iopen(si)) != 0)
return (error);
f->f_devdata = si;
return 0;
}
int
tape_close(f)
struct open_file *f;
{
struct saioreq *si;
si = f->f_devdata;
prom_iclose(si);
f->f_devdata = NULL;
return 0;
}
int
tape_strategy(devdata, flag, dblk, size, buf, rsize)
void *devdata;
int flag;
daddr_t dblk;
u_int size;
char *buf;
u_int *rsize;
{
struct saioreq *si;
struct boottab *ops;
char *dmabuf;
int si_flag, xcnt;
si = devdata;
ops = si->si_boottab;
#ifdef DEBUG_PROM
printf("tape_strategy: size=%d dblk=%d\n", size, dblk);
#else
twiddle();
#endif
dmabuf = dvma_mapin(buf, size);
si->si_bn = dblk;
si->si_ma = dmabuf;
si->si_cc = size;
si_flag = (flag == F_READ) ? SAIO_F_READ : SAIO_F_WRITE;
xcnt = (*ops->b_strategy)(si, si_flag);
dvma_mapout(dmabuf, size);
#ifdef DEBUG_PROM
printf("tape_strategy: xcnt = %x\n", xcnt);
#endif
/* At end of tape, xcnt == 0 (not an error) */
if (xcnt < 0)
return (EIO);
*rsize = xcnt;
return (0);
}
int
tape_ioctl()
{
return EIO;
}

View File

@ -0,0 +1,7 @@
/* $NetBSD: dev_tape.h,v 1.1.1.1 1995/10/13 21:27:30 gwr Exp $ */
int tape_open __P((struct open_file *, ...));
int tape_close __P((struct open_file *));
int tape_strategy __P((void *, int, daddr_t, size_t, void *, size_t *));
int tape_ioctl();

View File

@ -0,0 +1,9 @@
/* $NetBSD: version.c,v 1.1.1.1 1995/10/13 21:27:30 gwr Exp $ */
/*
* NOTE ANY CHANGES YOU MAKE TO THE BOOTBLOCKS HERE.
*
* 1.1
*/
char *version = "$Revision: 1.1.1.1 $";