Commit Graph

313 Commits

Author SHA1 Message Date
Toomas Soome
b4cb3fe0e3 loader: implement mount/unmount rootfs
We want to keep our root file system open to preserve bcache segment
between file accesses, thus reducing physical disk IO.

Reviewed by:	imp, allanjude, kevans (previous version)
Differential Revision:	https://reviews.freebsd.org/D30848
MFC after:	1 month
2021-09-08 04:01:20 +03:00
Toomas Soome
4c7a3a70e0 loader.efi: fix console output after BS off
When Boot Services (BS) are switched off, we can not use BS
functions any more. Since drawn console does implement our own
Blt(), we can use it to draw the console.

However, SimpleTextOutput protocol based console output must be
blocked.

Tested by inserting printf() after ExitBootServices() call.

MFC after:	1 week
2021-09-03 00:48:56 +03:00
Konstantin Belousov
b54eec8366 efi loader: disallow user to configure staging area size less than default
We need to round it up to 2M, for instance.  Having staging area too small
might cause the first resize to use negative size for memmove()/memcpy(),
which kills loader.

Tested by:	Harry Schmalzbauer <freebsd@omnilan.de>
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2021-08-27 19:49:01 +03:00
Konstantin Belousov
b850806921 Restore the definition of EFI_STAGING_SIZE
The definition can be overridden by users, and before f75caed644 it
was in MBs.  Make the symbol' unit MB, to be compatible with users
customizations.

Reported and tested by:	Harry Schmalzbauer <freebsd@omnilan.de>
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2021-08-27 19:48:53 +03:00
Konstantin Belousov
6032b6ba95 amd64 UEFI loader: enable automatic disable of staging area copying
Discussed with:	emaste
Sponsored by:	The FreeBSD Foundation
MFC after:	1 month
2021-08-25 22:26:52 +03:00
Konstantin Belousov
f75caed644 amd64 UEFI loader: stop copying staging area to 2M physical
On amd64, add a possibility to activate kernel with staging area in place.
Add 'copy_staging' command to control this.  For now, by default the
old mode of copying kernel to 2M phys is retained.  It is going to be
changed in several weeks.

On amd64, add some slop to the staging area to satisfy both requirements
of the kernel startup allocator, and to have space for minor staging data
increase after the final size is calculated.  Add a new command
'staging_slop' to control its size.

Improve staging area resizing, in particular, reallocate it anew if
we cannot grow it neither down nor up.

Reviewed by:	kevans, markj
Discussed with:	emaste (the delivery plan)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D31121
2021-08-08 22:52:29 +03:00
Colin Percival
313724bab9 loader: Use tslog to instrument some functions
In my initial testing, these are the functions which showed up as
being worth instrumenting.  More may be added later.

common/console.c: cons_probe
common/gfx_fb.c: read_list, insert_font, autoload_font
common/interp.c: interact
common/interp_lua.c: interp_init, interp_run
efi/libefi/efipart.c: efipart_readwrite
i386/libi386/biosdisk.c: bd_init, bd_open, bd_edd_io, bd_chs_io, bd_io
libsa/open.c: open
libsa/read.c: read
libsa/twiddle.c: twiddle

Note that profiling interp_run may be of questionable utility as it
may depend on user behaviour (e.g. pressing keys).

Reviewed by:	kevans (earlier version)
2021-06-20 20:09:48 -07:00
Colin Percival
f49381ccb6 efi/loader: Call tslog_init
This allows the EFI loader to start recording timestamps.
2021-06-20 20:09:45 -07:00
Andrew Turner
0a0d6ce34d Use the arm virtual counter in the arm64 loader
It exist on all ARMv8+ CPUs, and other boot loaders rely on it being
present.

Sponsored by:	Innovate UK
Differential Revision: https://reviews.freebsd.org/D30410
2021-06-02 10:58:20 +00:00
Andrew Turner
93f7be080f Update the EFI timer to be called once a second
There is no need to call it evert 10ms when we need 1s granularity.
Update to update the time every second.

Reviewed by:	imp, manu, tsoome
Sponsored by:	Innovate UK
Differential Revision: https://reviews.freebsd.org/D30227
2021-05-12 14:12:34 +00:00
Eric van Gyzen
eda28feb2e EFI secure boot VECTX related changes
When VECTX is enabled as a kernel option and non-EFI loaders are
built, many reads will fail due to the mis-match of whether
LOADER_VERIEXEC_VECTX or not in readin.h.  Source that includes
bootstrap.h must ensure the kernel option agrees with the compile
time CFLAGS in the various make related files.

