Commit Graph

54 Commits

Author SHA1 Message Date
Simon Glass
f74db7258c sysreset: Add -c flag for explicit cold reset
Add support for reset -c flag to explicitly request cold reset.
This provides symmetry with -w (warm) and -u (firmware UI) flags.

For EFI apps, this performs EFI_RESET_COLD which does a full system
reboot without going to firmware setup interface.

Series-to: concept
Series-cc: heinrich
Cover-letter:
efi: Improve integration of the app with a Shim environment
This series collects together various small fixes and improvements which
make it easier to use the U-Boot EFI app in a bootflow which includes
Shim:

- 'Reset' back to the caller (e.g. EDK2)
- Machine reset using cold and warm reset
- Reset and enter the firmware UI
- Shim command now supports persistent debug
- Bootmenu shows the real media for each bootflow rather than just 'efi'
END

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-09-02 08:51:40 -06:00
Simon Glass
96adc477be sysreset: Add SYSRESET_TO_FIRMWARE_UI with reset -u support
Add new SYSRESET_TO_FIRMWARE_UI reset type to allow resetting directly
to firmware UI. This is implemented via the reset command's new -u flag.

For the EFI app, this sets the EFI_OS_INDICATIONS_BOOT_TO_FW_UI bit in
the OsIndications variable before performing a warm reset, causing the
firmware to boot to its setup interface.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-09-02 08:51:26 -06:00
Simon Glass
1ad04a7895 efi: app: Support proper reset options
At present reset just exits the U-Boot app and returns to the caller.
Add support for proper warm and cold resets, with 'hot' reset preserving
the current behaviour.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-09-02 08:51:26 -06:00
Simon Glass
b304fb16d7 efi: Use the console mux by default with the EFI app
It is handy to have the pager in the app, since some output can be quite
long. Enable the console mux since the pager feature depends on it.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-09-02 08:45:36 -06:00
Simon Glass
fe127667dc efi: Set the log category throughout lib/efi_client/
All files in this directory relate to EFI, so set the log category
consistently.

Series-to: concept
Series-cc: heinrich
Cover-letter:
efi: A few minor improvements
This series mostly tidies up the efidebug command, but includes a few
other pieces as well.
END

Signed-off-by: Simon Glass <sjg@chromium.org>
Series-links: 1:20
2025-09-02 06:41:32 -06:00
Simon Glass
56dab05ff1 efi: app: Sync EFI reserved-memory to the devicetree
Obtain EFI's view of reserved memory and ensure that everything
mentioned there is present in a devicetree reserved-memory node. This
ensures that the OS doesn't try to access memory it shouldn't.

Series-to: concept
Series-cc: heinrich
Cover-letter:
efi: App and devicetree improvements

This series improves U-Boot's EFI app support and adds new functionality
for managing devicetree reserved-memory regions.

The main focus is on enhancing memory management when running as an EFI
application. A new mechanism is introduced to sync EFI reserved-memory
regions (such as runtime services and ACPI tables) with the devicetree's
/reserved-memory nodes. This ensures that Linux doesn't inadvertently use
memory regions that EFI firmware has reserved.

The main improvements are:

- New 'fdt reserved' command to display devicetree reserved-memory regions
- New 'efi memsync' command to synchronize EFI memory map with devicetree
- Enhance EFI application support with better memory region handling
- Improve EFI debugging commands and device path handling
- Better integrate EFI boot services and devicetree setup

There are a few other minor thigns:
- Enhance efidebug commands with media device and driver information
- Expose EFI device-paths in a few places in bootstd
- Improve bootflow device reporting
- ARM-specific fixes for exception level handling

