Commit Graph

68 Commits

Author SHA1 Message Date
Warner Losh
2b46091032 efivar: Really look for labels for the provider with right efimedia
The prior code mistakently thought that the g_consumer that hung off the
provider we found were the right thing to use to find all the glabel
aliases for this node. However, the only way to find that is to iterate
through all the geoms that belong to the glabel geom class, looking for
those geoms with the same name as the provider with the right efimedia.
Do this in a way that caches glabel class, and allows for it to be
absent. Tighten the filter for mounted filesystems to only look
for the ones that are mounted on /dev/.. since the rest of the code
assumes that.

MFC After:		3 days
Sponsored by:		Netflix
Reviewed by:		corvink, asomers
Differential Revision:	https://reviews.freebsd.org/D38619
2023-02-16 08:54:39 -07:00
Warner Losh
57d5ca4eeb efivar: support device paths as well as mounted paths in path_to_dp
In path_to_dp, allow passing in either the actual device path "eg
/dev/foo/bar" or the path where the device is mounted (say
/mnt/baz/bing). In the former case we'll assume the path within the
device is nothing (the relpath). In the latter, we'll take from the
mount point on down as the relpath.

Sponsored by:		Netflix
Reviewed by:		corvink, manu, asomers
Differential Revision:	https://reviews.freebsd.org/D38616
2023-02-16 08:54:39 -07:00
Warner Losh
49fd6affdb efivar: Allow NULL paths in build_dp
Allow there to be NULL paths in buildp. This lets us return the device
path to the partition, as well as to files on the partition.

Sponsored by:		Netflix
Reviewed by:		corvink, manu, asomers
Differential Revision:	https://reviews.freebsd.org/D38615
2023-02-16 08:54:39 -07:00
Warner Losh
ccf2121d59 efivar: Try harder to find label's efimedia
If there's no efimedia attribute on the provider, and the provider's a
glabel, then find the 'parent' geom. In this case, the provider's name
is label-type/name, but the geom's label will that of the underlying
device (eg ada0p1). If it is, recurisvely call find_geom_efimedia with
the geom's name, which shuold have the efimedia attribute.

Sponsored by:		Netflix
Reviewed by:		corvink, manu, asomers
Differential Revision:	https://reviews.freebsd.org/D38614
2023-02-16 08:54:39 -07:00
Warner Losh
942815c548 libefivar: Add note about extra compiler flags
Add a note about why we need these extra compiler flags to suppress
warnings. EDK2 upstream code is being used verbatim and as of the last
update these issuse persist, but are benign.

Sponsored by:		Netflix
Reviewed by:		asomers
Differential Revision:	https://reviews.freebsd.org/D38613
2023-02-15 16:03:54 -07:00
John Baldwin
d30a1689f5 libefivar: Fix a buffer overread.
DevPathToTextUsbWWID allocates a separate copy of the SerialNumber
string to append a null terminator if the original string is not
null terminated.  However, by using AllocateCopyPool, it tries to
copy 'Length + 1' words from the existing string containing 'Length'
characters into the target string.  Split the copy out to only
copy 'Length' characters instead.

Reviewed by:	imp, emaste
Reported by:	GCC 12 -Wstringop-overread
Differential Revision:	https://reviews.freebsd.org/D36826
2022-10-03 16:10:44 -07:00
Gordon Bergling
b1c5f60ce8 libefivar(3): Fix a typo in a source code comment
- s/partiton/partition/

MFC after:	3 days
2022-03-28 19:27:58 +02:00
Jose Luis Duran
5754f5823b libefivar: Apply uncrustify changes
Apply uncrustify changes to .c/.h files.

Reduce the diffs with EDK2 to aid with future merges.  The
unconventional way we've imported this code makes using a vendor branch
to manage it at the very least tricky. Update FreeBSD-update to reflect
the slight shift in advise.

Reviewed by:	imp
Upstream Bug:	https://bugzilla.tianocore.org/show_bug.cgi?id=3737
Obtained from:	2f88bd3a12
Pull Request:   https://github.com/freebsd/freebsd-src/pull/581
2022-02-27 09:45:34 -07:00
Jose Luis Duran
60de142cfc libefivar: Change OPTIONAL keyword usage style
Update all use of ', OPTIONAL' to ' OPTIONAL,' for function params.

