diff options
Diffstat (limited to 'tools/binman')
-rw-r--r-- | tools/binman/bintool_test.py | 20 | ||||
-rwxr-xr-x | tools/binman/cbfs_util_test.py | 15 | ||||
-rw-r--r-- | tools/binman/control.py | 6 | ||||
-rw-r--r-- | tools/binman/elf_test.py | 3 | ||||
-rw-r--r-- | tools/binman/entries.rst | 16 | ||||
-rw-r--r-- | tools/binman/etype/atf_bl1.py | 23 | ||||
-rw-r--r-- | tools/binman/etype/section.py | 6 | ||||
-rwxr-xr-x | tools/binman/fip_util_test.py | 11 | ||||
-rw-r--r-- | tools/binman/ftest.py | 113 | ||||
-rw-r--r-- | tools/binman/image_test.py | 4 | ||||
-rwxr-xr-x | tools/binman/main.py | 4 | ||||
-rw-r--r-- | tools/binman/test/347_bl1.dts | 13 |
12 files changed, 151 insertions, 83 deletions
diff --git a/tools/binman/bintool_test.py b/tools/binman/bintool_test.py index 949d6f4c8a9..7e8dafea94e 100644 --- a/tools/binman/bintool_test.py +++ b/tools/binman/bintool_test.py @@ -55,14 +55,14 @@ class TestBintool(unittest.TestCase): def test_version(self): """Check handling of a tool being present or absent""" btest = Bintool.create('_testing') - with test_util.capture_sys_output() as (stdout, _): + with terminal.capture() as (stdout, _): btest.show() self.assertFalse(btest.is_present()) self.assertIn('-', stdout.getvalue()) btest.present = True self.assertTrue(btest.is_present()) self.assertEqual('123', btest.version()) - with test_util.capture_sys_output() as (stdout, _): + with terminal.capture() as (stdout, _): btest.show() self.assertIn('123', stdout.getvalue()) @@ -90,7 +90,7 @@ class TestBintool(unittest.TestCase): col = terminal.Color() with unittest.mock.patch.object(tools, 'download', side_effect=fake_download): - with test_util.capture_sys_output() as (stdout, _): + with terminal.capture() as (stdout, _): btest.fetch_tool(method, col, False) return stdout.getvalue() @@ -144,7 +144,7 @@ class TestBintool(unittest.TestCase): with unittest.mock.patch.object(bintool.Bintool, 'tooldir', destdir): with unittest.mock.patch.object(tools, 'download', side_effect=handle_download): - with test_util.capture_sys_output() as (stdout, _): + with terminal.capture() as (stdout, _): Bintool.fetch_tools(bintool.FETCH_ANY, ['_testing'] * 2) self.assertTrue(os.path.exists(dest_fname)) data = tools.read_file(dest_fname) @@ -177,7 +177,7 @@ class TestBintool(unittest.TestCase): self.count = collections.defaultdict(int) with unittest.mock.patch.object(bintool.Bintool, 'fetch_tool', side_effect=fake_fetch): - with test_util.capture_sys_output() as (stdout, _): + with terminal.capture() as (stdout, _): Bintool.fetch_tools(method, ['all']) lines = stdout.getvalue().splitlines() self.assertIn(f'{self.count[bintool.FETCHED]}: ', lines[-2]) @@ -220,7 +220,7 @@ class TestBintool(unittest.TestCase): side_effect=[all_tools]): with unittest.mock.patch.object(bintool.Bintool, 'create', side_effect=self.btools.values()): - with test_util.capture_sys_output() as (stdout, _): + with terminal.capture() as (stdout, _): Bintool.fetch_tools(bintool.FETCH_ANY, ['missing']) lines = stdout.getvalue().splitlines() num_tools = len(self.btools) @@ -255,7 +255,7 @@ class TestBintool(unittest.TestCase): with unittest.mock.patch.object(bintool.Bintool, 'tooldir', self._indir): with unittest.mock.patch.object(tools, 'run', side_effect=fake_run): - with test_util.capture_sys_output() as (stdout, _): + with terminal.capture() as (stdout, _): btest.fetch_tool(bintool.FETCH_BUILD, col, False) fname = os.path.join(self._indir, '_testing') return fname if write_file else self.fname, stdout.getvalue() @@ -278,7 +278,7 @@ class TestBintool(unittest.TestCase): btest.install = True col = terminal.Color() with unittest.mock.patch.object(tools, 'run', return_value=None): - with test_util.capture_sys_output() as _: + with terminal.capture() as _: result = btest.fetch_tool(bintool.FETCH_BIN, col, False) self.assertEqual(bintool.FETCHED, result) @@ -287,7 +287,7 @@ class TestBintool(unittest.TestCase): btest = Bintool.create('_testing') btest.disable = True col = terminal.Color() - with test_util.capture_sys_output() as _: + with terminal.capture() as _: result = btest.fetch_tool(bintool.FETCH_BIN, col, False) self.assertEqual(bintool.FAIL, result) @@ -314,7 +314,7 @@ class TestBintool(unittest.TestCase): with unittest.mock.patch.object(tools, 'run', side_effect=fake_run): with unittest.mock.patch.object(tools, 'download', side_effect=handle_download): - with test_util.capture_sys_output() as _: + with terminal.capture() as _: for name in Bintool.get_tool_list(): btool = Bintool.create(name) for method in range(bintool.FETCH_COUNT): diff --git a/tools/binman/cbfs_util_test.py b/tools/binman/cbfs_util_test.py index 4c415b7ce94..2494a6b9405 100755 --- a/tools/binman/cbfs_util_test.py +++ b/tools/binman/cbfs_util_test.py @@ -20,6 +20,7 @@ from binman import bintool from binman import cbfs_util from binman.cbfs_util import CbfsWriter from binman import elf +from u_boot_pylib import terminal from u_boot_pylib import test_util from u_boot_pylib import tools @@ -314,7 +315,7 @@ class TestCbfs(unittest.TestCase): newdata = data[:-4] + struct.pack('<I', cbw._header_offset + 1) # We should still be able to find the master header by searching - with test_util.capture_sys_output() as (stdout, _stderr): + with terminal.capture() as (stdout, _stderr): cbfs = cbfs_util.CbfsReader(newdata) self.assertIn('Relative offset seems wrong', stdout.getvalue()) self.assertIn('u-boot', cbfs.files) @@ -330,7 +331,7 @@ class TestCbfs(unittest.TestCase): # Drop most of the header and try reading the modified CBFS newdata = data[:cbw._header_offset + 4] - with test_util.capture_sys_output() as (stdout, _stderr): + with terminal.capture() as (stdout, _stderr): with self.assertRaises(ValueError) as e: cbfs_util.CbfsReader(newdata) self.assertIn('Relative offset seems wrong', stdout.getvalue()) @@ -351,7 +352,7 @@ class TestCbfs(unittest.TestCase): # Remove all but 4 bytes of the file headerm and try to read the file newdata = data[:pos + 4] - with test_util.capture_sys_output() as (stdout, _stderr): + with terminal.capture() as (stdout, _stderr): with io.BytesIO(newdata) as fd: fd.seek(pos) self.assertEqual(False, cbr._read_next_file(fd)) @@ -373,7 +374,7 @@ class TestCbfs(unittest.TestCase): # Create a new CBFS with only the first 16 bytes of the file name, then # try to read the file newdata = data[:pos + cbfs_util.FILE_HEADER_LEN + 16] - with test_util.capture_sys_output() as (stdout, _stderr): + with terminal.capture() as (stdout, _stderr): with io.BytesIO(newdata) as fd: fd.seek(pos) self.assertEqual(False, cbr._read_next_file(fd)) @@ -389,7 +390,7 @@ class TestCbfs(unittest.TestCase): try: cbfs_util.DEBUG = True - with test_util.capture_sys_output() as (stdout, _stderr): + with terminal.capture() as (stdout, _stderr): cbfs_util.CbfsReader(data) self.assertEqual('name u-boot\nftype 50\ndata %s\n' % U_BOOT_DATA, stdout.getvalue()) @@ -416,7 +417,7 @@ class TestCbfs(unittest.TestCase): # Create a new CBFS with the tag changed to something invalid newdata = data[:pos] + struct.pack('>I', 0x123) + data[pos + 4:] - with test_util.capture_sys_output() as (stdout, _stderr): + with terminal.capture() as (stdout, _stderr): cbfs_util.CbfsReader(newdata) self.assertEqual('Unknown attribute tag 123\n', stdout.getvalue()) @@ -441,7 +442,7 @@ class TestCbfs(unittest.TestCase): tag_pos = (4 + pos + cbfs_util.FILE_HEADER_LEN + cbfs_util.ATTRIBUTE_ALIGN) newdata = data[:tag_pos + 4] - with test_util.capture_sys_output() as (stdout, _stderr): + with terminal.capture() as (stdout, _stderr): with io.BytesIO(newdata) as fd: fd.seek(pos) self.assertEqual(False, cbr._read_next_file(fd)) diff --git a/tools/binman/control.py b/tools/binman/control.py index 81f61e3e152..1946656f7d3 100644 --- a/tools/binman/control.py +++ b/tools/binman/control.py @@ -777,7 +777,7 @@ def Binman(args): if args.cmd in ['ls', 'extract', 'replace', 'tool', 'sign']: try: - tout.init(args.verbosity) + tout.init(args.verbosity + 1) if args.cmd == 'replace': tools.prepare_output_dir(args.outdir, args.preserve) else: @@ -835,9 +835,9 @@ def Binman(args): args.indir.append(board_pathname) try: - tout.init(args.verbosity) + tout.init(args.verbosity + 1) elf.debug = args.debug - cbfs_util.VERBOSE = args.verbosity > 2 + cbfs_util.VERBOSE = args.verbosity > tout.NOTICE state.use_fake_dtb = args.fake_dtb # Normally we replace the 'u-boot' etype with 'u-boot-expanded', etc. diff --git a/tools/binman/elf_test.py b/tools/binman/elf_test.py index 2f22639dffc..5b173392898 100644 --- a/tools/binman/elf_test.py +++ b/tools/binman/elf_test.py @@ -13,6 +13,7 @@ import unittest from binman import elf from u_boot_pylib import command +from u_boot_pylib import terminal from u_boot_pylib import test_util from u_boot_pylib import tools from u_boot_pylib import tout @@ -187,7 +188,7 @@ class TestElf(unittest.TestCase): entry = FakeEntry(24) section = FakeSection() elf_fname = self.ElfTestFile('u_boot_binman_syms') - with test_util.capture_sys_output() as (stdout, stderr): + with terminal.capture() as (stdout, stderr): elf.LookupAndWriteSymbols(elf_fname, entry, section) self.assertTrue(len(stdout.getvalue()) > 0) finally: diff --git a/tools/binman/entries.rst b/tools/binman/entries.rst index 4f05aa0a323..12a39d070e4 100644 --- a/tools/binman/entries.rst +++ b/tools/binman/entries.rst @@ -53,6 +53,22 @@ respecting the `bootph-xxx` tags in the devicetree. +.. _etype_atf_bl1: + +Entry: atf-bl1: AP Trusted ROM (TF-A) BL1 blob +----------------------------------------------------- + +Properties / Entry arguments: + - atf-bl1-path: Filename of file to read into entry. This is typically + called bl1.bin + +This entry holds the AP Trusted ROM firmware typically used by an SoC to +help initialize the SoC before the SPL or U-Boot is started. See +https://github.com/TrustedFirmware-A/trusted-firmware-a for more information +about Boot Loader stage 1 (BL1) or about Trusted Firmware (TF-A) + + + .. _etype_atf_bl31: Entry: atf-bl31: ARM Trusted Firmware (ATF) BL31 blob diff --git a/tools/binman/etype/atf_bl1.py b/tools/binman/etype/atf_bl1.py new file mode 100644 index 00000000000..7adf10e693c --- /dev/null +++ b/tools/binman/etype/atf_bl1.py @@ -0,0 +1,23 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright 2025 Texas Instruments Incorporated +# +# Entry-type module for Application Processor Trusted ROM (BL1) +# + +from binman.etype.blob_named_by_arg import Entry_blob_named_by_arg + +class Entry_atf_bl1(Entry_blob_named_by_arg): + """Application Processor (AP) Trusted ROM BL1 blob + + Properties / Entry arguments: + - atf-bl1-path: Filename of file to read into entry. This is typically + called bl1.bin or bl1.elf + + This entry holds the boot code initialization like exception vectors and + processor and platform initialization. + + See https://github.com/TrustedFirmware-A/trusted-firmware-a for more information. + """ + def __init__(self, section, etype, node): + super().__init__(section, etype, node, 'atf-bl1') + self.external = True diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py index 4c4c8c417f8..1d50bb47753 100644 --- a/tools/binman/etype/section.py +++ b/tools/binman/etype/section.py @@ -189,7 +189,7 @@ class Entry_section(Entry): self._sort = fdt_util.GetBool(self._node, 'sort-by-offset') self._end_at_4gb = fdt_util.GetBool(self._node, 'end-at-4gb') self._skip_at_start = fdt_util.GetInt(self._node, 'skip-at-start') - if self._end_at_4gb: + if self._end_at_4gb and self.GetImage().copy_to_orig: if not self.size: self.Raise("Section size must be provided when using end-at-4gb") if self._skip_at_start is not None: @@ -263,6 +263,8 @@ class Entry_section(Entry): super().AddMissingProperties(have_image_pos) if self.compress != 'none': have_image_pos = False + if self._end_at_4gb: + state.AddZeroProp(self._node, 'skip-at-start') for entry in self._entries.values(): entry.AddMissingProperties(have_image_pos) @@ -505,6 +507,8 @@ class Entry_section(Entry): def SetCalculatedProperties(self): super().SetCalculatedProperties() + if self._end_at_4gb: + state.SetInt(self._node, 'skip-at-start', self._skip_at_start) for entry in self._entries.values(): entry.SetCalculatedProperties() diff --git a/tools/binman/fip_util_test.py b/tools/binman/fip_util_test.py index 56aa56f4643..cb4001be020 100755 --- a/tools/binman/fip_util_test.py +++ b/tools/binman/fip_util_test.py @@ -22,6 +22,7 @@ sys.path.insert(2, os.path.join(OUR_PATH, '..')) # pylint: disable=C0413 from binman import bintool from binman import fip_util +from u_boot_pylib import terminal from u_boot_pylib import test_util from u_boot_pylib import tools @@ -215,7 +216,7 @@ toc_entry_t toc_entries[] = { macros = fip_util.parse_macros(self._indir) names = fip_util.parse_names(self._indir) - with test_util.capture_sys_output() as (stdout, _): + with terminal.capture() as (stdout, _): fip_util.create_code_output(macros, names) self.assertIn( "UUID 'UUID_TRUSTED_OS_FW_KEY_CERT' is not mentioned in tbbr_config.c file", @@ -239,7 +240,7 @@ FIP_TYPE_LIST = [ ] # end blah de blah ''', binary=False) - with test_util.capture_sys_output() as (stdout, _): + with terminal.capture() as (stdout, _): fip_util.main(self.args, self.src_file) self.assertIn('Needs update', stdout.getvalue()) @@ -256,7 +257,7 @@ FIP_TYPE_LIST = [ 0x9d, 0xf3, 0x19, 0xed, 0xa1, 0x1f, 0x68, 0x01]), ] # end blah blah''', binary=False) - with test_util.capture_sys_output() as (stdout, _): + with terminal.capture() as (stdout, _): fip_util.main(self.args, self.src_file) self.assertIn('is up-to-date', stdout.getvalue()) @@ -269,7 +270,7 @@ blah blah''', binary=False) args = self.args.copy() args.remove('-D') tools.write_file(self.src_file, '', binary=False) - with test_util.capture_sys_output(): + with terminal.capture(): fip_util.main(args, self.src_file) @unittest.skipIf(not HAVE_FIPTOOL, 'No fiptool available') @@ -389,7 +390,7 @@ Trusted Boot Firmware BL2: offset=0xC0, size=0xE, cmdline="--tb-fw" def test_fiptool_errors(self): """Check some error reporting from fiptool""" with self.assertRaises(Exception) as err: - with test_util.capture_sys_output(): + with terminal.capture(): FIPTOOL.create_bad() self.assertIn("unrecognized option '--fred'", str(err.exception)) diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index fa174900014..4cf7dfc8216 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -36,6 +36,7 @@ from binman.etype import fdtmap from binman.etype import image_header from binman.image import Image from u_boot_pylib import command +from u_boot_pylib import terminal from u_boot_pylib import test_util from u_boot_pylib import tools from u_boot_pylib import tout @@ -87,6 +88,7 @@ REFCODE_DATA = b'refcode' FSP_M_DATA = b'fsp_m' FSP_S_DATA = b'fsp_s' FSP_T_DATA = b'fsp_t' +ATF_BL1_DATA = b'bl1' ATF_BL31_DATA = b'bl31' TEE_OS_DATA = b'this is some tee OS data' TI_DM_DATA = b'tidmtidm' @@ -225,6 +227,7 @@ class TestFunctional(unittest.TestCase): TestFunctional._MakeInputFile('compress', COMPRESS_DATA) TestFunctional._MakeInputFile('compress_big', COMPRESS_DATA_BIG) + TestFunctional._MakeInputFile('bl1.bin', ATF_BL1_DATA) TestFunctional._MakeInputFile('bl31.bin', ATF_BL31_DATA) TestFunctional._MakeInputFile('tee-pager.bin', TEE_OS_DATA) TestFunctional._MakeInputFile('dm.bin', TI_DM_DATA) @@ -273,7 +276,7 @@ class TestFunctional(unittest.TestCase): @classmethod def setup_test_args(cls, preserve_indir=False, preserve_outdirs=False, - toolpath=None, verbosity=None): + toolpath=None, verbosity=None, no_capture=False): """Accept arguments controlling test execution Args: @@ -282,12 +285,13 @@ class TestFunctional(unittest.TestCase): preserve_outdir: Preserve the output directories used by tests. Each test has its own, so this is normally only useful when running a single test. - toolpath: ist of paths to use for tools + toolpath: list of paths to use for tools """ cls.preserve_indir = preserve_indir cls.preserve_outdirs = preserve_outdirs cls.toolpath = toolpath cls.verbosity = verbosity + cls.no_capture = no_capture def _CheckBintool(self, bintool): if not bintool.is_present(): @@ -1796,14 +1800,14 @@ class TestFunctional(unittest.TestCase): def testEntryDocs(self): """Test for creation of entry documentation""" - with test_util.capture_sys_output() as (stdout, stderr): + with terminal.capture() as (stdout, stderr): control.WriteEntryDocs(control.GetEntryModules()) self.assertTrue(len(stdout.getvalue()) > 0) def testEntryDocsMissing(self): """Test handling of missing entry documentation""" with self.assertRaises(ValueError) as e: - with test_util.capture_sys_output() as (stdout, stderr): + with terminal.capture() as (stdout, stderr): control.WriteEntryDocs(control.GetEntryModules(), 'u_boot') self.assertIn('Documentation is missing for modules: u_boot', str(e.exception)) @@ -1918,7 +1922,7 @@ class TestFunctional(unittest.TestCase): entry_args = { 'keydir': 'devkeys', } - with test_util.capture_sys_output() as (_, stderr): + with terminal.capture() as (_, stderr): self._DoTestFile('071_gbb.dts', force_missing_bintools='futility', entry_args=entry_args) err = stderr.getvalue() @@ -2014,7 +2018,7 @@ class TestFunctional(unittest.TestCase): entry_args = { 'keydir': 'devkeys', } - with test_util.capture_sys_output() as (_, stderr): + with terminal.capture() as (_, stderr): self._DoTestFile('074_vblock.dts', force_missing_bintools='futility', entry_args=entry_args) @@ -2058,7 +2062,7 @@ class TestFunctional(unittest.TestCase): # We should only get the expected message in verbose mode for verbosity in (0, 2): - with test_util.capture_sys_output() as (stdout, stderr): + with terminal.capture() as (stdout, stderr): retcode = self._DoTestFile('006_dual_image.dts', verbosity=verbosity, images=['image2']) @@ -2247,7 +2251,7 @@ class TestFunctional(unittest.TestCase): def testExtendSizeBad(self): """Test an extending entry which fails to provide contents""" - with test_util.capture_sys_output() as (stdout, stderr): + with terminal.capture() as (stdout, stderr): with self.assertRaises(ValueError) as e: self._DoReadFileDtb('089_extend_size_bad.dts', map=True) self.assertIn("Node '/binman/_testing': Cannot obtain contents when " @@ -2376,7 +2380,7 @@ class TestFunctional(unittest.TestCase): def testPackOverlapMap(self): """Test that overlapping regions are detected""" - with test_util.capture_sys_output() as (stdout, stderr): + with terminal.capture() as (stdout, stderr): with self.assertRaises(ValueError) as e: self._DoTestFile('014_pack_overlap.dts', map=True) map_fname = tools.get_output_filename('image.map') @@ -2570,7 +2574,7 @@ class TestFunctional(unittest.TestCase): def testIfwiMissing(self): """Test that binman still produces an image if ifwitool is missing""" self._SetupIfwi('fitimage.bin') - with test_util.capture_sys_output() as (_, stderr): + with terminal.capture() as (_, stderr): self._DoTestFile('111_x86_rom_ifwi.dts', force_missing_bintools='ifwitool') err = stderr.getvalue() @@ -2914,7 +2918,7 @@ class TestFunctional(unittest.TestCase): tmpdir = None try: tmpdir, updated_fname = self._SetupImageInTmpdir() - with test_util.capture_sys_output() as (stdout, stderr): + with terminal.capture() as (stdout, stderr): self._DoBinman('ls', '-i', updated_fname) finally: if tmpdir: @@ -3078,7 +3082,7 @@ class TestFunctional(unittest.TestCase): tmpdir = None try: tmpdir, updated_fname = self._SetupImageInTmpdir() - with test_util.capture_sys_output() as (stdout, stderr): + with terminal.capture() as (stdout, stderr): self._DoBinman('extract', '-i', updated_fname, 'u-boot', '-f', fname) finally: @@ -3729,7 +3733,7 @@ class TestFunctional(unittest.TestCase): u_boot_fname1 = os.path.join(outdir, 'u-boot') os.remove(u_boot_fname1) - with test_util.capture_sys_output() as (stdout, stderr): + with terminal.capture() as (stdout, stderr): control.ReplaceEntries(updated_fname, None, outdir, []) self.assertIn("Skipping entry '/u-boot' from missing file", stderr.getvalue()) @@ -3870,7 +3874,7 @@ class TestFunctional(unittest.TestCase): def testMkimageMissing(self): """Test that binman still produces an image if mkimage is missing""" self._SetupSplElf() - with test_util.capture_sys_output() as (_, stderr): + with terminal.capture() as (_, stderr): self._DoTestFile('156_mkimage.dts', force_missing_bintools='mkimage') err = stderr.getvalue() @@ -3890,7 +3894,7 @@ class TestFunctional(unittest.TestCase): def testExtblobMissingOk(self): """Test an image with an missing external blob that is allowed""" - with test_util.capture_sys_output() as (stdout, stderr): + with terminal.capture() as (stdout, stderr): ret = self._DoTestFile('158_blob_ext_missing.dts', allow_missing=True) self.assertEqual(103, ret) @@ -3901,7 +3905,7 @@ class TestFunctional(unittest.TestCase): def testExtblobMissingOkFlag(self): """Test an image with an missing external blob allowed with -W""" - with test_util.capture_sys_output() as (stdout, stderr): + with terminal.capture() as (stdout, stderr): ret = self._DoTestFile('158_blob_ext_missing.dts', allow_missing=True, ignore_missing=True) self.assertEqual(0, ret) @@ -3912,7 +3916,7 @@ class TestFunctional(unittest.TestCase): def testExtblobMissingOkSect(self): """Test an image with an missing external blob that is allowed""" - with test_util.capture_sys_output() as (stdout, stderr): + with terminal.capture() as (stdout, stderr): self._DoTestFile('159_blob_ext_missing_sect.dts', allow_missing=True) err = stderr.getvalue() @@ -3920,7 +3924,7 @@ class TestFunctional(unittest.TestCase): def testPackX86RomMeMissingDesc(self): """Test that an missing Intel descriptor entry is allowed""" - with test_util.capture_sys_output() as (stdout, stderr): + with terminal.capture() as (stdout, stderr): self._DoTestFile('164_x86_rom_me_missing.dts', allow_missing=True) err = stderr.getvalue() self.assertRegex(err, "Image 'image'.*missing.*: intel-descriptor") @@ -3930,7 +3934,7 @@ class TestFunctional(unittest.TestCase): self._SetupIfwi('fitimage.bin') pathname = os.path.join(self._indir, 'fitimage.bin') os.remove(pathname) - with test_util.capture_sys_output() as (stdout, stderr): + with terminal.capture() as (stdout, stderr): self._DoTestFile('111_x86_rom_ifwi.dts', allow_missing=True) err = stderr.getvalue() self.assertRegex(err, "Image 'image'.*missing.*: intel-ifwi") @@ -4152,7 +4156,7 @@ class TestFunctional(unittest.TestCase): def testFitMissingOK(self): """Test that binman still produces a FIT image if mkimage is missing""" - with test_util.capture_sys_output() as (_, stderr): + with terminal.capture() as (_, stderr): self._DoTestFile('162_fit_external.dts', allow_missing=True, force_missing_bintools='mkimage') err = stderr.getvalue() @@ -4226,7 +4230,7 @@ class TestFunctional(unittest.TestCase): def testFitExtblobMissingOk(self): """Test a FIT with a missing external blob that is allowed""" - with test_util.capture_sys_output() as (stdout, stderr): + with terminal.capture() as (stdout, stderr): self._DoTestFile('168_fit_missing_blob.dts', allow_missing=True) err = stderr.getvalue() @@ -4395,7 +4399,7 @@ class TestFunctional(unittest.TestCase): control.missing_blob_help = control._ReadMissingBlobHelp() control.missing_blob_help['wibble'] = 'Wibble test' control.missing_blob_help['another'] = 'Another test' - with test_util.capture_sys_output() as (stdout, stderr): + with terminal.capture() as (stdout, stderr): self._DoTestFile('168_fit_missing_blob.dts', allow_missing=True) err = stderr.getvalue() @@ -4664,7 +4668,7 @@ class TestFunctional(unittest.TestCase): def testLz4Missing(self): """Test that binman still produces an image if lz4 is missing""" - with test_util.capture_sys_output() as (_, stderr): + with terminal.capture() as (_, stderr): self._DoTestFile('185_compress_section.dts', force_missing_bintools='lz4') err = stderr.getvalue() @@ -5061,7 +5065,7 @@ class TestFunctional(unittest.TestCase): def testTiming(self): """Test output of timing information""" data = self._DoReadFile('055_sections.dts') - with test_util.capture_sys_output() as (stdout, stderr): + with terminal.capture() as (stdout, stderr): state.TimingShow() self.assertIn('read:', stdout.getvalue()) self.assertIn('compress:', stdout.getvalue()) @@ -5156,7 +5160,7 @@ class TestFunctional(unittest.TestCase): self.assertEqual(version, state.GetVersion(self._indir)) with self.assertRaises(SystemExit): - with test_util.capture_sys_output() as (_, stderr): + with terminal.capture() as (_, stderr): self._DoBinman('-V') self.assertEqual('Binman %s\n' % version, stderr.getvalue()) @@ -5176,7 +5180,7 @@ class TestFunctional(unittest.TestCase): try: tmpdir, updated_fname = self._SetupImageInTmpdir() - with test_util.capture_sys_output() as (stdout, _): + with terminal.capture() as (stdout, _): self._DoBinman('extract', '-i', updated_fname, '-F', 'list') self.assertEqual( '''Flag (-F) Entry type Description @@ -5218,7 +5222,7 @@ fdt fdtmap Extract the devicetree blob from the fdtmap def testExtblobListMissingOk(self): """Test an image with an missing external blob that is allowed""" - with test_util.capture_sys_output() as (stdout, stderr): + with terminal.capture() as (stdout, stderr): self._DoTestFile('216_blob_ext_list_missing.dts', allow_missing=True) err = stderr.getvalue() @@ -5295,7 +5299,7 @@ fdt fdtmap Extract the devicetree blob from the fdtmap tmpdir = None try: tmpdir, updated_fname = self._SetupImageInTmpdir() - with test_util.capture_sys_output() as (stdout, stderr): + with terminal.capture() as (stdout, stderr): self._DoBinman('ls', '-i', updated_fname) finally: if tmpdir: @@ -5378,7 +5382,7 @@ fdt fdtmap Extract the devicetree blob from the fdtmap self.assertEqual(True, fent.valid) def testFipMissing(self): - with test_util.capture_sys_output() as (stdout, stderr): + with terminal.capture() as (stdout, stderr): self._DoTestFile('209_fip_missing.dts', allow_missing=True) err = stderr.getvalue() self.assertRegex(err, "Image 'image'.*missing.*: rmm-fw") @@ -5432,7 +5436,7 @@ fdt fdtmap Extract the devicetree blob from the fdtmap def testFakeBlob(self): """Test handling of faking an external blob""" - with test_util.capture_sys_output() as (stdout, stderr): + with terminal.capture() as (stdout, stderr): self._DoTestFile('217_fake_blob.dts', allow_missing=True, allow_fake_blobs=True) err = stderr.getvalue() @@ -5442,7 +5446,7 @@ fdt fdtmap Extract the devicetree blob from the fdtmap def testExtblobListFaked(self): """Test an extblob with missing external blob that are faked""" - with test_util.capture_sys_output() as (stdout, stderr): + with terminal.capture() as (stdout, stderr): self._DoTestFile('216_blob_ext_list_missing.dts', allow_fake_blobs=True) err = stderr.getvalue() @@ -5450,7 +5454,7 @@ fdt fdtmap Extract the devicetree blob from the fdtmap def testListBintools(self): args = ['tool', '--list'] - with test_util.capture_sys_output() as (stdout, _): + with terminal.capture() as (stdout, _): self._DoBinman(*args) out = stdout.getvalue().splitlines() self.assertTrue(len(out) >= 2) @@ -5474,20 +5478,20 @@ fdt fdtmap Extract the devicetree blob from the fdtmap args = ['tool', '--fetch', '_testing'] with unittest.mock.patch.object(tools, 'download', side_effect=fail_download): - with test_util.capture_sys_output() as (stdout, _): + with terminal.capture() as (stdout, _): self._DoBinman(*args) self.assertIn('failed to fetch with all methods', stdout.getvalue()) def testBintoolDocs(self): """Test for creation of bintool documentation""" - with test_util.capture_sys_output() as (stdout, stderr): + with terminal.capture() as (stdout, stderr): control.write_bintool_docs(control.bintool.Bintool.get_tool_list()) self.assertTrue(len(stdout.getvalue()) > 0) def testBintoolDocsMissing(self): """Test handling of missing bintool documentation""" with self.assertRaises(ValueError) as e: - with test_util.capture_sys_output() as (stdout, stderr): + with terminal.capture() as (stdout, stderr): control.write_bintool_docs( control.bintool.Bintool.get_tool_list(), 'mkimage') self.assertIn('Documentation is missing for modules: mkimage', @@ -5507,7 +5511,7 @@ fdt fdtmap Extract the devicetree blob from the fdtmap tmpdir = None try: tmpdir, updated_fname = self._SetupImageInTmpdir() - with test_util.capture_sys_output() as (stdout, stderr): + with terminal.capture() as (stdout, stderr): self._RunBinman('ls', '-i', updated_fname) finally: if tmpdir: @@ -5532,7 +5536,7 @@ fdt fdtmap Extract the devicetree blob from the fdtmap entry_args = { 'keydir': 'devkeys', } - with test_util.capture_sys_output() as (_, stderr): + with terminal.capture() as (_, stderr): self._DoTestFile('220_fit_subentry_bintool.dts', force_missing_bintools='futility', entry_args=entry_args) err = stderr.getvalue() @@ -5573,6 +5577,11 @@ fdt fdtmap Extract the devicetree blob from the fdtmap data = self._DoReadFile('225_ti_dm.dts') self.assertEqual(TI_DM_DATA, data[:len(TI_DM_DATA)]) + def testPackBl1(self): + """test if an image with a bl1 binary can be created""" + data = self._DoReadFile('347_bl1.dts') + self.assertEqual(ATF_BL1_DATA, data[:len(ATF_BL1_DATA)]) + def testFitFdtOper(self): """Check handling of a specified FIT operation""" entry_args = { @@ -5729,7 +5738,7 @@ fdt fdtmap Extract the devicetree blob from the fdtmap 'tee-os-path': 'missing.elf', } test_subdir = os.path.join(self._indir, TEST_FDT_SUBDIR) - with test_util.capture_sys_output() as (stdout, stderr): + with terminal.capture() as (stdout, stderr): self._DoTestFile( '226_fit_split_elf.dts', entry_args=entry_args, extra_indirs=[test_subdir], verbosity=3, **kwargs) @@ -5784,7 +5793,7 @@ fdt fdtmap Extract the devicetree blob from the fdtmap def testMkimageMissingBlob(self): """Test using mkimage to build an image""" - with test_util.capture_sys_output() as (stdout, stderr): + with terminal.capture() as (stdout, stderr): self._DoTestFile('229_mkimage_missing.dts', allow_missing=True, allow_fake_blobs=True) err = stderr.getvalue() @@ -6497,7 +6506,7 @@ fdt fdtmap Extract the devicetree blob from the fdtmap fdt_util.fdt32_to_cpu(node.props['entry'].value)) self.assertEqual(U_BOOT_DATA, node.props['data'].bytes) - with test_util.capture_sys_output() as (stdout, stderr): + with terminal.capture() as (stdout, stderr): self.checkFitTee('264_tee_os_opt_fit.dts', '') err = stderr.getvalue() self.assertRegex( @@ -6530,7 +6539,7 @@ fdt fdtmap Extract the devicetree blob from the fdtmap def testExtblobOptional(self): """Test an image with an external blob that is optional""" - with test_util.capture_sys_output() as (stdout, stderr): + with terminal.capture() as (stdout, stderr): data = self._DoReadFile('266_blob_ext_opt.dts') self.assertEqual(REFCODE_DATA, data) err = stderr.getvalue() @@ -6686,7 +6695,7 @@ fdt fdtmap Extract the devicetree blob from the fdtmap 'tee-os-path': 'missing.bin', } test_subdir = os.path.join(self._indir, TEST_FDT_SUBDIR) - with test_util.capture_sys_output() as (stdout, stderr): + with terminal.capture() as (stdout, stderr): data = self._DoReadFileDtb( '276_fit_firmware_loadables.dts', entry_args=entry_args, @@ -6722,7 +6731,7 @@ fdt fdtmap Extract the devicetree blob from the fdtmap def testTooldir(self): """Test that we can specify the tooldir""" - with test_util.capture_sys_output() as (stdout, stderr): + with terminal.capture() as (stdout, stderr): self.assertEqual(0, self._DoBinman('--tooldir', 'fred', 'tool', '-l')) self.assertEqual('fred', bintool.Bintool.tooldir) @@ -6731,7 +6740,7 @@ fdt fdtmap Extract the devicetree blob from the fdtmap self.assertEqual(['fred'], tools.tool_search_paths) # Try with a few toolpaths; the tooldir should be at the end - with test_util.capture_sys_output() as (stdout, stderr): + with terminal.capture() as (stdout, stderr): self.assertEqual(0, self._DoBinman( '--toolpath', 'mary', '--toolpath', 'anna', '--tooldir', 'fred', 'tool', '-l')) @@ -6836,7 +6845,7 @@ fdt fdtmap Extract the devicetree blob from the fdtmap entry_args = { 'keyfile': 'keyfile', } - with test_util.capture_sys_output() as (_, stderr): + with terminal.capture() as (_, stderr): self._DoTestFile('279_x509_cert.dts', force_missing_bintools='openssl', entry_args=entry_args) @@ -6850,7 +6859,7 @@ fdt fdtmap Extract the devicetree blob from the fdtmap def testMkimageMissingBlobMultiple(self): """Test missing blob with mkimage entry and multiple-data-files""" - with test_util.capture_sys_output() as (stdout, stderr): + with terminal.capture() as (stdout, stderr): self._DoTestFile('292_mkimage_missing_multiple.dts', allow_missing=True) err = stderr.getvalue() self.assertIn("is missing external blobs and is non-functional", err) @@ -7196,7 +7205,7 @@ fdt fdtmap Extract the devicetree blob from the fdtmap entry_args = { 'keyfile': keyfile, } - with test_util.capture_sys_output() as (_, stderr): + with terminal.capture() as (_, stderr): self._DoTestFile('296_ti_secure.dts', force_missing_bintools='openssl', entry_args=entry_args) @@ -7372,7 +7381,7 @@ fdt fdtmap Extract the devicetree blob from the fdtmap self._MakeInputFile("ssk.pem", data) self._SetupPmuFwlElf() self._SetupSplElf() - with test_util.capture_sys_output() as (_, stderr): + with terminal.capture() as (_, stderr): self._DoTestFile('307_xilinx_bootgen_sign.dts', force_missing_bintools='bootgen') err = stderr.getvalue() @@ -7575,7 +7584,7 @@ fdt fdtmap Extract the devicetree blob from the fdtmap def test_assume_size_ok(self): """Test handling of the assume-size where it fits OK""" - with test_util.capture_sys_output() as (stdout, stderr): + with terminal.capture() as (stdout, stderr): self._DoTestFile('327_assume_size_ok.dts', allow_missing=True, allow_fake_blobs=True) err = stderr.getvalue() @@ -7585,7 +7594,7 @@ fdt fdtmap Extract the devicetree blob from the fdtmap def test_assume_size_no_fake(self): """Test handling of the assume-size where it fits OK""" - with test_util.capture_sys_output() as (stdout, stderr): + with terminal.capture() as (stdout, stderr): self._DoTestFile('327_assume_size_ok.dts', allow_missing=True) err = stderr.getvalue() self.assertRegex( @@ -7817,7 +7826,7 @@ fdt fdtmap Extract the devicetree blob from the fdtmap def testMkeficapsuleMissingOk(self): """Test that binman deals with mkeficapsule being missing""" - with test_util.capture_sys_output() as (stdout, stderr): + with terminal.capture() as (stdout, stderr): ret = self._DoTestFile('311_capsule.dts', force_missing_bintools='mkeficapsule', allow_missing=True) @@ -7842,7 +7851,7 @@ fdt fdtmap Extract the devicetree blob from the fdtmap def testSymbolsCompressed(self): """Test binman complains about symbols from a compressed section""" - with test_util.capture_sys_output() as (stdout, stderr): + with terminal.capture() as (stdout, stderr): self.checkSymbols('338_symbols_comp.dts', U_BOOT_SPL_DATA, None) out = stdout.getvalue() self.assertIn('Symbol-writing: no value for /binman/section/u-boot', diff --git a/tools/binman/image_test.py b/tools/binman/image_test.py index 7d65e2d589a..26e161c91fc 100644 --- a/tools/binman/image_test.py +++ b/tools/binman/image_test.py @@ -7,7 +7,7 @@ import unittest from binman.image import Image -from u_boot_pylib.test_util import capture_sys_output +from u_boot_pylib import terminal class TestImage(unittest.TestCase): def testInvalidFormat(self): @@ -29,7 +29,7 @@ class TestImage(unittest.TestCase): def testMissingSymbolOptional(self): image = Image('name', 'node', test=True) image._entries = {} - with capture_sys_output() as (stdout, stderr): + with terminal.capture() as (stdout, stderr): val = image.GetSymbolValue('_binman_type_prop_pname', True, 'msg', 0) self.assertEqual(val, None) self.assertEqual("Warning: msg: Entry 'type' not found in list ()\n", diff --git a/tools/binman/main.py b/tools/binman/main.py index 326f5c93155..fa5ad79ca0e 100755 --- a/tools/binman/main.py +++ b/tools/binman/main.py @@ -77,8 +77,8 @@ def RunTests(debug, verbosity, processes, test_preserve_dirs, args, toolpath): # Run the entry tests first ,since these need to be the first to import the # 'entry' module. result = test_util.run_test_suites( - 'binman', debug, verbosity, test_preserve_dirs, processes, test_name, - toolpath, + 'binman', debug, verbosity, False, test_preserve_dirs, processes, + test_name, toolpath, [bintool_test.TestBintool, entry_test.TestEntry, ftest.TestFunctional, fdt_test.TestFdt, elf_test.TestElf, image_test.TestImage, cbfs_util_test.TestCbfs, fip_util_test.TestFip]) diff --git a/tools/binman/test/347_bl1.dts b/tools/binman/test/347_bl1.dts new file mode 100644 index 00000000000..1a109956204 --- /dev/null +++ b/tools/binman/test/347_bl1.dts @@ -0,0 +1,13 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + binman { + atf-bl1 { + filename = "bl1.bin"; + }; + }; +}; |