100 Commits
Author SHA1 Message Date
Warner Losh 041802b362 Add loongarch64 as an optional boot-test.sh arch
D59889 brings up a FreeBSD/loongarch64 EFI loader, none of it in
this tree yet. Add a disabled config entry (excluded from -A, usable
via -a once the port lands) using the confirmed QEMU virt/la464
recipe; hw/loongarch/virt.c defaults to virtio-blk/net, so the
existing generic EFI+GPT builder needs no arch-specific QEMU code.

loongarch64 has never had a FreeBSD release, so
install_minimal_userland's ISO extraction can never find one. Split
it into ISO and installworld-cross-build paths, selected by a new
no_release capability, so archs without a release can still get a
minimal userland.

Differential Revision:	https://reviews.freebsd.org/D59923
2026-10-19 01:03:19 -06:00
Warner Losh ee96770ee3 nvmecontrol: Fix mixup between pi and pil
pi and pil were extracted from the incorrect place. Swap how we get/set
there to be correct. However, since these are always 0, this is a nop.
2026-10-19 00:22:51 -06:00
Warner Losh bf3726998f nvmecontrol: Use admin device for admin-passthru
When we're doing admin-passhtru, we need to use the admin device, not
the namespace device. So when we're passed in ndaX or nvdX, we need to
translate that to nvmeY for this command for the admin-passthru command,
but not the io-passthru command. Note namespace nuance in man page.

Differential Revision:	https://reviews.freebsd.org/D59878
2026-10-19 00:22:51 -06:00
Warner Losh 3b66efc6e9 nvmecontrol: add format dry-run support
Add -n/--dry-run to resolve and print the Format NVM command without
submitting it. This lets users verify namespace selection and format
parameters before making destructive media changes.

Reviewed by:		seuros, chuck
Differential Revision:	https://reviews.freebsd.org/D59835
2026-10-19 00:22:51 -06:00
Warner Losh b991e2dd82 nvmecontrol: support controller-wide sector sizes
Extend sector-size selection to controller-wide formats when every
namespace has one compatible format index and matching effective
metadata and protection settings. Reject ambiguous or inconsistent
layouts so heterogeneous fleets can request a sector size without
risking an unintended controller-wide format.

Reviewed by:		seuros, chuck
Differential Revision:	https://reviews.freebsd.org/D59834
2026-10-19 00:22:51 -06:00
Warner Losh 4623bbfe7b nvmecontrol: select format by sector size
Add automatic selection of lbaf value based on a single sector size. The
lbas (the data sector size) is selected based on the power of 2 in the
sector size, and the metadata size is selected by the remainder. If an
lbaf matches these values is used, otherwise we exit with an error.
When there's a tie, we prefer the higher performance.

Manual selection of these values remains as well for times when we
select incorrectly.

Reviewed by:		seuros, chuck
Differential Revision:	https://reviews.freebsd.org/D59833
2026-10-19 00:22:51 -06:00
Warner Losh e65ccec8c0 nvme: Notify namespaces on reset sometimes
When we're resetting after a controller failure, and we fix the failure,
and we've not resetting as part of initialization, notify the all the
children devices of new namespaces. When we failed the controller
before, we removed all the namespaces.

Reviewed by:		seuros
Differential Revision:	https://reviews.freebsd.org/D59832
2026-10-19 00:22:51 -06:00
Warner Losh 66c24c9432 nvme: Refactor namespace notifications for additions
When we add a namespace, we have the code inline to do the
notifications. Refactor ahead or reuse.

Reviewed by:		seuros
Differential Revision:	https://reviews.freebsd.org/D59831
2026-10-19 00:22:50 -06:00
Warner Losh 15cd8528b1 nvme: honor Linux passthrough command timeouts
Now that we have per-command timeouts, allow linux-compat ioctls to have
a passed-in timeout.

Reviewed by:		seuros, chuck
Differential Revision:	https://reviews.freebsd.org/D59829
2026-10-19 00:22:50 -06:00
Warner Losh 1c31ef40e1 nvme: support per-request timeouts
Allow different timeouts per command.

Reviewed by:		seuros, chuck
Differential Revision:	https://reviews.freebsd.org/D59828
2026-10-19 00:22:50 -06:00
Warner Losh 5258b44e84 nvme: add a timeout for Format NVM commands
Format commands need a longer timeout.

Reviewed by:		seuros, chuck
Differential Revision:	https://reviews.freebsd.org/D59827
2026-10-19 00:22:50 -06:00
Warner Losh ab7249c288 cam: Assert we have the periph lock when updating the iosched stats
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D60350
2026-10-06 16:50:38 -06:00
Warner Losh 7845cf8de8 ada: Update trim stats for every bio
Separate the updating the stats for the completion from the biodone for
each one.

Sponsored by:		Netflix
Reviewed by:		ali_mashtizadeh.com
Differential Revision:	https://reviews.freebsd.org/D60157
2026-10-06 16:46:23 -06:00
Warner Losh bd86f0508e da: Update trim stats with the periph lock held
Separate the updating the stats for the completion from the biodone for
each one.

Sponsored by:		Netflix
Reviewed by:		ali_mashtizadeh.com
Differential Revision:	https://reviews.freebsd.org/D60156
2026-10-06 16:46:23 -06:00
Warner Losh 4a3a5de8ac nda: Update trim stats with the periph lock held
Separate the updating the stats for the completion from the biodone for
each one.

