From: Simon Glass Date: Tue, 17 Jul 2018 19:25:28 +0000 (-0600) Subject: binman: Enhance the map and fdt-update output X-Git-Url: http://git.dujemihanovic.xyz/login.html?a=commitdiff_plain;h=8122f3967f6eaab7134051d1d8c9b1bfc3babadb;p=u-boot.git binman: Enhance the map and fdt-update output At present the .map file produced for each image does not include the overall image size. This is useful information. Update the code to generate it in the .map file as well as the updated FDT. Also fix a few comments while we are here. Signed-off-by: Simon Glass --- diff --git a/tools/binman/README b/tools/binman/README index 5ff20f15c6..4b13776ffa 100644 --- a/tools/binman/README +++ b/tools/binman/README @@ -584,10 +584,11 @@ The -m option causes binman to output a .map file for each image that it generates. This shows the offset and size of each entry. For example: Offset Size Name - 00000000 00000010 section@0 - 00000000 00000004 u-boot - 00000010 00000010 section@1 - 00000000 00000004 u-boot + 00000000 00000028 main-section + 00000000 00000010 section@0 + 00000000 00000004 u-boot + 00000010 00000010 section@1 + 00000000 00000004 u-boot This shows a hierarchical image with two sections, each with a single entry. The offsets of the sections are absolute hex byte offsets within the image. The diff --git a/tools/binman/bsection.py b/tools/binman/bsection.py index d78a25e83d..1604b9915e 100644 --- a/tools/binman/bsection.py +++ b/tools/binman/bsection.py @@ -50,6 +50,7 @@ class Section(object): import entry from entry import Entry + self._name = name self._node = node self._offset = 0 self._size = None @@ -90,11 +91,20 @@ class Section(object): entry.SetPrefix(self._name_prefix) self._entries[node.name] = entry + def SetOffset(self, offset): + self._offset = offset + def AddMissingProperties(self): + """Add new properties to the device tree as needed for this entry""" + for prop in ['offset', 'size']: + if not prop in self._node.props: + self._node.AddZeroProp(prop) for entry in self._entries.values(): entry.AddMissingProperties() def SetCalculatedProperties(self): + self._node.SetInt('offset', self._offset) + self._node.SetInt('size', self._size) for entry in self._entries.values(): entry.SetCalculatedProperties() @@ -269,7 +279,7 @@ class Section(object): fd.write(self.GetData()) def GetData(self): - """Write the section to a file""" + """Get the contents of the section""" section_data = chr(self._pad_byte) * self._size for entry in self._entries.values(): @@ -335,13 +345,31 @@ class Section(object): raise ValueError("%s: No such property '%s'" % (msg, prop_name)) def GetEntries(self): + """Get the number of entries in a section + + Returns: + Number of entries in a section + """ return self._entries + def GetSize(self): + """Get the size of a section in bytes + + This is only meaningful if the section has a pre-defined size, or the + entries within it have been packed, so that the size has been + calculated. + + Returns: + Entry size in bytes + """ + return self._size + def WriteMap(self, fd, indent): """Write a map of the section to a .map file Args: fd: File to write the map to """ + Entry.WriteMapLine(fd, indent, self._name, self._offset, self._size) for entry in self._entries.values(): - entry.WriteMap(fd, indent) + entry.WriteMap(fd, indent + 1) diff --git a/tools/binman/entry.py b/tools/binman/entry.py index c9529d8322..cb693c9382 100644 --- a/tools/binman/entry.py +++ b/tools/binman/entry.py @@ -36,7 +36,7 @@ class Entry(object): Entry. Attributes: - section: The section containing this entry + section: Section object containing this entry node: The node that created this entry offset: Offset of entry within the section, None if not known yet (in which case it will be calculated by Pack()) @@ -72,7 +72,7 @@ class Entry(object): """Create a new entry for a node. Args: - section: Image object containing this node + section: Section object containing this node node: Node object containing information about the entry to create etype: Entry type to use, or None to work it out (used for tests) @@ -133,7 +133,7 @@ class Entry(object): def AddMissingProperties(self): """Add new properties to the device tree as needed for this entry""" - for prop in ['offset', 'size', 'global-pos']: + for prop in ['offset', 'size']: if not prop in self._node.props: self._node.AddZeroProp(prop) @@ -285,6 +285,10 @@ class Entry(object): """ pass + @staticmethod + def WriteMapLine(fd, indent, name, offset, size): + print('%s%08x %08x %s' % (' ' * indent, offset, size, name), file=fd) + def WriteMap(self, fd, indent): """Write a map of the entry to a .map file @@ -292,5 +296,4 @@ class Entry(object): fd: File to write the map to indent: Curent indent level of map (0=none, 1=one level, etc.) """ - print('%s%08x %08x %s' % (' ' * indent, self.offset, self.size, - self.name), file=fd) + self.WriteMapLine(fd, indent, self.name, self.offset, self.size) diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py index 5a0b0b8c70..1d27301ae9 100644 --- a/tools/binman/etype/section.py +++ b/tools/binman/etype/section.py @@ -42,7 +42,8 @@ class Entry_section(Entry): def Pack(self, offset): """Pack all entries into the section""" self._section.PackEntries() - self.size = self._section.CheckSize() + self._section.SetOffset(offset) + self.size = self._section.GetSize() return super(Entry_section, self).Pack(offset) def WriteSymbols(self, section): @@ -66,5 +67,4 @@ class Entry_section(Entry): Args: fd: File to write the map to """ - super(Entry_section, self).WriteMap(fd, indent) - self._section.WriteMap(fd, indent + 1) + self._section.WriteMap(fd, indent) diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 91b59f84ea..94e48f3ab3 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -1004,27 +1004,32 @@ class TestFunctional(unittest.TestCase): def testSections(self): """Basic test of sections""" data = self._DoReadFile('55_sections.dts') - expected = U_BOOT_DATA + '!' * 12 + U_BOOT_DATA + 'a' * 12 + '&' * 8 + expected = (U_BOOT_DATA + '!' * 12 + U_BOOT_DATA + 'a' * 12 + + U_BOOT_DATA + '&' * 4) self.assertEqual(expected, data) def testMap(self): """Tests outputting a map of the images""" _, _, map_data, _ = self._DoReadFileDtb('55_sections.dts', map=True) self.assertEqual(''' Offset Size Name -00000000 00000010 section@0 - 00000000 00000004 u-boot -00000010 00000010 section@1 - 00000000 00000004 u-boot +00000000 00000028 main-section + 00000000 00000010 section@0 + 00000000 00000004 u-boot + 00000010 00000010 section@1 + 00000000 00000004 u-boot + 00000020 00000004 section@2 + 00000000 00000004 u-boot ''', map_data) def testNamePrefix(self): """Tests that name prefixes are used""" _, _, map_data, _ = self._DoReadFileDtb('56_name_prefix.dts', map=True) self.assertEqual(''' Offset Size Name -00000000 00000010 section@0 - 00000000 00000004 ro-u-boot -00000010 00000010 section@1 - 00000000 00000004 rw-u-boot +00000000 00000028 main-section + 00000000 00000010 section@0 + 00000000 00000004 ro-u-boot + 00000010 00000010 section@1 + 00000000 00000004 rw-u-boot ''', map_data) def testUnknownContents(self): @@ -1051,6 +1056,7 @@ class TestFunctional(unittest.TestCase): with open(out_dtb_fname) as inf: outf.write(inf.read()) self.assertEqual({ + 'offset': 0, '_testing:offset': 32, '_testing:size': 1, 'section@0/u-boot:offset': 0, diff --git a/tools/binman/test/55_sections.dts b/tools/binman/test/55_sections.dts index 2ada395b03..6b306aeda4 100644 --- a/tools/binman/test/55_sections.dts +++ b/tools/binman/test/55_sections.dts @@ -24,5 +24,9 @@ u-boot { }; }; + section@2 { + u-boot { + }; + }; }; };