Skip to contentSkip to conversation

test/py: fit: Deduplicate the test

PATCH In review Marek Vasut 2 participants 3 messages Nov 25, 2025 – Dec 7, 2025

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/2 test/py: fit: Deduplicate the test

Introduce generate_and_check_fit_image() and call it with various parameters to test various configurations of the fitImage. This is identical to the existing test, expect for the code duplication.

---
Cc: "Carlos López" <[email protected]>
Cc: Aristo Chen <[email protected]>
Cc: Ilias Apalodimas <[email protected]>
Cc: Julien Masson <[email protected]>
Cc: Mattijs Korpershoek <[email protected]>
Cc: Mayuresh Chitale <[email protected]>
Cc: Paul HENRYS <[email protected]>
Cc: Quentin Schulz <[email protected]>
Cc: Rasmus Villemoes <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: Wolfgang Wallner <[email protected]>
Cc: [email protected]
Cc: [email protected]
---
V2: New patch
V3: - Report test configuration on failure
- Add RB from Quentin

---
 test/py/tests/test_fit_auto_signed.py | 97 +++++++++++----------------
 1 file changed, 38 insertions(+), 59 deletions(-)
test/py/tests/test_fit_auto_signed.py +38 -59
index 0b5dbd5401c..6220fe6ff59 100644
@@ -138,6 +138,28 @@ class SignedFitHelper(object):
 @pytest.mark.buildconfigspec('fit_signature')
 @pytest.mark.requiredtool('fdtget')
 def test_fit_auto_signed(ubman):
+    def generate_and_check_fit_image(cmd, crc=False, simgs=False, scfgs=False, bl31present=False, key_name="", sign_algo="", verifier=""):
+        """Generate fitImage and test for expected entries.
+
+        Generate a fitImage and test whether suitable entries are part of
+        the generated fitImage. Test whether checksums and signatures are
+        part of the generated fitImage.
+        """
+        mkimage = ubman.config.build_dir + '/tools/mkimage'
+        utils.run_and_log(ubman, mkimage + cmd)
+
+        fit = SignedFitHelper(ubman, fit_file)
+        if fit.build_nodes_sets() == 0:
+            raise ValueError(f'FIT has no "/image" nor "/configuration" nodes, test settings: cmd={cmd} crc={crc} simgs={simgs} scfgs={scfgs} bl31present={bl31present} teepresent={teepresent} key_name={key_name} sign_algo={sign_algo} verifier={verifier}')
+        if crc:
+            fit.check_fit_crc32_images()
+        if simgs:
+            fit.check_fit_signed_images(key_name, sign_algo, verifier)
+        if scfgs:
+            fit.check_fit_signed_confgs(key_name, sign_algo)
+
+        fit.check_fit_loadables(bl31present)
+
     """Test that mkimage generates auto-FIT with signatures/hashes as expected.
 
     The mkimage tool can create auto generated (i.e. without an ITS file
@@ -150,7 +172,6 @@ def test_fit_auto_signed(ubman):
 
     The test does not run the sandbox. It only checks the host tool mkimage.
     """
-    mkimage = ubman.config.build_dir + '/tools/mkimage'
     tempdir = os.path.join(ubman.config.result_dir, 'auto_fit')
     os.makedirs(tempdir, exist_ok=True)
     kernel_file = f'{tempdir}/vmlinuz'
@@ -186,39 +207,18 @@ def test_fit_auto_signed(ubman):
     s_args = " -k" + tempdir + " -g" + key_name + " -o" + sign_algo
 
     # 1 - Create auto FIT with images crc32 checksum, and verify it
-    utils.run_and_log(ubman, mkimage + ' -fauto' + b_args + " " + fit_file)
-
-    fit = SignedFitHelper(ubman, fit_file)
-    if fit.build_nodes_sets() == 0:
-        raise ValueError('FIT-1 has no "/image" nor "/configuration" nodes')
-
-    fit.check_fit_crc32_images()
-
-    fit.check_fit_loadables(present=False)
+    generate_and_check_fit_image(' -fauto' + b_args + " " + fit_file,
+                                 crc=True)
 
     # 2 - Create auto FIT with signed images, and verify it
-    utils.run_and_log(ubman, mkimage + ' -fauto' + b_args + s_args + " " +
-                      fit_file)
-
-    fit = SignedFitHelper(ubman, fit_file)
-    if fit.build_nodes_sets() == 0:
-        raise ValueError('FIT-2 has no "/image" nor "/configuration" nodes')
-
-    fit.check_fit_signed_images(key_name, sign_algo, verifier)
-
-    fit.check_fit_loadables(present=False)
+    generate_and_check_fit_image(' -fauto' + b_args + s_args + " " + fit_file,
+                                 simgs=True,
+                                 key_name=key_name, sign_algo=sign_algo, verifier=verifier)
 
     # 3 - Create auto FIT with signed configs and hashed images, and verify it
