95 Commits

Author SHA1 Message Date
Simon Glass
aaf889390f boot: Support a fake go with pxe
Provide a way to pass the 'fake go' flag from the bootflow flag through
to the PXE implementation, so that a request for a fake go
(via 'bootflow boot -f') is handled correctly in the bootmeth and when
booting.

Add a little more debugging of this in PXE.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-09-22 11:23:05 -06:00
Simon Glass
36e81b81f5 boot: Record the kernel size in pxe_utils
Write the kernel size into the bootm_info so it can be used as needed.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-11 10:02:16 -06:00
Simon Glass
123f73037b boot: pxe: Retain the kernel address in the context
Converting back and forth between a string and a ulong does not make
much sense. Simplify the code by adding a separate value for the kernel
address.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-09 12:04:30 -06:00
Simon Glass
7ed6c096ee boot: pxe: Rename kern_addr in struct pxe_context
This variable is a string, so add a _str suffix to make this clear.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-09 12:04:30 -06:00
Simon Glass
137765cf69 boot: pxe: Allow loading a kernel without kernel_addr_r
When this environment variable is missing, reserve space using lmb.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-09 12:04:30 -06:00
Simon Glass
d6c2e45c4f boot: Simplify kernel-address handling in label_boot()
This function is needlessly convoluted, reading the kernel address as a
string, possibly adding the FIT configuration, then parsing that to
obtain the kernel address again.

Create a kern_addr variable to hold the kernel address, so we can
simplify the code.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-09 12:04:30 -06:00
Simon Glass
90e9403749 boot: Rename kern_addr in label_boot()
Rename this variable to kern_addr_str so that it is clear it is a string
and not an address.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-09 12:04:30 -06:00
Simon Glass
d252bf77da boot: Support reserving memory in get_relfile_envaddr()
We normally require environment variables when loading files using PXE/
syslinux. This is not really necessary, since we can use lmb to find a
suitable space.

Add support for reserving space in get_relfile_envaddr(), which is the
commonly used function for reading a file. Use env_get() so no error is
shown if the environment variable does not exist.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-09 12:04:30 -06:00
Simon Glass
9fdd26efc1 boot: Drop the allocation in label_boot()
It doesn't seem worth allocating space for a label when it is normally
going to be under 20 characters. Use a fixed-sized string (with plenty
of space) instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-09 12:04:30 -06:00
Simon Glass
c9c2faad2f boot: Add a conf_fdt ulong to struct pxe_context
Keep this value around separately from the string, since the string
needs to be converted before use.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-09 12:04:30 -06:00
Simon Glass
793839d6e7 boot: pxe: Rename conf_fdt to conf_fdt_str
This is a string, so add a string suffix to make that clear.

Switch the assignment order in label_run_boot(), since the FDT is loaded
after the kernel.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-09 12:04:30 -06:00
Simon Glass
cbd55c1d88 boot: Convert struct pxe_context initrd_filesize to ulong
Convert initrd_filesize to a ulong and rename it.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-09 12:04:30 -06:00
Simon Glass
258c30f7af boot: Convert struct pxe_context initrd address to ulong
Several of the strings in this struct would be better off as addresses,
now that they are passed around a fair bit.

Start by converting initrd_addr_str to ulong

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-09 12:04:30 -06:00
Simon Glass
20c5318124 boot: Return the chosen address from get_relfile_envaddr()
Update this function to return the address obtained from the environment
variable. That will allow the caller to know where the image ended up.
For now this is not used.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-09 12:04:30 -06:00
Simon Glass
ceef5b5949 boot: Adjust PXE get_relfile() to support reservation
In some cases we don't have a particular address to read into so would
like one reserved. Adjust this function to support that.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-09 12:04:30 -06:00
Simon Glass
5ead77edd5 boot: Update pxe_getfile_func() to support reservation
In some cases we don't have a particular address to read into so would
like one reserved. Adjust this function to support that.

