diff options
-rw-r--r-- | distrib/vax/Makefile | 4 | ||||
-rw-r--r-- | distrib/vax/Makefile.inc | 8 | ||||
-rw-r--r-- | distrib/vax/install.md | 250 | ||||
-rw-r--r-- | distrib/vax/list2sh.awk | 30 | ||||
-rw-r--r-- | distrib/vax/ramdisk/Makefile.inc | 15 | ||||
-rw-r--r-- | distrib/vax/ramdisk/dot.commonutils | 133 | ||||
-rw-r--r-- | distrib/vax/ramdisk/dot.profile | 138 | ||||
-rw-r--r-- | distrib/vax/ramdisk/list | 42 | ||||
-rw-r--r-- | distrib/vax/rdsetroot.c | 229 |
9 files changed, 843 insertions, 6 deletions
diff --git a/distrib/vax/Makefile b/distrib/vax/Makefile index 5424f904f75..e49bcfd7535 100644 --- a/distrib/vax/Makefile +++ b/distrib/vax/Makefile @@ -1,5 +1,5 @@ -# $OpenBSD: Makefile,v 1.2 1997/09/21 11:46:08 deraadt Exp $ +# $OpenBSD: Makefile,v 1.3 2001/02/24 10:55:02 hugh Exp $ -SUBDIR= inst tk50 rx50 rx33 +SUBDIR= ../ramdisk .include <bsd.subdir.mk> diff --git a/distrib/vax/Makefile.inc b/distrib/vax/Makefile.inc index eabf1f44052..e7107a12e1e 100644 --- a/distrib/vax/Makefile.inc +++ b/distrib/vax/Makefile.inc @@ -1,4 +1,6 @@ -# $OpenBSD: Makefile.inc,v 1.3 1997/09/21 11:46:09 deraadt Exp $ +# $OpenBSD: Makefile.inc,v 1.4 2001/02/24 10:55:02 hugh Exp $ -# Revision is 1.0 -REV= 10A +SUBDIR= ../ramdisk +REV= 28 + +.include <bsd.subdir.mk> diff --git a/distrib/vax/install.md b/distrib/vax/install.md new file mode 100644 index 00000000000..c1ad6aca15e --- /dev/null +++ b/distrib/vax/install.md @@ -0,0 +1,250 @@ +# $OpenBSD: install.md,v 1.1 2001/02/24 10:55:02 hugh Exp $ +# $NetBSD: install.md,v 1.3.2.5 1996/08/26 15:45:28 gwr Exp $ +# +# +# Copyright (c) 1996 The NetBSD Foundation, Inc. +# All rights reserved. +# +# This code is derived from software contributed to The NetBSD Foundation +# by Jason R. Thorpe. +# +# 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 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. +# + +# +# machine dependent section of installation/upgrade script. +# + +# Machine-dependent install sets +MSGBUF=/kern/msgbuf +HOSTNAME=/kern/hostname +MDSETS="kernel" + +# an alias for hostname(1) +hostname() { + if [ -x /bin/hostname ]; then + /bin/hostname $1 + else + if [ -z "$1" ]; then + cat $HOSTNAME + else + echo $1 > $HOSTNAME + fi + fi +} + +md_set_term() { + test -n "$TERM" && return + echo -n "Specify terminal type [vt100]: " + getresp vt100 + TERM=$resp + export TERM +} + +md_makerootwritable() { + # Was: do_mfs_mount "/tmp" "2048" + # /tmp is the mount point + # 2048 is the size in DEV_BIZE blocks + + if [ ! -w /tmp ]; then + umount /tmp > /dev/null 2>&1 + if ! mount_mfs -s 2048 swap /tmp ; then + cat << __EOT + +FATAL ERROR: Can't mount the memory filesystem. + +__EOT + exit + fi + + # Bleh. Give mount_mfs a chance to DTRT. + sleep 2 + fi +} + +md_get_msgbuf() { + # Only want to see one boot's worth of info + sed -n -f /dev/stdin $MSGBUF <<- OOF + /^OpenBSD /h + /^OpenBSD /!H + \${ + g + p + } + OOF +} + +md_machine_arch() { + cat /kern/machine +} + +md_get_diskdevs() { + # return available disk devices + md_get_msgbuf | sed -n -e '/^sd[0-9] /{s/ .*//;p;}' \ + -e '/^x[ra][0-9] /{s/ .*//;p;}' +} + +md_get_cddevs() { + # return available CDROM devices + md_get_msgbuf | sed -n -e '/^cd[0-9] /{s/ .*//;p;}' +} + +md_get_partition_range() { + # return range of valid partition letters + echo [a-p] +} + +md_questions() { + : +} + +md_installboot() { + echo "Installing boot block..." + /sbin/disklabel -B $1 +} + +md_native_fstype() { + : +} + +md_native_fsopts() { + : +} + +md_checkfordisklabel() { + # $1 is the disk to check + local rval + + disklabel $1 > /dev/null 2> /tmp/checkfordisklabel + if grep "no disk label" /tmp/checkfordisklabel; then + rval=1 + elif grep "disk label corrupted" /tmp/checkfordisklabel; then + rval=2 + else + rval=0 + fi + + rm -f /tmp/checkfordisklabel + return $rval +} + +md_prep_disklabel() +{ + local _disk=$1 + + md_checkfordisklabel $_disk + case $? in + 0) + ;; + 1) + echo WARNING: Label on disk $_disk has no label. You will be creating a new one. + echo + ;; + 2) + echo WARNING: Label on disk $_disk is corrupted. You will be repairing. + echo + ;; + esac + + # display example + cat << __EOT +If you are unsure of how to use multiple partitions properly +(ie. separating /, /usr, /tmp, /var, /usr/local, and other things) +just split the space into a root and swap partition for now. + +__EOT + disklabel -W ${_disk} + disklabel -f /tmp/fstab.${_disk} -E ${_disk} +} + +md_welcome_banner() { +{ + if [ "$MODE" = install ]; then + cat << __EOT +Welcome to the OpenBSD/vax ${VERSION_MAJOR}.${VERSION_MINOR} installation program. + +This program is designed to help you put OpenBSD on your disk in a simple and +rational way. + +__EOT + + else + cat << __EOT +echo Welcome to the OpenBSD/vax ${VERSION} upgrade program. + +This program is designed to help you upgrade your OpenBSD system in a +simple and rational way. + +As a reminder, installing the 'etc' binary set is NOT recommended. +Once the rest of your system has been upgraded, you should manually +merge any changes to files in the 'etc' set into those files which +already exist on your system. + +__EOT + fi + +cat << __EOT + +As with anything which modifies your disk's contents, this program can +cause SIGNIFICANT data loss, and you are advised to make sure your +data is backed up before beginning the installation process. + +Default answers are displayed in brackets after the questions. You +can hit Control-C at any time to quit, but if you do so at a prompt, +you may have to hit return. Also, quitting in the middle of +installation may leave your system in an inconsistent state. + +__EOT +} | more +} + +md_not_going_to_install() { + cat << __EOT + +OK, then. Enter 'halt' at the prompt to halt the machine. Once the +machine has halted, power-cycle the system to load new boot code. + +__EOT +} + +md_congrats() { + local what; + if [ "$MODE" = install ]; then + what=installed + else + what=upgraded + fi + cat << __EOT + +CONGRATULATIONS! You have successfully $what OpenBSD! +To boot the installed system, enter halt at the command prompt. Once the +system has halted, reset the machine and boot from the disk. + +__EOT +} diff --git a/distrib/vax/list2sh.awk b/distrib/vax/list2sh.awk index 6c6d8034e87..2ad8bb69416 100644 --- a/distrib/vax/list2sh.awk +++ b/distrib/vax/list2sh.awk @@ -1,4 +1,4 @@ -# $OpenBSD: list2sh.awk,v 1.3 2000/03/01 22:10:13 todd Exp $ +# $OpenBSD: list2sh.awk,v 1.4 2001/02/24 10:55:02 hugh Exp $ BEGIN { printf("cd ${CURDIR}\n"); @@ -18,6 +18,34 @@ $1 == "LINK" { printf("(cd ${TARGDIR}; ln %s %s)\n", $2, $3); next; } +$1 == "SYMLINK" { + printf("echo '%s'\n", $0); + for (i = 3; i <= NF; i++) { + printf("rm -f ${TARGDIR}/%s\n", $i); + printf("(cd ${TARGDIR}; ln -s %s %s)\n", $2, $i); + } + next; +} +$1 == "ARGVLINK" { + # crunchgen directive; ignored here + next; +} +$1 == "SRCDIRS" { + # crunchgen directive; ignored here + next; +} +$1 == "CRUNCHSPECIAL" { + # crunchgen directive; ignored here + next; +} +$1 == "COPYDIR" { + printf("echo '%s'\n", $0); + printf("(cd ${TARGDIR}/%s && find . ! -name . | xargs /bin/rm -rf)\n", + $3); + printf("(cd %s && find . ! -name . | cpio -pdamu ${TARGDIR}/%s)\n", $2, + $3); + next; +} $1 == "SPECIAL" { printf("echo '%s'\n", $0); printf("(cd ${TARGDIR};"); diff --git a/distrib/vax/ramdisk/Makefile.inc b/distrib/vax/ramdisk/Makefile.inc new file mode 100644 index 00000000000..ecaa076c895 --- /dev/null +++ b/distrib/vax/ramdisk/Makefile.inc @@ -0,0 +1,15 @@ +# $OpenBSD: Makefile.inc,v 1.1 2001/02/24 10:55:03 hugh Exp $ + +IMAGESIZE= 4352 +GZIP?= gzip +GZIPFLAGS?= -9v +GZIPEXT?= .gz +MAKEFLOPPY= 1 +RAWLABEL= +#STRIP= echo +#NEWFS_WILL_FAIL= true +#NEWFSOPTS_RD= -t ffs -m 0 -o space -f 1024 -i 16384 -c 4 -s 8192 +HOSTCCFLAGS= -DDEBUG -O0 +#HOSTCCFLAGS= -DBROKEN_NMAGIC -DDEBUG +BOOT= ${DESTDIR}/boot +BOOTXX= ${DESTDIR}/usr/mdec/sdboot diff --git a/distrib/vax/ramdisk/dot.commonutils b/distrib/vax/ramdisk/dot.commonutils new file mode 100644 index 00000000000..0b3a1cedcab --- /dev/null +++ b/distrib/vax/ramdisk/dot.commonutils @@ -0,0 +1,133 @@ +# $OpenBSD: dot.commonutils,v 1.1 2001/02/24 10:55:02 hugh Exp $ +# $NetBSD: dot.commonutils,v 1.1 1999/03/12 18:36:52 ragge Exp $ +# +# Copyright (c) 1994 Christopher G. Demetriou +# 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 Christopher G. Demetriou. +# 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. +# + +# Installation utilites (functions), to get NetBSD installed on +# the hard disk. These are meant to be invoked from the shell prompt, +# by people installing NetBSD. + +# we know that /etc/fstab is only generated on the hard drive +dest_dir=/ +if [ ! -f /etc/fstab ]; then + dest_dir=/mnt/ +fi + +# counter for possible shared library confusion +TAR=/usr/bin/tar +GUNZIP=/usr/bin/gunzip + +Set_tmp_dir() +{ + def_tmp_dir=`pwd` + if [ "$def_tmp_dir" = "/" -o "$def_tmp_dir" = "/mnt" ]; then + def_tmp_dir="$dest_dir"usr/distrib + fi + + echo -n "What directory should be used to find and/or store " + echo "installtion" + echo -n "files? [$def_tmp_dir] " + read tmp_dir + if [ "$tmp_dir" = "" ]; then + tmp_dir=$def_tmp_dir + fi + if [ ! -d "$tmp_dir" ]; then + /bin/rm -rf $tmp_dir + mkdir -p $tmp_dir + fi +} + +Tmp_dir() +{ + if [ "$tmp_dir" = "" ]; then + Set_tmp_dir + fi + cd $tmp_dir +} + +Load_fd() +{ + Tmp_dir + which= +# echo "Don't forget that you can't load from the drive you booted from." + echo "" + + while [ "$which" != "0" -a "$which" != "1" ]; do + echo -n "Read from which floppy drive ('0' or '1')? [0] " + read which + if [ "X$which" = "X" ]; then + which=0 + fi + done + echo "" + echo "WARNING: during the floppy loading process, you should only" + echo "use Control-C at the prompt." + echo "" + while echo -n \ + "Insert floppy (hit Control-C to terminate, enter to load): " + do + read foo + mount -r -t msdos /dev/fd${which}a /mnt2 + cp -rp /mnt2/* . + umount /mnt2 + done +} + +Load_tape() +{ + Tmp_dir + echo -n "Which tape drive will you be using? [rst0] " + read which + if [ "X$which" = "X" ]; then + which=rst0 + fi + echo -n "Insert the tape into the tape drive and hit return to " + echo -n "continue..." + read foo + echo "Extracting files from the tape..." + $TAR --unlink -xvpf /dev/$which + echo "Done." +} + +Extract() +{ + Tmp_dir + echo -n "Would you like to list the files as they're extracted? [n] " + read verbose + case $verbose in + y*|Y*) + tarverbose=v + ;; + *) + tarverbose= + ;; + esac + cat "$1"* | $GUNZIP | (cd $dest_dir ; $TAR --unlink -xp"$tarverbose"f - ) +} diff --git a/distrib/vax/ramdisk/dot.profile b/distrib/vax/ramdisk/dot.profile new file mode 100644 index 00000000000..85a1d3be598 --- /dev/null +++ b/distrib/vax/ramdisk/dot.profile @@ -0,0 +1,138 @@ +# $OpenBSD: dot.profile,v 1.1 2001/02/24 10:55:02 hugh Exp $ +# $NetBSD: dot.profile,v 1.1 1995/12/18 22:54:43 pk Exp $ +# +# Copyright (c) 1995 Jason R. Thorpe +# Copyright (c) 1994 Christopher G. Demetriou +# 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 Christopher G. Demetriou. +# 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. +# + +export PATH=/sbin:/bin:/usr/bin:/usr/sbin:/ +export HISTFILE=/.sh_history + +umask 022 + +set -o emacs # emacs-style command line editing +alias dmesg="cat /kern/msgbuf" + +# XXX +# the TERM/EDITOR stuff is really well enough parameterized to be moved +# into install.sub where it could use the routines there and be invoked +# from the various (semi) MI install and upgrade scripts + +# terminals believed to be in termcap, default TERM +TERMS="sun vt* pcvt* pc3 dumb" +TERM=sun + +# editors believed to be in $EDITBIN, smart and dumb defaults +EDITORS="vi ed" +EDITOR=vi +DUMB=ed +EDITBIN=/bin + +if [ "X${DONEPROFILE}" = "X" ]; then + DONEPROFILE=YES + + # mount kernfs and re-mount the boot media (perhaps r/w) + mount_kernfs /kern /kern + mount_ffs -o update /kern/rootdev / + + # set up some sane defaults + echo 'erase ^H, werase ^W, kill ^U, intr ^C' + stty newcrt werase ^W intr ^C kill ^U erase ^H 9600 + + # get the terminal type + _forceloop="" + while [ "X$_forceloop" = X"" ]; do + echo "Supported terminals are: $TERMS" + eval `tset -s -m ":?$TERM"` + if [ "X$TERM" != X"unknown" ]; then + _forceloop="done" + fi + done + export TERM + + # get the editor preference + if [ "X$TERM" = "Xdumb" -o "X$TERM" = "Xunknown" ]; then + echo -n "$TERM can't handle $EDITOR" + EDITOR="$DUMB" + echo ", using $EDITOR as text editor!" + elif [ "X$EDITOR" = "X$EDITORS" ]; then + echo "Only one editor available, you get to use $EDITOR!" + else + _forceloop="" + while [ "X$_forceloop" = X"" ]; do + echo "Supported editors are: $EDITORS" + echo -n "text editor? [$EDITOR] " + read _choice + if [ "X$_choice" = "X" ]; then + _choice="$EDITOR" + _forceloop="$_choice" + else + for _editor in $EDITORS; do + if [ "X$_choice" = "X$_editor" ]; then + _forceloop="$_choice" + break + fi + done + fi + if [ "X$_forceloop" != "X" -a ! -x $EDITBIN/$_choice ] + then + _forceloop="" + fi + if [ "X$_forceloop" = "X" ]; then + echo "Sorry, $_choice isn't available." + _forceloop="" + fi + done + EDITOR="$_choice" + fi + export EDITOR + + # Installing or upgrading? + _forceloop="" + while [ "X$_forceloop" = X"" ]; do + echo -n '(I)nstall, (U)pgrade, or (S)hell? ' + read _forceloop + case "$_forceloop" in + i*|I*) + /install + ;; + + u*|U*) + /upgrade + ;; + + s*|S*) + ;; + + *) + _forceloop="" + ;; + esac + done +fi diff --git a/distrib/vax/ramdisk/list b/distrib/vax/ramdisk/list new file mode 100644 index 00000000000..2a955f76991 --- /dev/null +++ b/distrib/vax/ramdisk/list @@ -0,0 +1,42 @@ +# $OpenBSD: list,v 1.1 2001/02/24 10:55:02 hugh Exp $ +# $NetBSD: list,v 1.2.4.2 1996/06/26 19:25:00 pk Exp $ + +# extras +LINK instbin sbin/disklabel + +SYMLINK ../../instbin usr/bin/basename +SYMLINK ../../instbin usr/bin/cksum usr/bin/sum +SYMLINK ../../instbin usr/bin/grep usr/bin/egrep usr/bin/fgrep +SYMLINK ../../instbin usr/bin/netstat +SYMLINK ../../instbin usr/bin/rsh +SYMLINK ../../instbin usr/bin/tset usr/bin/reset +SYMLINK ../../instbin usr/bin/less usr/bin/more +SYMLINK ../../instbin usr/sbin/sysctl + +# Minimize use of MFS +SYMLINK /tmp var/tmp + +# copy the MAKEDEV script and make some devices +COPY ${DESTDIR}/dev/MAKEDEV dev/MAKEDEV +SPECIAL cd dev; sh MAKEDEV ramdisk + +# copy and link first stage boot code +COPY ${DESTDIR}/usr/mdec/xxboot usr/mdec/xxboot +LINK usr/mdec/xxboot usr/mdec/hpboot +LINK usr/mdec/xxboot usr/mdec/raboot +LINK usr/mdec/xxboot usr/mdec/rdboot +LINK usr/mdec/xxboot usr/mdec/sdboot + +# and a few useful bits of the termcap file (512K and still growing 8-) +SPECIAL tic -C ${CURDIR}/../../share/termtypes/termtypes.master | sed -n -e 's,/usr/share/lib/tabset,/usr/share/tabset,g' -e 's,/usr/lib/tabset,/usr/share/tabset,g' -e '/^dumb|/,/:[ ]*$/p' -e '/^unknown|/,/:[ ]*$/p' -e '/^vt.*|/,/:[ ]*$/p' > usr/share/misc/termcap + +# various files that we need in /etc for the install +COPY ${DESTDIR}/etc/disktab etc/disktab.shadow +SYMLINK /tmp/disktab.shadow etc/disktab +SYMLINK /tmp/fstab.shadow etc/fstab +SYMLINK /tmp/resolv.conf.shadow etc/resolv.conf +SYMLINK /tmp/hosts etc/hosts + +# and the installation tools +COPY ${ARCHDIR}/../miniroot/dot.profile .profile +COPY ${ARCHDIR}/../install.md install.md diff --git a/distrib/vax/rdsetroot.c b/distrib/vax/rdsetroot.c new file mode 100644 index 00000000000..754d0e29e80 --- /dev/null +++ b/distrib/vax/rdsetroot.c @@ -0,0 +1,229 @@ +/* $OpenBSD: rdsetroot.c,v 1.1 2001/02/24 10:55:02 hugh Exp $ */ +/* $NetBSD: rdsetroot.c,v 1.2 1995/10/13 16:38:39 gwr Exp $ */ + +/* + * Copyright (c) 1994 Gordon W. Ross + * 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. 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. + */ + +/* + * Copy a ramdisk image into the space reserved for it. + * Kernel variables: rd_root_size, rd_root_image + */ + +#include <sys/types.h> +#include <sys/file.h> +#include <sys/mman.h> + +#include <stdio.h> +#include <unistd.h> +#include <a.out.h> + +extern off_t lseek(); + +struct exec head; +char *file; + +/* Virtual addresses of the symbols we frob. */ +long rd_root_image_va, rd_root_size_va; + +/* Offsets relative to start of data segment. */ +long rd_root_image_off, rd_root_size_off; + +/* value in the location at rd_root_size_off */ +int rd_root_size_val; + +/* pointers to pieces of mapped file */ +char *dataseg; + +/* and lengths */ +int data_len; +int data_off; +int data_pgoff; + +void find_rd_root_image(char *); + + +int main(argc,argv) + int argc; + char **argv; +{ + int fd, n; + int *ip; + + if (argc < 2) { + printf("%s: missing file name\n", argv[0]); + exit(1); + } + file = argv[1]; + + fd = open(file, O_RDWR); + if (fd < 0) { + perror(file); + exit(1); + } + + n = read(fd, &head, sizeof(head)); + if (n < sizeof(head)) { + printf("%s: reading header\n", file); + exit(1); + } + + if (N_BADMAG(head)) { + printf("%s: bad magic number\n", file); + exit(1); + } + +#ifdef DEBUG + printf(" text: %9d\n", head.a_text); + printf(" data: %9d\n", head.a_data); + printf(" bss: %9d\n", head.a_bss); + printf(" syms: %9d\n", head.a_syms); + printf("entry: 0x%08X\n", head.a_entry); + printf("trsiz: %9d\n", head.a_trsize); + printf("drsiz: %9d\n", head.a_drsize); +#endif + + if (head.a_syms <= 0) { + printf("%s: no symbols\n", file); + exit(1); + } + if (head.a_trsize || + head.a_drsize) + { + printf("%s: has relocations\n", file); + exit(1); + } + + find_rd_root_image(file); + + /* + * Map in the whole data segment. + * The file offset needs to be page aligned. + */ + data_off = N_DATOFF(head); + data_len = head.a_data; + /* align... */ + data_pgoff = N_PAGSIZ(head) - 1; + data_pgoff &= data_off; + data_off -= data_pgoff; + data_len += data_pgoff; + /* map in in... */ + dataseg = mmap(NULL, /* any address is ok */ + data_len, /* length */ + PROT_READ | PROT_WRITE, + MAP_SHARED, + fd, data_off); + if ((long)dataseg == -1) { + printf("%s: can not map data seg\n", file); + perror(file); + exit(1); + } + dataseg += data_pgoff; + + /* + * Find value in the location: rd_root_size + */ + ip = (int*) (dataseg + rd_root_size_off); + rd_root_size_val = *ip; +#ifdef DEBUG + printf("rd_root_size val: 0x%08X (%d blocks)\n", + rd_root_size_val, (rd_root_size_val >> 9)); +#endif + + /* + * Copy the symbol table and string table. + */ +#ifdef DEBUG + printf("copying root image...\n"); +#endif + n = read(0, dataseg + rd_root_image_off, + rd_root_size_val); + if (n < 0) { + perror("read"); + exit(1); + } + + msync(dataseg - data_pgoff, data_len, 0); + +#ifdef DEBUG + printf("...copied %d bytes\n", n); +#endif + close(fd); + exit(0); +} + + +/* + * Find locations of the symbols to patch. + */ +struct nlist wantsyms[] = { + { "_rd_root_size", 0 }, + { "_rd_root_image", 0 }, + { NULL, 0 }, +}; + +void find_rd_root_image(file) + char *file; +{ + int data_va; + int std_entry; + + if (nlist(file, wantsyms)) { + printf("%s: no rd_root_image symbols?\n", file); + exit(1); + } + std_entry = N_TXTADDR(head) + + (head.a_entry & (N_PAGSIZ(head)-1)); + data_va = N_DATADDR(head); + if (head.a_entry != std_entry) { + printf("%s: warning: non-standard entry point: 0x%08x\n", + file, head.a_entry); + printf("\texpecting entry=0x%X\n", std_entry); + data_va += (head.a_entry - std_entry); + } + + rd_root_size_off = wantsyms[0].n_value - data_va; + rd_root_image_off = wantsyms[1].n_value - data_va; +#ifdef DEBUG + printf(".data segment va: 0x%08X\n", data_va); + printf("rd_root_size va: 0x%08X\n", wantsyms[0].n_value); + printf("rd_root_image va: 0x%08X\n", wantsyms[1].n_value); + printf("rd_root_size off: 0x%08X\n", rd_root_size_off); + printf("rd_root_image off: 0x%08X\n", rd_root_image_off); +#endif + + /* + * Sanity check locations of db_* symbols + */ + if (rd_root_image_off < 0 || rd_root_image_off >= head.a_data) { + printf("%s: rd_root_image not in data segment?\n", file); + exit(1); + } + if (rd_root_size_off < 0 || rd_root_size_off >= head.a_data) { + printf("%s: rd_root_size not in data segment?\n", file); + exit(1); + } +} |