aboutsummaryrefslogtreecommitdiff
path: root/lib/efi_loader/efi_device_path.c
Commit message (Collapse)AuthorAgeFilesLines
* efi_loader: split unrelated code from efi_bootmgr.cAKASHI Takahiro2024-01-171-1/+2
| | | | | | | | | | | | | 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>
* efi_loader: Clean up efi_dp_append and efi_dp_concatIlias Apalodimas2024-01-131-49/+21
| | | | | | | | | | | | | | | | | | 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>
* efi_loader: Remove <common.h>Tom Rini2023-12-211-1/+0
| | | | | | | | | 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>
* efi_loader: simplify dp_fill()Heinrich Schuchardt2023-07-281-27/+18
| | | | | | | | 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>
* efi_loader: device paths for special block devicesHeinrich Schuchardt2023-07-281-93/+21
| | | | | | | | | | | | | | | | | | 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>
* efi_loader: support all uclasses in device pathHeinrich Schuchardt2023-07-201-31/+25
| | | | | | | | | | | | | | | | 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>
* efi_loader: fix dp_fill() for BLKMAP, HOST, VIRTIOHeinrich Schuchardt2023-07-201-9/+3
| | | | | | | | | | | 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>
* efi_loader: check return value of part_get_info()Heinrich Schuchardt2023-06-021-1/+6
| | | | | | | | 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>
* efi_loader: fix efi_dp_from_file()Heinrich Schuchardt2023-05-131-28/+11
| | | | | | | | | | | | * 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>
* efi_loader: simplify efi_dp_from_name()Heinrich Schuchardt2023-05-131-10/+8
| | | | | | Don't do the same check and assignment in multiple places. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
* efi_loader: error code efi_dp_from_name()Heinrich Schuchardt2023-05-131-1/+1
| | | | | | Use EFI_OUT_OF_RESOURCES if the device path cannot be constructed. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
* efi_loader: clean up efi_dp_from_fileHeinrich Schuchardt2023-05-131-7/+9
| | | | | | | | * 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>
* efi_loader: duplicate code in efi_dp_from_nameHeinrich Schuchardt2023-05-131-13/+1
| | | | | | | 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>
* efi_loader: avoid #ifdef in efi_dp_from_name()Heinrich Schuchardt2023-05-131-12/+8
| | | | | | | | | 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>
* efi_loader: support booting semihosting fileHeinrich Schuchardt2023-05-131-1/+2
| | | | | | | | | | | | 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>
* efi_loader: device_path: support blkmap devicesTobias Waldekranz2023-04-051-0/+30
| | | | | | | 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>
* Merge branch 'next'Tom Rini2023-04-031-27/+13
|\ | | | | | | Signed-off-by: Tom Rini <trini@konsulko.com>
| * efi_loader: move dp_alloc() to efi_alloc()Heinrich Schuchardt2023-03-251-27/+13
| | | | | | | | | | | | | | | | | | | | 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>
| * efi_loader: fix device-path for USB devicesHeinrich Schuchardt2023-03-251-12/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | efi_loader: remove duplicate assignmentHeinrich Schuchardt2023-04-011-1/+1
| | | | | | | | | | | | | | | | 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>
* | efi_loader: correct shortening of device-pathsHeinrich Schuchardt2023-04-011-15/+6
| | | | | | | | | | | | | | | | | | | | | | 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>
* | efi_loader: fix device-path for USB devicesHeinrich Schuchardt2023-03-251-12/+33
|/ | | | | | | | | | | | | | | | | 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>
* dm: sandbox: Switch over to using the new host uclassSimon Glass2022-11-071-3/+2
| | | | | | | | | | | | | | | | | 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>
* efi_loader: Let networking support depend on NETDEVICESJan Kiszka2022-11-061-3/+3
| | | | | | | | | | | 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>
* efi_loader: efi_dp_part_node check dp_alloc return valueHeinrich Schuchardt2022-10-061-1/+2
| | | | | | | 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>
* efi_loader: expose END device path nodeMasahisa Kojima2022-07-131-1/+1
| | | | | | | 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>
* cmd: load: add load command for memory mappedRui Miguel Silva2022-06-221-0/+9
| | | | | | | | | | | | | | | | | 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>
* efi_loader: create boot options without file pathHeinrich Schuchardt2022-06-121-9/+24
| | | | | | | | | 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>
* efi_loader: PARTITION_UUIDS should be optionalAKASHI Takahiro2022-04-231-2/+7
| | | | | | | | | | 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>
* efi_loader: typo devie-pathHeinrich Schuchardt2022-03-261-1/+1
| | | | | | | %s/devie-path/device-path/ Reported-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
* efi_loader: efi_dp_find_obj() add protocol checkHeinrich Schuchardt2022-03-201-7/+16
| | | | | | | 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>
* efi_loader: fix efi_dp_find_obj()Heinrich Schuchardt2022-03-201-49/+61
| | | | | | | 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>
* efi_loader: export efi_dp_shorten()Heinrich Schuchardt2022-03-201-8/+13
| | | | | | Rename function shorten_path() to efi_dp_shorten() and export it. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
* efi: Drop unnecessary calls to blk_find_device()Simon Glass2022-02-051-12/+2
| | | | | | | | 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>
* efi: Use device_get_uclass_id() where appropriateSimon Glass2022-02-051-5/+5
| | | | | | | | | | | Use this function rather than following the pointers, since it is there for this purpose. Add the uclass name to the debug call at the end of dp_fill() since it is quite useful. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* doc: replace @return by Return:Heinrich Schuchardt2022-01-191-3/+3
| | | | | | | | | | | | Sphinx expects Return: and not @return to indicate a return value. find . -name '*.c' -exec \ sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \; find . -name '*.h' -exec \ sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \; Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
* efi_loader: add UEFI GPT measurementMasahisa Kojima2021-10-261-0/+27
| | | | | | | | This commit adds the UEFI GPT disk partition topology measurement required in TCG PC Client Platform Firmware Profile Specification Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
* efi_loader: efi_dp_from_lo() should skip VenMedia nodeHeinrich Schuchardt2021-10-211-1/+1
| | | | | | | | | | | The 'efidebug boot dump' command should not display the VenMedia() device path node preceding the device path of the initial ram disk. By letting efi_dp_from_lo() skip the VenMedia() device path node we can simplify the coding. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
* efi_loader: efi_dp_from_lo() unused parameter sizeHeinrich Schuchardt2021-10-211-2/+0
| | | | | | | Parameter size is never used in function efi_dp_from_lo(). Remove it. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
* efi_loader: efi_dp_from_lo() don't copy GUIDHeinrich Schuchardt2021-10-211-2/+3
| | | | | | | Instead of copying a GUID and then using a pointer to the copy for calling guidcmp(), just pass the pointer to the orginal GUID. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: Drop code that doesn't work with driver modelSimon Glass2021-10-211-75/+21
| | | | | | | | | | | | | This code should never have been added as it builds a new feature on top of legacy code. This has already been improved with the dependency on BLK. Add a dependency on DM_ETH also, to avoid needing to deal with this old code. Boards which want EFI_LOADER should migrate to driver model first. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: use EfiBootServicesData for device pathHeinrich Schuchardt2021-08-171-1/+1
| | | | | | | dp_alloc() was using a constant from the wrong enum resulting in creating device paths in EfiReservedMemory. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
* efi_loader: set partition GUID in device path for SIG_TYPE_GUIDAlfonso Sánchez-Beato2021-07-181-2/+8
| | | | | | | | | | | Previously, the GPT device GUID was being used instead of the partition, which was incorrect. Signed-off-by: Alfonso Sánchez-Beato <alfonso.sanchez-beato@canonical.com> Let EFI_LOADER select CONFIG_PARTITION_UUIDS. Use log_warning() instead of printf() for warning. Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
* efi_loader: path length in efi_dp_from_name()Heinrich Schuchardt2021-05-251-2/+7
| | | | | | | | | | Before this patch efi_dp_from_name() only accommodated a maximum file path length of 31 characters. This leads to boot failures due to file name truncation. Allow arbitrary path lengths. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: Add device path related functions for initrd via Boot####Ilias Apalodimas2021-03-251-5/+105
| | | | | | | | | | | | | | | On the following patches we allow for an initrd path to be stored in Boot#### variables. Specifically we encode in the FIlePathList[] of the EFI_LOAD_OPTIONS for each Boot#### variable. The FilePathList[] array looks like this: kernel - 0xff - VenMedia(initrd GUID) - initrd1 - 0x01 initrd2 - 0xff So let's add the relevant functions to concatenate and retrieve a device path based on a Vendor GUID. Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> Reformat function descriptions. Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: Uart device pathHeinrich Schuchardt2021-03-251-9/+32
| | | | | | | | | | When uploading an EFI binary via the UART we need to assign a device path. * Provide devicepath node to text conversion for Uart() node. * Provide function to create Uart() device path. * Add UART support to efi_dp_from_name(). Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* dm: Use access methods for dev/uclass private dataSimon Glass2021-01-051-1/+1
| | | | | | | | | | | Most drivers use these access methods but a few do not. Update them. In some cases the access is not permitted, so mark those with a FIXME tag for the maintainer to check. Signed-off-by: Simon Glass <sjg@chromium.org> Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Acked-by: Pratyush Yadav <p.yadav@ti.com>
* dm: Avoid accessing seq directlySimon Glass2020-12-181-2/+2
| | | | | | | | | | At present various drivers etc. access the device's 'seq' member directly. This makes it harder to change the meaning of that member. Change access to go through a function instead. The drivers/i2c/lpc32xx_i2c.c file is left unchanged for now. Signed-off-by: Simon Glass <sjg@chromium.org>
* dm: treewide: Rename 'platdata' variables to just 'plat'Simon Glass2020-12-131-7/+7
| | | | | | | | | | We use 'priv' for private data but often use 'platdata' for platform data. We can't really use 'pdata' since that is ambiguous (it could mean private or platform data). Rename some of the latter variables to end with 'plat' for consistency. Signed-off-by: Simon Glass <sjg@chromium.org>
* efi_loader: efi_dp_check_length()Heinrich Schuchardt2020-08-241-0/+33
| | | | | | | | | | We need to check that device paths provided via UEFI variables are not malformed. Provide function efi_dp_check_length() to check if a device path has an end node within a given number of bytes. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>