Commit Graph

3711 Commits

Author SHA1 Message Date
Simon Glass
65091e5d24 efi_loader: Test that active-DMA devices are removed
When exit-boot-services is called, active devices should be removed.

Update testapp to call this method and check that the USB controller is
removed as expected.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-01-30 13:05:19 -07:00
Simon Glass
b5cd469c34 efi_loader: Update testapp to get memory map correctly
Allocate enough memory for the memory map so that it can be received
successfully.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-01-30 13:05:19 -07:00
Simon Glass
911b75d77d efi_loader: Correct bounce-buffer setup
This should set the bounce buffer to a pointer, not an address. Fix it.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-01-30 13:05:19 -07:00
Simon Glass
c0bc39f924 efi_loader: Return the memory map in pointer format
An EFI app expects pointers to be returned, cast to u64. The conversion
to use addresses missed this, so fix the call.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-01-30 13:05:18 -07:00
Simon Glass
1c43924b3f efi_loader: Fix display of addresses in log
The allocate/free-pages functions return an address, so there is no need
to convert it. Fix this.

Signed-off-by: Simon Glass <sjg@chromium.org>
Fixes: c824a96d76 ("efi_loader: Use the log with memory-related...")
2025-01-30 13:05:18 -07:00
Simon Glass
94757bfb0a hash: Plumb crc8 into the hash functions
Add an entry for crc8, with watchdog handling.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>
2025-01-08 10:07:26 -07:00
Simon Glass
6392a4be41 lib: Allow crc8 in TPL and VPL
Provide options to enable the CRC8 feature in TPL and VPL builds.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-01-08 10:07:26 -07:00
Simon Glass
543ca1278d spl: lib: Allow for decompression in any SPL build
Add Kconfig symbols and update the Makefile rules so that decompression
can be used in TPL and VPL

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-01-08 10:07:26 -07:00
Simon Glass
c824a96d76 efi_loader: Use the log with memory-related functions
Update a few memory functions to log their inputs and outputs. To avoid
the use of 'goto', etc. the functions are turned into stubs, calling a
separate function to do the actual operation.

Add a few tests.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-18 19:50:32 -07:00
Simon Glass
b9dcd6fde2 test: efi_loader: Add a simple test for the EFI log
Create a test which does some sample calls and checks the output.

Expand the size of the sandbox bloblist to accommodate the log.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-18 19:48:05 -07:00
Simon Glass
c965933395 efi_loader: Create the log on startup
Create an EFI log when the EFI subsystem is first touched. This happens
after relocation in board_init_f()

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-18 19:47:44 -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
eb83a008aa efi_loader: Fix free in ..._media_device_boot_option()
Freeing a NULL pointer is an error in EFI, so check the pointer first,
before freeing it.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-18 19:47:44 -07:00
Simon Glass
102af0d5f3 bootmeth_efi: Support PXE booting
Finish off the implementation so it is possible to boot an EFI app over
a network.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-18 16:51:29 -07:00
Simon Glass
87eced2863 efi_loader: Pass in the required parameters from EFI bootmeth
Rather than setting up the global variables and then making the call,
pass them into function directly. This cleans up the code and makes it
all a bit easier to understand.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-18 16:51:28 -07:00
Simon Glass
ad5f691ede efi_loader: Move the fallback code from efi_run_image()
This code is only needed if an invalid image/device path is passed in.
Move the code out to a caller where this can be dealt with. The normal
flow will provide these parameters.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-18 16:51:17 -07:00
Simon Glass
37aad645e4 efi_loader: Add a version of efi_binary_run() with more parameters
This uses a few global variables at present. With the bootflow we have
the required parameters, so add a function which accepts these. Update
the existing function to call the new one with the globals.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-18 16:50:59 -07:00
Simon Glass
c5db9e4ca7 efi_loader: Update efi_run_image() to accept image and device path
Provide these globals as parameters to this function, on the way to
making it possible to start an image without relying on the globals.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2024-12-18 16:50:59 -07:00
Simon Glass
f371642341 efi_loader: Make efi_run_image() static
This function is not called from outside this file and has no entry in
the header file, so mark it static.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2024-12-18 16:50:59 -07:00
Simon Glass
86a5352a14 efi_loader: Refactor device and image paths into a function
Move this code into a function so it can be called from elsewhere.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-18 16:50:59 -07:00
Simon Glass
43104a2100 fdt: Swap the signature for board_fdt_blob_setup()
This returns a devicetree and updates a parameter with an error code.
Swap it, since this fits better with the way U-Boot normally works. It
also (more easily) allows leaving the existing pointer unchanged.