This series addresses many of the issues found in booting Linux on
Qualcomm X-Elite laptops using the EFI app.
END

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-28 13:21:33 -06:00
Simon Glass
6e9071ba14 efi: app: Add a simple-framebuffer node if enabled
The EFI app cannot make the EFI GOP available to Linux directly, since
it calls exit-boot-services before booting Linux. The easiest way to
provide an early console is with the simple-framebuffer feature. Add
this node to the devicetree if the feature is enabled.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-28 13:21: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
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
cd8d6ccaef efi: app: Avoid freeing memory on exit
The private data is used to perform the exit, so freeing anything used
by the app may cause a hang or crash. The underlying EFI system should
be able to free any memory allocated by the app, so just skip the call
to free_memory()

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-27 16:51:47 -06:00
Simon Glass
a7cc8de618 efi: app: Avoid switching exception levels on ARM
The EFI app runs under the environment provided to it and is not allowed
to change the exception level. Remove this call for the app.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-27 16:51:47 -06:00
Simon Glass
dea4ea00a7 efi: Set the efi_media device name when binding
Binding a new efi_media device uses a placeholder name which is then
changed after the device is bound. But binding the device immediately
causes a child block device to be bound, which uses this placeholder
name as its base, rather than the eventual name of the efi_media device.

To fix, decide on the name earlier (based on the number of existing
devices), then pass that name to device_bind()

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-27 16:51:47 -06:00
Simon Glass
480be6d905 efi: Enable the console pager for the app
The app can produce quite a bit of output, so enable the pager feature.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-26 14:36:07 -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
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
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
59f797f922 efi: app: Implement efidebug boot dump
Seeing the boot order is useful in the app. Everything we need is
present except an implementation of efi_query_variable_info_int(), so
add that and enable 'efidebug boot dump'.

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
c0e80e8d76 efi: app: Add a simplefb node to the devicetree
Use simplefb on ARM devices so that we see a console earlier, assuming
that 'console=tty0' is passed to Linux.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-19 17:36:44 -06:00
Simon Glass
a1f2aa6d5f efi: app: Only show the memory map when debugging
This is quite a long dump and is only useful when debugging. Show it
only if LOG_DEBUG is defined in this file.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-19 17:36:44 -06:00
Simon Glass
043c879dd1 efi: app: Use the relocated global_data
The new global_data is set up by the app but it never uses it. Switch to
the new value after board_init_f(), so that the output of the 'meminfo'
command is more contiguous.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-19 17:36:44 -06:00
Simon Glass
70139c8226 efi: app: Print the final message before freeing memory
Printing may make use of tables which could go away when freed, so do
the free as the last thing before exiting the app.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-19 17:36:44 -06:00
Simon Glass
9bb839094e efi: app: Use EFI_PAGE_SHIFT instead of 12 in free_memory()
Use the constant intended for this purpose, instead of open-coding the
value.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-19 17:36:44 -06:00
Simon Glass
6428b7ffd8 efi: app: Pick up the SMBIOS table
If an SMBIOS table is available, pick it up so that it can be parsed, or
examined with the 'smbios' command.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-19 17:36:44 -06:00
Simon Glass
f7c25b1735 efi: app: Allocate pages in any region
Rather than immediately falling back to the pool allocator when we
cannot get enough memory below 4GB, try the page allocator first. This
provides 4K-aligned memory, which is nicer to look at when debugging.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-19 17:36:44 -06:00
Simon Glass
968ee73c16 efi: app: Tidy up some stale comments in setup_memory()
A few comments are out of date. Drop the one about global_data_ptr and
reword the one about memory above 4GB.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-19 17:36:44 -06:00
Simon Glass
50ac26d13c efi: app: Show only a summary of disks and partitions
The EFI app shows a list of every disk and partition it can find. On
Qualcomm x1e laptops this can fill the screen. The information is not
that useful, so just show a summary.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-19 17:36:44 -06:00
Simon Glass
5cd3f28e09 efi: arm: Add the memory map to the FDT
Before booting using extlinux we must add the memory map to the FDT.
Provide a ft_system_setup() function to handle this.

To determine the memory size, scan the memory map looking for entries
that look like real memory.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-14 07:45:25 -06:00
Simon Glass
ea30e7c267 efi: boot: Correct calculation of load address in app
The conversion to using an event was not done correctly, with the
result that it has no effect. Fix it, by passing in the length and
actually using the returned address.