Submitted by:	bret_ketchum@dell.com (original revision)
Reviewed by:	sjg, bdrewery, dab, bret_ketchum@dell.com
MFC after:	1 week
Sponsored by:	Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D29993
2021-04-30 12:53:45 -05:00
Yongbo Yao
5984246f96 Loader: support booting OS from memory disk (MD)
Until now, the boot image can be embedded into the loader with
/sys/tools/embed_mfs.sh, and memory disk (MD) is already supported
in loader source. But due to memory disk (MD) driver isn't registered
to the loader yet, the boot image can't be boot from embedded memory
disk.

Reviewed by:	dab, tsoome
MFC after:	1 week
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D29512
2021-04-07 13:40:57 -05:00
Warner Losh
42cd37dfbd gptboot.efi: Add man page
Add a man page for gptboot.efi. Describe when and how to use this as it differs
from the BIOS cases. Include cross reference for the preferred method described
in efibootmgr(8) as well as cross links in both gptboot(8) and gptboot.efi(8) to
the other.

This man page was heavily copied from the gptboot.8 man page by Warren Block.
They are different enough to need separate man pages for clarity, but there's
enough similarity that I worry about the duplication. In the really long term,
gptboot(8) will disappear, so having the same info here will help when that
day comes. In the short to medium term, the information is likely to not
change in gptboot(8) and any changes to gptboot.efi(8) will be easier to
make in a separate copy.

loader.efi(8) needs a complete rewrite from scratch, otherwise I'd have
referenced gptboot.efi(8) from there.

Suggetions from:	cress@, mhorne@
Reviewed by:		rpokala@
Differential Revision:	https://reviews.freebsd.org/D29591
2021-04-05 23:57:57 -06:00
Gordon Bergling
5666643a95 Fix some common typos in comments
- occured -> occurred
- normaly -> normally
- controling -> controlling
- fileds -> fields
- insterted -> inserted
- outputing -> outputting

MFC after:	1 week
2021-03-13 18:26:15 +01:00
Andrew Turner
773fc43fb0 Revert "Split out the loader efifb setup to a new function"
It was broken by a rebase. Revert until it can be fixed.

This reverts commit c8db60c067.
2021-03-03 16:10:12 +00:00
Andrew Turner
c8db60c067 Split out the loader efifb setup to a new function
This makes bi_load_efi_data cleaner to add common acpi setup code.

Reviewed by:	imp, tsoome
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D28936
2021-03-03 14:18:02 +00:00
Toomas Soome
becaac3972 loader: use display pixel density for font autoselection
Calculate font size from 16 density independent pixels (dp) by using:
size = 16 * ppi/160 * display_factor

We are specifying font size 16dp, and assuming 1dp = 160ppi.
Also apply scaling factor 2 (display_factor).

MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D28849
2021-02-27 11:26:02 +02:00
Roger Pau Monné
0eaa97f0e8 stand/multiboot2: fix header length check
Check whether we have reached the end of the buffer using search_size
instead of MULTIBOOT_SEARCH, which is the maximum defined by the
specification, but the file can be shorter than that.

This prevents printing a harmless error message when loading a file
that is smaller than MULTIBOOT_SEARCH.

Sponsored by: Citrix Systems R&D
MFC after: 3 days
Fixes: adda2797eb ('stand/multiboot2: add support for booting a Xen dom0 in UEFI mode')
2021-02-23 16:05:03 +01:00
Roger Pau Monné
ab379c15af stand/multiboot2: fix error message format
Add a missing space in one error message.

Sponsored by: Citrix Systems R&D
MFC after: 3 days
Fixes: adda2797eb ('stand/multiboot2: add support for booting a Xen dom0 in UEFI mode')
2021-02-23 16:04:58 +01:00
Toomas Soome
61c50cbc09 loader: autoload_font will hung loader when there is no local console
If we start with console set to comconsole, the local
console (vidconsole, efi) is never initialized and attempt to
use the data can render the loader hung.

Reported by:	Kamigishi Rei
MFC after: 3 days
2021-02-21 12:45:36 +02:00
Roger Pau Monné
97527e9c4f bi_load: only add MODULEP on arches that have it defined
Do not attempt to add MODINFOMD_MODULEP to the kernel medatada on
arches that don't have it defined.

