Commit Graph

94 Commits

Author SHA1 Message Date
Simon Glass
2b8858b779 efi: Move loaded-image, fs and device-path GUIDs to common
Allow these to be used from the app, when EFI_LOADER is disabled.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-09-02 06:41:32 -06:00
Simon Glass
a815b91b97 efi: Allow inclusion of EFI-runtime headers
Some headers use the __efi_runtime macro in their declarations. With the
app we do not have a separate runtime sections, so define this to be
empty. This allows the headers to be included from the app.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-09-02 06:41:32 -06:00
Simon Glass
eb85d76a42 efi: Provide a way to sync EFI reserved-memory to fdt
When booting Linux with EFI the devicetree memory-map is ignored and
Linux calls through EFI to obtain the real memory map.

When booting Linux from the EFI app, without EFI, we must pass the
reserved memory onto Linux using the devicetree.

Add a function to support this. It reads the EFI memory-map and adds any
missing regions to the reserved-memory node.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-28 07:00:55 -06:00
Simon Glass
a945ee1098 efi: Add an efi subcommand to show the loaded image
Sometimes it is useful to see the device-path of the app itself. Add a
new 'efi image' command for this.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-28 06:55:49 -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
f73b3aaab8 efi: Use abuf when reading EFI variables
The abuf interface provides a nicer abstraction of the data and size of
EFI variables.

Create a new efi_read_var() function and export it so it can be used
elsewhere. Adjust the existing efi_dump_single_var() to use it.

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
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
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
c8c34fba1c efi: app: Use the same efi_free_pool() signature as loader
The app has a function of this name, but it does not return any value.
Return success (always) so that we can use the same signature.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-20 09:05:49 -06:00
Simon Glass
16ed1a82ab efi: app: Find the device-path-to-text protocol on startup
Some protocols are generally useful for the app and it makes sense to
store these in the priv struct rather than requesting them each time
they are needed.

Add a new function which locates the device-path-to-text protocol and
stores it.

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
7cc4e9b062 efi: app: Provide easy access to runtime services
Add a function which allows the app to obtain the runtime services
without first obtaining the priv data.

Make use of this in efi_vars.c

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-20 09:05:49 -06:00
Simon Glass
10e31d38f8 efi: Exit EFI boot-services before starting the next app
When the app is booting a kernel without using EFI, it must first exit
the boot services provided by EFI. Add a hook for this, using
bootm_final()

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-14 07:45:25 -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
bd5194356b efi: Move efi_store_memory_map() to the stub
This function is not called from the app at present. Even if it were, it
would be called later, after stdio is working, so there is no need to
use printhex2() and the like.

Move the function into the stub.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-12 13:41:07 -06:00
Simon Glass
75bf1ee3c5 efi_client: Allow access to the parent image
This value is useful when running a binary, so provide a function to
obtain it.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-08 16:59:11 -06:00
Simon Glass
3d81bf9ac0 efi_loader: Split out efi_binary_run_dp() et all
efi_binary_run_dp() calls efi_init_obj_list() which is specific to the
EFI loader. Move this into a new file within lib/efi_loader

Similarly, move efi_run_image() since the app will need a different
implementation.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-08 16:59:10 -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
5ce96f0139 efi: Move EFI_FDT_USE_INTERNAL to a common header
Move this constant to the efi.h header so that it can be used by the
app.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-08 16:59:10 -06:00
Simon Glass
cf92622d07 efi: Move x86 over to use the common efi_main() function
Fill in the required helper functions and call efi_main_common() to
do everything else.

Delete the old efi_main() function.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-30 14:28:08 -06:00
Simon Glass
c0c2b1237e efi: Create a common efi_main() implementation for the stub
At present x86 and ARM have different implementations, but they are
similar enough that it is not too hard to unify them.

Create a new common function, with arch-specific pieces at the start
(setting up the address to which to copy U-Boot) and end (to jump to
U-Boot).

For now, nothing uses this code.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-30 14:27:53 -06:00
Simon Glass
d43aab19fb efi: Create a common file for the stub
There is some duplicated code across x86 and ARM even though they have
slightly different implementations.

They both call efi_stub_exit_boot_services() and this function does not
relate to the app, so belongs better outside the general-purpose efi.c
file.

