Commit Graph

101 Commits

Author SHA1 Message Date
Simon Glass
5ea9e69b82 efi: Add a flag to enable ulib
When running as an EFI app we should set the ulib flag early so as to
avoid printing unwanted output on start. Add a parameter to
efi_startup() to control whether ulib is used.

Drop the starting message in this case.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-12 08:40:05 -07:00
Simon Glass
dc475d0c11 efi: Allow init messages to be optional
Add a 'verbose' argument to efi_init() so that the init messages can be
suppressed if desired.

For now, keep them as they are.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-12 08:40:05 -07:00
Simon Glass
89611203f0 efi: Use EVT_RESERVE_BOARD to reserve memory for efi_priv
Use the EVT_RESERVE_BOARD event handler to allocate the efi_priv struct
in the normal memory area. This avoids the caller needing to keep it on
the stack.

Copy the struct to the new place and start using it there.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-12 08:40:05 -07:00
Simon Glass
7477fe4d9b efi: Allow excluding efi_main()
In some cases this function may be provided outside the library, e.g. by
a Rust main program. Add a Kconfig to control this and refactor the code
so that it is optional.

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
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