HomeFreeBSD

MFC efivar changes: r321429, r323056-r323057, r323066, r323259-r323260,

Description

MFC efivar changes: r321429, r323056-r323057, r323066, r323259-r323260,
r323519, r325684, r326050-r326051, r326231, r326287, r326457-r326459,
r326472, r326658, r326805, r327574-r327575, r330279

r321429:
fix typo

r323056:
Fix printing File() nodes in device paths.

Device paths encoded into the FILEPATH_DEVICE_PATH are UCS2 not
ASCII/UTF8. Convert to utf8 and print that when printing File
paths. Also, since File may be at the end of a long device path,
output File() around the path so it doesn't just show up as random
nodes that might accidentally match real node paths names and cause
errors.

r323057:
Fix parsing File() nodes in device paths.

o Add File to the mUefiDevicePathLibDevPathFromTextTable table so we

don't include 'File()' in the supposed path name. This happens because
of a possible misfeature in the EDK2 code where any path that's not
recognized is treated as a File() node.

o Convert utf8 input into ucs2 output rather than just copying the

utf8 and hoping for the best (no good comes from that).

o Remove bogus comment about needing to add 1. The dummy array already

is length 1, so that's included in sizeof the struct, so there's no
need to add it.

Sponsored by: Netflix

r323066:
Add UCS2->UTF8 option.

Many UEFI variables are UCS2 strings (some NUL terminated, others
not). Add --utf8 (-u) to convert UCS2 strings to UTF8 before printing.

Sponsored by: Netflix

r323259:
Implement efidp_size

efidp_size will return the size, in bytes, of a EFI device path
structure. This is a convenience wrapper in the same style as the
other linux routines. It's implemented by GetDevicePathSize from EDK2
we already needed for other things.

Sponsored by: Netflix

r323260:
Create efi utility printing routines

Split out asciidump, utf8dump, bindump, and hexdump into a separate
file efiutil.c. Implement new efi_print_load_option for printing out
the EFI_LOADER_OPTION data structure used to specify different options
to the UEFI boot manager.

Sponsored by: Netflix

r323519:
Minor fixes to edge cases in efi_get_next_variable_name

Fix allocating more memory for the names (unlikely to be needed, but
still best to get right) to ask for the length the kernel told use we
needed, not the old length of the variable. Mind the proper NUL that
we add in the space we allocate. Free the old name string before we
allcoate a new one to limit what we leak to the last one (free passed
in name for the last one in the list), and detect the last one by rv
!= 0 and errno == ENOENT, rather then just the former to avoid false
positives if errno happens to be ENOENT on entry.

Sponsored by: Netflix

r325684:
Simplify the efivar interface a little.

We started out having Linux compatible libefivar interfaces. This was
in anticipation of porting the GPL'd efibootmgr to FreeBSD via a
port. However, since we need that functionality in the base, that port
isn't going to happened. It also appears that efivar is a private
library that's not used much outside a command line util and
efibootmgr. Reduce compatibility with the Linux version a little by
removing the mode parameter to efi_set_variable (which was unused on
FreeBSD, and not set to something useful in the code we'd
written). Also remove some efi error routines that were never
implemented and existed only to placate early GPL efibootmgr porting
experiments.

Suggested by: Matt Williams
Sponsored by: Netflix

r326050:
Document what the command line arguments actually do. List some of the
size limitations.

Sponsored by: Netflix

r326051:
This program is more useful if it skips leading whitespace when
parsing a textual UEFI Device Path, since otherwise it things the
passed in path is a filename. While here, reduce the repetition of

Sponsored by: Netflix

r326231:
Add efidp_format_device_path_node to format a single node in a device
path, much like efidp_format_device_path will format the entire path.

Sponsored by: Netflix

r326287:
efivar: add missing getopt 'u' option

r326457:
Read multiple lines when parsing the data. Allow multiple device paths
to be read when formatting device paths. Set the upper limit to 64k
(most of these paths are < 64 bytes).

Sponsored by: Netflix

r326458:
Create a function to translate UEFI paths to unix paths

efivar_device_path_to_unix_path translates from UEFI to Unix
efivar_unix_path_to_device_path translates from Unix to UEFI

At present, only HD() device types are supported (both GPT and
MBR). CdRom and floppy devices aren't supported. ZFS isn't supported
because there's no way in the UEFI standard to specify a ZFS datastore.
Network devices aren't supported either.

Three forms of Unix path are accepted: /path/to/file (for a mounted
filesystem), //path/to/file (uses the EFI partition on the same disk
as /), and dev:/path/to/file (for unmounted filesystem). Two forms are
produced (the first and last).

Sponsored by: Netflix

r326459:
Add -u (--to-unix) and -e (--to-efi) to convert unix or efi paths to
the other.

Sponsored by: Netflix

r326472:
Add forgotten libgeom.

Sponsored by: Netflix

r326658:
Ensure that "out" is initialized in all error paths.

Reported by: gcc
Reviewed by: cem
Differential Revision: https://reviews.freebsd.org/D13402

r326805:
Iniailize str so ucs2_to_utf8 won't free stack garbage.

CID: 1381037
Sponsored by: Netflix

r327574:
Set dp to NULL when we free it, and tree a NULL dp as an error
condition. This should prevent a double free. In addition, prevent a
leak by freeing dp each loop and when we're done.

CID: 1383577
Sponsored by: Netflix

r327575:
Need to convert '/' back to '\' when creating a path. Ideally, this
would be filesystem type dependent, but that's difficult to accomplish
and it's unclear how the UEFI firmware will cope. Be conservative and
make boot loaders cope instead.

Sponsored by: Netflix

r330279:
libefivar: use standard 2-Clause FreeBSD license

Approved by: imp
Sponsored by: The FreeBSD Foundation

Details

Provenance
kevansAuthored on
Reviewer
cem
Differential Revision
D13402: Don't free() uninitialized memory
Parents
rS332122: Move most of the contents of opt_compat.h to opt_global.h.
Branches
Unknown
Tags
Unknown