Commit graph

63 commits

Author SHA1 Message Date
Warner Losh d4d32e5899 It sure would be nice to use printf with wide strings. Implement %S to
do that. The C_WIDEOUT flag indicates that the console supports
it. Mark the EFI console as supporting this.

MFC After: 3 days
2016-05-17 14:10:45 +00:00
Allan Jude 87ed2b7f5a 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
Steven Hartland dc9ba0270b Make common boot file_loadraw name parameter const
Fix compiler warnings about dropping const qualifier by changing file_loadraw
name param to const, and updating method to make that the case (it was
abusing the variable).

MFC after:	2 weeks
X-MFC-With:	r293268
Sponsored by:	Multiplay
2016-01-15 00:55:36 +00:00
Steven Hartland 4b09a8fdbc Improve non-interactive forth cmd error reporting
Non-interactive forth command errors where silent even for critical issues
e.g. failing to load a required kernel module or mfs_root.

This resulted in later unexplained and hard to trace errors such as mount
root failures.

This introduces additional command return codes that are treated
appropriately by the non-interactive command processor (bf_command).
* CMD_CRIT = print error
* CMD_FATAL = panic

Also fix minor style(9) issues with command_load return codes.

MFC after:	2 weeks
X-MFC-With:	r293268
Sponsored by:	Multiplay
2016-01-13 18:33:12 +00:00
Roger Pau Monné ca49b3342d loader: implement multiboot support for Xen Dom0
Implement a subset of the multiboot specification in order to boot Xen
and a FreeBSD Dom0 from the FreeBSD bootloader. This multiboot
implementation is tailored to boot Xen and FreeBSD Dom0, and it will
most surely fail to boot any other multiboot compilant kernel.

In order to detect and boot the Xen microkernel, two new file formats
are added to the bootloader, multiboot and multiboot_obj. Multiboot
support must be tested before regular ELF support, since Xen is a
multiboot kernel that also uses ELF. After a multiboot kernel is
detected, all the other loaded kernels/modules are parsed by the
multiboot_obj format.

