summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAristo Chen <[email protected]>2026-07-10 15:33:40 +0000
committerTom Rini <[email protected]>2026-07-23 13:42:49 -0600
commit7551ce097779014405bd4976e0f9f1246dbb80d7 (patch)
tree75f87a995f90e4f51ee82c41b05c177eb845a500
parenteecc4148fe61a53fa1f4d16ffb453c3901fc704f (diff)
test: py: add regression test for fit_import_data() stale state
Build an external-data FIT, remove the data-offset property from the second image so that only its data-size remains, and re-process the result with mkimage -F. mkimage must reject the malformed FIT with a clear diagnostic from the hashing stage. Previously the stale per-image state in fit_import_data() made the import copy the first image's data into the second image and abort without printing anything. Signed-off-by: Aristo Chen <[email protected]> Reviewed-by: Simon Glass <[email protected]>
-rw-r--r--test/py/tests/test_fit_import_data.py89
1 files changed, 89 insertions, 0 deletions
diff --git a/test/py/tests/test_fit_import_data.py b/test/py/tests/test_fit_import_data.py
new file mode 100644
index 00000000000..efbbad14262
--- /dev/null
+++ b/test/py/tests/test_fit_import_data.py
@@ -0,0 +1,89 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright 2026 Canonical Ltd.
+#
+# Test mkimage import of external data in fit_import_data()
+
+"""Regression test for stale per-image state in fit_import_data().
+
+The import loop used to keep the data pointer and external property name
+of the previous image, so an image node carrying data-size but neither
+data-offset nor data-position imported the previous image's data and
+then made mkimage abort without printing any diagnostic. Such a node
+must be skipped by the import and reported by the later processing
+stages instead.
+"""
+
+import os
+import subprocess
+
+import pytest
+
+import fit_util
+
+BASE_ITS = '''
+/dts-v1/;
+
+/ {
+ description = "import-data test";
+
+ images {
+ kernel-1 {
+ description = "first kernel";
+ data = /incbin/("%(kernel1)s");
+ type = "kernel";
+ arch = "sandbox";
+ os = "linux";
+ compression = "none";
+ load = <0x40000>;
+ entry = <0x40000>;
+ };
+ kernel-2 {
+ description = "second kernel";
+ data = /incbin/("%(kernel2)s");
+ type = "kernel";
+ arch = "sandbox";
+ os = "linux";
+ compression = "none";
+ load = <0x80000>;
+ entry = <0x80000>;
+ };
+ };
+
+ configurations {
+ default = "conf-1";
+ conf-1 {
+ kernel = "kernel-1";
+ };
+ };
+};
+'''
+
+
+def test_fit_import_data_missing_offset(ubman):
+ """An image with data-size but no data-offset must not inherit data"""
+ mkimage = os.path.join(ubman.config.build_dir, 'tools/mkimage')
+ params = {
+ 'kernel1': fit_util.make_kernel(ubman, 'imp-kernel1.bin', 'first'),
+ 'kernel2': fit_util.make_kernel(ubman, 'imp-kernel2.bin', 'second'),
+ }
+ its = fit_util.make_its(ubman, BASE_ITS, params, 'imp.its')
+ itb = fit_util.make_fname(ubman, 'imp.itb')
+
+ result = subprocess.run([mkimage, '-E', '-f', its, itb],
+ capture_output=True, text=True)
+ assert result.returncode == 0, result.stderr
+
+ # Remove the offset so that only data-size is left on kernel-2
+ subprocess.run(['fdtput', '-d', itb, '/images/kernel-2', 'data-offset'],
+ check=True)
+
+ # Re-processing must skip the malformed image in the import, so that
+ # the hashing stage reports it; previously the stale pointer made the
+ # import write kernel-1's data into kernel-2 and abort silently
+ result = subprocess.run([mkimage, '-F', itb],
+ capture_output=True, text=True)
+ assert result.returncode != 0
+ assert "Can't get image data/size" in result.stderr