For now, sysbot_read_file() fails if the address is not provided. This
will be resolved in a later patch.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-09 12:04:30 -06:00
Simon Glass
cbe563ed8b boot: pxe: Init initrd_str in label_boot()
When 'bootflow read' is used to read images, initrd_str is not inited
before strdup() is called. Note that this is only used by developers.

Set the variable to an empty string to start.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-07 04:37:15 -06:00
Simon Glass
e385bac1b6 boot: Given up pxe boot if kernel_addr_r is missing
At present we require this environment variable in order to do any
booting. The check for this actually later (the '"malloc fail' message)
but there is a possible NULL access before getting to that point.

Check it immediately after reading.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-07 05:12:19 -06:00
Simon Glass
53b02e1015 boot: Support restarting a bootm sequence from PXE
If a load-only FIT has already provided a devicetree, PXE boot may need
to restart the bootm sequence, rather than starting an entirely new one,
so that the devicetree is preserved and used for booting.

Add support for this by adding a new field in the context and updating
extlinux_boot() to receive the value as a new parameter.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-04 14:40:00 -06:00
Simon Glass
cd8057dd58 boot: Move PXE-parsing logic out to a separate file
The pxe_utils.c file is quite large and has a mix of parsing and booting
code. Split out the parsing into a new 'pxe_parse.c' file.

Add function prototypes for parse_pxefile_top() and label_destroy(), the
two functions used by pxe_utils.c

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-04 14:40:00 -06:00
Simon Glass
684fc8c4d7 Revert "Merge branch 'loadg' into 'master'"
This reverts merge request !141
2025-08-02 19:50:30 +00:00
Simon Glass
87c3760161 boot: Support restarting a bootm sequence from PXE
If a load-only FIT has already provided a devicetree, PXE boot may need
to restart the bootm sequence, rather than starting an entirely new one,
so that the devicetree is preserved and used for booting.

Add support for this by adding a new field in the context and updating
extlinux_boot() to receive the value as a new parameter.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-02 12:29:35 -06:00
Simon Glass
4c423e6711 boot: Move PXE-parsing logic out to a separate file
The pxe_utils.c file is quite large and has a mix of parsing and booting
code. Split out the parsing into a new 'pxe_parse.c' file.

Add function prototypes for parse_pxefile_top() and label_destroy(), the
two functions used by pxe_utils.c

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-02 12:29:34 -06:00
Simon Glass
7a37413818 pxe_utils: Support the SAY command
This shows a message for the user. Implement it to keep the user
informed.

Series-to: u-boot
pxe: Support an automatic localboot
It seems that extlinux expects that boards know how to boot a local OS
from attached media. U-Boot currently assumes that boards define a
"localcmd" environment variable to support this. None does.

Provide an automatic means to find a kernel and ramdisk, using common
filenames. This addresses booting on MAAS, at least.
END

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
2025-07-30 15:01:52 +12:00
Simon Glass
de881bfad7 pxe_utils: Support a backup for localboot
The current localboot implementation assumes that a 'localcmd'
environment variable is provided, with the instructions to follow. This
may not be included, so provide a fallback in that case.

Add a test image and test as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-30 15:00:59 +12:00
Simon Glass
6657f739a3 pxe_utils: Allow the FDT to be missing
The devicetree file may not be provided, so avoid a failure in that
case.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
2025-07-30 14:59:40 +12:00
Simon Glass
855adaaa02 boot: Allow zboot without CMDLINE in pxe_utils
Use CONFIG_ZBOOT instead of CONFIG_CMD_ZBOOT as the condition for
supporting booting from a zImage, so that this works when CONFIG_CMDLINE
is disabled.

Series-to: heinrich
Cover-letter:
boot: Enable bootstd features without CMDLINE
This series refactors various Kconfig options to allow programmatic boot
to operate on x86.
END

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-02 13:36:47 -06:00
Simon Glass
eaad588780 boot: Correct ramdisk address
We must use the ramdisk address for the initrd_addr field, not the kernel
address. Fix this.