No yaks were harmed in this change, but there is a very small code-size
reduction.

For sifive, the OF_BOARD option must be set for the function to be
called, so there is no point in checking it again. Also OF_SEPARATE is
defined always.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Matthias Brugger <mbrugger@suse.com>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
2024-12-17 17:30:25 -07:00
Simon Glass
d93fd416c3 efi_loader: Simplify efi_dp_from_mem()
This function should take a pointer, not an address. Update it along
with all users.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-17 10:59:09 -07:00
Simon Glass
a92beb14c9 efi_bootmgr: Avoid casts in try_load_from_uri_path()
Update this function to use map_sysmem() so that it can work correctly
on sandbox

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-17 10:59:09 -07:00
Simon Glass
ad0c01de70 efi_loader: Drop comments about incorrect addresses
Now that these problems have been resolved, drop the comments.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-17 10:59:09 -07:00
Simon Glass
887013b0ca efi_loader: Correct address-usage in copy_fdt()
Update this function to work correctly with sandbox

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-17 10:59:09 -07:00
Simon Glass
448ef82da3 efi_loader: Update to use addresses internally
This collects together several v3 patches into one, to avoid any
temporary test-breakage which would make future bisecting difficult.

For efi_memory, the efi_allocate_pool() call uses a pointer to refer to
memory, but efi_allocate_pages() uses an int. This causes quite a bit of
confusion, since sandbox has a distinction between pointers and
addresses. Adjust efi_allocate/free_pages_ext() to handle the
conversions.

Update efi_add_memory_map() function and its friend to use an address
rather than a pointer cast to an integer.

For lmb, now that efi_add_memory_map_pg() uses a address rather than a
pointer cast to an int, we can simplify the code here.

For efi_reserve_memory(), use addresses rather than pointers, so that it
doesn't have to use mapmem.

In general this simplifies the code, but the main benefit is that casts
are no-longer needed in most places, so the compiler can check that we
are doing the right thing.

For efi_add_runtime_mmio(), now that efi_add_memory_map() takes an
address rather than a pointer, do the mapping in this function.

Update the memset() parameter to be a char while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-17 10:59:08 -07:00
Simon Glass
eb0c02d5e3 efi_loader: Don't try to add sandbox runtime code
This cannot work since the code is not present in the emulated memory.
In any case, sandbox cannot make use of the runtime code.

For now, just drop it from sandbox. We can always adjust things to copy
it into memory, if needed.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-17 10:58:19 -07:00
Simon Glass
1238b0bb80 efi_loader: Show the address for pool allocations
When logging pool allocations, show the address of the pointer, not the
pointer itself. This makes it easier to debug with sandbox

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-17 10:58:19 -07:00
Simon Glass
183027892e efi_loader: Use correct type in efi_add_runtime_mmio()
This function is passed the address of a void * so update the argument
to match. It is better to have casts in the caller than introduce
confusion as to what is passed in.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-17 10:58:19 -07:00
Simon Glass
192f48da42 efi_loader: Rename physical_start to base
The word 'physical' suggests that there is an associated virtual address
but there is not. Use 'base' since this is the base address of a region.

Change some uint64_t and remove some brackets to keep checkpatch happy.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-17 10:58:19 -07:00
Simon Glass
58c6e4d0b3 efi_loader: Rename struct efi_mem_list to mem_node
This struct is really a node in the list, not a list itself. Also it
doesn't need an efi_ prefix. Rename it.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-17 10:58:19 -07:00
Simon Glass
764b9ae523 efi_loader: Move struct efi_mem_list fields together
We don't need a separate struct for the values in this node. Move
everything in together, so that there is just one struct to consider.