Upstream Bug:	https://bugzilla.tianocore.org/show_bug.cgi?id=3760
Obtained from:	d0e2f8232a
Pull Request:   https://github.com/freebsd/freebsd-src/pull/581
2022-02-27 09:13:47 -07:00
Jose Luis Duran
11a9ff5bc1 libefivar: Replace BSD License with BSD+Patent License
Replace BSD 2-Clause License with BSD+Patent License.  This change is
based on the following emails:

  https://lists.01.org/pipermail/edk2-devel/2019-February/036260.html
  https://lists.01.org/pipermail/edk2-devel/2018-October/030385.html

RFCs with detailed process for the license change:

  V3: https://lists.01.org/pipermail/edk2-devel/2019-March/038116.html
  V2: https://lists.01.org/pipermail/edk2-devel/2019-March/037669.html
  V1: https://lists.01.org/pipermail/edk2-devel/2019-March/037500.html

Upstream Bug:	https://bugzilla.tianocore.org/show_bug.cgi?id=1373
Obtained from:	9344f09215
Pull Request:   https://github.com/freebsd/freebsd-src/pull/581
2022-02-27 09:13:43 -07:00
Jose Luis Duran
e871598ad4 libefivar: Check Length para before use in DevPathToTextUsbWWID
In function DevPathToTextUsbWWID, the Length parameter is used
without check. This patch is to add check before using it.

Upstream Bug:	https://bugzilla.tianocore.org/show_bug.cgi?id=1336
Obtained from:	d8e702693a
Pull Request:   https://github.com/freebsd/freebsd-src/pull/581
2022-02-27 09:13:40 -07:00
Jose Luis Duran
c1fa6f4c5d libefivar: Fix incorrect check for DisplayOnly text format in AcpiEx
Text format for AcpiEx device path in UEFI Spec:
AcpiEx(HID,CID,UID,HIDSTR,CIDSTR,UIDSTR)
AcpiEx(HID|HIDSTR,(CID|CIDSTR,UID|UIDSTR))(Display Only)

When convert device path to text for AcpiEx device path,
current code check AllowShortcuts parameter to convert
the device path to DisplayOnly text format(shorter text
representation) by mistake.
It should check DisplayOnly parameter.

This commit is to fix this issue.

Upstream Bug:	https://bugzilla.tianocore.org/show_bug.cgi?id=1312
Obtained from:	e9ab1635a2
Pull Request:   https://github.com/freebsd/freebsd-src/pull/581
2022-02-27 09:13:35 -07:00
Jose Luis Duran
492d9953fa libefivar: Handle AcpiExp device path when optional para is not specified
AcpiExp text device path: AcpiExp(HID,CID,UIDSTR)
And according to UEFI spec, the CID parameter is optional
and has a default value of 0. But current implementation
miss to check following cases for the AcpiExp.
FromText: when text device is AcpiExp(HID,,UIDSTR)/AcpiExp(HID,0,UIDSTR)
ToText: when the CID is 0 in the node structure

This commit is to do the enhancement.

Upstream Bug:	https://bugzilla.tianocore.org/show_bug.cgi?id=1243
Obtained from:	a8b5750901
Pull Request:   https://github.com/freebsd/freebsd-src/pull/581
2022-02-27 09:13:31 -07:00
Jose Luis Duran
965f85271c libefivar: Handle USBxxx device path when optional para is not specified
According to UEFI spec,
for the Messaging Device Path with USB Class SubType, some paras
are optional in the text device path.
Take UsbClass(VID,PID,Class,SubClass,Protocol) for example,
The VID is an integer between 0 and 65535 and is optional. The
default value is 0xFFFF.
The PID is an integer between 0 and 65535 and is optional. The
default value is 0xFFFF.
The Class is an integer between 0 and 255 and is optional. The
default value is 0xFF.
The SubClass is an integer between 0 and 255 and is optional. The
default value is 0xFF.
The Protocol is an integer between 0 and 255 and is optional. The
default value is 0xFF.
So if any the optional para is not specified in the text device,
we should set related para in the node structure to default value.

This commit is to do the enhancement for USB Class device path
when optional para is not specified.

Upstream Bug:	https://bugzilla.tianocore.org/show_bug.cgi?id=1243
Obtained from:	3874108034
Pull Request:   https://github.com/freebsd/freebsd-src/pull/581
2022-02-27 09:13:24 -07:00
Jose Luis Duran
4e83ac7d2e libefivar: Handle Sata device path when optional para is not specified
Sata device path format:Sata(HPN, PMPN, LUN)
According to UEFI Spec, the PMPN is an integer between
0 and 65535 and is optional. If not provided, the default is 0xFFFF.

This commit is to do the enhancement for Sata device path
when optional para is not specified.

