Commit Graph

2247 Commits

Author SHA1 Message Date
Simon Glass
712dd7cebc x86: Drop bootm_announce_and_cleanup()
Now that bootm_final() does most of what we want, drop this separate
function.

Series-to: concept
Cover-letter:
bootm: Clean up arch-specific, pre-OS clean-up
Each arch does something slightly different before booting the OS. Some
archs even do different things depending on the CPU type.

EFT_LOADER has its own special code, regardless of which arch is being
booted.

It is quite hard to know what actually happens in the final milliseconds
before the OS boot.

This series attempts to clean up U-Boot in this area.

The basic approach is to create a new bootm_final() function which is
called by all archs. It provides some flags for a couple of necessary
variations but otherwise it is generic.

RISC-V, x86 and ARM are converted over to use this new function. For
consistency, EFI loader is converted as well.

A noteable change is that EFI_LOADER now does bootstage processing
before boot, if enabled, thus producing a report.

Future work could take this a little further:
- Drop board_quiesce_devices() and rely on driver model for that
- Similarly with udc_disconnect()
- cleanup_before_linux() could use more details as to what it is
  supposed to do, to reduce the number of arch-specific variations
END

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-12 16:25:43 -06:00
Simon Glass
7482087639 bootm: Move cleanup_before_linux() to bootm.h
Move the declaration of this function to a common header. Make sure it
is included by files which define it.

Fix up a few whitespace problems while here.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-12 16:18:34 -06:00
Simon Glass
0cde568159 x86: Add cleanup_before_linux()
This function is not present on x86, but there is an x86-specific
version which is never called. Add the former, making it call the
latter.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-12 16:17:08 -06:00
Simon Glass
c3b0c2979e x86: Call bootm_final()
The x86 code in bootm_announce_and_cleanup() is very similar to the new
bootm_final() function, so just use the latter. Move over a useful
comment.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-12 16:14:47 -06:00
Simon Glass
e30db25efa x86: Use the existing function to find the FACP
Rather than searching for this table, use the existing search function.
Update that to check the header and checksums.

This allows the code to work correctly with boards that have the tables
in a bloblist, such as QEMU.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-11 21:12:11 +02:00
Simon Glass
0f640f96c8 Make the bdinfo printing-functions more generic
The bdinfo command makes use of quite a few functions which show a label
followed by a value, on a single line.

This sort of thing is generally useful outside of bdinfo, so move it to
a generic place. Use 'l' (for label) as the prefix.

The margin is still hard-coded to 12, which seems a reasonable limit for
a label.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-09 23:26:02 +02:00
Simon Glass
be47cbc296 arm: x86: Move Kconfig from arch/ to board/
Set up a single place in Kconfig where board/emulation/Kconfig is
included, removing the two sites in arch/arm and arch/x86

Move the ARM-specific Kconfig into this file.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-09 05:22:09 +02:00
Simon Glass
cd93381ec5 emulation: x86: Rename VENDOR_EMULATION to ARCH_QEMU_X86
This name matches the ARM name and 'emulation' is not really a vendor.
Use ARCH_QEMU_X86 instead, moving that option from its existing location.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-09 05:21:59 +02:00
Simon Glass
537e97237e x86: Rename QEMU to ARCH_QEMU_X86
CONFIG_QEMU is too generic for an x86-specific option. Rename it to
ARCH_QEMU_X86

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-05 05:48:28 -06:00
Simon Glass
38b4a48a3e x86: Show jump address in SPL when debugging
Add debugging info for the jump address and range, to assist in checking
the memory map and usage.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-02 12:34:58 -06:00
Simon Glass
78dead849f x86: Emit a post code before booting
It is possible to benchmark U-Boot using QEMU as described here:

   https://github.com/stefano-garzarella/qemu-boot-time

On x86 devices, that script can read post codes from a perf trace. Add
a code which is emitted just before handing off to the Linux kernel.
Existing post codes can be used to determine when U-Boot starts.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-12 19:43:54 +00:00
Simon Glass
0aabc7b4df x86: Avoid adding two SPL binaries to the image
At present two separate SPL binaries are included in the ROM. This
affects QEMU which is quite tight with only a 2MB ROM. Adjust the
image description so that space is not wasted when microcode is not
needed.

