pylibfdt: Add support for the rest of the header functions

Export all of these through Python.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
Simon Glass
2018-06-06 15:37:02 -06:00
committed by David Gibson
parent 582a7159a5
commit 29bb05aa42
2 changed files with 76 additions and 3 deletions

View File

@@ -234,21 +234,86 @@ class Fdt:
""" """
return check_err(fdt_next_subnode(self._fdt, nodeoffset), quiet) return check_err(fdt_next_subnode(self._fdt, nodeoffset), quiet)
def magic(self):
"""Return the magic word from the header
Returns:
Magic word
"""
# Use a mask to ensure that this does not return a -ve number
return fdt_magic(self._fdt) & 0xffffffff
def totalsize(self): def totalsize(self):
"""Return the total size of the device tree """Return the total size of the device tree
Returns: Returns:
Total tree size in bytes Total tree size in bytes
""" """
return check_err(fdt_totalsize(self._fdt)) return fdt_totalsize(self._fdt)
def off_dt_struct(self): def off_dt_struct(self):
"""Return the start of the device tree struct area """Return the start of the device-tree struct area
Returns: Returns:
Start offset of struct area Start offset of struct area
""" """
return check_err(fdt_off_dt_struct(self._fdt)) return fdt_off_dt_struct(self._fdt)
def off_dt_strings(self):
"""Return the start of the device-tree string area
Returns:
Start offset of string area
"""
return fdt_off_dt_strings(self._fdt)
def off_mem_rsvmap(self):
"""Return the start of the memory reserve map
Returns:
Start offset of memory reserve map
"""
return fdt_off_mem_rsvmap(self._fdt)
def version(self):
"""Return the version of the device tree
Returns:
Version number of the device tree
"""
return fdt_version(self._fdt)
def last_comp_version(self):
"""Return the last compatible version of the device tree
Returns:
Last compatible version number of the device tree
"""
return fdt_last_comp_version(self._fdt)
def boot_cpuid_phys(self):
"""Return the physical boot CPU ID
Returns:
Physical boot CPU ID
"""
return fdt_boot_cpuid_phys(self._fdt)
def size_dt_strings(self):
"""Return the start of the device-tree string area
Returns:
Start offset of string area
"""
return fdt_size_dt_strings(self._fdt)
def size_dt_struct(self):
"""Return the start of the device-tree struct area
Returns:
Start offset of struct area
"""
return fdt_size_dt_struct(self._fdt)
def subnode_offset(self, parentoffset, name, quiet=()): def subnode_offset(self, parentoffset, name, quiet=()):
"""Get the offset of a named subnode """Get the offset of a named subnode

View File

@@ -275,8 +275,16 @@ class PyLibfdtTests(unittest.TestCase):
def testHeader(self): def testHeader(self):
"""Test that we can access the header values""" """Test that we can access the header values"""
self.assertEquals(self.fdt.magic(), 0xd00dfeed)
self.assertEquals(self.fdt.totalsize(), len(self.fdt._fdt)) self.assertEquals(self.fdt.totalsize(), len(self.fdt._fdt))
self.assertEquals(self.fdt.off_dt_struct(), 88) self.assertEquals(self.fdt.off_dt_struct(), 88)
self.assertEquals(self.fdt.off_dt_strings(), 652)
self.assertEquals(self.fdt.off_mem_rsvmap(), 40)
self.assertEquals(self.fdt.version(), 17)
self.assertEquals(self.fdt.last_comp_version(), 16)
self.assertEquals(self.fdt.boot_cpuid_phys(), 0)
self.assertEquals(self.fdt.size_dt_strings(), 105)
self.assertEquals(self.fdt.size_dt_struct(), 564)
def testPack(self): def testPack(self):
"""Test that we can pack the tree after deleting something""" """Test that we can pack the tree after deleting something"""