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
import entry
from entry import Entry
+ self._name = name
self._node = node
self._offset = 0
self._size = None
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()
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():
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)
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())
"""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)
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)
"""
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
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)
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):
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)
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):
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,
u-boot {
};
};
+ section@2 {
+ u-boot {
+ };
+ };
};
};