Series-to: u-boot
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-04 15:07:08 -06:00
Simon Glass
165311eaab x86: Make ZBOOT depend on BOOT
There is already a CONFIG_ZBOOT option, separate from CONFIG_CMD_ZBOOT
so make it depend on CONFIG_BOOT

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-02 13:36:47 -06:00
Simon Glass
cba7622d29 boot: global: Use BOOT to pull in boot functions
Each arch has its own set of functions related to booting. Rather than
including them for each enabled command, have a single rule to include
them, using the new CONFIG_BOOT

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-02 13:36:47 -06:00
Simon Glass
653eef340d x86: efi: Enable --gc-sections to drop unused code
Add --gc-sections to help reduce the size of the EFI app. Add a check
for undefined symbols too, since using these can hang or crash the app.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-02 08:25:41 -06:00
Simon Glass
3fc6d8c051 x86: efi: Drop relocate and physmem
These two files are not used in the EFI app and it does not make sense
to compile them in. Omit relocate.c and physmem.c

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-02 08:25:41 -06:00
Simon Glass
362ef8e91e x86: efi: Tidy up the link scripts
Mark important sections with KEEP so that the linker will not remove
them when garbage-collection is (later) enabled.

Provide a _end symbol so that this can be accessed in setup_mon_len()

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-02 08:25:41 -06:00
Simon Glass
105918f3b9 x86: efi: Sync up the two link scripts somewhat
The 32- and 64-bit scripts are more different than they need to be.
Make some changes to both so that it is easier to see the necessary
differences.

For the 32-bit script this is mostly just whitespace. For the 64-bit
script the eh_frame section is discarded and the .data section is
reordered.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-02 08:25:41 -06:00
Simon Glass
e2670b665d spl: Rename jump_to_image_no_args()
This is about to become a misnomer since with standard passage we need to
pass arguments to U-Boot. Rename the function.

Also rename the local variable to 'jumper' to avoid a conflict.

Series-changes: 2
- Split the jump_to_image_no_args() change into its own patch

Signed-off-by: Simon Glass <sjg@chromium.org>
Change-Id: Ieb1fd7a5478ba1dfe3a58666ed586e83b0641590
2025-05-29 17:21:36 +01:00
Simon Glass
3e940f2082 x86: Move Intel GNVS file into the common include directory
Move this so we can include it from sandbox, needed since it is in a
bloblist and must have a check.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-05-29 17:21:36 +01:00
Heinrich Schuchardt
a41cc36db3 x86/acpi: simplify updating header checksum
Use acpi_update_checksum() for updating ACPI table header checksum.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Matthias Brugger <mbrugger@suse.com>
2025-05-29 16:07:51 +01:00
Simon Glass
a9b4f147d9 x86: efi_loader: Ensure the SMBIOS tables are sent via EFI
The EFI-loader code has not been fully converted to use bloblist, so
relies on the SMBIOS-table address being set in global_data.

Set this up in write_tables() so that the SMBIOS tables are actually
available.

Enable the command for x86 QEMU so that the SMBIOS tests actually run.

Signed-off-by: Simon Glass <sjg@chromium.org>
Fixes: 83ce35d6eb ("emulation: Use bloblist to hold tables")
Reported-by: Niklas Sombert <niklas.sombert@uni-duesseldorf.de>
Tested-by: Niklas Sombert <niklas.sombert@uni-duesseldorf.de>
Tested-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2025-05-28 08:04:24 +01:00
Simon Glass
ca1f2dbd8e efi: Rename CONFIG_EFI to CONFIG_EFI_CLIENT
The generic name 'EFI' would be more useful for common EFI features. At
present it just refers to the EFI app and stub, which is confusing.

Rename it to EFI_CLIENT

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-05-28 08:02:11 +01:00
Heinrich Schuchardt
24fa04ebac common: clean up setjmp.h
Separate setjmp.h into an architecture independent part and an architecture
specific part. This simplifies moving from using struct jmp_buf_data
directly to using type jmp_buf in our code which is the C compliant way.

Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2025-05-16 14:45:25 +02:00
Jeremy Compostella
373929b961 arch/x86/lib: Fix CONFIG_X86_64 usage in zimage.c
Correct the preprocessor directive used to check for 64-bit kernel
support in the `zboot_go` function. The code previously checked for
`CONFIG_X86_RUN_64BIT`, which is not the correct configuration option
for determining if the kernel should run in 64-bit mode. The correct
option is `CONFIG_X86_64`.

