test/py: fit: Deduplicate the test
PATCH v2 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
--- test/py/tests/test_fit_auto_signed.py | 98 +++++++++++---------------- 1 file changed, 39 insertions(+), 59 deletions(-)
test/py/tests/test_fit_auto_signed.py +39 -59
@@ -138,6 +138,29 @@ 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('FIT-1 has no "/image" nor "/configuration" nodes') + + 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 +173,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 +208,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 +227,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
PATCH v2 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
--- doc/mkimage.1 | 12 +++++ include/image.h | 1 + test/py/tests/test_fit_auto_signed.py | 65 ++++++++++++++++++++++++--- tools/fit_image.c | 55 ++++++++++++++++++++++- tools/imagetool.h | 2 + tools/mkimage.c | 17 ++++++- 6 files changed, 142 insertions(+), 10 deletions(-)
doc/mkimage.1 +12 -0
@@ -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 TEE file to the image. +. +.TP +.B \-Z +.TQ +.B \-\-tee-addr +Set TEE file load and entry point address, in hexadecimal. +. .SS Options for creating FIT images . .TP
include/image.h +1 -0
@@ -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 +53 -2
85 lines not on this page · raw message
tools/imagetool.h +2 -0
@@ -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
@@ -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 TEE file to the image\n" +" -Z ==> set 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
Re: [PATCH v2 2/2] mkimage: Add support for bundling TEE in mkimage -f auto
Hi Marek,
Quoted 53 lines · Marek Vasut
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.
Signed-off-by Marek Vasut <[email protected]>---
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--- doc/mkimage.1 | 12 +++++ include/image.h | 1 + test/py/tests/test_fit_auto_signed.py | 65 ++++++++++++++++++++++++--- tools/fit_image.c | 55 ++++++++++++++++++++++- tools/imagetool.h | 2 + tools/mkimage.c | 17 ++++++- 6 files changed, 142 insertions(+), 10 deletions(-)doc/mkimage.1 +0
-0
doc/mkimage.1 Append TFA BL31 file to the image. · line 258
Quoted 8 lines
doc/mkimage.1 +5
-0@@ -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 TEE file to the image.
Please specify which format is supported here if only select ones are.
doc/mkimage.1 Append TFA BL31 file to the image. · line 264
Quoted 6 lines
doc/mkimage.1 +6
-0+. +.TP +.B \-Z +.TQ +.B \-\-tee-addr +Set TEE file load and entry point address, in hexadecimal.
s/address/addresses/ ?
[...]
doc/mkimage.1 def test_fit_auto_signed(ubman): · line 259
Quoted 10 lines
doc/mkimage.1 +6
-0@@ -239,3 +251,42 @@ def test_fit_auto_signed(ubman): 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) + + # Run the same tests as 1/2/3 above, but this time with TEE + # options -z tee.bin -Z 0x56780000 to cover both mkimage with + # and without TEE use cases. + b_args = " -d" + kernel_file + " -b" + dt1_file + " -b" + dt2_file + " -z" + tee_file + " -Z 0x56780000" +
General remark but using f-string may improve readability:
b_args = f'-d {kernel_file} -b {dt1_file} -b {dt2_file} -z {tee_file} -Z 0x56780000'
[...]
Quoted 9 lines
doc/mkimage.1 +4
-1@@ -473,10 +504,20 @@ static void fit_write_configs(struct image_tool_params *params, char *fdt) len = strlen(str); fdt_property_string(fdt, typename, str); - if (params->fit_tfa_bl31) { + if (params->fit_tfa_bl31 && params->fit_tee) { + snprintf(str, sizeof(str), "%s-1." FIT_TFA_BL31_PROP "-1." FIT_TEE_PROP "-1", typename); + str[len] = 0; + len += strlen(FIT_TFA_BL31_PROP "-1") + 1;
doc/mkimage.1 static void fit_write_configs(struct image_tool_params *params, char *fdt) · line 520
Quoted 10 lines
doc/mkimage.1 +7
-0+ str[len] = 0; + len += strlen(FIT_TEE_PROP "-1") + 1; + } else if (params->fit_tfa_bl31) { snprintf(str, sizeof(str), "%s-1." FIT_TFA_BL31_PROP "-1", typename); str[len] = 0; len += strlen(FIT_TFA_BL31_PROP "-1") + 1; + } else if (params->fit_tee) { + snprintf(str, sizeof(str), "%s-1." FIT_TEE_PROP "-1", typename); + str[len] = 0; + len += strlen(FIT_TEE_PROP "-1") + 1;
It actually took me a while to figure out that we are reusing len from outside of the if block because the loadables property starts with kernel-1.
I'm wondering if it would make it more readable to do the following
if (params->fit_tfa_bl31) {
snprintf(&str[len + 1], sizeof(str) - (len + 1), FIT_TFA_BL31_PROP
"-1");
len += strlen(&str[len + 1]) + 1;
}if (params->fit_tee) {
snprintf(&str[len + 1], sizeof(str) - (len + 1), FIT_TEE_PROP "-1");
len += strlen(&str[len + 1]) + 1;
}(NOT TESTED!)
(snprintf apparently adds the trailing NUL character so no need to str[len] = 0 as far as I could tell, c.f. https://cplusplus.com/reference/cstdio/snprintf/ though that is c++ and the manpage of snprintf(3) isn't clear enough).
The issue is that we're now making access to an array and have to deal with possible out-of-bounds, as opposed to snprintf on str which handles this by itself by simply truncating safely. Not sure it's worth it.
Quoted 43 lines
doc/mkimage.1 +11
-1} fdt_property(fdt, FIT_LOADABLE_PROP, str, len + 1);@@ -498,10 +539,20 @@ static void fit_write_configs(struct image_tool_params *params, char *fdt) len = strlen(str); fdt_property_string(fdt, typename, str); - if (params->fit_tfa_bl31) { + if (params->fit_tfa_bl31 && params->fit_tee) { + snprintf(str, sizeof(str), "%s-1." FIT_TFA_BL31_PROP "-1." FIT_TEE_PROP "-1", typename); + str[len] = 0; + len += strlen(FIT_TFA_BL31_PROP "-1") + 1; + str[len] = 0; + len += strlen(FIT_TEE_PROP "-1") + 1; + } else if (params->fit_tfa_bl31) { snprintf(str, sizeof(str), "%s-1." FIT_TFA_BL31_PROP "-1", typename); str[len] = 0; len += strlen(FIT_TFA_BL31_PROP "-1") + 1; + } else if (params->fit_tee) { + snprintf(str, sizeof(str), "%s-1." FIT_TEE_PROP "-1", typename); + str[len] = 0; + len += strlen(FIT_TEE_PROP "-1") + 1; } fdt_property(fdt, FIT_LOADABLE_PROP, str, len + 1);tools/imagetool.h +2
-0@@ -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 +0
-0
tools/mkimage.c static void usage(const char *msg) · line 107
Quoted 5 lines
tools/mkimage.c +2
-0@@ -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 TEE file to the image\n" +" -Z ==> set TEE file load and entry point address\n"
s/address/addresses/ ?
Looks ok to me, so
Thanks!
Quentin
Re: [PATCH v2 2/2] mkimage: Add support for bundling TEE in mkimage -f auto
On 11/25/25 12:37 PM, Quentin Schulz wrote:
Hello Quentin,
Quoted 13 lines
Quoted 10 lines
+++ b/doc/mkimage.1
(quoted diff) +0
-0@@ -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 TEE file to the image.Please specify which format is supported here if only select ones are.
Quoted 8 lines
Quoted 6 lines
+.
+.TP
+.B \-Z
+.TQ
+.B \-\-tee-addr
+Set TEE file load and entry point address, in hexadecimal.s/address/addresses/ ?
This is a single address here, so no plural.
Quoted 51 lines
[...]
Quoted 11 lines
test/py/tests/test_fit_auto_signed.py +5
-0@@ -239,3 +251,42 @@ def test_fit_auto_signed(ubman): 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) + + # Run the same tests as 1/2/3 above, but this time with TEE + # options -z tee.bin -Z 0x56780000 to cover both mkimage with + # and without TEE use cases. + b_args = " -d" + kernel_file + " -b" + dt1_file + " -b" +
dt2_file+ " -z" +tee_file+ " -Z0x56780000"
+General remark but using f-string may improve readability:
b_args= f'-d {kernel_file} -b {dt1_file} -b {dt2_file} -z {tee_file} -Z0x56780000'[...]
Quoted 11 lines
tools/fit_image.c +5
-1@@ -473,10 +504,20 @@ static void fit_write_configs(struct image_tool_params *params, char *fdt) len = strlen(str); fdt_property_string(fdt, typename, str); - if (params->fit_tfa_bl31) { + if (params->fit_tfa_bl31 && params->fit_tee) { + snprintf(str, sizeof(str), "%s-1." FIT_TFA_BL31_PROP"-1." FIT_TEE_PROP "-1" , typename); + str[len] = 0; + len += strlen(FIT_TFA_BL31_PROP "-1") + 1; + str[len] = 0;tools/fit_image.c static void fit_write_configs(struct · line 522
Quoted 10 lines
tools/fit_image.c +6
-0+ len += strlen(FIT_TEE_PROP "-1") + 1; + } else if (params->fit_tfa_bl31) { snprintf(str, sizeof(str), "%s-1." FIT_TFA_BL31_PROP "-1", typename); str[len] = 0; len += strlen(FIT_TFA_BL31_PROP "-1") + 1; + } else if (params->fit_tee) { + snprintf(str, sizeof(str), "%s-1." FIT_TEE_PROP "-1", typename); + str[len] = 0; + len += strlen(FIT_TEE_PROP "-1") + 1;It actually took me a while to figure out that we are reusing len from outside of the if block because the loadables property starts with kernel-1.
I'm wondering if it would make it more readable to do the following
if (
params->fit_tfa_bl31) {
snprintf(&str[len + 1], sizeof(str) - (len + 1),FIT_TFA_BL31_PROP
"-1");
len +=strlen(&str[len + 1])+ 1;
}
Quoted 6 lines
if (
params->fit_tee) {
snprintf(&str[len + 1], sizeof(str) - (len + 1), FIT_TEE_PROP "-1"); len +=strlen(&str[len + 1])+ 1;
}(NOT TESTED!)
Works. and this is much better than the current code, thanks !
Hi Marek,
On 11/24/25 8:40 PM, Marek Vasut wrote:
[...]
test/py/tests/test_fit_auto_signed.py class SignedFitHelper(object): · line 141
Quoted 13 lines
--- test/py/tests/test_fit_auto_signed.py | 98 +++++++++++---------------- 1 file changed, 39 insertions(+), 59 deletions(-)test/py/tests/test_fit_auto_signed.py +1
-0@@ -138,6 +138,29 @@ 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=""):
I would have grouped variables for the same "theme" together, e.g. simgs, scfgs with key_name, sign_algo and verifier for example. But that's fine as is.
test/py/tests/test_fit_auto_signed.py class SignedFitHelper(object): · line 146
Quoted 5 lines
test/py/tests/test_fit_auto_signed.py +5
-0+ """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.
Would be nice to have documentation on what the parameters represent and what this returns/raises. Not a blocker though, I see we already don't do it for other functions.
test/py/tests/test_fit_auto_signed.py class SignedFitHelper(object): · line 154
Quoted 8 lines
test/py/tests/test_fit_auto_signed.py +8
-0+ """ + 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('FIT-1 has no "/image" nor "/configuration" nodes') +
Only downside is that this exception will be raised with the same string for all callers. We call it multiple times in the same test so it might be difficult to identify which one actually failed. We could try..except the exception, use the content of the exception with
try:
generate_and_check_fit_image(...)
except Exception as e:
pytest.fail(f'FIT-X failed: {str(e)}')
maybe? (NOT TESTED!)
test/py/tests/test_fit_auto_signed.py class SignedFitHelper(object): · line 160
Quoted 6 lines
test/py/tests/test_fit_auto_signed.py +6
-0+ 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)
This is a typo.... that already exists in the code (confgs instead of configs), so "fine".
Mmmm, we should also verify the signature of the configs, but it's a TODO in fit.check_fit_signed_confgs(). Maybe someone will implement that. I think it would be valuable as I would expect most should be using conf signature instead of image signature for added security (though I haven't found articles about that but I'm sure this has been raised a few times already).
Checked the diff and it looks okay so:
Thanks!
Quentin
Quoted 28 lines · Quentin Schulz
Hi Marek,
On 11/24/25 8:40 PM, Marek Vasut wrote:
[...]test/py/tests/test_fit_auto_signed.py class SignedFitHelper(object): · line 141
Quoted 13 lines
--- test/py/tests/test_fit_auto_signed.py | 98 +++++++++++---------------- 1 file changed, 39 insertions(+), 59 deletions(-)test/py/tests/test_fit_auto_signed.py +1
-0@@ -138,6 +138,29 @@ 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=""):I would have grouped variables for the same "theme" together, e.g. simgs, scfgs with
key_name,sign_algoand verifier for example. But that's fine as is.test/py/tests/test_fit_auto_signed.py class SignedFitHelper(object): · line 146
Quoted 5 lines
test/py/tests/test_fit_auto_signed.py +5
-0+ """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.
Quoted 3 lines
Would be nice to have documentation on what the parameters represent and what this returns/raises. Not a blocker though, I see we already don't do it for other functions.
Enhancing documentation within the tests is usually done when someone has time to add it to doc/develop/pytest/ and so yes, doing it later / follow-up is fine. And I still need to experiment on what's needed so that readthedocs generates the output correctly, and not just local builds get it correct.
Signature · 1 line
Tom
On 11/25/25 11:50 AM, Quentin Schulz wrote:
Hello Quentin,
Quoted 6 lines · Marek Vasut
[...]
Quoted 4 lines
---
test/py/tests/test_fit_auto_signed.py| 98 +++++++++++----------------1 file changed, 39 insertions(+), 59 deletions(-)
Quoted 12 lines
Quoted 10 lines
test/py/tests/test_fit_auto_signed.py +0
-0@@ -138,6 +138,29 @@ 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=""):I would have grouped variables for the same "theme" together, e.g. simgs, scfgs with
key_name,sign_algoand verifier for example. But that's fine as is.
They are grouped together, this way:
- Command
- Checker switches (crc, simgs, scfgs, bl31, tee)
- The rest of the params
Quoted 9 lines
Quoted 7 lines
+ """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.Would be nice to have documentation on what the parameters represent and what this returns/raises. Not a blocker though, I see we already don't do it for other functions.
I am not that deep in python, so if you could tell me how to do that or share an example, I can do that.
Quoted 12 lines
Quoted 9 lines
+ """
+ mkimage = ubman.config.build_dir + '/tools/mkimage' +utils.run_and_log(ubman, mkimage + cmd)
+
+ fit =SignedFitHelper(ubman, fit_file)
+ iffit.build_nodes_sets()== 0:
+ raiseValueError('FIT-1 has no "/image" nor "/ configuration" nodes')
+Only downside is that this exception will be raised with the same string for all callers. We call it multiple times in the same test so it might be difficult to identify which one actually failed. We could try..except the exception, use the content of the exception with
Quoted 6 lines
try:
generate_and_check_fit_image(...)
except Exception as e:
pytest.fail(f'FIT-X failed: {str(e)}')maybe? (NOT TESTED!)
Maybe it would be better to simply print the test configuration ?
Like this:
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}')
Quoted 10 lines
Quoted 6 lines
+ 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)This is a typo.... that already exists in the code (confgs instead of configs), so "fine".
Mmmm, we should also verify the signature of the configs, but it's a TODO in
fit.check_fit_signed_confgs(). Maybe someone will implement that. I think it would be valuable as I would expect most should be using conf signature instead of image signature for added security (though I haven't found articles about that but I'm sure this has been raised a few times already).
Fixing that todo seems a bit out of scope here.
[...]
Quoted 6 lines · Marek Vasut
On 11/25/25 11:50 AM, Quentin Schulz wrote:
Hello Quentin,
Quoted 2 lines · Marek Vasut
[...]
[...]
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
+ """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.
Quoted 4 lines
Quoted 1 line
Would be nice to have documentation on what the parameters represent and what this returns/raises. Not a blocker though, I see we already don't do it for other functions.
I am not that deep in python, so if you could tell me how to do that or share an example, I can do that.
Just follow binman's example I guess. If it's wrong, we'll need to fix the format everywhere anyway at some point (e.g. when someone manages to setup rST doc generation from docstring, maybe with [1]?).
"""Get the operation referenced by a subnode
Args:
node (Node): Subnode (of the FIT) to check
Returns:
int: Operation to perform
Raises:
ValueError: Invalid operation name
This seems to follow Google-Style Docstrings format, c.f. https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings
[1] https://www.sphinx-doc.org/en/master/usage/extensions/napoleon.html
Quoted 17 lines
Quoted 17 lines
Quoted 9 lines
+ """
+ mkimage = ubman.config.build_dir + '/tools/mkimage' +utils.run_and_log(ubman, mkimage + cmd)
+
+ fit =SignedFitHelper(ubman, fit_file)
+ iffit.build_nodes_sets()== 0:
+ raiseValueError('FIT-1 has no "/image" nor "/ configuration" nodes')
+Only downside is that this exception will be raised with the same string for all callers. We call it multiple times in the same test so it might be difficult to identify which one actually failed. We could try..except the exception, use the content of the exception with
try:
generate_and_check_fit_image(...)
except Exception as e:
pytest.fail(f'FIT-X failed: {str(e)}')
Quoted 8 lines
Quoted 1 line
maybe? (NOT TESTED!)
Maybe it would be better to simply print the test configuration ?
Like this:
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}')
Considering that the only arguments used before this is raised are the mkimage cmd arguments, I think it'd be enough to just print that? But yes, that would work.
Cheers,
Quentin