Add a comment about physical_start, so it is clear that it is really
a pointer.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-17 10:58:19 -07:00
Simon Glass
f6f2ccdf34 efi_loader: Avoid assigning desc in efi_mem_carve_out()
Rather than assigning desc and then changing two fields, assign all four
fields, for clarity.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-17 10:58:19 -07:00
Simon Glass
a298d539ba efi_loader: Use the enum for the memory type in priv_mem_desc
We can make use of the enum now, since this struct is not exported to
the EFI app.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-17 10:58:19 -07:00
Simon Glass
deec2674ea efi_loader: Drop reserved from priv_mem_desc
This field is not used. Drop it and set the value to 0 when the
memory-map is requested.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-17 10:58:19 -07:00
Simon Glass
6f771f86aa efi_loader: Drop virtual_start from priv_mem_desc
This field is always the same as physical_start, so keeping track of it
separately is unnecessary and confusing. Drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-17 10:58:19 -07:00
Simon Glass
d25caaca61 efi_loader: Use a separate struct for memory nodes
At present efi_memory uses struct efi_mem_desc for each node of its
memory list. This is convenient but is not ideal, since:

- it means that the fields are under a 'desc' sub-structure
- it includes an unused 'reserved' field
- it includes virtual_start which is confusing as it is always the same
  as physical_start
- we must use u64 to store pointers, since that is how they are returned
  by calls to efi_get_memory_map()

As a first step to tidying this up, create a new, private struct to hold
these fields.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-17 10:58:19 -07:00
Simon Glass
ca2203ca86 efi_loader: Move some memory-function comments to header
Exported functions should be documented in the header file, not the
implementation. We tend to make such updates on a piecemeal basis to
avoid a 'flag day'. Move some comments related to memory allocation to
follow the convention.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-17 10:58:19 -07:00
Simon Glass
d9b45a2d53 efi_loader: Update startimage_exit self-test to check error
Check for an error returned from the decompress() function, just in
case.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2024-12-17 10:58:19 -07:00
Simon Glass
c636e69159 efi_loader: Show the resulting memory address from an alloc
Update efi_allocate_pool_ext() to log the pointer returned from this
call, which can be helpful when debugging.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-17 10:58:19 -07:00
Simon Glass
fb2081fc3b efi_loader: Add comments where incorrect addresses are used
Some functions are passing addresses instead of pointers to the
efi_add_memory_map() function. This confusion is understandable since
the function arguments indicate an address.

Make a note of the 8 places where there are problems, which would break
usage in sandbox tests.

Future work will resolve these problems.

Signed-off-by: Simon Glass <sjg@chromium.org>
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
Simon Glass
2ea15e57a0 sandbox: efi_loader: Correct use of addresses as pointers
The cache-flush function is incorrect which causes a crash in the
remoteproc tests with arm64.

Fix both problems by using map_sysmem() to convert an address to a
pointer and map_to_sysmem() to convert a pointer to an address.

Also update the image-loader's cache-flushing logic.

Signed-off-by: Simon Glass <sjg@chromium.org>
Fixes: 3286d223fd ("sandbox: implement invalidate_icache_all()")
Acked-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

Changes in v6:
- Re-introduce

Changes in v2:
- Drop message about EFI_LOADER

 arch/sandbox/cpu/cache.c              |  8 +++++++-
 drivers/remoteproc/rproc-elf-loader.c | 18 +++++++++++-------
 lib/efi_loader/efi_image_loader.c     |  3 ++-
 3 files changed, 20 insertions(+), 9 deletions(-)
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2024-12-17 06:53:19 -07:00
Simon Glass
e6eed34cc7 efi: Correct logic for OF_EMBED and OF_SEPARATE co-existing
While we do plan to switch to OF_SEPARATE now it is supported, it seems
worth at least showing how OF_EMBED could be used instead, just for the
record.

So make the Makefile rule conditional on OF_SEPARATE and adjust fdtdec
to avoid a build error when OF_EMBED is used.

Finally. the dtb symbol has a double underscore, so update it to avoid a
build warning.

With future patches, OF_EMBED will no-longer be used with the EFI app,
so it is expected that it will eventually stop working.

Signed-off-by: Simon Glass <sjg@chromium.org>
Fixes: 2e7bf25f6b ("Support separate DTB files with the UEFI app")
2024-12-17 05:34:41 -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