History log of /freebsd-current/usr.sbin/efibootmgr/efibootmgr.c
Revision Date Author Comments
# 65904399 24-Mar-2024 Mark Peek <mp@FreeBSD.org>

efibootmgr: allow -u as a valid option

PR: 277907
Reported by: vsasjason@gmail.com
MFC after: 1 week


# 09cb8031 22-Feb-2024 Jessica Clarke <jrtc27@FreeBSD.org>

efibootmgr: Simplify make_next_boot_var_name and fix cnt == 0 case

If cnt == 0 we access element 0 unconditionally, which is out of bounds,
and then if that doesn't crash and happens to be 0 we will access
element - 1, also out of bounds, and then if that doesn't crash will add
1 to whatever junk is there and use that for the variable. On CHERI,
though, this does crash. This code is also overly complicated, with
unnecessary special cases and tracking more state than needed.

Rewrite it in a more general manner that doesn't need those special
cases and naturally works for cnt == 0.

Found by: CHERI
Reviewed by: imp
Fixes: 1285bcc833a3 ("Import Netflix's efibootmgr to help manage UEFI boot variables")
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D44029


# bf87d4a4 25-Oct-2022 Andriy Gapon <avg@FreeBSD.org>

efibootmgr: fix potential endless loop with -v

I observed the problem on a system with fairly old and, apparently,
buggy EFI implementation. A list of boot devices had an invalid
trailing entry. efidp_size() for that entry returned zero, which means
that the code got stuck looping on that entry.


# e02bee0b 18-Dec-2023 Warner Losh <imp@FreeBSD.org>

efibootmgr: Report the path to the device

Report the entire path to the device, rather than the the bit after /dev/
for the --esp command. Nothing in the tree depends on the output
format: Only bsdinstall's bootconfig script calls efibootmgr, and it
doesn't use the --esp/-E flag.

Sponsored by: Netflix


# 731f91c0 17-May-2022 Warner Losh <imp@FreeBSD.org>

efibootmgr: -C isn't implemented

-C isn't implemented, so just errx out until it is. It's not listed in
the man page, but is parsed for compatibility with the Linux
efibootmgr(8) command.

Sponsored by: Netflix


# 98d2608a 17-May-2022 Warner Losh <imp@FreeBSD.org>

efibootmgr: support '-b bootXXXX' as an alias for '-b XXXX'

Sponsored by: Netflix


# c08ba4a5 15-Oct-2023 Ed Maste <emaste@FreeBSD.org>

efibootmgr: provide explicit error message if run as non-root

This should be less confusing for new users.

Reviewed by: imp
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D42213


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 4ef1c6f7 26-Jul-2023 Marius Strobl <marius@FreeBSD.org>

base: Remove support for the VTOC8 partitioning scheme

The removal of the sparc64 support in February 2020 obsoleted the
VTOC8 partitioning scheme as no other FreeBSD platform makes use
of it. Moreover, the code is bitrotting as nothing defines e. g.
LOADER_VTOC8_SUPPORT any more and, thus, should go now, too. With
this change, the following commits are reverted as far as VTOC8
is concerned and parts haven't already previously been deleted
along with prior sparc64 removals:
094fcb157d4c98211899cf09d06e2cf19149b7e0
a7d366e9589c95feda6f3bc78c59c6355d51f126
ba8d50d08b9df4e8213f9a6997ff6792ecebcd9b

The alignment example d9711c28efc4ec89ba5ea11f8fd63e9d0a7fc81b
added to the VTOC8 section of gpart.8 is folded into the MBR one.

This should finally conclude the deorbit of sparc64-specific bits.

We had joy, we had fun
we ran Unix on a Sun.
But that source and the song
of FreeBSD have all gone.

Credits to Michael Bueker for the original "Unix on a Sun" and Rod
McKuen for the "Seasons in the Sun" lyrics.


# 17a5a290 23-Feb-2023 Ed Maste <emaste@FreeBSD.org>

efibootmgr: add missing break for 'u' case

Reviewed by: imp, zlei
Reported by: Coverity
CID: 1505695
Fixes: 9a7915299484 ("efibootmgr: Add --efidev (-u) to dis...")
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D38747


# 9a791529 16-Feb-2023 Warner Losh <imp@FreeBSD.org>

efibootmgr: Add --efidev (-u) to discover UEFI's device path to a dev or file

"efibootmgr --efidev unix-path" will return the UEFI device-path to the
file or device specified by unix-path. It's useful for debugging, but
may also be useful for scripting.

Sponsored by: Netflix
Reviewed by: corvink, manu
Differential Revision: https://reviews.freebsd.org/D38617


