Commit Graph

2168 Commits

Author SHA1 Message Date
Warner Losh 1145891d07 kboot: Create quit command
Create a command that just quits out of the loader. Useful for
debugging.

Sponsored by:		Netflix
Reviewed by:		tsoome
Differential Revision:	https://reviews.freebsd.org/D50589
2025-05-30 09:56:51 -06:00
Warner Losh aeb446be4e style: Use static consistently
C doesn't require that we have static on both the declaration and
definition of a function. But stylistically, FreeBSD does. Make that
so. Also make a function static that wasn't because, it seems, that
static and struct look a lot alike in a column of text.

Sponsored by:		Netflix
Reviewed by:		tsoome, jhibbits
Differential Revision:	https://reviews.freebsd.org/D50588
2025-05-30 09:56:50 -06:00
Warner Losh 6aea7b224a stand: Retire arch_loadaddr using md_align, pending its replacement
arch_loadaddr() is inconsistently used. In fact, I removed it entirely
from kboot because its interface wasn't wide enough (though I broke
powerpc kboot several years ago, and this commit might fix that).  For
now, modify uboot to put it into copyin like all the other loaders
do. This might break arm ubldr.

In its place, use the new md_align() and any replacement will be called
from there, or via some explicit init() function.

These changes allow me to load a amd64 kernel via UEFI with all the
modules aligned to 16k.

Sponsored by:		Netflix
Reviewed by:		jhibbits
Differential Revision:	https://reviews.freebsd.org/D50587
2025-05-30 09:56:50 -06:00
Warner Losh 18582d3542 stand: Style nit
Sponsored by:		Netflix
Reviewed by:		chs, tsoome
Differential Revision:	https://reviews.freebsd.org/D50586
2025-05-30 09:56:50 -06:00
Warner Losh a3bdf33f3e stand: Introduce md_align
When we're loading metadata, we need to align it in a certain way. Right
now that way is hard-coded to be PAGE_SIZE. Rather than do the actual
physical thing in all these places, move this into a wrapper routine. We
may want to load a 16k kernel and align all these on 16k or a 4k kernel
and align on 4k on aarch64 (today you have to compile the loader with
the right page size). This will also reduce the number of places we
might have to touch to do that.

Sponsored by:		Netflix
Reviewed by:		tsoome, jhibbits
Differential Revision:	https://reviews.freebsd.org/D50585
2025-05-30 09:56:50 -06:00
Warner Losh 700a2c08dc stand/efi: Use EFI_PAGE_SIZE here, it's more appropriate
No functional change: We're allocating a page from EFI, which is always
4k on amd64. So, this should always be 4k. PAGE_SIZE usually is this,
but might not be in some cases. For the end of the stack pointer in the
ist1, it should point the architecture's physical page past where we've
allocated. EFI_PAGE_SIZE more faithfully reflects that here since
PAGE_SIZE might not be exactly that in the future (if we had a larger
logical page than physical page). Since the AllocPage interface is in
EFI_PAGE_SIZE pages always, this seems safer. No functional change since
they are both 2096 today.

Sponsored by:		Netflix
Reviewed by:	tsoome
Differential Revision:	https://reviews.freebsd.org/D50584
2025-05-30 09:56:50 -06:00
Marek Zarychta 9486d6d57d loader: Fix beastie and fbsdbw logo positions
Fix the beaste, beastiebw and fbsdbw postions broken after
ee233742a5

PR: 285044, 286356
Fixes: 1b4e117131
Reviewed by: imp
MFC After: 2 days (14.3 candiate)
Sponsored by: PANS Jarosław
2025-05-29 12:37:03 -06:00
Warner Losh 8e5eacbfde stand: Update comment
Some routines are necessary, so note that.

Sponsored by:		Netflix
2025-05-26 11:09:54 -06:00
Warner Losh 8cf4ac0c21 stand/kboot: Remove _end forward decl
We don't need/use it.

