Permalink
Browse files

Import the sun3 version of this on the "vendor branch".

  • Loading branch information...
gwr
gwr committed Mar 13, 1997
1 parent a2bca40 commit 8cf93fd08095dd8b607ada060f2053a850a20543
Showing with 3,168 additions and 0 deletions.
  1. +5 −0 sys/arch/sun3x/stand/Makefile
  2. +50 −0 sys/arch/sun3x/stand/Makefile.inc
  3. +38 −0 sys/arch/sun3x/stand/README
  4. +14 −0 sys/arch/sun3x/stand/bootxx/Makefile
  5. +147 −0 sys/arch/sun3x/stand/bootxx/bootxx.c
  6. +11 −0 sys/arch/sun3x/stand/bootxx/conf.c
  7. +10 −0 sys/arch/sun3x/stand/installboot/Makefile
  8. +58 −0 sys/arch/sun3x/stand/installboot/installboot.8
  9. +377 −0 sys/arch/sun3x/stand/installboot/installboot.c
  10. +45 −0 sys/arch/sun3x/stand/libsa/Makefile
  11. +87 −0 sys/arch/sun3x/stand/libsa/SRT0.S
  12. +78 −0 sys/arch/sun3x/stand/libsa/SRT1.c
  13. +21 −0 sys/arch/sun3x/stand/libsa/clock.c
  14. +6 −0 sys/arch/sun3x/stand/libsa/clock.h
  15. +169 −0 sys/arch/sun3x/stand/libsa/dev_disk.c
  16. +6 −0 sys/arch/sun3x/stand/libsa/dev_disk.h
  17. +32 −0 sys/arch/sun3x/stand/libsa/devopen.c
  18. +118 −0 sys/arch/sun3x/stand/libsa/dvma.c
  19. +9 −0 sys/arch/sun3x/stand/libsa/dvma.h
  20. +178 −0 sys/arch/sun3x/stand/libsa/exec_sun.c
  21. +116 −0 sys/arch/sun3x/stand/libsa/gets.c
  22. +15 −0 sys/arch/sun3x/stand/libsa/netif.h
  23. +451 −0 sys/arch/sun3x/stand/libsa/netif_sun.c
  24. +17 −0 sys/arch/sun3x/stand/libsa/panic.c
  25. +73 −0 sys/arch/sun3x/stand/libsa/promboot.c
  26. +5 −0 sys/arch/sun3x/stand/libsa/promboot.h
  27. +26 −0 sys/arch/sun3x/stand/libsa/promcons.c
  28. +225 −0 sys/arch/sun3x/stand/libsa/promdev.c
  29. +4 −0 sys/arch/sun3x/stand/libsa/promdev.h
  30. +19 −0 sys/arch/sun3x/stand/netboot/Makefile
  31. +80 −0 sys/arch/sun3x/stand/netboot/boot.c
  32. +19 −0 sys/arch/sun3x/stand/netboot/conf.c
  33. +7 −0 sys/arch/sun3x/stand/netboot/version.c
  34. +9 −0 sys/arch/sun3x/stand/tapeboot/Makefile
  35. +83 −0 sys/arch/sun3x/stand/tapeboot/boot.c
  36. +20 −0 sys/arch/sun3x/stand/tapeboot/conf.c
  37. +193 −0 sys/arch/sun3x/stand/tapeboot/dev_tape.c
  38. +6 −0 sys/arch/sun3x/stand/tapeboot/dev_tape.h
  39. +201 −0 sys/arch/sun3x/stand/tapeboot/rawfs.c
  40. +15 −0 sys/arch/sun3x/stand/tapeboot/rawfs.h
  41. +10 −0 sys/arch/sun3x/stand/tapeboot/version.c
  42. +9 −0 sys/arch/sun3x/stand/ufsboot/Makefile
  43. +83 −0 sys/arch/sun3x/stand/ufsboot/boot.c
  44. +16 −0 sys/arch/sun3x/stand/ufsboot/conf.c
  45. +7 −0 sys/arch/sun3x/stand/ufsboot/version.c