-    utils.run_and_log(ubman, mkimage + ' -fauto-conf' + b_args + s_args + " " +
-                      fit_file)
-
-    fit = SignedFitHelper(ubman, fit_file)
-    if fit.build_nodes_sets() == 0:
-        raise ValueError('FIT-3 has no "/image" nor "/configuration" nodes')
-
-    fit.check_fit_signed_confgs(key_name, sign_algo)
-
-    fit.check_fit_loadables(present=False)
+    generate_and_check_fit_image(' -fauto-conf' + b_args + s_args + " " + fit_file,
+                                 scfgs=True,
+                                 key_name=key_name, sign_algo=sign_algo)
 
     # Run the same tests as 1/2/3 above, but this time with TFA BL31
     # options -y tfa-bl31.bin -Y 0x12340000 to cover both mkimage with
@@ -226,36 +226,15 @@ def test_fit_auto_signed(ubman):
     b_args = " -d" + kernel_file + " -b" + dt1_file + " -b" + dt2_file + " -y" + tfa_file + " -Y 0x12340000"
 
     # 4 - Create auto FIT with images crc32 checksum, and verify it
-    utils.run_and_log(ubman, mkimage + ' -fauto' + b_args + " " + fit_file)
-
-    fit = SignedFitHelper(ubman, fit_file)
-    if fit.build_nodes_sets() == 0:
-        raise ValueError('FIT-4 has no "/image" nor "/configuration" nodes')
-
-    fit.check_fit_crc32_images()
-
-    fit.check_fit_loadables(present=True)
+    generate_and_check_fit_image(' -fauto' + b_args + " " + fit_file,
+                                 crc=True, bl31present=True)
 
     # 5 - Create auto FIT with signed images, and verify it
-    utils.run_and_log(ubman, mkimage + ' -fauto' + b_args + s_args + " " +
-                      fit_file)
-
-    fit = SignedFitHelper(ubman, fit_file)
-    if fit.build_nodes_sets() == 0:
-        raise ValueError('FIT-5 has no "/image" nor "/configuration" nodes')
-
-    fit.check_fit_signed_images(key_name, sign_algo, verifier)
-
-    fit.check_fit_loadables(present=True)
+    generate_and_check_fit_image(' -fauto' + b_args + s_args + " " + fit_file,
+                                 simgs=True, bl31present=True,
+                                 key_name=key_name, sign_algo=sign_algo, verifier=verifier)
 
     # 6 - Create auto FIT with signed configs and hashed images, and verify it
-    utils.run_and_log(ubman, mkimage + ' -fauto-conf' + b_args + s_args + " " +
-                      fit_file)
-
-    fit = SignedFitHelper(ubman, fit_file)
-    if fit.build_nodes_sets() == 0:
-        raise ValueError('FIT-6 has no "/image" nor "/configuration" nodes')
-
-    fit.check_fit_signed_confgs(key_name, sign_algo)
-
-    fit.check_fit_loadables(present=True)
+    generate_and_check_fit_image(' -fauto-conf' + b_args + s_args + " " + fit_file,
+                                 scfgs=True, bl31present=True,
+                                 key_name=key_name, sign_algo=sign_algo)
Signature · 1 line
2.51.0
#1 lore raw

PATCH v3 2/2 mkimage: Add support for bundling TEE in mkimage -f auto

Introduce two new parameters to be used with mkimage -f auto to bundle TEE image into fitImage, using auto-generated fitImage. Add -z to specify TEE file name and -Z to specify TEE load and entry point address. This is meant to be used with systems which boot all of TEE, Linux and its DT from a single fitImage, all booted by U-Boot.

Example invocation:
"

$ mkimage -E -A arm -C none -e 0xc0008000 -a 0xc0008000 -f auto \
          -d arch/arm/boot/zImage \
          -b arch/arm/boot/dts/st/stm32mp135f-dhcor-dhsbc.dtb \
          -z ../optee_os/out/arm-plat-stm32mp1/core/tee-raw.bin \
	  -Z 0xde000000 \
          /path/to/output/fitImage
"

Documentation update and test are also included, the test validates both positive and negative test cases, where fitImage does not include TEE and does include TEE blobs.

---
Cc: "Carlos López" <[email protected]>
Cc: Aristo Chen <[email protected]>
Cc: Ilias Apalodimas <[email protected]>
Cc: Julien Masson <[email protected]>
Cc: Mattijs Korpershoek <[email protected]>
Cc: Mayuresh Chitale <[email protected]>
Cc: Paul HENRYS <[email protected]>
Cc: Quentin Schulz <[email protected]>
Cc: Rasmus Villemoes <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: Wolfgang Wallner <[email protected]>
Cc: [email protected]
Cc: [email protected]
---
V2: - Update manpage to list --tee-* options instead of --optee-*
- Update comments in pytest test to reflect the TEE support
V3: - Replace snprintf() handling in fit_write_configs()
- Add AB from Quentin

