Commit Graph

98 Commits

Author SHA1 Message Date
Simon Glass
0f97a71491 efi: Add missing mmc and net checks from device_path
The MMC and network subsystems must be present to use device paths for
them. Add the missing checks.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-12 08:40:05 -07:00
Simon Glass
e7b305014e efi: Add definitions for the absolute-pointer protocol
Add these definitions to the API so that we can make use of this feature
in drivers, etc.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-10-07 09:55:12 -06:00
Simon Glass
4113d6a01c efi: Move key decoding into a shared file
Create a new file in lib/efi to handle conversion of keys from EFI
format to characters, so we can use it from multiple places. Update the
serial_efi driver accordingly.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-09-25 09:47:09 -06:00
Simon Glass
5d802fc523 efi: Add the simple-pointer protocol
Add definitions for the simple-pointer protocol so that it can be used
in drivers.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-09-15 03:26:58 -06:00
Simon Glass
a2759428a9 efi: Correct calculate_paths() when an image is used
The device path is updated if an image is used, so move the setting of
*device_pathp lower, to take account of this.

Signed-off-by: Simon Glass <sjg@chromium.org>
Fixes: 73ad2d9909 ("efi: Move efi_bootflow_run() to a common file")
2025-09-02 06:41:27 -06:00
Simon Glass
27f066d157 efi: Add a command to help with shim
Shim is a program which normally comes before U-Boot in the boot
process. But when the app runs first, it can sometimes chain Shim since
that is what is contained within the bootaa64.efi file, for example.