Sponsored by:		Netflix
Reviewed by:		ali_mashtizadeh.com
Differential Revision:	https://reviews.freebsd.org/D60155
2026-10-06 16:46:22 -06:00
Warner Losh 0040d1fb7a cam: Rename cam_iosched_bio_complete to cam_iosched_bio_update_stats
The function updates scheduler statistics but does not complete the
bio. Rename it to avoid implying ownership of bio completion.

Sponsored by:		Netflix

Reviewed by:	ali_mashtizadeh.com
Differential Revision:	https://reviews.freebsd.org/D60349
2026-10-06 16:46:22 -06:00
Warner Losh 35b59986b5 g_part: access leak causes process to hang
So if one inserts a USB drive with a GPT that doesn't match the media
size, a resize is initiated, so gpart takes g_access(cp, 1, 1, 1) on the
disk and holds it until the resize is accepted or rejected. The orphan
path releases it, but the spoil path does not. So if the drive is
ejected while the resize is in flight, we call spoil directly, without
releasing the access. Since gpt_opened is not cleared for the spoil
path, this causes several different process to hang in the open path
waiting for the leaked access.

Move the release into the wither function when gpt_opened is set, and
remove the release elsewhere. Since all paths to destroy the geom pass
through wither, this ensure that access is always released when we've
taken the access for resize.

PR:			297777
Reported by:		Rick Richard
MFC After:		1 week
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D59138
2026-10-04 13:21:17 -06:00
Warner Losh edc51d1de5 stand: Bump version to 3.1
Sponsored by:		Netflix
2026-10-03 23:17:08 -06:00
Warner Losh 262fa4695d stand: Implement zfs_dnode_readlink in terms of zfs_dnode_sa_lookup
Get the link offset using the zfs_dnode_sa_lookup helper now.

Recently, the symbolic links we rely on in the boot loader have stopped
working.

Prior to OpenZFS commit e90badec11 ("Inherit the project ID for every
object type", Matt Turner, 2026-08-14), symbolic link information was
written at a fixed offset in the SA data. Since that commit, the
inherited PROJIDs mean that all pools with quota enabled have started
writing symbolic links with a new, non-fixed offset. Old symbolic links
remained unchanged, but new ones were written with a different
offset. At work, we have all these things: rewritten BEs, quotas, and a
dependence on symbolic links in our boot path.

This came in on 2026-08-24 OpenZFS merge (22649d4dba). This was 12
hours after stab week for August, so we didn't hit this until the
September stab week. Since the new kernel has to write links at the new
offset, the initial tests worked, but the second ones didn't.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D60268
2026-10-03 11:32:08 -06:00
Warner Losh f382ef1dc8 stand: update zfs_dnode_stat to use zfs_dnode_sa_lookup
Find the SA values with the zfs_dnode_sa_lookup and read out the
relevant bits for the stat buffer.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D60267
2026-10-03 11:32:08 -06:00
Warner Losh 8bc06ba211 stand: Lookup specific SA value in a dnode
zfs_dnode_sa_lookup will look in the bonus part of the dnode for the
requested SA values, and fall back to the spill as if it's not there.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D60266
2026-10-03 11:32:08 -06:00
Warner Losh 4175fa107f stand: Lookup the offsets for this SA bundle
Compute the offset for the data for this bundle and the requested data
type.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D60265
2026-10-03 11:32:08 -06:00
Warner Losh 32fcc66dd3 stand: Load dynamic system attribute offsets
zfs_sa_load looks up all the system attribute offsets and stores them in
the mountpoint.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D60264
2026-10-03 11:32:08 -06:00
Warner Losh 16cf795d3e stand: zfs_dnode_readlink move from spa to mount argument
For the dynamic system attributes, we'll need the mount argument. Adjust
zfs_dnode_readlink to take that argument.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D60262
2026-10-03 11:32:07 -06:00
Warner Losh ecd41c0df3 stand: zfs_dnode_stat move from spa to mount argument
When reading dynamic system attributes, we'll need the mount argument
since we can no longer hard-code the offsets. Adjust zfs_dnode_stat to
take it.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D60261
2026-10-03 11:32:07 -06:00
Warner Losh acbcb68c9f stand: Remove const from zfs_lookup's zfsmount argument
Dynamic system attribute layout can require modifications to the mount
structure on lookup. Drop the const to allow that.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D60260
2026-10-03 11:32:07 -06:00
Warner Losh d8acc2a9a4 boot-test.sh: Add gptboot.efi tests
Make sure that we can chainboot with gptboot.efi. Many projects use this
as their migration tool from gptboot to ping-pong partitions to boot
from. This tests that functionality which I recently broke.

Assisted-by: Claude Code (Fable 5, Opus 5)
Sponsored by:		Netflix
2026-09-26 00:44:21 -06:00
Warner Losh 9ecc2493ca Restore booting the partition the EFI boot image was loaded from.
BSDRP images are built with "poudriere image -t firmware", which puts
gptboot.efi on the ESP instead of loader.efi.  gptboot.efi reads the GPT
bootme attribute, picks the active system partition (BSDRP1 or BSDRP2),
chainloads /boot/loader.efi from it and hands loader.efi that partition
in LoadedImage->DeviceHandle (stand/efi/boot1/boot1.c:try_boot).

Since ce9bfd7816 ("loader.efi: Refactor try_boot_device_partitions"),
find_currdev() no longer tries that device: try_boot_device_partitions()
walks the parent disk while explicitly skipping dp->pd_handle, on the
assumption that the boot image always comes from an ESP holding no root
filesystem.  When chainloaded, the partition gptboot.efi selected is
therefore the one partition never considered, and loader.efi falls
through to the first other UFS partition on the disk - the previous
system.  Every A/B upgrade silently boots the old slice.

Commit 1c85c5eea0, which introduced try_boot_device_partitions(), did
try dp itself before its siblings; the refactor dropped it.  Restore it,
keeping the sibling walk as the fallback for the normal ESP case.

Fixes: ce9bfd7816
Assisted-by: Claude Code (Fable 5, Opus 5)
Sponsored by: Netflix
2026-09-26 00:44:20 -06:00
Warner Losh 4f06a8e490 edk2: Import FileInfo.h from edk2-stable202502
Sponsored by:		Netflix
2026-09-26 00:44:20 -06:00
Warner Losh a844bc229e boot-test.sh: Add netboot-http-efi test
Using iPXE, chainboot loader.efi with rootdev=http://${next-server}/
to test the loader's http:// code.

Sponsored by:		Netflix
2026-09-26 00:43:54 -06:00
Warner Losh ab9130c737 boot-test.sh: Add a http server per interface
Add the built-in python http server, bound to each of the interaces we
create to expand network testing to include http:// in various
scenarios.

Sponsored by:		Netflix
2026-09-26 00:43:53 -06:00
Warner Losh 58741fa51d boot-test.sh: Add virtio-rng-pci to the EFI RAM-disk netboot qemu invocation
Since the PixieFail security fixes (CVE-2023-45237), EDK II's DxeNetLib --
underneath essentially all of NetworkPkg (Mnp/Arp/Ip4/Dhcp4/Tcp/Http) --
carries a DEPEX on EFI_RNG_PROTOCOL. With no RNG protocol producer
available, that DEPEX is never satisfied and the entire NetworkPkg driver
stack silently fails to load: no error, no assert, it just isn't there.

netboot-efi and netboot-ramdisk never noticed because they only ever touch
the raw EFI_SIMPLE_NETWORK_PROTOCOL via our own net.c, which has no such
dependency. A test that needs EDK II's own NetworkPkg (e.g. one exercising
EFI_HTTP_PROTOCOL) is the first to be affected.

