Commit Graph

52 Commits

Author SHA1 Message Date
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
Bryan Drewery
ea825d0274 DIRDEPS_BUILD: Update dependencies.
Sponsored by:	Dell EMC Isilon
2017-10-31 00:07:04 +00:00
Warner Losh
0e5d767884 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
2017-09-13 04:32:23 +00:00
Warner Losh
1028a2d4b3 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
2017-09-07 07:30:14 +00:00
Ryan Libby
92ac7e80da libefivar: -fno-strict-aliasing
Avoid dealing with some code that uses type-punned pointers.

See D12210 and D12211 for more background.

Reviewed by:	imp
Approved by:	markj (mentor)
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D12219
2017-09-04 18:59:44 +00:00
Warner Losh
ae3adc0645 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
2017-08-31 15:53:47 +00:00
Warner Losh
0d802f5a7a 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.
2017-08-31 15:53:27 +00:00
Warner Losh
4c69a17ff9 fix typo 2017-07-24 18:10:42 +00:00
Warner Losh
d780e0595c Fix a coverity-discovered NULL pointer dereference.
*** CID 1372598:  Null pointer dereferences  (FORWARD_NULL)
/lib/libefivar/efivar-dp-parse.c: 3612 in UefiDevicePathLibConvertTextToDeviceNode()
   Dereferencing null pointer "FromText".

When ported from Tiano core, I commented this out with an ifdef. That
was in error because we're supposed to fallback to a filepath when
nothing else patches. Instead, restore the original code, but fix
DevPathFromTextFilePath to cope with the conversion to narrow
strings. Also, fix the off-by-one error in the size of the memory it
allocates.

The off by one error is documented in Tiano core bug
https://bugzilla.tianocore.org/show_bug.cgi?id=441

CID: 1372598
Sponsored by: Netflix
2017-03-23 02:30:57 +00:00
Warner Losh
8af6a2c64e Define StrCmp in a funky was to be bug-compatible with EDK2 code.
Paper over a coverity issue:

*** CID 1372592:  API usage errors  (BAD_COMPARE)
/lib/libefivar/efivar-dp-parse.c: 2723 in DevPathFromTextiSCSI()
   Truncating the result of "strcmp" to "unsigned short" may cause it
   to be misinterpreted as 0. Note that "strcmp" may return an integer
   besides -1, 0, or 1.

We do this by making StrCmp return either 0 or 1 for equal or
not-equal.  There's a bug in the DevPathFromTextiSCSI cast of the
return value and this workaround will fix it without breaking other
users of StrCmp (all of which test for == 0).

https://bugzilla.tianocore.org/show_bug.cgi?id=440 has been filed
upstream to log this issue.

CID: 1372592
Sponsored by: Netflix
2017-03-23 02:30:52 +00:00
Warner Losh
7270962aa5 Bring in EDK2 routines for printing and parsing device paths.
This commit implements the (mostly?) Linux compatible
efidp_format_device_path and efidp_parse_device_path APIs. These are
the only APIs exposed through this library. However, they are built on
code from Tianocore's EDK2 MdePkg. They are brought in as new files
here for reasons described in FreeBSD-update.

Symbol versioning will be introduced to control what's exported from
the EDK2 code.

Some structural changes may be necessary when we move to sharing with
sys/boot/efi.

Sponsored by: Netflix
2017-03-09 00:31:31 +00:00
Warner Losh
bea9d78b2d Share UCS2/UTF8 routines between boot loader and userland.
Move the UCS2 to UTF8 routines over into sys/boot/efi and have
libefivar grab them from there.

Sponsored by: Netflix
2017-03-09 00:24:01 +00:00
Warner Losh
8ff15e8613 Make sure guid table is compiled before we use it.
Sponsored by: Netflix
2017-03-03 20:23:23 +00:00
Warner Losh
80967c8e1c Only compile the known uuid table once.
Sponsored by: Netflix
2017-03-03 20:22:56 +00:00
Warner Losh
e174551332 Move uuid_table definition to efivar.h.
Create new function efi_known_guid() to return list of guids.

Sponsored by: Netflix
2017-03-03 20:22:47 +00:00
Warner Losh
589c673b32 Don't convert ENOENT to nothing for individual lookup, just for the
iterative get_next interface. This prevents efivar(3) from printing 4k
of 0's when a variable isn't set.

Sponsored by: Netflix
2017-02-25 00:09:21 +00:00
Bryan Drewery
d329c46cfa DIRDEPS_BUILD: Connect new dependencies.
MFC after:	2 weeks
Sponsored by:	Dell EMC Isilon
2016-11-13 00:11:23 +00:00