Page MenuHomeFreeBSD

Finalize the boot manager protocol support for next-stage boot loading.
ClosedPublic

Authored by imp on Jul 23 2018, 6:35 AM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Nov 22, 10:42 PM
Unknown Object (File)
Nov 4 2024, 4:56 PM
Unknown Object (File)
Oct 20 2024, 6:26 AM
Unknown Object (File)
Oct 19 2024, 9:22 AM
Unknown Object (File)
Oct 4 2024, 7:22 PM
Unknown Object (File)
Oct 3 2024, 2:15 PM
Unknown Object (File)
Oct 3 2024, 1:15 PM
Unknown Object (File)
Oct 3 2024, 10:15 AM
Subscribers
None

Details

Summary

Implement efi_devpath_to_media_path

Takes a generic device path as its input. Scans through it to find the
first media_path node in it and returns a pointer to it. If none is
found, NULL is returned.

Store the number of handles we get back in efipart_nhandles rather than the number of bytes. Don't divide by the element size every time we have to iterate. Eliminate now-unused variables.

Implement efi_devpath_match_node

Returns true if the first node pointed to by devpath1 is identical to
the first node pointed to by devpath2, with care taken to not read
past the end of the valid parts of either devpath1 or
devpath2. Otherwise, returns false.

Implement efi_devpath_length

Return the total length, in bytes, of the device path (including the
terminating node at the end).

Implement efiblk_get_pdinfo_by_device_path

Lookup a block device by it's device path. We use a 'loose' lookup
whereby we scan forward to the first Media Path portion of the device
path, then look at all our handles for one whose first Media Path
matches. This will also work if the device path pointed to has a
following file path (or paths) as that's ignored. It assumes that
there's only one media path node that describes the entire device,
which is true as of the latest UEFI spec (2.7 Errata A) as far as I've
been able to determine.

Finalize the boot manager protocol support for next-stage boot loading.

If we are booting in a conforming UEFI Boot Manager Environment, then
use the BootCurrent variable to find the BootXXXX we're using. Once we
find that, then if it contains more than one EFI_DEVICE_PATH in its
what to boot section, try to use the last one as the kernel to
load. This will also set the default root partition as well. If
there's only one path, or if there's an error along the way, assume
that nothing specific was specified and revert to the old
algorithm. If something was specified, but not found, then fail the
boot. Otherwise you that, specific thing. On FreeBSD, this can be set
using efibootmgr -l <loader> -k <kernel>. We try a few variations of
kernel to cope with the fact that UEFI comes from a DOS world where
paths might be upper case and/or contain back-slashes.

Note: In an ideal world, we'd work out where we are in chain loading
by looking at the passed-in image handle and doing name
matching. However, that's unreliable since at least boot1.efi booted
images don't have that, hence the assumption that loader.efi needs to
load the last thing on the list, if possible.

The reason we fail for something specific is so that we can fully
participate in the UEFI Boot Manager Protocol and fail over to the
next item in the list of BootOrder choices when something goes wrong
at this stage.

This implements was was talked about in freebsd-arch@ last year
https://docs.freebsd.org/cgi/getmsg.cgi?fetch=3576+0+archive/2017/freebsd-arch/20171022.freebsd-arch
and documented in full (after changed resulting from the discussion) in
https://docs.google.com/document/d/1aK9IqF-60JPEbUeSAUAkYjF2W_8EnmczFs6RqCT90Jg/edit#
although one or two minor details may have been modified in this
implementation to make it work, and the ZFS MEDIA PATH extension isn't
implemented. This does not yet move things to ESP:\efi\freebsd\loader.efi.

RelNotes: Yes
Sponsored by: Netflix

Diff Detail

Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 18276
Build 18001: arc lint + arc unit

Event Timeline

stand/efi/loader/main.c
4

Note: Over the past year, I've written or re-written at least 1/3 of this file.

This revision is now accepted and ready to land.Jul 23 2018, 8:31 PM
This revision was automatically updated to reflect the committed changes.
UPDATING
35–36

can you say a little about what is new - what will a user notice / have to do differently / can do now that they couldn't before?

imp marked an inline comment as done.Jul 23 2018, 10:16 PM
imp added inline comments.
UPDATING
35–36

Done, in -current.