Upstream Bug:	https://bugzilla.tianocore.org/show_bug.cgi?id=1243
Obtained from:	6d9b9bbb61
Pull Request:   https://github.com/freebsd/freebsd-src/pull/581
2022-02-27 09:13:20 -07:00
Jose Luis Duran
9a62aa9329 libefivar: Use VENDOR_DEVICE_PATH structure for Debug Port device path
When converting DebugPort device path from text,
current code use VENDOR_DEFINED_MESSAGING_DEVICE_PATH structure
for Debug port device node.
typedef struct {
  EFI_DEVICE_PATH_PROTOCOL  Header;
  EFI_GUID                  Guid;
  UINT8                     VendorDefinedData[1];
} VENDOR_DEFINED_MESSAGING_DEVICE_PATH;

And Debugport Device Path is a vendor-defined messaging
device path with no data, only a GUID. So it's better to
use VENDOR_DEVICE_PATH to create the Debug port device node.
typedef struct {
  EFI_DEVICE_PATH_PROTOCOL        Header;
  EFI_GUID                        Guid;
} VENDOR_DEVICE_PATH;

Upstream Bug:	https://bugzilla.tianocore.org/show_bug.cgi?id=1229
Obtained from:	9343d0a1cd
Pull Request:   https://github.com/freebsd/freebsd-src/pull/581
2022-02-27 09:13:12 -07:00
Jose Luis Duran
a51ae7212d libefivar: Add PciRoot/PcieRoot text for ACPI Expanded Device Path
According to UEFI spec,for ACPI Expanded Device Path
when HID=PNP0A03 or CID=PNP0A03 and HID != PNP0A08,
the device path node can be displayed as: PciRoot(UID|UIDSTR)
When HID=PNP0A08 or CID=PNP0A08, the device path node can be
displayed as: PcieRoot(UID|UIDSTR). But current code miss the
code logic.

This commit is to do the enhancement.

Upstream Bug:	https://bugzilla.tianocore.org/show_bug.cgi?id=1228
Obtained from:	78af0984b4
Pull Request:   https://github.com/freebsd/freebsd-src/pull/581
2022-02-27 09:13:08 -07:00
Jose Luis Duran
ac2b16d3b1 libefivar: Correct condition check for AcpiExp text format
According to UEFI Spec, for ACPI Expanded Device Path,
when HIDSTR=empty, CIDSTR=empty, UID STR!=empty,
the ACPI Expanded Device Path node can be displayed as
AcpiExp(HID,CID,UIDSTR) format.
And if UID is 0 and UIDSTR is empty, then use AcpiEx format.

This patch is to correct the condition check to follow UEFI
Spec when convert the device path node to the AcpiExp text
format.

Upstream Bug:	https://bugzilla.tianocore.org/show_bug.cgi?id=1226
Obtained from:	fb4bea551e
Pull Request:   https://github.com/freebsd/freebsd-src/pull/581
2022-02-27 09:13:04 -07:00
Jose Luis Duran
8278071ae1 libefivar: Correct the string order of ACPI Expanded Device Path
According to UEFI Spec, ACPI Expanded Device Path can be display
AcpiEx(HID|HIDSTR,(CID|CIDSTR,UID|UIDSTR)), but current code display
UID|UIDSTR before CID|CIDSTR.
This patch is to fix this issue.

Upstream Bug:	https://bugzilla.tianocore.org/show_bug.cgi?id=1227
Obtained from:	05fe752589
Pull Request:   https://github.com/freebsd/freebsd-src/pull/581
2022-02-27 09:13:00 -07:00
Jose Luis Duran
49951297d2 libefivar: Clean up source files
1. Do not use tab characters
2. No trailing white space in one line
3. All files must end with CRLF

Adapted according to FreeBSD-update instructions, with the sole purpose
of reducing the differences with upstream sources.

Obtained from:	9095d37b8f
Pull Request:   https://github.com/freebsd/freebsd-src/pull/581
2022-02-27 09:12:55 -07:00
Jose Luis Duran
50668299b3 libefivar: Fix iSCSI.Lun byte order issue
Obtained from:	19f21ed916
Pull Request:   https://github.com/freebsd/freebsd-src/pull/581
2022-02-27 09:12:52 -07:00
Jose Luis Duran
acfee0131a libefivar: Fix byte orders of iSCSI.Lun
Per UEFI spec, iSCSI.Lun is a 8-byte array with byte #0 in the left.
It means "0102030405060708" should be converted to:
    UINT8[8] = {01, 02, 03, 04, 05, 06, 07, 08}
or  UINT64 = {0807060504030201}

