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) <[email protected]> --- tools/binman/ftest.py | 78 ++++++++++++++++++++++ tools/binman/test/vendor/nxp_imx93_csf.dts | 18 +++++ .../binman/test/vendor/nxp_imx93_csf_imagename.dts | 24 +++++++ 3 files changed, 120 insertions(+) diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 66695a83508..ee5c027e0ea 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,83 @@ 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 with an i.MX93 SPL container including 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') + + 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') + + 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