Sponsored by:		Netflix
2025-05-26 09:30:38 -06:00
Warner Losh 26178196de stand/userboot: Initialize archsw at compile time
Sponsored by:		Netflix
2025-05-26 09:30:38 -06:00
Warner Losh 5b90ffad87 stand/i386/zfsboot: Initialzie archsw at compile time.
Also, add a comment about the weird reason we even have an archsw here
at all. tl;dr: zfs code uses archsw when it aught not, but this hack
here is easier than fixing that code properly.

Sponsored by:		Netflix
2025-05-26 09:30:37 -06:00
Warner Losh b33f61833b stand/uboot: Move archsw init to compile time
Sponsored by:		Netflix
2025-05-26 09:30:37 -06:00
Warner Losh 36b05c0588 stand/powerpc/ofw: Initialize archsw at compile time
There's no real reason to do this at runtime.

Sponsored by:		Netflix
2025-05-26 09:30:37 -06:00
Warner Losh e94f269cd3 stand/efi: Initialize archsw at compile time
Sponsored by:		Netflix
2025-05-26 09:30:37 -06:00
Warner Losh 62d1ec7889 stand/i386: Initialize archsw at compile time
No need to initialize this at runtime. This trades .bss space + code in
.text for just .data and is net smaller by 4 bytes.

Sponsored by:		Netflix
2025-05-26 09:30:37 -06:00
Warner Losh 7429d6158c kboot: Initialize archsw at compile time
No need to initialize this at runtime. This trades .bss space + code in
.text for just .data and is net smaller.

Sponsored by:		Netflix
2025-05-26 09:30:37 -06:00
Warner Losh c4270ea884 stand/powerpc/ofw: Remove bogus end decl
This likely used to be needed for some code here, or maybe it's been
here since it was copied from elsewhere that did neeed it. Remove it.

Sponsored by:		Netflix
2025-05-26 09:30:37 -06:00
Warner Losh 81336653be stand/uboot: Remove unneeded _etext and _edata 2025-05-26 09:30:36 -06:00
Warner Losh 06a894ca9b stand/uboot: Remove unneeded nitems definition
Also, remove the trailing white space that was introduced in the same
commit as the nitems fallback definition.

Sponsored by:		Netflix
2025-05-26 09:30:36 -06:00
Simon J. Gerraty 2982c70852 stand allow for local.defs.mk
This allows us to change the VERSION_FILE used for loaders
as well as set NEWVERS_DATE and BUILD_UTC to reflect the publish
date of loaders for secure-boot.

Sponsored by:	Juniper Networks, Inc.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D50478
2025-05-22 15:47:21 -07:00
Simon J. Gerraty 41cf74fe8c loader - guard against empty rootdev
At least one instance of u-boot pretending to be EFI
is passing empty rootdev to loader which does not end well.

A simple precaution is harmless.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D50334
2025-05-20 09:10:50 -07:00
Mitchell Horne 13e520658e fdt_loader_cmd.c: fix compilation with DEBUG
It was broken on 64-bit platforms.
2025-05-15 10:53:31 -03:00
Toomas Soome 3bcf8e6db8 loader: loader can pick too large font (check if one side is larger)
The 5e25f7b099 still allows one side to be too large, fix it.
2025-05-13 10:44:35 +03:00
Alexander Ziaee 5d59c1b4f1 stand/lua manuals: Describe better
The lua boot loader module manuals were getting pulled into search
results for FreeBSD, but not for "boot" or "loader". Reword them to
increase clarity for boot or loader searches, as well as the FreeBSD
search term which we've been scoping to system topic overview manuals.

MFC after:	3 days
Reviewed by:	imp, mhorne
Approved by:	mhorne (mentor)
Pull Request:	https://github.com/freebsd/freebsd-src/pulls/1628
2025-05-12 16:58:40 -04:00
Alexander Ziaee ecdb0b79bf cdboot.8: Initial manual page
Add cdboot to the reference manual, fixing an undocumented bug where it
is undocumented. There's almost nothing here, but that's better than
"only imp and jhb know what this is".

MFC after:		3 days
Reported by:		jhb, imp
Reviewed by:		mhorne
Approved by:		mhorne (mentor)
Differential Revision:	https://reviews.freebsd.org/D50274
2025-05-12 12:23:04 -04:00
Toomas Soome 5e25f7b099 loader: loader can pick too large font
While calculating font size based on EDID data, we can end up
selecting too large font and too small terminal. Add check to
prevent it.

