summaryrefslogtreecommitdiff
path: root/lib/efi_loader/efi_device_path.c
AgeCommit message (Collapse)Author
2025-06-02Merge patch series "Audit include list for include/[a-m]*.h"Tom Rini
Tom Rini <trini@konsulko.com> says: Hey all, Related to my other series I've posted recently on cleaning up some headers, this series here is the result of at least lightly auditing the #includes used in include/[a-m]*.h. This ignores subdirectories, as at least in part I think the top-level includes we've constructed are the most likely places to have some extra transitive include paths. I'm sure there's exceptions and I'll likely audit deeper once this first pass is done. This only gets as far as "include/m*.h" because I didn't want this to get too big. This also sets aside <miiphy.h> and <phy.h>. While miiphy.h does not directly need <phy.h> there are *so* many users and I think I had half of the tree just about not building when I first tried. It might be worth further investigation, but it might just be OK as-is. Link: https://lore.kernel.org/r/20250521230119.2084088-1-trini@konsulko.com
2025-06-02include/ide.h: Cleanup usageTom Rini
At this point in time, <ide.h> provides the IDE_BUS macro and the function prototype for ide_set_reset, which is used with IDE_RESET. The only files which should include this header are the ones that either use that macro or that function. Remove <blk.h> from <ide.h> and remove <ide.h> from places which do not need it. Signed-off-by: Tom Rini <trini@konsulko.com>
2025-05-25efi: Rename END to EFI_DP_ENDSimon Glass
This exported symbol has a very generic name. Rename it to indicate that it relates to EFI and device-paths. Fix checkpatch warnings related to use of multiple assignments. Signed-off-by: Simon Glass <sjg@chromium.org> Suggested-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2025-05-25efi_loader: Separate device path into its own headerSimon Glass
These functions are useful for the EFI app. As a first step towards making these available outside lib/efi_loader, create a separate header file and include it where needed. Add proper comments to the functions, since many are missing at present. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2025-03-10efi_loader: efi_net: Add device path cacheAdriano Cordova
In preparation to support mutiple efi net udevices. Add a device path cache to support device paths from multiple ethernet udevices. The device paths can be added to the cache before EFI gets initialized and the protocols get installed. Signed-off-by: Adriano Cordova <adriano.cordova@canonical.com>
2025-03-10efi_loader: efi_device_path: Pass net udevice as argumentAdriano Cordova
In preparation to support multiple EFI net objects, support constructing device paths using an ethernet device different than the default. Add a udevice argument to the device path generation, and keep the callsites with eth_get_dev() to preserve existing functionality. Signed-off-by: Adriano Cordova <adriano.cordova@canonical.com>
2024-12-04Merge tag 'efi-next-2024-12-04' of ↵Tom Rini
https://source.denx.de/u-boot/custodians/u-boot-efi into next CI: https://source.denx.de/u-boot/custodians/u-boot-efi/-/pipelines/23707 With this pull request support for the EFI_HTTP_PROTOCOL and EFI_IP4_CONFIG2 protocols are added. This allows EFI applications to load files via HTTP. UEFI: add efi_dp_from_ipv4 function add efi_net_set_addr, efi_net_get_addr functions add support for HTTP device path set EFI bootdevice device path to HTTP when loaded from wget add support to send http requests and parse http headers provide EFI_IP4_CONFIG2_PROTOCOL provide EFI_HTTP_PROTOCOL support IPv4() in device path to text protocol provide unit tests for the HTTP and IPv4 Config2 protocols Network: zero terminate string with headers in wget_fill_info() zero terminate string with headers in wget_lwip_fill_info() pass port and server_name via wget_ctx in lwIP network stack let wget_with_dns work with dns disabled Others: Add HTTP and IPV4 Config II protocols to UUID library functions.
2024-12-04efi_loader: net: set EFI bootdevice device path to HTTP when loaded from wgetAdriano Cordova
Set the device path of the efi boot device to an HTTP device path (as formed by efi_dp_from_http) when the next boot stage is loaded using wget (i.e., when wget is used with wget_info.set_bootdev=1). When loaded from HTTP, the device path should account for it so that the next boot stage is aware (e.g. grub only loads its http stack if it itself was loaded from http, and it checks this from its device path). Signed-off-by: Adriano Cordova <adrianox@gmail.com> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2024-12-04efi_loader: device_path: add support for HTTP device pathAdriano Cordova
Add efi_dp_from_http to form a device path from HTTP. The device path is the concatenation of the device path returned by efi_dp_from_ipv4 together with an URI node and an END node. Signed-off-by: Adriano Cordova <adrianox@gmail.com> Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2024-12-04efi_loader: device_path: add efi_dp_from_ipv4Adriano Cordova
Add efi_dp_from_ipv4 to form a device path from an ipv4 address. Signed-off-by: Adriano Cordova <adrianox@gmail.com> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2024-11-09efi_loader: Change efi_dp_from_mem() to use sizeMoritz Fischer
All call sites are using size rather than end addresses, so instead - as previously done - calculating an end address everywhere, just modify the function to use size and internally calculate the end address Cc: Heinrich Schuchardt <xypron.glpk@gmx.de> Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org> Cc: Patrick Wildt <pwildt@google.com> Signed-off-by: Moritz Fischer <moritzf@google.com> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2024-10-31lib: efi_loader: Fix efi_dp_from_mem() callsMoritz Fischer
The function expects an end address but is being called with an size instead. Fixes: 6422820ac3 ("efi_loader: split unrelated code from efi_bootmgr.c") Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> Signed-off-by: Moritz Fischer <moritzf@google.com> Reviewed-by: Patrick Wildt <pwildt@google.com>
2024-09-12include: export uuid.hCaleb Connolly
Move this header to include/u-boot/ so that it can be used by external tools. Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
2024-06-10efi_loader: return binary from efi_dp_from_lo()Heinrich Schuchardt
For finding distro supplied device-trees we need to know from which device we are booting. This can be identified via the device-path of the binary. Up to now efi_dp_from_lo() only could return the initrd or fdt device-path. Allow returning the binary device-path, too. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2024-06-10efi_loader: allow concatenation with contained end nodeHeinrich Schuchardt
Allow appending a device-path to a device-path that contains an end node as separator. We need this feature for creating boot options specifying kernel, initrd, and dtb. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2024-05-01efi_loader: fix description efi_dp_shortenHeinrich Schuchardt
Use Sphinx style for return value. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2024-01-17efi_loader: split unrelated code from efi_bootmgr.cAKASHI Takahiro
Some code moved from cmd/bootefi.c is actually necessary only for "bootefi <addr>" command (starting an image manually loaded by a user using U-Boot load commands or other methods (like JTAG debugger). The code will never been opted out as unused code by a compiler which doesn't know how EFI boot manager is implemented. So introduce a new configuration, CONFIG_EFI_BINARY_EXEC, to enforce them opted out explicitly. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
2024-01-13efi_loader: Clean up efi_dp_append and efi_dp_concatIlias Apalodimas
Looking back at the initrd storing functionality, we introduced three functions, efi_dp_append_or_concatenate(), efi_dp_append/concat(). In hindsight we could have simplified that by a lot. First of all none of the functions append anything. They all allocate a new device path and concatenate the contents of two device paths in one. A boolean parameter controls the final device path -- if that's true an end node is injected between the two device paths. So let's rewrite this and make it a bit easier to read. Get rid of efi_dp_append(), efi_dp_concat() and rename efi_dp_append_or_concatenate() to efi_dp_concat(). This is far more intuitive and the only adjustment that is needed is an extra boolean argument on all callsites. Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2023-12-21efi_loader: Remove <common.h>Tom Rini
We largely do not need <common.h> in these files, so drop it. The only exception here is that efi_freestanding.c needs <linux/types.h> and had been getting that via <common.h>. Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Tom Rini <trini@konsulko.com>
2023-07-28efi_loader: simplify dp_fill()Heinrich Schuchardt
Move the recursive dp_fill(dev->parent) call to a single location. Determine uclass_id only once. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2023-07-28efi_loader: device paths for special block devicesHeinrich Schuchardt
The UEFI specification does not provide node types matching UCLASS_BLKMAP, UCLASS_HOST, UCLASS_VIRTIO block devices. The current implementation uses VenHw() nodes with uclass specific GUIDs and a single byte for the device number appended. This leads to unaligned integers in succeeding device path nodes. The current implementation fails to create unique device paths for block devices based on other uclasses like UCLASS_PVBLOCK. Let's use a VenHw() node with the U-Boot GUID with a length dividable by four and encoding blkdesc->uclass_id as well as blkdesc->devnum. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2023-07-20efi_loader: support all uclasses in device pathHeinrich Schuchardt
On devices with multiple USB mass storage devices errors like Path /../USB(0x0,0x0)/USB(0x1,0x0)/Ctrl(0x0) already installed. are seen. This is due to creating non-unique device paths. To uniquely identify devices we must provide path nodes for all devices on the path from the root device. Add support for generating device path nodes for all uclasses. Reported-by: Suniel Mahesh <sunil@amarulasolutions.com> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2023-07-20efi_loader: fix dp_fill() for BLKMAP, HOST, VIRTIOHeinrich Schuchardt
Do not assume that the preceding device path contains a single VenHW node. Instead use the return value of dp_fill() which provides the address of the next node. Fixes: 23ad52fff4da ("efi_loader: device_path: support Sandbox's "host" devices") Fixes: 19ecced71cfb ("efi_loader: device path for virtio block devices") Fixes: 272ec6b45304 ("efi_loader: device_path: support blkmap devices") Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2023-06-02efi_loader: check return value of part_get_info()Heinrich Schuchardt
part_get_info() may return an error code. Check it. Update function description of dp_part_node(). Addresses-Coverity-ID: 184067 ("Unchecked return value") Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2023-05-13efi_loader: fix efi_dp_from_file()Heinrich Schuchardt
* When called from efi_dp_from_name() we miss to append the filename for non-block devices. * expand_media_path() could be simplified by using efi_dp_from_file to prepend the device path of the boot device. This can be avoided by passing a device path to efi_dp_from_file() instead of a block device descriptor and a partition number. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2023-05-13efi_loader: simplify efi_dp_from_name()Heinrich Schuchardt
Don't do the same check and assignment in multiple places. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2023-05-13efi_loader: error code efi_dp_from_name()Heinrich Schuchardt
Use EFI_OUT_OF_RESOURCES if the device path cannot be constructed. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2023-05-13efi_loader: clean up efi_dp_from_fileHeinrich Schuchardt
* Improve variable name usage: Use pos instead of buf to indicate the current position in a buffer. * Avoid double assignment in a single code line. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2023-05-13efi_loader: duplicate code in efi_dp_from_nameHeinrich Schuchardt
efi_dp_from_name() has duplicate code to replace slash by backslash. path_to_uefi() called by efi_dp_from_file() already does this. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2023-05-13efi_loader: avoid #ifdef in efi_dp_from_name()Heinrich Schuchardt
According to our coding style guide #ifdef should be avoided. Use IS_ENABLED() instead. Sort string comparisons alphabetically. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2023-05-13efi_loader: support booting semihosting fileHeinrich Schuchardt
Executing an EFI binary fails for files loaded via semihosting. Construct a dummy device path for EFI binaries loaded via semihosting. A future complete solution may include the creation of a handle with a simple file system protocol. Reported-by: Andre Przywara <andre.przywara@arm.com> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2023-04-05efi_loader: device_path: support blkmap devicesTobias Waldekranz
Create a distinct EFI device path for each blkmap device. Signed-off-by: Tobias Waldekranz <tobias@waldekranz.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2023-04-03Merge branch 'next'Tom Rini
Signed-off-by: Tom Rini <trini@konsulko.com>
2023-04-01efi_loader: remove duplicate assignmentHeinrich Schuchardt
Assigning the value of a variable to itself should be avoided. Addresses-Coverity-ID: 451089 ("Evaluation order violation") Fixes: 180b7118bed8 ("efi_loader: fix device-path for USB devices") Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2023-04-01efi_loader: correct shortening of device-pathsHeinrich Schuchardt
We use short device-paths in boot options so that a file on a block device can be found independent of the port into which the device is plugged. Usb() device-path nodes only contain port and interface information and therefore cannot identify a block device. UsbWwi() device-path nodes contain the serial number of USB devices. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2023-03-25efi_loader: move dp_alloc() to efi_alloc()Heinrich Schuchardt
The incumbent function efi_alloc() is unused. Replace dp_alloc() by a new function efi_alloc() that we can use more widely. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2023-03-25efi_loader: fix device-path for USB devicesHeinrich Schuchardt
EFI device paths for block devices must be unique. If a non-unique device path is discovered, probing of the block device fails. Currently we use UsbClass() device path nodes. As multiple devices may have the same vendor and product id these are non-unique. Instead we should use Usb() device path nodes. They include the USB port on the parent hub. Hence they are unique. A USB storage device may contain multiple logical units. These can be modeled as Ctrl() nodes. Reported-by: Patrick Delaunay <patrick.delaunay@foss.st.com> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2023-03-25efi_loader: fix device-path for USB devicesHeinrich Schuchardt
EFI device paths for block devices must be unique. If a non-unique device path is discovered, probing of the block device fails. Currently we use UsbClass() device path nodes. As multiple devices may have the same vendor and product id these are non-unique. Instead we should use Usb() device path nodes. They include the USB port on the parent hub. Hence they are unique. A USB storage device may contain multiple logical units. These can be modeled as Ctrl() nodes. Reported-by: Patrick Delaunay <patrick.delaunay@foss.st.com> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2022-11-07dm: sandbox: Switch over to using the new host uclassSimon Glass
Update the sandbox implementation to use UCLASS_HOST and adjust all the pieces to continue to work: - Update the 'host' command to use the new API - Replace various uses of UCLASS_ROOT with UCLASS_HOST - Disable test_eficonfig since it doesn't work (this should have a unit test to allow this to be debugged) - Update the blk test to use the new API - Drop the old header file Unfortunately it does not seem to be possible to split this change up further. Signed-off-by: Simon Glass <sjg@chromium.org>
2022-11-06efi_loader: Let networking support depend on NETDEVICESJan Kiszka
CONFIG_NET does not imply that there are actually network devices available, only CONFIG_NETDEVICES does. Changing to this dependency obsoletes the check in Kconfig because NETDEVICES means DM_ETH. Fixes: 0efe1bcf5c2c ("efi_loader: Add network access support") Suggested-by: Tom Rini <trini@konsulko.com> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2022-10-06efi_loader: efi_dp_part_node check dp_alloc return valueHeinrich Schuchardt
dp_alloc() may return NULL. This needs to be caught. Fixes: 98d48bdf415e ("efi_loader: provide a function to create a partition node") Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2022-07-13efi_loader: expose END device path nodeMasahisa Kojima
This commit exposes the END device path node. Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org> Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2022-06-22cmd: load: add load command for memory mappedRui Miguel Silva
cp.b is used a lot as a way to load binaries to memory and execute them, however we may need to integrate this with the efi subsystem to set it up as a bootdev. So, introduce a loadm command that will be consistent with the other loadX commands and will call the efi API's. ex: loadm $kernel_addr $kernel_addr_r $kernel_size with this a kernel with CONFIG_EFI_STUB enabled will be loaded and then subsequently booted with bootefi command. Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org> Reviewed-by: Tom Rini <trini@konsulko.com>
2022-06-12efi_loader: create boot options without file pathHeinrich Schuchardt
Allow the efidebug command to create boot options without file path, e.g. efidebug boot add -b 0001 'short dev only' host 0:1 '' efidebug boot add -B 0002 'long dev only' host 0:1 '' Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2022-04-23efi_loader: PARTITION_UUIDS should be optionalAKASHI Takahiro
In the current implementation, partition table support (either GPT or DOS) is not mandatory. So CONFIG_PARTITION_UUIDS should not be enabled (selected) unconditionally. Fixes: commit 17f8cda505e3 ("efi_loader: set partition GUID in device path for SIG_TYPE_GUID") Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2022-03-26efi_loader: typo devie-pathHeinrich Schuchardt
%s/devie-path/device-path/ Reported-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2022-03-20efi_loader: efi_dp_find_obj() add protocol checkHeinrich Schuchardt
Let function efi_dp_find_obj() additionally check if a given protocol is installed on the handle relating to the device-path. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2022-03-20efi_loader: fix efi_dp_find_obj()Heinrich Schuchardt
efi_dp_find_obj() should not return any handle with a partially matching device path but the handle with the maximum matching device path. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2022-03-20efi_loader: export efi_dp_shorten()Heinrich Schuchardt
Rename function shorten_path() to efi_dp_shorten() and export it. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2022-02-05efi: Drop unnecessary calls to blk_find_device()Simon Glass
When we have the block descriptor we can simply access the device. Drop the unnecessary function call. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>