This fixes the build for arches different than amd64 after
7d3259775c.

Sponsored by:	Citrix Systems R&D
Reported by:	lwhsu, arichardson
2021-02-16 16:14:32 +01:00
Roger Pau Monné
adda2797eb stand/multiboot2: add support for booting a Xen dom0 in UEFI mode
Add some basic multiboot2 infrastructure to the EFI loader in order to
be capable of booting a FreeBSD/Xen dom0 when booted from UEFI.

Only a very limited subset of the multiboot2 protocol is implemented
in order to support enough to boot into Xen, the implementation
doesn't intend to be a full multiboot2 capable implementation.

Such multiboot2 functionality is hooked up into the amd64 EFI loader,
which is the only architecture that supports Xen dom0 on FreeBSD.

The options to boot a FreeBSD/Xen dom0 system are exactly the same as
on BIOS, and requires setting the xen_kernel and xen_cmdline options
in loader.conf.

Sponsored by:		Citrix Systems R&D
Reviewed by:		tsoome, imp
Differential revision:	https://reviews.freebsd.org/D28497
2021-02-16 15:26:11 +01:00
Roger Pau Monné
7d3259775c stand/efi: add modulep to kernel metadata
This mirrors the functionality of the BIOS amd64 bi_load function,
that stashes the absolute address of the module metadata. This is
required for booting as a Xen dom0 that does relocate the modulep and
the loaded modules, and thus requires adjusting the offset.

No functional change introduced, further patches will make use of this
functionality for Xen dom0 loading.

Sponsored by:		Citrix Systems R&D
Reviewed by:		imp
Differential revision:	https://reviews.freebsd.org/D28496
2021-02-16 15:26:11 +01:00
Roger Pau Monné
ed87efbe24 stand/efi: allow not exiting boot services
Xen requires that UEFI BootServices are enabled in order to boot, so
introduce a new parameter to bi_load in order to select whether BS
should be exited.

No functional change introduced in this patch, as all current users of
bi_load request BS to be exited. Further changes will make use of this
functionality.

Note the memory map is still appended to the kernel metadata, even
when it could be modified by further calls to the Boot Services, as it
will be used to detect if the kernel has been booted from UEFI.

Sponsored by:		Citrix Systems R&D
Reviewed by:		tsoome, imp
Differential revision:	https://reviews.freebsd.org/D28495
2021-02-16 15:26:10 +01:00
Toomas Soome
2bd4ff2d89 loader.efi: There are systems without ConOut, also use ConOutDev
Conout does contian the default output device name.
ConOutDev does contain all possible output device names, so we can
use it as fallback, when there is no ConOut.

PR: 253253
2021-02-04 23:29:38 +02:00
Toomas Soome
6c789c55c4 loader: create built in font from bold font face
We did replace full version of default font 8x16v with bold, also
use bold version for built in font.
2021-01-23 10:53:30 +02:00
Emmanuel Vadot
d002814d6b loader: Use TERM_EMU for arm and arm64
Even if it didn't behave well previously this is fixed.
Tested on: OrangePi One (armv7 u-boot) (serial only and serial + HDMI)
Tested on: Pine64-LTS (aarch64 u-boot) (serial only and serial + HDMI)
Tested on: Honeycomb (aarch64 EDK2) (serial only)

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D28153
2021-01-17 17:44:16 +01:00
Toomas Soome
52ec89a93c loader.efi: commands gop, uga and autoresize should use cached data
We are setting up pointers for gop or uga protocol in
efi_find_framebuffer(), reuse those pointers.
2021-01-17 15:33:48 +02:00
Toomas Soome
9adce1aedd loader.efi: variable 'hlist' is uninitialized
framebuffer.c:481:65: error: variable 'hlist' is uninitialized
2021-01-17 13:46:00 +02:00
Toomas Soome
fb3a792a88 loader.efi: unused variable 'mode'
framebuffer.c:707:8: error: unused variable 'mode' [-Wunused-variable]
        u_int mode;
2021-01-17 13:39:44 +02:00
Toomas Soome
ef698fabe4 loader.efi: handle multiple gop instances
Some systems may provide multiple GOP instances and not all are
bound to hardware. The current loader is picking up the first GOP,
which may not be usable. Instead we load the GOP handle array,
and test every handle to have registered ConOut protocol. If ConOut is
present, we can use this GOP handle to open GOP protocol.
2021-01-17 01:29:35 +02:00
Toomas Soome
fdaf9cb942 Revert "loader.efi: disable workaround for serial console on non-x86"
This patch is creating some issues, reverting it.

