Commit Graph

55 Commits

Author SHA1 Message Date
Mark Peek
65904399db efibootmgr: allow -u as a valid option
PR:		277907
Reported by:	vsasjason@gmail.com
MFC after:	1 week
2024-03-24 12:37:12 -07:00
Jessica Clarke
09cb8031b4 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:		1285bcc833 ("Import Netflix's efibootmgr to help manage UEFI boot variables")
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D44029
2024-02-23 02:36:21 +00:00
Andriy Gapon
bf87d4a4bf 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.
2024-01-28 15:20:29 +02:00
Warner Losh
e02bee0b3e 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
2023-12-18 10:09:13 -07:00
Warner Losh
6aa1b4332f efibootmgr: Document -e command line switch
-e env will include `env` in the boot loader. Document that the boot
loader appends the `env` to the BootXXXX variable, and will parse it as
a series of a=b values to set in the boot loader's environment.  These
assignments are separated by spaces. The env arg needs to be quoted if
more than one env var is to be set (we parse only the next argument on
the command line).

Sponsored by:		Netflix
2023-12-18 10:01:38 -07:00
Warner Losh
731f91c077 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
2023-10-26 22:01:16 -06:00
Warner Losh
98d2608a2a efibootmgr: support '-b bootXXXX' as an alias for '-b XXXX'
Sponsored by:		Netflix
2023-10-26 22:01:16 -06:00
Ed Maste
c08ba4a588 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
2023-10-15 14:31:51 -04:00
Warner Losh
fa9896e082 Remove $FreeBSD$: two-line nroff pattern
Remove /^\.\\"\n\.\\"\s*\$FreeBSD\$$\n/
2023-08-16 11:55:10 -06:00
Warner Losh
d0b2dbfa0e Remove $FreeBSD$: one-line sh pattern
Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
2023-08-16 11:55:03 -06:00
Warner Losh
1d386b48a5 Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:42 -06:00
Marius Strobl
4ef1c6f75d 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:
094fcb157d
a7d366e958
ba8d50d08b

The alignment example d9711c28ef
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.
2023-07-26 13:16:12 +02:00
Ed Maste
17a5a29003 efibootmgr: add missing break for 'u' case
Reviewed by:	imp, zlei
Reported by:	Coverity
CID:		1505695
Fixes:		9a79152994 ("efibootmgr: Add --efidev (-u) to dis...")
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D38747
2023-02-23 14:13:18 -05:00
Warner Losh
9a79152994 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
2023-02-16 08:54:39 -07:00
Mateusz Piotrowski
5fce57dd12 efibootmgr: Use the hier(7) ESP mount point in examples
MFC after:	1 week
2022-04-03 14:52:07 +02:00
Emmanuel Vadot
d8d41d3b84 pkgbase: Remove libefivar package and add a efi-tools one
Put all the efi related tools into FreeBSD-efi-tools.

Differential Revision:	https://reviews.freebsd.org/D31803
2021-09-07 10:24:21 +02:00
Warner Losh
7fe2f504f8 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.
2021-02-11 16:09:51 -07:00
Mitchell Horne
2e085395e1 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
2020-11-30 22:16:11 +00:00
Ryan Moeller
b8adbe1c15 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
2020-10-19 10:38:40 +00:00
Toomas Soome
b95807751a efibootmgr: wrong check for opts.order
opts.order && !(opts.order) does not really make sense.

Reported by:	swildner
2020-08-26 14:02:38 +00:00
D Scott Phillips
83c4237258 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
2020-08-26 02:05:58 +00:00
John-Mark Gurney
98b765e5c2 update example to make it active when creating a new boot method...
Clean up some of the sentences and grammar...

make igor happy..
2020-07-23 22:28:35 +00:00
Toomas Soome
6b8b1bfef0 efibootmgr: typo in long option name
del-timout should be del-timeout