@@ -0,0 +1,5 @@
+# $NetBSD: Makefile,v 1.1.1.1 1997/03/13 16:27:27 gwr Exp $
+
+SUBDIR= installboot libsa bootxx ufsboot netboot tapeboot
+
+.include <bsd.subdir.mk>
@@ -0,0 +1,50 @@
+# $NetBSD: Makefile.inc,v 1.1.1.1 1997/03/13 16:27:27 gwr Exp $
+
+.if defined(SA_PROG)
+
+# Must have S=/usr/src/sys (or equivalent)
+# But note: this is w.r.t. a subdirectory
+S= ${.CURDIR}/../../../..
+
+RELOC?= 240000
+DEFS?= -Dsun3 -DSTANDALONE
+INCL?= -I${.CURDIR} -I${.CURDIR}/../libsa -I${S}/lib/libsa -I${S}
+COPTS?= -msoft-float ${DEFS} ${DBG} ${INCL}
+
+LIBSA?= ../libsa
+SRTOBJ?= ${LIBSA}/SRT0.o ${LIBSA}/SRT1.o
+SRTLIB?= ${LIBSA}/libsa.a
+
+MDEC_DIR?=/usr/mdec
+
+SRCS?= ${SA_PROG}.c
+OBJS?= ${SRCS:S/.c/.o/g}
+
+CLEANFILES+= ${SA_PROG} ${SA_PROG}.bin
+
+# Make a copy of the executable with its exec header removed,
+# and with its length padded to a multiple of 1k bytes.
+# (The padding is for convenience when making tapes.)
+${SA_PROG}.bin : ${SA_PROG}
+ cp ${SA_PROG} a.out ; strip a.out
+ dd if=a.out ibs=32 skip=1 of=$@ obs=1k conv=osync
+ -rm -f a.out
+
+${SA_PROG} : ${OBJS} ${DPADD}
+ ${LD} -N -Ttext ${RELOC} -e start -o $@ \
+ ${SRTOBJ} ${OBJS} ${LDADD} ${SRTLIB}
+ @size $@
+
+.if !target(clean)
+clean:
+ -rm -f a.out [Ee]rrs mklog core *.core
+ -rm -f ${CLEANFILES} *.o
+.endif
+
+.if !target(install)
+install: ${SA_PROG}.bin
+ install ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
+ ${SA_PROG}.bin ${DESTDIR}${MDEC_DIR}/${SA_PROG}
+.endif
+
+.endif
@@ -0,0 +1,38 @@
+/* $NetBSD: README,v 1.1.1.1 1997/03/13 16:27:27 gwr Exp $ */
+
+The sun bootblocks are split into two parts: a small 1st-level program that
+gets written right after the superblock in a partition (and is hence limited
+in size to SBSIZE - DEV_BSIZE bytes), and a 2nd-level program that resides
+in the filesystem proper.
+
+The 1st-level program is loaded into memory by the PROM. It loads the second
+stage program from a set of filesystem block numbers that are hard-coded
+into it by the `installboot' program. The prototype code for the 1st-level
+bootblocks are in `bootxx'.
+
+The 2nd-level program (`ufsboot') is normally installed in the root FS
+as `/ufsboot'. It uses the device drivers in the PROM and the stand-alone
+filesystem code in `libsa.a' to locate and load the kernel.
+
+Use the following command to install the 1st-level bootblocks in the
+root filesystem (on `sd0a') using the file `/boot' as the second level
+boot program:
+
+ mount /dev/sd0a /mnt
+ cd /usr/mdec
+ cp -p ufsboot /mnt/ufsboot
+ sync ; sleep 1 ; sync
+ ./installboot -v /mnt/ufsboot bootxx /dev/rsd0a
+
+The above only works with securelevel <= 0 (see init.8 manual).
+
+Status:
+
+netboot works.
+
+bootxx, installboot are tested and working. It would be nice if
+installboot would find the inumber for the 2nd stage boot program
+without having the filesystem mounted so this command can work
+with securelevel==1 (the default). Doing this requies adding
+code to read and do a directory lookup in the root...
+
@@ -0,0 +1,14 @@
+# $NetBSD: Makefile,v 1.1.1.1 1997/03/13 16:27:27 gwr Exp $
+
+SA_PROG= bootxx
+SRCS= bootxx.c conf.c
+
+all: ${SA_PROG}
+
+# Do not strip or remove a.out header for this one.
+install: ${SA_PROG}
+ ${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
+ ${SA_PROG} ${DESTDIR}${MDEC_DIR}/${SA_PROG}
+
+.include <bsd.prog.mk>
+
@@ -0,0 +1,147 @@
+/* $NetBSD: bootxx.c,v 1.1.1.1 1997/03/13 16:27:27 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/time.h>
+#include <sys/exec.h>
+
+#include <machine/mon.h>
+#include "stand.h"
+
+/*
+ * Boot device is derived from ROM provided information.
+ */
+#define LOADADDR 0x4000
+
+/* This determines the largest boot program we can load. */
+#define MAXBLOCKNUM 64
+
+/*
+ * These three names are known by installboot.
+ * The block_table contains starting block numbers,
+ * in terms of 512-byte blocks. Each non-zero value
+ * will result in a read of block_size bytes.
+ */
+int block_size = 512; /* default */
+int block_count = MAXBLOCKNUM; /* length of table */
+daddr_t block_table[MAXBLOCKNUM] = { 0 };
+
+
+main()
+{
+ struct open_file f;
+ void (*entry)();
+ char *addr;
+ int n, error;
+
+#ifdef DEBUG
+ printf("bootxx: open...\n");
+#endif
+ f.f_flags = F_RAW;
+ if (devopen(&f, 0, &addr)) {
+ printf("bootxx: open failed\n");
+ exit();
+ }
+
+ addr = (char*)LOADADDR;
+ error = copyboot(&f, addr);
+ f.f_dev->dv_close(&f);
+ if (!error) {
+#ifdef DEBUG
+ printf("bootxx: start 0x%x\n", (long)addr);
+#endif
+ entry = (void (*)())addr;
+ (*entry)();
+ }
+ /* copyboot had a problem... */
+ exit();
+}
+
+int
+copyboot(fp, addr)
+ struct open_file *fp;
+ char *addr;
+{
+ int n, i, blknum;
+ char *buf;
+
+#ifdef sparc
+ /*
+ * On the sparc, the 2nd stage boot has an a.out header.
+ * On the sun3, (by tradition) the 2nd stage boot programs
+ * have the a.out header stripped off. (1st stage boot
+ * programs have the header stripped by installboot.)
+ */
+ /* XXX - This assumes OMAGIC format! */
+ addr -= sizeof(struct exec); /* XXX */
+#endif
+
+ /* Need to use a buffer that can be mapped into DVMA space. */
+ buf = alloc(block_size);
+ if (!buf)
+ panic("bootxx: alloc failed");
+
+ for (i = 0; i < block_count; i++) {
+
+ if ((blknum = block_table[i]) == 0)
+ break;
+
+#ifdef DEBUG
+ printf("bootxx: block # %d = %d\n", i, blknum);
+#endif
+ if ((fp->f_dev->dv_strategy)(fp->f_devdata, F_READ,
+ blknum, block_size, buf, &n))
+ {
+ printf("bootxx: read failed\n");
+ return -1;
+ }
+ if (n != block_size) {
+ printf("bootxx: short read\n");
+ return -1;
+ }
+ bcopy(buf, addr, block_size);
+ addr += block_size;
+ }
+
+ return 0;
+}
+
@@ -0,0 +1,11 @@
+/* $NetBSD: conf.c,v 1.1.1.1 1997/03/13 16:27:27 gwr Exp $ */
+
+#include <stand.h>
+#include <dev_disk.h>
+
+struct devsw devsw[] = {
+ { "disk", disk_strategy, disk_open, disk_close, disk_ioctl },
+};
+int ndevs = 1;
+
+int debug;
@@ -0,0 +1,10 @@
+# $NetBSD: Makefile,v 1.1.1.1 1997/03/13 16:27:27 gwr Exp $
+
+PROG= installboot
+MAN= installboot.8
+BINDIR=/usr/mdec
+
+# Need this to work in the miniroot
+LDSTATIC= -static
+
+.include <bsd.prog.mk>
@@ -0,0 +1,58 @@
+.\" $Id: installboot.8,v 1.1.1.1 1997/03/13 16:27:27 gwr Exp $
+.\"
+.Dd 31 May 1995
+.Dt INSTALLBOOT 8
+.Os
+.Sh NAME
+.Nm installboot
+.Nd install a bootstrap on a UFS disk
+.Sh SYNOPSIS
+.Nm installboot
+.Fl n | Fl v
+.Ar ufsboot
+.Ar bootxx
+.Ar rawdev
+.Sh DESCRIPTION
+.Nm installboot
+is used to install a "first-stage" boot program into the boot area
+of a UFS disk partition, and initialize the table of block numbers the
+.Ar bootxx
+program uses to load the second-stage boot program.
+.Pp
+The options are as follows:
+.Bl -tag -width flag
+.It Fl n
+Do not actually write anything on the disk.
+.It Fl v
+Be verbose, printing out the block numbers that
+.Ar bootxx
+will use to load
+.Ar ufsboot .
+.El
+.Pp
+The arguments are:
+.Bl -tag -width ufsboot
+.It Ar ufsboot
+the name of the second-stage boot program in the file system
+where the first-stage boot program is to be installed.
+.It Ar bootxx
+the name of the prototype file for the first stage boot program.
+.It Ar rawdev
+the name of the raw device in which the first-stage boot program
+is to be installed. This should correspond to the block device
+on which the file system containing
+.Ar ufsboot
+is mounted.
+.El
+.Sh BUGS
+.Nm installboot
+requires simultaneous access to the mounted file system and
+the raw device, but that is not allowed with the kernel
+.Nm securelevel
+variable set to a value greater than zero (the default), so
+.Nm installboot
+only works in single-user mode (or insecure mode - see
+.Xr init 8 ).
+.Sh "SEE ALSO"
+.Xr disklabel 8 ,
+.Xr init 8
Oops, something went wrong.

0 comments on commit 8cf93fd

Please sign in to comment.