mirror of
https://github.com/brain-hackers/u-boot-brain
synced 2024-06-09 23:36:03 +09:00
dtoc: Add new check that offsets are correct
Add a few more internal checks to make sure offsets are correct, before updating the dtb. To make this easier, update the functions which add a property to return that property,. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
f6176651bc
commit
5d1bec30ef
|
@ -233,6 +233,11 @@ class Prop:
|
||||||
if self.dirty:
|
if self.dirty:
|
||||||
node = self._node
|
node = self._node
|
||||||
fdt_obj = node._fdt._fdt_obj
|
fdt_obj = node._fdt._fdt_obj
|
||||||
|
node_name = fdt_obj.get_name(node._offset)
|
||||||
|
if node_name and node_name != node.name:
|
||||||
|
raise ValueError("Internal error, node '%s' name mismatch '%s'" %
|
||||||
|
(node.path, node_name))
|
||||||
|
|
||||||
if auto_resize:
|
if auto_resize:
|
||||||
while fdt_obj.setprop(node.Offset(), self.name, self.bytes,
|
while fdt_obj.setprop(node.Offset(), self.name, self.bytes,
|
||||||
(libfdt.NOSPACE,)) == -libfdt.NOSPACE:
|
(libfdt.NOSPACE,)) == -libfdt.NOSPACE:
|
||||||
|
@ -328,6 +333,11 @@ class Node:
|
||||||
fdt_obj = self._fdt._fdt_obj
|
fdt_obj = self._fdt._fdt_obj
|
||||||
if self._offset != my_offset:
|
if self._offset != my_offset:
|
||||||
self._offset = my_offset
|
self._offset = my_offset
|
||||||
|
name = fdt_obj.get_name(self._offset)
|
||||||
|
if name and self.name != name:
|
||||||
|
raise ValueError("Internal error, node '%s' name mismatch '%s'" %
|
||||||
|
(self.path, name))
|
||||||
|
|
||||||
offset = fdt_obj.first_subnode(self._offset, QUIET_NOTFOUND)
|
offset = fdt_obj.first_subnode(self._offset, QUIET_NOTFOUND)
|
||||||
for subnode in self.subnodes:
|
for subnode in self.subnodes:
|
||||||
if subnode.name != fdt_obj.get_name(offset):
|
if subnode.name != fdt_obj.get_name(offset):
|
||||||
|
@ -451,8 +461,13 @@ class Node:
|
||||||
Args:
|
Args:
|
||||||
prop_name: Name of property to add
|
prop_name: Name of property to add
|
||||||
val: Bytes value of property
|
val: Bytes value of property
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Prop added
|
||||||
"""
|
"""
|
||||||
self.props[prop_name] = Prop(self, None, prop_name, val)
|
prop = Prop(self, None, prop_name, val)
|
||||||
|
self.props[prop_name] = prop
|
||||||
|
return prop
|
||||||
|
|
||||||
def AddString(self, prop_name, val):
|
def AddString(self, prop_name, val):
|
||||||
"""Add a new string property to a node
|
"""Add a new string property to a node
|
||||||
|
@ -463,9 +478,12 @@ class Node:
|
||||||
Args:
|
Args:
|
||||||
prop_name: Name of property to add
|
prop_name: Name of property to add
|
||||||
val: String value of property
|
val: String value of property
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Prop added
|
||||||
"""
|
"""
|
||||||
val = bytes(val, 'utf-8')
|
val = bytes(val, 'utf-8')
|
||||||
self.AddData(prop_name, val + b'\0')
|
return self.AddData(prop_name, val + b'\0')
|
||||||
|
|
||||||
def AddInt(self, prop_name, val):
|
def AddInt(self, prop_name, val):
|
||||||
"""Add a new integer property to a node
|
"""Add a new integer property to a node
|
||||||
|
@ -476,8 +494,11 @@ class Node:
|
||||||
Args:
|
Args:
|
||||||
prop_name: Name of property to add
|
prop_name: Name of property to add
|
||||||
val: Integer value of property
|
val: Integer value of property
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Prop added
|
||||||
"""
|
"""
|
||||||
self.AddData(prop_name, struct.pack('>I', val))
|
return self.AddData(prop_name, struct.pack('>I', val))
|
||||||
|
|
||||||
def AddSubnode(self, name):
|
def AddSubnode(self, name):
|
||||||
"""Add a new subnode to the node
|
"""Add a new subnode to the node
|
||||||
|
|
|
@ -265,6 +265,22 @@ class TestNode(unittest.TestCase):
|
||||||
|
|
||||||
self.dtb.Sync(auto_resize=True)
|
self.dtb.Sync(auto_resize=True)
|
||||||
|
|
||||||
|
def testRefreshNameMismatch(self):
|
||||||
|
"""Test name mismatch when syncing nodes and properties"""
|
||||||
|
prop = self.node.AddInt('integer-a', 12)
|
||||||
|
|
||||||
|
wrong_offset = self.dtb.GetNode('/i2c@0')._offset
|
||||||
|
self.node._offset = wrong_offset
|
||||||
|
with self.assertRaises(ValueError) as e:
|
||||||
|
self.dtb.Sync()
|
||||||
|
self.assertIn("Internal error, node '/spl-test' name mismatch 'i2c@0'",
|
||||||
|
str(e.exception))
|
||||||
|
|
||||||
|
with self.assertRaises(ValueError) as e:
|
||||||
|
self.node.Refresh(wrong_offset)
|
||||||
|
self.assertIn("Internal error, node '/spl-test' name mismatch 'i2c@0'",
|
||||||
|
str(e.exception))
|
||||||
|
|
||||||
|
|
||||||
class TestProp(unittest.TestCase):
|
class TestProp(unittest.TestCase):
|
||||||
"""Test operation of the Prop class"""
|
"""Test operation of the Prop class"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user