Today's implementation wrongly uses the reversed order.

Obtained from:	d0196be1e3
Pull Request:   https://github.com/freebsd/freebsd-src/pull/581
2022-02-27 09:12:47 -07:00
Jose Luis Duran
76ed5f1b26 libefivar: Fix bug when converting iSCSI node
If protocol string is not specified, default TCP(0) should be used.
Today's implementation wrongly sets to 1 for this case.

Obtained from:	e6c80aea71
Pull Request:   https://github.com/freebsd/freebsd-src/pull/581
2022-02-27 09:12:41 -07:00
Jose Luis Duran
d9d1a1e7ab libefivar: Add DevPathFromTextDns and DevPathToTextDns libraries
V3:
* Fix the bug in DevPathFromTextDns()

V2:
* Add no IP instance case check.

Obtained from:	9b9d0655c1
Pull Request:   https://github.com/freebsd/freebsd-src/pull/581
2022-02-27 09:12:29 -07:00
Jose Luis Duran
e8fc7f1189 libefivar: Add BluetoothLe device path node support
Obtained from:	ff5623e990
Pull Request:   https://github.com/freebsd/freebsd-src/pull/581
2022-02-27 09:12:25 -07:00
Jose Luis Duran
0081638344 libefivar: Reverse the byte order of BD_ADDR for Bluetooth
For the following two functions:
DevPathFromTextBluetooth()
DevPathToTextBluetooth()

The Bluetooth device address "UINT8  Address[6]" is displayed with the
order from Address[5] to Address[0]. This commit reverses the order.

Obtained from:	4fc8277133
Pull Request:   https://github.com/freebsd/freebsd-src/pull/581
2022-02-27 09:12:21 -07:00
Jose Luis Duran
7ca6daff6a libefivar: Refine the DevPathFromTextiSCSI protocol parsing
For current iSCSI protocol parsing, UINT16 truncation may be happened. Since
the Spec already have declaimed that 0 is TCP Protocol and 1+ is reserved, the
parsing can be refined as below:

  if (StrCmp (ProtocolStr, L"TCP") == 0) {
    ISCSIDevPath->NetworkProtocol = 0;
  } else {
    //
    // Undefined and reserved.
    //
    ISCSIDevPath->NetworkProtocol = 1;
  }

Obtained from:	7571a1c191
Pull Request:   https://github.com/freebsd/freebsd-src/pull/581
2022-02-27 09:12:18 -07:00
Jose Luis Duran
b782b7884c libefivar: Fix FromText bug for multi-instance devicepath
UefiDevicePathLibConvertTextToDevicePath correctly detects when it
has hit a ',' splicing together multiple paths. However, the code
that tries to cope with it:
{code}
if (IsInstanceEnd) {
  DeviceNode = (EFI_DEVICE_PATH_PROTOCOL *) AllocatePool (
                                   END_DEVICE_PATH_LENGTH);
  ASSERT (DeviceNode != NULL);
  SetDevicePathEndNode (DeviceNode);

  NewDevicePath = AppendDevicePathNode (DevicePath, DeviceNode);
  FreePool (DevicePath);
  FreePool (DeviceNode);
  DevicePath = NewDevicePath;
}
{code}
causes a problem. The END node that's appended it the node for the
entire list. So when the node is appended in AppendDevicePathNode,
it winds up disappearing. This leads to the path
'PciRoot(0x0),PciRoot(0x0)' parsing as if 'PciRoot(0x0)/PciRoot(0x0)'
were specified. These are two very different things.

NOTE:
This fix was already committed.  It has been included with the sole
intention of reducing diffs with upstream.

Upstream Bug:	https://bugzilla.tianocore.org/show_bug.cgi?id=419
Obtained from:	647636e175
Pull Request:	https://github.com/freebsd/freebsd-src/pull/581
2022-02-27 09:11:59 -07:00
Jose Luis Duran
81a659e364 libefivar: Fix the wrong MAC address length
Network interface type should be checked before the conversion between
text device path node and MAC device path. Otherwise, the MAC text string
can't be converted to the representation of a device node, which leads to
the series failure of network HII configuration(e.g. IP, VLAN, HTTP Boot
configuration in Network Device List).

Obtained from:	2d67f2bae3
Pull Request: https://github.com/freebsd/freebsd-src/pull/581
2022-02-27 09:11:55 -07:00
Jose Luis Duran
91a35e5803 libefivar: Correct the string expression of UTF8 vendor device path
According to UEFI spec, the string expression of UTF8 vendor
device node should be displayed as: VenUtf8(). Current code
display it as: VenUft8() by mistake when convert device
path node to text.

