diff options
author | Tom Rini <trini@konsulko.com> | 2025-06-26 08:13:03 -0600 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2025-06-26 08:33:42 -0600 |
commit | 579d1a1bb77004d0e22d9db6de12fe87cac44055 (patch) | |
tree | 6ebae9d54675880c7a71214b384c4249ecc570d6 /test | |
parent | 40e083353a1610276f12fdbe613bf12004452656 (diff) | |
parent | 647931cfeda1ed594904e7dd4262783a264cb97a (diff) |
Merge patch series "mkimage: validate image references in FIT configurations"
Aristo Chen <jj251510319013@gmail.com> says:
This series introduces a validation step in mkimage to ensure that all image
names referenced under the /configurations node of a FIT source (ITS) are
actually defined under the /images node.
### Motivation
When using mkimage to build FIT images, it's easy to mistakenly reference
nonexistent image nodes in configurations (e.g., referencing a missing `fdt` or
`firmware` node). Such issues are often not caught until runtime in U-Boot.
This series aims to catch these errors early during FIT image creation by
validating the configuration references in mkimage itself.
Link: https://lore.kernel.org/r/20250610074121.8308-1-aristo.chen@canonical.com
Diffstat (limited to 'test')
-rw-r--r-- | test/py/tests/test_fit_mkimage_validate.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/test/py/tests/test_fit_mkimage_validate.py b/test/py/tests/test_fit_mkimage_validate.py new file mode 100644 index 00000000000..af56f08ca10 --- /dev/null +++ b/test/py/tests/test_fit_mkimage_validate.py @@ -0,0 +1,58 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (c) 2025 +# +# Test that mkimage validates image references in configurations + +import os +import subprocess +import pytest +import fit_util + +@pytest.mark.boardspec('sandbox') +@pytest.mark.requiredtool('dtc') +def test_fit_invalid_image_reference(ubman): + """Test that mkimage fails when configuration references a missing image""" + + its_fname = fit_util.make_fname(ubman, "invalid.its") + itb_fname = fit_util.make_fname(ubman, "invalid.itb") + kernel = fit_util.make_kernel(ubman, 'kernel.bin', 'kernel') + + # Write ITS with an invalid reference to a nonexistent image + its_text = ''' +/dts-v1/; + +/ { + images { + kernel@1 { + description = "Test Kernel"; + data = /incbin/("kernel.bin"); + type = "kernel"; + arch = "sandbox"; + os = "linux"; + compression = "none"; + load = <0x40000>; + entry = <0x40000>; + }; + }; + + configurations { + default = "conf@1"; + conf@1 { + kernel = "kernel@1"; + fdt = "notexist"; + }; + }; +}; +''' + + with open(its_fname, 'w') as f: + f.write(its_text) + + mkimage = os.path.join(ubman.config.build_dir, 'tools/mkimage') + cmd = [mkimage, '-f', its_fname, itb_fname] + + result = subprocess.run(cmd, capture_output=True, text=True) + + assert result.returncode != 0, "mkimage should fail due to missing image reference" + assert "references undefined image 'notexist'" in result.stderr + |