Signed-off-by: Simon Glass <sjg@chromium.org>
Fixes: e05cda3004 ("boot: pxe: Refactor label_run_boot() to avoid")
Reviewed-by: Tom Rini <trini@konsulko.com>
2025-03-15 08:49:00 +00:00
Simon Glass
44d3e7f46a pxe_utils: Correct setting of no_prompt
This should only be forced on, never off. Fix this so that the menu is
shown when expected.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-01-25 11:19:30 -07:00
Simon Glass
a976bcf2b4 pxe_utils: Refactor to separate reading from booting
It is useful to be able to select a bootflow and read its images,
without actually doing the boot. This allows adjusting the bootargs, for
example.

Provide support for this in the pxe_utils module, by adding a 'probe'
method which selects a label and saves its settings, so it can be booted
later, if desired.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-19 05:55:32 -07:00
Simon Glass
13eb86be35 boot: Detect booti format properly in pxe_utils
Rather than assuming that a file can be booted with bootm, check that
the format is correct first. Do the same for booti.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-19 05:55:32 -07:00
Simon Glass
c137ff3399 pxe: Deal with a missing FDT in the bootflow
Move processing of a missing FDT so that it happens before booting, so
we can see the result in the bootflow.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-19 05:55:32 -07:00
Simon Glass
4edac0db4d pxe: Collect the FDT in the bootflow
Move processing of the FDT so that it happens before booting. Add a test
to check that the FDT is now visible.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-19 05:55:32 -07:00
Simon Glass
415cd2e8c0 pxe: Allow skipping the boot
Provide a way to skip booting the OS and just return. This will allow
bootstd to read out useful information.

Add debugging to help figure out the flow.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-19 05:55:32 -07:00
Simon Glass
35dea9df30 pxe: Record the bootflow in the PXE context
At present the only option with PXE is to boot it and see what happens.

Provide a bootflow, when available, so that PXE will eventually be able
to add some useful information to it.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-19 05:55:32 -07:00
Simon Glass
70d37cbab9 pxe: Drop the cmdline parameter
Now that PXE can operate without the command line, drop the parameter
throughout the code.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-19 05:55:32 -07:00
Simon Glass
e05cda3004 boot: pxe: Refactor label_run_boot() to avoid cmdline
Adjust the remaining call in this function to use the bootm API. This
will allow PXE to work without the command line.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-19 05:55:32 -07:00
Simon Glass
ae798539f4 pxe_utils: Simplify default fdt in label_run_boot()
Tidy up this code a little to avoid two calls to env_get() for both
fdt_addr and fdtcontroladdr

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Quentin Schulz <quentin.schulz@cherry.de>
2024-12-19 05:55:32 -07:00
Simon Glass
47eda7e80e boot: pxe: Use bootm_...() functions where possible
Rather than building a command line for each operation, use the
functions provided by the bootm API.

Make sure that the bootm functions are available if pxe_utils is used.

Since SYS_BOOTM_LEN is not present for the tools-only build, adjust the
code to handle that.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Quentin Schulz <quentin.schulz@cherry.de>
2024-12-19 05:55:32 -07:00
Simon Glass
f65b36e9b5 boot: Pass just the FDT argument to label_process_fdt()
Since this function only adjusts one element of the bootm command, pass
just that. This will make it easier to refactor things to remove the
bootm command.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Quentin Schulz <quentin.schulz@cherry.de>
2024-12-19 05:55:15 -07:00
Simon Glass
66b0cf32a3 boot: Split pxe label_run_boot() into two parts
This function is quite long. Split out the FDT processing into its own
function.

Add a function comment for the new label_process_fdt() function.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Quentin Schulz <quentin.schulz@cherry.de>
2024-12-19 05:55:15 -07:00
Simon Glass
0fa4ca4a45 boot: Split pxe label_boot() into two parts
This function is far too long. Split out the part which builds and runs
the bootm/i/z commands into its own function.

Add a function comment for the new label_run_boot() function.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Quentin Schulz <quentin.schulz@cherry.de>
2024-12-19 05:55:15 -07:00
Simon Glass
89f9271b17 boot: Use strlcpy() in label_boot()
This function is recommended instead of strncpy() since it always
terminates the string.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-19 05:55:15 -07:00
Simon Glass
b67f66ed57 boot: Update extlinux pxe_getfile_func() to include type
Add a file-type parameter to this function and update all users. Add a
proper comment to the function which we are here.