---
 doc/mkimage.1                         | 12 +++++
 include/image.h                       |  1 +
 test/py/tests/test_fit_auto_signed.py | 65 ++++++++++++++++++++++++---
 tools/fit_image.c                     | 51 ++++++++++++++++++---
 tools/imagetool.h                     |  2 +
 tools/mkimage.c                       | 17 ++++++-
 6 files changed, 134 insertions(+), 14 deletions(-)
doc/mkimage.1 +12 -0
index c705218d345..9a2d07cee75 100644
@@ -251,6 +251,18 @@ Append TFA BL31 file to the image.
 .B \-\-tfa-bl31-addr
 Set TFA BL31 file load and entry point address.
 .
+.TP
+.B \-z
+.TQ
+.B \-\-tee-file
+Append raw TEE file to the image.
+.
+.TP
+.B \-Z
+.TQ
+.B \-\-tee-addr
+Set raw TEE file load and entry point address, in hexadecimal.
+.
 .SS Options for creating FIT images
 .
 .TP
include/image.h +1 -0
index 9a1c828416d..d543c6cf254 100644
@@ -1105,6 +1105,7 @@ int booti_setup(ulong image, ulong *relocated_addr, ulong *size,
 #define FIT_SCRIPT_PROP		"script"
 #define FIT_PHASE_PROP		"phase"
 #define FIT_TFA_BL31_PROP	"tfa-bl31"
+#define FIT_TEE_PROP		"tee"
 
 #define FIT_MAX_HASH_LEN	HASH_MAX_DIGEST_SIZE
 
test/py/tests/test_fit_auto_signed.py +58 -7

108 lines not on this page · raw message

tools/fit_image.c +45 -6

75 lines not on this page · raw message

tools/imagetool.h +2 -0
index 866b8834fd7..d0e7d6d56e3 100644
@@ -101,6 +101,8 @@ struct image_tool_params {
 	struct image_summary summary;	/* results of signing process */
 	char *fit_tfa_bl31;	/* TFA BL31 file to include */
 	unsigned int fit_tfa_bl31_addr;	/* TFA BL31 load and entry point address */
+	char *fit_tee;		/* TEE file to include */
+	unsigned int fit_tee_addr;	/* TEE load and entry point address */
 };
 
 /*
tools/mkimage.c +16 -1
index a800f9507bf..3c43962807d 100644
@@ -103,6 +103,8 @@ static void usage(const char *msg)
 		"          -s ==> create an image with no data\n"
 		"          -y ==> append TFA BL31 file to the image\n"
 		"          -Y ==> set TFA BL31 file load and entry point address\n"
+		"          -z ==> append raw TEE file to the image\n"
+		"          -Z ==> set raw TEE file load and entry point address\n"
 		"          -v ==> verbose\n",
 		params.cmdname);
 	fprintf(stderr,
@@ -162,7 +164,7 @@ static int add_content(int type, const char *fname)
 }
 
 static const char optstring[] =
-	"a:A:b:B:c:C:d:D:e:Ef:Fg:G:i:k:K:ln:N:o:O:p:qrR:stT:vVxy:Y:";
+	"a:A:b:B:c:C:d:D:e:Ef:Fg:G:i:k:K:ln:N:o:O:p:qrR:stT:vVxy:Y:z:Z:";
 
 static const struct option longopts[] = {
 	{ "load-address", required_argument, NULL, 'a' },
@@ -200,6 +202,8 @@ static const struct option longopts[] = {
 	{ "xip", no_argument, NULL, 'x' },
 	{ "tfa-bl31-file", no_argument, NULL, 'y' },
 	{ "tfa-bl31-addr", no_argument, NULL, 'Y' },
+	{ "tee-file", no_argument, NULL, 'z' },
+	{ "tee-addr", no_argument, NULL, 'Z' },
 	{ /* sentinel */ },
 };
 
@@ -382,6 +386,17 @@ static void process_args(int argc, char **argv)
 				exit(EXIT_FAILURE);
 			}
 			break;
+		case 'z':
+			params.fit_tee = optarg;
+			break;
+		case 'Z':
+			params.fit_tee_addr = strtoull(optarg, &ptr, 16);
+			if (*ptr) {
+				fprintf(stderr, "%s: invalid TEE address %s\n",
+					params.cmdname, optarg);
+				exit(EXIT_FAILURE);
+			}
+			break;
 		default:
 			usage("Invalid option");
 		}
Signature · 1 line
2.51.0
#2 lore raw
In reply to Marek Vasut
Quoted 5 lines · Marek Vasut

Introduce generate_and_check_fit_image() and call it with various parameters to test various configurations of the fitImage. This is identical to the existing test, expect for the code duplication.

Applied to u-boot/next, thanks!

[1/2] test/py: fit: Deduplicate the test

      commit: 23eb6c9ce11b6b781f7902ced7340f2c6c433e4f
[2/2] mkimage: Add support for bundling TEE in mkimage -f auto
      commit: 22aa122eee021a631e1b92c761ff1a434d46890e
Signature · 1 line
Tom