Create a new efi_stub C file containing this function. Leave out the
efi_ prefix since this is obvious from the directory name.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-30 14:26:34 -06:00
Heinrich Schuchardt
b5b8d970ad cmd: efidebug: update output of memory attributes
* add EFI_MEMORY_CPU_CRYPTO, EFI_MEMORY_HOT_PLUGGABLE
* correct output for EFI_MEMORY_XP
* remove duplicate list entry for EFI_MEMORY_UC

Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2025-05-16 13:59:37 +02:00
Simon Glass
1cdebf7d8f efi: Avoid including net.h unless necessary
When exfat is enabled this causes linux/byteorder to be included:

In file included from include/linux/byteorder/little_endian.h:107,
                 from arch/sandbox/include/asm/byteorder.h:19,
                 from include/net-legacy.h:16,
                 from include/net.h:11,
                 from include/efi.h:23,
                 from include/blk.h:12,
                 from include/part.h:9,
                 from include/fs_internal.h:11,
                 from fs/exfat/io.c:50:

Fix it by only added the net.h include for the EFI app, which is the
only user. The EFI app is highly unlikely to make use of exfat in any
case. If it does, we could refactor net.h to separate the struct
definitions from the functions, perhaps.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-05-01 05:56:48 -06: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
Simon Glass
9224c73471 efi_loader: Add support for logging EFI calls
The current logging system suffers from some disadvantages, mainly that
it writes its output to the console and cannot be easily reviewed.

Add a dedicated log, storing records in a binary format and including
the result codes and any return values from each call. The log is built
sequentially in memory and can be reviewed after any EFI operation. It
could potentially be written to media for later review, but that is not
implemented so far.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-18 19:47:44 -07:00
Simon Glass
3f2cb29c8a efi_loader: Fix typos in enum efi_allocate_type
Fix 'indicatged' and 'adress' typos.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Tom Rini <trini@konsulko.com>
2024-12-17 10:58:19 -07:00
Simon Glass
aa7ec78ed7 efi: Define fields in struct efi_mem_desc
There is quite a bit of confusion in the EFI code as to whether a field
contains an address or a pointer. As a first step towards resolving
this, document the memory-descriptor struct, indicating that it holds
pointers, not addresses.

Dro the same for efi_add_memory_map() as it is widely used, as well as
efi_add_memory_map_pg() which is only used by lmb

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-17 10:58:19 -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
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
Simon Glass
7506c15669 sandbox: Report host default-filename in native mode
When the --native flag is given, pretend to be running the host
architecture rather than sandbox.

Allow the same control for PXE too.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-11-09 10:01:47 +01:00
Simon Glass
8aa8a33661 efi_loader: Move get_efi_pxe_arch() to efi_helper
Move this function from the EFI bootmeth to the common efi_helper file.
No functional change is intended.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-11-09 10:01:46 +01:00
Simon Glass
9fd623afed efi: Move default filename to a function
Use a function to obtain the device EFI filename, so that we can control
how sandbox behaves.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-11-09 10:00:38 +01:00
Caleb Connolly
3cc3bc08f4 efi: define struct efi_guid
This let's us forward declare efi_guid_t in the UUID code without
pulling in efi.h

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
Vincent Stehlé
0a1bf35f5f efi: move guid helper functions to efi.h
Move the guidcmp() and guidcpy() functions to efi.h, near the definition of
the efi_guid_t type those functions deal with.

Signed-off-by: Vincent Stehlé <vincent.stehle@arm.com>
Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>
Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: Tom Rini <trini@konsulko.com>
2024-07-16 17:09:33 -06:00
Heinrich Schuchardt
e0fa2cf39c efi_loader: handle EFI_VARIABLE_ENHANCED_AUTHENTICATED_ACCESS
We don't yet support EFI_VARIABLE_ENHANCED_AUTHENTICATED_ACCESS for file
based variables, but we should pass it to TEE based variable stores.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2024-04-08 13:03:34 +02:00
Heinrich Schuchardt
19327c1f90 efi_loader: all variable attributes are 32bit
GetVariable() and SetVariable() use an uint32_t value for attributes.
The UEFI specification defines the related constants as 32bit.

Add the missing EFI_VARIABLE_ENHANCED_AUTHENTICATED_ACCESS constant.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2024-04-08 13:03:11 +02:00
Simon Glass
041840eeeb efi: Split out table-listing code into a new file
This code is used with EFI_LOADER but is also useful (with some
modifications) for the EFI app and payload. Move it into a shared
file.