Signed-off-by: Jeremy Compostella <jeremy.compostella@intel.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2025-05-08 07:15:56 +02:00
Jeremy Compostella
5bd726deb6 arch/x86/cpu: Call x86_cpu_reinit_f for 64-bits
As both CONFIG_X86_RUN_64BIT and X86_RUN_64BIT_NO_SPL cases run U-Boot
in 64-bit mode with the CPU fully initialized already.

Signed-off-by: Jeremy Compostella <jeremy.compostella@intel.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2025-05-08 07:15:54 +02:00
Jeremy Compostella
79812bcccc arch/x86: Add 64-bit U-Boot configuration without SPL
This commit introduces a new configuration option X86_RUN_64BIT_NO_SPL
to allow building U-Boot as a 64-bit binary without using the SPL
(Secondary Program Loader). The motivation is to simplify the boot
process for certain x86-based platforms that do not require SPL, such as
those booting directly from a 64-bit coreboot firmware.

This update revises the `X86_RUN_64BIT` configuration to more accurately
describe its role as "32-bit SPL followed by 64-bit U-Boot." It
clarifies the sequence of operations during the boot process, where the
system transitions from a 32-bit SPL (Secondary Program Loader) to the
main 64-bit U-Boot.

Signed-off-by: Jeremy Compostella <jeremy.compostella@intel.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2025-05-08 07:15:52 +02:00
Tom Rini
2825b387b0 Kbuild: Always use $(PHASE_)
It is confusing to have both "$(PHASE_)" and "$(XPL_)" be used in our
Makefiles as part of the macros to determine when to do something in our
Makefiles based on what phase of the build we are in. For consistency,
bring this down to a single macro and use "$(PHASE_)" only.

Signed-off-by: Tom Rini <trini@konsulko.com>
2025-05-01 05:56:48 -06:00
Simon Glass
f4fdb3a8be efi: arm: x86: Allow use of the EFI table in the app
It isn't worth the hassle of omitting this field for the app, since code
is shared between the payload and the app. Adjust the condition to avoid
a build error in the 'efi' command with the app on 64-bit ARM.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-03-27 05:31:43 -06:00
Simon Glass
255a0f2165 efi: x86: Allow setting the global_data pointer with EFI
Provide a function which sets this pointer, for use in the EFI app.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-03-27 05:31:43 -06:00
Simon Glass
ab351a6c58 efi: x86: Rework VENDOR_EFI option to permit other archs
At present only x86 supports the EFI app and (apart from Qualcomm) the
payload. In preparation for supporting 64-bit ARM more generally, rename
the existing ARCH_EFI option to ARCH_EFI_X86, using that to define a
generic ARCH_EFI which will be enabled for all architectures.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-03-27 05:31:43 -06:00
Simon Glass
711542d2c6 treewide: Rename VENDOR_EFI to ARCH_EFI
The 'vendor' concept comes from arch/x86. Rather than letting this
spread around the tree, rename it to ARCH_EFI.

While EFI is not quite an architecture in the strict sense, it is
similar to sandbox in that it sits somewhat above the CPU architecture.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-03-27 05:31:43 -06:00
Simon Glass
97b1f411a8 efi: x86: Move EFI SDRAM-handling into a common file
This code is not actually x86-specific, so move it into the lib/efi dir
where other archs can use it.

Drop inclusion of the unnecessary x86-specific header.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
2025-03-27 05:31:43 -06:00
Simon Glass
a95cdd3559 efi: Allow board/efi Kconfig to be used outside x86
So far only x86 supports the EFI app. ARM is going the same way, so
allow these options to be enabled for 64-bit ARM too.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
2025-03-27 05:31:43 -06:00
Simon Glass
a950791b57 x86: Support a 64-bit ramdisk address
Add some missing pieces to bootparams so that a 64-bit ramdisk address
can be used. Tidy up the logging while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-03-15 08:49:43 +00:00
Simon Glass
b363db0ba2 x86: emulation: Support BLOBLIST_TABLES properly
The existing QEMU implementation mostly ignored BLOBLIST_TABLES and
allocates the bulk of the tables with malloc(). Update it to place all
tables in the bloblist. Since QEMU declares a size of 128KB regardless
of the size of its tables, this requires a larger bloblist.