The layout of the loaded objects in memory is the following; first the
Xen kernel is loaded as a 32bit ELF into memory (Xen will switch to
long mode by itself), after that the FreeBSD kernel is loaded as a RAW
file (Xen will parse and load it using it's internal ELF loader), and
finally the metadata and the modules are loaded using the native
FreeBSD way. After everything is loaded we jump into Xen's entry point
using a small trampoline. The order of the multiboot modules passed to
Xen is the following, the first module is the RAW FreeBSD kernel, and
the second module is the metadata and the FreeBSD modules.

Since Xen will relocate the memory position of the second
multiboot module (the one that contains the metadata and native
FreeBSD modules), we need to stash the original modulep address inside
of the metadata itself in order to recalculate its position once
booted. This also means the metadata must come before the loaded
modules, so after loading the FreeBSD kernel a portion of memory is
reserved in order to place the metadata before booting.

In order to tell the loader to boot Xen and then the FreeBSD kernel the
following has to be added to the /boot/loader.conf file:

xen_cmdline="dom0_mem=1024M dom0_max_vcpus=2 dom0pvh=1 console=com1,vga"
xen_kernel="/boot/xen"

The first argument contains the command line that will be passed to the Xen
kernel, while the second argument is the path to the Xen kernel itself. This
can also be done manually from the loader command line, by for example
typing the following set of commands:

OK unload
OK load /boot/xen dom0_mem=1024M dom0_max_vcpus=2 dom0pvh=1 console=com1,vga
OK load kernel
OK load zfs
OK load if_tap
OK load ...
OK boot

Sponsored by: Citrix Systems R&D
Reviewed by: jhb
Differential Revision: https://reviews.freebsd.org/D517

For the Forth bits:
Submitted by: Julien Grall <julien.grall AT citrix.com>
2015-01-15 16:27:20 +00:00
Marcel Moolenaar ca0a6da1a2 Rename command_unload() to unload() and re-implement command_unload()
in terms of unload() This allows unloading all files by the loader
itself.

Obtained from:	Juniper Networks, Inc.
2014-08-06 00:06:25 +00:00
Marcel Moolenaar 7fe0b4f160 Give loaders more control over the Forth initialization process. In
particular, allow loaders to define the name of the RC script the
interpreter needs to use. Use this new-found control to have the
PXE loader (when compiled with TFTP support and not NFS support)
read from ${bootfile}.4th, where ${bootfile} is the name of the
file fetched by the PXE firmware.

The normal startup process involves reading the following files:
1.  /boot/boot.4th
2.  /boot/loader.rc or alternatively /boot/boot.conf

When these come from a FreeBSD-defined file system, this is all
good. But when we boot over the network, subdirectories and fixed
file names are often painful to administrators and there's really
no way for them to change the behaviour of the loader.

Obtained from:	Juniper Networks, Inc.
2014-07-27 16:12:51 +00:00
Ian Lepore 84207cf3b0 Change file_loadraw() from static to public. Change the order of its
arguments from type,filename to filename,type to be consistant with other
public file_whatever() functions, and change it to return a pointer to
the preloaded_file struct describing the file.  Adjust existing callers.
2014-02-22 22:03:26 +00:00
Tim Kientzle 6d4a620eba Fix the bug I introduced in r247045.
After digging through more carefully, it looks like there's
no real need to have the DTB in the module directory.
So we can simplify a lot:  Just copy DTB into local heap
for "fdt addr" and U-Boot integration, drop all the extra
COPYIN() calls.

I've left one final COPYIN() to update the in-kernel DTB
for consistency with how this code used to work, but I'm
no longer convinced it's appropriate here.

I've also remove the mem_load_raw() utility that I added
to boot/common/module.c with r247045 since it's no longer
necessary.
2013-02-25 01:50:04 +00:00
Tim Kientzle 3e256ed764 Add mem_load_raw() for loading data from another location in memory.
This will be used by some upcoming changes to loader(8) FDT
handling to allow it to use an FDT provided by an earlier
boot stage the same as an FDT loaded from disk.
2013-02-18 23:13:13 +00:00
Andriy Gapon 4ecbcb6f49 boot/console: handle consoles that fail to probe
- clarify meaning of console flags
- perform i/o via a console only if both of the following conditions are met:
   o console is active (selected by user or config)
   o console flags that it can perform the operation
- warn if a chosen console can not work (the warning may go nowhere without
  working and active console, though)

Reviewed by:	jhb
Tested by:	Uffe Jakobsen <uffe@uffe.org>,
		Olivier Cochard-Labbe' <olivier@cochard.me>
MFC after:	26 days
2012-10-06 20:01:17 +00:00
Andriy Gapon 1702e62f67 zfsboot/zfsloader: support accessing filesystems within a pool
In zfs loader zfs device name format now is "zfs:pool/fs",
fully qualified file path is "zfs:pool/fs:/path/to/file"
loader allows accessing files from various pools and filesystems as well
as changing currdev to a different pool/filesystem.

zfsboot accepts kernel/loader name in a format pool:fs:path/to/file or,
as before, pool:path/to/file; in the latter case a default filesystem
is used (pool root or bootfs).  zfsboot passes guids of the selected
pool and dataset to zfsloader to be used as its defaults.

zfs support should be architecture independent and is provided
in a separate library, but architectures wishing to use this zfs support
still have to provide some glue code and their devdesc should be
compatible with zfs_devdesc.
arch_zfs_probe method is used to discover all disk devices that may
be part of ZFS pool(s).

libi386 unconditionally includes zfs support, but some zfs-specific
functions are stubbed out as weak symbols.  The strong definitions
are provided in libzfsboot.
This change mean that the size of i386_devspec becomes larger
to match zfs_devspec.

Backward-compatibility shims are provided for recently added sparc64
zfs boot support.  Currently that architecture still works the old
way and does not support the new features.

TODO:
- clear up pool root filesystem vs pool bootfs filesystem distinction
- update sparc64 support
- set vfs.root.mountfrom based on currdev (for zfs)

Mid-future TODO:
- loader sub-menu for selecting alternative boot environment

Distant future TODO:
- support accessing snapshots, using a snapshot as readonly root

Reviewed by:	marius (sparc64),
		Gavin Mu <gavin.mu@gmail.com> (sparc64)
Tested by:	Florian Wagner <florian@wagner-flo.net> (x86),
		marius (sparc64)
No objections:	fs@, hackers@
MFC after:	1 month
2012-05-12 09:03:30 +00:00
Andriy Gapon 5ef10e566c sys/boot: add common CTASSERT definition 2012-05-09 07:55:42 +00:00
Marius Strobl 1a7f270047 Add multiple inclusion protection.
PR:		165025
Submitted by:	Gavin Mu
MFC after:	1 week
2012-04-29 15:54:40 +00:00
Marcel Moolenaar 0cca5d3d90 Add 2 new archsw interfaces:
1.  arch_loadaddr - used by platform code to adjust the address at which
    the object gets loaded. Implement PC98 using this new interface instead
    of using conditional compilation. For ELF objects the ELF header is
    passed as the data pointer. For raw files it's the filename. Note that
    ELF objects are first considered as raw files.
2.  arch_loadseg - used by platform code to keep track of actual segments,
    so that (instruction) caches can be flushed or translations can be
    created. Both the ELF header as well as the program header are passed
    to allow platform code to treat the kernel proper differently from any
    additional modules and to have all the relevant details of the loaded
    segment (e.g. protection).
2011-04-03 22:31:51 +00:00
Marcel Moolenaar 429d5c051f Revert rev 165325. The arch_maphint interface hasn't been in use for
more than 4 years.
2011-04-03 05:09:25 +00:00
Marcel Moolenaar 716f79c093 Remove file system support based on the simple file system protocol
as this only allows us to access file systems that EFI knows about.
With a loader that can only use EFI-supported file systems, we're
forced to put /boot on the EFI system partition. This is suboptimal
in the following ways:
1.  With /boot a symlink to /efi/boot, mergemaster complains about
    the mismatch and there's no quick solution.
2.  The EFI loader can only boot a single version of FreeBSD. There's
    no way to install multiple versions of FreeBSD and select one
    at the loader prompt.
3.  ZFS maintains /boot/zfs/zpool.cache and with /boot a symlink we
    end up with the file on a MSDOS file system. ZFS does not have
    proper handling of file systems that are under Giant.

Implement a disk device based on the block I/O protocol instead and
pull in file system code from libstand. The disk devices are really
the partitions that EFI knows about.

This change is backward compatible.

MFC after:	1 week
2010-01-09 22:54:29 +00:00
Pawel Jakub Dawidek 1ba4a712dd 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
Marcel Moolenaar e641a443f4 Add __elfN(relocation_offset). It holds the offset between the virtual
(link) address and the physical (load) address. Ideally, the mapping
between link and load addresses should be abstracted by the copyin(),
copyout() and readin() functions, so that we don't have to add kluges
in __elfN(loadimage)(). Then, we could also have paged virtual memory
for the kernel. This can be important under EFI, where you need to
allocate physical memory form the firmware if you want to work in all
scenarios.
2008-02-23 18:33:50 +00:00
Kip Macy 2d74924b65 add an interface for passing the entire kernel size up front to the
loader so that it can memory can be allocated aligned at the beginning of
the desired large page
2006-12-18 07:35:14 +00:00
Marcel Moolenaar 932d8c46a2 Extend struct devdesc with a unit field, called d_unit. Promote the
device (kind) specific unit field to the common field. This change
allows a future version of libefi to work without requiring anything
more than what is defined in struct devdesc and as such makes it
possible to compile said version of libefi for different platforms
without requiring that those platforms have identical derivatives
of struct devdesc.
2006-11-02 01:23:18 +00:00
Marcel Moolenaar 757686b115 Make our ELF64 type definitions match standards. In particular this
means:
o  Remove Elf64_Quarter,
o  Redefine Elf64_Half to be 16-bit,
o  Redefine Elf64_Word to be 32-bit,
o  Add Elf64_Xword and Elf64_Sxword for 64-bit entities,
o  Use Elf_Size in MI code to abstract the difference between
   Elf32_Word and Elf64_Word.
o  Add Elf_Ssize as the signed counterpart of Elf_Size.

MFC after: 2 weeks
2005-12-18 04:52:37 +00:00
Ian Dowse 941fdb393b Add the loader side of support for preloading ELF relocatable object
format modules, which are currently only used on the amd64 platform.
This initial implementation just parses enough of the module to
allow it to extract dependencies and load all the bits into the
right place in memory, so the kernel must still do the full relocation
and linking. The details of the loaded sections are passed to the
kernel by supplying a copy of the ELF section header table as module
metadata with the MODINFOMD_SHDR tag.
2004-08-29 00:48:42 +00:00
Ian Dowse 45b8d7c46e Separate out the ELF relocation code from the ELF loader, and add
better relocation support for the amd64 and i386 platforms. This
should not result in any change in functionality, but moves a step
towards supporting the relocatable object file modules on amd64.

The same hack/trick as load_elf*.c uses is used here to simultaneously
support both elf32 and elf64 on amd64 and i386.
2004-08-28 23:03:05 +00:00
Ian Dowse c0b43624d5 Add a few helper functions for zeroing kernel space and reading
from specified file offsets. Make use of these in load_elf.c.
2004-08-28 14:57:34 +00:00
Peter Wemm 48a0b96a50 Enable the i386 loader to load and run an amd64 kernel. If this puts
things over floppy size limits, I can exclude it for release builds or
something like that.  Most of the changes are to get the load_elf.c file
into a seperate elf32_ or elf64_ namespace so that you can have two
ELF loaders present at once.  Note that for 64 bit kernels, it actually
starts up the kernel already in 64 bit mode with paging enabled.  This
is really easy because we have a known minimum feature set.

Of note is that for amd64, we have to pass in the bios int 15 0xe821
memory map because once in long mode, you absolutely cannot make VM86
calls.  amd64 does not use 'struct bootinfo' at all.  It is a pure loader
metadata startup, just like sparc64 and powerpc.  Much of the
infrastructure to support this was adapted from sparc64.
2003-05-01 03:56:30 +00:00
Peter Wemm 30f445e056 Zap some a.out leftovers 2003-04-06 06:28:08 +00:00
Maxim Sobolev 5616599331 CG superfluous prototype. 2002-03-10 22:33:04 +00:00
Bruce Evans 0c6ec4aca0 Declare time(not3) instead of depending on namespace pollution 3 layers
deep in <stand.h> to eventually include <time.h> to declare the user
version.

This is not quite the right place to declare it, but <stand.h> would
be worse because time() is very MD so it isn't in libstand.

Many places in the boot sources still get the user version using only
1 layer of pollution (#include <sys/time.h>.  Some pollute themselves
directly (#include <time.h>).  But the boot Makefiles are too broken
to enable warnings for redeclarations.
2002-02-25 04:31:25 +00:00
John Baldwin 9248a89d0b Add a DEVT_CD type for CD drivers. 2001-11-05 18:51:47 +00:00
Peter Wemm 505222d35f Implement the long-awaited module->file cache database. A userland
tool (kldxref(8)) keeps a cache of what modules and versions are inside
what .ko files.  I have tested this on both Alpha and i386.

Submitted by:	bp
2001-09-11 01:09:24 +00:00
Peter Wemm 44fa54f5f6 Nuke old gensetdefs based linker sets with extreme prejudice 2001-06-14 01:23:57 +00:00
Daniel C. Sobral 3053524c85 Make the pnp structure a global variable, so it can be used elsewhere. 2000-09-08 16:51:29 +00:00
John Baldwin 4ae4202e70 Cleanup warnings. Most of these are signed/unsigned warnings, as well as
some added const's.
2000-08-03 09:14:02 +00:00
Paul Saab cc3d937224 Delay calling the device cleanup routines until the absolute last
moment.  We were cleaning up after PXE too early and the module
dependancy code would not be able to load any files if it needed
too.
2000-06-14 10:34:29 +00:00
Jake Burkholder e39756439c Back out the previous change to the queue(3) interface.
It was not discussed and should probably not happen.

Requested by:		msmith and others
2000-05-26 02:09:24 +00:00
Jake Burkholder 740a1973a6 Change the way that the queue(3) structures are declared; don't assume that
the type argument to *_HEAD and *_ENTRY is a struct.

Suggested by:	phk
Reviewed by:	phk
Approved by:	mdodd
2000-05-23 20:41:01 +00:00
Boris Popov 801e789e01 Update loader logic to distinguish modules vs. files.
Add support for module metadata. The old way of dependancy
handling will be supported for a while.

Reviewed by:	peter
2000-05-01 17:41:25 +00:00
Daniel C. Sobral a5686d2f66 bcache_strategy() now receives an unit number, and keep track of what
was the last unit number received. If it changes, it flushes the cache.
Add bcache_flash().

The actual fix is sligthly different from the one in the PR.

PR:		17098
Submitted by:	John Hood <jhood@sitaranetworks.com>
2000-03-15 01:56:12 +00:00
Peter Wemm c3aac50f28 $Id$ -> $FreeBSD$ 1999-08-28 01:08:13 +00:00
Mike Smith 73332890ea Walk around the end of all the silly guessing of device types and unit
numbers that we have been doing in the past, and read /etc/fstab off the
proposed root filesystem to determine the actual device name and vfs
type for the root filesystem.  These are then exported to the kernel
via the environment variable vfs.root.mountfrom.
1999-07-21 00:08:54 +00:00
Peter Wemm 240ee5d0e0 ABS_SET() and BSS_SET() are no longer used. The sole remaining user of
TEXT_SET() is DDB's command tables.
1999-06-26 12:27:01 +00:00
Peter Wemm 6182fdbda8 Bring the 'new-bus' to the i386. This extensively changes the way the
i386 platform boots, it is no longer ISA-centric, and is fully dynamic.
Most old drivers compile and run without modification via 'compatability
shims' to enable a smoother transition.  eisa, isapnp and pccard* are
not yet using the new resource manager.  Once fully converted, all drivers
will be loadable, including PCI and ISA.

(Some other changes appear to have snuck in, including a port of Soren's
 ATA driver to the Alpha.  Soren, back this out if you need to.)

This is a checkpoint of work-in-progress, but is quite functional.

The bulk of the work was done over the last few years by Doug Rabson and
Garrett Wollman.

Approved by:	core
1999-04-16 21:22:55 +00:00
Daniel C. Sobral 47749087ac Make use of prototypes to silence warnings.
Change include() so it will be able to load files with forth code,
instead of just builtins. Remove #@- from the include section of the
help file, since they don't work in the new version of include, unless
BOOT_FORTH is not defined.

Change bf_run() so it will return the result returned by ficlExec(). Also,
make bf_run() push "interpret" to be executed by ficlExec(), since ficlExec()
doesn't do it by itself. (Things worked previously because nothing
recursed through ficlExec() by the way of bf_run()).

Change/extend comments on builtin behavior.

Search for "interpret" at the end of bf_init(), so /boot/boot.4th can
provide it's own version.

Remove dead code.
1999-02-04 17:06:46 +00:00
Mike Smith b7fd9e91ed bootstrap.h
help.common
interp.c
	Rename the 'source' command to 'include' in order to avoid conflict
	with the ANS Forth command of the same name. (kern/9473)

interp_forth.c:
	Changes from kern/9412 (EXCEPTION word), kern/9442 (TIB buffer
	sizing) and an improved version of kern/9460 (set
	version numbers).

load_aout.c:
	Trim some obsolete #if 0'ed cruft.

pnp.c:
	Tidy the pnpscan output, turn off the module scanning until we
	sort out how to do it right.

PR:		kern/9412 kern/9442 kern/9460 kern/9473
Submitted by:	PRs from Daniel Sobral <dcs@newsguy.com>
1999-01-22 23:50:14 +00:00
John Polstra 5e26973571 Replace duplicated "old" linker set definitions with an include of
<sys/linker_set.h>.  Note, this isn't used on the i386.
1999-01-16 03:25:24 +00:00
Andrzej Bialecki 0d9ab84751 Fall back to /boot/boot.conf, if /boot/loader.rc was not fount. This is
to cover the transition period.

Suggested by:	msmith
1999-01-15 00:31:45 +00:00
Mike Smith af1f6e0673 Implement a simple LRU block cache. By default this is initialised to 16k,
and will bypass transfers for more than 8k.  Blocks are invalidated after
2 seconds, so removable media should not confuse the cache.

The 8k threshold is a compromise; all UFS transfers performed by
libstand are 8k or less, so large file reads thrash the cache.
However many filesystem metadata operations are also performed using
8k blocks, so using a lower threshold gives poor performance.

Those of you with an eye for cache algorithms are welcome to tell me
how badly this one sucks; you can start with the 'bcachestats' command
which will print the contents of the cache and access statistics.
1998-11-02 23:28:11 +00:00
Mike Smith 60edbabff6 Export an interface for presetting the ISA PnP read port address.
Make the EISA ID formatter generally available
1998-10-22 20:20:51 +00:00
Mike Smith eddbe21def Make ISA PnP work. This successfully enumerates as many ISA devices as I
can fit into my test machine.

 - Move to using STAILQs rather than ad-hoc singly-linked lists.
 - Use a mostly procedural interface to the PnP information.  This
   improves data-hiding.

Implement a new linker-set technique (currently on i386 only but should work
on Alpha as well).  This is a good candidate for replacing the current
gensetdefs cruft completely.
1998-10-21 20:07:05 +00:00