Show the address of the table so it can be examined if needed. Also show
the table name as unknown if necessary. Our list of GUIDs is fairly
small.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-03-25 11:07:22 +01:00
Heinrich Schuchardt
92b931b8ef efi_loader: move struct efi_device_path to efi.h
Avoid forward declaration of struct efi_device_path.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2023-03-25 11:06:03 +01:00
Masahisa Kojima
1dd705cf99 efi: use 32-bit alignment for efi_guid_t
Current U-Boot implements 64-bit boundary for efi_guid_t structure.
It follows the UEFI specification, page 21 of the UEFI Specification v2.10
says about EFI_GUID:
  128-bit buffer containing a unique identifier value. Unless
  otherwise specified, aligned on a 64-bit boundary.

On the other hand, page 163 of the UEFI specification v2.10 and
EDK2 reference implementation both define EFI_GUID as
struct { u32 a; u16; b; u16 c; u8 d[8]; }; and so the implied
alignment is 32-bit not 64-bit like U-Boot efi_guid_t.

Due to this alignment difference, EDK2 application "CapsuleApp.efi -P"
does not work as expected.
This calls EFI_FIRMWARE_MANAGEMENT_PROTOCOL.GetImageInfo()
and dump the EFI_FIRMWARE_IMAGE_DESCRIPTOR structure,
offsetof(EFI_FIRMWARE_IMAGE_DESCRIPTOR, ImageTypeId) is different,
8 in U-Boot and 4 in EDK2(CapsuleApp.efi).
Here is the wrong EFI_GUID dump.
  wrong dump : ImageTypeId - 00000000-7D83-058B-D550-474CA19560D8
  expected   : ImageTypeId - 058B7D83-50D5-4C47-A195-60D86AD341C4

EFI_FIRMWARE_IMAGE_DESCRIPTOR structure is defined in UEFI specification:
  typedef struct {
          UINT8 ImageIndex;
          EFI_GUID ImageTypeId;
          UINT64 ImageId
          <snip>

  } EFI_FIRMWARE_IMAGE_DESCRIPTOR;

There was the relevant patch for linux kernel to use 32-bit alignment
for efi_guid_t [1].
U-Boot should get aligned to EDK2 reference implementation and
linux kernel.

Due to this alignment change, efi_hii_ref structure in include/efi_api.h
is affected, but it is not used in the current U-Boot code.

[1] https://lore.kernel.org/all/20190202094119.13230-5-ard.biesheuvel@linaro.org/

Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2023-02-10 13:05:39 +01:00
Ilias Apalodimas
05c4c9e21a efi_loader: define internal implementations of install/uninstallmultiple
A following patch is cleaning up the core EFI code trying to remove
sequences of efi_create_handle, efi_add_protocol.

Although this works fine there's a problem with the latter since it is
usually combined with efi_delete_handle() which blindly removes all
protocols on a handle and deletes the handle.  We should try to adhere to
the EFI spec which only deletes a handle if the last instance of a protocol
has been removed.  Another problem is that efi_delete_handle() never checks
for opened protocols,  but the EFI spec defines that the caller is
responsible for ensuring that there are no references to a protocol
interface that is going to be removed.

So let's fix this by replacing all callsites of
efi_create_handle(), efi_add_protocol() , efi_delete_handle() with
Install/UninstallMultipleProtocol.

In order to do that redefine functions that can be used by the U-Boot
proper internally and add '_ext' variants that will be used from the
EFI API

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2022-10-06 22:54:58 +02:00
Simon Glass
6b3873c5ea efi: Tidy up some comments in efi header
Document the return value in efi_init(). Fix up @sizep in efi_info_get().
Use Return: instead of @return

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2022-01-15 10:57:22 +01:00
Simon Glass
25a326b006 efi: Support the efi command in the app
At present the 'efi' command only works in the EFI payload. Update it to
work in the app too, so the memory map can be examined.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2022-01-15 10:57:22 +01:00
Simon Glass
ce1dc0cc17 x86: efi: Update efi_get_next_mem_desc() to avoid needing a map
At present this function requires a pointer to struct efi_entry_memmap
but the only field used in there is the desc_size. We want to be able
to use it from the app, so update it to use desc_size directly.

Signed-off-by: Simon Glass <sjg@chromium.org>
2022-01-15 10:57:22 +01:00
Simon Glass
866e2ac5aa efi: Move exit_boot_services into a function
At present this code is inline in the app and stub. But they do the same
thing. The difference is that the stub does it immediately and the app
doesn't want to do it until the end (when it boots a kernel) or not at
all, if returning to UEFI.

Move it into a function so it can be called as needed.

Add a comment showing how to store the memory map so that it can be
accessed within the app if needed, for debugging purposes only. The map
can change without notice.

Signed-off-by: Simon Glass <sjg@chromium.org>
2022-01-15 10:57:22 +01:00