[PATCH 1/5] binman: Fix subentry expansion for FIT entry type
Alper Nebi Yasak
alpernebiyasak at gmail.com
Sun Feb 6 22:02:45 CET 2022
Binman tries to expand some entries into parts that make it up, e.g.
'u-boot' into a 'u-boot-expanded' section that contains 'u-boot-nodtb'
and 'u-boot-dtb'. Entries with child entries must call ExpandEntries()
on them to build a correct image, as it's possible that unexpanded child
entries have no data of their own. The FIT entry type doesn't currently
do this, which means putting a "u-boot" entry inside it doesn't work as
expected.
Implement ExpandEntries() for FIT and add a copy of a simple FIT image
test that checks subentry expansion in FIT entries.
Signed-off-by: Alper Nebi Yasak <alpernebiyasak at gmail.com>
---
tools/binman/etype/fit.py | 5 +++++
tools/binman/ftest.py | 45 +++++++++++++++++++++++++++++++++++++++
2 files changed, 50 insertions(+)
diff --git a/tools/binman/etype/fit.py b/tools/binman/etype/fit.py
index 6ad4a686df55..38bc2a2d784e 100644
--- a/tools/binman/etype/fit.py
+++ b/tools/binman/etype/fit.py
@@ -237,6 +237,11 @@ def _AddNode(base_node, depth, node):
self._fdt = Fdt.FromData(fdt.as_bytearray())
self._fdt.Scan()
+ def ExpandEntries(self):
+ super().ExpandEntries()
+ for section in self._fit_sections.values():
+ section.ExpandEntries()
+
def ObtainContents(self):
"""Obtain the contents of the FIT
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index 5400f76c676a..b0f548057980 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -61,6 +61,9 @@
U_BOOT_NODTB_DATA = b'nodtb with microcode pointer somewhere in here'
U_BOOT_SPL_NODTB_DATA = b'splnodtb with microcode pointer somewhere in here'
U_BOOT_TPL_NODTB_DATA = b'tplnodtb with microcode pointer somewhere in here'
+U_BOOT_EXP_DATA = U_BOOT_NODTB_DATA + U_BOOT_DTB_DATA
+U_BOOT_SPL_EXP_DATA = U_BOOT_SPL_NODTB_DATA + U_BOOT_SPL_DTB_DATA
+U_BOOT_TPL_EXP_DATA = U_BOOT_TPL_NODTB_DATA + U_BOOT_TPL_DTB_DATA
FSP_DATA = b'fsp'
CMC_DATA = b'cmc'
VBT_DATA = b'vbt'
@@ -3755,6 +3758,48 @@ def testSimpleFit(self):
self.assertEqual(len(U_BOOT_DATA), int(data_sizes[0].split()[0]))
self.assertEqual(len(U_BOOT_SPL_DTB_DATA), int(data_sizes[1].split()[0]))
+ def testSimpleFitExpandsSubentries(self):
+ """Test that FIT images expand their subentries"""
+ data = self._DoReadFileDtb('161_fit.dts', use_expanded=True)[0]
+ self.assertEqual(U_BOOT_EXP_DATA, data[:len(U_BOOT_EXP_DATA)])
+ self.assertEqual(U_BOOT_NODTB_DATA, data[-len(U_BOOT_NODTB_DATA):])
+ fit_data = data[len(U_BOOT_EXP_DATA):-len(U_BOOT_NODTB_DATA)]
+
+ # The data should be inside the FIT
+ dtb = fdt.Fdt.FromData(fit_data)
+ dtb.Scan()
+ fnode = dtb.GetNode('/images/kernel')
+ self.assertIn('data', fnode.props)
+
+ fname = os.path.join(self._indir, 'fit_data.fit')
+ tools.WriteFile(fname, fit_data)
+ out = tools.Run('dumpimage', '-l', fname)
+
+ # Check a few features to make sure the plumbing works. We don't need
+ # to test the operation of mkimage or dumpimage here. First convert the
+ # output into a dict where the keys are the fields printed by dumpimage
+ # and the values are a list of values for each field
+ lines = out.splitlines()
+
+ # Converts "Compression: gzip compressed" into two groups:
+ # 'Compression' and 'gzip compressed'
+ re_line = re.compile(r'^ *([^:]*)(?:: *(.*))?$')
+ vals = collections.defaultdict(list)
+ for line in lines:
+ mat = re_line.match(line)
+ vals[mat.group(1)].append(mat.group(2))
+
+ self.assertEquals('FIT description: test-desc', lines[0])
+ self.assertIn('Created:', lines[1])
+ self.assertIn('Image 0 (kernel)', vals)
+ self.assertIn('Hash value', vals)
+ data_sizes = vals.get('Data Size')
+ self.assertIsNotNone(data_sizes)
+ self.assertEqual(2, len(data_sizes))
+ # Format is "50 Bytes = 0.00 KiB = 0.00 MiB" so take the first word
+ self.assertEqual(len(U_BOOT_EXP_DATA), int(data_sizes[0].split()[0]))
+ self.assertEqual(len(U_BOOT_SPL_DTB_DATA), int(data_sizes[1].split()[0]))
+
def testFitExternal(self):
"""Test an image with an FIT with external images"""
data = self._DoReadFile('162_fit_external.dts')
--
2.34.1
More information about the U-Boot
mailing list