RngDxe can satisfy the DEPEX from the RDRAND instruction alone on a
sufficiently recent edk2 build, but not every installed OVMF is that
recent. -device virtio-rng-pci provides an RNG unconditionally via
VirtioRngDxe, regardless of edk2 vintage or host CPU features.

Unfortunately, the edk2 shipped with qemu lacks the network this needs.

Sponsored by:		Netflix
2026-09-26 00:43:53 -06:00
Warner Losh d2cce99069 build/options: Remove old, obolsete GCC options
These aren't referenced in the tree anymore, so remove them from
here. This doesn't chanage src.conf.5, so I didn't commit that file.

Sponsored by:		Netflix
2026-09-24 08:32:32 -06:00
Warner Losh b5f0e7f36a loader.efi: Be cautious about using GOPs
When we're searching for the EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID (GOPs) to
use, skip any whose Mode or Mode->Info pointers are NULL. The spec
requires these to be non-null, however, some firmwares seem to fail to
populate the Info when, for example, a monitor is not present. Work
around these bugs by skipping any GOPs with bad pointers.

PR: 288900
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D59830
2026-09-24 01:22:25 -06:00
Warner Losh 85fb40bad5 loader.efi: Use EfiLoaderData memory type for ram disks
For the images we read into the memory, use EfiLoaderData memory type
instead of EfiReservedMemoryType. The kernel handles the former properly
and won't reallocate it. While the latter isn't necessarily mapped,
which can cause ram disks to fault when loaded. memdisk_uefi.efi
used the latter type, but also registered the device as an ACPI
RAM disk, which we don't do.

Fixes: afee781523
Sponsored by: Netflix
2026-09-24 00:59:42 -06:00
Warner Losh e960cb4c03 edk2: Import Loadfile2.h and TcgService.h from edk2-stable202502
Verbatim import of these files, with unix line endings.

Sponsored by:		Netflix
2026-09-24 00:46:04 -06:00
Warner Losh 06488d2a12 linux: LINUX_PR_SET_THP_DISABLE all non-zero values are disable
Linux treats any nonzero value as "disable", so accept them all.

Fixes: a8a6eac570
Sponsored by:		Netflix
2026-09-12 10:59:17 -06:00
Warner Losh 772c658c66 loader: Use %u to print unsigned value
Fixes: 7055aa7a07
Sponsored by:		Netflix
2026-09-12 10:59:17 -06:00
Warner Losh 6413a870fa loader: Move some support things around, maybe lame?
Sponsored by:		Netflix
2026-09-12 10:59:17 -06:00
Warner Losh 197df29edb loader.efi: Only try to download md if we're netbooting
The only possible time we could download the initmd that the dhcp server
told us about is if we're netbooting. So only attempt to do that if the
load device for loader.efi is a network. IF you are booting off disk and
then need to snag an initmd off the network, that's a different path,
and wouldn't need to necessarily do a dhcp exchange, except to get the
IP address.

