Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/i386/stand/bootxx bootxx: bootstrap code - installa...



details:   https://anonhg.NetBSD.org/src/rev/262db74854e5
branches:  trunk
changeset: 545830:262db74854e5
user:      dsl <dsl%NetBSD.org@localhost>
date:      Wed Apr 16 22:16:36 2003 +0000

description:
bootxx: bootstrap code - installable by MI installboot.
Loads /boot using filesystem accesses (rather than a list of block numbers)

diffstat:

 sys/arch/i386/stand/bootxx/Makefile                |    6 +
 sys/arch/i386/stand/bootxx/Makefile.bootxx         |  144 ++++++++
 sys/arch/i386/stand/bootxx/boot1.c                 |  108 ++++++
 sys/arch/i386/stand/bootxx/boot_params.S           |    9 +
 sys/arch/i386/stand/bootxx/bootxx.S                |  128 +++++++
 sys/arch/i386/stand/bootxx/bootxx_ffsv1/Makefile   |    5 +
 sys/arch/i386/stand/bootxx/bootxx_ffsv2/Makefile   |    5 +
 sys/arch/i386/stand/bootxx/bootxx_lfsv1/Makefile   |    5 +
 sys/arch/i386/stand/bootxx/bootxx_lfsv2/Makefile   |    5 +
 sys/arch/i386/stand/bootxx/bootxx_ufs/Makefile     |    5 +
 sys/arch/i386/stand/bootxx/bootxx_ustarfs/Makefile |    7 +
 sys/arch/i386/stand/bootxx/label.S                 |   13 +
 sys/arch/i386/stand/bootxx/pbr.S                   |  368 +++++++++++++++++++++
 13 files changed, 808 insertions(+), 0 deletions(-)

diffs (truncated from 860 to 300 lines):