Tested by:	bz, ziaee
Reviewed by:	adrian
Differential Revision:	https://reviews.freebsd.org/D50258
2025-05-12 02:07:15 +03:00
Colin Percival 206198289e loader: Instrument gfx_fb_fill with tslog
Some systems boot absurdly slowly, apparently due to problems with
UEFI framebuffer accesses being sluggish.  This does not fix the
problem, but at least makes gfx_fb_fill show up as a large block
in boot flamecharts, which will save time when the next user needs
to identify why their system is booting slowly.

PR:	284595
Tested by:	Peter Miller
2025-05-11 15:19:34 -07:00
Kyle Evans 78661696e6 loader: i386: use -z nostart-stop-gc for bfd as well
binutils 2.37 seems to have added the knob, so let's just use that
version here (it's not clear if GC'ing start/stop symbols was actually
made the default at the time, and it didn't seem worth it to dig much
further).  This fixes misbehavior when built with more recent binutils,
as we do rely on linker sets for loader commands that we use.

Reported by:	sjg
Reviewed by:	dim, sjg
Differential Revision:	https://reviews.freebsd.org/D50252
2025-05-08 14:47:16 -05:00
Kyle Evans 354fb783e6 loader: ficl: restore isvirtualized?
This word was accidentally removed when gfx bindings were made optional
to remove some overhead not needed for all loaders.  This one isn't
graphics related, so we can safely restore it without irritating anyone.

Reported by:	sjg
Reviewed by:	adrian, imp
Fixes:	9c8bf69a53 ("loader: Only create gfx 4th bindings when [...]")
2025-05-07 23:06:22 -05:00
Alexander Ziaee 1ec2c8b2f3 stand: Enable Spleen 32x64 font in the bootloader
Spleen 32x64 provides my 14" 2560x1600 display with the ancestral 80x25,
BSD standard console. We already include it in contrib, and it is built
for the runtime vt(4) font directory, but was previously unavailable to
the bootloader. Enable it in the build, selectable in loader.conf with:

screen.font="32x64"

MFC after:		3 days
Reviewed by:		adrian, carlavilla, emaste, imp, mhorne, tsoome
Approved by:		imp, tsoome (loader)
Approved by:		mhorne (mentor)
Differential Revision:	https://reviews.freebsd.org/D49768
2025-05-06 11:50:28 -04:00
Warner Losh d7e6ab7a97 kboot: Add support for UEFI booting amd64
In an ideal world, we'd get systbl and efi memory map from
/sys/firmware/efi somewhere. They are currently not published,
but may be in the future.

The systab comes from the first call to the EFI entry point and there's
no way to find it otherwise.

Memmap is obtained from BootServices which is long gone. And besides,
it's modified for the runtime entries for the call to
SetVirtualAddresses call in runtime services. Even though that's in
runtime services, it can be called only once.

kexec tools + Pandora (the kexec boot loader embedded in the Linux
kenrel) don't need this because pandora copyies this structure over when
the new kernel is a bzImage. Our current trampoline doesn't do that, so
we have to get it from the current kernel. Even so, we have to pass the
PAs for the memory map to the trampoline which copies this over (in part
so we can boot an modified kernel, otherwise we could put this into an
alternative entry point, but those are hard to manage).

So, we can sig out the PA of the memory map via this method, but some
care is needed. For the initial round, it suffices. However, Linux on
x86 does some odd things with EFI_RUNTIME that need to be preserved (so
this is a temporary measure until we get the /sys/firmware/efi code
working). The Linux kernel keeps this memory around, but it's not clear
how long. It stops referencing it after it converts it to the BIOS e820
memory map array it uses elsewhere. It seems to be OK to use since our
use case is an immediate boot to FreeBSD, not a boot after Linux runs a
while and had a chance to (maybe) overwrite this data.

Migrating to a proper interface that publishes the modified EFI
map in /sys/firmware/efi/memmap is in the future.