Reported by:	mjg
MFC after:	1 week
2020-07-16 10:20:35 +00:00
Warner Losh
1cdb8eb8fe 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
2019-11-20 23:58:36 +00:00
Yuri Pankov
736dcdb75a efibootmgr(8): fix markup and style issues
- split synopsis into separate options that can't be used together
- sort options
- fix (style) issues reported by mandoc lint

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D21710
2019-09-25 21:23:30 +00:00
Emmanuel Vadot
67a5e53398 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
2019-05-10 16:44:35 +00:00
Warner Losh
52467047aa 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)
2019-02-04 21:28:25 +00:00
Rebecca Cran
70de14d82f Update the efibootmgr(8) man page to document changes to options. 2019-01-01 04:57:46 +00:00
Rebecca Cran
9ed0802914 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
2018-12-31 00:09:45 +00:00
Rebecca Cran
557a5ad425 Improve the efibootmgr(8) man page
Fix formatting, typos, and attempt to improve the wording.

Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D18646
2018-12-28 21:26:45 +00:00
Rebecca Cran
a2581e8021 Activate support for efibootmgr(8) -b --bootnum parameter
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D18647
2018-12-24 15:38:36 +00:00
Warner Losh
de6b4aa8c4 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
2018-09-02 18:40:18 +00:00
Warner Losh
de26ba4d82 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
2018-07-27 18:18:20 +00:00
Warner Losh
83caf7e590 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
2018-05-08 20:02:44 +00:00
Warner Losh
39c0a13bc7 efibootmgr.8: fix example
The example given was for the old, and now deleted, Linux
compatibility mode. Update the example for the current code.

Submitted by: Vlad Movchan
2018-05-08 20:02:39 +00:00
Warner Losh
51922c697b 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
2018-05-08 19:43:57 +00:00
Warner Losh
12f409ff75 Inline print_order(). It's used one palce. 2018-05-08 18:25:37 +00:00
Warner Losh
3fcd5d6e92 Make not getting BootOrder a warning, not a fatal error when printing.
Sponsored by: Netflix
2018-03-16 18:16:31 +00:00
Warner Losh
018caaaed0 Fix error in determining the next available boot slot.
Sponsored by: Netflix
2018-01-12 15:30:48 +00:00
Warner Losh
cac7bbe16a There's no need / benefit from deleting the variable before we set it.
Sponsored by: Netflix
2018-01-06 06:00:40 +00:00
Warner Losh
af9d0c273f Fix usage strings. -d and -p were removed before this was committed to
FreeBSD, but the strings weren't updated.

Sponsored by: Netflix
2018-01-06 06:00:34 +00:00
Warner Losh
63b5669494 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
2018-01-05 07:09:19 +00:00
Warner Losh
da15338df8 Ensure that we have a description string. When unspecified, default to "".
Sponsored by: Netflix
2018-01-05 07:09:09 +00:00
Alexander Kabaev
96289d0961 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.
2017-12-24 16:39:57 +00:00
Warner Losh
155b183ad2 Actually insert the free(d) call missed in r326802.
Noticed by: rpokala@
2017-12-12 19:45:24 +00:00
Warner Losh
af934ea3ba Add sanity testing against maximum sane lengths for device paths for
loader and kernel.

CID: 1383608
Sponsored by: Netflix
2017-12-12 19:26:24 +00:00
Warner Losh
a6b6f888b5 Free load_opt_buf after we're done with it.
CID: 1383607
Sponsored by: Netflix
2017-12-12 19:26:19 +00:00
Warner Losh
8354d13d9b Fix resource leak. Free converted description after printing it.
Also minor style sort of local vars.

CID: 1383606
Sponsored by: Netflix
2017-12-12 19:26:15 +00:00
Warner Losh
3af42ca7c1 Don't leak new_data.
CID: 1383605
Sponsored by: Netflix
2017-12-12 19:26:10 +00:00
Warner Losh
c66805a5d5 Check return value for set_bootvar and give a good error message.
CID: 1383601
Sponsored by: Netflix
2017-12-12 19:25:54 +00:00