Add a simple command for dealing with shim. For now it only supports
enabling verbosity.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-28 05:21:49 -06:00
Simon Glass
e6f9a0ae58 boot: Show the device path for EFI bootflows
If the bootflow relates to the EFI bootmeth, show the device path along
with the other info.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-28 05:21:49 -06:00
Simon Glass
af0299b9de efi: Convert a device-path to a uclass and name
Add a function which looks through a device path and tries to figure out
the corresponding name (e.g. 'nvme' and uclass ID. This can be useful
for showing a short summary of the device path.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-27 17:08:45 -06:00
Simon Glass
b0341ef417 efi: Move guid used for variables to common files
Move efi_guid_image_security_database to a common file so that it can be
used by the app.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-22 08:23:17 -06:00
Simon Glass
2e0fab9f72 efi: app: Allow booting an EFI app
Enable booting an app from the U-Boot app, since many distros package
their bootloader as an EFI app.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-20 10:07:17 -06:00
Simon Glass
49d762e7ef efi: Add a little debugging to calculate_paths()
Provide some debugging for when things go wrong.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-20 10:07:17 -06:00
Simon Glass
cea7a888bf efi: Add device-path support for EFI media devices
Add proper device-path handling for UCLASS_EFI_MEDIA devices in both
dp_size() and dp_fill() functions. This enables EFI applications to use
firmware device-paths for media devices accessed through the EFI block
I/O protocol.

Add some debugging while we are here.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-20 10:07:17 -06:00
Simon Glass
2d2b8cff43 efi: Add the component-name2 protocol to efidebug dh
Add the GUID and API for this protocol so that we can use it in the
'efidebug dh' command.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-20 10:07:17 -06:00
Simon Glass
f06ec4fbcd efi: Move driver-binding guid to a common file
Move efi_guid_driver_binding_protocol to lib/efi so that it can be used
from the app.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-20 10:07:17 -06:00
Simon Glass
fc274ee3d0 efi: Move efi_load_option_dp_join() to a common file
This function is useful in the app so move it to the common helper.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-20 09:05:49 -06:00
Simon Glass
c43c1681ee efi: Move efi_string utilities to the common directory
This file contains some useful utility functions which are not specific
to the EFI loader. Move them to lib/efi so they can be used by the app.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-20 09:05:49 -06:00
Simon Glass
fe33f0fbfb efi: app: Implement %pD in the app
This printf() extension is useful for the app. Add an implementation of
efi_dp_str() so that it works as expected.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-20 09:05:49 -06:00
Simon Glass
712bd388ef efi: Move FDT and global-variable GUIDs to common files
The global-variable GUID is already set in the common device_path.c file
but its declaration is only in the efi_loader header.

Move it and also move over the FDT GUIDs.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-20 09:05:49 -06:00
Simon Glass
4500ade27f efi: Move some load-options handling into the common dir
These functions are useful for the app as well as the loader.

For now, efi_set_load_options() calls efi_search_protocol() which is
still in the loader, but we can provide an 'app' version when needed. It
doesn't seem worth keeping that one function in a separate file.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-20 09:05:49 -06:00
Simon Glass
eeaec57199 efi: Move a few helper functions into the common efi/ dir
Checking if a variable is a load option is useful for the app, so move
efi_varname_is_load_option() and u16_tohex() into a new helper.c file.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-20 09:05:49 -06:00
Simon Glass
8bc5cf50ff efi: Update path_uefi() to avoid allowed_unaligned()
This call seems to have been added in an unrelated commit, likely to fix
a bug:

  046fe7b507 ("efi_loader: efi_dp_from_file() expect UTF-8 path")

With standard boot we don't need to call efi_set_bootdev(). Also this
function is not available in the EFI app.

So for now, add a condition, to avoid a build error in the x86 app when
CONFIG_EFI_BINARY_EXEC is enabled.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-20 09:05:49 -06:00
Simon Glass
ddb6d94b03 efi: Add missing break to dp_fill()
While this doesn't really affect anything in practice, it is better to
deal with an incorrect use of this function (calling it with a UCLASS
which is not enabled).

Add a break after the UCLASS_BLK case, to help this.

Signed-off-by: Simon Glass <sjg@chromium.org>
Fixes: a48a8929de ("efi: Move most of efi_device_path into lib/efi")
2025-08-20 09:05:49 -06:00
Simon Glass
6a54b56015 efi: Add missing break statements in dp_size()
The conversion to using a size variable was missing a break statement
for the BLK case. Fix it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Fixes: ffde1a3922 ("efi: Use variables in dp_size()")
2025-08-20 09:05:49 -06:00
Simon Glass
d07934b67e efi: Add a function to obtain the memory type as a string
It is sometimes useful to display the memory type in logs, etc. Add a
function to convert it to a string, which is more user-friendly than a
number.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-14 07:45:25 -06:00
Simon Glass
02e141912b efi: Move memory-map dumping into a common file
The 'efi mem' command dumps out the memory map. This is useful within
the app, even if commands are not enabled, so move it to a common file.
Rename it from 'print' to 'dump' since most things that dump information
use that word.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-14 07:45:25 -06:00
Simon Glass
92aad5b59e efi: Move EFI_BINARY_EXEC to lib/efi
The EFI app will eventually execute binaries, but it does not enable
the CONFIG_EFI_LOADER option. So move the option to a common directory.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-08 16:59:11 -06:00
Simon Glass
28b512bad3 efi_client: Support running an app
Add support for running another app from with the EFI app. This can be
used to boot an OS, for example.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-08 16:59:11 -06:00
Simon Glass
73ad2d9909 efi: Move efi_bootflow_run() to a common file
Move this function and some dependencies into the lib/efi directory so
that it can be used by the app, which does not enable CONFIG_EFI_LOADER

Since the networking has an #ifdef add CONFIG_EFI_LOADER to it, since
the definitions are in efi_loader.h for now.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-08 16:59:10 -06:00
Simon Glass
a48a8929de efi: Move most of efi_device_path into lib/efi
Most of these utility functions are useful for the app, so move them
into the common directory.

Move the GUIDs used by this file from their various other location, so
they are available to the app, even if it doesn't enabled EFI_LOADER

Fix the rather large number of checkpath warnings in this file, except
for the lwip one, best left to the maintainer to sort out.

One noteable change is adding a return value to dp_fill() for the case
where an option is not enabled but its uclass is referenced. This
presuambly never happens during execution, since if the uclass is not
supported there can be no device in that uclass and therefore nothing
will ever request its path. So just handle this like an invalid device.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-08 16:59:10 -06:00
Simon Glass
ed4bb8d982 efi: Move FDT-filename discovery into lib/efi
Move efi_get_distro_fdt_name() into lib/efi so it can be used from the
app.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2025-05-28 08:02:11 +01:00
Simon Glass
0121164bef efi: Adjust copyright and mention constant source
While the file where the basename.c code came from is marked as Linaro
from 2020, commit [1] was based on Heinrich's email. Also, [2] and [3]
were my patches. Linaro is not the copyright holder and none of the code
is from 2020.

Update the file accordingly.

Link: https://lore.kernel.org/u-boot/2175cecb-a392-5107-b932-b099ec21d62c@gmx.de
[1] 4e65ca00f3 ("efi_loader: bootmgr: add booting from removable media")
[2] 3e18860e3f ("bootstd: Allow reading an EFI file from the network")
[3] 7506c15669 ("sandbox: Report host default-filename in native mode")

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2025-05-28 08:02:11 +01:00
Simon Glass
624cdc9228 efi: Move the base name and PXE info into lib/efi
Move efi_get_basename() and efi_get_pxe_arch() into lib/efi so they can
be used from the app.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-05-28 08:02:11 +01:00
Simon Glass
a07abd67da efi: Create a new CONFIG_EFI
Create a Kconfig which indicates that EFI functionality is in use,
either as a client (EFI app / stub) or provider (EFI loader). This will
make it easier to share code between these two parts of U-Boot

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-05-28 08:02:11 +01:00
Simon Glass
5f4327ec9f efi: Rename the lib/efi directory
This directory was created when U-Boot gained the ability to run as an
EFI app in 2015. Since then the EFI-loader feature has been added.

The code in lib/efi is not actually used by the loader, so the name is
confusing.

Rename the directory to efi_client to indicate that it includes files
just for U-Boot being a client of EFI, i.e. the EFI app and stub.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-05-28 08:02:11 +01:00
Simon Glass
483d409aa3 efi: arm: Add an EFI app for arm64
Introduce an EFI app for arm64 and update the documentation.

Provide a value for LOAD_ADDR to avoid a link error.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-03-27 05:31:43 -06:00
Simon Glass
63c52892ec efi: Tidy up setup of global_data
Use the available functions for setting and getting the global_data
pointer so that EFI-startup can operate on 64-bit ARM as well as x86.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-03-27 05:31:43 -06:00
Simon Glass
97b1f411a8 efi: x86: Move EFI SDRAM-handling into a common file
This code is not actually x86-specific, so move it into the lib/efi dir
where other archs can use it.

Drop inclusion of the unnecessary x86-specific header.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
2025-03-27 05:31:43 -06:00
Caleb Connolly
de6dd73b4e efi: stub: add known memory to U-Boot's EFI memory map
When running U-Boot as an EFI payload with CONFIG_EFI_STUB, the reserved
regions from the previous stage EFI bootloader should be carried over
since they may not fully align with the reserved-memory regions in
devicetree.

Implement a helper to map these pages when the EFI subsystem starts up.

Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
2025-02-03 04:46:46 -07:00
Caleb Connolly
8cb8d63b43 efi: stub: log EFI memory banks
Add a debug log for these since its often useful to inspect the memory
map from the EFI we're jumping from.

Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
2025-02-03 04:46:46 -07:00
Caleb Connolly
cef0312def efi: stub: add additional types of memory
U-Boot itself might be mapped as LOADER_CODE, there's also no reason not
to make additional pages accessible to the OS. This fixes an issue where
U-Boot can't run EFI apps because it gets relocated somewhere outside of
its own memory map.

Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
2025-02-03 04:46:46 -07:00
Caleb Connolly
d9d2b8fb71 efi: stub: add helpers to populate memory map and framebuffer
Introduce two new helpers dram_init_banksize_from_efi() and
of_populate_from_efi(). These populate the DRAM bank info and simplefb
framebuffer OF node respectively using the EFI table populated by the
EFI stub.

dram_init_banksize_from_efi() is directly moved from the x86 payload
code to make it available for other boards.

Populating the simplefb node allows for an easy way to bring up video
without the full heft of VIDEO_EFI which is not particularly well-suited
to ARM.

Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
Avoid changing the devicetree with the EFI app; fix build error on x86:
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-03 04:46:45 -07:00
Caleb Connolly
630cb84000 efi: move efi_info_get() to a new header file
Split out the EFI stub specific code to a new efi_stub.h header file.

Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
2025-02-03 04:43:48 -07:00
Caleb Connolly
e0a8bf6f45 efi: stub: support running U-Boot as an EFI payload on ARM64
Implement support for launching U-Boot via an EFI stub app on ARM64.

This is more or less a straight port of the x86 implementation, but due
to the highly x86/qemu specific nature of that implementation I decided
to just split it out to its own file.

Unlike the x86 implementation, there is no debug UART here since ARM
platforms don't have a standard UART interface. However it is usually
possible to port over the debug uart implementation for you platform for
bringup purposes.

Currently this implementation doesn't provide a DTB to U-Boot and
expects U-Boot to use a built-in one, however this ought to be a fairly
trivial addition in the future.

The other significant difference to the x86 version is that rather than
copying U-Boot to CONFIG_TEXT_OFFSET, we require that U-Boot is built
position independent and copy it to EFI allocated memory.

Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
2025-02-03 04:43:48 -07:00
Janis Danisevskis
de05434022 Fix efi_bind_block.
efi_bind_block had two issues.
1. A pointer to a the stack was inserted as plat structure and thus used
beyond its life time.
2. Only the first segment of the device path was copied into the
platfom data structure resulting in an unterminated device path.

Signed-off-by: Janis Danisevskis <jdanisevskis@aurora.tech>
Signed-off-by: Matthew Garrett <mgarrett@aurora.tech>
Reviewed-by: Simon Glass <sjg@chromium.org>
2024-12-08 07:44:33 -07:00
Matthew Garrett
2e7bf25f6b Support separate DTB files with the UEFI app
The UEFI app is an actual executable with things like section headers,
so just gluing the DTB onto the end of it won't work. Add an additional
section to contain this and allocate some space, and then during build
copy the DTB into that section.

Signed-off-by: Matthew Garrett <mgarrett@aurora.tech>
Reviewed-by: Simon Glass <sjg@chromium.org>
2024-12-08 07:44:33 -07:00
Matthew Garrett
f07b9497ba Add UEFI TPM2 driver
Add support for driving a TPM via UEFI firmware provided drivers, and
bind those devices from the UEFI app.

Signed-off-by: Matthew Garrett <mgarrett@aurora.tech>
Reviewed-by: Simon Glass <sjg@chromium.org>
2024-12-08 07:44:33 -07:00
Matthew Garrett
4bb984a205 Add EFI network driver
Add a driver that makes use of the UEFI Simple Network Protocol to
support network access when using the UEFI app implementation, and hook
up the app code to instantiate it for probed devices.

Signed-off-by: Matthew Garrett <mgarrett@aurora.tech>
Reviewed-by: Simon Glass <sjg@chromium.org>
Add include of linux/ctype in epautoconf.c and conditional net.h:
Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-08 07:44:21 -07:00
Matthew Garrett
d4aa4b64d4 Hook up EFI env variable support in the EFI app
Add simple support for accessing EFI variables when in EFI app mode

Signed-off-by: Matthew Garrett <mgarrett@aurora.tech>
Reviewed-by: Simon Glass <sjg@chromium.org>
2024-12-07 17:53:09 -07:00
Matthew Garrett
9121737455 Add EFI handover support to bootm
We want to jump into the EFI stub in the kernel so it can perform
appropriate init and call ExitBootServices. Add support for doing that,
including ensuring that we copy the kernel to somewhere that's not
currently being used by the firmware.

Signed-off-by: Matthew Garrett <mgarrett@aurora.tech>
Reviewed-by: Simon Glass <sjg@chromium.org>
Drop use of image_info_t:
Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-07 17:52:59 -07:00
Caleb Connolly
58d825fb18 include: export uuid.h
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-09-12 17:35:37 +02:00