1998-08-21 03:17:42 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1998 Michael Smith <msmith@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 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.
|
|
|
|
*/
|
|
|
|
|
2003-08-25 23:28:32 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1998-08-21 03:17:42 +00:00
|
|
|
/*
|
|
|
|
* MD bootstrap main() and assorted miscellaneous
|
|
|
|
* commands.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stand.h>
|
2012-05-09 08:23:24 +00:00
|
|
|
#include <stddef.h>
|
1998-08-21 03:17:42 +00:00
|
|
|
#include <string.h>
|
1998-09-26 01:31:10 +00:00
|
|
|
#include <machine/bootinfo.h>
|
2012-09-18 08:53:11 +00:00
|
|
|
#include <machine/cpufunc.h>
|
2008-08-08 19:41:20 +00:00
|
|
|
#include <machine/psl.h>
|
loader: zfs reader should check all labels
The current zfs reader is only checking first label from each device, however,
we do have 4 labels on device and we should check all 4 to be protected
against disk failures and incomplete label updates.
The difficulty is about the fact that 2 label copies are in front of the
pool data, and 2 are at the end, which means, we have to know the size of
the pool data area.
Since we have now the mechanism from common/disk.c to use the partition
information, it does help us in this task; however, there are still some
corner cases.
Namely, if the pool is created without partition, directly on the disk,
and firmware will give us the wrong size for the disk, we only can check
the first two label copies.
Reviewed by: allanjude
Differential Revision: https://reviews.freebsd.org/D10203
2017-04-06 18:17:29 +00:00
|
|
|
#include <sys/disk.h>
|
1998-09-26 01:31:10 +00:00
|
|
|
#include <sys/reboot.h>
|
Implement boot-time encryption key passing (keybuf)
This patch adds a general mechanism for providing encryption keys to the
kernel from the boot loader. This is intended to enable GELI support at
boot time, providing a better mechanism for passing keys to the kernel
than environment variables. It is designed to be extensible to other
applications, and can easily handle multiple encrypted volumes with
different keys.
This mechanism is currently used by the pending GELI EFI work.
Additionally, this mechanism can potentially be used to interface with
GRUB, opening up options for coreboot+GRUB configurations with completely
encrypted disks.
Another benefit over the existing system is that it does not require
re-deriving the user key from the password at each boot stage.
Most of this patch was written by Eric McCorkle. It was extended by
Allan Jude with a number of minor enhancements and extending the keybuf
feature into boot2.
GELI user keys are now derived once, in boot2, then passed to the loader,
which reuses the key, then passes it to the kernel, where the GELI module
destroys the keybuf after decrypting the volumes.
Submitted by: Eric McCorkle <eric@metricspace.net> (Original Version)
Reviewed by: oshogbo (earlier version), cem (earlier version)
MFC after: 3 weeks
Relnotes: yes
Sponsored by: ScaleEngine Inc.
Differential Revision: https://reviews.freebsd.org/D9575
2017-04-01 05:05:22 +00:00
|
|
|
#include <common/drv.h>
|
1998-08-21 03:17:42 +00:00
|
|
|
|
|
|
|
#include "bootstrap.h"
|
2012-05-09 08:04:29 +00:00
|
|
|
#include "common/bootargs.h"
|
1998-08-21 03:17:42 +00:00
|
|
|
#include "libi386/libi386.h"
|
2015-04-06 06:55:47 +00:00
|
|
|
#include "libi386/smbios.h"
|
1998-09-17 23:52:16 +00:00
|
|
|
#include "btxv86.h"
|
1998-08-21 03:17:42 +00:00
|
|
|
|
2012-05-12 09:03:30 +00:00
|
|
|
#ifdef LOADER_ZFS_SUPPORT
|
2018-07-08 07:42:58 +00:00
|
|
|
#include "libzfs.h"
|
2012-05-12 09:03:30 +00:00
|
|
|
#endif
|
|
|
|
|
2012-05-09 08:04:29 +00:00
|
|
|
CTASSERT(sizeof(struct bootargs) == BOOTARGS_SIZE);
|
|
|
|
CTASSERT(offsetof(struct bootargs, bootinfo) == BA_BOOTINFO);
|
|
|
|
CTASSERT(offsetof(struct bootargs, bootflags) == BA_BOOTFLAGS);
|
|
|
|
CTASSERT(offsetof(struct bootinfo, bi_size) == BI_SIZE);
|
2000-01-27 21:21:01 +00:00
|
|
|
|
1998-09-26 01:31:10 +00:00
|
|
|
/* Arguments passed in from the boot1/boot2 loader */
|
2012-05-09 08:04:29 +00:00
|
|
|
static struct bootargs *kargs;
|
1998-09-26 01:31:10 +00:00
|
|
|
|
2018-03-13 16:33:00 +00:00
|
|
|
static uint32_t initial_howto;
|
|
|
|
static uint32_t initial_bootdev;
|
1998-10-04 09:12:54 +00:00
|
|
|
static struct bootinfo *initial_bootinfo;
|
1998-09-26 01:31:10 +00:00
|
|
|
|
1998-08-21 03:17:42 +00:00
|
|
|
struct arch_switch archsw; /* MI/MD interface boundary */
|
|
|
|
|
1998-10-02 16:33:43 +00:00
|
|
|
static void extract_currdev(void);
|
1998-10-21 20:10:33 +00:00
|
|
|
static int isa_inb(int port);
|
|
|
|
static void isa_outb(int port, int value);
|
2000-08-03 09:14:02 +00:00
|
|
|
void exit(int code);
|
2016-03-16 23:12:19 +00:00
|
|
|
#ifdef LOADER_GELI_SUPPORT
|
Implement boot-time encryption key passing (keybuf)
This patch adds a general mechanism for providing encryption keys to the
kernel from the boot loader. This is intended to enable GELI support at
boot time, providing a better mechanism for passing keys to the kernel
than environment variables. It is designed to be extensible to other
applications, and can easily handle multiple encrypted volumes with
different keys.
This mechanism is currently used by the pending GELI EFI work.
Additionally, this mechanism can potentially be used to interface with
GRUB, opening up options for coreboot+GRUB configurations with completely
encrypted disks.
Another benefit over the existing system is that it does not require
re-deriving the user key from the password at each boot stage.
Most of this patch was written by Eric McCorkle. It was extended by
Allan Jude with a number of minor enhancements and extending the keybuf
feature into boot2.
GELI user keys are now derived once, in boot2, then passed to the loader,
which reuses the key, then passes it to the kernel, where the GELI module
destroys the keybuf after decrypting the volumes.
Submitted by: Eric McCorkle <eric@metricspace.net> (Original Version)
Reviewed by: oshogbo (earlier version), cem (earlier version)
MFC after: 3 weeks
Relnotes: yes
Sponsored by: ScaleEngine Inc.
Differential Revision: https://reviews.freebsd.org/D9575
2017-04-01 05:05:22 +00:00
|
|
|
#include "geliboot.h"
|
2016-03-16 23:12:19 +00:00
|
|
|
struct geli_boot_args *gargs;
|
Fix args cross-threading between gptboot(8) and loader(8) with zfs support.
When loader(8) is built with zfs support enabled, it assumes that any extarg
data present is a zfs_boot_args struct, but if the first-stage loader was
gptboot(8) the extarg data is actually a geli_boot_args struct. Luckily,
zfsboot(8) and gptzfsboot(8) have always passed KARGS_FLAGS_ZFS along with
KARGS_FLAGS_EXTARG, so we can use KARGS_FLAGS_ZFS to decide whether the
extarg data is a zfs_boot_args struct.
To avoid similar problems in the future, gptboot(8) now passes a new
KARGS_FLAGS_GELI to indicate that extarg data is geli_boot_args. In
loader(8), if the neither KARGS_FLAGS_ZFS nor KARGS_FLAGS_GELI is set but
extarg data is present (which will be the case for gptboot compiled before
this change), we now check for the known size of the geli_boot_args struct
passed by the older versions of gptboot as a way of confirming what type of
extarg data is present.
In a semi-related tidying up, since loader's main() has already decided
what type of extarg data is present and set the global 'zargs' var
accordingly, don't repeat the check in extract_currdev, just check whether
zargs is NULL or not.
X-MFC after: a few days, along with prior related changes.
2018-12-04 16:43:50 +00:00
|
|
|
struct geli_boot_data *gbdata;
|
2016-03-16 23:12:19 +00:00
|
|
|
#endif
|
2012-05-12 09:03:30 +00:00
|
|
|
#ifdef LOADER_ZFS_SUPPORT
|
2016-03-16 23:12:19 +00:00
|
|
|
struct zfs_boot_args *zargs;
|
2012-05-12 09:03:30 +00:00
|
|
|
static void i386_zfs_probe(void);
|
|
|
|
#endif
|
1998-10-02 16:33:43 +00:00
|
|
|
|
1998-08-21 03:17:42 +00:00
|
|
|
/* XXX debugging */
|
|
|
|
extern char end[];
|
|
|
|
|
2005-12-19 09:26:42 +00:00
|
|
|
static void *heap_top;
|
|
|
|
static void *heap_bottom;
|
|
|
|
|
2000-08-03 09:14:02 +00:00
|
|
|
int
|
1998-08-21 03:17:42 +00:00
|
|
|
main(void)
|
|
|
|
{
|
|
|
|
int i;
|
1998-09-14 18:27:06 +00:00
|
|
|
|
1998-09-26 01:31:10 +00:00
|
|
|
/* Pick up arguments */
|
|
|
|
kargs = (void *)__args;
|
1998-10-04 09:12:54 +00:00
|
|
|
initial_howto = kargs->howto;
|
|
|
|
initial_bootdev = kargs->bootdev;
|
2000-03-28 01:19:53 +00:00
|
|
|
initial_bootinfo = kargs->bootinfo ? (struct bootinfo *)PTOV(kargs->bootinfo) : NULL;
|
1998-09-26 01:31:10 +00:00
|
|
|
|
2008-08-08 19:41:20 +00:00
|
|
|
/* Initialize the v86 register set to a known-good state. */
|
|
|
|
bzero(&v86, sizeof(v86));
|
|
|
|
v86.efl = PSL_RESERVED_DEFAULT | PSL_I;
|
|
|
|
|
1998-08-21 03:17:42 +00:00
|
|
|
/*
|
1998-09-17 23:52:16 +00:00
|
|
|
* Initialise the heap as early as possible. Once this is done, malloc() is usable.
|
1998-08-21 03:17:42 +00:00
|
|
|
*/
|
1999-12-29 09:54:46 +00:00
|
|
|
bios_getmem();
|
2000-04-08 01:22:14 +00:00
|
|
|
|
2009-12-07 16:00:59 +00:00
|
|
|
#if defined(LOADER_BZIP2_SUPPORT) || defined(LOADER_FIREWIRE_SUPPORT) || \
|
|
|
|
defined(LOADER_GPT_SUPPORT) || defined(LOADER_ZFS_SUPPORT)
|
2009-12-07 16:29:43 +00:00
|
|
|
if (high_heap_size > 0) {
|
|
|
|
heap_top = PTOV(high_heap_base + high_heap_size);
|
|
|
|
heap_bottom = PTOV(high_heap_base);
|
|
|
|
if (high_heap_base < memtop_copyin)
|
|
|
|
memtop_copyin = high_heap_base;
|
|
|
|
} else
|
2005-12-19 09:26:42 +00:00
|
|
|
#endif
|
2009-12-07 16:29:43 +00:00
|
|
|
{
|
|
|
|
heap_top = (void *)PTOV(bios_basemem);
|
|
|
|
heap_bottom = (void *)end;
|
|
|
|
}
|
2005-12-19 09:26:42 +00:00
|
|
|
setheap(heap_bottom, heap_top);
|
2000-03-28 01:19:53 +00:00
|
|
|
|
2015-04-06 06:55:47 +00:00
|
|
|
/*
|
1998-08-21 03:17:42 +00:00
|
|
|
* XXX Chicken-and-egg problem; we want to have console output early, but some
|
|
|
|
* console attributes may depend on reading from eg. the boot device, which we
|
|
|
|
* can't do yet.
|
|
|
|
*
|
|
|
|
* We can use printf() etc. once this is done.
|
1998-09-26 01:31:10 +00:00
|
|
|
* If the previous boot stage has requested a serial console, prefer that.
|
1998-08-21 03:17:42 +00:00
|
|
|
*/
|
2005-09-22 15:14:13 +00:00
|
|
|
bi_setboothowto(initial_howto);
|
2005-05-27 19:31:00 +00:00
|
|
|
if (initial_howto & RB_MULTIPLE) {
|
|
|
|
if (initial_howto & RB_SERIAL)
|
|
|
|
setenv("console", "comconsole vidconsole", 1);
|
|
|
|
else
|
|
|
|
setenv("console", "vidconsole comconsole", 1);
|
|
|
|
} else if (initial_howto & RB_SERIAL)
|
1998-09-28 20:17:05 +00:00
|
|
|
setenv("console", "comconsole", 1);
|
2005-05-27 19:31:00 +00:00
|
|
|
else if (initial_howto & RB_MUTE)
|
2000-09-20 18:13:36 +00:00
|
|
|
setenv("console", "nullconsole", 1);
|
1998-08-21 03:17:42 +00:00
|
|
|
cons_probe();
|
|
|
|
|
1998-11-02 23:28:11 +00:00
|
|
|
/*
|
A new implementation of the loader block cache
The block cache implementation in loader has proven to be almost useless, and in worst case even slowing down the disk reads due to insufficient cache size and extra memory copy.
Also the current cache implementation does not cache reads from CDs, or work with zfs built on top of multiple disks.
Instead of an LRU, this code uses a simple hash (O(1) read from cache), and instead of a single global cache, a separate cache per block device.
The cache also implements limited read-ahead to increase performance.
To simplify read ahead management, the read ahead will not wrap over bcache end, so in worst case, single block physical read will be performed to fill the last block in bcache.
Booting from a virtual CD over IPMI:
0ms latency, before: 27 second, after: 7 seconds
60ms latency, before: over 12 minutes, after: under 5 minutes.
Submitted by: Toomas Soome <tsoome@me.com>
Reviewed by: delphij (previous version), emaste (previous version)
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D4713
2016-04-18 23:09:22 +00:00
|
|
|
* Initialise the block cache. Set the upper limit.
|
1998-11-02 23:28:11 +00:00
|
|
|
*/
|
A new implementation of the loader block cache
The block cache implementation in loader has proven to be almost useless, and in worst case even slowing down the disk reads due to insufficient cache size and extra memory copy.
Also the current cache implementation does not cache reads from CDs, or work with zfs built on top of multiple disks.
Instead of an LRU, this code uses a simple hash (O(1) read from cache), and instead of a single global cache, a separate cache per block device.
The cache also implements limited read-ahead to increase performance.
To simplify read ahead management, the read ahead will not wrap over bcache end, so in worst case, single block physical read will be performed to fill the last block in bcache.
Booting from a virtual CD over IPMI:
0ms latency, before: 27 second, after: 7 seconds
60ms latency, before: over 12 minutes, after: under 5 minutes.
Submitted by: Toomas Soome <tsoome@me.com>
Reviewed by: delphij (previous version), emaste (previous version)
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D4713
2016-04-18 23:09:22 +00:00
|
|
|
bcache_init(32768, 512);
|
1998-11-02 23:28:11 +00:00
|
|
|
|
2000-03-28 01:19:53 +00:00
|
|
|
/*
|
2001-11-05 19:03:01 +00:00
|
|
|
* Special handling for PXE and CD booting.
|
2000-03-28 01:19:53 +00:00
|
|
|
*/
|
2004-03-14 05:48:04 +00:00
|
|
|
if (kargs->bootinfo == 0) {
|
2001-11-05 19:03:01 +00:00
|
|
|
/*
|
|
|
|
* We only want the PXE disk to try to init itself in the below
|
|
|
|
* walk through devsw if we actually booted off of PXE.
|
|
|
|
*/
|
|
|
|
if (kargs->bootflags & KARGS_FLAGS_PXE)
|
|
|
|
pxe_enable(kargs->pxeinfo ? PTOV(kargs->pxeinfo) : NULL);
|
|
|
|
else if (kargs->bootflags & KARGS_FLAGS_CD)
|
|
|
|
bc_add(initial_bootdev);
|
2000-03-28 01:19:53 +00:00
|
|
|
}
|
|
|
|
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
archsw.arch_autoload = i386_autoload;
|
|
|
|
archsw.arch_getdev = i386_getdev;
|
|
|
|
archsw.arch_copyin = i386_copyin;
|
|
|
|
archsw.arch_copyout = i386_copyout;
|
|
|
|
archsw.arch_readin = i386_readin;
|
|
|
|
archsw.arch_isainb = isa_inb;
|
|
|
|
archsw.arch_isaoutb = isa_outb;
|
2012-05-12 09:03:30 +00:00
|
|
|
#ifdef LOADER_ZFS_SUPPORT
|
|
|
|
archsw.arch_zfs_probe = i386_zfs_probe;
|
2016-03-16 23:12:19 +00:00
|
|
|
|
Fix args cross-threading between gptboot(8) and loader(8) with zfs support.
When loader(8) is built with zfs support enabled, it assumes that any extarg
data present is a zfs_boot_args struct, but if the first-stage loader was
gptboot(8) the extarg data is actually a geli_boot_args struct. Luckily,
zfsboot(8) and gptzfsboot(8) have always passed KARGS_FLAGS_ZFS along with
KARGS_FLAGS_EXTARG, so we can use KARGS_FLAGS_ZFS to decide whether the
extarg data is a zfs_boot_args struct.
To avoid similar problems in the future, gptboot(8) now passes a new
KARGS_FLAGS_GELI to indicate that extarg data is geli_boot_args. In
loader(8), if the neither KARGS_FLAGS_ZFS nor KARGS_FLAGS_GELI is set but
extarg data is present (which will be the case for gptboot compiled before
this change), we now check for the known size of the geli_boot_args struct
passed by the older versions of gptboot as a way of confirming what type of
extarg data is present.
In a semi-related tidying up, since loader's main() has already decided
what type of extarg data is present and set the global 'zargs' var
accordingly, don't repeat the check in extract_currdev, just check whether
zargs is NULL or not.
X-MFC after: a few days, along with prior related changes.
2018-12-04 16:43:50 +00:00
|
|
|
/*
|
|
|
|
* zfsboot and gptzfsboot have always passed KARGS_FLAGS_ZFS, so if that is
|
|
|
|
* set along with KARGS_FLAGS_EXTARG we know we can interpret the extarg
|
|
|
|
* data as a struct zfs_boot_args.
|
|
|
|
*/
|
|
|
|
#define KARGS_EXTARGS_ZFS (KARGS_FLAGS_EXTARG | KARGS_FLAGS_ZFS)
|
|
|
|
|
|
|
|
if ((kargs->bootflags & KARGS_EXTARGS_ZFS) == KARGS_EXTARGS_ZFS) {
|
2016-03-16 23:12:19 +00:00
|
|
|
zargs = (struct zfs_boot_args *)(kargs + 1);
|
|
|
|
}
|
Fix args cross-threading between gptboot(8) and loader(8) with zfs support.
When loader(8) is built with zfs support enabled, it assumes that any extarg
data present is a zfs_boot_args struct, but if the first-stage loader was
gptboot(8) the extarg data is actually a geli_boot_args struct. Luckily,
zfsboot(8) and gptzfsboot(8) have always passed KARGS_FLAGS_ZFS along with
KARGS_FLAGS_EXTARG, so we can use KARGS_FLAGS_ZFS to decide whether the
extarg data is a zfs_boot_args struct.
To avoid similar problems in the future, gptboot(8) now passes a new
KARGS_FLAGS_GELI to indicate that extarg data is geli_boot_args. In
loader(8), if the neither KARGS_FLAGS_ZFS nor KARGS_FLAGS_GELI is set but
extarg data is present (which will be the case for gptboot compiled before
this change), we now check for the known size of the geli_boot_args struct
passed by the older versions of gptboot as a way of confirming what type of
extarg data is present.
In a semi-related tidying up, since loader's main() has already decided
what type of extarg data is present and set the global 'zargs' var
accordingly, don't repeat the check in extract_currdev, just check whether
zargs is NULL or not.
X-MFC after: a few days, along with prior related changes.
2018-12-04 16:43:50 +00:00
|
|
|
#endif /* LOADER_ZFS_SUPPORT */
|
|
|
|
|
2016-03-16 23:12:19 +00:00
|
|
|
#ifdef LOADER_GELI_SUPPORT
|
Fix args cross-threading between gptboot(8) and loader(8) with zfs support.
When loader(8) is built with zfs support enabled, it assumes that any extarg
data present is a zfs_boot_args struct, but if the first-stage loader was
gptboot(8) the extarg data is actually a geli_boot_args struct. Luckily,
zfsboot(8) and gptzfsboot(8) have always passed KARGS_FLAGS_ZFS along with
KARGS_FLAGS_EXTARG, so we can use KARGS_FLAGS_ZFS to decide whether the
extarg data is a zfs_boot_args struct.
To avoid similar problems in the future, gptboot(8) now passes a new
KARGS_FLAGS_GELI to indicate that extarg data is geli_boot_args. In
loader(8), if the neither KARGS_FLAGS_ZFS nor KARGS_FLAGS_GELI is set but
extarg data is present (which will be the case for gptboot compiled before
this change), we now check for the known size of the geli_boot_args struct
passed by the older versions of gptboot as a way of confirming what type of
extarg data is present.
In a semi-related tidying up, since loader's main() has already decided
what type of extarg data is present and set the global 'zargs' var
accordingly, don't repeat the check in extract_currdev, just check whether
zargs is NULL or not.
X-MFC after: a few days, along with prior related changes.
2018-12-04 16:43:50 +00:00
|
|
|
/*
|
|
|
|
* If we decided earlier that we have zfs_boot_args extarg data, and it is
|
|
|
|
* big enough to contain the embedded geli data (the early zfs_boot_args
|
|
|
|
* structs weren't), then init the gbdata pointer accordingly. If there is
|
|
|
|
* extarg data which isn't zfs_boot_args data, determine whether it is
|
|
|
|
* geli_boot_args data. Recent versions of gptboot set KARGS_FLAGS_GELI to
|
|
|
|
* indicate that. Earlier versions didn't, but we presume that's what we
|
|
|
|
* have if the extarg size exactly matches the size of the geli_boot_args
|
|
|
|
* struct during that pre-flag era.
|
|
|
|
*/
|
|
|
|
#define LEGACY_GELI_ARGS_SIZE 260 /* This can never change */
|
|
|
|
|
2018-12-06 20:28:09 +00:00
|
|
|
#ifdef LOADER_ZFS_SUPPORT
|
Fix args cross-threading between gptboot(8) and loader(8) with zfs support.
When loader(8) is built with zfs support enabled, it assumes that any extarg
data present is a zfs_boot_args struct, but if the first-stage loader was
gptboot(8) the extarg data is actually a geli_boot_args struct. Luckily,
zfsboot(8) and gptzfsboot(8) have always passed KARGS_FLAGS_ZFS along with
KARGS_FLAGS_EXTARG, so we can use KARGS_FLAGS_ZFS to decide whether the
extarg data is a zfs_boot_args struct.
To avoid similar problems in the future, gptboot(8) now passes a new
KARGS_FLAGS_GELI to indicate that extarg data is geli_boot_args. In
loader(8), if the neither KARGS_FLAGS_ZFS nor KARGS_FLAGS_GELI is set but
extarg data is present (which will be the case for gptboot compiled before
this change), we now check for the known size of the geli_boot_args struct
passed by the older versions of gptboot as a way of confirming what type of
extarg data is present.
In a semi-related tidying up, since loader's main() has already decided
what type of extarg data is present and set the global 'zargs' var
accordingly, don't repeat the check in extract_currdev, just check whether
zargs is NULL or not.
X-MFC after: a few days, along with prior related changes.
2018-12-04 16:43:50 +00:00
|
|
|
if (zargs != NULL) {
|
|
|
|
if (zargs->size > offsetof(struct zfs_boot_args, gelidata)) {
|
|
|
|
gbdata = &zargs->gelidata;
|
|
|
|
}
|
2018-12-06 20:28:09 +00:00
|
|
|
} else
|
|
|
|
#endif /* LOADER_ZFS_SUPPORT */
|
|
|
|
if ((kargs->bootflags & KARGS_FLAGS_EXTARG) != 0) {
|
2016-03-16 23:12:19 +00:00
|
|
|
gargs = (struct geli_boot_args *)(kargs + 1);
|
Fix args cross-threading between gptboot(8) and loader(8) with zfs support.
When loader(8) is built with zfs support enabled, it assumes that any extarg
data present is a zfs_boot_args struct, but if the first-stage loader was
gptboot(8) the extarg data is actually a geli_boot_args struct. Luckily,
zfsboot(8) and gptzfsboot(8) have always passed KARGS_FLAGS_ZFS along with
KARGS_FLAGS_EXTARG, so we can use KARGS_FLAGS_ZFS to decide whether the
extarg data is a zfs_boot_args struct.
To avoid similar problems in the future, gptboot(8) now passes a new
KARGS_FLAGS_GELI to indicate that extarg data is geli_boot_args. In
loader(8), if the neither KARGS_FLAGS_ZFS nor KARGS_FLAGS_GELI is set but
extarg data is present (which will be the case for gptboot compiled before
this change), we now check for the known size of the geli_boot_args struct
passed by the older versions of gptboot as a way of confirming what type of
extarg data is present.
In a semi-related tidying up, since loader's main() has already decided
what type of extarg data is present and set the global 'zargs' var
accordingly, don't repeat the check in extract_currdev, just check whether
zargs is NULL or not.
X-MFC after: a few days, along with prior related changes.
2018-12-04 16:43:50 +00:00
|
|
|
if ((kargs->bootflags & KARGS_FLAGS_GELI) ||
|
|
|
|
gargs->size == LEGACY_GELI_ARGS_SIZE) {
|
|
|
|
gbdata = &gargs->gelidata;
|
2016-03-16 23:12:19 +00:00
|
|
|
}
|
|
|
|
}
|
Fix args cross-threading between gptboot(8) and loader(8) with zfs support.
When loader(8) is built with zfs support enabled, it assumes that any extarg
data present is a zfs_boot_args struct, but if the first-stage loader was
gptboot(8) the extarg data is actually a geli_boot_args struct. Luckily,
zfsboot(8) and gptzfsboot(8) have always passed KARGS_FLAGS_ZFS along with
KARGS_FLAGS_EXTARG, so we can use KARGS_FLAGS_ZFS to decide whether the
extarg data is a zfs_boot_args struct.
To avoid similar problems in the future, gptboot(8) now passes a new
KARGS_FLAGS_GELI to indicate that extarg data is geli_boot_args. In
loader(8), if the neither KARGS_FLAGS_ZFS nor KARGS_FLAGS_GELI is set but
extarg data is present (which will be the case for gptboot compiled before
this change), we now check for the known size of the geli_boot_args struct
passed by the older versions of gptboot as a way of confirming what type of
extarg data is present.
In a semi-related tidying up, since loader's main() has already decided
what type of extarg data is present and set the global 'zargs' var
accordingly, don't repeat the check in extract_currdev, just check whether
zargs is NULL or not.
X-MFC after: a few days, along with prior related changes.
2018-12-04 16:43:50 +00:00
|
|
|
|
|
|
|
if (gbdata != NULL)
|
|
|
|
import_geli_boot_data(gbdata);
|
2016-03-16 23:12:19 +00:00
|
|
|
#endif /* LOADER_GELI_SUPPORT */
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
|
1998-08-21 03:17:42 +00:00
|
|
|
/*
|
|
|
|
* March through the device switch probing for things.
|
|
|
|
*/
|
|
|
|
for (i = 0; devsw[i] != NULL; i++)
|
|
|
|
if (devsw[i]->dv_init != NULL)
|
|
|
|
(devsw[i]->dv_init)();
|
1999-12-29 09:54:46 +00:00
|
|
|
printf("BIOS %dkB/%dkB available memory\n", bios_basemem / 1024, bios_extmem / 1024);
|
2002-10-01 19:31:09 +00:00
|
|
|
if (initial_bootinfo != NULL) {
|
|
|
|
initial_bootinfo->bi_basemem = bios_basemem / 1024;
|
|
|
|
initial_bootinfo->bi_extmem = bios_extmem / 1024;
|
|
|
|
}
|
1998-08-21 03:17:42 +00:00
|
|
|
|
2001-08-30 00:42:12 +00:00
|
|
|
/* detect ACPI for future reference */
|
|
|
|
biosacpi_detect();
|
|
|
|
|
2005-07-14 19:52:22 +00:00
|
|
|
/* detect SMBIOS for future reference */
|
2015-04-06 06:55:47 +00:00
|
|
|
smbios_detect(NULL);
|
2005-07-14 19:52:22 +00:00
|
|
|
|
2014-09-10 21:07:00 +00:00
|
|
|
/* detect PCI BIOS for future reference */
|
|
|
|
biospci_detect();
|
|
|
|
|
2016-12-18 13:57:23 +00:00
|
|
|
printf("\n%s", bootprog_info);
|
1998-09-18 02:03:30 +00:00
|
|
|
|
1998-10-02 16:33:43 +00:00
|
|
|
extract_currdev(); /* set $currdev and $loaddev */
|
|
|
|
setenv("LINES", "24", 1); /* optional */
|
1998-08-21 03:17:42 +00:00
|
|
|
|
2003-05-01 03:56:30 +00:00
|
|
|
bios_getsmap();
|
|
|
|
|
2017-12-19 04:05:55 +00:00
|
|
|
interact();
|
2000-08-03 09:14:02 +00:00
|
|
|
|
|
|
|
/* if we ever get here, it is an error */
|
|
|
|
return (1);
|
1998-08-21 03:17:42 +00:00
|
|
|
}
|
|
|
|
|
1998-10-02 16:33:43 +00:00
|
|
|
/*
|
|
|
|
* Set the 'current device' by (if possible) recovering the boot device as
|
|
|
|
* supplied by the initial bootstrap.
|
|
|
|
*
|
|
|
|
* XXX should be extended for netbooting.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
extract_currdev(void)
|
|
|
|
{
|
2012-05-12 09:03:30 +00:00
|
|
|
struct i386_devdesc new_currdev;
|
|
|
|
#ifdef LOADER_ZFS_SUPPORT
|
2012-10-06 19:47:24 +00:00
|
|
|
char buf[20];
|
2012-05-12 09:03:30 +00:00
|
|
|
#endif
|
|
|
|
int biosdev = -1;
|
1998-10-02 16:33:43 +00:00
|
|
|
|
2000-03-28 01:19:53 +00:00
|
|
|
/* Assume we are booting from a BIOS disk by default */
|
2018-11-30 08:01:11 +00:00
|
|
|
new_currdev.dd.d_dev = &bioshd;
|
1998-10-02 16:33:43 +00:00
|
|
|
|
2000-03-28 01:19:53 +00:00
|
|
|
/* new-style boot loaders such as pxeldr and cdldr */
|
2004-03-14 05:48:04 +00:00
|
|
|
if (kargs->bootinfo == 0) {
|
2000-03-28 01:19:53 +00:00
|
|
|
if ((kargs->bootflags & KARGS_FLAGS_CD) != 0) {
|
2001-11-05 19:03:01 +00:00
|
|
|
/* we are booting from a CD with cdboot */
|
2018-03-12 21:39:49 +00:00
|
|
|
new_currdev.dd.d_dev = &bioscd;
|
2018-11-30 08:01:11 +00:00
|
|
|
new_currdev.dd.d_unit = bd_bios2unit(initial_bootdev);
|
2000-03-28 01:19:53 +00:00
|
|
|
} else if ((kargs->bootflags & KARGS_FLAGS_PXE) != 0) {
|
|
|
|
/* we are booting from pxeldr */
|
2018-03-12 21:39:49 +00:00
|
|
|
new_currdev.dd.d_dev = &pxedisk;
|
|
|
|
new_currdev.dd.d_unit = 0;
|
2000-03-28 01:19:53 +00:00
|
|
|
} else {
|
|
|
|
/* we don't know what our boot device is */
|
2000-08-03 09:14:02 +00:00
|
|
|
new_currdev.d_kind.biosdisk.slice = -1;
|
|
|
|
new_currdev.d_kind.biosdisk.partition = 0;
|
2000-03-28 01:19:53 +00:00
|
|
|
biosdev = -1;
|
|
|
|
}
|
2012-05-12 09:03:30 +00:00
|
|
|
#ifdef LOADER_ZFS_SUPPORT
|
|
|
|
} else if ((kargs->bootflags & KARGS_FLAGS_ZFS) != 0) {
|
Fix args cross-threading between gptboot(8) and loader(8) with zfs support.
When loader(8) is built with zfs support enabled, it assumes that any extarg
data present is a zfs_boot_args struct, but if the first-stage loader was
gptboot(8) the extarg data is actually a geli_boot_args struct. Luckily,
zfsboot(8) and gptzfsboot(8) have always passed KARGS_FLAGS_ZFS along with
KARGS_FLAGS_EXTARG, so we can use KARGS_FLAGS_ZFS to decide whether the
extarg data is a zfs_boot_args struct.
To avoid similar problems in the future, gptboot(8) now passes a new
KARGS_FLAGS_GELI to indicate that extarg data is geli_boot_args. In
loader(8), if the neither KARGS_FLAGS_ZFS nor KARGS_FLAGS_GELI is set but
extarg data is present (which will be the case for gptboot compiled before
this change), we now check for the known size of the geli_boot_args struct
passed by the older versions of gptboot as a way of confirming what type of
extarg data is present.
In a semi-related tidying up, since loader's main() has already decided
what type of extarg data is present and set the global 'zargs' var
accordingly, don't repeat the check in extract_currdev, just check whether
zargs is NULL or not.
X-MFC after: a few days, along with prior related changes.
2018-12-04 16:43:50 +00:00
|
|
|
/* zargs was set in main() if we have new style extended argument */
|
2012-10-06 19:47:24 +00:00
|
|
|
if (zargs != NULL &&
|
|
|
|
zargs->size >= offsetof(struct zfs_boot_args, primary_pool)) {
|
2012-05-12 09:03:30 +00:00
|
|
|
/* sufficient data is provided */
|
|
|
|
new_currdev.d_kind.zfs.pool_guid = zargs->pool;
|
|
|
|
new_currdev.d_kind.zfs.root_guid = zargs->root;
|
2012-10-06 19:47:24 +00:00
|
|
|
if (zargs->size >= sizeof(*zargs) && zargs->primary_vdev != 0) {
|
|
|
|
sprintf(buf, "%llu", zargs->primary_pool);
|
|
|
|
setenv("vfs.zfs.boot.primary_pool", buf, 1);
|
|
|
|
sprintf(buf, "%llu", zargs->primary_vdev);
|
|
|
|
setenv("vfs.zfs.boot.primary_vdev", buf, 1);
|
|
|
|
}
|
2012-05-12 09:03:30 +00:00
|
|
|
} else {
|
|
|
|
/* old style zfsboot block */
|
|
|
|
new_currdev.d_kind.zfs.pool_guid = kargs->zfspool;
|
|
|
|
new_currdev.d_kind.zfs.root_guid = 0;
|
|
|
|
}
|
2018-03-12 21:39:49 +00:00
|
|
|
new_currdev.dd.d_dev = &zfs_dev;
|
2012-05-12 09:03:30 +00:00
|
|
|
#endif
|
2000-01-27 21:21:01 +00:00
|
|
|
} else if ((initial_bootdev & B_MAGICMASK) != B_DEVMAGIC) {
|
1998-10-04 09:12:54 +00:00
|
|
|
/* The passed-in boot device is bad */
|
2000-08-03 09:14:02 +00:00
|
|
|
new_currdev.d_kind.biosdisk.slice = -1;
|
|
|
|
new_currdev.d_kind.biosdisk.partition = 0;
|
1998-10-04 09:12:54 +00:00
|
|
|
biosdev = -1;
|
|
|
|
} else {
|
2007-10-24 04:03:25 +00:00
|
|
|
new_currdev.d_kind.biosdisk.slice = B_SLICE(initial_bootdev) - 1;
|
2000-08-03 09:14:02 +00:00
|
|
|
new_currdev.d_kind.biosdisk.partition = B_PARTITION(initial_bootdev);
|
1998-10-04 09:12:54 +00:00
|
|
|
biosdev = initial_bootinfo->bi_bios_dev;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we are booted by an old bootstrap, we have to guess at the BIOS
|
2006-08-04 07:56:35 +00:00
|
|
|
* unit number. We will lose if there is more than one disk type
|
1998-10-04 09:12:54 +00:00
|
|
|
* and we are not booting from the lowest-numbered disk type
|
|
|
|
* (ie. SCSI when IDE also exists).
|
|
|
|
*/
|
|
|
|
if ((biosdev == 0) && (B_TYPE(initial_bootdev) != 2)) /* biosdev doesn't match major */
|
|
|
|
biosdev = 0x80 + B_UNIT(initial_bootdev); /* assume harddisk */
|
|
|
|
}
|
2012-05-12 09:03:30 +00:00
|
|
|
|
2000-03-28 01:19:53 +00:00
|
|
|
/*
|
|
|
|
* If we are booting off of a BIOS disk and we didn't succeed in determining
|
|
|
|
* which one we booted off of, just use disk0: as a reasonable default.
|
|
|
|
*/
|
2018-11-30 08:01:11 +00:00
|
|
|
if ((new_currdev.dd.d_dev->dv_type == bioshd.dv_type) &&
|
2018-03-12 21:39:49 +00:00
|
|
|
((new_currdev.dd.d_unit = bd_bios2unit(biosdev)) == -1)) {
|
1998-10-04 09:12:54 +00:00
|
|
|
printf("Can't work out which disk we are booting from.\n"
|
|
|
|
"Guessed BIOS device 0x%x not found by probes, defaulting to disk0:\n", biosdev);
|
2018-03-12 21:39:49 +00:00
|
|
|
new_currdev.dd.d_unit = 0;
|
1998-10-02 16:33:43 +00:00
|
|
|
}
|
2012-05-12 09:03:30 +00:00
|
|
|
|
2016-01-09 19:13:25 +00:00
|
|
|
#ifdef LOADER_ZFS_SUPPORT
|
2018-03-12 21:39:59 +00:00
|
|
|
if (new_currdev.dd.d_dev->dv_type == DEVT_ZFS)
|
2016-01-09 19:13:25 +00:00
|
|
|
init_zfs_bootenv(zfs_fmtdev(&new_currdev));
|
|
|
|
#endif
|
|
|
|
|
2000-08-03 09:14:02 +00:00
|
|
|
env_setenv("currdev", EV_VOLATILE, i386_fmtdev(&new_currdev),
|
|
|
|
i386_setcurrdev, env_nounset);
|
|
|
|
env_setenv("loaddev", EV_VOLATILE, i386_fmtdev(&new_currdev), env_noset,
|
|
|
|
env_nounset);
|
1998-10-02 16:33:43 +00:00
|
|
|
}
|
|
|
|
|
1998-08-21 03:17:42 +00:00
|
|
|
COMMAND_SET(reboot, "reboot", "reboot the system", command_reboot);
|
|
|
|
|
|
|
|
static int
|
|
|
|
command_reboot(int argc, char *argv[])
|
|
|
|
{
|
2000-04-20 00:06:15 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; devsw[i] != NULL; ++i)
|
|
|
|
if (devsw[i]->dv_cleanup != NULL)
|
|
|
|
(devsw[i]->dv_cleanup)();
|
1998-08-21 03:17:42 +00:00
|
|
|
|
|
|
|
printf("Rebooting...\n");
|
|
|
|
delay(1000000);
|
1998-09-17 23:52:16 +00:00
|
|
|
__exit(0);
|
1998-08-21 03:17:42 +00:00
|
|
|
}
|
|
|
|
|
1998-09-18 02:03:30 +00:00
|
|
|
/* provide this for panic, as it's not in the startup code */
|
1998-09-17 23:52:16 +00:00
|
|
|
void
|
|
|
|
exit(int code)
|
|
|
|
{
|
|
|
|
__exit(code);
|
|
|
|
}
|
|
|
|
|
1998-08-21 03:17:42 +00:00
|
|
|
COMMAND_SET(heap, "heap", "show heap usage", command_heap);
|
|
|
|
|
|
|
|
static int
|
|
|
|
command_heap(int argc, char *argv[])
|
|
|
|
{
|
1998-09-26 01:31:10 +00:00
|
|
|
mallocstats();
|
2005-12-19 09:26:42 +00:00
|
|
|
printf("heap base at %p, top at %p, upper limit at %p\n", heap_bottom,
|
|
|
|
sbrk(0), heap_top);
|
1998-08-21 03:17:42 +00:00
|
|
|
return(CMD_OK);
|
|
|
|
}
|
1998-10-21 20:10:33 +00:00
|
|
|
|
2012-09-18 08:53:11 +00:00
|
|
|
/* ISA bus access functions for PnP. */
|
2012-09-11 06:15:55 +00:00
|
|
|
static int
|
1998-10-21 20:10:33 +00:00
|
|
|
isa_inb(int port)
|
|
|
|
{
|
2012-09-11 06:15:55 +00:00
|
|
|
|
2012-09-18 08:53:11 +00:00
|
|
|
return (inb(port));
|
1998-10-21 20:10:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
isa_outb(int port, int value)
|
|
|
|
{
|
2012-09-11 06:15:55 +00:00
|
|
|
|
2012-09-18 08:53:11 +00:00
|
|
|
outb(port, value);
|
1998-10-21 20:10:33 +00:00
|
|
|
}
|
|
|
|
|
2012-05-12 09:03:30 +00:00
|
|
|
#ifdef LOADER_ZFS_SUPPORT
|
|
|
|
static void
|
|
|
|
i386_zfs_probe(void)
|
|
|
|
{
|
|
|
|
char devname[32];
|
2018-11-30 08:01:11 +00:00
|
|
|
struct i386_devdesc dev;
|
2012-05-12 09:03:30 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Open all the disks we can find and see if we can reconstruct
|
2012-08-05 14:48:28 +00:00
|
|
|
* ZFS pools from them.
|
2012-05-12 09:03:30 +00:00
|
|
|
*/
|
2018-11-30 08:01:11 +00:00
|
|
|
dev.dd.d_dev = &bioshd;
|
|
|
|
for (dev.dd.d_unit = 0; bd_unit2bios(&dev) >= 0; dev.dd.d_unit++) {
|
|
|
|
snprintf(devname, sizeof(devname), "%s%d:", bioshd.dv_name,
|
|
|
|
dev.dd.d_unit);
|
2012-08-05 14:48:28 +00:00
|
|
|
zfs_probe_dev(devname, NULL);
|
2012-05-12 09:03:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|