Sponsored by:		Netflix
2026-09-12 10:59:17 -06:00
Warner Losh 577ea37d6d loader.efi: Expose efi_devpath_get_mac to get mac
This is a convenient way to test if a device path is a nic or not, so
expose it to the world.

Sponsored by:		Netflix
2026-09-12 10:59:17 -06:00
Warner Losh bbee544312 loader.efi: Fix memory leak in efihttp_dev_close
Save enough context to free the host we allocated in open on close.

Fixes: 6788e42d53
Noticed by: claude + Sonet 5
Sponsored by: Netflix
2026-09-12 10:59:16 -06:00
Warner Losh f9517d2374 mpsutil: Better naming form the discovery_status function
It's really discovery_status_str(). Rename it and use open_memstream()
to write the string so we don't have to play as many str* games.

Fixes: afb60897a1
Noticed by: claude + Sonet 5 (size error, bad fix ignored)
Sponsored by: Netflix
2026-09-12 10:59:16 -06:00
Warner Losh baa78c87eb nvmecontrol: Minor correctness issues
Turn an assert into a bounds check to not overflow if the nvme drive
reports too many power states (we validate the user input, but not the
drive's identify data).

Use a uint32_t instead of int for entry so right shift we do is defined.

No functional changes.

Fixes:			35793364d7
Noticed by:		claude + Sonet 5
Sponsored by:		Netflix
2026-09-12 10:59:16 -06:00
Warner Losh 79e2a46a6a nvmecontrol: Fix APST transition encoding
Use uin64_t casts to encode data sent to avoid overflows.

Fixes: 35793364d7
Sponsored by: Netflix
2026-09-12 10:59:16 -06:00
Warner Losh a8a6eac570 linux: implement prctl PR_{G,S}ET_THP_DISABLE
Since we don't have THP in FreeBSD, return that it's disabled. Linux
applications use this to get around the weird latency spikes THP in
Linux creates. Since FreeBSD superpages don't suffer from this issue,
just say it's disabled.

This removes the noisiest noise from the linux claude running on
FreeBSD.

Sponsored by:		Netflix
2026-09-10 23:42:34 -06:00
Warner Losh a259b98fa2 tests: skip gracefully when the tested binary's own package isn't installed
pkgbase splits programs and their tests into separate packages (e.g.
unifdef/yacc/indent/file2c -> toolchain, jail -> jail, etc), while their
tests always land in the generic tests package.  Installing just the
tests package therefore leaves these suites unable to find the binary
they exercise, and they fail confusingly instead of skipping.

Rather than force all packages to be installed for the tests package,
make the tests cope with the missing packages.  Add require.progs (or,
for TAP/PLAIN-style suites with no atf_set hook: TEST_METADATA
required_programs) for the binary under test in: bectl, certctl,
ctfconvert, dhclient, file2c, indent, ipfw, jail, lastcomm, mixer,
newsyslog, nvmecontrol, pfctl, praudit, sa, syslogd, tunefs, unifdef,
yacc, ztest.

I skipped adding data for all the binaries in the base runtime
package for simplicity.

Assisted-by:		Claude Code (Sonnet 5)
Sponsored by:		Netflix
Reviewed by:		ngie
Differential Revision:	https://reviews.freebsd.org/D58262
2026-09-10 23:42:25 -06:00
Warner Losh 73df5f2ec9 man: Do glob expansion with echo instead of ls
echo is a shell builtin, and always present. While ls usually works,
some upgrade scenarios need to have ls be a build to to work
correctly. Rather than add it as a build tool, use echo instead which is
always safe because sh is a build tool.

Sponsored by:		Netflix
2026-09-10 23:13:46 -06:00
Warner Losh c4c790949f dtrace: Instrument more of the CAM device lifecycle
cam::periph:error, cam::{,a,n,sd}da:error
	Trace the error evolution for I/O errors the periph encounters

cam::periph:recovery, cam::{,a,n,sd}da:recovery
	Trace the result of the error sorting

cam::periph:invalidate
	Trace device invalidations

cam::periph:hold-boot
cam::periph:release-boot
cam::xpt:hold-boot
cam::xpt:release-boot
	Trace boot holds and releases at different levels

cam::xpt:bus-register
	Trace new busses added

These additions allow fairly complete instrumentation of the discovery
process at boot through dtrace's anonymous tracing. It would be mildly
better to have the boot holds have the periph, but dtrace sbts have to
be static at compile time.

Sponsored by:		Netflix
Reviewed by:		dteske
Differential Revision:	https://reviews.freebsd.org/D58523
2026-09-10 23:13:30 -06:00
Warner Losh afb60897a1 mpsutil: Add Show Discovery command
Prints the current discovry tables for the driver.

Sponsored by:		Netflix
Assisted by:		Claude (sonet-5)
Differential Revision:	https://reviews.freebsd.org/D58528
2026-09-10 23:13:14 -06:00
Warner Losh d04083d52b cam: Add devctl message for invalidation of a periph.
Report serial number, if available, otherwise report the path of the
device invalidated.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D58527
2026-09-10 23:13:08 -06:00
Warner Losh e2bcab51fb da: Fix logic error
Apply de-morgan's law correctly to force only 4/2 to go to the
invalidate stage for that ASC/ASCQ.

Fixes: d78d04b17c
Sponsored by:		Netflix
MFC After: 1 week
Reviewed by:	ali_mashtizadeh.com, mav
Differential Revision:	https://reviews.freebsd.org/D58525
2026-09-10 23:12:55 -06:00
Warner Losh 0bc6c9279e da: Stop the probing when periph invalidated in dadone_proberc
When READ CAPACITY fails, we call cam_periph_invalidate() for some
hopeless ASC/ASCQ combinations and then fall through to test the cache
state. This results in excess commands to the abandoned device that may
take a while to timeout and/or report confusing errors. Instead, call
daprobedone() when the periph is invalid to terminate the probe.

Fixes: d78d04b17c
Sponsored by:		Netflix
MFC After: 1 week
Differential Revision:	https://reviews.freebsd.org/D58524
2026-09-10 23:12:29 -06:00
Warner Losh 8821d42d8b loader.efi: Allow downloading of ramdisk or md to be aborted
Hitting <ESC> will now allow one to abort a (possibly mistaken)
download.

Sponsored by:		Netflix
2026-09-10 22:15:29 -06:00
Warner Losh 0ca12047be loader.efi: Eat the character used to break to OK
When we can't find root, we give the user a chance to drop to the boot
loader OK prompt. We should eat the character that's pressed to not
interfere with the interactive session.

Sponsored by:		Netflix
2026-09-10 22:15:29 -06:00
Warner Losh 08265d5ede loader: Fix starting typo
Fixes:			a22fa5ec74 ("laoder.efi: Fix error in download protcol")
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D59434
2026-09-10 22:15:29 -06:00
Warner Losh 6de311d309 loader.efi: download DHCP initmd specified image
When we haven't downloaded an image via mem{disk,cd} and ipxe, try any
image specified by the FreeBSD-specific initmd dhcp option. This allows
direct booting of loader.efi with a detached root ramdisk filesystem.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D59433
2026-09-10 22:15:29 -06:00
Warner Losh d48e9bff8c loader.efi: fetch initmd specified by DHCP
Configure net0, read the DHCP-provided initmd URL, and download it
through the file API so directly booted loader.efi can construct its
root memory disk.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D59432
2026-09-10 22:15:29 -06:00
Warner Losh 25b58eb37a loader.efi: download md images through file API
Feed the existing decompressor from loader file descriptors as well as
iPXE callbacks, allowing arbitrary HTTP filesystem URLs to become
kernel-exportable memory disks.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D59431
2026-09-10 22:15:29 -06:00
Warner Losh 5bbd617cc5 loader.efi: release SNP after network configuration
Close the exclusively opened SNP protocol after loader networking
finishes so the firmware network stack can reconnect the controller and
service a subsequent HTTP request.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D59430
2026-09-10 22:15:28 -06:00
Warner Losh e6b997c73c loader: add standalone network configuration
Allow callers to obtain DHCP configuration without opening a network
file, enabling loader.efi to discover an initmd URL before handing the
interface back to firmware HTTP.

Differential Revision:	https://reviews.freebsd.org/D59429
Sponsored by:		Netflix
2026-09-10 22:15:28 -06:00
Warner Losh a098fd021e loader: request DHCP initmd option
Request FreeBSD RFC 3925 PEM 2238 DHCP 125 option. Use suboption 1 to
specify a ramdisk image to load and use to load the kernel and as the
root file system.

Differential Revision:	https://reviews.freebsd.org/D59428
Sponsored by:		Netflix
2026-09-10 22:15:28 -06:00
Warner Losh 6788e42d53 stand/efihttp: Support arbitrary http[N]://host[:port]/path devspecs
Until now, the "http" device only worked when firmware itself booted
loader.efi via EFI HTTP Boot: efihttp_dev_init() required a URI node on
the loader's own boot device path, and every fetch went to that same
server. Add a second form, using the parse_uri() helper from libsa/dev.c,
that works anywhere: http[N]://host[:port]/path (N is a network interface
unit, defaulting to 0). This lets a devspec like this be used as rootdev,
in loader.conf, or interactively, independent of how loader.efi itself
was booted.