This reverts commit 8b18395487.
2021-01-13 20:18:35 +02:00
Toomas Soome
98c15d4dc2 loader.efi: initial terminal size should base on UEFI terminal size
We do select font based on desired terminal size, we do query
UEFI terminal size with conout->QueryMode(), but by mistake, the fallback
values are used.
2021-01-13 19:05:51 +02:00
Toomas Soome
8b18395487 loader.efi: disable workaround for serial console on non-x86
As efi console is drawn and with functional comconsole driver,
we can use proper terminal emulator on efi framebuffer console.
2021-01-12 13:09:11 +02:00
Toomas Soome
50180d2b52 loader.efi: reworked framebuffer setup
Pass gfx_state to efi_find_framebuffer(), so we can pick between
GOP and UGA in efi_find_framebuffer(), also we can then
set up struct gen_fb in gfx_state from efifb and isolate efi fb data
processing into framebuffer.c.

This change does allow us to clean up efi_cons_init() and reduce
BS->LocateProtocol() calls.

A little downside is that we now need to translate gen_fb back to
efifb in bootinfo.c (for passing to kernel), and we need to add few
-I options to CFLAGS.
2021-01-12 13:07:27 +02:00
Toomas Soome
1a816c7560 loader.efi: efifb_mask_from_pixfmt is missing PixelBltOnly
We are missing way to set RGB masks for BLT only framebuffer.
2021-01-11 21:16:42 +02:00
Toomas Soome
89632acb50 loader: term_image_display() should test screen_buffer
Make sure screen_buffer is not NULL.
2021-01-10 21:59:52 +02:00
Toomas Soome
3630506b9d loader: implement framebuffer console
Draw console on efi.
Add vbe framebuffer for BIOS loader (vbe off, vbe on, vbe list,
vbe set xxx).
autoload font (/boot/fonts) based on resolution and font size.
Add command loadfont (set font by file) and
variable screen.font (set font by size). Pass loaded font to kernel.

Export variables:
screen.height
screen.width
screen.depth

Add gfx primitives to draw the screen and put png image on the screen.
Rework menu draw to iterate list of consoles to enamble device specific
output.

Probably something else I forgot...

Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D27420
2021-01-02 21:41:36 +02:00
Eric van Gyzen
670d2ad820 efi loader: fix typos in a comment
...mostly because it's a harmless way to try the shiny new git repo.

Sponsored by:	Dell EMC Isilon
2021-01-01 11:38:39 -06:00
Kyle Evans
ac5f382a9d stand: properly declare subdir deps or .WAIT, do parallel build
buildworld already runs the stand build in parallel[1], so make it easier to
identify ordering issues by properly establishing dependencies or adding
.WAIT where needed.

Everything in stand/ relies on libsa, either directly or indirectly, because
libsa build is where the stand headers get installed and it gets linked in
most places.

Interpreters depend on their libs, machine dirs usually depend on top-level
libs that are getting built and at least one of the interpreter flavors.

For i386, order btx/libi386/libfirewire before everything else using a
big-ol-.WAIT hammer. btx is the most common dependency, but the others are
used sporadically. This seems to be where the race reporting on the mailing
list is- AFAICT, the following sequence is happening:

1.) One of the loaders gets built based on stale btx/btxldr
2.) btx/btxldr gets rebuilt
3.) installworld triggers loader rebuild because btx was rebuilt after

This seems like the most plausible explanation, as they've verified system
time and timestamps.

While we're here, let's switch stand/ over to a completely parallel build so
we can work out these kinds of issues in isolation rather than in the middle
of a larger build.

Reviewed by:	bdragon, sjg, tsoome
Tested by:	bdragon (-j1024, no failures, significant speed improvement)
Differential Revision:	https://reviews.freebsd.org/D23411
2020-12-31 11:15:45 -06:00
Warner Losh
4d6047edb6 Drop EFI_STAGING_SIZE back down to 64M
vmware can't cope with anything larger than 64MB. Drop this back to
64MB everywhere but arm.

