Commit graph

241 commits

Author SHA1 Message Date
Tobias Waldekranz
e45bba562f image: Fix script execution from FIT images with external data
Update the script loading code to recognize when script data is stored
externally from the FIT metadata (i.e., built with `mkimage -E`).

Signed-off-by: Tobias Waldekranz <tobias@waldekranz.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2023-04-05 10:54:47 -04:00
Safae Ouajih
57e405e1f4 android: boot: support bootconfig
Support Bootconfig feature.
- The bootconfig feature replaces the androidboot.*
  kernel cmdline options.

This was adapted from downstream [1] commit : 7af0a0506d4d ("cuttlefish:
support bootconfig parameters").

Link:[1] https://android.googlesource.com/platform/external/u-boot/

Signed-off-by: Safae Ouajih <souajih@baylibre.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
Tested-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
2023-04-04 14:50:47 -04:00
Safae Ouajih
636da2039a android: boot: support boot image header version 3 and 4
Enable the support for boot image header version 3 and 4
using abootimg command.

In order to use version 3 or 4:

1- Vendor boot image address should be given to abootimg cmd.

	abootimg addr $1 $vendor_boot_load_addr

2- "ramdisk_addr_r" env variable (ramdisk address) should be set to host
the ramdisk : generic ramdisk + vendor ramdisk

Replace "struct andr_boot_img_hdr_v0*" by "void *" in
some functions since v3 and v4 are now supported as well.

Signed-off-by: Safae Ouajih <souajih@baylibre.com>
Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
Tested-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
2023-04-04 14:50:47 -04:00
Safae Ouajih
2d0da1972d android: boot: update android_image_get_dtb_img_addr to support v3, v4
Add support for boot image version 3 and 4 in
android_image_get_dtb_img_addr().
Since the dtb is now included in vendor_boot image
instead of boot image, extract the dtb address from
vendor_boot image when a v3 or v4 is used.

Signed-off-by: Safae Ouajih <souajih@baylibre.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
Tested-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
2023-04-04 14:50:47 -04:00
Safae Ouajih
b36b227b6a android: boot: support extra command line
In version 3 and 4 of boot image header, the vendor specific
command line are located in vendor boot image. Thus, use
extra command line to add those cmd to bootargs.

Signed-off-by: Safae Ouajih <souajih@baylibre.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
Tested-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
2023-04-04 14:50:47 -04:00
Safae Ouajih
c79a2e6823 android: boot: ramdisk: support vendor ramdisk
Version 3 and 4 of boot image header introduced
vendor boot ramdisk: Please check include/android_image.h
for details.

The ramdisk is now split into a generic ramdisk in boot image
and a vendor ramdisk in vendor boot image.

Support the new vendor ramdisk.

Signed-off-by: Safae Ouajih <souajih@baylibre.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
Tested-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
2023-04-04 14:50:47 -04:00
Safae Ouajih
1115027d2f android: boot: update android_image_get_data to support v3, v4
Since boot image header version 3 and 4 introduced vendor boot image,
use the following functions to fill the generic android
structure : andr_image_data:

 - android_boot_image_v3_v4_parse_hdr()
 - android_vendor_boot_image_v3_v4_parse_hdr()

Update android_image_get_data() to support v3 and v4

Signed-off-by: Safae Ouajih <souajih@baylibre.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
Tested-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
2023-04-04 14:50:47 -04:00
Safae Ouajih
e058176be3 android: boot: add vendor boot image to prepare for v3, v4 support
Introduce vendor boot image for version 3 and 4 of boot image header.
The vendor boot image will hold extra information about kernel, dtb
and ramdisk.

This is done to prepare for boot image version 3 and 4 support.

Signed-off-by: Safae Ouajih <souajih@baylibre.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
Tested-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
2023-04-04 14:50:47 -04:00
Safae Ouajih
447240e27b android: boot: boot image header v3, v4 do not support recovery DTBO
android_image_get_dtbo() is used to get recovery DTBO via abootimg cmd.
This is not supported in boot image header v3 and v4. Thus, print an
error message when v1,v2 header version are not used.

Signed-off-by: Safae Ouajih <souajih@baylibre.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
Tested-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
2023-04-04 14:50:47 -04:00
Safae Ouajih
bb5d692732 android: boot: content print is not supported for v3, v4 header version
Content print is not supported for version 3 and 4 of boot image header.
Thus, only print that content when v2 is used.

Update android_print_contents() to print an error message
when trying to print boot image header version 3 or 4 content.

Signed-off-by: Safae Ouajih <souajih@baylibre.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
Tested-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
2023-04-04 14:50:46 -04:00
Safae Ouajih
607b07554e android: boot: move to andr_image_data structure
Move from andr_boot_img_hdr_v0 to andr_image_data
structure to prepare for boot image header
version 3 and 4.

Signed-off-by: Safae Ouajih <souajih@baylibre.com>
Tested-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
2023-04-04 14:50:46 -04:00
Safae Ouajih
f48efa0edb android: boot: kcomp: support andr_image_data
andr_image_data structure is used as a global representation of
boot image header structure. Introduce this new structure to
support all boot header versions : v0,v1.v2.v3.v4 and to support
v3 and v4 while maitaining support for v0,v1,v2.
The need of using andr_image_data comes from the change of header
structure in both version 3 and 4.

Rework android_image_get_kcomp()  to support this new struct.

Signed-off-by: Safae Ouajih <souajih@baylibre.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
Tested-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
2023-04-04 14:50:46 -04:00
Safae Ouajih
734cb47d6d android: boot: replace android_image_check_header
With the new vendor boot image introduced in versions 3 and 4
of boot image header, the header check must be done for both boot
image and vendor boot image. Thus, replace android_image_check_header()
by is_android_boot_image_header() to only refer to boot image header check.

Signed-off-by: Safae Ouajih <souajih@baylibre.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
Tested-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
2023-04-04 14:50:46 -04:00
Safae Ouajih
d71a732af4 android: boot: rename andr_img_hdr -> andr_boot_img_hdr_v0
Android introduced boot header version 3 or 4.
The header structure change with version 3 and 4 to support
the new updates such as:
- Introducing Vendor boot image: with a vendor ramdisk
- Bootconfig feature (v4)

Change andr_img_hdr struct name to maintain support for version v0,
v1 and v2 while introducing version 3 and 4.

Signed-off-by: Safae Ouajih <souajih@baylibre.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
Tested-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
2023-04-04 14:50:46 -04:00
Marek Vasut
771cb4d58b image: Fix potentially uninitialized data variable
In case fitImage support is disabled, and image_locate_script() is
passed a fitImage, then the 'data' variable is used uninitialized.
Drop into the default: branch of the switch-case statement and do
not return the uninitialized data, and do not modify the return
pointer either, just print an error message.

Reported by clang build:
"
$ make HOSTCC=clang CC=clang KCFLAGS=-Werror sandbox64_defconfig && make HOSTCC=clang CC=clang KCFLAGS=-Werror
...
boot/image-board.c:1006:7: error: variable 'data' is used uninitialized whenever switch case is taken [-Werror,-Wsometimes-uninitialized]
        case IMAGE_FORMAT_LEGACY:
             ^~~~~~~~~~~~~~~~~~~
include/image.h:608:29: note: expanded from macro 'IMAGE_FORMAT_LEGACY'
                                ^~~~
boot/image-board.c:1128:19: note: uninitialized use occurs here
        *datap = (char *)data;
                         ^~~~
boot/image-board.c:1001:11: note: initialize the variable 'data' to silence this warning
        u32 *data;
                 ^
                  = NULL
"

Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2023-03-30 15:09:58 -04:00
Tom Rini
605bc145f9 Merge branch 'master' into next 2023-03-27 15:19:57 -04:00
Simon Glass
a0c739c184 boot: Create a common BOOT_DEFAULTS for distro and bootstd
These two features use a lot of common options. Move them into a common
CONFIG to reduce duplication.

Use 'select' for most options since these are things that boards aren't
supposed to override. For now it is not possible to disable
BOOT_DEFAULTS but we may take another look later.

Note that five options use 'imply' to match existing behaviour.

Signed-off-by: Simon Glass <sjg@chromium.org>
[trini: Rework a bit so we don't grow so many platforms unintentionally]
Signed-off-by: Tom Rini <trini@konsulko.com>
2023-03-27 11:16:04 -04:00
Simon Glass
febb985261 lmb: Enable LMB if SYS_BOOT_RAMDISK_HIGH
Ramdisk relocation requires LMB, so enable it automatically to avoid
build errors.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-03-27 11:16:04 -04:00
Simon Glass
c9d4abee6d Move DISTRO_DEFAULTS into boot/
This relates to booting so move it in to that Kconfig file, before
changing it.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-03-27 11:16:04 -04:00
Simon Glass
47dd6b4d7d bootstd: Replicate the dtb-filename quirks of distroboot
For EFI, the distro boot scripts search in three different directories
for the .dtb file. The SOC-based filename fallback is supported only for
32-bit ARM.

Adjust the code to mirror this behaviour.

Also some boards can use a prior-stage FDT if one is not found in the
normal way. Support this and show a message in that case.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Mark Kettenis <kettenis@openbsd.org>
2023-03-08 11:40:49 -08:00
Simon Glass
4f806f31fc bootflow: Rename bootflow_flags_t
These flags actually relate to the iterator, not the bootflow struct
itself. Rename them.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-03-08 11:40:49 -08:00
Simon Glass
1c419582f6 bootstd: Correct 'VPL' typo
Correct a 'VPL' typo in the Kconfig.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-03-02 17:45:58 -05:00
Simon Glass
1d46753395 Correct SPL use of DM_RNG
This converts 1 usage of this option to the non-SPL form, since there is
no SPL_DM_RNG defined in Kconfig

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-03-02 17:45:58 -05:00
Simon Glass
da900e527b boot: Add Kconfigs for BOOTMETH_VBE_REQUEST
Allow this to be enabled separately in U-Boot proper and in SPL, since
it is not needed in SPL.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-03-02 17:45:58 -05:00
Simon Glass
714c8f2222 bootstd: Disable QFW bootmeth in SPL
Move this Makefile line into the non-SPL area so we don't have to repy
on the SPL_TPL_ macro.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-03-02 17:45:57 -05:00
Simon Glass
c9696b177d Correct SPL uses of CMD_BOOTEFI_BOOTMGR
This converts 3 usages of this option to the non-SPL form, since there is
no SPL_CMD_BOOTEFI_BOOTMGR defined in Kconfig

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2023-02-10 07:41:41 -05:00
Simon Glass
210af54947 Correct SPL uses of LMB
This converts 9 usages of this option to the non-SPL form, since there is
no SPL_LMB defined in Kconfig

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-02-10 07:41:39 -05:00
Simon Glass
39c0da4186 Correct SPL use of CMD_PSTORE
This converts 1 usage of this option to the non-SPL form, since there is
no SPL_CMD_PSTORE defined in Kconfig

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-02-09 16:32:26 -05:00
Simon Glass
3a09f38d5e Correct SPL uses of CMD_FDT
This converts 2 usages of this option to the non-SPL form, since there is
no SPL_CMD_FDT defined in Kconfig

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-02-09 16:32:25 -05:00
Simon Glass
494bcf1af7 Correct SPL uses of CMD_BOOTM_PRE_LOAD
This converts 2 usages of this option to the non-SPL form, since there is
no SPL_CMD_BOOTM_PRE_LOAD defined in Kconfig

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-02-09 16:32:25 -05:00
Simon Glass
ef65aa3572 Correct SPL use of CMD_BOOTI
This converts 1 usage of this option to the non-SPL form, since there is
no SPL_CMD_BOOTI defined in Kconfig

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-02-09 16:32:25 -05:00
Simon Glass
9c6d57dc7e qemu: Add a bootmeth for qfw
This supports reading a kernel and ramdisk from qfw, then loading it with
either the booti or bootz commands.

For now this uses the existing booti and bootz commands, rather than
trying to call that functionality directly (e.g. do_bootm_states()). It
does not require the HUSH parser though, which helps a little with size.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-02-06 13:04:53 -05:00
Simon Glass
22353fa6b5 bootstd: Add some default filesystems and commands
We need to support a basic set of filesystems for booting to work in most
cases. Add these in via a new option, letting the board disable them
individually (for space reasons) if desired.

This enables the filesystem commands as well as the actual functionality,
even though bootstd is quite happy to use ext4 without the ext4 command.
Further work would be needed to disintangle this and reduce code size.

Add several other options as well, providing sensible defaults.

We cannot enable this by default, since it expands the size of many
boards quite a lot.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-02-06 13:04:53 -05:00
Simon Glass
965020c3f7 bootstd: Probe the block device before use
In some cases the block device is obtained but is not probed, since it
is a sibling of the bootdev. Make sure it is probed, so it can be used
without any trouble.

This fixes a bug with virtio, where the device is accessed before it has
been set up by the virtio uclass.

Signed-off-by: Simon Glass <sjg@chromium.org>
Fixes: 201417d700 ("bootstd: Add the bootdev uclass")
Reported-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2023-02-06 13:04:53 -05:00
Simon Glass
0041b1c09a bootstd: Allow enabling BOOTSTD_FULL without needing EXPO
It is sometimes useful to have one without the other, e.g. on a device
without a display, since at present the expo feature requires CONFIG_VIDEO
to be enabled.

Update the Makefile and bootflow command to support this, as well as the
EXPO dependency.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-02-06 13:04:53 -05:00
Simon Glass
f738c73a2b bootstd: Add a little more logging of bootflows
Add some logging to aid debugging of problems with bootflows.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-01-23 18:11:41 -05:00
Simon Glass
a950f2855a bootstd: Record the bootdevs used during scanning
Add a way to record the bootdevs used when scanning for bootflows. This is
useful for testing.

Enable this only with BOOTSTD_FULL and do the same for the progress
reporting.

Re-enable and update the affected tests now that we have this feature.

For bootdev_test_order_default() there is no-longer any support for using
the bootdev aliases to specify an ordering, so drop that part of the test.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-01-23 18:11:41 -05:00
Simon Glass
4b7cb058df bootstd: Drop the old bootflow_scan_first()
This function is not used outside tests. Drop it and rename
bootflow_scan_dev() since it is how we start a scan now.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-01-23 18:11:41 -05:00
Simon Glass
91943ff703 bootstd: Allow scanning a single bootdev label
We want to support scanning a single label, like 'mmc' or 'usb0'. Add
this feature by plumbing the label through to the iterator, setting a
flag to indicate that only siblings of the initial device should be used.

This means that scanning a bootdev by its name is not supported anymore.
That feature doesn't seem very useful in practice, so it is no great loss.

Add a test for bootdev_find_by_any() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-01-23 18:11:41 -05:00
Simon Glass
47aedc29dc bootstd: Switch bootdev scanning to use labels
At present we set up the bootdev order at the start, then scan the
bootdevs one by one.

However this approach cannot be used with hunters, since the bootdevs may
not exist until the hunter is used. Nor can we just run all the hunters at
the start, since that violate's U-Boot's 'lazy init' requirement. It also
increases boot time.

So we need to adjust the algorithm to scan by labels instead. As a first
step, drop the dev_order[] array in favour of a list of labels. Update the
name of bootdev_setup_iter_order() to better reflect what it does.

Update some related comments and log messages. Also disable a few tests
until a later commit where we can use them.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-01-23 18:11:41 -05:00
Simon Glass
43e89a3069 bootstd: Allow iterating to the next bootdev priortiy
Add a function which moves to the next priority to be processed.

This works by storing the current priority in the bootflow iterator. The
logic to set this up is included in a subsequent commit.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-01-23 18:11:41 -05:00
Simon Glass
e4b694893f bootstd: Allow iterating to the next label in a list
Add a function which moves to the next label in a list of labels. This
allows processing the boot_targets environment variable.

This works using a new label list in the bootflow iterator. The logic to
set this up is included in a subsequent commit.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-01-23 18:11:41 -05:00
Simon Glass
66e3dce787 bootstd: Allow hunting for a bootdev by label
Add a function to hunt for a bootdev label and find the bootdev produced
by the hunter (or already present).

Add a few extra flags so that we can distinguish between "mmc1", "mmc" and
"1" which all need to be handled differently.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-01-23 18:11:41 -05:00
Simon Glass
eacc261178 bootstd: Add a new pre-scan priority for bootdevs
We need extensions to be set up before we start trying to boot any of the
bootdevs. Add a new priority before all the others for tht sort of thing.
Also add a 'none' option, so that the first one is not 0.

While we are here, comment enum bootdev_prio_t fully and expand the test
for the 'bootdev hunt' command.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-01-23 18:11:41 -05:00
Simon Glass
79a7d4a61f bootstd: Allow hunting for bootdevs of a given priority
Add a way to run the hunter function for a particular priority, so that
new bootdevs can be found.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-01-23 18:11:41 -05:00
Simon Glass
d9f48579dc bootstd: Treat DHCP and PXE as bootdev labels
These are associated with the ethernet boot device but do not match its
uclass name, so handle them as special cases.

Provide a way to pass flags through with the bootdev so that we know
how to process it. The flags are checked by the bootmeths, to ensure that
only the selected bootmeth is used.

While these both use the network device, they work quite differently. It
is common to run only one of these, or to run PXE before DHCP. Provide
bootflow flags to control which methods are used. Check these in the two
bootmeths so that only the chosen one is used.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-01-23 18:11:41 -05:00
Simon Glass
5143a41e10 bootstd: Support reading a script from network or SPI flash
At present this bootmeth only supports a block device and the sandbox
host filesystem. Add support for obtaining the script from a network
device. Also implement the set_bootflow() method so that it is easy
for other bootdevs (such as enabling SPI flash to support scripts).

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-01-23 18:11:41 -05:00
Simon Glass
0c1f4a9fb1 bootstd: Add a SPI flash bootdev
Add a bootdev for SPI flash so that these devices can be used with
standard boot. It only supports loading a script.

Add a special case for the label, since we want to use "spi", not
"spi_flash".

Enable the new bootdev on sandbox.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-01-23 18:11:41 -05:00
Simon Glass
22061d3d2a bootstd: Add a new bootmeth method to set the bootflow
Normally the bootmeth driver reads the bootflow from the bootdev, since
it knows the correct way to do it.

However it is easier for some bootdevs to handle this themselves. For
example, reading from SPI flash is quite different from other devices.

Add a way for the bootdev to pass a bootflow to the bootmeth, so that
this can be supported.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-01-23 18:11:41 -05:00
Simon Glass
74ebfb60f6 bootstd: Move label parsing into its own function
This is complicated enough to merit its own function, particularly as we
are about to add to it. Create a new label_to_uclass() function to decode
a label.

Also update the code to ignore an empty label or one consisting of just a
number.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-01-23 18:11:41 -05:00