# 7fe2f504 11-Feb-2021 Warner Losh <imp@FreeBSD.org>

efibootmgr: Check for efi supported after parsing args

Move the check for efi variables being supported to after parsing the args. This
allows '-h' to produce both as a normal user as well as on all systems.


# 2e085395 30-Nov-2020 Mitchell Horne <mhorne@FreeBSD.org>

efibootmgr: fix an incorrect error handling check

efivar_device_path_to_unix_path() returns standard error codes on
failure and zero on success. Checking for a return value less than zero
means that the actual failure cases won't be handled. This could
manifest as a segfault during the subsequent call to printf().

Reviewed by: imp
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D27424


# b8adbe1c 19-Oct-2020 Ryan Moeller <freqlabs@FreeBSD.org>

efibootmgr: Use returned error code for error message, not errno

efivar_unix_path_to_device_path returns the error code, it does not set errno.

Reviewed by: imp
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D26852


# b9580775 26-Aug-2020 Toomas Soome <tsoome@FreeBSD.org>

efibootmgr: wrong check for opts.order

opts.order && !(opts.order) does not really make sense.

Reported by: swildner


# 83c42372 25-Aug-2020 D Scott Phillips <scottph@FreeBSD.org>

efibootmgr: Add option to request booting to the firmware user interface

The OsIndications UEFI variable can request the firware to stop at
its UI instead of continuing with boot. Add flags for setting and
clearing this request.

Reviewed by: manu, bcr (manpages)
Approved by: scottl (implicit)
MFC after: 1 week
Sponsored by: Ampere Computing, Inc.
Differential Revision: https://reviews.freebsd.org/D25839


# 6b8b1bfe 16-Jul-2020 Toomas Soome <tsoome@FreeBSD.org>

efibootmgr: typo in long option name

del-timout should be del-timeout

Reported by: mjg
MFC after: 1 week


# 1cdb8eb8 20-Nov-2019 Warner Losh <imp@FreeBSD.org>

Add --esp/-E argument to print the currently booted ESP

Add code to decode the BootCurrent and BootXXXX variable it points at
to deduce the ESP used to boot the system. By default, it prints the
path to that device. With --unix-path (-p) it will instead print the
current mount point for the ESP, if any (or an error). With
--device-path (-d) it wil print the UEFI device path for the ESP.

Note: This is the best guess based on the UEFI variables. If the ESP
is part of a gmirror, etc, that won't be reported. If by some weird
chance there was a complicated series of chain boots, this may not be
what you want. For setups that don't add layers on top of the raw
devices, it is accurate.

Differential Revision: https://reviews.freebsd.org/D22432


# 67a5e533 10-May-2019 Emmanuel Vadot <manu@FreeBSD.org>

efibootmgr: Do not add the new boot entry in dry-run is specified

While here fix a typo.

Sponsored-by: Ampere Computing, LLC
Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D20212


# 52467047 04-Feb-2019 Warner Losh <imp@FreeBSD.org>

Regularize the Netflix copyright

Use recent best practices for Copyright form at the top of
the license:
1. Remove all the All Rights Reserved clauses on our stuff. Where we
piggybacked others, use a separate line to make things clear.
2. Use "Netflix, Inc." everywhere.
3. Use a single line for the copyright for grep friendliness.
4. Use date ranges in all places for our stuff.

Approved by: Netflix Legal (who gave me the form), adrian@ (pmc files)


# 9ed08029 30-Dec-2018 Rebecca Cran <bcran@FreeBSD.org>

Change the way efibootmgr works by specifying bootnum via -b parameter

Instead of passing the bootnum to each different parameter, require users
to specify -b when running operations that need a bootnum.

This allows activation of a new boot entry at the same time it's created
by adding -a onto the command line.

Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D18648


# a2581e80 24-Dec-2018 Rebecca Cran <bcran@FreeBSD.org>

Activate support for efibootmgr(8) -b --bootnum parameter

Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D18647


# de6b4aa8 02-Sep-2018 Warner Losh <imp@FreeBSD.org>

Make -a (to make the entry active) apply to creation of a new boot
variable.

Approved by: re@ (rgrimes)
PR: 231013
Differential Revision: https://reviews.freebsd.org/D16977


# de26ba4d 27-Jul-2018 Warner Losh <imp@FreeBSD.org>

Add -b bootnum to allow creation of a specific boot number (rather
than the auotmatic selection). This is important in some scripting
environments.

Also, remove bogus checks for bootnum != 0. 0 is a valid bootnum.

Sponsored by: Netflix


# 83caf7e5 08-May-2018 Warner Losh <imp@FreeBSD.org>

Remove ignored command line options