Network configuration is shared, loader-wide state (the myip/netmask/
gateip/nameip globals from net.h): if something has already configured
them (e.g. tftp/nfs via net_open()), the http device just reuses those
values, applying them to EFI_IP4_CONFIG2_PROTOCOL as a static address. If
nothing has, it drives IP4Config2's own DHCP directly instead of calling
netdev's net_open(): net_open() opens the NIC's SNP
EFI_OPEN_PROTOCOL_EXCLUSIVE, which would disconnect the Mnp/Ip4/.../
HttpDxe driver chain this code depends on. That chain is also commonly
disconnected already by whatever chained us here (e.g. iPXE excludes and
exclusively opens SNP for its own raw I/O), so reconnect it explicitly
with ConnectController() before giving up.

The legacy EFI HTTP Boot path is untouched.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D59423
2026-09-10 22:15:28 -06:00
Warner Losh 7208b3b845 libsa: Add a generic URI-syntax devspec parser
Add parse_uri(), a helper for devices whose devspec can take a
"[N]://host[:port][/path]" form in addition to the traditional "N:path"
form. It returns EINVAL when devspec doesn't match that pattern, so a
caller's own dv_parsedev can fall back to the traditional form.

Un-static default_parsedev() so it can serve as that fallback.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D59422
2026-09-10 22:15:28 -06:00
Warner Losh f1163b9436 loader.efi: For ipxe booting, fall back to md when ramdisk fails
Some UEFI firmwares do not contain the RamDisk protocol. When this
happens, load the file into a md disk instead. This is less desireable
than the RamDisk (since that allows better chain-booting options), but
sufficient to boot an image as a md device for FreeBSD. While most
severs have the RamDisk protocol enabled in their builds, I have two
IoT class boards from different manufacturers that do not. Since it
works just fine with this fallback, that's preferable.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D59421
2026-09-10 22:15:28 -06:00
Warner Losh 96b1e04a74 loader: Add md support
Allow md devices like efi allows them.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D59420
2026-09-10 22:15:27 -06:00
Warner Losh 69d1595ded loader.efi: Move probing the md up to before doing bootmgr
When someone has loaded a ram disk, that's a stronger hint about what to
boot than the UEFI boot manager. Prefer it and rework a little the #ifdefs
to reduce their number.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D59419
2026-09-10 22:15:27 -06:00
Warner Losh 752bde7da6 loader: Allow dynmaic creation of MD disks
Augment the md device to allow creation of md devices. This is useful
when UEFI doesn't support RamDisk and in other cases where we have a
handy initrd-like image we want to use.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D59418
2026-09-10 22:15:27 -06:00
Warner Losh 7055aa7a07 loader: Move ramdisk export to md.c
Move the common routine to md.c and use it where we do memdisks today.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D59417
2026-09-10 22:15:27 -06:00
Warner Losh 4f7475ab5b loader: Small tweak to how md is configured
Only the EFI loader supports the md devices (as the moment). Create
LOADER_MD_SUPPORT and only try to compile md when that's true. For the
moment, also allow it when only MD_IMAGE_SIZE is defined, but that
will be dropped since LOADER_MD_SUPPORT is a superset.