This commit is to fix this bug.

Upstream Bug:	https://bugzilla.tianocore.org/show_bug.cgi?id=1225
Obtained from:	959be180e1
Pull Request:	https://github.com/freebsd/freebsd-src/pull/580
2022-02-23 09:20:26 -07:00
Li-Wen Hsu
71779dddff
libefivar(3): efi_set_variables_supported.3 should be efi_variables_supported.3
MFC after:	3 days
2021-12-21 20:42:39 +08: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
Dimitry Andric
f643997a17 Cleanup compiler warning flags in lib/libefivar/Makefile
There is no need to set -Wno-unused-parameter twice, and instead of
appending to CFLAGS, append to CWARNFLAGS instead. While here, add
-Wno-unused-but-set-variable for the sake of clang 13.0.0.

MFC after:	3 days
2021-08-26 20:53:26 +02:00
Mitchell Horne
10aabc8b83 libefivar: define MDE_CPU_RISCV64
The necessary definitions from EDK2 are present, so this allows the
library to be built on RISC-V.
2020-07-06 17:47:29 +00:00
Simon J. Gerraty
2c9a9dfc18 Update Makefile.depend files
Update a bunch of Makefile.depend files as
a result of adding Makefile.depend.options files

Reviewed by:	 bdrewery
MFC after:	1 week
Sponsored by:   Juniper Networks
Differential Revision:  https://reviews.freebsd.org/D22494
2019-12-11 17:37:53 +00:00
Warner Losh
f17a98a602 Add additional sanity checks. 2019-12-09 01:32:18 +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
Warner Losh
366a7b3d0c Ensure that the device path is sane before trying to decode and print
it.

Sponsored by: Netflix, Inc
2018-10-26 22:49:36 +00:00
Mateusz Piotrowski
4026e1cc68 efivar(3): Fix some typos and improve style
- Fix some typos.
- Remove redundant semicolons from the synopsis section.
- Stylize variable names and types with Vt and Va respectively.
- Use a list to present non-implemented functions.
- Sort the order of the sections.
- Add a history section.
- Use Nm when "libefivar" is mentioned.

PR:		232626
Reported by:	Tiwei Bie <btw@mail.ustc.edu.cn>
Reviewed by:	bcr, imp
Approved by:	krion (mentor, implicit), mat (mentor, implicit)
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D17686
2018-10-25 15:41:19 +00:00
Kyle Evans
503478afd1 Add efidev(4)/efirt(9)
Document efidev(4), provider of userland access to EFI Runtime Services. A link is created to efirtc(4), which handles the time-of-day clock side.

efirt(9) is the kernel side of this.

Reviewed by:	imp, kib (earlier version)
Differential Revision:	https://reviews.freebsd.org/D16696
2018-08-17 04:17:51 +00:00
Warner Losh
03307d7ac3 Fix an obvious 'is odd' check.
len % 1 is always true. Fix StrHexToBytes to do a proper odd length
check. This was only called by DevPathFromTextGenericPath,
ConvertFromTextVendor and DevPathFromTextMAC, which we've not had
a need to actually use just yet.

Submitted by: David Binderman
PR: 229718
2018-07-12 16:19:17 +00:00
Ed Maste
6decf2ccbb libefivar: use standard 2-Clause FreeBSD license
Approved by:	imp
Sponsored by:	The FreeBSD Foundation
2018-03-02 15:12:18 +00:00
Warner Losh
670a4056e2 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
2018-01-05 07:09:29 +00:00
Warner Losh
167b7a41ff 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
2018-01-05 07:09:24 +00:00
Eitan Adler
d52a982ea8 lib: Fix several typos and minor errors
- duplicate words
- typos
- references to old versions of FreeBSD

Reviewed by:	imp, benno
2017-12-27 03:23:41 +00:00
Mark Johnston
3e4f07fc77 Ensure that "out" is initialized in all error paths.
Reported by:	gcc
Reviewed by:	cem
Differential Revision:	https://reviews.freebsd.org/D13402
2017-12-07 15:16:17 +00:00
Warner Losh
09ee5d8ab6 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
2017-12-02 07:29:19 +00:00
Warner Losh
5320ef6adf 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
2017-11-26 16:12:10 +00:00
Warner Losh
ca987d4641 Move sys/boot to stand. Fix all references to new location
Sponsored by:	Netflix
2017-11-14 23:02:19 +00:00
Warner Losh
831bec1163 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
2017-11-10 23:30:23 +00:00