This will allow tracking of the file types loaded by the extlinux
bootmeth.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-05 11:00:22 -07:00
Simon Glass
03ef0727f8 boot: pxe: Drop the duplicate comment on get_pxe_file()
This function is exported, so document it in the header file. Drop the
duplicate comment in the C file.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-12-05 11:00:22 -07:00
Weijie Gao
ccdd7948e2 menu: add support to check if menu needs to be reprinted
This patch adds a new callback named need_reprint for menu.
The need_reprint will be called before printing the menu. If the
callback exists and returns FALSE, menu printing will be canceled.

This is very useful if the menu was not changed. It can save time
for serial-based menu to handle more input data.

Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
Reviewed-by: Daniel Golle <daniel@makrotopia.org>
Tested-by: Daniel Golle <daniel@makrotopia.org>
2024-11-04 16:41:38 -06:00
Martyn Welch
8ba82a91b3 boot: Add logic to enable booting from fallback option
The "fallback" extlinux config option allows us to set an alternative
default boot option for when it has been detected that the default is
failing. Implement the logic required to boot from this option when
desired.

Signed-off-by: Martyn Welch <martyn.welch@collabora.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2024-10-15 10:24:27 -06:00
Martyn Welch
d2faad3ff3 boot: pxe_utils: Add fallback support
When configured correctly, we can detect when boot fails after the boot
process has been handed over to the kernel through the use of U-Boot's
bootcount support. In some instances, such as when we are performing
atomic updates via a system such as OSTree, it is desirable to provide a
fallback option so that we can return to a previous (hopefully working)
state.

Add a "fallback" option to the supported extlinux configuration options
that points to a label like "default" so that we can utilise this in
later commits.

Signed-off-by: Martyn Welch <martyn.welch@collabora.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2024-10-15 10:24:27 -06:00
Marek Vasut
789934f1bb boot: Remove duplicate newlines
Drop all duplicate newlines. No functional change.

Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
2024-07-15 12:12:17 -06:00
Tom Rini
48641bfab7 Merge patch series "automatically add /chosen/kaslr-seed and deduplicate code"
Tim Harvey <tharvey@gateworks.com> says:

This series will automatically add /chosen/kaslr-seed to the dt if
DM_RNG is enabled
during the boot process.

If RANDOMIZE_BASE is enabled in the Linux kernel instructing it to
randomize the virtual address at which the kernel image is loaded, it
expects entropy to be provided by the bootloader by populating
/chosen/kaslr-seed with a 64-bit value from source of entropy at boot.

If we have DM_RNG enabled populate this value automatically when
fdt_chosen is called. We skip this if ARMV8_SEC_FIRMWARE_SUPPORT
is enabled as its implementation uses a different source of entropy
that is not yet implemented as DM_RNG. We also skip this if
MEASURED_BOOT is enabled as in that case any modifications to the
dt will cause measured boot to fail (although there are many other
places the dt is altered).

As this fdt node is added elsewhere create a library function and
use it to deduplicate code. We will provide a parameter to overwrite
the node if present.

For our automatic injection, we will use the first rng device and
not overwrite if already present with a non-zero value (which may
have been populated by an earlier boot stage). This way if a board
specific ft_board_setup() function wants to customize this behavior
it can call fdt_kaslrseed with a rng device index of its choosing and
set overwrite true.

Note that the kalsrseed command (CMD_KASLRSEED) is likely pointless now
but left in place in case boot scripts exist that rely on this command
existing and returning success. An informational message is printed to
alert users of this command that it is likely no longer needed.

Note that the Kernel's EFI STUB only relies on EFI_RNG_PROTOCOL for
randomization and completely ignores the kaslr-seed for its own
randomness needs (i.e the randomization of the physical placement of
the kernel). It gets weeded out from the DTB that gets handed over via
efi_install_fdt() as it would also mess up the measured boot DTB TPM
measurements as well.
2024-06-28 17:31:28 -06:00