Sponsored by:		Netflix
Reviewed by:		tsoome
Differential Revision:	https://reviews.freebsd.org/D59416
2026-09-10 22:15:27 -06:00
Warner Losh 8fae9294d6 loader: Allow this to compile w/o MD_IMAGE_SIZE defined
Slight tweak to allow md.c to be compiled when MD_IMAGE_SIZE isn't
defined.

Sponsored by:		Netflix
Reviewed by:		olivier, tsoome
Differential Revision:	https://reviews.freebsd.org/D59415
2026-09-10 22:15:27 -06:00
Warner Losh 68a4a53e82 loader.kboot.8: Use right headers
Uggg, copied this instead of using the new style.

Sponsored by:		Netflix
2026-09-01 10:26:26 -06:00
Warner Losh a0d5b130ef loader.kboot: Add man page
Sponsored by:		Netflix
2026-09-01 09:58:07 -06:00
Warner Losh ba9aaed01a Revert "ciss: Add max physical target"
This reverts commit 45645518ea.

Although this changed looks like it should just be a harmless change to
bookkeeping, it turns out that it changes the termination condition of
the initial device scan, resulting in it never finishing. This causes
the boot to hang forever coming up. Since I don't have good access to
hardware, I'm reverting until the exact details can be sorted out.

Reported by: Edward Scroop
Sponsored by: Netflix
MFC After: 1 week
2026-08-17 07:11:52 -06:00
Warner Losh 6671bbf2f9 nda: Tag the command set used for devctl errors
Different command sets have different encoding for op codes, etc. While
one can normally puzzle out which is which, it's better to explicitly
tag the command set used.

Sponsored by:		Netflix
2026-07-20 06:37:10 -06:00
Warner Losh 878bf20fa5 Ignore the white-space-only change for decompress.c
Sponsored by:		Netflix
2026-07-13 14:25:00 -06:00
Warner Losh e49fc64b9b loader: Fix indentation mistakes
Somehow, I wound up with space indents rather than tab indents, so fix
this.

Sponsored by:		Netflix
2026-07-13 14:23:31 -06:00
Warner Losh df9d6403ca loader: Add forgotten xz.c and zstdfs.c
These were overlooked when I added compression support.

Fixes: 86d719ae68 ("loader: Add xzfs, like gzipfs but with xz.")
Fixes: c61ee49cd0 ("loader: zstd based filesystem, zstdfs like gzipfs")
Sponsored by:		Netflix
2026-07-11 21:53:29 -06:00
Warner Losh 541e6e2d51 bsd.dirs.mk: Fix MK_INSTALL_AS_USER for directories
Sponsored by:		Netflix
2026-07-11 13:52:17 -06:00
Warner Losh a7ebe2d436 boot-test.sh: Test many boot loader combinations.
This is a script that eventually will test boot with qemu all the
supproted combinations for the boot loader. There's several things that
could be done with gptboot or boot0sio (or not) that aren't tested. We
don't test the 10-odd hardware root devices we support, nor do we test
complex scenarios like RELAXED vs STRICT zfs efi booting.