Signed-off-by: Simon Glass <sjg@chromium.org>
Fixes: 207bf34de7 ("boot: efi: Use an event to relocate the OS")
2025-08-14 07:45:25 -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
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
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
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
ca57421d07 efi_client: Provide generic malloc() and free() functions
The device-path code requires memory allocation. Provide an
implementation of these for use by the client.

Note that this will not work for the stub, since in that case it needs
to use U-Boot's memory allocation. This was a subject of a long argument
on the mailing list about U-Boot using its own malloc() where possible,
so it seems best to just leave this broken.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-08 16:53:16 -06:00
Simon Glass
61844e4076 efi: Drop information about removing C flags
A 'removing flags -mregparm=3' message appears when building sometimes.
It isn't very useful and does not indicate a problem, so remove it.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-23 20:19:42 -06:00
Simon Glass
5209eaf9e5 efi: Switch x86 and ARM to use the unified stub
Now that the stub code is unified, switch over to it, dropping the
individual efi_main() functions.

Series-to: concept
Cover-letter:
efi: Unify the scripts and start-up code
We have two scripts which run QEMU, one for EFI and one for bare metal.
They have similar options so it seems reasonable to try to unify them a
bit. This series creates a common file and adjusts arguments so they are
consistent across both scripts.

The EFI app for ARM and x86 have different start-up code but in fact
the code is quiet similar. This series creates a new common main
program, called efi_main_common() which is used for both architectures.
The small number of differences are handled in arch-specific code.
END
2025-06-30 14:28:08 -06:00
Simon Glass
c3c7d368a0 efi: Move ARM 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
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
4df2a3f4a1 efi: Unify the names for use_uart and ebs_called
The x86 and ARM implementations use a different variable for the same
thing, just inverted.

Invent a third name for this, adjust both files to use it and store it
in the common stub.c file.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-30 14:26:34 -06:00
Simon Glass
baee46f95b efi: Move more common stub code into the common file
Pull in several functions which are identical in the ARM and x86 files.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-30 14:26:34 -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
Simon Glass
0b00c34e7c efi: Drop the efi_ prefix on the arch-specific stub files
These are already in the lib/efi/ directory so the extra efi_ prefix is
redundant and makes files harder to find. Drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-30 14:26:34 -06:00
Simon Glass
cf4fc6dd9a efi: Rename efi_stub.o Makefile variable
This variable is a bit confusing as it looks like a filename. Use
stub_obj instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-30 14:26:34 -06:00
Simon Glass
d50a7577e1 efi: x86: Show app banner on startup
Print a line that indicates if this is the app, to match the line shown
for the payload, i.e.:

   Model: EFI x86 Application

or:

   Model: EFI x86 Payload

or:

   Model: EFI ARM Application

Drop CONFIG_DISPLAY_BOARDINFO_LATE as it is not needed.

Note that there is no (generic) stub for ARM.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-30 14:26:16 -06:00
Simon Glass
207bf34de7 boot: efi: Use an event to relocate the OS
Rather than a weak function, use the recently added event to adjust the
OS load-address. Tidy up the code a little while here.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-05 14:42:47 -06:00
Simon Glass
2762f777b8 x86: efi: Add a few dummy functions
Although GD_FLG_SKIP_RELOC is enabled for the app, the code for
relocation is still present in the image. Add a few dummy functions
needed on x86.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-02 08:25:41 -06:00
Simon Glass
21ae2207d5 efi: Provide an easy way to debug with gdb
Add a Kconfig option to easily enable debugging of the app using the
recommended method. Provide some docs too.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-02 08:25:41 -06:00
Simon Glass
0af4a0a5ad efi: Allow disabling the TPM in the app
When the TPM is disabled, avoid trying to use it in the app.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-02 08:25:41 -06:00
Simon Glass
d702ab5cd5 efi: Allow disabling networking in the app
When networking is disabled, avoid trying to use networking in the app.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-02 08:25:41 -06:00