diff -r 143fc81ced06 -r 262db74854e5 sys/arch/i386/stand/bootxx/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/i386/stand/bootxx/Makefile       Wed Apr 16 22:16:36 2003 +0000
@@ -0,0 +1,6 @@
+# $NetBSD: Makefile,v 1.1 2003/04/16 22:17:44 dsl Exp $
+
+SUBDIR= bootxx_ufs bootxx_ffsv1 bootxx_ffsv2 bootxx_lfsv1 bootxx_lfsv2
+SUBDIR+= bootxx_dosfs bootxx_ustarfs
+
+.include <bsd.subdir.mk>
diff -r 143fc81ced06 -r 262db74854e5 sys/arch/i386/stand/bootxx/Makefile.bootxx
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/i386/stand/bootxx/Makefile.bootxx        Wed Apr 16 22:16:36 2003 +0000
@@ -0,0 +1,144 @@
+# $NetBSD: Makefile.bootxx,v 1.1 2003/04/16 22:17:44 dsl Exp $
+
+S=     ${.CURDIR}/../../../../../
+
+NOMAN=
+STRIPFLAG=
+PROG= bootxx_${FS}
+PRIMARY_LOAD_ADDRESS=0x600
+SECONDARY_LOAD_ADDRESS=0x10000
+
+# We ought (need?) to fit into track 0 of a 1.2M floppy.
+# This restricts us to 15 sectors (including pbr and label)
+BOOTXX_SECTORS?=15
+BOOTXX_MAXSIZE?= $$(( ${BOOTXX_SECTORS} * 512 ))
+
+SRCS= pbr.S label.S bootxx.S boot1.c
+
+.include <bsd.own.mk>
+
+LIBCRT0=       # nothing
+LIBCRTBEGIN=   # nothing
+LIBCRTEND=     # nothing
+LIBC=          # nothing
+
+BINDIR=/usr/mdec
+BINMODE=444
+
+.PATH: ${.CURDIR}/.. ${.CURDIR}/../../lib
+
+LDFLAGS+= -N -e start
+CPPFLAGS+= -DBOOTXX
+# CPPFLAGS+= -D__daddr_t=int32_t
+CPPFLAGS+= -I ${.CURDIR}/../../lib -I ${.OBJDIR}
+CPPFLAGS+= -DBOOTXX_SECTORS=${BOOTXX_SECTORS}
+CPPFLAGS+= -DPRIMARY_LOAD_ADDRESS=${PRIMARY_LOAD_ADDRESS}
+CPPFLAGS+= -DSECONDARY_LOAD_ADDRESS=${SECONDARY_LOAD_ADDRESS}
+# Magic number also known by usr.sbin/installboot/arch/i386.c
+CPPFLAGS+= -DX86_BOOT_MAGIC_1="('x' << 24 | 0x86b << 12 | 'm' << 4 | 1)"
+CPPFLAGS+= -DXXfs_open=${FS}_open
+CPPFLAGS+= -DXXfs_close=${FS}_close
+CPPFLAGS+= -DXXfs_read=${FS}_read
+CPPFLAGS+= -DXXfs_stat=${FS}_stat
+
+# Make sure we override any optimization options specified by the user
+COPTS=  -Os
+
+.if ${MACHINE} == "x86_64"
+LDFLAGS+=  -m elf_i386
+AFLAGS+=   -m32
+COPTS+=    -m32
+LIBKERN_ARCH=i386
+KERNMISCMAKEFLAGS="LIBKERN_ARCH=i386"
+.else
+COPTS+=    -mcpu=i386
+.endif
+
+COPTS+=    -ffreestanding
+CFLAGS+= -Wall -Wmissing-prototypes -Wstrict-prototypes
+CPPFLAGS+= -nostdinc -D_STANDALONE
+CPPFLAGS+= -I$S
+
+CPPFLAGS+= -DLIBSA_SINGLE_FILESYSTEM=xxfs \
+               -DLIBSA_NO_TWIDDLE \
+               -DLIBSA_NO_FD_CHECKING \
+               -DLIBSA_NO_RAW_ACCESS \
+               -DLIBSA_NO_FS_WRITE \
+               -DLIBSA_NO_FS_SEEK \
+               -DLIBSA_USE_MEMCPY \
+               -DLIBSA_USE_MEMSET \
+               -DLIBSA_SINGLE_DEVICE=blkdev \
+               -DLIBKERN_OPTIMISE_SPACE \
+               -D"blkdevioctl(x,y,z)=EINVAL" \
+               -D"blkdevclose(f)=0" \
+               -D"devopen(f,n,fl)=(*(fl)=(void *)n,0)" \
+               -DLIBSA_NO_DISKLABEL_MSGS
+
+# -DLIBSA_FS_SINGLECOMPONENT 
+
+# CPPFLAGS+= -DBOOTXX_RAID1_SUPPORT
+
+I386_STAND_DIR?= $S/arch/i386/stand
+
+.if !make(obj) && !make(clean) && !make(cleandir)
+.BEGIN: machine
+.NOPATH: machine
+.endif
+
+realdepend realall: machine
+CLEANFILES+= machine
+
+machine::
+       -rm -f $@
+       ln -s $S/arch/i386/include $@
+
+${OBJS}: machine
+
+### find out what to use for libi386
+I386DIR= ${I386_STAND_DIR}/lib
+I386DST= ${.OBJDIR}/../lib/i386
+.include "${I386DIR}/Makefile.inc"
+LIBI386= ${I386LIB}
+
+### find out what to use for libsa
+SA_AS= library
+SADST= ${.OBJDIR}/../lib/libsa
+SAMISCMAKEFLAGS+="SA_USE_LOADFILE=yes"
+.include "${S}/lib/libsa/Makefile.inc"
+LIBSA= ${SALIB}
+
+### find out what to use for libkern
+KERN_AS=        library
+KERNDST= ${.OBJDIR}/../lib/libkern
+.include "${S}/lib/libkern/Makefile.inc"
+LIBKERN=        ${KERNLIB}
+
+
+cleandir distclean: cleanlibdir
+
+cleanlibdir:
+       rm -rf lib
+
+LIBLIST= ${LIBI386} ${LIBSA} ${LIBKERN} ${LIBI386} ${LIBSA}
+
+CLEANFILES+= ${PROG}.tmp ${PROG}.map
+
+${PROG}: ${OBJS} ${LIBLIST}
+       ${LD} -o ${PROG}.tmp ${LDFLAGS} -Ttext ${PRIMARY_LOAD_ADDRESS} \
+               -Map ${PROG}.map -cref ${OBJS} ${LIBLIST}
+       ${OBJCOPY} -O binary ${PROG}.tmp ${PROG}
+       # rm -f ${PROG}.tmp
+       @ sz=$$(ls -ln ${PROG}|tr -s ' '|cut -d' ' -f5); \
+       if [ "$$sz" -gt "${BOOTXX_MAXSIZE}" ]; then \
+               echo "### ${PROG} size $$sz is larger than ${BOOTXX_MAXSIZE}" >&2; \
+               rm ${PROG}; \
+               ! :; \
+       else \
+               : pad to sector boundary; \
+               pad=$$(( 512 - ( $$sz & 511 ) )); \
+               [ $$pad != 512 ] && \
+                   dd if=/dev/zero bs=1 count=$$pad >>${PROG} 2>/dev/null; \
+               echo "${PROG} size $$sz, $$((${BOOTXX_MAXSIZE} - $$sz)) free"; \
+       fi
+
+.include <bsd.prog.mk>
diff -r 143fc81ced06 -r 262db74854e5 sys/arch/i386/stand/bootxx/boot1.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/i386/stand/bootxx/boot1.c        Wed Apr 16 22:16:36 2003 +0000
@@ -0,0 +1,108 @@
+/*     $NetBSD: boot1.c,v 1.1 2003/04/16 22:17:44 dsl Exp $    */
+
+/*-
+ * Copyright (c) 2003 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by David Laight.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *        This product includes software developed by the NetBSD
+ *        Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: boot1.c,v 1.1 2003/04/16 22:17:44 dsl Exp $");
+
+#include <lib/libsa/stand.h>
+#include <lib/libkern/libkern.h>
+#include <biosdisk_ll.h>
+
+#include <sys/param.h>
+#include <sys/bootblock.h>
+
+static uint32_t bios_dev;
+static uint32_t bios_sector;
+
+struct biosdisk_ll d;
+
+const char *boot1(uint32_t biosdev, uint32_t sector);
+extern void putstr(const char *);
+
+const char *
+boot1(uint32_t biosdev, uint32_t sector)
+{
+        struct stat sb;
+       int fd;
+
+       bios_sector = sector;
+       bios_dev = biosdev;
+       d.dev = biosdev;
+
+        putstr("\r\nNetBSD/i386 Primary Bootstrap\r\n");
+
+       if (set_geometry(&d, NULL))
+               return "set_geometry\r\n";
+
+       fd = open("boot", 0);
+       if (fd == -1 || fstat(fd, &sb) == -1)
+               return "Can't open /boot.\r\n";
+
+#if 0
+       if (sb.st_size > SECONDARY_MAX_LOAD)
+               return "/boot too large.\r\n";
+#endif
+
+       if (read(fd, (void *)SECONDARY_LOAD_ADDRESS, sb.st_size) != sb.st_size)
+               return "/boot load failed.\r\n";
+
+       if (*(uint32_t *)(SECONDARY_LOAD_ADDRESS + 4) != X86_BOOT_MAGIC_2)
+               return "Invalid /boot file format.\r\n";
+
+       /* We need to jump to the secondary bootstrap in realmode */
+       return 0;
+}
+
+int
+blkdevstrategy(void *devdata, int flag, daddr_t dblk, size_t size, void *buf, size_t *rsize)
+{
+       if (flag != F_READ)
+               return EROFS;
+
+       if (size & (BIOSDISK_SECSIZE - 1))
+               return EINVAL;
+
+       if (rsize)
+               *rsize = size;
+
+       if (size != 0 && readsects(&d, bios_sector + dblk,
+                                  size / BIOSDISK_SECSIZE, buf, 1) != 0)
+               return EIO;
+
+       return 0;
+}
diff -r 143fc81ced06 -r 262db74854e5 sys/arch/i386/stand/bootxx/boot_params.S
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/i386/stand/bootxx/boot_params.S  Wed Apr 16 22:16:36 2003 +0000
@@ -0,0 +1,9 @@
+/*     $NetBSD: boot_params.S,v 1.1 2003/04/16 22:17:44 dsl Exp $      */
+
+/* Default boot parameters */
+
+       .long   0                       /* flags */
+       .long   5                       /* timeout in seconds */
+       .long   0                       /* console device 0 => CONSDEV_PC */
+       .long   9600                    /* serial baud rate */
+       .space  16                      /* md5 boot password */
diff -r 143fc81ced06 -r 262db74854e5 sys/arch/i386/stand/bootxx/bootxx.S
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/i386/stand/bootxx/bootxx.S       Wed Apr 16 22:16:36 2003 +0000
@@ -0,0 +1,128 @@
+/*     $NetBSD: bootxx.S,v 1.1 2003/04/16 22:17:44 dsl Exp $   */
+
+/*-
+ * Copyright (c) 2003 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by David Laight.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright



Home | Main Index | Thread Index | Old Index