However, the scenarios we do support are included here. We test aarch64,
amd64, armv7, powerpc64, powerpc64le, and riscv64 for BIOS, UEFI, and
Prep and OpenFirmware (as appropriate) crossed with CDROM, MBR and GPT
(and some hybrid) crossed with lua, 4th and simple loaders. Plus some
linuxboot and memdisk scenarios, including the recently added
compression for ram disk scenarios:

=== Results: 67 passed, 3 failed, 9 timed out (of 79) ===

The timeouts are well understood, usually failure to find the root
disk. The failures are bad console assumptions. netboot-bios fails
because TFTP with a single packet buffer in qemu gives horrible
throughput, so the test takes 18-20 minutes. Now that I have a
dashboard, I can fix the rest one by one.

There's also a powerpc architecture that you can request specifically,
but it's just for convenience and tests with the non-functional mac99
qemu machine. I will eventually eliminate this architecture. I added it
to make sure the FreeBSD version wasn't too hard coded since this
framework pulls from CD images to get the binaries for the minimal root
used in testing and there's no 15.x 32-bit powerpc images.

We need to add http and nfs root booting tests, but that's for the
future. Plus there's some other functional tests that we should also add
for different types of root (usb, sata, sas, nvme, ufs, emmc, sd, etc)
that would be useful to test, especailly the non-sata/non-nvme ones.
How we do that is still TBD.

I leaned on claude to iterate over the recipes that I've developed over
the years, collected off the internet or got on IRC recently to produce
this framework. Most of this code is fairly good, while a few parts,
especailly some of the comments, are detectable as AI produced. My plans
are to iteratively improve those.  Since this is just a test, and since
I've broken many scenarios w/o realizing, it's a good tradeoff. I've not
made it an ATF test since we test all the architectures, but I'm open to
feedback in this area.

Total time to test all the architectures is about 10 minutes. It assumes
you've built GENERIC* and the boot loader for all the architectures too.
In the future, I plan on moving to MINIMAL for all the boot testing, but
likely only after PCI devmatch is integrated into it. That would be
incrementally faster test times.

The man page is decent, but was also generated by Claude with only
trivial edits by me to date.... But at least there's a man page for it,
though neither it nor the script is installed onto the system.

Sponsored by: Netflix
Assisted-by: Claude Code (Opus 4.6, Opus 4.8(1M) and Sonet 5.0)
Differential Revision:	https://reviews.freebsd.org/D58008
2026-07-11 13:45:37 -06:00
Warner Losh 7db502d50c loader: Add xzfs support by defualt to BIOS and EFI loaders
For the BIOS, add xzfs support. This is a tiny increase in the loader
size, but allows us to fetch compressed files from any of the
filesystems we support, including over the network.

For EFI, also add gzipfs and bzip2fs support we well. The increment for
these files is tiny.

Sponsored by:		Netflix
2026-07-11 13:28:47 -06:00
Warner Losh c61ee49cd0 loader: zstd based filesystem, zstdfs like gzipfs
Off by default.

Sponsored by:		Netflix
2026-07-11 13:28:47 -06:00
Warner Losh 86d719ae68 loader: Add xzfs, like gzipfs but with xz.
This is just like gzipfs or bzipfs, except done with the newer xz
program. This is off by default for the moment.

Sponsored by:		Netflix
2026-07-11 13:28:47 -06:00
Warner Losh dc6c193bb4 loader.efi: Add xz decompression
We can now decompress .xz compressed memory disks, like
FreeBSD-15.1-RELEASE-amd64-disc1.iso.xz

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D58073
2026-07-11 13:28:47 -06:00
Warner Losh 584ecfeb9c XZ kernel build cleanup
-I${SRCTOP}/sys/contrib/xz-embedded/linux/lib/xz isn't used, and
.PATH: ${SRCTOP}/sys/contrib/xz-embedded/freebsd isn't used either.
Remove them both to simplify things a little.

Sponsored by:		Netflix
2026-07-09 22:14:51 -06:00
Warner Losh 45f9f6ebac kldxref: Add -m filag to print info about modules in one file
kldxref -m <file> will print the same data that the '-d' flag produces,
except restrict the output to one file. This should be the full path to
the file, and the directory name to process is omitted.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D57902
2026-07-09 22:14:51 -06:00
Warner Losh bcb1b157fd loader: Add two new build knobs for x86 BIOS loaders
We have two sets of BIOS loaders: One that lives in stand/i386 and one
that lives in stand/userboot. Add knows to turn these on/off, with the
default being on. These often aren't needed when creating a minimal UEFI
system, so add knobs to turn them off.  Given light-weight VMs have
created a new use cases for these loaders, there's no plans at all to
eliminate them.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D58072
2026-07-09 22:13:07 -06:00
Warner Losh c8842f1d18 Revert "loader.efi: Trim ZFS searching for other booting options"
This reverts commit 3e3fd1fde8.

This appears to break chainbooting with boot1.efi and similar scenarios
with Root-on-ZFS scenarios. Revert until it's better understood.

PR: 296309
Sponsored by: Netflix
Differential Revision:	https://reviews.freebsd.org/D58071
2026-07-09 22:09:41 -06:00
Warner Losh 1d1298269d loader.efi: Simplify the code for null decompression a little
This code is simpler when we spell it the Unix way. Also, add sanity
checks to make sure the offset is where we think it is.

