aboutsummaryrefslogtreecommitdiff
path: root/sys/boot
diff options
context:
space:
mode:
authorMarcel Moolenaar <marcel@FreeBSD.org>2010-10-26 02:34:47 +0000
committerMarcel Moolenaar <marcel@FreeBSD.org>2010-10-26 02:34:47 +0000
commit6f3544cd7084abbadd83637993a4f41fd30e6ccd (patch)
tree016db2cb582287919cbc41b771064efcbc4e1852 /sys/boot
parentb17f9ad2c9da34e8544d02c3d530fe9fb41fdbe2 (diff)
parent3082dd3fc7372032d322b738439a633f1056c8b8 (diff)
Notes
Diffstat (limited to 'sys/boot')
-rw-r--r--sys/boot/Makefile20
-rw-r--r--sys/boot/Makefile.amd644
-rw-r--r--sys/boot/Makefile.arm3
-rw-r--r--sys/boot/Makefile.i3864
-rw-r--r--sys/boot/Makefile.ia643
-rw-r--r--sys/boot/Makefile.pc984
-rw-r--r--sys/boot/Makefile.powerpc4
-rw-r--r--sys/boot/Makefile.sparc643
-rw-r--r--sys/boot/arm/ixp425/boot2/Makefile2
-rw-r--r--sys/boot/arm/uboot/Makefile2
-rw-r--r--sys/boot/common/Makefile.inc10
-rw-r--r--sys/boot/common/crc32.c108
-rw-r--r--sys/boot/common/crc32.h13
-rw-r--r--sys/boot/common/gpt.c381
-rw-r--r--sys/boot/common/gpt.h39
-rw-r--r--sys/boot/common/loader.81
-rw-r--r--sys/boot/common/ufsread.c13
-rw-r--r--sys/boot/common/util.c176
-rw-r--r--sys/boot/common/util.h53
-rw-r--r--sys/boot/efi/libefi/Makefile2
-rw-r--r--sys/boot/fdt/dts/dockstar.dts265
-rw-r--r--sys/boot/ficl/Makefile14
-rw-r--r--sys/boot/forth/beastie.4th5
-rw-r--r--sys/boot/forth/loader.conf1
-rw-r--r--sys/boot/i386/Makefile.inc2
-rw-r--r--sys/boot/i386/boot2/Makefile7
-rw-r--r--sys/boot/i386/boot2/boot2.c4
-rw-r--r--sys/boot/i386/common/cons.c152
-rw-r--r--sys/boot/i386/common/cons.h34
-rw-r--r--sys/boot/i386/common/drv.c131
-rw-r--r--sys/boot/i386/common/drv.h48
-rw-r--r--sys/boot/i386/common/rbx.h61
-rw-r--r--sys/boot/i386/efi/Makefile2
-rw-r--r--sys/boot/i386/gptboot/Makefile16
-rw-r--r--sys/boot/i386/gptboot/gptboot.c566
-rw-r--r--sys/boot/i386/gptzfsboot/Makefile12
-rw-r--r--sys/boot/i386/libfirewire/Makefile4
-rw-r--r--sys/boot/i386/libi386/Makefile4
-rw-r--r--sys/boot/i386/libi386/biosdisk.c4
-rw-r--r--sys/boot/i386/libi386/pxe.c59
-rw-r--r--sys/boot/i386/loader/Makefile4
-rw-r--r--sys/boot/i386/zfsboot/Makefile19
-rw-r--r--sys/boot/i386/zfsboot/zfsboot.c428
-rw-r--r--sys/boot/i386/zfsloader/Makefile2
-rw-r--r--sys/boot/ia64/common/Makefile4
-rw-r--r--sys/boot/ia64/efi/Makefile10
-rw-r--r--sys/boot/ia64/ski/Makefile4
-rw-r--r--sys/boot/ofw/libofw/Makefile4
-rw-r--r--sys/boot/ofw/libofw/ofw_copy.c2
-rw-r--r--sys/boot/pc98/boot2/Makefile5
-rw-r--r--sys/boot/pc98/boot2/boot2.c9
-rw-r--r--sys/boot/sparc64/boot1/boot1.c60
-rw-r--r--sys/boot/uboot/lib/Makefile2
-rw-r--r--sys/boot/zfs/Makefile13
-rw-r--r--sys/boot/zfs/zfs.c4
-rw-r--r--sys/boot/zfs/zfsimpl.c81
56 files changed, 1891 insertions, 996 deletions
diff --git a/sys/boot/Makefile b/sys/boot/Makefile
index b2eeb9554703..6c879972f928 100644
--- a/sys/boot/Makefile
+++ b/sys/boot/Makefile
@@ -1,31 +1,13 @@
# $FreeBSD$
.include <bsd.own.mk>
+.include <bsd.arch.inc.mk>
.if ${MK_FORTH} != "no"
# Build the add-in FORTH interpreter.
SUBDIR+= ficl
.endif
-# Build EFI library.
-.if ${MACHINE_ARCH} == "amd64" || ${MACHINE} == "i386" || ${MACHINE_ARCH} == "ia64"
-SUBDIR+= efi
-.endif
-
-# Build Open Firmware library.
-.if ${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "powerpc64" || ${MACHINE_ARCH} == "sparc64"
-SUBDIR+= ofw
-.endif
-
-# Build U-Boot library.
-.if ${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "powerpc64" || ${MACHINE_ARCH} == "arm"
-SUBDIR+= uboot
-.endif
-
-.if ${MACHINE_ARCH} == "amd64" || ${MACHINE} == "i386"
-SUBDIR+= zfs
-.endif
-
.if ${MK_FDT} != "no"
SUBDIR+= fdt
.endif
diff --git a/sys/boot/Makefile.amd64 b/sys/boot/Makefile.amd64
new file mode 100644
index 000000000000..256201d4f940
--- /dev/null
+++ b/sys/boot/Makefile.amd64
@@ -0,0 +1,4 @@
+# $FreeBSD$
+
+SUBDIR+= efi
+SUBDIR+= zfs
diff --git a/sys/boot/Makefile.arm b/sys/boot/Makefile.arm
new file mode 100644
index 000000000000..f96104db47c5
--- /dev/null
+++ b/sys/boot/Makefile.arm
@@ -0,0 +1,3 @@
+# $FreeBSD$
+
+SUBDIR+= uboot
diff --git a/sys/boot/Makefile.i386 b/sys/boot/Makefile.i386
new file mode 100644
index 000000000000..256201d4f940
--- /dev/null
+++ b/sys/boot/Makefile.i386
@@ -0,0 +1,4 @@
+# $FreeBSD$
+
+SUBDIR+= efi
+SUBDIR+= zfs
diff --git a/sys/boot/Makefile.ia64 b/sys/boot/Makefile.ia64
new file mode 100644
index 000000000000..921f2930d300
--- /dev/null
+++ b/sys/boot/Makefile.ia64
@@ -0,0 +1,3 @@
+# $FreeBSD$
+
+SUBDIR+= efi
diff --git a/sys/boot/Makefile.pc98 b/sys/boot/Makefile.pc98
new file mode 100644
index 000000000000..aa989e1784bd
--- /dev/null
+++ b/sys/boot/Makefile.pc98
@@ -0,0 +1,4 @@
+# $FreeBSD$
+
+# Blank, to override Makefile.i386 since Makefile.$MACHINE is included before
+# Makefile.$MACHINE_ARCH
diff --git a/sys/boot/Makefile.powerpc b/sys/boot/Makefile.powerpc
new file mode 100644
index 000000000000..ca8c33139b11
--- /dev/null
+++ b/sys/boot/Makefile.powerpc
@@ -0,0 +1,4 @@
+# $FreeBSD$
+
+SUBDIR+= ofw
+SUBDIR+= uboot
diff --git a/sys/boot/Makefile.sparc64 b/sys/boot/Makefile.sparc64
new file mode 100644
index 000000000000..5723629ba475
--- /dev/null
+++ b/sys/boot/Makefile.sparc64
@@ -0,0 +1,3 @@
+# $FreeBSD$
+
+SUBDIR+= ofw
diff --git a/sys/boot/arm/ixp425/boot2/Makefile b/sys/boot/arm/ixp425/boot2/Makefile
index 138446b6fa25..a329b65c0db6 100644
--- a/sys/boot/arm/ixp425/boot2/Makefile
+++ b/sys/boot/arm/ixp425/boot2/Makefile
@@ -20,7 +20,7 @@ NO_MAN=
KERNPHYSADDR=0x180000
KERNVIRTADDR=${KERNPHYSADDR}
BOOT_STACK=0x200000-4
-M=${MACHINE_ARCH}
+M=${MACHINE}
LDFLAGS=-e ${KERNPHYSADDR} -EB -T ldscript.${M}
OBJS+= ${SRCS:N*.h:R:S/$/.o/g}
S=${.CURDIR}/../../../..
diff --git a/sys/boot/arm/uboot/Makefile b/sys/boot/arm/uboot/Makefile
index 573f9489f353..906fc871a887 100644
--- a/sys/boot/arm/uboot/Makefile
+++ b/sys/boot/arm/uboot/Makefile
@@ -77,7 +77,7 @@ CLEANFILES+= vers.c loader.help
CFLAGS+= -ffreestanding
-LDFLAGS= -nostdlib -static -T ${.CURDIR}/ldscript.arm
+LDFLAGS= -nostdlib -static -T ${.CURDIR}/ldscript.${MACHINE_CPUARCH}
# Pull in common loader code
.PATH: ${.CURDIR}/../../uboot/common
diff --git a/sys/boot/common/Makefile.inc b/sys/boot/common/Makefile.inc
index 23f8fbf444d7..989327839e7f 100644
--- a/sys/boot/common/Makefile.inc
+++ b/sys/boot/common/Makefile.inc
@@ -4,19 +4,19 @@ SRCS+= boot.c commands.c console.c devopen.c interp.c
SRCS+= interp_backslash.c interp_parse.c ls.c misc.c
SRCS+= module.c panic.c
-.if ${MACHINE} == "i386" || ${MACHINE_ARCH} == "amd64"
+.if ${MACHINE} == "i386" || ${MACHINE_CPUARCH} == "amd64"
SRCS+= load_elf32.c load_elf32_obj.c reloc_elf32.c
SRCS+= load_elf64.c load_elf64_obj.c reloc_elf64.c
-.elif ${MACHINE} == "ia64"
+.elif ${MACHINE_CPUARCH} == "ia64"
SRCS+= load_elf64.c load_elf64_obj.c reloc_elf64.c
.elif ${MACHINE} == "pc98"
SRCS+= load_elf32.c load_elf32_obj.c reloc_elf32.c
-.elif ${MACHINE_ARCH} == "arm"
+.elif ${MACHINE_CPUARCH} == "arm"
SRCS+= load_elf32.c reloc_elf32.c
-.elif ${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "powerpc64"
+.elif ${MACHINE_CPUARCH} == "powerpc"
SRCS+= load_elf32.c reloc_elf32.c
SRCS+= load_elf64.c reloc_elf64.c
-.elif ${MACHINE_ARCH} == "sparc64"
+.elif ${MACHINE_CPUARCH} == "sparc64"
SRCS+= load_elf64.c reloc_elf64.c
.endif
diff --git a/sys/boot/common/crc32.c b/sys/boot/common/crc32.c
new file mode 100644
index 000000000000..032517993a49
--- /dev/null
+++ b/sys/boot/common/crc32.c
@@ -0,0 +1,108 @@
+/*-
+ * COPYRIGHT (C) 1986 Gary S. Brown. You may use this program, or
+ * code or tables extracted from it, as desired without restriction.
+ */
+
+/*
+ * First, the polynomial itself and its table of feedback terms. The
+ * polynomial is
+ * X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0
+ *
+ * Note that we take it "backwards" and put the highest-order term in
+ * the lowest-order bit. The X^32 term is "implied"; the LSB is the
+ * X^31 term, etc. The X^0 term (usually shown as "+1") results in
+ * the MSB being 1
+ *
+ * Note that the usual hardware shift register implementation, which
+ * is what we're using (we're merely optimizing it by doing eight-bit
+ * chunks at a time) shifts bits into the lowest-order term. In our
+ * implementation, that means shifting towards the right. Why do we
+ * do it this way? Because the calculated CRC must be transmitted in
+ * order from highest-order term to lowest-order term. UARTs transmit
+ * characters in order from LSB to MSB. By storing the CRC this way
+ * we hand it to the UART in the order low-byte to high-byte; the UART
+ * sends each low-bit to hight-bit; and the result is transmission bit
+ * by bit from highest- to lowest-order term without requiring any bit
+ * shuffling on our part. Reception works similarly
+ *
+ * The feedback terms table consists of 256, 32-bit entries. Notes
+ *
+ * The table can be generated at runtime if desired; code to do so
+ * is shown later. It might not be obvious, but the feedback
+ * terms simply represent the results of eight shift/xor opera
+ * tions for all combinations of data and CRC register values
+ *
+ * The values must be right-shifted by eight bits by the "updcrc
+ * logic; the shift must be unsigned (bring in zeroes). On some
+ * hardware you could probably optimize the shift in assembler by
+ * using byte-swap instructions
+ * polynomial $edb88320
+ *
+ *
+ * CRC32 code derived from work by Gary S. Brown.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+
+#include "crc32.h"
+
+static uint32_t crc32_tab[] = {
+ 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
+ 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
+ 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
+ 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
+ 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
+ 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
+ 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
+ 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
+ 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
+ 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
+ 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
+ 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
+ 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
+ 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
+ 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
+ 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
+ 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
+ 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
+ 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
+ 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
+ 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
+ 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
+ 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
+ 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
+ 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
+ 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
+ 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
+ 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
+ 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
+ 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
+ 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
+ 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
+ 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
+ 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
+ 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
+ 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
+ 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
+ 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
+ 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
+ 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
+ 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
+ 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
+ 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
+};
+
+uint32_t
+crc32(const void *buf, size_t size)
+{
+ const uint8_t *p = buf;
+ uint32_t crc;
+
+ crc = ~0U;
+ while (size--)
+ crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8);
+ return (crc ^ ~0U);
+}
diff --git a/sys/boot/common/crc32.h b/sys/boot/common/crc32.h
new file mode 100644
index 000000000000..adfd628671aa
--- /dev/null
+++ b/sys/boot/common/crc32.h
@@ -0,0 +1,13 @@
+/*-
+ * COPYRIGHT (C) 1986 Gary S. Brown. You may use this program, or
+ * code or tables extracted from it, as desired without restriction.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _CRC32_H_
+#define _CRC32_H_
+
+uint32_t crc32(const void *buf, size_t size);
+
+#endif /* !_CRC32_H_ */
diff --git a/sys/boot/common/gpt.c b/sys/boot/common/gpt.c
new file mode 100644
index 000000000000..9c0098008e30
--- /dev/null
+++ b/sys/boot/common/gpt.c
@@ -0,0 +1,381 @@
+/*-
+ * Copyright (c) 2010 Pawel Jakub Dawidek <pjd@FreeBSD.org>
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS 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 AUTHORS 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>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/gpt.h>
+
+#ifndef LITTLE_ENDIAN
+#error gpt.c works only for little endian architectures
+#endif
+
+#include "crc32.h"
+#include "drv.h"
+#include "util.h"
+#include "gpt.h"
+
+#define MAXTBLENTS 128
+
+static struct gpt_hdr hdr_primary, hdr_backup, *gpthdr;
+static uint64_t hdr_primary_lba, hdr_backup_lba;
+static struct gpt_ent table_primary[MAXTBLENTS], table_backup[MAXTBLENTS];
+static struct gpt_ent *gpttable;
+static int curent, bootonce;
+
+/*
+ * Buffer below 64kB passed on gptread(), which can hold at least
+ * one sector of data (512 bytes).
+ */
+static char *secbuf;
+
+static void
+gptupdate(const char *which, struct dsk *dskp, struct gpt_hdr *hdr,
+ struct gpt_ent *table)
+{
+ int entries_per_sec, firstent;
+ daddr_t slba;
+
+ /*
+ * We need to update the following for both primary and backup GPT:
+ * 1. Sector on disk that contains current partition.
+ * 2. Partition table checksum.
+ * 3. Header checksum.
+ * 4. Header on disk.
+ */
+
+ entries_per_sec = DEV_BSIZE / hdr->hdr_entsz;
+ slba = curent / entries_per_sec;
+ firstent = slba * entries_per_sec;
+ bcpy(&table[firstent], secbuf, DEV_BSIZE);
+ slba += hdr->hdr_lba_table;
+ if (drvwrite(dskp, secbuf, slba, 1)) {
+ printf("%s: unable to update %s GPT partition table\n",
+ BOOTPROG, which);
+ return;
+ }
+ hdr->hdr_crc_table = crc32(table, hdr->hdr_entries * hdr->hdr_entsz);
+ hdr->hdr_crc_self = 0;
+ hdr->hdr_crc_self = crc32(hdr, hdr->hdr_size);
+ bzero(secbuf, DEV_BSIZE);
+ bcpy(hdr, secbuf, hdr->hdr_size);
+ if (drvwrite(dskp, secbuf, hdr->hdr_lba_self, 1)) {
+ printf("%s: unable to update %s GPT header\n", BOOTPROG, which);
+ return;
+ }
+}
+
+int
+gptfind(const uuid_t *uuid, struct dsk *dskp, int part)
+{
+ struct gpt_ent *ent;
+ int firsttry;
+
+ if (part >= 0) {
+ if (part == 0 || part > gpthdr->hdr_entries) {
+ printf("%s: invalid partition index\n", BOOTPROG);
+ return (-1);
+ }
+ ent = &gpttable[part - 1];
+ if (bcmp(&ent->ent_type, uuid, sizeof(uuid_t)) != 0) {
+ printf("%s: specified partition is not UFS\n",
+ BOOTPROG);
+ return (-1);
+ }
+ curent = part - 1;
+ goto found;
+ }
+
+ firsttry = (curent == -1);
+ curent++;
+ if (curent >= gpthdr->hdr_entries) {
+ curent = gpthdr->hdr_entries;
+ return (-1);
+ }
+ if (bootonce) {
+ /*
+ * First look for partition with both GPT_ENT_ATTR_BOOTME and
+ * GPT_ENT_ATTR_BOOTONCE flags.
+ */
+ for (; curent < gpthdr->hdr_entries; curent++) {
+ ent = &gpttable[curent];
+ if (bcmp(&ent->ent_type, uuid, sizeof(uuid_t)) != 0)
+ continue;
+ if (!(ent->ent_attr & GPT_ENT_ATTR_BOOTME))
+ continue;
+ if (!(ent->ent_attr & GPT_ENT_ATTR_BOOTONCE))
+ continue;
+ /* Ok, found one. */
+ goto found;
+ }
+ bootonce = 0;
+ curent = 0;
+ }
+ for (; curent < gpthdr->hdr_entries; curent++) {
+ ent = &gpttable[curent];
+ if (bcmp(&ent->ent_type, uuid, sizeof(uuid_t)) != 0)
+ continue;
+ if (!(ent->ent_attr & GPT_ENT_ATTR_BOOTME))
+ continue;
+ if (ent->ent_attr & GPT_ENT_ATTR_BOOTONCE)
+ continue;
+ /* Ok, found one. */
+ goto found;
+ }
+ if (firsttry) {
+ /*
+ * No partition with BOOTME flag was found, try to boot from
+ * first UFS partition.
+ */
+ for (curent = 0; curent < gpthdr->hdr_entries; curent++) {
+ ent = &gpttable[curent];
+ if (bcmp(&ent->ent_type, uuid, sizeof(uuid_t)) != 0)
+ continue;
+ /* Ok, found one. */
+ goto found;
+ }
+ }
+ return (-1);
+found:
+ dskp->part = curent + 1;
+ ent = &gpttable[curent];
+ dskp->start = ent->ent_lba_start;
+ if (ent->ent_attr & GPT_ENT_ATTR_BOOTONCE) {
+ /*
+ * Clear BOOTME, but leave BOOTONCE set before trying to
+ * boot from this partition.
+ */
+ if (hdr_primary_lba > 0) {
+ table_primary[curent].ent_attr &= ~GPT_ENT_ATTR_BOOTME;
+ gptupdate("primary", dskp, &hdr_primary, table_primary);
+ }
+ if (hdr_backup_lba > 0) {
+ table_backup[curent].ent_attr &= ~GPT_ENT_ATTR_BOOTME;
+ gptupdate("backup", dskp, &hdr_backup, table_backup);
+ }
+ }
+ return (0);
+}
+
+static int
+gptread_hdr(const char *which, struct dsk *dskp, struct gpt_hdr *hdr,
+ uint64_t hdrlba)
+{
+ uint32_t crc;
+
+ if (drvread(dskp, secbuf, hdrlba, 1)) {
+ printf("%s: unable to read %s GPT header\n", BOOTPROG, which);
+ return (-1);
+ }
+ bcpy(secbuf, hdr, sizeof(*hdr));
+ if (bcmp(hdr->hdr_sig, GPT_HDR_SIG, sizeof(hdr->hdr_sig)) != 0 ||
+ hdr->hdr_lba_self != hdrlba || hdr->hdr_revision < 0x00010000 ||
+ hdr->hdr_entsz < sizeof(struct gpt_ent) ||
+ hdr->hdr_entries > MAXTBLENTS || DEV_BSIZE % hdr->hdr_entsz != 0) {
+ printf("%s: invalid %s GPT header\n", BOOTPROG, which);
+ return (-1);
+ }
+ crc = hdr->hdr_crc_self;
+ hdr->hdr_crc_self = 0;
+ if (crc32(hdr, hdr->hdr_size) != crc) {
+ printf("%s: %s GPT header checksum mismatch\n", BOOTPROG,
+ which);
+ return (-1);
+ }
+ hdr->hdr_crc_self = crc;
+ return (0);
+}
+
+void
+gptbootfailed(struct dsk *dskp)
+{
+
+ if (!(gpttable[curent].ent_attr & GPT_ENT_ATTR_BOOTONCE))
+ return;
+
+ if (hdr_primary_lba > 0) {
+ table_primary[curent].ent_attr &= ~GPT_ENT_ATTR_BOOTONCE;
+ table_primary[curent].ent_attr |= GPT_ENT_ATTR_BOOTFAILED;
+ gptupdate("primary", dskp, &hdr_primary, table_primary);
+ }
+ if (hdr_backup_lba > 0) {
+ table_backup[curent].ent_attr &= ~GPT_ENT_ATTR_BOOTONCE;
+ table_backup[curent].ent_attr |= GPT_ENT_ATTR_BOOTFAILED;
+ gptupdate("backup", dskp, &hdr_backup, table_backup);
+ }
+}
+
+static void
+gptbootconv(const char *which, struct dsk *dskp, struct gpt_hdr *hdr,
+ struct gpt_ent *table)
+{
+ struct gpt_ent *ent;
+ daddr_t slba;
+ int table_updated, sector_updated;
+ int entries_per_sec, nent, part;
+
+ table_updated = 0;
+ entries_per_sec = DEV_BSIZE / hdr->hdr_entsz;
+ for (nent = 0, slba = hdr->hdr_lba_table;
+ slba < hdr->hdr_lba_table + hdr->hdr_entries / entries_per_sec;
+ slba++, nent += entries_per_sec) {
+ sector_updated = 0;
+ for (part = 0; part < entries_per_sec; part++) {
+ ent = &table[nent + part];
+ if ((ent->ent_attr & (GPT_ENT_ATTR_BOOTME |
+ GPT_ENT_ATTR_BOOTONCE |
+ GPT_ENT_ATTR_BOOTFAILED)) !=
+ GPT_ENT_ATTR_BOOTONCE) {
+ continue;
+ }
+ ent->ent_attr &= ~GPT_ENT_ATTR_BOOTONCE;
+ ent->ent_attr |= GPT_ENT_ATTR_BOOTFAILED;
+ table_updated = 1;
+ sector_updated = 1;
+ }
+ if (!sector_updated)
+ continue;
+ bcpy(&table[nent], secbuf, DEV_BSIZE);
+ if (drvwrite(dskp, secbuf, slba, 1)) {
+ printf("%s: unable to update %s GPT partition table\n",
+ BOOTPROG, which);
+ }
+ }
+ if (!table_updated)
+ return;
+ hdr->hdr_crc_table = crc32(table, hdr->hdr_entries * hdr->hdr_entsz);
+ hdr->hdr_crc_self = 0;
+ hdr->hdr_crc_self = crc32(hdr, hdr->hdr_size);
+ bzero(secbuf, DEV_BSIZE);
+ bcpy(hdr, secbuf, hdr->hdr_size);
+ if (drvwrite(dskp, secbuf, hdr->hdr_lba_self, 1))
+ printf("%s: unable to update %s GPT header\n", BOOTPROG, which);
+}
+
+static int
+gptread_table(const char *which, const uuid_t *uuid, struct dsk *dskp,
+ struct gpt_hdr *hdr, struct gpt_ent *table)
+{
+ struct gpt_ent *ent;
+ int entries_per_sec;
+ int part, nent;
+ daddr_t slba;
+
+ if (hdr->hdr_entries == 0)
+ return (0);
+
+ entries_per_sec = DEV_BSIZE / hdr->hdr_entsz;
+ slba = hdr->hdr_lba_table;
+ nent = 0;
+ for (;;) {
+ if (drvread(dskp, secbuf, slba, 1)) {
+ printf("%s: unable to read %s GPT partition table\n",
+ BOOTPROG, which);
+ return (-1);
+ }
+ ent = (struct gpt_ent *)secbuf;
+ for (part = 0; part < entries_per_sec; part++, ent++) {
+ bcpy(ent, &table[nent], sizeof(table[nent]));
+ if (++nent >= hdr->hdr_entries)
+ break;
+ }
+ if (nent >= hdr->hdr_entries)
+ break;
+ slba++;
+ }
+ if (crc32(table, nent * hdr->hdr_entsz) != hdr->hdr_crc_table) {
+ printf("%s: %s GPT table checksum mismatch\n", BOOTPROG, which);
+ return (-1);
+ }
+ return (0);
+}
+
+int
+gptread(const uuid_t *uuid, struct dsk *dskp, char *buf)
+{
+ uint64_t altlba;
+
+ /*
+ * Read and verify both GPT headers: primary and backup.
+ */
+
+ secbuf = buf;
+ hdr_primary_lba = hdr_backup_lba = 0;
+ curent = -1;
+ bootonce = 1;
+ dskp->start = 0;
+
+ if (gptread_hdr("primary", dskp, &hdr_primary, 1) == 0 &&
+ gptread_table("primary", uuid, dskp, &hdr_primary,
+ table_primary) == 0) {
+ hdr_primary_lba = hdr_primary.hdr_lba_self;
+ gpthdr = &hdr_primary;
+ gpttable = table_primary;
+ }
+
+ altlba = drvsize(dskp);
+ if (altlba > 0)
+ altlba--;
+ else if (hdr_primary_lba > 0) {
+ /*
+ * If we cannot obtain disk size, but primary header
+ * is valid, we can get backup header location from
+ * there.
+ */
+ altlba = hdr_primary.hdr_lba_alt;
+ }
+ if (altlba == 0)
+ printf("%s: unable to locate backup GPT header\n", BOOTPROG);
+ else if (gptread_hdr("backup", dskp, &hdr_backup, altlba) == 0 &&
+ gptread_table("backup", uuid, dskp, &hdr_backup,
+ table_backup) == 0) {
+ hdr_backup_lba = hdr_backup.hdr_lba_self;
+ if (hdr_primary_lba == 0) {
+ gpthdr = &hdr_backup;
+ gpttable = table_backup;
+ printf("%s: using backup GPT\n", BOOTPROG);
+ }
+ }
+
+ /*
+ * Convert all BOOTONCE without BOOTME flags into BOOTFAILED.
+ * BOOTONCE without BOOTME means that we tried to boot from it,
+ * but failed after leaving gptboot and machine was rebooted.
+ * We don't want to leave partitions marked as BOOTONCE only,
+ * because when we boot successfully start-up scripts should
+ * find at most one partition with only BOOTONCE flag and this
+ * will mean that we booted from that partition.
+ */
+ if (hdr_primary_lba != 0)
+ gptbootconv("primary", dskp, &hdr_primary, table_primary);
+ if (hdr_backup_lba != 0)
+ gptbootconv("backup", dskp, &hdr_backup, table_backup);
+
+ if (hdr_primary_lba == 0 && hdr_backup_lba == 0)
+ return (-1);
+ return (0);
+}
diff --git a/sys/boot/common/gpt.h b/sys/boot/common/gpt.h
new file mode 100644
index 000000000000..c42b40de8a3f
--- /dev/null
+++ b/sys/boot/common/gpt.h
@@ -0,0 +1,39 @@
+/*-
+ * Copyright (c) 2010 Pawel Jakub Dawidek <pjd@FreeBSD.org>
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS 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 AUTHORS 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.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _GPT_H_
+#define _GPT_H_
+
+#include <uuid.h>
+#include <drv.h>
+
+int gptread(const uuid_t *uuid, struct dsk *dskp, char *buf);
+int gptfind(const uuid_t *uuid, struct dsk *dskp, int part);
+void gptbootfailed(struct dsk *dskp);
+
+#endif /* !_GPT_H_ */
diff --git a/sys/boot/common/loader.8 b/sys/boot/common/loader.8
index 2490e3dcdbea..7ccd184a6aaf 100644
--- a/sys/boot/common/loader.8
+++ b/sys/boot/common/loader.8
@@ -643,7 +643,6 @@ by it as arguments, and it is processed by a special parser which
is not used for regular Forth commands.
.Pp
This special parser applies the following rules to the parsed text:
-.Pp
.Bl -enum
.It
All backslash characters are preprocessed.
diff --git a/sys/boot/common/ufsread.c b/sys/boot/common/ufsread.c
index cd3ba4c5d126..5d0e8af56b8e 100644
--- a/sys/boot/common/ufsread.c
+++ b/sys/boot/common/ufsread.c
@@ -223,14 +223,19 @@ fsread(ino_t inode, void *buf, size_t nbyte)
return -1;
n = INO_TO_VBO(n, inode);
#if defined(UFS1_ONLY)
- dp1 = ((struct ufs1_dinode *)blkbuf)[n];
+ memcpy(&dp1, (struct ufs1_dinode *)blkbuf + n,
+ sizeof(struct ufs1_dinode));
#elif defined(UFS2_ONLY)
- dp2 = ((struct ufs2_dinode *)blkbuf)[n];
+ memcpy(&dp2, (struct ufs2_dinode *)blkbuf + n,
+ sizeof(struct ufs2_dinode));
#else
if (fs->fs_magic == FS_UFS1_MAGIC)
- dp1 = ((struct ufs1_dinode *)blkbuf)[n];
+ memcpy(&dp1, (struct ufs1_dinode *)blkbuf + n,
+ sizeof(struct ufs1_dinode));
else
- dp2 = ((struct ufs2_dinode *)blkbuf)[n];
+ memcpy(&dp2, (struct ufs2_dinode *)blkbuf + n,
+ sizeof(struct ufs2_dinode));
+
#endif
inomap = inode;
fs_off = 0;
diff --git a/sys/boot/common/util.c b/sys/boot/common/util.c
new file mode 100644
index 000000000000..012106aef8ac
--- /dev/null
+++ b/sys/boot/common/util.c
@@ -0,0 +1,176 @@
+/*-
+ * Copyright (c) 1998 Robert Nordier
+ * Copyright (c) 2010 Pawel Jakub Dawidek <pjd@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are freely
+ * permitted provided that the above copyright notice and this
+ * paragraph and the following disclaimer are duplicated in all
+ * such forms.
+ *
+ * This software is provided "AS IS" and without any express or
+ * implied warranties, including, without limitation, the implied
+ * warranties of merchantability and fitness for a particular
+ * purpose.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+
+#include <stdarg.h>
+
+#include "cons.h"
+#include "util.h"
+
+void
+memcpy(void *dst, const void *src, int len)
+{
+ const char *s = src;
+ char *d = dst;
+
+ while (len--)
+ *d++ = *s++;
+}
+
+void
+memset(void *b, int c, size_t len)
+{
+ char *bp = b;
+
+ while (len--)
+ *bp++ = (unsigned char)c;
+}
+
+int
+memcmp(const void *b1, const void *b2, size_t len)
+{
+ const unsigned char *p1, *p2;
+
+ for (p1 = b1, p2 = b2; len > 0; len--, p1++, p2++) {
+ if (*p1 != *p2)
+ return ((*p1) - (*p2));
+ }
+ return (0);
+}
+
+int
+strcmp(const char *s1, const char *s2)
+{
+
+ for (; *s1 == *s2 && *s1 != '\0'; s1++, s2++)
+ ;
+ return ((unsigned char)*s1 - (unsigned char)*s2);
+}
+
+int
+strncmp(const char *s1, const char *s2, size_t len)
+{
+
+ for (; *s1 == *s2 && *s1 != '\0' && len > 0; len--, s1++, s2++)
+ ;
+ return ((unsigned char)*s1 - (unsigned char)*s2);
+}
+
+void
+strcpy(char *dst, const char *src)
+{
+
+ while (*src != '\0')
+ *dst++ = *src++;
+ *dst = '\0';
+}
+
+void
+strcat(char *dst, const char *src)
+{
+
+ while (*dst != '\0')
+ dst++;
+ while (*src != '\0')
+ *dst++ = *src++;
+ *dst = '\0';
+}
+
+char *
+strchr(const char *s, char ch)
+{
+
+ for (; *s != '\0'; s++) {
+ if (*s == ch)
+ return ((char *)(uintptr_t)(const void *)s);
+ }
+ return (NULL);
+}
+
+size_t
+strlen(const char *s)
+{
+ size_t len = 0;
+
+ while (*s++ != '\0')
+ len++;
+ return (len);
+}
+
+void
+printf(const char *fmt, ...)
+{
+ va_list ap;
+ const char *hex = "0123456789abcdef";
+ char buf[10], *s;
+ unsigned long long u;
+ int c, l;
+
+ va_start(ap, fmt);
+ while ((c = *fmt++) != '\0') {
+ if (c != '%') {
+ putchar(c);
+ continue;
+ }
+ l = 0;
+nextfmt:
+ c = *fmt++;
+ switch (c) {
+ case 'l':
+ l++;
+ goto nextfmt;
+ case 'c':
+ putchar(va_arg(ap, int));
+ break;
+ case 's':
+ for (s = va_arg(ap, char *); *s != '\0'; s++)
+ putchar(*s);
+ break;
+ case 'd': /* A lie, always prints unsigned */
+ case 'u':
+ case 'x':
+ switch (l) {
+ case 2:
+ u = va_arg(ap, unsigned long long);
+ break;
+ case 1:
+ u = va_arg(ap, unsigned long);
+ break;
+ default:
+ u = va_arg(ap, unsigned int);
+ break;
+ }
+ s = buf;
+ if (c == 'd' || c == 'u') {
+ do
+ *s++ = '0' + (u % 10U);
+ while (u /= 10);
+ } else {
+ do
+ *s++ = hex[u & 0xfu];
+ while (u >>= 4);
+ }
+ while (--s >= buf)
+ putchar(*s);
+ break;
+ }
+ }
+ va_end(ap);
+}
diff --git a/sys/boot/common/util.h b/sys/boot/common/util.h
new file mode 100644
index 000000000000..600c4e04c679
--- /dev/null
+++ b/sys/boot/common/util.h
@@ -0,0 +1,53 @@
+/*-
+ * Copyright (c) 2010 Pawel Jakub Dawidek <pjd@FreeBSD.org>
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS 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 AUTHORS 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.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _UTIL_H_
+#define _UTIL_H_
+
+#include <sys/types.h>
+
+#include <stdarg.h>
+
+void memcpy(void *dst, const void *src, int len);
+void memset(void *b, int c, size_t len);
+int memcmp(const void *b1, const void *b2, size_t len);
+
+#define bcpy(src, dst, len) memcpy((dst), (src), (len))
+#define bzero(buf, size) memset((buf), 0, (size))
+#define bcmp(b1, b2, len) (memcmp((b1), (b2), (len)) != 0)
+
+int strcmp(const char *s1, const char *s2);
+int strncmp(const char *s1, const char *s2, size_t len);
+void strcpy(char *dst, const char *src);
+void strcat(char *dst, const char *src);
+char *strchr(const char *s, char ch);
+size_t strlen(const char *s);
+
+void printf(const char *fmt, ...);
+
+#endif /* !_UTIL_H_ */
diff --git a/sys/boot/efi/libefi/Makefile b/sys/boot/efi/libefi/Makefile
index 55053e1042f7..beb9269d0a25 100644
--- a/sys/boot/efi/libefi/Makefile
+++ b/sys/boot/efi/libefi/Makefile
@@ -7,7 +7,7 @@ SRCS= delay.c efi_console.c efinet.c efipart.c errno.c handles.c \
libefi.c time.c
CFLAGS+= -I${.CURDIR}/../include
-CFLAGS+= -I${.CURDIR}/../include/${MACHINE_ARCH:S/amd64/i386/}
+CFLAGS+= -I${.CURDIR}/../include/${MACHINE_CPUARCH:S/amd64/i386/}
CFLAGS+= -I${.CURDIR}/../../../../lib/libstand
# Pick up the bootstrap header for some interface items
diff --git a/sys/boot/fdt/dts/dockstar.dts b/sys/boot/fdt/dts/dockstar.dts
new file mode 100644
index 000000000000..46981094e5dc
--- /dev/null
+++ b/sys/boot/fdt/dts/dockstar.dts
@@ -0,0 +1,265 @@
+/*
+ * Copyright (c) 2010 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Semihalf under sponsorship from
+ * the FreeBSD Foundation.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
+ *
+ * Seagate DockStar (Marvell SheevaPlug based) Device Tree Source.
+ *
+ * $FreeBSD$
+ */
+
+/dts-v1/;
+
+/ {
+ model = "seagate,DockStar";
+ compatible = "DockStar";
+ #address-cells = <1>;
+ #size-cells = <1>;
+
+ aliases {
+ ethernet0 = &enet0;
+ mpp = &MPP;
+ serial0 = &serial0;
+ serial1 = &serial1;
+ soc = &SOC;
+ sram = &SRAM;
+ };
+
+ cpus {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ cpu@0 {
+ device_type = "cpu";
+ compatible = "ARM,88FR131";
+ reg = <0x0>;
+ d-cache-line-size = <32>; // 32 bytes
+ i-cache-line-size = <32>; // 32 bytes
+ d-cache-size = <0x4000>; // L1, 16K
+ i-cache-size = <0x4000>; // L1, 16K
+ timebase-frequency = <0>;
+ bus-frequency = <0>;
+ clock-frequency = <0>;
+ };
+ };
+
+ memory {
+ device_type = "memory";
+ reg = <0x0 0x8000000>; // 128M at 0x0
+ };
+
+ localbus@f1000000 {
+ #address-cells = <2>;
+ #size-cells = <1>;
+ compatible = "mrvl,lbc";
+
+ /* This reflects CPU decode windows setup. */
+ ranges = <0x0 0x0f 0xf9300000 0x00100000
+ 0x1 0x1e 0xfa000000 0x00100000
+ 0x2 0x1d 0xfa100000 0x02000000
+ 0x3 0x1b 0xfc100000 0x00000400>;
+
+ nor@0,0 {
+ #address-cells = <1>;
+ #size-cells = <1>;
+ compatible = "cfi-flash";
+ reg = <0x0 0x0 0x00100000>;
+ bank-width = <2>;
+ device-width = <1>;
+ };
+
+ led@1,0 {
+ #address-cells = <1>;
+ #size-cells = <1>;
+ compatible = "led";
+ reg = <0x1 0x0 0x00100000>;
+ };
+
+ nor@2,0 {
+ #address-cells = <1>;
+ #size-cells = <1>;
+ compatible = "cfi-flash";
+ reg = <0x2 0x0 0x02000000>;
+ bank-width = <2>;
+ device-width = <1>;
+ };
+
+ nand@3,0 {
+ #address-cells = <1>;
+ #size-cells = <1>;
+ reg = <0x3 0x0 0x00100000>;
+ bank-width = <2>;
+ device-width = <1>;
+ };
+ };
+
+ SOC: soc88f6281@f1000000 {
+ #address-cells = <1>;
+ #size-cells = <1>;
+ compatible = "simple-bus";
+ ranges = <0x0 0xf1000000 0x00100000>;
+ bus-frequency = <0>;
+
+ PIC: pic@20200 {
+ interrupt-controller;
+ #address-cells = <0>;
+ #interrupt-cells = <1>;
+ reg = <0x20200 0x3c>;
+ compatible = "mrvl,pic";
+ };
+
+ timer@20300 {
+ compatible = "mrvl,timer";
+ reg = <0x20300 0x30>;
+ interrupts = <1>;
+ interrupt-parent = <&PIC>;
+ mrvl,has-wdt;
+ };
+
+ MPP: mpp@10000 {
+ #pin-cells = <2>;
+ compatible = "mrvl,mpp";
+ reg = <0x10000 0x34>;
+ pin-count = <50>;
+ pin-map = <
+ 0 1 /* MPP[0]: NF_IO[2] */
+ 1 1 /* MPP[1]: NF_IO[3] */
+ 2 1 /* MPP[2]: NF_IO[4] */
+ 3 1 /* MPP[3]: NF_IO[5] */
+ 4 1 /* MPP[4]: NF_IO[6] */
+ 5 1 /* MPP[5]: NF_IO[7] */
+ 6 1 /* MPP[6]: SYSRST_OUTn */
+ 8 2 /* MPP[8]: UA0_RTS */
+ 9 2 /* MPP[9]: UA0_CTS */
+ 10 3 /* MPP[10]: UA0_TXD */
+ 11 3 /* MPP[11]: UA0_RXD */
+ 12 1 /* MPP[12]: SD_CLK */
+ 13 1 /* MPP[13]: SD_CMD */
+ 14 1 /* MPP[14]: SD_D[0] */
+ 15 1 /* MPP[15]: SD_D[1] */
+ 16 1 /* MPP[16]: SD_D[2] */
+ 17 1 /* MPP[17]: SD_D[3] */
+ 18 1 /* MPP[18]: NF_IO[0] */
+ 19 1 /* MPP[19]: NF_IO[1] */
+ 29 1 >; /* MPP[29]: TSMP[9] */
+ };
+
+ GPIO: gpio@10100 {
+ #gpio-cells = <3>;
+ compatible = "mrvl,gpio";
+ reg = <0x10100 0x20>;
+ gpio-controller;
+ interrupts = <35 36 37 38 39 40 41>;
+ interrupt-parent = <&PIC>;
+ };
+
+ rtc@10300 {
+ compatible = "mrvl,rtc";
+ reg = <0x10300 0x08>;
+ };
+
+ twsi@11000 {
+ #address-cells = <1>;
+ #size-cells = <0>;
+ compatible = "mrvl,twsi";
+ reg = <0x11000 0x20>;
+ interrupts = <43>;
+ interrupt-parent = <&PIC>;
+ };
+
+ enet0: ethernet@72000 {
+ #address-cells = <1>;
+ #size-cells = <1>;
+ model = "V2";
+ compatible = "mrvl,ge";
+ reg = <0x72000 0x2000>;
+ ranges = <0x0 0x72000 0x2000>;
+ local-mac-address = [ 00 00 00 00 00 00 ];
+ interrupts = <12 13 14 11 46>;
+ interrupt-parent = <&PIC>;
+ phy-handle = <&phy0>;
+
+ mdio@0 {
+ #address-cells = <1>;
+ #size-cells = <0>;
+ compatible = "mrvl,mdio";
+
+ phy0: ethernet-phy@0 {
+ reg = <0x0>;
+ };
+ };
+ };
+
+ serial0: serial@12000 {
+ compatible = "ns16550";
+ reg = <0x12000 0x20>;
+ reg-shift = <2>;
+ clock-frequency = <0>;
+ interrupts = <33>;
+ interrupt-parent = <&PIC>;
+ };
+
+ serial1: serial@12100 {
+ compatible = "ns16550";
+ reg = <0x12100 0x20>;
+ reg-shift = <2>;
+ clock-frequency = <0>;
+ interrupts = <34>;
+ interrupt-parent = <&PIC>;
+ };
+
+ crypto@30000 {
+ compatible = "mrvl,cesa";
+ reg = <0x30000 0x10000>;
+ interrupts = <22>;
+ interrupt-parent = <&PIC>;
+ };
+
+ usb@50000 {
+ compatible = "mrvl,usb-ehci", "usb-ehci";
+ reg = <0x50000 0x1000>;
+ interrupts = <48 19>;
+ interrupt-parent = <&PIC>;
+ };
+
+ xor@60000 {
+ compatible = "mrvl,xor";
+ reg = <0x60000 0x1000>;
+ interrupts = <5 6 7 8>;
+ interrupt-parent = <&PIC>;
+ };
+ };
+
+ SRAM: sram@fd000000 {
+ compatible = "mrvl,cesa-sram";
+ reg = <0xfd000000 0x00100000>;
+ };
+
+ chosen {
+ stdin = "serial0";
+ stdout = "serial0";
+ };
+};
diff --git a/sys/boot/ficl/Makefile b/sys/boot/ficl/Makefile
index cdc8f7eddeed..61760d003280 100644
--- a/sys/boot/ficl/Makefile
+++ b/sys/boot/ficl/Makefile
@@ -1,20 +1,20 @@
# $FreeBSD$
#
-.PATH: ${.CURDIR}/${MACHINE_ARCH:S/amd64/i386/:S/powerpc64/powerpc/}
+.PATH: ${.CURDIR}/${MACHINE_CPUARCH:S/amd64/i386/}
BASE_SRCS= dict.c ficl.c fileaccess.c float.c loader.c math64.c \
prefix.c search.c stack.c tools.c vm.c words.c
SRCS= ${BASE_SRCS} sysdep.c softcore.c
CLEANFILES= softcore.c testmain testmain.o
CFLAGS+= -ffreestanding
-.if ${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "amd64"
+.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"
CFLAGS+= -mpreferred-stack-boundary=2
CFLAGS+= -mno-mmx -mno-3dnow -mno-sse -mno-sse2
.endif
-.if ${MACHINE_ARCH} == "i386"
+.if ${MACHINE_CPUARCH} == "i386"
CFLAGS+= -mno-sse3
.endif
-.if ${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "powerpc64" || ${MACHINE_ARCH} == "arm"
+.if ${MACHINE_CPUARCH} == "powerpc" || ${MACHINE_CPUARCH} == "arm"
CFLAGS+= -msoft-float
.endif
.if ${MACHINE} == "pc98"
@@ -41,7 +41,7 @@ SOFTWORDS= softcore.fr jhlocal.fr marker.fr freebsd.fr ficllocal.fr \
# Optional OO extension softwords
#SOFTWORDS+= oo.fr classes.fr
-.if ${MACHINE_ARCH} == "amd64"
+.if ${MACHINE_CPUARCH} == "amd64"
CFLAGS+= -m32 -march=i386 -I.
.endif
@@ -49,14 +49,14 @@ CFLAGS+= -m32 -march=i386 -I.
CFLAGS+= -m32 -mcpu=powerpc -I.
.endif
-CFLAGS+= -I${.CURDIR} -I${.CURDIR}/${MACHINE_ARCH:S/amd64/i386/:S/powerpc64/powerpc/} \
+CFLAGS+= -I${.CURDIR} -I${.CURDIR}/${MACHINE_CPUARCH:S/amd64/i386/} \
-I${.CURDIR}/../common
softcore.c: ${SOFTWORDS} softcore.awk
(cd ${.CURDIR}/softwords; cat ${SOFTWORDS} \
| awk -f softcore.awk -v datestamp="`LC_ALL=C date`") > ${.TARGET}
-.if ${MACHINE_ARCH} == "amd64"
+.if ${MACHINE_CPUARCH} == "amd64"
${SRCS:M*.c:R:S/$/.o/g}: machine
beforedepend ${OBJS}: machine
diff --git a/sys/boot/forth/beastie.4th b/sys/boot/forth/beastie.4th
index c726875907fa..d96f5791e79f 100644
--- a/sys/boot/forth/beastie.4th
+++ b/sys/boot/forth/beastie.4th
@@ -240,7 +240,10 @@ set-current
drop
10
else
- 0 0 2swap >number drop drop drop
+ 2dup s" -1" compare 0= if
+ 0 boot
+ then
+ 0 s>d 2swap >number 2drop drop
then
begin
dup tkey
diff --git a/sys/boot/forth/loader.conf b/sys/boot/forth/loader.conf
index eac8fe6886d6..4f07b912178b 100644
--- a/sys/boot/forth/loader.conf
+++ b/sys/boot/forth/loader.conf
@@ -473,6 +473,7 @@ vkbd_load="NO" # Virtual AT keyboard interface
vpd_load="NO" # Vital Product Data kernel interface
vpo_load="NO" # Parallel to SCSI interface driver
amdtemp_load="NO" # AMD K8/K10/K11 temperature monitor
+tpm_load="NO" # Trusted Platform Module
##############################################################
### ACPI settings ##########################################
diff --git a/sys/boot/i386/Makefile.inc b/sys/boot/i386/Makefile.inc
index 72c6395acf0f..a25684012c90 100644
--- a/sys/boot/i386/Makefile.inc
+++ b/sys/boot/i386/Makefile.inc
@@ -9,7 +9,7 @@ CFLAGS+= -ffreestanding -mpreferred-stack-boundary=2 \
-mno-mmx -mno-3dnow -mno-sse -mno-sse2 -mno-sse3
LDFLAGS+= -nostdlib
-.if ${MACHINE_ARCH} == "amd64"
+.if ${MACHINE_CPUARCH} == "amd64"
CFLAGS+= -m32 -march=i386
LDFLAGS+= -m elf_i386_fbsd
AFLAGS+= --32
diff --git a/sys/boot/i386/boot2/Makefile b/sys/boot/i386/boot2/Makefile
index ab5a69a8ba46..b91a43bccc4e 100644
--- a/sys/boot/i386/boot2/Makefile
+++ b/sys/boot/i386/boot2/Makefile
@@ -1,5 +1,10 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
+# XXX: clang can compile the boot code just fine, but boot2 gets too big
+CC:=${CC:C/^(.*\/)?clang$/gcc/1}
+
FILES= boot boot1 boot2
NM?= nm
@@ -94,7 +99,7 @@ boot2.h: boot1.out
ORG1=`printf "%d" ${ORG1}` \
REL1=`printf "%d" ${REL1}` > ${.TARGET}
-.if ${MACHINE_ARCH} == "amd64"
+.if ${MACHINE_CPUARCH} == "amd64"
beforedepend boot2.s: machine
CLEANFILES+= machine
machine:
diff --git a/sys/boot/i386/boot2/boot2.c b/sys/boot/i386/boot2/boot2.c
index f521fd7e071a..307d4c5df087 100644
--- a/sys/boot/i386/boot2/boot2.c
+++ b/sys/boot/i386/boot2/boot2.c
@@ -348,7 +348,7 @@ load(void)
return;
p += hdr.ex.a_data + roundup2(hdr.ex.a_bss, PAGE_SIZE);
bootinfo.bi_symtab = VTOP(p);
- memcpy(p, &hdr.ex.a_syms, sizeof(hdr.ex.a_syms));
+ *(uint32_t*)p = hdr.ex.a_syms;
p += sizeof(hdr.ex.a_syms);
if (hdr.ex.a_syms) {
if (xfsread(ino, p, hdr.ex.a_syms))
@@ -385,7 +385,7 @@ load(void)
if (xfsread(ino, &es, sizeof(es)))
return;
for (i = 0; i < 2; i++) {
- memcpy(p, &es[i].sh_size, sizeof(es[i].sh_size));
+ *(Elf32_Word *)p = es[i].sh_size;
p += sizeof(es[i].sh_size);
fs_off = es[i].sh_offset;
if (xfsread(ino, p, es[i].sh_size))
diff --git a/sys/boot/i386/common/cons.c b/sys/boot/i386/common/cons.c
new file mode 100644
index 000000000000..56febf2037fb
--- /dev/null
+++ b/sys/boot/i386/common/cons.c
@@ -0,0 +1,152 @@
+/*-
+ * Copyright (c) 1998 Robert Nordier
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are freely
+ * permitted provided that the above copyright notice and this
+ * paragraph and the following disclaimer are duplicated in all
+ * such forms.
+ *
+ * This software is provided "AS IS" and without any express or
+ * implied warranties, including, without limitation, the implied
+ * warranties of merchantability and fitness for a particular
+ * purpose.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+
+#include <machine/psl.h>
+
+#include <btxv86.h>
+
+#include "lib.h"
+#include "rbx.h"
+#include "util.h"
+#include "cons.h"
+
+#define V86_ZR(x) ((x) & PSL_Z)
+
+#define SECOND 18 /* Circa that many ticks in a second. */
+
+uint8_t ioctrl = IO_KEYBOARD;
+
+void
+putc(int c)
+{
+
+ v86.addr = 0x10;
+ v86.eax = 0xe00 | (c & 0xff);
+ v86.ebx = 0x7;
+ v86int();
+}
+
+void
+xputc(int c)
+{
+
+ if (ioctrl & IO_KEYBOARD)
+ putc(c);
+ if (ioctrl & IO_SERIAL)
+ sio_putc(c);
+}
+
+void
+putchar(int c)
+{
+
+ if (c == '\n')
+ xputc('\r');
+ xputc(c);
+}
+
+int
+getc(int fn)
+{
+
+ /*
+ * The extra comparison against zero is an attempt to work around
+ * what appears to be a bug in QEMU and Bochs. Both emulators
+ * sometimes report a key-press with scancode one and ascii zero
+ * when no such key is pressed in reality. As far as I can tell,
+ * this only happens shortly after a reboot.
+ */
+ v86.ctl = V86_FLAGS;
+ v86.addr = 0x16;
+ v86.eax = fn << 8;
+ v86int();
+ return fn == 0 ? v86.eax & 0xff : (!V86_ZR(v86.efl) && (v86.eax & 0xff));
+}
+
+int
+xgetc(int fn)
+{
+
+ if (OPT_CHECK(RBX_NOINTR))
+ return (0);
+ for (;;) {
+ if (ioctrl & IO_KEYBOARD && getc(1))
+ return (fn ? 1 : getc(0));
+ if (ioctrl & IO_SERIAL && sio_ischar())
+ return (fn ? 1 : sio_getc());
+ if (fn)
+ return (0);
+ }
+ /* NOTREACHED */
+}
+
+int
+keyhit(unsigned int secs)
+{
+ uint32_t t0, t1;
+
+ if (OPT_CHECK(RBX_NOINTR))
+ return (0);
+ secs *= SECOND;
+ t0 = 0;
+ for (;;) {
+ if (xgetc(1))
+ return (1);
+ if (secs > 0) {
+ t1 = *(uint32_t *)PTOV(0x46c);
+ if (!t0)
+ t0 = t1;
+ if (t1 < t0 || t1 >= t0 + secs)
+ return (0);
+ }
+ }
+ /* NOTREACHED */
+}
+
+void
+getstr(char *cmdstr, size_t cmdstrsize)
+{
+ char *s;
+ int c;
+
+ s = cmdstr;
+ for (;;) {
+ switch (c = xgetc(0)) {
+ case 0:
+ break;
+ case '\177':
+ case '\b':
+ if (s > cmdstr) {
+ s--;
+ printf("\b \b");
+ }
+ break;
+ case '\n':
+ case '\r':
+ *s = 0;
+ return;
+ default:
+ if (s - cmdstr < cmdstrsize - 1)
+ *s++ = c;
+ putchar(c);
+ break;
+ }
+ }
+}
diff --git a/sys/boot/i386/common/cons.h b/sys/boot/i386/common/cons.h
new file mode 100644
index 000000000000..fe00a13e7171
--- /dev/null
+++ b/sys/boot/i386/common/cons.h
@@ -0,0 +1,34 @@
+/*-
+ * Copyright (c) 1998 Robert Nordier
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are freely
+ * permitted provided that the above copyright notice and this
+ * paragraph and the following disclaimer are duplicated in all
+ * such forms.
+ *
+ * This software is provided "AS IS" and without any express or
+ * implied warranties, including, without limitation, the implied
+ * warranties of merchantability and fitness for a particular
+ * purpose.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _CONS_H_
+#define _CONS_H_
+
+#define IO_KEYBOARD 1
+#define IO_SERIAL 2
+
+extern uint8_t ioctrl;
+
+void putc(int c);
+void xputc(int c);
+void putchar(int c);
+int getc(int fn);
+int xgetc(int fn);
+int keyhit(unsigned int secs);
+void getstr(char *cmdstr, size_t cmdstrsize);
+
+#endif /* !_CONS_H_ */
diff --git a/sys/boot/i386/common/drv.c b/sys/boot/i386/common/drv.c
new file mode 100644
index 000000000000..d249bc186406
--- /dev/null
+++ b/sys/boot/i386/common/drv.c
@@ -0,0 +1,131 @@
+/*-
+ * Copyright (c) 1998 Robert Nordier
+ * Copyright (c) 2010 Pawel Jakub Dawidek <pjd@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are freely
+ * permitted provided that the above copyright notice and this
+ * paragraph and the following disclaimer are duplicated in all
+ * such forms.
+ *
+ * This software is provided "AS IS" and without any express or
+ * implied warranties, including, without limitation, the implied
+ * warranties of merchantability and fitness for a particular
+ * purpose.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+
+#include <machine/psl.h>
+
+#include <btxv86.h>
+
+#include "rbx.h"
+#include "util.h"
+#include "drv.h"
+#ifndef GPT
+#include "xreadorg.h"
+#endif
+
+#define V86_CY(x) ((x) & PSL_C)
+#define V86_ZR(x) ((x) & PSL_Z)
+
+#ifdef GPT
+uint64_t
+drvsize(struct dsk *dskp)
+{
+ unsigned char params[0x42];
+ uint64_t sectors;
+
+ *(uint32_t *)params = sizeof(params);
+
+ v86.ctl = V86_FLAGS;
+ v86.addr = 0x13;
+ v86.eax = 0x4800;
+ v86.edx = dskp->drive;
+ v86.ds = VTOPSEG(params);
+ v86.esi = VTOPOFF(params);
+ v86int();
+ if (V86_CY(v86.efl)) {
+ printf("error %u\n", v86.eax >> 8 & 0xff);
+ return (0);
+ }
+ memcpy(&sectors, params + 0x10, sizeof(sectors));
+ return (sectors);
+}
+#endif /* GPT */
+
+#ifdef GPT
+static struct {
+ uint16_t len;
+ uint16_t count;
+ uint16_t off;
+ uint16_t seg;
+ uint64_t lba;
+} packet;
+#endif /* GPT */
+
+int
+drvread(struct dsk *dskp, void *buf, daddr_t lba, unsigned nblk)
+{
+ static unsigned c = 0x2d5c7c2f;
+
+ if (!OPT_CHECK(RBX_QUIET))
+ printf("%c\b", c = c << 8 | c >> 24);
+#ifdef GPT
+ packet.len = 0x10;
+ packet.count = nblk;
+ packet.off = VTOPOFF(buf);
+ packet.seg = VTOPSEG(buf);
+ packet.lba = lba;
+ v86.ctl = V86_FLAGS;
+ v86.addr = 0x13;
+ v86.eax = 0x4200;
+ v86.edx = dskp->drive;
+ v86.ds = VTOPSEG(&packet);
+ v86.esi = VTOPOFF(&packet);
+#else /* !GPT */
+ v86.ctl = V86_ADDR | V86_CALLF | V86_FLAGS;
+ v86.addr = XREADORG; /* call to xread in boot1 */
+ v86.es = VTOPSEG(buf);
+ v86.eax = lba;
+ v86.ebx = VTOPOFF(buf);
+ v86.ecx = lba >> 32;
+ v86.edx = nblk << 8 | dskp->drive;
+#endif /* !GPT */
+ v86int();
+ if (V86_CY(v86.efl)) {
+ printf("%s: error %u lba %u\n",
+ BOOTPROG, v86.eax >> 8 & 0xff, lba);
+ return (-1);
+ }
+ return (0);
+}
+
+#ifdef GPT
+int
+drvwrite(struct dsk *dskp, void *buf, daddr_t lba, unsigned nblk)
+{
+
+ packet.len = 0x10;
+ packet.count = nblk;
+ packet.off = VTOPOFF(buf);
+ packet.seg = VTOPSEG(buf);
+ packet.lba = lba;
+ v86.ctl = V86_FLAGS;
+ v86.addr = 0x13;
+ v86.eax = 0x4300;
+ v86.edx = dskp->drive;
+ v86.ds = VTOPSEG(&packet);
+ v86.esi = VTOPOFF(&packet);
+ v86int();
+ if (V86_CY(v86.efl)) {
+ printf("error %u lba %u\n", v86.eax >> 8 & 0xff, lba);
+ return (-1);
+ }
+ return (0);
+}
+#endif /* GPT */
diff --git a/sys/boot/i386/common/drv.h b/sys/boot/i386/common/drv.h
new file mode 100644
index 000000000000..1ecfbc3af9e6
--- /dev/null
+++ b/sys/boot/i386/common/drv.h
@@ -0,0 +1,48 @@
+/*-
+ * Copyright (c) 2010 Pawel Jakub Dawidek <pjd@FreeBSD.org>
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS 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 AUTHORS 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.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _DRV_H_
+#define _DRV_H_
+
+struct dsk {
+ unsigned int drive;
+ unsigned int type;
+ unsigned int unit;
+ unsigned int slice;
+ int part;
+ daddr_t start;
+ int init;
+};
+
+int drvread(struct dsk *dskp, void *buf, daddr_t lba, unsigned nblk);
+#ifdef GPT
+int drvwrite(struct dsk *dskp, void *buf, daddr_t lba, unsigned nblk);
+uint64_t drvsize(struct dsk *dskp);
+#endif /* GPT */
+
+#endif /* !_DRV_H_ */
diff --git a/sys/boot/i386/common/rbx.h b/sys/boot/i386/common/rbx.h
new file mode 100644
index 000000000000..21371a563805
--- /dev/null
+++ b/sys/boot/i386/common/rbx.h
@@ -0,0 +1,61 @@
+/*-
+ * Copyright (c) 1998 Robert Nordier
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are freely
+ * permitted provided that the above copyright notice and this
+ * paragraph and the following disclaimer are duplicated in all
+ * such forms.
+ *
+ * This software is provided "AS IS" and without any express or
+ * implied warranties, including, without limitation, the implied
+ * warranties of merchantability and fitness for a particular
+ * purpose.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _RBX_H_
+#define _RBX_H_
+
+#define RBX_ASKNAME 0x0 /* -a */
+#define RBX_SINGLE 0x1 /* -s */
+/* 0x2 is reserved for log2(RB_NOSYNC). */
+/* 0x3 is reserved for log2(RB_HALT). */
+/* 0x4 is reserved for log2(RB_INITNAME). */
+#define RBX_DFLTROOT 0x5 /* -r */
+#define RBX_KDB 0x6 /* -d */
+/* 0x7 is reserved for log2(RB_RDONLY). */
+/* 0x8 is reserved for log2(RB_DUMP). */
+/* 0x9 is reserved for log2(RB_MINIROOT). */
+#define RBX_CONFIG 0xa /* -c */
+#define RBX_VERBOSE 0xb /* -v */
+#define RBX_SERIAL 0xc /* -h */
+#define RBX_CDROM 0xd /* -C */
+/* 0xe is reserved for log2(RB_POWEROFF). */
+#define RBX_GDB 0xf /* -g */
+#define RBX_MUTE 0x10 /* -m */
+/* 0x11 is reserved for log2(RB_SELFTEST). */
+/* 0x12 is reserved for boot programs. */
+/* 0x13 is reserved for boot programs. */
+#define RBX_PAUSE 0x14 /* -p */
+#define RBX_QUIET 0x15 /* -q */
+#define RBX_NOINTR 0x1c /* -n */
+/* 0x1d is reserved for log2(RB_MULTIPLE) and is just misnamed here. */
+#define RBX_DUAL 0x1d /* -D */
+/* 0x1f is reserved for log2(RB_BOOTINFO). */
+
+/* pass: -a, -s, -r, -d, -c, -v, -h, -C, -g, -m, -p, -D */
+#define RBX_MASK (OPT_SET(RBX_ASKNAME) | OPT_SET(RBX_SINGLE) | \
+ OPT_SET(RBX_DFLTROOT) | OPT_SET(RBX_KDB ) | \
+ OPT_SET(RBX_CONFIG) | OPT_SET(RBX_VERBOSE) | \
+ OPT_SET(RBX_SERIAL) | OPT_SET(RBX_CDROM) | \
+ OPT_SET(RBX_GDB ) | OPT_SET(RBX_MUTE) | \
+ OPT_SET(RBX_PAUSE) | OPT_SET(RBX_DUAL))
+
+#define OPT_SET(opt) (1 << (opt))
+#define OPT_CHECK(opt) ((opts) & OPT_SET(opt))
+
+extern uint32_t opts;
+
+#endif /* !_RBX_H_ */
diff --git a/sys/boot/i386/efi/Makefile b/sys/boot/i386/efi/Makefile
index 2d1104611f58..943de1190812 100644
--- a/sys/boot/i386/efi/Makefile
+++ b/sys/boot/i386/efi/Makefile
@@ -42,7 +42,7 @@ ${PROG}: ${LDSCRIPT}
CLEANFILES= vers.c loader.efi
-NEWVERSWHAT= "EFI loader" ${MACHINE_ARCH}
+NEWVERSWHAT= "EFI loader" x86
vers.c: ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version
sh ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version ${NEWVERSWHAT}
diff --git a/sys/boot/i386/gptboot/Makefile b/sys/boot/i386/gptboot/Makefile
index cc71b3575e83..a0fad610c000 100644
--- a/sys/boot/i386/gptboot/Makefile
+++ b/sys/boot/i386/gptboot/Makefile
@@ -1,6 +1,6 @@
# $FreeBSD$
-.PATH: ${.CURDIR}/../boot2
+.PATH: ${.CURDIR}/../boot2 ${.CURDIR}/../common ${.CURDIR}/../../common
FILES= gptboot
@@ -19,20 +19,24 @@ GPTBOOT_UFS?= UFS1_AND_UFS2
#GPTBOOT_UFS?= UFS2_ONLY
#GPTBOOT_UFS?= UFS1_ONLY
-CFLAGS= -Os \
+CFLAGS= -DBOOTPROG=\"gptboot\" \
+ -Os \
-fno-guess-branch-probability \
-fomit-frame-pointer \
-fno-unit-at-a-time \
-mno-align-long-strings \
-mrtd \
-mno-mmx -mno-3dnow -mno-sse -mno-sse2 -mno-sse3 \
+ -DGPT \
-D${GPTBOOT_UFS} \
-DSIOPRT=${BOOT_COMCONSOLE_PORT} \
-DSIOFMT=${B2SIOFMT} \
-DSIOSPD=${BOOT_COMCONSOLE_SPEED} \
-I${.CURDIR}/../../common \
+ -I${.CURDIR}/../common \
-I${.CURDIR}/../btx/lib -I. \
-I${.CURDIR}/../boot2 \
+ -I${.CURDIR}/../../.. \
-Wall -Waggregate-return -Wbad-function-cast -Wcast-align \
-Wmissing-declarations -Wmissing-prototypes -Wnested-externs \
-Wpointer-arith -Wshadow -Wstrict-prototypes -Wwrite-strings \
@@ -57,17 +61,17 @@ gptldr.bin: gptldr.out
gptldr.out: gptldr.o
${LD} ${LDFLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} gptldr.o
-CLEANFILES+= gptboot.bin gptboot.out gptboot.o sio.o
+CLEANFILES+= gptboot.bin gptboot.out gptboot.o sio.o ufsread.o
gptboot.bin: gptboot.out
objcopy -S -O binary gptboot.out ${.TARGET}
-gptboot.out: ${BTXCRT} gptboot.o sio.o
- ${LD} ${LDFLAGS} -Ttext ${ORG2} -o ${.TARGET} ${.ALLSRC}
+gptboot.out: ${BTXCRT} gptboot.o sio.o gpt.o crc32.o drv.o cons.o util.o
+ ${LD} ${LDFLAGS} -Ttext ${ORG2} -o ${.TARGET} ${.ALLSRC} ${LIBSTAND}
gptboot.o: ${.CURDIR}/../../common/ufsread.c
-.if ${MACHINE_ARCH} == "amd64"
+.if ${MACHINE_CPUARCH} == "amd64"
beforedepend gptboot.o: machine
CLEANFILES+= machine
machine:
diff --git a/sys/boot/i386/gptboot/gptboot.c b/sys/boot/i386/gptboot/gptboot.c
index 6939556eb0dd..5f0ab7c655cb 100644
--- a/sys/boot/i386/gptboot/gptboot.c
+++ b/sys/boot/i386/gptboot/gptboot.c
@@ -32,46 +32,11 @@ __FBSDID("$FreeBSD$");
#include <btxv86.h>
#include "lib.h"
-
-#define IO_KEYBOARD 1
-#define IO_SERIAL 2
-
-#define SECOND 18 /* Circa that many ticks in a second. */
-
-#define RBX_ASKNAME 0x0 /* -a */
-#define RBX_SINGLE 0x1 /* -s */
-/* 0x2 is reserved for log2(RB_NOSYNC). */
-/* 0x3 is reserved for log2(RB_HALT). */
-/* 0x4 is reserved for log2(RB_INITNAME). */
-#define RBX_DFLTROOT 0x5 /* -r */
-#define RBX_KDB 0x6 /* -d */
-/* 0x7 is reserved for log2(RB_RDONLY). */
-/* 0x8 is reserved for log2(RB_DUMP). */
-/* 0x9 is reserved for log2(RB_MINIROOT). */
-#define RBX_CONFIG 0xa /* -c */
-#define RBX_VERBOSE 0xb /* -v */
-#define RBX_SERIAL 0xc /* -h */
-#define RBX_CDROM 0xd /* -C */
-/* 0xe is reserved for log2(RB_POWEROFF). */
-#define RBX_GDB 0xf /* -g */
-#define RBX_MUTE 0x10 /* -m */
-/* 0x11 is reserved for log2(RB_SELFTEST). */
-/* 0x12 is reserved for boot programs. */
-/* 0x13 is reserved for boot programs. */
-#define RBX_PAUSE 0x14 /* -p */
-#define RBX_QUIET 0x15 /* -q */
-#define RBX_NOINTR 0x1c /* -n */
-/* 0x1d is reserved for log2(RB_MULTIPLE) and is just misnamed here. */
-#define RBX_DUAL 0x1d /* -D */
-/* 0x1f is reserved for log2(RB_BOOTINFO). */
-
-/* pass: -a, -s, -r, -d, -c, -v, -h, -C, -g, -m, -p, -D */
-#define RBX_MASK (OPT_SET(RBX_ASKNAME) | OPT_SET(RBX_SINGLE) | \
- OPT_SET(RBX_DFLTROOT) | OPT_SET(RBX_KDB ) | \
- OPT_SET(RBX_CONFIG) | OPT_SET(RBX_VERBOSE) | \
- OPT_SET(RBX_SERIAL) | OPT_SET(RBX_CDROM) | \
- OPT_SET(RBX_GDB ) | OPT_SET(RBX_MUTE) | \
- OPT_SET(RBX_PAUSE) | OPT_SET(RBX_DUAL))
+#include "rbx.h"
+#include "drv.h"
+#include "util.h"
+#include "cons.h"
+#include "gpt.h"
#define PATH_CONFIG "/boot.config"
#define PATH_BOOT3 "/boot/loader"
@@ -82,8 +47,6 @@ __FBSDID("$FreeBSD$");
#define NDEV 3
#define MEM_BASE 0x12
#define MEM_EXT 0x15
-#define V86_CY(x) ((x) & PSL_C)
-#define V86_ZR(x) ((x) & PSL_Z)
#define DRV_HARD 0x80
#define DRV_MASK 0x7f
@@ -93,211 +56,178 @@ __FBSDID("$FreeBSD$");
#define TYPE_MAXHARD TYPE_DA
#define TYPE_FD 2
-#define OPT_SET(opt) (1 << (opt))
-#define OPT_CHECK(opt) ((opts) & OPT_SET(opt))
-
extern uint32_t _end;
static const uuid_t freebsd_ufs_uuid = GPT_ENT_TYPE_FREEBSD_UFS;
static const char optstr[NOPT] = "DhaCcdgmnpqrsv"; /* Also 'P', 'S' */
static const unsigned char flags[NOPT] = {
- RBX_DUAL,
- RBX_SERIAL,
- RBX_ASKNAME,
- RBX_CDROM,
- RBX_CONFIG,
- RBX_KDB,
- RBX_GDB,
- RBX_MUTE,
- RBX_NOINTR,
- RBX_PAUSE,
- RBX_QUIET,
- RBX_DFLTROOT,
- RBX_SINGLE,
- RBX_VERBOSE
+ RBX_DUAL,
+ RBX_SERIAL,
+ RBX_ASKNAME,
+ RBX_CDROM,
+ RBX_CONFIG,
+ RBX_KDB,
+ RBX_GDB,
+ RBX_MUTE,
+ RBX_NOINTR,
+ RBX_PAUSE,
+ RBX_QUIET,
+ RBX_DFLTROOT,
+ RBX_SINGLE,
+ RBX_VERBOSE
};
+uint32_t opts;
static const char *const dev_nm[NDEV] = {"ad", "da", "fd"};
static const unsigned char dev_maj[NDEV] = {30, 4, 2};
-static struct dsk {
- unsigned drive;
- unsigned type;
- unsigned unit;
- int part;
- daddr_t start;
- int init;
-} dsk;
-static char cmd[512], cmddup[512];
+static struct dsk dsk;
static char kname[1024];
-static uint32_t opts;
static int comspeed = SIOSPD;
static struct bootinfo bootinfo;
-static uint8_t ioctrl = IO_KEYBOARD;
void exit(int);
-static int bcmp(const void *, const void *, size_t);
static void load(void);
-static int parse(void);
+static int parse(char *, int *);
static int xfsread(ino_t, void *, size_t);
static int dskread(void *, daddr_t, unsigned);
-static void printf(const char *,...);
-static void putchar(int);
-static void memcpy(void *, const void *, int);
static uint32_t memsize(void);
-static int drvread(void *, daddr_t, unsigned);
-static int keyhit(unsigned);
-static int xputc(int);
-static int xgetc(int);
-static int getc(int);
-
-static void
-memcpy(void *dst, const void *src, int len)
-{
- const char *s = src;
- char *d = dst;
-
- while (len--)
- *d++ = *s++;
-}
-
-static inline int
-strcmp(const char *s1, const char *s2)
-{
- for (; *s1 == *s2 && *s1; s1++, s2++);
- return (unsigned char)*s1 - (unsigned char)*s2;
-}
#include "ufsread.c"
static inline int
xfsread(ino_t inode, void *buf, size_t nbyte)
{
- if ((size_t)fsread(inode, buf, nbyte) != nbyte) {
- printf("Invalid %s\n", "format");
- return -1;
- }
- return 0;
+
+ if ((size_t)fsread(inode, buf, nbyte) != nbyte) {
+ printf("Invalid %s\n", "format");
+ return (-1);
+ }
+ return (0);
}
static inline uint32_t
memsize(void)
{
- v86.addr = MEM_EXT;
- v86.eax = 0x8800;
- v86int();
- return v86.eax;
+
+ v86.addr = MEM_EXT;
+ v86.eax = 0x8800;
+ v86int();
+ return (v86.eax);
}
-static inline void
-getstr(void)
+static int
+gptinit(void)
{
- char *s;
- int c;
- s = cmd;
- for (;;) {
- switch (c = xgetc(0)) {
- case 0:
- break;
- case '\177':
- case '\b':
- if (s > cmd) {
- s--;
- printf("\b \b");
- }
- break;
- case '\n':
- case '\r':
- *s = 0;
- return;
- default:
- if (s - cmd < sizeof(cmd) - 1)
- *s++ = c;
- putchar(c);
+ if (gptread(&freebsd_ufs_uuid, &dsk, dmadat->secbuf) == -1) {
+ printf("%s: unable to load GPT\n", BOOTPROG);
+ return (-1);
}
- }
-}
-
-static inline void
-putc(int c)
-{
- v86.addr = 0x10;
- v86.eax = 0xe00 | (c & 0xff);
- v86.ebx = 0x7;
- v86int();
+ if (gptfind(&freebsd_ufs_uuid, &dsk, dsk.part) == -1) {
+ printf("%s: no UFS partition was found\n", BOOTPROG);
+ return (-1);
+ }
+ dsk_meta = 0;
+ return (0);
}
int
main(void)
{
- int autoboot;
- ino_t ino;
+ char cmd[512], cmdtmp[512];
+ int autoboot, dskupdated;
+ ino_t ino;
- dmadat = (void *)(roundup2(__base + (int32_t)&_end, 0x10000) - __base);
- v86.ctl = V86_FLAGS;
- v86.efl = PSL_RESERVED_DEFAULT | PSL_I;
- dsk.drive = *(uint8_t *)PTOV(ARGS);
- dsk.type = dsk.drive & DRV_HARD ? TYPE_AD : TYPE_FD;
- dsk.unit = dsk.drive & DRV_MASK;
- dsk.part = -1;
- bootinfo.bi_version = BOOTINFO_VERSION;
- bootinfo.bi_size = sizeof(bootinfo);
- bootinfo.bi_basemem = 0; /* XXX will be filled by loader or kernel */
- bootinfo.bi_extmem = memsize();
- bootinfo.bi_memsizes_valid++;
+ dmadat = (void *)(roundup2(__base + (int32_t)&_end, 0x10000) - __base);
+ v86.ctl = V86_FLAGS;
+ v86.efl = PSL_RESERVED_DEFAULT | PSL_I;
+ dsk.drive = *(uint8_t *)PTOV(ARGS);
+ dsk.type = dsk.drive & DRV_HARD ? TYPE_AD : TYPE_FD;
+ dsk.unit = dsk.drive & DRV_MASK;
+ dsk.part = -1;
+ dsk.start = 0;
+ bootinfo.bi_version = BOOTINFO_VERSION;
+ bootinfo.bi_size = sizeof(bootinfo);
+ bootinfo.bi_basemem = 0; /* XXX will be filled by loader or kernel */
+ bootinfo.bi_extmem = memsize();
+ bootinfo.bi_memsizes_valid++;
- /* Process configuration file */
+ /* Process configuration file */
- autoboot = 1;
+ if (gptinit() != 0)
+ return (-1);
- if ((ino = lookup(PATH_CONFIG)))
- fsread(ino, cmd, sizeof(cmd));
+ autoboot = 1;
+ *cmd = '\0';
- if (*cmd) {
- memcpy(cmddup, cmd, sizeof(cmd));
- if (parse())
- autoboot = 0;
- if (!OPT_CHECK(RBX_QUIET))
- printf("%s: %s", PATH_CONFIG, cmddup);
- /* Do not process this command twice */
- *cmd = 0;
- }
+ for (;;) {
+ *kname = '\0';
+ ino = lookup(PATH_CONFIG);
+ if (ino > 0)
+ fsread(ino, cmd, sizeof(cmd));
+
+ if (*cmd != '\0') {
+ memcpy(cmdtmp, cmd, sizeof(cmdtmp));
+ if (parse(cmdtmp, &dskupdated))
+ break;
+ if (dskupdated && gptinit() != 0)
+ break;
+ if (!OPT_CHECK(RBX_QUIET))
+ printf("%s: %s", PATH_CONFIG, cmd);
+ *cmd = '\0';
+ }
- /*
- * Try to exec stage 3 boot loader. If interrupted by a keypress,
- * or in case of failure, try to load a kernel directly instead.
- */
+ if (autoboot && keyhit(3)) {
+ if (*kname == '\0')
+ memcpy(kname, PATH_BOOT3, sizeof(PATH_BOOT3));
+ break;
+ }
+ autoboot = 0;
- if (autoboot && !*kname) {
- memcpy(kname, PATH_BOOT3, sizeof(PATH_BOOT3));
- if (!keyhit(3*SECOND)) {
- load();
- memcpy(kname, PATH_KERNEL, sizeof(PATH_KERNEL));
+ /*
+ * Try to exec stage 3 boot loader. If interrupted by a
+ * keypress, or in case of failure, try to load a kernel
+ * directly instead.
+ */
+ if (*kname != '\0')
+ load();
+ memcpy(kname, PATH_BOOT3, sizeof(PATH_BOOT3));
+ load();
+ memcpy(kname, PATH_KERNEL, sizeof(PATH_KERNEL));
+ load();
+ gptbootfailed(&dsk);
+ if (gptfind(&freebsd_ufs_uuid, &dsk, -1) == -1)
+ break;
+ dsk_meta = 0;
}
- }
- /* Present the user with the boot2 prompt. */
+ /* Present the user with the boot2 prompt. */
- for (;;) {
- if (!autoboot || !OPT_CHECK(RBX_QUIET))
- printf("\nFreeBSD/x86 boot\n"
- "Default: %u:%s(%up%u)%s\n"
- "boot: ",
- dsk.drive & DRV_MASK, dev_nm[dsk.type], dsk.unit,
- dsk.part, kname);
- if (ioctrl & IO_SERIAL)
- sio_flush();
- if (!autoboot || keyhit(5*SECOND))
- getstr();
- else if (!autoboot || !OPT_CHECK(RBX_QUIET))
- putchar('\n');
- autoboot = 0;
- if (parse())
- putchar('\a');
- else
- load();
- }
+ for (;;) {
+ if (!OPT_CHECK(RBX_QUIET)) {
+ printf("\nFreeBSD/x86 boot\n"
+ "Default: %u:%s(%up%u)%s\n"
+ "boot: ",
+ dsk.drive & DRV_MASK, dev_nm[dsk.type], dsk.unit,
+ dsk.part, kname);
+ }
+ if (ioctrl & IO_SERIAL)
+ sio_flush();
+ *cmd = '\0';
+ if (keyhit(0))
+ getstr(cmd, sizeof(cmd));
+ else if (!OPT_CHECK(RBX_QUIET))
+ putchar('\n');
+ if (parse(cmd, &dskupdated)) {
+ putchar('\a');
+ continue;
+ }
+ if (dskupdated && gptinit() != 0)
+ continue;
+ load();
+ }
+ /* NOTREACHED */
}
/* XXX - Needed for btxld to link the boot2 binary; do not remove. */
@@ -321,8 +251,11 @@ load(void)
int fmt, i, j;
if (!(ino = lookup(kname))) {
- if (!ls)
- printf("No %s\n", kname);
+ if (!ls) {
+ printf("%s: No %s on %u:%s(%up%u)\n", BOOTPROG,
+ kname, dsk.drive & DRV_MASK, dev_nm[dsk.type], dsk.unit,
+ dsk.part);
+ }
return;
}
if (xfsread(ino, &hdr, sizeof(hdr)))
@@ -402,14 +335,15 @@ load(void)
}
static int
-parse(void)
+parse(char *cmdstr, int *dskupdated)
{
- char *arg = cmd;
+ char *arg = cmdstr;
char *ep, *p, *q;
const char *cp;
unsigned int drv;
int c, i, j;
+ *dskupdated = 0;
while ((c = *arg++)) {
if (c == ' ' || c == '\t' || c == '\n')
continue;
@@ -480,7 +414,7 @@ parse(void)
drv = dsk.unit;
dsk.drive = (dsk.type <= TYPE_MAXHARD
? DRV_HARD : 0) + drv;
- dsk_meta = 0;
+ *dskupdated = 1;
}
if ((i = ep - arg)) {
if ((size_t)i >= sizeof(kname))
@@ -496,232 +430,6 @@ parse(void)
static int
dskread(void *buf, daddr_t lba, unsigned nblk)
{
- struct gpt_hdr hdr;
- struct gpt_ent *ent;
- char *sec;
- daddr_t slba, elba;
- int part, entries_per_sec;
- if (!dsk_meta) {
- /* Read and verify GPT. */
- sec = dmadat->secbuf;
- dsk.start = 0;
- if (drvread(sec, 1, 1))
- return -1;
- memcpy(&hdr, sec, sizeof(hdr));
- if (bcmp(hdr.hdr_sig, GPT_HDR_SIG, sizeof(hdr.hdr_sig)) != 0 ||
- hdr.hdr_lba_self != 1 || hdr.hdr_revision < 0x00010000 ||
- hdr.hdr_entsz < sizeof(*ent) || DEV_BSIZE % hdr.hdr_entsz != 0) {
- printf("Invalid GPT header\n");
- return -1;
- }
-
- /* XXX: CRC check? */
-
- /*
- * If the partition isn't specified, then search for the first UFS
- * partition and hope it is /. Perhaps we should be using an OS
- * flag in the GPT entry to mark / partitions.
- *
- * If the partition is specified, then figure out the LBA for the
- * sector containing that partition index and load it.
- */
- entries_per_sec = DEV_BSIZE / hdr.hdr_entsz;
- if (dsk.part == -1) {
- slba = hdr.hdr_lba_table;
- elba = slba + hdr.hdr_entries / entries_per_sec;
- while (slba < elba && dsk.part == -1) {
- if (drvread(sec, slba, 1))
- return -1;
- for (part = 0; part < entries_per_sec; part++) {
- ent = (struct gpt_ent *)(sec + part * hdr.hdr_entsz);
- if (bcmp(&ent->ent_type, &freebsd_ufs_uuid,
- sizeof(uuid_t)) == 0) {
- dsk.part = (slba - hdr.hdr_lba_table) *
- entries_per_sec + part + 1;
- dsk.start = ent->ent_lba_start;
- break;
- }
- }
- slba++;
- }
- if (dsk.part == -1) {
- printf("No UFS partition was found\n");
- return -1;
- }
- } else {
- if (dsk.part > hdr.hdr_entries) {
- printf("Invalid partition index\n");
- return -1;
- }
- slba = hdr.hdr_lba_table + (dsk.part - 1) / entries_per_sec;
- if (drvread(sec, slba, 1))
- return -1;
- part = (dsk.part - 1) % entries_per_sec;
- ent = (struct gpt_ent *)(sec + part * hdr.hdr_entsz);
- if (bcmp(&ent->ent_type, &freebsd_ufs_uuid, sizeof(uuid_t)) != 0) {
- printf("Specified partition is not UFS\n");
- return -1;
- }
- dsk.start = ent->ent_lba_start;
- }
- /*
- * XXX: No way to detect SCSI vs. ATA currently.
- */
-#if 0
- if (!dsk.init) {
- if (d->d_type == DTYPE_SCSI)
- dsk.type = TYPE_DA;
- dsk.init++;
- }
-#endif
- }
- return drvread(buf, dsk.start + lba, nblk);
-}
-
-static void
-printf(const char *fmt,...)
-{
- va_list ap;
- char buf[10];
- char *s;
- unsigned u;
- int c;
-
- va_start(ap, fmt);
- while ((c = *fmt++)) {
- if (c == '%') {
- c = *fmt++;
- switch (c) {
- case 'c':
- putchar(va_arg(ap, int));
- continue;
- case 's':
- for (s = va_arg(ap, char *); *s; s++)
- putchar(*s);
- continue;
- case 'u':
- u = va_arg(ap, unsigned);
- s = buf;
- do
- *s++ = '0' + u % 10U;
- while (u /= 10U);
- while (--s >= buf)
- putchar(*s);
- continue;
- }
- }
- putchar(c);
- }
- va_end(ap);
- return;
-}
-
-static void
-putchar(int c)
-{
- if (c == '\n')
- xputc('\r');
- xputc(c);
-}
-
-static int
-bcmp(const void *b1, const void *b2, size_t length)
-{
- const char *p1 = b1, *p2 = b2;
-
- if (length == 0)
- return (0);
- do {
- if (*p1++ != *p2++)
- break;
- } while (--length);
- return (length);
-}
-
-static struct {
- uint16_t len;
- uint16_t count;
- uint16_t off;
- uint16_t seg;
- uint64_t lba;
-} packet;
-
-static int
-drvread(void *buf, daddr_t lba, unsigned nblk)
-{
- static unsigned c = 0x2d5c7c2f;
-
- if (!OPT_CHECK(RBX_QUIET))
- printf("%c\b", c = c << 8 | c >> 24);
- packet.len = 0x10;
- packet.count = nblk;
- packet.off = VTOPOFF(buf);
- packet.seg = VTOPSEG(buf);
- packet.lba = lba;
- v86.ctl = V86_FLAGS;
- v86.addr = 0x13;
- v86.eax = 0x4200;
- v86.edx = dsk.drive;
- v86.ds = VTOPSEG(&packet);
- v86.esi = VTOPOFF(&packet);
- v86int();
- if (V86_CY(v86.efl)) {
- printf("error %u lba %u\n", v86.eax >> 8 & 0xff, lba);
- return -1;
- }
- return 0;
-}
-
-static int
-keyhit(unsigned ticks)
-{
- uint32_t t0, t1;
-
- if (OPT_CHECK(RBX_NOINTR))
- return 0;
- t0 = 0;
- for (;;) {
- if (xgetc(1))
- return 1;
- t1 = *(uint32_t *)PTOV(0x46c);
- if (!t0)
- t0 = t1;
- if (t1 < t0 || t1 >= t0 + ticks)
- return 0;
- }
-}
-
-static int
-xputc(int c)
-{
- if (ioctrl & IO_KEYBOARD)
- putc(c);
- if (ioctrl & IO_SERIAL)
- sio_putc(c);
- return c;
-}
-
-static int
-xgetc(int fn)
-{
- if (OPT_CHECK(RBX_NOINTR))
- return 0;
- for (;;) {
- if (ioctrl & IO_KEYBOARD && getc(1))
- return fn ? 1 : getc(0);
- if (ioctrl & IO_SERIAL && sio_ischar())
- return fn ? 1 : sio_getc();
- if (fn)
- return 0;
- }
-}
-
-static int
-getc(int fn)
-{
- v86.addr = 0x16;
- v86.eax = fn << 8;
- v86int();
- return fn == 0 ? v86.eax & 0xff : !V86_ZR(v86.efl);
+ return drvread(&dsk, buf, lba + dsk.start, nblk);
}
diff --git a/sys/boot/i386/gptzfsboot/Makefile b/sys/boot/i386/gptzfsboot/Makefile
index 467d3123aec0..30a5fc78abac 100644
--- a/sys/boot/i386/gptzfsboot/Makefile
+++ b/sys/boot/i386/gptzfsboot/Makefile
@@ -1,6 +1,8 @@
# $FreeBSD$
-.PATH: ${.CURDIR}/../boot2 ${.CURDIR}/../gptboot ${.CURDIR}/../zfsboot
+.PATH: ${.CURDIR}/../boot2 ${.CURDIR}/../gptboot \
+ ${.CURDIR}/../zfsboot ${.CURDIR}/../common \
+ ${.CURDIR}/../../common
FILES= gptzfsboot
@@ -14,7 +16,8 @@ REL1= 0x700
ORG1= 0x7c00
ORG2= 0x0
-CFLAGS= -Os \
+CFLAGS= -DBOOTPROG=\"gptzfsboot\" \
+ -Os \
-fno-guess-branch-probability \
-fomit-frame-pointer \
-fno-unit-at-a-time \
@@ -26,6 +29,7 @@ CFLAGS= -Os \
-DSIOFMT=${B2SIOFMT} \
-DSIOSPD=${BOOT_COMCONSOLE_SPEED} \
-I${.CURDIR}/../../common \
+ -I${.CURDIR}/../common \
-I${.CURDIR}/../../zfs \
-I${.CURDIR}/../../../cddl/boot/zfs \
-I${.CURDIR}/../btx/lib -I. \
@@ -59,12 +63,12 @@ CLEANFILES+= gptzfsboot.bin gptzfsboot.out zfsboot.o sio.o
gptzfsboot.bin: gptzfsboot.out
objcopy -S -O binary gptzfsboot.out ${.TARGET}
-gptzfsboot.out: ${BTXCRT} zfsboot.o sio.o
+gptzfsboot.out: ${BTXCRT} zfsboot.o sio.o gpt.o drv.o cons.o util.o
${LD} ${LDFLAGS} -Ttext ${ORG2} -o ${.TARGET} ${.ALLSRC} ${LIBSTAND}
zfsboot.o: ${.CURDIR}/../../zfs/zfsimpl.c
-.if ${MACHINE_ARCH} == "amd64"
+.if ${MACHINE_CPUARCH} == "amd64"
beforedepend zfsboot.o: machine
CLEANFILES+= machine
machine:
diff --git a/sys/boot/i386/libfirewire/Makefile b/sys/boot/i386/libfirewire/Makefile
index 28f76307d8a0..191b95479e25 100644
--- a/sys/boot/i386/libfirewire/Makefile
+++ b/sys/boot/i386/libfirewire/Makefile
@@ -16,7 +16,7 @@ CFLAGS+= -I${.CURDIR}/../libi386
CFLAGS+= -Wformat -Wall
-.if ${MACHINE_ARCH} == "amd64"
+.if ${MACHINE_CPUARCH} == "amd64"
CLEANFILES+= machine
machine:
ln -sf ${.CURDIR}/../../../i386/include machine
@@ -24,7 +24,7 @@ machine:
.include <bsd.lib.mk>
-.if ${MACHINE_ARCH} == "amd64"
+.if ${MACHINE_CPUARCH} == "amd64"
beforedepend ${OBJS}: machine
.endif
diff --git a/sys/boot/i386/libi386/Makefile b/sys/boot/i386/libi386/Makefile
index f1a461a88c4e..3b897847ea8b 100644
--- a/sys/boot/i386/libi386/Makefile
+++ b/sys/boot/i386/libi386/Makefile
@@ -53,7 +53,7 @@ CFLAGS+= -I${.CURDIR}/../../common -I${.CURDIR}/../btx/lib \
# the location of libstand
CFLAGS+= -I${.CURDIR}/../../../../lib/libstand/
-.if ${MACHINE_ARCH} == "amd64"
+.if ${MACHINE_CPUARCH} == "amd64"
CLEANFILES+= machine
machine:
ln -sf ${.CURDIR}/../../../i386/include machine
@@ -61,6 +61,6 @@ machine:
.include <bsd.lib.mk>
-.if ${MACHINE_ARCH} == "amd64"
+.if ${MACHINE_CPUARCH} == "amd64"
beforedepend ${OBJS}: machine
.endif
diff --git a/sys/boot/i386/libi386/biosdisk.c b/sys/boot/i386/libi386/biosdisk.c
index cf0b03353ea7..a67a7ef9a882 100644
--- a/sys/boot/i386/libi386/biosdisk.c
+++ b/sys/boot/i386/libi386/biosdisk.c
@@ -214,10 +214,12 @@ bd_init(void)
/* sequence 0, 0x80 */
for (base = 0; base <= 0x80; base += 0x80) {
for (unit = base; (nbdinfo < MAXBDDEV); unit++) {
+#ifndef VIRTUALBOX
/* check the BIOS equipment list for number of fixed disks */
if((base == 0x80) &&
(nfd >= *(unsigned char *)PTOV(BIOS_NUMDRIVES)))
- break;
+ break;
+#endif
bdinfo[nbdinfo].bd_unit = unit;
bdinfo[nbdinfo].bd_flags = (unit < 0x80) ? BD_FLOPPY : 0;
diff --git a/sys/boot/i386/libi386/pxe.c b/sys/boot/i386/libi386/pxe.c
index 5629d90e2cb6..0caee6abe42b 100644
--- a/sys/boot/i386/libi386/pxe.c
+++ b/sys/boot/i386/libi386/pxe.c
@@ -409,6 +409,7 @@ pxe_perror(int err)
* Reach inside the libstand NFS code and dig out an NFS handle
* for the root filesystem.
*/
+#ifdef OLD_NFSV2
struct nfs_iodesc {
struct iodesc *iodesc;
off_t off;
@@ -456,6 +457,64 @@ pxe_setnfshandle(char *rootpath)
sprintf(cp, "X");
setenv("boot.nfsroot.nfshandle", buf, 1);
}
+#else /* !OLD_NFSV2 */
+
+#define NFS_V3MAXFHSIZE 64
+
+struct nfs_iodesc {
+ struct iodesc *iodesc;
+ off_t off;
+ uint32_t fhsize;
+ u_char fh[NFS_V3MAXFHSIZE];
+ /* structure truncated */
+};
+extern struct nfs_iodesc nfs_root_node;
+extern int rpc_port;
+
+static void
+pxe_rpcmountcall()
+{
+ struct iodesc *d;
+ int error;
+
+ if (!(d = socktodesc(pxe_sock)))
+ return;
+ d->myport = htons(--rpc_port);
+ d->destip = rootip;
+ if ((error = nfs_getrootfh(d, rootpath, &nfs_root_node.fhsize,
+ nfs_root_node.fh)) != 0) {
+ printf("NFS MOUNT RPC error: %d\n", error);
+ nfs_root_node.fhsize = 0;
+ }
+ nfs_root_node.iodesc = d;
+}
+
+static void
+pxe_setnfshandle(char *rootpath)
+{
+ int i;
+ u_char *fh;
+ char buf[2 * NFS_V3MAXFHSIZE + 3], *cp;
+
+ /*
+ * If NFS files were never opened, we need to do mount call
+ * ourselves. Use nfs_root_node.iodesc as flag indicating
+ * previous NFS usage.
+ */
+ if (nfs_root_node.iodesc == NULL)
+ pxe_rpcmountcall();
+
+ fh = &nfs_root_node.fh[0];
+ buf[0] = 'X';
+ cp = &buf[1];
+ for (i = 0; i < nfs_root_node.fhsize; i++, cp += 2)
+ sprintf(cp, "%02x", fh[i]);
+ sprintf(cp, "X");
+ setenv("boot.nfsroot.nfshandle", buf, 1);
+ sprintf(buf, "%d", nfs_root_node.fhsize);
+ setenv("boot.nfsroot.nfshandlelen", buf, 1);
+}
+#endif /* OLD_NFSV2 */
void
pxenv_call(int func)
diff --git a/sys/boot/i386/loader/Makefile b/sys/boot/i386/loader/Makefile
index 71307c04606d..b834ea064f36 100644
--- a/sys/boot/i386/loader/Makefile
+++ b/sys/boot/i386/loader/Makefile
@@ -6,7 +6,7 @@ MK_SSP= no
LOADER?= loader
PROG= ${LOADER}.sym
INTERNALPROG=
-NEWVERSWHAT?= "bootstrap loader" i386
+NEWVERSWHAT?= "bootstrap loader" x86
# architecture-specific loader code
SRCS= main.c conf.c vers.c
@@ -119,7 +119,7 @@ LDADD= ${LIBFICL} ${LIBFIREWIRE} ${LIBZFS} ${LIBI386} ${LIBSTAND}
.include <bsd.prog.mk>
-.if ${MACHINE_ARCH} == "amd64"
+.if ${MACHINE_CPUARCH} == "amd64"
beforedepend ${OBJS}: machine
CLEANFILES+= machine
machine:
diff --git a/sys/boot/i386/zfsboot/Makefile b/sys/boot/i386/zfsboot/Makefile
index 1653534a3257..10616e418acc 100644
--- a/sys/boot/i386/zfsboot/Makefile
+++ b/sys/boot/i386/zfsboot/Makefile
@@ -1,6 +1,6 @@
# $FreeBSD$
-.PATH: ${.CURDIR}/../boot2
+.PATH: ${.CURDIR}/../boot2 ${.CURDIR}/../common ${.CURDIR}/../../common
FILES= zfsboot
@@ -17,7 +17,8 @@ REL1= 0x700
ORG1= 0x7c00
ORG2= 0x2000
-CFLAGS= -Os -g \
+CFLAGS= -DBOOTPROG=\"zfsboot\" \
+ -Os -g \
-fno-guess-branch-probability \
-fomit-frame-pointer \
-fno-unit-at-a-time \
@@ -29,6 +30,8 @@ CFLAGS= -Os -g \
-DSIOPRT=${BOOT_COMCONSOLE_PORT} \
-DSIOFMT=${B2SIOFMT} \
-DSIOSPD=${BOOT_COMCONSOLE_SPEED} \
+ -I${.CURDIR}/../../common \
+ -I${.CURDIR}/../common \
-I${.CURDIR}/../../zfs \
-I${.CURDIR}/../../../cddl/boot/zfs \
-I${.CURDIR}/../btx/lib -I. \
@@ -57,7 +60,7 @@ zfsldr.out: zfsldr.o
${LD} ${LDFLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} zfsldr.o
CLEANFILES+= zfsboot2 zfsboot.ld zfsboot.ldr zfsboot.bin zfsboot.out \
- zfsboot.o zfsboot.s zfsboot.s.tmp zfsboot.h sio.o
+ zfsboot.o zfsboot.s zfsboot.s.tmp xreadorg.h sio.o
# We currently allow 32768 bytes for zfsboot - in practice it could be
# any size up to 3.5Mb but keeping it fixed size simplifies zfsldr.
@@ -79,26 +82,26 @@ zfsboot.ldr:
zfsboot.bin: zfsboot.out
objcopy -S -O binary zfsboot.out ${.TARGET}
-zfsboot.out: ${BTXCRT} zfsboot.o sio.o
+zfsboot.out: ${BTXCRT} zfsboot.o sio.o drv.o cons.o util.o
${LD} ${LDFLAGS} -Ttext ${ORG2} -o ${.TARGET} ${.ALLSRC} ${LIBSTAND}
zfsboot.o: zfsboot.s
-SRCS= zfsboot.c zfsboot.h
+SRCS= zfsboot.c xreadorg.h
-zfsboot.s: zfsboot.c zfsboot.h ${.CURDIR}/../../zfs/zfsimpl.c
+zfsboot.s: zfsboot.c xreadorg.h ${.CURDIR}/../../zfs/zfsimpl.c
${CC} ${CFLAGS} -S -o zfsboot.s.tmp ${.CURDIR}/zfsboot.c
sed -e '/align/d' -e '/nop/d' < zfsboot.s.tmp > zfsboot.s
rm -f zfsboot.s.tmp
-zfsboot.h: zfsldr.out
+xreadorg.h: zfsldr.out
${NM} -t d ${.ALLSRC} | awk '/([0-9])+ T xread/ \
{ x = $$1 - ORG1; \
printf("#define XREADORG %#x\n", REL1 + x) }' \
ORG1=`printf "%d" ${ORG1}` \
REL1=`printf "%d" ${REL1}` > ${.TARGET}
-.if ${MACHINE_ARCH} == "amd64"
+.if ${MACHINE_CPUARCH} == "amd64"
beforedepend zfsboot.s: machine
CLEANFILES+= machine
machine:
diff --git a/sys/boot/i386/zfsboot/zfsboot.c b/sys/boot/i386/zfsboot/zfsboot.c
index b6e5f0cfc7c4..1d0077b7a4af 100644
--- a/sys/boot/i386/zfsboot/zfsboot.c
+++ b/sys/boot/i386/zfsboot/zfsboot.c
@@ -36,50 +36,11 @@ __FBSDID("$FreeBSD$");
#include <btxv86.h>
-#ifndef GPT
-#include "zfsboot.h"
-#endif
#include "lib.h"
-
-#define IO_KEYBOARD 1
-#define IO_SERIAL 2
-
-#define SECOND 18 /* Circa that many ticks in a second. */
-
-#define RBX_ASKNAME 0x0 /* -a */
-#define RBX_SINGLE 0x1 /* -s */
-/* 0x2 is reserved for log2(RB_NOSYNC). */
-/* 0x3 is reserved for log2(RB_HALT). */
-/* 0x4 is reserved for log2(RB_INITNAME). */
-#define RBX_DFLTROOT 0x5 /* -r */
-#define RBX_KDB 0x6 /* -d */
-/* 0x7 is reserved for log2(RB_RDONLY). */
-/* 0x8 is reserved for log2(RB_DUMP). */
-/* 0x9 is reserved for log2(RB_MINIROOT). */
-#define RBX_CONFIG 0xa /* -c */
-#define RBX_VERBOSE 0xb /* -v */
-#define RBX_SERIAL 0xc /* -h */
-#define RBX_CDROM 0xd /* -C */
-/* 0xe is reserved for log2(RB_POWEROFF). */
-#define RBX_GDB 0xf /* -g */
-#define RBX_MUTE 0x10 /* -m */
-/* 0x11 is reserved for log2(RB_SELFTEST). */
-/* 0x12 is reserved for boot programs. */
-/* 0x13 is reserved for boot programs. */
-#define RBX_PAUSE 0x14 /* -p */
-#define RBX_QUIET 0x15 /* -q */
-#define RBX_NOINTR 0x1c /* -n */
-/* 0x1d is reserved for log2(RB_MULTIPLE) and is just misnamed here. */
-#define RBX_DUAL 0x1d /* -D */
-/* 0x1f is reserved for log2(RB_BOOTINFO). */
-
-/* pass: -a, -s, -r, -d, -c, -v, -h, -C, -g, -m, -p, -D */
-#define RBX_MASK (OPT_SET(RBX_ASKNAME) | OPT_SET(RBX_SINGLE) | \
- OPT_SET(RBX_DFLTROOT) | OPT_SET(RBX_KDB ) | \
- OPT_SET(RBX_CONFIG) | OPT_SET(RBX_VERBOSE) | \
- OPT_SET(RBX_SERIAL) | OPT_SET(RBX_CDROM) | \
- OPT_SET(RBX_GDB ) | OPT_SET(RBX_MUTE) | \
- OPT_SET(RBX_PAUSE) | OPT_SET(RBX_DUAL))
+#include "rbx.h"
+#include "drv.h"
+#include "util.h"
+#include "cons.h"
/* Hint to loader that we came from ZFS */
#define KARGS_FLAGS_ZFS 0x4
@@ -91,10 +52,8 @@ __FBSDID("$FreeBSD$");
#define ARGS 0x900
#define NOPT 14
#define NDEV 3
-#define V86_CY(x) ((x) & 1)
-#define V86_ZR(x) ((x) & 0x40)
-#define BIOS_NUMDRIVES 0x475
+#define BIOS_NUMDRIVES 0x475
#define DRV_HARD 0x80
#define DRV_MASK 0x7f
@@ -103,8 +62,7 @@ __FBSDID("$FreeBSD$");
#define TYPE_MAXHARD TYPE_DA
#define TYPE_FD 2
-#define OPT_SET(opt) (1 << (opt))
-#define OPT_CHECK(opt) ((opts) & OPT_SET(opt))
+#define MAXBDDEV 31
extern uint32_t _end;
@@ -128,26 +86,16 @@ static const unsigned char flags[NOPT] = {
RBX_SINGLE,
RBX_VERBOSE
};
+uint32_t opts;
static const char *const dev_nm[NDEV] = {"ad", "da", "fd"};
static const unsigned char dev_maj[NDEV] = {30, 4, 2};
-struct dsk {
- unsigned drive;
- unsigned type;
- unsigned unit;
- unsigned slice;
- unsigned part;
- int init;
- daddr_t start;
-};
static char cmd[512];
static char kname[1024];
-static uint32_t opts;
static int comspeed = SIOSPD;
static struct bootinfo bootinfo;
static uint32_t bootdev;
-static uint8_t ioctrl = IO_KEYBOARD;
vm_offset_t high_heap_base;
uint32_t bios_basemem, bios_extmem, high_heap_size;
@@ -173,79 +121,7 @@ static struct dmadat *dmadat;
void exit(int);
static void load(void);
static int parse(void);
-static void printf(const char *,...);
-static void putchar(int);
static void bios_getmem(void);
-static int drvread(struct dsk *, void *, daddr_t, unsigned);
-static int keyhit(unsigned);
-static int xputc(int);
-static int xgetc(int);
-static int getc(int);
-
-static void memcpy(void *, const void *, int);
-static void
-memcpy(void *dst, const void *src, int len)
-{
- const char *s = src;
- char *d = dst;
-
- while (len--)
- *d++ = *s++;
-}
-
-static void
-strcpy(char *dst, const char *src)
-{
- while (*src)
- *dst++ = *src++;
- *dst++ = 0;
-}
-
-static void
-strcat(char *dst, const char *src)
-{
- while (*dst)
- dst++;
- while (*src)
- *dst++ = *src++;
- *dst++ = 0;
-}
-
-static int
-strcmp(const char *s1, const char *s2)
-{
- for (; *s1 == *s2 && *s1; s1++, s2++);
- return (unsigned char)*s1 - (unsigned char)*s2;
-}
-
-static const char *
-strchr(const char *s, char ch)
-{
- for (; *s; s++)
- if (*s == ch)
- return s;
- return 0;
-}
-
-static int
-memcmp(const void *p1, const void *p2, size_t n)
-{
- const char *s1 = (const char *) p1;
- const char *s2 = (const char *) p2;
- for (; n > 0 && *s1 == *s2; s1++, s2++, n--);
- if (n)
- return (unsigned char)*s1 - (unsigned char)*s2;
- else
- return 0;
-}
-
-static void
-memset(void *p, char val, size_t n)
-{
- char *s = (char *) p;
- while (n--)
- *s++ = val;
-}
static void *
malloc(size_t n)
@@ -261,15 +137,6 @@ malloc(size_t n)
return p;
}
-static size_t
-strlen(const char *s)
-{
- size_t len = 0;
- while (*s++)
- len++;
- return len;
-}
-
static char *
strdup(const char *s)
{
@@ -324,6 +191,7 @@ vdev_read(vdev_t *vdev, void *priv, off_t off, void *buf, size_t bytes)
p = buf;
lba = off / DEV_BSIZE;
+ lba += dsk->start;
while (bytes > 0) {
nb = bytes / DEV_BSIZE;
if (nb > READ_BUF_SIZE / DEV_BSIZE)
@@ -435,46 +303,6 @@ bios_getmem(void)
}
}
-static inline void
-getstr(void)
-{
- char *s;
- int c;
-
- s = cmd;
- for (;;) {
- switch (c = xgetc(0)) {
- case 0:
- break;
- case '\177':
- case '\b':
- if (s > cmd) {
- s--;
- printf("\b \b");
- }
- break;
- case '\n':
- case '\r':
- *s = 0;
- return;
- default:
- if (s - cmd < sizeof(cmd) - 1)
- *s++ = c;
- putchar(c);
- }
- }
-}
-
-static inline void
-putc(int c)
-{
- v86.ctl = 0;
- v86.addr = 0x10;
- v86.eax = 0xe00 | (c & 0xff);
- v86.ebx = 0x7;
- v86int();
-}
-
/*
* Try to detect a device supported by the legacy int13 BIOS
*/
@@ -571,7 +399,7 @@ probe_drive(struct dsk *dsk, spa_t **spap)
* We record the first pool we find (we will try
* to boot from that one).
*/
- spap = 0;
+ spap = NULL;
/*
* This slice had a vdev. We need a new dsk
@@ -667,7 +495,12 @@ main(void)
* will find any other available pools and it may fill in missing
* vdevs for the boot pool.
*/
- for (i = 0; i < *(unsigned char *)PTOV(BIOS_NUMDRIVES); i++) {
+#ifndef VIRTUALBOX
+ for (i = 0; i < *(unsigned char *)PTOV(BIOS_NUMDRIVES); i++)
+#else
+ for (i = 0; i < MAXBDDEV; i++)
+#endif
+ {
if ((i | DRV_HARD) == *(uint8_t *)PTOV(ARGS))
continue;
@@ -682,7 +515,7 @@ main(void)
dsk->part = 0;
dsk->start = 0;
dsk->init = 0;
- probe_drive(dsk, 0);
+ probe_drive(dsk, NULL);
}
/*
@@ -692,7 +525,7 @@ main(void)
if (!spa) {
spa = STAILQ_FIRST(&zfs_pools);
if (!spa) {
- printf("No ZFS pools located, can't boot\n");
+ printf("%s: No ZFS pools located, can't boot\n", BOOTPROG);
for (;;)
;
}
@@ -721,7 +554,7 @@ main(void)
if (autoboot && !*kname) {
memcpy(kname, PATH_BOOT3, sizeof(PATH_BOOT3));
- if (!keyhit(3*SECOND)) {
+ if (!keyhit(3)) {
load();
memcpy(kname, PATH_KERNEL, sizeof(PATH_KERNEL));
}
@@ -737,8 +570,8 @@ main(void)
spa->spa_name, kname);
if (ioctrl & IO_SERIAL)
sio_flush();
- if (!autoboot || keyhit(5*SECOND))
- getstr();
+ if (!autoboot || keyhit(5))
+ getstr(cmd, sizeof(cmd));
else if (!autoboot || !OPT_CHECK(RBX_QUIET))
putchar('\n');
autoboot = 0;
@@ -853,7 +686,7 @@ load(void)
}
static int
-parse()
+parse(void)
{
char *arg = cmd;
char *ep, *p, *q;
@@ -945,222 +778,3 @@ parse()
}
return 0;
}
-
-static void
-printf(const char *fmt,...)
-{
- va_list ap;
- char buf[20];
- char *s;
- unsigned long long u;
- int c;
- int minus;
- int prec;
- int l;
- int len;
- int pad;
-
- va_start(ap, fmt);
- while ((c = *fmt++)) {
- if (c == '%') {
- minus = 0;
- prec = 0;
- l = 0;
- nextfmt:
- c = *fmt++;
- switch (c) {
- case '-':
- minus = 1;
- goto nextfmt;
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- prec = 10 * prec + (c - '0');
- goto nextfmt;
- case 'c':
- putchar(va_arg(ap, int));
- continue;
- case 'l':
- l++;
- goto nextfmt;
- case 's':
- s = va_arg(ap, char *);
- if (prec) {
- len = strlen(s);
- if (len < prec)
- pad = prec - len;
- else
- pad = 0;
- if (minus)
- while (pad--)
- putchar(' ');
- for (; *s; s++)
- putchar(*s);
- if (!minus)
- while (pad--)
- putchar(' ');
- } else {
- for (; *s; s++)
- putchar(*s);
- }
- continue;
- case 'u':
- switch (l) {
- case 2:
- u = va_arg(ap, unsigned long long);
- break;
- case 1:
- u = va_arg(ap, unsigned long);
- break;
- default:
- u = va_arg(ap, unsigned);
- break;
- }
- s = buf;
- do
- *s++ = '0' + u % 10U;
- while (u /= 10U);
- while (--s >= buf)
- putchar(*s);
- continue;
- }
- }
- putchar(c);
- }
- va_end(ap);
- return;
-}
-
-static void
-putchar(int c)
-{
- if (c == '\n')
- xputc('\r');
- xputc(c);
-}
-
-#ifdef GPT
-static struct {
- uint16_t len;
- uint16_t count;
- uint16_t off;
- uint16_t seg;
- uint64_t lba;
-} packet;
-#endif
-
-static int
-drvread(struct dsk *dsk, void *buf, daddr_t lba, unsigned nblk)
-{
-#ifdef GPT
- static unsigned c = 0x2d5c7c2f;
-
- if (!OPT_CHECK(RBX_QUIET))
- printf("%c\b", c = c << 8 | c >> 24);
- packet.len = 0x10;
- packet.count = nblk;
- packet.off = VTOPOFF(buf);
- packet.seg = VTOPSEG(buf);
- packet.lba = lba + dsk->start;
- v86.ctl = V86_FLAGS;
- v86.addr = 0x13;
- v86.eax = 0x4200;
- v86.edx = dsk->drive;
- v86.ds = VTOPSEG(&packet);
- v86.esi = VTOPOFF(&packet);
- v86int();
- if (V86_CY(v86.efl)) {
- printf("error %u lba %u\n", v86.eax >> 8 & 0xff, lba);
- return -1;
- }
- return 0;
-#else
- static unsigned c = 0x2d5c7c2f;
-
- lba += dsk->start;
- if (!OPT_CHECK(RBX_QUIET))
- printf("%c\b", c = c << 8 | c >> 24);
- v86.ctl = V86_ADDR | V86_CALLF | V86_FLAGS;
- v86.addr = XREADORG; /* call to xread in boot1 */
- v86.es = VTOPSEG(buf);
- v86.eax = lba;
- v86.ebx = VTOPOFF(buf);
- v86.ecx = lba >> 32;
- v86.edx = nblk << 8 | dsk->drive;
- v86int();
- v86.ctl = V86_FLAGS;
- if (V86_CY(v86.efl)) {
- printf("error %u lba %u\n", v86.eax >> 8 & 0xff, lba);
- return -1;
- }
- return 0;
-#endif
-}
-
-static int
-keyhit(unsigned ticks)
-{
- uint32_t t0, t1;
-
- if (OPT_CHECK(RBX_NOINTR))
- return 0;
- t0 = 0;
- for (;;) {
- if (xgetc(1))
- return 1;
- t1 = *(uint32_t *)PTOV(0x46c);
- if (!t0)
- t0 = t1;
- if (t1 < t0 || t1 >= t0 + ticks)
- return 0;
- }
-}
-
-static int
-xputc(int c)
-{
- if (ioctrl & IO_KEYBOARD)
- putc(c);
- if (ioctrl & IO_SERIAL)
- sio_putc(c);
- return c;
-}
-
-static int
-xgetc(int fn)
-{
- if (OPT_CHECK(RBX_NOINTR))
- return 0;
- for (;;) {
- if (ioctrl & IO_KEYBOARD && getc(1))
- return fn ? 1 : getc(0);
- if (ioctrl & IO_SERIAL && sio_ischar())
- return fn ? 1 : sio_getc();
- if (fn)
- return 0;
- }
-}
-
-static int
-getc(int fn)
-{
- /*
- * The extra comparison against zero is an attempt to work around
- * what appears to be a bug in QEMU and Bochs. Both emulators
- * sometimes report a key-press with scancode one and ascii zero
- * when no such key is pressed in reality. As far as I can tell,
- * this only happens shortly after a reboot.
- */
- v86.ctl = V86_FLAGS;
- v86.addr = 0x16;
- v86.eax = fn << 8;
- v86int();
- return fn == 0 ? v86.eax & 0xff : (!V86_ZR(v86.efl) && (v86.eax & 0xff));
-}
diff --git a/sys/boot/i386/zfsloader/Makefile b/sys/boot/i386/zfsloader/Makefile
index 51338e17f82b..926d69d05480 100644
--- a/sys/boot/i386/zfsloader/Makefile
+++ b/sys/boot/i386/zfsloader/Makefile
@@ -3,7 +3,7 @@
.PATH: ${.CURDIR}/../loader
LOADER= zfsloader
-NEWVERSWHAT= "ZFS enabled bootstrap loader" i386
+NEWVERSWHAT= "ZFS enabled bootstrap loader" x86
LOADER_ZFS_SUPPORT=yes
LOADER_ONLY= yes
NO_MAN= yes
diff --git a/sys/boot/ia64/common/Makefile b/sys/boot/ia64/common/Makefile
index 8261c25539cc..3204edcd6c4f 100644
--- a/sys/boot/ia64/common/Makefile
+++ b/sys/boot/ia64/common/Makefile
@@ -9,7 +9,7 @@ INTERNALLIB=
SRCS= autoload.c bootinfo.c copy.c devicename.c exec.c
CFLAGS+= -I${.CURDIR}/../../efi/include
-CFLAGS+= -I${.CURDIR}/../../efi/include/${MACHINE_ARCH}
+CFLAGS+= -I${.CURDIR}/../../efi/include/${MACHINE_CPUARCH}
CFLAGS+= -I${.CURDIR}/../../..
CFLAGS+= -I${.CURDIR}/../../../../lib/libstand
@@ -17,7 +17,7 @@ CFLAGS+= -I${.CURDIR}/../../../../lib/libstand
BOOT_FORTH= yes
CFLAGS+= -DBOOT_FORTH
CFLAGS+= -I${.CURDIR}/../../ficl
-CFLAGS+= -I${.CURDIR}/../../ficl/${MACHINE_ARCH}
+CFLAGS+= -I${.CURDIR}/../../ficl/${MACHINE_CPUARCH}
.endif
.PATH: ${.CURDIR}/../../common
diff --git a/sys/boot/ia64/efi/Makefile b/sys/boot/ia64/efi/Makefile
index 5682ac85ea61..27e81b996ab5 100644
--- a/sys/boot/ia64/efi/Makefile
+++ b/sys/boot/ia64/efi/Makefile
@@ -9,21 +9,21 @@ PROG= loader.sym
INTERNALPROG=
SRCS= conf.c efimd.c main.c pal.S start.S vers.c
-.PATH: ${.CURDIR}/../../../${MACHINE_ARCH}/${MACHINE_ARCH}
+.PATH: ${.CURDIR}/../../../${MACHINE_CPUARCH}/${MACHINE_CPUARCH}
CFLAGS+= -I${.CURDIR}/../common
CFLAGS+= -I${.CURDIR}/../../common
CFLAGS+= -I${.CURDIR}/../../efi/include
-CFLAGS+= -I${.CURDIR}/../../efi/include/${MACHINE_ARCH}
+CFLAGS+= -I${.CURDIR}/../../efi/include/${MACHINE_CPUARCH}
CFLAGS+= -I${.CURDIR}/../../..
CFLAGS+= -I${.CURDIR}/../../../../lib/libstand
-LDSCRIPT= ${.CURDIR}/ldscript.${MACHINE_ARCH}
+LDSCRIPT= ${.CURDIR}/ldscript.${MACHINE_CPUARCH}
LDFLAGS= -Wl,-T${LDSCRIPT} -shared -symbolic
${PROG}: ${LDSCRIPT}
-NEWVERSWHAT= "EFI boot" ${MACHINE_ARCH}
+NEWVERSWHAT= "EFI boot" ${MACHINE_CPUARCH}
vers.c: ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version
sh ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version ${NEWVERSWHAT}
@@ -42,7 +42,7 @@ loader.efi: loader.sym
fi
${OBJCOPY} -j .data -j .dynamic -j .dynstr -j .dynsym -j .hash \
-j .rela.dyn -j .reloc -j .sdata -j .text \
- --target=efi-app-${MACHINE_ARCH} ${.ALLSRC} ${.TARGET}
+ --target=efi-app-${MACHINE_CPUARCH} ${.ALLSRC} ${.TARGET}
CLEANFILES= vers.c loader.efi
diff --git a/sys/boot/ia64/ski/Makefile b/sys/boot/ia64/ski/Makefile
index 081fd72e8e77..5151435b94c0 100644
--- a/sys/boot/ia64/ski/Makefile
+++ b/sys/boot/ia64/ski/Makefile
@@ -17,10 +17,10 @@ CFLAGS+= -I${.CURDIR}/../../common
CFLAGS+= -I${.CURDIR}/../../..
CFLAGS+= -I${.CURDIR}/../../../../lib/libstand
-LDSCRIPT= ${.CURDIR}/ldscript.${MACHINE_ARCH}
+LDSCRIPT= ${.CURDIR}/ldscript.${MACHINE_CPUARCH}
LDFLAGS= -Wl,-T${LDSCRIPT}
-NEWVERSWHAT= "SKI boot" ${MACHINE_ARCH}
+NEWVERSWHAT= "SKI boot" ${MACHINE_CPUARCH}
vers.c: ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version
sh ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version ${NEWVERSWHAT}
diff --git a/sys/boot/ofw/libofw/Makefile b/sys/boot/ofw/libofw/Makefile
index 5ea0de972af3..945d6508988a 100644
--- a/sys/boot/ofw/libofw/Makefile
+++ b/sys/boot/ofw/libofw/Makefile
@@ -13,7 +13,7 @@ CFLAGS+= -I${.CURDIR}/../../../../lib/libstand/
CFLAGS+= -I${.CURDIR}/../../common -I${.CURDIR}/../../.. -I.
CFLAGS+= -ffreestanding
-.if ${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "powerpc64"
+.if ${MACHINE_CPUARCH} == "powerpc"
CFLAGS+= -msoft-float
SRCS+= ppc64_elf_freebsd.c
.endif
@@ -24,7 +24,7 @@ CFLAGS+= -DDISK_DEBUG
.endif
machine:
- ln -sf ${.CURDIR}/../../../${MACHINE_ARCH}/include machine
+ ln -sf ${.CURDIR}/../../../${MACHINE_CPUARCH}/include machine
CLEANFILES+= machine
diff --git a/sys/boot/ofw/libofw/ofw_copy.c b/sys/boot/ofw/libofw/ofw_copy.c
index 93e7ec656d04..781d4233a014 100644
--- a/sys/boot/ofw/libofw/ofw_copy.c
+++ b/sys/boot/ofw/libofw/ofw_copy.c
@@ -68,7 +68,7 @@ ofw_mapmem(vm_offset_t dest, const size_t len)
/*
* Trim area covered by existing mapping, if any
*/
- if (dest < (last_dest + last_len)) {
+ if (dest < (last_dest + last_len) && dest >= last_dest) {
nlen -= (last_dest + last_len) - dest;
dest = last_dest + last_len;
}
diff --git a/sys/boot/pc98/boot2/Makefile b/sys/boot/pc98/boot2/Makefile
index 63f364c2261a..dfd8607510c2 100644
--- a/sys/boot/pc98/boot2/Makefile
+++ b/sys/boot/pc98/boot2/Makefile
@@ -1,5 +1,10 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
+# XXX: clang can compile the boot code just fine, but boot2 gets too big
+CC:=${CC:C/^(.*\/)?clang$/gcc/1}
+
FILES= boot boot1 boot2
NM?= nm
diff --git a/sys/boot/pc98/boot2/boot2.c b/sys/boot/pc98/boot2/boot2.c
index 8c833ba02d82..259d5de93fe3 100644
--- a/sys/boot/pc98/boot2/boot2.c
+++ b/sys/boot/pc98/boot2/boot2.c
@@ -187,9 +187,8 @@ xfsread(ino_t inode, void *buf, size_t nbyte)
static inline uint32_t
memsize(void)
{
- u_char *p = (u_char *)PTOV(0);
-
- return *(p + 0x401) * 128 * 1024 + *(u_int16_t *)(p + 0x594) * 1024 * 1024;
+ return (*(u_char *)PTOV(0x401) * 128 * 1024 +
+ *(uint16_t *)PTOV(0x594) * 1024 * 1024);
}
static inline void
@@ -486,7 +485,7 @@ load(void)
return;
p += hdr.ex.a_data + roundup2(hdr.ex.a_bss, PAGE_SIZE);
bootinfo.bi_symtab = VTOP(p);
- memcpy(p, &hdr.ex.a_syms, sizeof(hdr.ex.a_syms));
+ *(uint32_t*)p = hdr.ex.a_syms;
p += sizeof(hdr.ex.a_syms);
if (hdr.ex.a_syms) {
if (xfsread(ino, p, hdr.ex.a_syms))
@@ -523,7 +522,7 @@ load(void)
if (xfsread(ino, &es, sizeof(es)))
return;
for (i = 0; i < 2; i++) {
- memcpy(p, &es[i].sh_size, sizeof(es[i].sh_size));
+ *(Elf32_Word *)p = es[i].sh_size;
p += sizeof(es[i].sh_size);
fs_off = es[i].sh_offset;
if (xfsread(ino, p, es[i].sh_size))
diff --git a/sys/boot/sparc64/boot1/boot1.c b/sys/boot/sparc64/boot1/boot1.c
index 813da29f4ecf..6b9fa30ace4e 100644
--- a/sys/boot/sparc64/boot1/boot1.c
+++ b/sys/boot/sparc64/boot1/boot1.c
@@ -26,9 +26,7 @@ __FBSDID("$FreeBSD$");
#define _PATH_LOADER "/boot/loader"
#define _PATH_KERNEL "/boot/kernel/kernel"
-#define BSIZEMAX 16384
-
-typedef int putc_func_t(int c, void *arg);
+typedef int putc_func_t(char c, void *arg);
typedef int32_t ofwh_t;
struct sp_data {
@@ -44,11 +42,6 @@ static char bootargs[128];
static ofwh_t bootdev;
-static struct fs fs;
-static ino_t inomap;
-static char blkbuf[BSIZEMAX];
-static unsigned int fsblks;
-
static uint32_t fs_off;
int main(int ac, char **av);
@@ -66,14 +59,13 @@ static int mount(const char *device);
static void panic(const char *fmt, ...) __dead2;
static int printf(const char *fmt, ...);
-static int putchar(int c, void *arg);
+static int putchar(char c, void *arg);
static int vprintf(const char *fmt, va_list ap);
static int vsnprintf(char *str, size_t sz, const char *fmt, va_list ap);
static int __printf(const char *fmt, putc_func_t *putc, void *arg, va_list ap);
-static int __putc(int c, void *arg);
static int __puts(const char *s, putc_func_t *putc, void *arg);
-static int __sputc(int c, void *arg);
+static int __sputc(char c, void *arg);
static char *__uitoa(char *buf, u_int val, int base);
static char *__ultoa(char *buf, u_long val, int base);
@@ -83,19 +75,18 @@ static char *__ultoa(char *buf, u_long val, int base);
typedef u_int64_t ofwcell_t;
typedef u_int32_t u_ofwh_t;
typedef int (*ofwfp_t)(ofwcell_t []);
-ofwfp_t ofw; /* the prom Open Firmware entry */
+static ofwfp_t ofw; /* the PROM Open Firmware entry */
void ofw_init(int, int, int, int, ofwfp_t);
-ofwh_t ofw_finddevice(const char *);
-ofwh_t ofw_open(const char *);
-int ofw_getprop(ofwh_t, const char *, void *, size_t);
-int ofw_read(ofwh_t, void *, size_t);
-int ofw_write(ofwh_t, const void *, size_t);
-int ofw_seek(ofwh_t, u_int64_t);
-void ofw_exit(void) __dead2;
+static ofwh_t ofw_finddevice(const char *);
+static ofwh_t ofw_open(const char *);
+static int ofw_getprop(ofwh_t, const char *, void *, size_t);
+static int ofw_read(ofwh_t, void *, size_t);
+static int ofw_write(ofwh_t, const void *, size_t);
+static int ofw_seek(ofwh_t, u_int64_t);
+static void ofw_exit(void) __dead2;
-ofwh_t bootdevh;
-ofwh_t stdinh, stdouth;
+static ofwh_t stdinh, stdouth;
/*
* This has to stay here, as the PROM seems to ignore the
@@ -138,7 +129,7 @@ ofw_init(int d, int d1, int d2, int d3, ofwfp_t ofwaddr)
exit(main(ac, av));
}
-ofwh_t
+static ofwh_t
ofw_finddevice(const char *name)
{
ofwcell_t args[] = {
@@ -156,7 +147,7 @@ ofw_finddevice(const char *name)
return (args[4]);
}
-int
+static int
ofw_getprop(ofwh_t ofwh, const char *name, void *buf, size_t len)
{
ofwcell_t args[] = {
@@ -178,7 +169,7 @@ ofw_getprop(ofwh_t ofwh, const char *name, void *buf, size_t len)
return (0);
}
-ofwh_t
+static ofwh_t
ofw_open(const char *path)
{
ofwcell_t args[] = {
@@ -196,7 +187,7 @@ ofw_open(const char *path)
return (args[4]);
}
-int
+static int
ofw_close(ofwh_t devh)
{
ofwcell_t args[] = {
@@ -213,12 +204,12 @@ ofw_close(ofwh_t devh)
return (0);
}
-int
+static int
ofw_read(ofwh_t devh, void *buf, size_t len)
{
ofwcell_t args[] = {
(ofwcell_t)"read",
- 4,
+ 3,
1,
(u_ofwh_t)devh,
(ofwcell_t)buf,
@@ -233,7 +224,7 @@ ofw_read(ofwh_t devh, void *buf, size_t len)
return (0);
}
-int
+static int
ofw_write(ofwh_t devh, const void *buf, size_t len)
{
ofwcell_t args[] = {
@@ -253,12 +244,12 @@ ofw_write(ofwh_t devh, const void *buf, size_t len)
return (0);
}
-int
+static int
ofw_seek(ofwh_t devh, u_int64_t off)
{
ofwcell_t args[] = {
(ofwcell_t)"seek",
- 4,
+ 3,
1,
(u_ofwh_t)devh,
off >> 32,
@@ -273,7 +264,7 @@ ofw_seek(ofwh_t devh, u_int64_t off)
return (0);
}
-void
+static void
ofw_exit(void)
{
ofwcell_t args[3];
@@ -299,6 +290,7 @@ bcopy(const void *src, void *dst, size_t len)
static void
memcpy(void *dst, const void *src, size_t len)
{
+
bcopy(src, dst, len);
}
@@ -314,6 +306,7 @@ bzero(void *b, size_t len)
static int
strcmp(const char *s1, const char *s2)
{
+
for (; *s1 == *s2 && *s1; s1++, s2++)
;
return ((u_char)*s1 - (u_char)*s2);
@@ -431,6 +424,7 @@ load(const char *fname)
static int
dskread(void *buf, u_int64_t lba, int nblk)
{
+
/*
* The Open Firmware should open the correct partition for us.
* That means, if we read from offset zero on an open instance handle,
@@ -468,7 +462,7 @@ printf(const char *fmt, ...)
}
static int
-putchar(int c, void *arg)
+putchar(char c, void *arg)
{
char buf;
@@ -614,7 +608,7 @@ reswitch: c = *fmt++;
}
static int
-__sputc(int c, void *arg)
+__sputc(char c, void *arg)
{
struct sp_data *sp;
diff --git a/sys/boot/uboot/lib/Makefile b/sys/boot/uboot/lib/Makefile
index 11088f133f2d..039a282553ce 100644
--- a/sys/boot/uboot/lib/Makefile
+++ b/sys/boot/uboot/lib/Makefile
@@ -23,7 +23,7 @@ CFLAGS+= -DDISK_DEBUG
.endif
machine:
- ln -sf ${.CURDIR}/../../../${MACHINE_ARCH}/include machine
+ ln -sf ${.CURDIR}/../../../${MACHINE_CPUARCH}/include machine
CLEANFILES+= machine
diff --git a/sys/boot/zfs/Makefile b/sys/boot/zfs/Makefile
index b48804bc37aa..91525d77c8d0 100644
--- a/sys/boot/zfs/Makefile
+++ b/sys/boot/zfs/Makefile
@@ -5,28 +5,29 @@ INTERNALLIB=
SRCS+= zfs.c
+CFLAGS+= -DBOOTPROG=\"zfsloader\"
CFLAGS+= -I${.CURDIR}/../common -I${.CURDIR}/../.. -I.
CFLAGS+= -I${.CURDIR}/../../../lib/libstand
CFLAGS+= -I${.CURDIR}/../../cddl/boot/zfs
CFLAGS+= -ffreestanding
-.if ${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "amd64"
+.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"
CFLAGS+= -mpreferred-stack-boundary=2
CFLAGS+= -mno-mmx -mno-3dnow -mno-sse -mno-sse2
.endif
-.if ${MACHINE_ARCH} == "i386"
+.if ${MACHINE_CPUARCH} == "i386"
CFLAGS+= -mno-sse3
.endif
-.if ${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "arm"
+.if ${MACHINE_CPUARCH} == "powerpc" || ${MACHINE_CPUARCH} == "arm"
CFLAGS+= -msoft-float
.endif
-.if ${MACHINE_ARCH} == "amd64"
+.if ${MACHINE_CPUARCH} == "amd64"
CFLAGS+= -m32 -march=i386
.endif
CFLAGS+= -Wformat -Wall
-.if ${MACHINE_ARCH} == "amd64"
+.if ${MACHINE_CPUARCH} == "amd64"
CLEANFILES+= machine
machine:
ln -sf ${.CURDIR}/../../i386/include machine
@@ -34,6 +35,6 @@ machine:
.include <bsd.lib.mk>
-.if ${MACHINE_ARCH} == "amd64"
+.if ${MACHINE_CPUARCH} == "amd64"
beforedepend ${OBJS}: machine
.endif
diff --git a/sys/boot/zfs/zfs.c b/sys/boot/zfs/zfs.c
index 5aec76676f16..a995f574f7ba 100644
--- a/sys/boot/zfs/zfs.c
+++ b/sys/boot/zfs/zfs.c
@@ -45,6 +45,8 @@ __FBSDID("$FreeBSD$");
#include "zfsimpl.c"
+#define MAXBDDEV 31
+
static int zfs_open(const char *path, struct open_file *f);
static int zfs_write(struct open_file *f, void *buf, size_t size, size_t *resid);
static int zfs_close(struct open_file *f);
@@ -402,7 +404,7 @@ zfs_dev_init(void)
* diskN, diskNpM or diskNsM.
*/
zfs_init();
- for (unit = 0; unit < 32 /* XXX */; unit++) {
+ for (unit = 0; unit < MAXBDDEV; unit++) {
sprintf(devname, "disk%d:", unit);
fd = open(devname, O_RDONLY);
if (fd == -1)
diff --git a/sys/boot/zfs/zfsimpl.c b/sys/boot/zfs/zfsimpl.c
index e645ebaa6cd1..cb0912099c12 100644
--- a/sys/boot/zfs/zfsimpl.c
+++ b/sys/boot/zfs/zfsimpl.c
@@ -376,6 +376,27 @@ vdev_mirror_read(vdev_t *vdev, const blkptr_t *bp, void *buf,
return (rc);
}
+static int
+vdev_replacing_read(vdev_t *vdev, const blkptr_t *bp, void *buf,
+ off_t offset, size_t bytes)
+{
+ vdev_t *kid;
+
+ /*
+ * Here we should have two kids:
+ * First one which is the one we are replacing and we can trust
+ * only this one to have valid data, but it might not be present.
+ * Second one is that one we are replacing with. It is most likely
+ * healthy, but we can't trust it has needed data, so we won't use it.
+ */
+ kid = STAILQ_FIRST(&vdev->v_children);
+ if (kid == NULL)
+ return (EIO);
+ if (kid->v_state != VDEV_STATE_HEALTHY)
+ return (EIO);
+ return (kid->v_read(kid, bp, buf, offset, bytes));
+}
+
static vdev_t *
vdev_find(uint64_t guid)
{
@@ -416,7 +437,7 @@ vdev_init_from_nvlist(const unsigned char *nvlist, vdev_t **vdevp, int is_newer)
vdev_t *vdev, *kid;
const unsigned char *kids;
int nkids, i, is_new;
- uint64_t is_offline, is_faulted, is_degraded, is_removed;
+ uint64_t is_offline, is_faulted, is_degraded, is_removed, isnt_present;
if (nvlist_find(nvlist, ZPOOL_CONFIG_GUID,
DATA_TYPE_UINT64, 0, &guid)
@@ -430,12 +451,13 @@ vdev_init_from_nvlist(const unsigned char *nvlist, vdev_t **vdevp, int is_newer)
if (strcmp(type, VDEV_TYPE_MIRROR)
&& strcmp(type, VDEV_TYPE_DISK)
- && strcmp(type, VDEV_TYPE_RAIDZ)) {
+ && strcmp(type, VDEV_TYPE_RAIDZ)
+ && strcmp(type, VDEV_TYPE_REPLACING)) {
printf("ZFS: can only boot from disk, mirror or raidz vdevs\n");
return (EIO);
}
- is_offline = is_removed = is_faulted = is_degraded = 0;
+ is_offline = is_removed = is_faulted = is_degraded = isnt_present = 0;
nvlist_find(nvlist, ZPOOL_CONFIG_OFFLINE, DATA_TYPE_UINT64, 0,
&is_offline);
@@ -445,6 +467,8 @@ vdev_init_from_nvlist(const unsigned char *nvlist, vdev_t **vdevp, int is_newer)
&is_faulted);
nvlist_find(nvlist, ZPOOL_CONFIG_DEGRADED, DATA_TYPE_UINT64, 0,
&is_degraded);
+ nvlist_find(nvlist, ZPOOL_CONFIG_NOT_PRESENT, DATA_TYPE_UINT64, 0,
+ &isnt_present);
vdev = vdev_find(guid);
if (!vdev) {
@@ -454,6 +478,8 @@ vdev_init_from_nvlist(const unsigned char *nvlist, vdev_t **vdevp, int is_newer)
vdev = vdev_create(guid, vdev_mirror_read);
else if (!strcmp(type, VDEV_TYPE_RAIDZ))
vdev = vdev_create(guid, vdev_raidz_read);
+ else if (!strcmp(type, VDEV_TYPE_REPLACING))
+ vdev = vdev_create(guid, vdev_replacing_read);
else
vdev = vdev_create(guid, vdev_disk_read);
@@ -470,12 +496,7 @@ vdev_init_from_nvlist(const unsigned char *nvlist, vdev_t **vdevp, int is_newer)
vdev->v_nparity = 0;
if (nvlist_find(nvlist, ZPOOL_CONFIG_PATH,
DATA_TYPE_STRING, 0, &path) == 0) {
- if (strlen(path) > 5
- && path[0] == '/'
- && path[1] == 'd'
- && path[2] == 'e'
- && path[3] == 'v'
- && path[4] == '/')
+ if (strncmp(path, "/dev/", 5) == 0)
path += 5;
vdev->v_name = strdup(path);
} else {
@@ -488,7 +509,16 @@ vdev_init_from_nvlist(const unsigned char *nvlist, vdev_t **vdevp, int is_newer)
vdev->v_name = strdup(type);
}
}
+ } else {
+ is_new = 0;
+ }
+ if (is_new || is_newer) {
+ /*
+ * This is either new vdev or we've already seen this vdev,
+ * but from an older vdev label, so let's refresh its state
+ * from the newer label.
+ */
if (is_offline)
vdev->v_state = VDEV_STATE_OFFLINE;
else if (is_removed)
@@ -497,28 +527,10 @@ vdev_init_from_nvlist(const unsigned char *nvlist, vdev_t **vdevp, int is_newer)
vdev->v_state = VDEV_STATE_FAULTED;
else if (is_degraded)
vdev->v_state = VDEV_STATE_DEGRADED;
+ else if (isnt_present)
+ vdev->v_state = VDEV_STATE_CANT_OPEN;
else
vdev->v_state = VDEV_STATE_HEALTHY;
- } else {
- is_new = 0;
-
- if (is_newer) {
- /*
- * We've already seen this vdev, but from an older
- * vdev label, so let's refresh its state from the
- * newer label.
- */
- if (is_offline)
- vdev->v_state = VDEV_STATE_OFFLINE;
- else if (is_removed)
- vdev->v_state = VDEV_STATE_REMOVED;
- else if (is_faulted)
- vdev->v_state = VDEV_STATE_FAULTED;
- else if (is_degraded)
- vdev->v_state = VDEV_STATE_DEGRADED;
- else
- vdev->v_state = VDEV_STATE_HEALTHY;
- }
}
rc = nvlist_find(nvlist, ZPOOL_CONFIG_CHILDREN,
@@ -665,7 +677,7 @@ pager_printf(const char *fmt, ...)
#endif
-#define STATUS_FORMAT " %-16s %-10s\n"
+#define STATUS_FORMAT " %s %s\n"
static void
print_state(int indent, const char *name, vdev_state_t state)
@@ -754,6 +766,7 @@ vdev_probe(vdev_phys_read_t *read, void *read_priv, spa_t **spap)
uint64_t val;
uint64_t guid;
uint64_t pool_txg, pool_guid;
+ uint64_t is_log;
const char *pool_name;
const unsigned char *vdevs;
int i, rc, is_newer;
@@ -830,6 +843,12 @@ vdev_probe(vdev_phys_read_t *read, void *read_priv, spa_t **spap)
return (EIO);
}
+ is_log = 0;
+ (void) nvlist_find(nvlist, ZPOOL_CONFIG_IS_LOG, DATA_TYPE_UINT64, 0,
+ &is_log);
+ if (is_log)
+ return (EIO);
+
/*
* Create the pool if this is the first time we've seen it.
*/
@@ -1369,7 +1388,7 @@ fzap_list(spa_t *spa, const dnode_phys_t *dnode)
*/
value = fzap_leaf_value(&zl, zc);
- printf("%-32s 0x%llx\n", name, value);
+ printf("%s 0x%llx\n", name, value);
}
}