From: "Jérémie Dautheribes (Schneider Electric)" <jeremie.dautheribes@bootlin.com>
To: "NXP i.MX U-Boot Team" <uboot-imx@nxp.com>,
u-boot@lists.u-boot-project.org
Cc: "Jérémie Dautheribes (Schneider Electric)"
<jeremie.dautheribes@bootlin.com>,
"Miquèl Raynal" <miquel.raynal@bootlin.com>,
"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
"Tom Rini" <trini@konsulko.com>, "Simon Glass" <sjg@chromium.org>,
"Alper Nebi Yasak" <alpernebiyasak@gmail.com>,
"Stefano Babic" <sbabic@nabladev.com>,
"Fabio Estevam" <festevam@gmail.com>,
"Marek Vasut" <marex@nabladev.com>,
"Denis Mukhin" <dmukhin@ford.com>,
"Rasmus Villemoes" <rv@rasmusvillemoes.dk>,
"Ilias Apalodimas" <ilias.apalodimas@linaro.org>,
"Krzysztof Drobiński" <krzysztof@kd-solutions.pl>,
"Peng Fan" <peng.fan@nxp.com>, "Alice Guo" <alice.guo@nxp.com>,
"Simona Toaca" <simona.toaca@nxp.com>, "Ye Li" <ye.li@nxp.com>,
"Quentin Schulz" <quentin.schulz@cherry.de>,
"Christophe Guerreiro" <christophe.guerreiro@non.se.com>
Subject: [PATCH v2 7/7] binman: test: add code coverage for nxp_imx93cst etype
Date: Wed, 02 Sep 2026 15:41:34 +0200 [thread overview]
Message-ID: <20260902-imx93-secureboot-v2-7-5947b92a5072@bootlin.com> (raw)
In-Reply-To: <20260902-imx93-secureboot-v2-0-5947b92a5072@bootlin.com>
Add test methods to cover all code paths of the nxp_imx93cst etype,
reusing the pattern of the nxp_imx8mcst as done in commit 0cab35362d77
("binman: test: Fix code coverage for iMX8 and cst bintool") by Simon
Glass.
This brings nxp_imx93cst to 100% coverage.
Signed-off-by: Jérémie Dautheribes (Schneider Electric) <jeremie.dautheribes@bootlin.com>
---
tools/binman/ftest.py | 85 ++++++++++++++++++++++
tools/binman/test/vendor/nxp_imx93_csf.dts | 18 +++++
.../binman/test/vendor/nxp_imx93_csf_imagename.dts | 24 ++++++
3 files changed, 127 insertions(+)
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index 5f0de4c74a7..ce012b415ff 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -35,6 +35,7 @@ from dtoc import fdt
from dtoc import fdt_util
from binman.etype import fdtmap
from binman.etype import image_header
+from binman.etype import nxp_imx93cst
from binman.image import Image
from u_boot_pylib import command
from u_boot_pylib import terminal
@@ -8152,6 +8153,90 @@ fdt fdtmap Extract the devicetree blob from the fdtmap
result = cst.fetch(bintool.FETCH_BUILD)
self.assertEqual(('cst', None), result)
+ def testNxpImx93cstNormal(self):
+ """Test CST signing with an i.MX93 SPL container (no ELE FW)"""
+ # Create a fake AHAB SPL container: tag at offset 3, image-entry
+ # flags at offset 40 whose low byte is the A55 core/type (0x23),
+ # and the signature block offset at offset 12
+ spl_data = bytearray(64)
+ spl_data[3] = nxp_imx93cst.CONTAINER_HDR_TAG
+ spl_data[12:14] = struct.pack('<H', 0x90)
+ spl_data[40:44] = struct.pack('<I', 0x123)
+ self._MakeInputFile('imx93-container.bin', bytes(spl_data))
+
+ with terminal.capture() as (_, stderr):
+ self._DoTestFile('vendor/nxp_imx93_csf.dts',
+ force_missing_bintools='cst')
+ err = stderr.getvalue()
+ self.assertRegex(err, "Image 'image'.*missing bintools.*: cst")
+
+ def testNxpImx93cstELE(self):
+ """Test CST signing where the SPL container starts with the ELE FW"""
+ # Create a fake AHAB image starting with the NXP-signed ELE
+ # container. The low byte of the first image entry flags (0x66) is
+ # the ELE core/type, so the SPL container header is at 0x400
+ ele_data = bytearray(0x410)
+ ele_data[3] = nxp_imx93cst.CONTAINER_HDR_TAG
+ ele_data[40:44] = struct.pack('<I', 0x866)
+ ele_data[0x400 + 3] = nxp_imx93cst.CONTAINER_HDR_TAG
+ ele_data[0x400 + 12:0x400 + 14] = struct.pack('<H', 0x90)
+ self._MakeInputFile('imx93-container.bin', bytes(ele_data))
+
+ with terminal.capture() as (_, stderr):
+ self._DoTestFile('vendor/nxp_imx93_csf.dts',
+ force_missing_bintools='cst')
+ err = stderr.getvalue()
+ self.assertRegex(err, "Image 'image'.*missing bintools.*: cst")
+
+ def testNxpImx93cstUnknownTag(self):
+ """Test CST with unknown input tag passes data through"""
+ # Trigger the pass-through path using an input without the AHAB
+ # container tag
+ data = b'\x00' * 64
+ self._MakeInputFile('imx93-container.bin', data)
+ self._DoTestFile('vendor/nxp_imx93_csf.dts',
+ force_missing_bintools='cst')
+
+ # The pass-through branch returns the input data unchanged, so the
+ # produced image must be exactly the 64 zero bytes
+ out = tools.read_file(tools.get_output_filename('image.bin'))
+ self.assertEqual(out, b'\x00' * 64)
+
+ def testNxpImx93cstSigned(self):
+ """Test CST-signing-success path with mocked cst invocation"""
+ spl_data = bytearray(64)
+ spl_data[3] = nxp_imx93cst.CONTAINER_HDR_TAG
+ spl_data[12:14] = struct.pack('<H', 0x90)
+ spl_data[40:44] = struct.pack('<I', 0x123)
+ self._MakeInputFile('imx93-container.bin', bytes(spl_data))
+
+ # Mock run_cmd() so that when cst is invoked, it creates a fake
+ # output blob and returns success, thus covering the signing path
+ original = bintool.Bintool.run_cmd
+
+ def fake_cst_run_cmd(self_tool, *args, binary=False):
+ if self_tool.name == 'cst':
+ arg_list = list(args)
+ if '-o' in arg_list:
+ idx = arg_list.index('-o')
+ tools.write_file(arg_list[idx + 1], b'\x00' * 32)
+ return 'fake cst output'
+ return original(self_tool, *args, binary=binary)
+
+ with unittest.mock.patch.object(bintool.Bintool, 'run_cmd',
+ new=fake_cst_run_cmd):
+ data = self._DoReadFile('vendor/nxp_imx93_csf.dts')
+
+ # The output must be the fake 32-byte CST blob produced by cst
+ self.assertEqual(data, b'\x00' * 32)
+
+ def testNxpImx93ImageSizeNone(self):
+ """Test SetImagePos() early return when an entry has no size"""
+ # The imagename entry is in GetEntries() but not packed, so has
+ # size=None, which triggers the early-return guard in SetImagePos()
+ self._DoTestFile('vendor/nxp_imx93_csf_imagename.dts',
+ force_missing_bintools='mkimage')
+
def testNxpImx8MFSPI(self):
"""Test that binman can produce an iMX8m FSPI image"""
self._DoTestFile('vendor/nxp_imx8m_fspi.dts')
diff --git a/tools/binman/test/vendor/nxp_imx93_csf.dts b/tools/binman/test/vendor/nxp_imx93_csf.dts
new file mode 100644
index 00000000000..bbe8eda4b70
--- /dev/null
+++ b/tools/binman/test/vendor/nxp_imx93_csf.dts
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/dts-v1/;
+
+/ {
+ #address-cells = <1>;
+ #size-cells = <1>;
+
+ binman {
+ nxp-imx93cst {
+ args;
+
+ blob {
+ filename = "imx93-container.bin";
+ };
+ };
+ };
+};
diff --git a/tools/binman/test/vendor/nxp_imx93_csf_imagename.dts b/tools/binman/test/vendor/nxp_imx93_csf_imagename.dts
new file mode 100644
index 00000000000..13009438ee8
--- /dev/null
+++ b/tools/binman/test/vendor/nxp_imx93_csf_imagename.dts
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/dts-v1/;
+
+/ {
+ #address-cells = <1>;
+ #size-cells = <1>;
+
+ binman {
+ nxp-imx93cst {
+ args;
+
+ u-boot {
+ };
+
+ imagename {
+ type = "section";
+
+ u-boot {
+ };
+ };
+ };
+ };
+};
--
2.55.0
prev parent reply other threads:[~2026-09-02 13:42 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-02 13:41 [PATCH v2 0/7] binman: add nxp_imx93cst etype for i.MX93 flash.bin signing Jérémie Dautheribes (Schneider Electric)
2026-09-02 13:41 ` [PATCH v2 1/7] binman: add nxp_imxcst base etype for i.MX CST signing Jérémie Dautheribes (Schneider Electric)
2026-09-02 13:41 ` [PATCH v2 2/7] binman: nxp_imx8mcst: use the nxp_imxcst base etype Jérémie Dautheribes (Schneider Electric)
2026-09-02 13:41 ` [PATCH v2 3/7] tools: binman: add nxp_imx93cst etype for i.MX93 flash.bin signing Jérémie Dautheribes (Schneider Electric)
2026-09-02 13:41 ` [PATCH v2 4/7] imx93-u-boot: wrap SPL and U-Boot nodes in a CST node if AHAB_BOOT enabled Jérémie Dautheribes (Schneider Electric)
2026-09-02 13:41 ` [PATCH v2 5/7] doc: imx: ahab: add AHAB introduction Jérémie Dautheribes (Schneider Electric)
2026-09-02 13:41 ` [PATCH v2 6/7] doc: imx: ahab: add i.MX93 secure boot guide Jérémie Dautheribes (Schneider Electric)
2026-09-02 13:41 ` Jérémie Dautheribes (Schneider Electric) [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260902-imx93-secureboot-v2-7-5947b92a5072@bootlin.com \
--to=jeremie.dautheribes@bootlin.com \
--cc=alice.guo@nxp.com \
--cc=alpernebiyasak@gmail.com \
--cc=christophe.guerreiro@non.se.com \
--cc=dmukhin@ford.com \
--cc=festevam@gmail.com \
--cc=ilias.apalodimas@linaro.org \
--cc=krzysztof@kd-solutions.pl \
--cc=marex@nabladev.com \
--cc=miquel.raynal@bootlin.com \
--cc=peng.fan@nxp.com \
--cc=quentin.schulz@cherry.de \
--cc=rv@rasmusvillemoes.dk \
--cc=sbabic@nabladev.com \
--cc=simona.toaca@nxp.com \
--cc=sjg@chromium.org \
--cc=thomas.petazzoni@bootlin.com \
--cc=trini@konsulko.com \
--cc=u-boot@lists.u-boot-project.org \
--cc=uboot-imx@nxp.com \
--cc=ye.li@nxp.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.