Fixes: afee781523 ("loader.efi: Recognize new memdisk=<url> and memcd=<url> options")
Sponsored by: Netflix
Differential Revision:	https://reviews.freebsd.org/D58070
2026-07-09 22:09:41 -06:00
Warner Losh 603270b4d6 loader.efi: Fix off by one error in size of the virtual disk
The end address is the final byte in the array, not one byte past the
end of the array, so we need to add 1 to get the full length.

Fixes: 59219fc76a ("loader.efi: efiblk_memdisk_preload passes the VirtualDisks to FreeBSD")
Sponsored by: Netflix
Differential Revision:	https://reviews.freebsd.org/D58069
2026-07-09 22:09:41 -06:00
Warner Losh a22fa5ec74 laoder.efi: Fix error in download protcol
The download protocol calls download_data with FileOffset and
BufferLength of 0 first to start the download (no data yet
available). Calls it again with BufferLength == 0 and FileOffset the
size of the download (again, no data). It then starts calling with
BufferLength != 0 and FileOffset == 0 to start the download. The
heuristic I used to detect the start was wrong, so we'd allocate the
buffer twice. Fix that by being more explicit and not using the
heuristic that was bogus.

Fixes: afee781523 ("loader.efi: Recognize new memdisk=<url> and memcd=<url> options")
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D58068
2026-07-09 22:09:41 -06:00
Warner Losh f273414c11 MINIMAL: Add device md
This can't be a loadable module, so add it to MINIMAL

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D58067
2026-07-09 22:09:40 -06:00
Warner Losh 1fc6923e6a loader: Test GCC cross builds as part of universe.sh
Sicne we have gcc15 in Jenkins, and since people are actually using it,
add cross building tests to universe.sh to avoid build breakage when
hacking on loader.efi (and others). UEFI makes it too easy to mix
pointers and integers since it deals in an odd mix of
EFI_PHYSICAL_ADDRESS and pointers...

Sponsored by:		Netflix
2026-06-26 17:12:55 -06:00
Warner Losh 9cb1459633 loader.efi: Fix build with gcc due to pointer / int issues on 32-bit build
Use (uintptr_t) casts to cast the EFI_PHYSICAL_ADDDRESS to a pointer.

Fixes: afee781523 ("loader.efi: Recognize new memdisk=<url> and memcd=<url> options")
Sponsored by:		Netflix
Reviewed by:	rlibby
Differential Revision:	https://reviews.freebsd.org/D57893
2026-06-26 17:12:48 -06:00
Warner Losh 4e9d303c83 pxeldr: Bump the limit by 30k for loader size
We have a ltitle wiggle room, so go ahead and bump the pxeldr size.
It should be a little larger than the limit we have for the /boot/loader
since we embed that in this loader...

Sponsored by:		Netflix
2026-06-26 08:54:37 -06:00
Warner Losh afee781523 loader.efi: Recognize new memdisk=<url> and memcd=<url> options
Support ipxe downloading of a memory disk (either presented to the OS as
a harddisk or a cd). This requires an ipxe server since it uses the ipxe
download protocol to grab the disk. If there is a disk, we add it to the
environment as a disk, and then the rest of the bootloader just sees it
and boots from it.

I've cribbed code from https://github.com/russor/memdisk_uefi and
adapted it to work in the context of the FreeBSD bootloader.

The ipxe_download.h file was created from the documentation of the
interface.

So a .ipxe file with the line
chain http://10.2.0.1/loader.efi memdisk=${cwduri}FreeBSD-15.1-RELEASE-amd64-bootonly.iso
would use the FreeBSD boot loader to boot the FreeBSD 15.1 release.

md(9) has a bug at the moment that prevents it from probing the
partitions on it.

Also, we'll automatically decompress gzip, bzip2 and zstd files
automatically.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D57677
2026-06-26 08:54:37 -06:00
Warner Losh 59219fc76a loader.efi: efiblk_memdisk_preload passes the VirtualDisks to FreeBSD
Set hint.md.%d.physaddr and hint.md.%d.len for each of the VirtualDisks.
The memory for these remains after we exit boot services so FreeBSD can
use them. This leverages the BIOS work we did for memdisks. In
hindsight, I should have passed this in via metadata, but it's been in a
release.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D57806
2026-06-26 08:54:36 -06:00
Warner Losh 3e3fd1fde8 loader.efi: Trim ZFS searching for other booting options
When we're searching the system for all the disks in relaxed mode, we
need to do a final pass over all the non-boot disks. We no longer need
to have two loops since ZFS on boot device is selected properly in
try_boot_device_partitions. This also simplifies the code a bit.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D57805
2026-06-26 08:54:36 -06:00
Warner Losh 7f5475594a loader.efi: Improve the trying MD messsages
Expand the tring MD message a little to make it clearer.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D57804
2026-06-26 08:54:36 -06:00
Warner Losh 82eb197075 loader.efi: Expand uefi_rootdev to probe disks
uefi_rootdev had to be the exact device to work. This is often difficult
to arrange and awkward. Instead, have it search the specified device: As
a partition if it specifies the partition, and as the whole disk if the
specified partition didn't work or it specifies a disk. This brings it
into lone what we do with other devices. This overrides the boot manager
search we do before we do this for the boot device, but this knob has
always been meant to overload the boot manager search.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D57803
2026-06-26 08:54:36 -06:00