The --device and --part command line options were planned for Linux
compatibility mode. However, that mode will never happen, so remove
them as last vestiges of a false start.

Submitted by: Vlad Movchan


# 51922c69 08-May-2018 Warner Losh <imp@FreeBSD.org>

Improve printing the boot variables.

Print the boot variables in the order in the BootOrder variable, if it
exists, and then in verbose mode print any unreferneced BootXXXX
variables. If BootOrder isn't set, fall back to printing all the
variables.

Sponsored by: Netflix


# 12f409ff 08-May-2018 Warner Losh <imp@FreeBSD.org>

Inline print_order(). It's used one palce.


# 3fcd5d6e 16-Mar-2018 Warner Losh <imp@FreeBSD.org>

Make not getting BootOrder a warning, not a fatal error when printing.

Sponsored by: Netflix


# 018caaae 12-Jan-2018 Warner Losh <imp@FreeBSD.org>

Fix error in determining the next available boot slot.

Sponsored by: Netflix


# cac7bbe1 05-Jan-2018 Warner Losh <imp@FreeBSD.org>

There's no need / benefit from deleting the variable before we set it.

Sponsored by: Netflix


# af9d0c27 05-Jan-2018 Warner Losh <imp@FreeBSD.org>

Fix usage strings. -d and -p were removed before this was committed to
FreeBSD, but the strings weren't updated.

Sponsored by: Netflix


# 63b56694 05-Jan-2018 Warner Losh <imp@FreeBSD.org>

Free options before setting them. This will prevent us from leaking
memory when we have multiple copies of the same option from being
specified.

Sponsored by: Netflix


# da15338d 05-Jan-2018 Warner Losh <imp@FreeBSD.org>

Ensure that we have a description string. When unspecified, default to "".

Sponsored by: Netflix


# 96289d09 24-Dec-2017 Alexander Kabaev <kan@FreeBSD.org>

Remove write-only opt and useless optlen variables.

This squashes the warning gebnerated by GCC 6.x. Since
variables that are now removed had come documentation
value, put relevant bits in comment, so they can be
resurrected from there when actually needed.


# 155b183a 12-Dec-2017 Warner Losh <imp@FreeBSD.org>

Actually insert the free(d) call missed in r326802.

Noticed by: rpokala@


# af934ea3 12-Dec-2017 Warner Losh <imp@FreeBSD.org>

Add sanity testing against maximum sane lengths for device paths for
loader and kernel.

CID: 1383608
Sponsored by: Netflix


# a6b6f888 12-Dec-2017 Warner Losh <imp@FreeBSD.org>

Free load_opt_buf after we're done with it.

CID: 1383607
Sponsored by: Netflix


# 8354d13d 12-Dec-2017 Warner Losh <imp@FreeBSD.org>

Fix resource leak. Free converted description after printing it.
Also minor style sort of local vars.

CID: 1383606
Sponsored by: Netflix


# 3af42ca7 12-Dec-2017 Warner Losh <imp@FreeBSD.org>

Don't leak new_data.

CID: 1383605
Sponsored by: Netflix


# c66805a5 12-Dec-2017 Warner Losh <imp@FreeBSD.org>

Check return value for set_bootvar and give a good error message.

CID: 1383601
Sponsored by: Netflix


# 6604afe9 11-Dec-2017 Warner Losh <imp@FreeBSD.org>

Unbreak gcc build by using (void) for functions that take no args.

Sponsored by: Netflix


# a2aa6671 09-Dec-2017 Warner Losh <imp@FreeBSD.org>

Indent multiple device path entries correctly.

Sponsored by: Netflix


# 1127aea3 09-Dec-2017 Warner Losh <imp@FreeBSD.org>

Remove vestiges of -d and -p commands.
Fix two core dumps when optional data isn't specified.

Sponsored by: Netflix


# a3e6c4a6 08-Dec-2017 Warner Losh <imp@FreeBSD.org>

Forgotten in 326725

Release Notes: Yes


# 1285bcc8 08-Dec-2017 Warner Losh <imp@FreeBSD.org>

Import Netflix's efibootmgr to help manage UEFI boot variables

efibootmgr manages the UEFI BootXXXX variables that implement the UEFI
Boot Manager protocol defined in the UEFI standards. It is modeled
after the Linux program of the same name with a mostly compatible set
of command line options. Since there's a fair amount of OS specifioc
code due to differeing names and methods of doing things, the
compatibility isn't 100%.

Basic functionality is implemented, though the more advanced next boot
functionality that's been defined elsewhere is unimplemented.

Submitted by: Matt Williams (with unix / efi path xlate by me)
Sponsored by: Netflix