Fix up the e820 table to handle this, keeping the old code as an option
for now, to assist with any future bug-fixing.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-03-15 08:49:43 +00:00
Simon Glass
1cbf91f89e x86: qemu: Use the new e820 API
Move over to use this API before making the code even more complicated.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-03-15 08:49:43 +00:00
Simon Glass
6b61f08d4c x86: Add a new API for e820
The existing mechanism is pretty painful as it requires manual
calculations for anything but a trivial setup.

Add a new API for adding e820 entries.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-03-15 08:49:43 +00:00
Simon Glass
699eea36c4 x86: e820: Add a function to dump the e820 table
There is already code for this in zimage. Move it to the e820 file so
it can be used elsewhere.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-03-15 08:49:43 +00:00
Simon Glass
02362ac39c x86: emulation: Set an MTRR for the RAM
QEMU likes to have an MTRR set up, just like real machines. Add an MTRR
which covers the total RAM size.

This does nothing on machines without MTRRs.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-03-15 08:49:43 +00:00
Simon Glass
6dae0e2741 x86: Allow adding non-aligned size for MTRR
At present mtrr_add_request() requires that the size is a power of two.
This is too limiting for machines with 4GB (or more) of RAM, since they
often must take account of a memory hole at 3GB.

Update the function to automatically deal with an unaligned size, using
more MTRRs as required.

The algorithm is taken from coreboot commit 60bce10750

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-03-15 08:49:43 +00:00
Simon Glass
7a1f448816 x86: Correct msr operation on amd64
The CONFIG option is no-longer correct since we can have SPL and PPL
with different bitness.

Fix this and sync up with Linux 6.13 in this area, since this is where
the code came from many years ago.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-03-15 08:49:43 +00:00
Simon Glass
31fe5731dd x86: Update cpuid_eax et al to work on amd64
The existing functions work but the register clobbers are wrong, so
strange bugs results.

The original functions were taken from a very old version of Linux.
Update them from Linux 6.13

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-03-15 08:49:43 +00:00
Simon Glass
70001544fe x86: Add functions to convert between mtrr size and mask
Rather than repeating the same code in several places, add some
functions which can do the conversion.

Use the cpu_phys_address_size() function to obtain the physical-address
size, since it is more reliable with kvm, where the host CPU may have a
different value from the emulation CPU.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-03-15 08:49:43 +00:00
Simon Glass
5ef7e0a18b x86: Support CPU functions in long mode
At present it is not possible to find out the physical-address size in
long mode, so a predefined value is used.

Update the macros to support this properly, since it is important when
programming MTRRs.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-03-15 08:49:43 +00:00
Simon Glass
10b612383f x86: Rename the _D dirty flag
This value happens to be used by ctype.h so chose a different name.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-03-15 08:49:43 +00:00
Simon Glass
a436d7a4cb x86: Use a simple jump into long mode
With the 64-bit descriptor we can use a jump instruction, rather than
pushing things on the stack.

Since the processor is in 64-bit mode by this point, pop a 64-bit value
from the stack, containing the target address.

This simplifies the code slightly, in particular its use of the stack.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-03-15 08:49:43 +00:00
Simon Glass
e5a12be04b x86: Use the same GDT when jumping to long mode
Make use the existing GDT which now includes entries for 64-bit code.
Leave the interrupt descriptors alone. They can be tidied up once U-Boot
starts up.

With this, kvm mode works with QEMU.

Signed-off-by: Simon Glass <sjg@chromium.org>
Fixes: https://source.denx.de/u-boot/custodians/u-boot-dm/-/issues/31
2025-03-15 08:49:43 +00:00
Simon Glass
e14bf92a70 x86: Disable paging before changing to long mode
This is required as part of the procedure. The existing code works
because it changes the GDT at the same time, but this makes kvm
unhappy.

Update the algorithm to disable and then re-enable paging.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-03-15 08:49:43 +00:00
Simon Glass
b9909c3e89 x86: Tidy up the GDT size in start/16.S
Use a symbol to select the size of the GDT, rather than hard-coding a
value. This matches how it is done in start64

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-03-15 08:49:43 +00:00