Update the trampoline to copy this data before jumping into the kernel.
We use the simple laucnhing interface instead of the bzImage interface
that kexec_file() uses, so there's no last-second chance to use the
boot params data.

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D49869
2025-04-17 15:56:47 -06:00
Warner Losh f3c0d74e3b kboot: Implement data_from_kernel to read kernel variables
Since the linux kernel doesn't expose enough of the EFI details to
userland via /sys/firmware/efi, write a routine to extract data from the
kernel directly by parsing /proc/kproc and /proc/kallsyms.

Sponsored by:		Netflix
Reviewed by:		kevans, jhibbits
Differential Revision:	https://reviews.freebsd.org/D49868
2025-04-17 15:56:46 -06:00
Warner Losh b7d1c3fdde kboot/amd64: Use efi_bi_loadsmap in bi_loadsmap
For the EFI case, we just need to call efi_bi_loadsmap in bi_loadsmap.
If we need to do BIOS again, we'll revisit.

Sponsored by:		Netflix
Reviewed by:		kevans,	jhibbits
Differential Revision:	https://reviews.freebsd.org/D49867
2025-04-17 15:56:46 -06:00
Warner Losh 50bc81e700 kboot/amd64: Use segs framework to find kernel location
Use the segs framework to find a place to land the kernel, with the same
super ugly defaults as aarch64.

Sponsored by:		Netflix
Reviewed by:		kevans,	jhibbits
Differential Revision:	https://reviews.freebsd.org/D49866
2025-04-17 15:56:46 -06:00
Warner Losh 9acf642220 kboot/amd64: Use common routines for memory map parsing
Use populate_avail_from_iomem and efi_read_from_sysfs from the
refactored work rather than replicating them (imperfectly) here.

Note: memmap might need to be revisited. EFI memory maps are complex on
x86 and we might need to reconstruct it from /sys/firmware/memmap as
well as using that for the BIOS case, should we ever want to support
that again (hardware makes no sense, but many VM hosting services use
that). For now, we're going all in on EFI, though, and will revisit what
to do about BIOS later. The zfsboot project suggests BIOS support isn't
really that hard (but is a distraction atm).

Sponsored by:		Netflix
Reviewed by:		kevans,	jhibbits
Differential Revision:	https://reviews.freebsd.org/D49864
2025-04-17 15:56:46 -06:00
Warner Losh 92ad79ec33 kboot: Move common EFI stuff from aarch64 to libkboot
Move efi_read_from_pa, efi_set_systbl and efi_bi_loadsmap into efi.c
Move prototype for populate_avail_from_efi as well, though that arrived
previously.

Move efi memory map variables into efi.c.

Add efi_read_from_sysfs, but if 0 it out. We'll want to use it if we can
get the proposed /sys/firmware/efi/memmap data published in the same
format and the code works, it's just that the current
/sys/firmware/efi/runtime-memmap isn't complete enough to use.

Sponsored by:		Netflix
Reviewed by:		kevans,	jhibbits
Differential Revision:	https://reviews.freebsd.org/D49863
2025-04-17 15:56:46 -06:00
Warner Losh 988ee1cc68 kboot: Method to populate the avail array from EFI map
If we can get an efi memory map, populate_avail_from_efi will create an
avail array. We only use the regiions marked as 'free' to find a place
for the kernel to land. The other regions are also eligible, but usually
too small to materially affect where we'd put the kernel (not to worry,
the kernel will use that memory).

Sponsored by:		Netflix
Reviewed by:		kevans,	jhibbits
Differential Revision:	https://reviews.freebsd.org/D49862
2025-04-17 15:56:46 -06:00
Warner Losh 0c48531b46 kboot: Account for machine specific padding
AMD64 kernels have an extra 2MB of padding that we need to account
for. So make the padding proper on a per-architecture basis.

Sponsored by:		Netflix
Reviewed by:		kevans,	jhibbits
Differential Revision:	https://reviews.freebsd.org/D49861
2025-04-17 15:56:46 -06:00
Warner Losh d27413a7d7 loader: Remove unneeded includes
We've not needed to include link.h in the loader for a long time. I
shoud have removed it in f38658e140 rather than going link.h ->
sys/sys_link.h. It's purely a userland shared library thing. Remove it
now, since it's not needed. Also remove a few headers that are redundant
with stand.h in this environment.

