bootstd: Support scripts in raw partitions
PATCH v3 2/4 bootstd: Export the script bootflow execution handler
In reply to He YongMake script_boot() available as bootmeth_script_boot() so another bootmeth can reuse the device environment setup and script execution without duplicating the filesystem script bootmeth's handler.
---
Changes in v3:
- Split the shared script execution-handler export into its own patch.
boot/bootmeth_script.c | 4 ++-- include/bootmeth.h | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-)
boot/bootmeth_script.c +2 -2
@@ -188,7 +188,7 @@ static int script_set_bootflow(struct udevice *dev, struct bootflow *bflow,return 0 ; } -static int script_boot (struct udevice *dev,struct bootflow *bflow) +int bootmeth_script_boot (struct udevice *dev,struct bootflow *bflow) {struct blk_desc *desc;ulong addr;
@@ -258,7 +258,7 @@ static struct bootmeth_ops script_bootmeth_ops = { .read_bootflow = script_read_bootflow, .set_bootflow = script_set_bootflow, .read_file = bootmeth_common_read_file, - .boot = script_boot, + .boot = bootmeth_script_boot, };static const struct udevice_id script_bootmeth_ids[] = {
include/bootmeth.h +12 -0
@@ -425,4 +425,16 @@ int bootmeth_common_read_file(struct udevice *dev, struct bootflow *bflow,*/ int bootmeth_get_bootflow (struct udevice *dev,struct bootflow *bflow); +/** +* bootmeth_script_boot() - Execute a script bootflow +* +* Set the device and partition environment variables and execute the script +* stored in the bootflow buffer. +* +* @dev: Bootmeth device +* @bflow: Bootflow containing the script image +* @return 0 on success, or a error code +*/ +int bootmeth_script_boot (struct udevice *dev,struct bootflow *bflow); +#endif
Signature · 1 line
2.43.0
PATCH v3 1/4 image: Bound FIT script checks by the image size
In reply to He YongFIT verification can follow malformed metadata or external-data offsets beyond a buffer whose size is known to the caller.
Pass the known buffer size to fit_check_format() so FIT_FULL_CHECK validates the complete structure against the actual buffer. Reject external data in all subimages of known-size FITs before verification, even when verify is disabled. Keep these checks in the shared parser so filesystem and raw-partition scripts receive the same protection. Leave unknown-size FIT handling unchanged.
Add C regression coverage with verification enabled and disabled, plus source coverage. Clear verify even when a test helper assertion fails.
---
Changes in v3:
- Replace the legacy parser changes with shared known-size FIT validation.
- Reject external data before verification and cover both verify settings.
boot/image-board.c | 19 +++++++- test/boot/image.c | 118 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+), 1 deletion(-)
boot/image-board.c +18 -1
@@ -1043,11 +1043,28 @@ int image_locate_script(void *buf, int size, const char *fit_uname, goto exit_image_format; }else { fit_hdr = buf; -if (fit_check_format (fit_hdr,IMAGE_SIZE_INVAL )) { +if (fit_check_format (fit_hdr, + size ? size :IMAGE_SIZE_INVAL )) {puts ("Bad FIT image format\n" );return 1 ; } +if (size) { +int images, node; + +/* Reject external data before any verification reads. */ + images =fdt_path_offset (fit_hdr,FIT_IMAGES_PATH ); +fdt_for_each_subnode (node, fit_hdr, images) { +if (fdt_getprop (fit_hdr, node, +FIT_DATA_OFFSET_PROP ,NULL ) || +fdt_getprop (fit_hdr, node, +FIT_DATA_POSITION_PROP ,NULL )) { +puts ("External FIT script data is not supported\n" ); +return 1 ; + } + } + } +if (!fit_uname) {/* If confname is empty, use the default */ if (confname && *confname)
test/boot/image.c +118 -0
128 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v3 3/4 bootstd: Add a bootmeth for scripts in raw partitions
In reply to He YongSome disk layouts store a U-Boot script image directly in a named partition, without a filesystem. Add a script_raw bootmeth to find these images without a board-specific bootcmd.
Read the image size from the first block and bound it by the partition size and configured limit. Support legacy scripts and FIT scripts with embedded data, using the shared script parser for validation and the shared execution handler for booting.
Keep raw-partition scanning independently selectable from filesystem script lookup. Document the configuration and self-contained FIT policy.
---
Changes in v3:
- Move shared FIT checks, handler export and sandbox tests to separate patches.
MAINTAINERS | 1 + boot/Kconfig | 26 +++++ boot/Makefile | 1 + boot/bootmeth_script_raw.c | 152 ++++++++++++++++++++++++++ doc/develop/bootstd/index.rst | 1 + doc/develop/bootstd/script_raw.rst | 51 +++++++++ doc/device-tree-bindings/bootmeth.txt | 1 + 7 files changed, 233 insertions(+) create mode 100644 boot/bootmeth_script_raw.c create mode 100644 doc/develop/bootstd/script_raw.rst
MAINTAINERS +1 -0
@@ -846,6 +846,7 @@ F: include/bootflow.h F: include/bootmeth.h F: include/bootstd.h F: test/boot/ +F: test/py/img/script_raw.py BOOTMETH_ANDROID M: Mattijs Korpershoek <[email protected]>
boot/Kconfig +26 -0
@@ -1009,6 +1009,32 @@ config BOOTMETH_SCRIPT This provides a way to try out standard boot on an existing boot flow. It is not enabled by default to save space. +config BOOTMETH_SCRIPT_RAW + bool "Boot from a script in a raw partition" + depends on BOOTMETH_SCRIPT && BLK && PARTITIONS + depends on LEGACY_IMAGE_FORMAT || FIT + help + Locate a named partition and read a U-Boot script image directly from + its first block, without a filesystem. This adds the script_raw boot + method. Legacy script images and FIT scripts with embedded data are + supported. + +config BOOTMETH_SCRIPT_RAW_PARTITION + string "Raw script partition name" + depends on BOOTMETH_SCRIPT_RAW + default "uboot_scr" + help + Partition label to match when scanning for a raw script image. + +config BOOTMETH_SCRIPT_RAW_MAX_SIZE + hex "Maximum raw script image size" + depends on BOOTMETH_SCRIPT_RAW + default 0x100000 + range 0x200 0x1000000 + help + Maximum script image size in bytes, including its image header. + The image must also fit within the selected partition. + config UPL bool "upl - Universal Payload Specification" imply CMD_UPL
boot/Makefile +1 -0
@@ -38,6 +38,7 @@ obj-$(CONFIG_$(PHASE_)BOOTMETH_QFW) += bootmeth_qfw.o obj-$(CONFIG_$(PHASE_)BOOTMETH_RAUC) += bootmeth_rauc.o obj-$(CONFIG_$(PHASE_)BOOTMETH_SANDBOX) += bootmeth_sandbox.o obj-$(CONFIG_$(PHASE_)BOOTMETH_SCRIPT) += bootmeth_script.o +obj-$(CONFIG_$(PHASE_)BOOTMETH_SCRIPT_RAW) += bootmeth_script_raw.o obj-$(CONFIG_$(PHASE_)CEDIT) += cedit.o obj-$(CONFIG_$(PHASE_)BOOTMETH_EFI_BOOTMGR) += bootmeth_efi_mgr.o
boot/bootmeth_script_raw.c new file +152 -0
152 lines not on this page · raw message
doc/develop/bootstd/index.rst +1 -0
@@ -15,4 +15,5 @@ Standard Boot cros rauc script + script_raw sandbox
doc/develop/bootstd/script_raw.rst new file +51 -0
51 lines not on this page · raw message
doc/device-tree-bindings/bootmeth.txt +1 -0
@@ -11,6 +11,7 @@ compatible: "u-boot,extlinux-pxe" - distro boot from a network device "u-boot,distro-efi" - EFI boot from an .efi file "u-boot,efi-bootmgr" - EFI boot using boot manager (bootmgr) + "u-boot,script-raw" - script boot from a named raw partition Example:
Signature · 1 line
2.43.0
PATCH v3 4/4 test: bootstd: Cover scripts in raw partitions on sandbox
In reply to He YongEnable script_raw for sandbox and add a GPT disk with valid legacy and FIT scripts, as well as malformed and unsupported images. Bind the bootmeth inside the new C test so existing bootmeth lists and bootflow tests, including bootflow scan -G coverage, remain unchanged.
Introduce test/py/img/ as a package for disk-image generators. Existing C-test image setup lives in test/py/tests/test_ut.py; keep the raw-script case definitions and image generation in the new module and call it from the existing test_ut_dm_init_bootstd() initialization.
Allow fs_helper.setup_image() to accept an sfdisk partition specification and reuse it for the named GPT partitions. This avoids a dependency on sgdisk or a separate initialization test. Annotate each expected C error with its Python case name to keep the two lists in sync.
---
Changes in v3:
- Split sandbox coverage into its own patch.
- Bind script_raw only inside its test and preserve existing scan -G coverage.
- Annotate expected errors with Python case names.
- Reuse fs_helper and sfdisk from the existing bootstd initialization test.
arch/sandbox/dts/test.dts | 8 ++++ configs/sandbox_defconfig | 1 + test/boot/bootflow.c | 81 +++++++++++++++++++++++++++++++ test/py/img/__init__.py | 2 + test/py/img/script_raw.py | 98 ++++++++++++++++++++++++++++++++++++++ test/py/tests/fs_helper.py | 19 +++++--- test/py/tests/test_ut.py | 3 ++ 7 files changed, 205 insertions(+), 7 deletions(-) create mode 100644 test/py/img/__init__.py create mode 100644 test/py/img/script_raw.py
arch/sandbox/dts/test.dts +8 -0
@@ -50,6 +50,7 @@ mmc9 = "/mmc9"; mmc10 = "/mmc10"; mmc11 = "/mmc11"; + mmc12 = "/mmc12"; pci0 = &pci0; pci1 = &pci1; pci2 = &pci2;
@@ -1398,6 +1399,13 @@ filename = "mmc11.img"; }; + /* This is used for raw script bootflow tests */ + mmc12 { + status = "disabled"; + compatible = "sandbox,mmc"; + filename = "mmc12.img"; + }; + pch { compatible = "sandbox,pch"; };
configs/sandbox_defconfig +1 -0
@@ -28,6 +28,7 @@ CONFIG_FIT_VERBOSE=y CONFIG_BOOTMETH_ANDROID=y CONFIG_BOOTMETH_BLS=y CONFIG_BOOTMETH_RAUC=y +CONFIG_BOOTMETH_SCRIPT_RAW=y CONFIG_UPL=y CONFIG_LEGACY_IMAGE_FORMAT=y CONFIG_MEASURED_BOOT=y
test/boot/bootflow.c +81 -0
91 lines not on this page · raw message
test/py/img/__init__.py new file +2 -0
@@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0+ +"""Disk-image generators for U-Boot C tests."""
test/py/img/script_raw.py new file +98 -0
98 lines not on this page · raw message
test/py/tests/fs_helper.py +12 -7
@@ -8,7 +8,7 @@ import re import os import shutil -from subprocess import call, check_call, check_output, CalledProcessError +from subprocess import call, check_call, check_output, CalledProcessError, run from subprocess import DEVNULL import tempfile
@@ -262,8 +262,8 @@ def mk_fs(config, fs_type, size, prefix, src_dir=None, fs_img=None, quiet=False) raise def setup_image(ubman, devnum, part_type, img_size=20, second_part=False, - basename='mmc'): - """Create a disk image with one or two partitions + basename='mmc', part_spec=None): + """Create a disk image with default or caller-specified partitions Args: ubman (ConsoleBase): Console to use
@@ -272,6 +272,8 @@ def setup_image(ubman, devnum, part_type, img_size=20, second_part=False, img_size (int): Image size in MiB second_part (bool): True to contain a small second partition basename (str): Base name to use in the filename, e.g. 'mmc' + part_spec (str): Optional sfdisk partition specification, overriding + part_type and second_part Returns: tuple:
@@ -281,14 +283,17 @@ def setup_image(ubman, devnum, part_type, img_size=20, second_part=False, fname = os.path.join(ubman.config.source_dir, f'{basename}{devnum}.img') mnt = os.path.join(ubman.config.persistent_data_dir, 'scratch') - spec = f'type={part_type:x}, size={img_size - 2}M, start=1M, bootable' - if second_part: - spec += '\ntype=c' + spec = part_spec + if spec is None: + spec = f'type={part_type:x}, size={img_size - 2}M, start=1M, bootable' + if second_part: + spec += '\ntype=c' try: check_call(f'mkdir -p {mnt}', shell=True) check_call(f'qemu-img create {fname} {img_size}M', shell=True) - check_call(f'printf "{spec}" | sfdisk {fname}', shell=True) + # Pass the specification directly, including quoted GPT names. + run(['sfdisk', fname], input=spec.encode(), check=True) except CalledProcessError: call(f'rm -f {fname}', shell=True) raise
test/py/tests/test_ut.py +3 -0
@@ -16,6 +16,7 @@ import re import pytest import utils +from img.script_raw import setup_script_raw_image # pylint: disable=E0611 from tests import fs_helper from fs_helper import DiskHelper, FsHelper
@@ -755,6 +756,8 @@ def test_ut_dm_init_bootstd(ubman): setup_efi_image(ubman) setup_rauc_image(ubman) setup_bls_prefix_image(ubman) + if ubman.config.buildconfig.get('config_bootmeth_script_raw') == 'y': + setup_script_raw_image(ubman) # Restart so that the new mmc1.img is picked up ubman.restart_uboot()
Signature · 1 line
2.43.0
v3 cover bootstd: Support scripts in raw partitions
This series adds a script_raw bootmeth for U-Boot script images stored at the start of a named partition, without a filesystem or a board-specific bootcmd. It supports legacy scripts and FIT scripts with embedded data. Image reads are bounded by the partition size and a configurable limit.
The raw and filesystem script bootmeths share the execution handler and script parser. For known-size FIT scripts, the parser passes the buffer size to fit_check_format() and rejects external data before verification. The existing FIT_FULL_CHECK configuration controls full structural checks.
Changes since v2:
- Split the series into shared FIT validation, execution-handler export, the raw bootmeth, and sandbox tests.
- Drop the legacy parser bounds-check changes from this series.
- Move known-size FIT validation and external-data rejection into the shared script parser, with tests for both verify settings and source.
- Bind script_raw inside its C test, following bootflow_rauc(), so existing bootmeth lists and bootflow tests stay unchanged, including -G coverage.
- Label each expected C error with its corresponding Python case name.
- Reuse fs_helper.setup_image() with an sfdisk partition specification and generate the disk from test_ut_dm_init_bootstd(), avoiding sgdisk and a separate initialization test.
- Preserve the CONFIG_SANDBOX comment and clear verify on helper failure.
Validation on this revision:
- Sandbox build: make O=build-sandbox -j8
- Sandbox pytest: 3 passed (bootstd image initialization, image_fit_script_bounds and bootflow_script_raw)
Previous version:
https://www.mail-archive.com/[email protected]/msg09207.html
He Yong (4):
image: Bound FIT script checks by the image size
bootstd: Export the script bootflow execution handler
bootstd: Add a bootmeth for scripts in raw partitions
test: bootstd: Cover scripts in raw partitions on sandbox
MAINTAINERS | 1 + arch/sandbox/dts/test.dts | 8 ++ boot/Kconfig | 26 +++++ boot/Makefile | 1 + boot/bootmeth_script.c | 4 +- boot/bootmeth_script_raw.c | 152 ++++++++++++++++++++++++++ boot/image-board.c | 19 +++- configs/sandbox_defconfig | 1 + doc/develop/bootstd/index.rst | 1 + doc/develop/bootstd/script_raw.rst | 51 +++++++++ doc/device-tree-bindings/bootmeth.txt | 1 + include/bootmeth.h | 12 ++ test/boot/bootflow.c | 81 ++++++++++++++ test/boot/image.c | 118 ++++++++++++++++++++ test/py/img/__init__.py | 2 + test/py/img/script_raw.py | 98 +++++++++++++++++ test/py/tests/fs_helper.py | 19 ++-- test/py/tests/test_ut.py | 3 + 18 files changed, 588 insertions(+), 10 deletions(-) create mode 100644 boot/bootmeth_script_raw.c create mode 100644 doc/develop/bootstd/script_raw.rst create mode 100644 test/py/img/__init__.py create mode 100644 test/py/img/script_raw.py
base-commit: 0a55b098d6f5f6bafa84fc2f18b433dd167bf729
Signature · 1 line
2.43.0
Re: [PATCH v3 1/4] image: Bound FIT script checks by the image size
In reply to He YongHi He,
Quoted 28 lines · He Yong
image: Bound FIT script checks by the image size
FIT verification can follow malformed metadata or external-data offsets beyond a buffer whose size is known to the caller.
Pass the known buffer size to
fit_check_format()soFIT_FULL_CHECKvalidates the complete structure against the actual buffer. Reject external data in all subimages of known-size FITs before verification, even when verify is disabled. Keep these checks in the shared parser so filesystem and raw-partition scripts receive the same protection. Leave unknown-size FIT handling unchanged.Add C regression coverage with verification enabled and disabled, plus source coverage. Clear verify even when a test helper assertion fails.
Signed-off-by He Yong <[email protected]>boot/image-board.c | 19 ++++++++- test/boot/image.c | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+), 1 deletion(-)boot/image-board.c +5
-0@@ -1043,11 +1043,28 @@ int image_locate_script(void *buf, int size, const char *fit_uname, +if (size) { +int images, node; + +/* Reject external data before any verification reads. */ + images =fdt_path_offset (fit_hdr,FIT_IMAGES_PATH );
boot/image-board.c int image_locate_script(void *buf, int size, const char *fit_uname, · line 1057
Quoted 10 lines
boot/image-board.c +10
-0+fdt_for_each_subnode (node, fit_hdr, images) { +if (fdt_getprop (fit_hdr, node, +FIT_DATA_OFFSET_PROP ,NULL ) || +fdt_getprop (fit_hdr, node, +FIT_DATA_POSITION_PROP ,NULL )) { +puts ("External FIT script data is not supported\n" ); +return 1 ; + } + } + }
One thing I'd like to check before this goes in.. bootmeth_script already passes bflow->size, which is the size of the whole file it read. A FIT script built with 'mkimage -E' has its external data inside that file, so it works today and would be rejected after this patch. It also rejects the FIT if any other subimage (e.g. a kernel) uses external data, even if that subimage is never used.
Since 'size' is known, it would be better to check that each image's data-offset/data-position plus data-size lies within it, rejecting only images that go past the end. fit_image_get_data() already does similar range checks, so a size-aware version of that might be the natural place. The raw bootmeth would still be safe, since anything past fdt_totalsize() would fail the check. What do you think?
If you prefer to keep the blanket rejection, you should describe it in the commit message and doc as a behaviour change for filesystem scripts too, not just raw partitions. I'm not sure if it would affect anyone, but I'm a bit nervous about it.
boot/image-board.c int image_locate_script(void *buf, int size, const char *fit_uname, · line 1044
Quoted 5 lines
boot/image-board.c +2
-1@@ -1043,11 +1043,28 @@ int image_locate_script(void *buf, int size, const char *fit_uname, -if (fit_check_format (fit_hdr,IMAGE_SIZE_INVAL )) { +if (fit_check_format (fit_hdr, + size ? size :IMAGE_SIZE_INVAL )) {
With FIT_FULL_CHECK disabled, 'size' is ignored, so nothing stops fdt_totalsize() from exceeding the buffer. It would be worth adding a plain 'fdt_totalsize(fit_hdr) > size' check when size is non-zero. It costs nothing and makes the subject line true in all configurations.
Regards,
Simon
Re: [PATCH v3 2/4] bootstd: Export the script bootflow execution handler
In reply to He YongHi He,
Quoted 14 lines · He Yong
bootstd: Export the script bootflow execution handler
Make
script_boot()available asbootmeth_script_boot()so another bootmeth can reuse the device environment setup and script execution without duplicating the filesystem script bootmeth's handler.Signed-off-by He Yong <[email protected]>boot/bootmeth_script.c | 4 ++-- include/bootmeth.h | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-)
include/bootmeth.h int bootmeth_common_read_file(struct udevice *dev, struct bootflow *bflow, · line 430
Quoted 6 lines
include/bootmeth.h +6
-0@@ -425,4 +425,16 @@ int bootmeth_common_read_file(struct udevice *dev, struct bootflow *bflow, +* Set the device and partition environment variables and execute the script +* stored in the bootflow buffer. +* +* @dev: Bootmeth device +* @bflow: Bootflow containing the script image +* @return 0 on success, or a error code
Please can you use 'Return:' here (the kernel-doc form used by most of this file) and change 'a error code' to '-ve on error'.
It would be worth listing the bootflow fields this uses, since a new caller needs to know them: bflow->buf for the script, bflow->subdir for the 'prefix' variable, and bflow->blk and bflow->part for devtype/devnum/distro_bootpart. Patch 3 sets bflow->subdir to an empty string just to satisfy this, so it is easy to miss.
Regards,
Simon
Re: [PATCH v3 3/4] bootstd: Add a bootmeth for scripts in raw partitions
In reply to He YongHi He,
Quoted 27 lines · He Yong
bootstd: Add a bootmeth for scripts in raw partitions
Some disk layouts store a U-Boot script image directly in a named partition, without a filesystem. Add a
script_rawbootmeth to find these images without a board-specific bootcmd.Read the image size from the first block and bound it by the partition size and configured limit. Support legacy scripts and FIT scripts with embedded data, using the shared script parser for validation and the shared execution handler for booting.
Keep raw-partition scanning independently selectable from filesystem script lookup. Document the configuration and self-contained FIT policy.
Signed-off-by He Yong <[email protected]>MAINTAINERS | 1 + boot/Kconfig | 26 ++++++ boot/Makefile | 1 + boot/bootmeth_script_raw.c | 152 ++++++++++++++++++++++++++++++++++ doc/develop/bootstd/index.rst | 1 + doc/develop/bootstd/script_raw.rst | 51 ++++++++++++ doc/device-tree-bindings/bootmeth.txt | 1 + 7 files changed, 233 insertions(+)
MAINTAINERS F: include/bootflow.h · line 850
Quoted 4 lines
MAINTAINERS +1
-0@@ -847,6 +847,7 @@ F: include/bootflow.h F: include/bootmeth.h F: include/bootstd.h F: test/boot/ +F: test/py/img/script_raw.py
This file is only added in the next patch, so ideally you could move the MAINTAINERS change there.
Regards,
Simon
Re: [PATCH v3 4/4] test: bootstd: Cover scripts in raw partitions on sandbox
In reply to He YongHi He,
Quoted 12 lines · He Yong
test: bootstd: Cover scripts in raw partitions on sandbox
Enable
script_rawfor sandbox and add a GPT disk with valid legacy and FIT scripts, as well as malformed and unsupported images. Bind the bootmeth inside the new C test so existing bootmeth lists and bootflow tests, including bootflow scan -G coverage, remain unchanged.Introduce test/py/img/ as a package for disk-image generators. Existing C-test image setup lives in
test/py/tests/test_ut.py; keep the raw-script case definitions and image generation in the new module and call it from the existingtest_ut_dm_init_bootstd()initialization.
Quoted 4 lines
Allow
fs_helper.setup_image()to accept an sfdisk partition specification and reuse it for the named GPT partitions. This avoids a dependency on sgdisk or a separate initialization test. Annotate each expected C error with its Python case name to keep the two lists in sync.
The fs_helper change affects every caller of setup_image(), since it switches from printf | sfdisk to run(). Please can you put it in its own patch, before this one?
Quoted 14 lines
Signed-off-by He Yong <[email protected]>arch/sandbox/dts/test.dts | 8 ++++ configs/sandbox_defconfig | 1 + test/boot/bootflow.c | 81 ++++++++++++++++++++++++++++++++++++++ test/py/img/__init__.py | 2 + test/py/img/script_raw.py | 98 ++++++++++++++++++++++++++++++++++++++++++++++ test/py/tests/fs_helper.py | 19 +++++---- test/py/tests/test_ut.py | 3 ++ 7 files changed, 205 insertions(+), 7 deletions(-)
test/boot/bootflow.c static int bootdev_hunt_fallthrough(struct unit_test_state *uts) · line 1958
Quoted 10 lines
test/boot/bootflow.c +10
-0@@ -1948,4 +1949,84 @@ static int bootdev_hunt_fallthrough(struct unit_test_state *uts) +0 ,/* legacy */ +0 ,/* fit */ + -EINVAL ,/* external */ + -EINVAL ,/* bad_crc */ + -E2BIG ,/* too_large */ + -ENOENT ,/* wrong_name */ + -ENOEXEC ,/* empty */ + -EINVAL ,/* bad_header */ + -E2BIG ,/* partition_size */ + -EINVAL, /* bad_fit */
The raw bootmeth turns every image_locate_script() failure into -EINVAL, so the external, bad_crc and bad_fit cases cannot tell which check rejected the image. For example, if the external-data check in patch 1 were dropped, the external case would still get -EINVAL from somewhere else. Since the test already uses UTF_CONSOLE, it would be worth checking the message for each case too, e.g. 'External FIT script data is not supported' and 'Bad FIT image format'.
test/boot/bootflow.c static int bootdev_hunt_fallthrough(struct unit_test_state *uts) · line 1952
Quoted 6 lines
test/boot/bootflow.c +4
-0@@ -1948,4 +1949,84 @@ static int bootdev_hunt_fallthrough(struct unit_test_state *uts) +bootflow_free (&bflow); + } + +return 0 ;
Please can you check that the scan ends after the last partition (i.e. bootflow_scan_next() returns -ENODEV)? Otherwise an unexpected extra bootflow would go unnoticed.
test/boot/bootflow.c static int bootdev_hunt_fallthrough(struct unit_test_state *uts) · line 1951
Quoted 5 lines
test/boot/bootflow.c +3
-0@@ -1948,4 +1949,84 @@ static int bootdev_hunt_fallthrough(struct unit_test_state *uts) +ut_assertok (prep_mmc_bootdev (uts,"mmc12" , false, &old_order)); +ut_assertok (bootstd_get_priv (&std)); + std->bootdev_order = order;
prep_mmc_bootdev() also binds the script bootmeth and sets its own order {'mmc2', 'mmc1', 'mmc12'}, and you then override both straight away. It would be clearer to bind mmc12 directly with lists_bind_fdt() and set the order once, as bootflow_bls_prefix() and bootflow_rauc() do.
test/py/img/script_raw.py line 10
Quoted 12 lines
test/py/img/script_raw.py +10
-0@@ -0,0 +1,98 @@ + if case == 'bad_crc': + data[-1] ^= 1 + elif case == 'too_large': + struct.pack_into('>I', data, 12, 2 * 1024 * 1024) + elif case == 'empty': + data = bytearray(512) + if case == 'too_large': + struct.pack_into('>I', data, 4, 0) + struct.pack_into('>I', data, 4, zlib.crc32(data[:64])) + return data
The corruption is split between script_image() and setup_script_raw_image() for no obvious reason, and the header-CRC fix-up is repeated in both. Please can you put all the per-case changes in one place, with the CRC fix-up in a small helper? For 'empty' it would also be simpler to return early, before running mkimage.
Regards,
Simon