PR: 251866
MFC After: 1 week
2020-12-17 17:02:09 +00:00
Jessica Clarke
f32672272f loader: Ignore the .interp section on RISC-V
Without this we risk having the .interp section be placed earlier in the
file and mess with section offsets; in particular it has been seen to be
placed at the start of the file and cause the PE/COFF header to not be
at address 0. This is the same fix as was done for arm64 in r365578.

Reviewed by:	mhorne, imp
Approved by:	mhorne, imp
Differential Revision:	https://reviews.freebsd.org/D27603
2020-12-14 00:54:05 +00:00
Maxim Sobolev
fd2ef8ef5a Unobfuscate "KERNLOAD" parameter on amd64. This change lines-up amd64 with the
i386 and the rest of supported architectures by defining KERNLOAD in the
vmparam.h and getting rid of magic constant in the linker script, which albeit
documented via comment but isn't programmatically accessible at a compile time.

Use KERNLOAD to eliminate another (matching) magic constant 100 lines down
inside unremarkable TU "copy.c" 3 levels deep in the EFI loader tree.

Reviewed by:	markj
Approved by:	markj
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D27355
2020-11-25 23:19:01 +00:00
Michal Meloun
5b5438c6f3 Add 'netserver' command to EFI loader.
In some environments is difficult to access bootp/dhcp
configuration as "standard user". Add a command that allows to set
or display the URI of the network server used as "net:" device.
Currently only tftp and nfs protocols are supported.

Typical usage pattern is:
netserver tftp://192.168.168.1/path_to_obj_dir/arm.armv7/sys/GENERIC/
boot net:kernel

Reviewed by:	imp, kevans
MFC after:	4 weeks
Differential Revision: https://reviews.freebsd.org/D26736
2020-10-14 13:13:14 +00:00
Andrew Turner
b9aa4537b2 Use adrp in the arm64 efi loader
On startup the arm64 efi loaders need to know PC-relative addresses.
Previously we used the adr instruction to find this address, however this
instruction is limited to +/- 1MiB.

Switch to adrp to find the 4k page the address is within and an add to
set the bottom 12 bits. This lets us address +/- 4GiB which should be
large enough for now.

Reported by:	imp
MFC after:	2 weeks
Sponsored by:	Innovate UK
2020-10-13 16:51:05 +00:00
Warner Losh
2fec3ae896 Add zstd support to the boot loader.
Add support to the _STANDALONE environment enough bits of the kernel
that we can compile it. We still have a small zstd_shim.c since there
were 3 items that were a bit hard to nail down and may be cleaned up
in the future. These go hand in hand with a number of commits to
sys/sys in the past weeks, should this need be MFCd.

Discussed with: mmacy (in review and on IRC/Slack)
Reviewed by: freqlabs (on openzfs repo)
Differential Revision: https://reviews.freebsd.org/D26218
2020-10-12 22:19:07 +00:00
Alex Richardson
253e820a4d Link efi programs with -pie rather than -shared
This was causing build failures in CheriBSD where we were passing -pie
already by default.

Reviewed By:	andrew
Differential Revision: https://reviews.freebsd.org/D24787
2020-10-12 11:27:08 +00:00
Warner Losh
d53ed73590 Fix video on PCI heuristic
The video on PCI heuristic was broken. It was supposed to infer a
video device when the last element of the path was a PCI DEVICE PATH
node. However, the last node in the device path is an END node, so
this heuristic never fired.

This leads, among other things, to bhyve only producing output in the
serial connection once we leave the boot loader. This restores the
dual headed boot on bhyve + UEFI (as we did in 11.2), but will favor
serial in the absence of other config which may be a change from 11.2.

MFC After: 3 days
Differential Revision: https://reviews.freebsd.org/D26572
2020-09-28 06:00:39 +00:00
Toomas Soome
1dc762d4fb loader: fix non-zfs build
We can not include zfs headers while building without zfs.

Reported by:	Oscar Holmlund
2020-09-23 19:15:22 +00:00
Toomas Soome
867ae3c38d loader: zfs_probe_dev should pick first matching zfs pool
During devswitch probe, we pick boot pool based on boot disk, if the boot
disk happens to have multiple pools in freebsd-zfs partitions, the current
code does pick last pool from boot disk as boot pool. While there is no
way at that stage to test, the more logical approach would be to pick
first matching pool.

This patch is assuming we do pass pool guid pointer with guid value 0,
this will help us to determine, if the guid value is already set or not.

The general suggestion would be not to share disk between different pools.

Reported by:	Alexander Leidinger
2020-09-23 08:22:14 +00:00