Compare commits

..

13 Commits
hein ... load2

Author SHA1 Message Date
Simon Glass
fa1373c3aa boot: Tidy local variables in fit_image_load()
Arrange these so that they look a little nicer.

Series-to: concept
Series-version: 2
Cover-letter:
boot: Make fit_image_load() easier to maintain
Before fit_image_load() was created, The code to load kernels, ramdisks
and devicetrees from a FIT was spread around many functions. By
combining most of the code in one place, it became possible to add more
features in a consistent way. The 'loadables' feature much easier to
plumb in, for example.

While fit_image_load() was a substantial advance, it has never been a
svelte function and the passing years have not been entirely kind. With
a few new features on the horizon, this is a good time to improve the
implementation.

This series splits much of the code from fit_image_load() into a number
of smaller functions. Most of the changes are fairly mechanical, with
just a few renames and tweaks here and there.

This should make the function much easier to maintain. It may also
encourage someone to take a look at its callers, which could also use
some attention.
END

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-24 05:29:41 -06:00
Simon Glass
4cbec6514c boot: Drop unnecessary data variable
This is always the same as 'buf' and is not used in any case. Drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-24 05:29:41 -06:00
Simon Glass
e7c96ff2f1 boot: Move setting the OS arch into check_allowed()
Remove a few more lines from fit_image_load() by dealing with this small
detail in check_allowed().

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-24 05:29:41 -06:00
Simon Glass
a202086895 boot: Move decomp_image() into handle_load_op()
Decompress is really part of loading, so simplify the code slightly by
moving decompression out of the top-level fit_image_load() function.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-24 05:29:41 -06:00
Simon Glass
9abeaefb5d boot: Move image-decompression into a separate function
Move handling of decompression (or perhaps relocation) of the image into
a separate function, to slim down fit_image_load() a little more.

Move the bootstage_mark() call in there too.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-24 05:29:41 -06:00
Simon Glass
94eb16fb83 boot: Move the architecture check into check_allowed()
We may as well have all the checks together, so move the call to
fit_image_check_target_arch() into check_allowed().

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-24 05:29:41 -06:00
Simon Glass
e773d28569 boot: Check the image is allowed before setting os.arch
There is no point in setting the architecture if the image cannot be
used. Move the check a little higher within fit_image_load().

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-24 05:29:41 -06:00
Simon Glass
c5ac209185 boot: Move obtaining data from a FIT image into a function
Move this code into a separate function, to help further slim down
fit_image_load().

Move the bootstage_mark() call in there too.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-24 05:29:41 -06:00
Simon Glass
c0c3344dcd boot: Move handling of the load_op into a separate function
Since fit_image_load() is still too long, move the load-operation
handling into a separate function.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-24 05:29:41 -06:00
Simon Glass
7815320ce0 boot: Move type and OS checking into a new function
Move the code which checks whether the image can be loaded into a
separate check_allowed() function.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-24 05:29:41 -06:00
Simon Glass
ec74b112e5 boot: Tidy up setting of the OS arch on host builds
This field is not present in host builds. Create an inline function to
handle this complexity, so we can drop the #ifdef in the C file.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-24 05:29:41 -06:00
Simon Glass
9803c5dd01 boot: Move call to fit_image_select() and rename it
This function is named a bit vaguely, since it prints some info and then
does verification of the image.

Rename it to print_and_verify() and move the call to select_image().

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-24 05:29:40 -06:00
Simon Glass
d73458d098 boot: Split out the first part of fit_image_load()
This function is over 250 lines long. Split out the image-selection part
into its own function.

Series-changes: 2
- Drop separate fit_uname variable in select_image()

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-24 05:28:25 -06:00

View File

@@ -178,9 +178,10 @@ sct_mnt = /mnt/sct
else:
tout.warning(f"Disk image '{disk}' not found")
cmd.extend(['-object', 'rng-random,filename=/dev/random,id=rng0',
'-device',
'virtio-rng-pci,rng=rng0,max-bytes=1024,period=1000'])
if args.rand:
cmd.extend(['-object', 'rng-random,filename=/dev/random,id=rng0',
'-device',
'virtio-rng-pci,rng=rng0,max-bytes=1024,period=1000'])
def add_common_args(parser):
"""Add some arguments which are common to build-efi/qemu scripts
@@ -210,6 +211,8 @@ def add_common_args(parser):
parser.add_argument(
'-R', '--release', default='24.04.1',
help='Select OS release version (e.g, 24.04) Default: 24.04.1')
parser.add_argument('--rand', '--random', action='store_true',
help='Provide a random-number device')
parser.add_argument('-s', '--serial-only', action='store_true',
help='Run QEMU with serial only (no display)')
parser.add_argument(