diff options
author | Simon Glass <sjg@chromium.org> | 2019-07-08 14:25:28 -0600 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2019-07-24 12:53:46 -0700 |
commit | cf2289435c7e1134c75d9217ef32238aec0ecdbf (patch) | |
tree | 9c58722f695d50ffae4968f0b89a30b1af201908 /tools/binman/ftest.py | |
parent | 086cec9f980efd6f25e184b84f626d4a667e6645 (diff) | |
download | u-boot-cf2289435c7e1134c75d9217ef32238aec0ecdbf.tar.gz |
binman: Add an image header
It is useful to be able to quickly locate the FDT map in the image. An
easy way to do this is with a pointer at the start or end of the image.
Add an 'image header' entry, which places a magic number followed by a
pointer to the FDT map. This can be located at the start or end of the
image, or at a chosen location.
As part of this, update GetSiblingImagePos() to detect missing siblings.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/binman/ftest.py')
-rw-r--r-- | tools/binman/ftest.py | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 934145ca3c..6fdecb2f3b 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -2076,7 +2076,7 @@ class TestFunctional(unittest.TestCase): # Mangle the section name, which should cause a mismatch between the # correct FDT path and the one expected by the section image = control.images['image'] - image._section._node.path += '-suffix' + image._node.path += '-suffix' entries = image.GetEntries() fdtmap = entries['fdtmap'] with self.assertRaises(ValueError) as e: @@ -2084,6 +2084,51 @@ class TestFunctional(unittest.TestCase): self.assertIn("Cannot locate node for path '/binman-suffix'", str(e.exception)) + def testFdtmapHeader(self): + """Test an FDT map and image header can be inserted in the image""" + data = self.data = self._DoReadFileRealDtb('116_fdtmap_hdr.dts') + fdtmap_pos = len(U_BOOT_DATA) + fdtmap_data = data[fdtmap_pos:] + fdt_data = fdtmap_data[16:] + dtb = fdt.Fdt.FromData(fdt_data) + fdt_size = dtb.GetFdtObj().totalsize() + hdr_data = data[-8:] + self.assertEqual('BinM', hdr_data[:4]) + offset = struct.unpack('<I', hdr_data[4:])[0] & 0xffffffff + self.assertEqual(fdtmap_pos - 0x400, offset - (1 << 32)) + + def testFdtmapHeaderStart(self): + """Test an image header can be inserted at the image start""" + data = self.data = self._DoReadFileRealDtb('117_fdtmap_hdr_start.dts') + fdtmap_pos = 0x100 + len(U_BOOT_DATA) + hdr_data = data[:8] + self.assertEqual('BinM', hdr_data[:4]) + offset = struct.unpack('<I', hdr_data[4:])[0] + self.assertEqual(fdtmap_pos, offset) + + def testFdtmapHeaderPos(self): + """Test an image header can be inserted at a chosen position""" + data = self.data = self._DoReadFileRealDtb('118_fdtmap_hdr_pos.dts') + fdtmap_pos = 0x100 + len(U_BOOT_DATA) + hdr_data = data[0x80:0x88] + self.assertEqual('BinM', hdr_data[:4]) + offset = struct.unpack('<I', hdr_data[4:])[0] + self.assertEqual(fdtmap_pos, offset) + + def testHeaderMissingFdtmap(self): + """Test an image header requires an fdtmap""" + with self.assertRaises(ValueError) as e: + self.data = self._DoReadFileRealDtb('119_fdtmap_hdr_missing.dts') + self.assertIn("'image_header' section must have an 'fdtmap' sibling", + str(e.exception)) + + def testHeaderNoLocation(self): + """Test an image header with a no specified location is detected""" + with self.assertRaises(ValueError) as e: + self.data = self._DoReadFileRealDtb('120_hdr_no_location.dts') + self.assertIn("Invalid location 'None', expected 'start' or 'end'", + str(e.exception)) + if __name__ == "__main__": unittest.main() |