Sponsored by:		Netflix
Reviewed by:		kevans, andrew,	jhibbits
Differential Revision:	https://reviews.freebsd.org/D49859
2025-04-17 15:56:45 -06:00
Warner Losh f0f44cdb69 kboot: Save the upper limit of the call stack.
The location of argc argument is a fine limit for the extent of the
stack traceback. We could save the location of return address for the
call to _start_c, but we'd have to move that into MD assembler. While
not hard, it wouldn't improve the traces we can get. And the math to
find it is architecture dependent (though the same for both arm64 and
amd64).

Sponsored by:		Netflix
Reviewed by:		kevans, andrew,	jhibbits
Differential Revision:	https://reviews.freebsd.org/D49858
2025-04-17 15:56:45 -06:00
Warner Losh 5fb044c885 kboot: format nit
Deleting trailing newline.

Sponsored by:		Netflix
Reviewed by:		kevans, andrew, emaste,	jhibbits
Differential Revision:	https://reviews.freebsd.org/D49857
2025-04-17 15:56:45 -06:00
Warner Losh 14acbf6159 kboot: Add option to parse 32-bit quantity
The type that's exposed from sysfs' memory map is 32-bit and so is the
data-type of memory description.

Sponsored by:		Netflix
Reviewed by:		kevans, andrew,	jhibbits
Differential Revision:	https://reviews.freebsd.org/D49856
2025-04-17 15:56:45 -06:00
Warner Losh 58c99df219 kboot: .note.GNU-stack is needed
Add '.section .note.GNU-stack,"",%progbits' to all assembler. Newer
versions of clang complain when this isn't present because executable
stacks are going away in the future. We don't need an executable stack
anyway.

Sponsored by:		Netflix
Reviewed by:		kevans, andrew, emaste, jhibbits
Differential Revision:	https://reviews.freebsd.org/D49855
2025-04-17 15:56:45 -06:00
Warner Losh 4caaab2e6d kboot: Spell Reserved correctly
Also, remove trailing NULL entry that's no longer needed.

Sponsored by:		Netflix
Reviewed by:		kevans, jhibbits
Differential Revision:	https://reviews.freebsd.org/D49854
2025-04-17 15:56:45 -06:00
Emmanuel Vadot a962800a09 loader: Add loader_menu
If set to 'none' then the menu isn't displayed.
The 'brand' and 'logo' part are stil displayed.

Differential Revision:	https://reviews.freebsd.org/D49820
Reviewed by:	imp, kevans
Sponsored by:	Beckhoff Automation GmbH & Co. KG
2025-04-17 10:18:48 +02:00
Emmanuel Vadot 8e727fb47a loader: Add loader_autoboot_show
It's used to control if the autoboot part of loader is displayed or not.

Differential Revision:	https://reviews.freebsd.org/D49819
Reviewed by:	imp
Sponsored by:	Beckhoff Automation GmbH & Co. KG
2025-04-17 10:18:20 +02:00
Warner Losh 3a05fa14f9 loader/efi: strip trailing whitespace
Many of these no-doubt are in upstream, but they are interfering with
the filters I use to judge commits (no traling whitespace). We don't
directly get stuff from upstream. If/when we pull this from contrib
we'll revisit.

Sponsored by:		Netflix
2025-04-11 16:02:58 -06:00
Warner Losh 7e791e2de6 loader/libefi: Fix trivial trailing whitespace
Sponsored by:		Netflix
2025-04-11 15:48:52 -06:00
Warner Losh 0d1d8c8cfa loader/efi: Fix trivial whitespace error
Sponsored by:		Netflix
2025-04-11 15:47:06 -06:00
Ravi Pokala 3adae4f27d loader: Add the CPU identification string to the data which is visible
in the bootloader.

Reviewed by:	imp
MFC after:	1 week
Sponsored by:	Vdura
Differential Revision: https://reviews.freebsd.org/D49708
2025-04-10 21:01:55 -07:00