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