mirror of
https://github.com/smaeul/u-boot.git
synced 2025-10-14 04:46:01 +01:00
dtoc: Support deleting a node
Add a function to delete a node. This is synced to the tree when requested. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
bc116029c0
commit
a30c39f2f7
@ -548,6 +548,23 @@ class Node:
|
|||||||
self.subnodes.append(subnode)
|
self.subnodes.append(subnode)
|
||||||
return subnode
|
return subnode
|
||||||
|
|
||||||
|
def Delete(self):
|
||||||
|
"""Delete a node
|
||||||
|
|
||||||
|
The node is deleted and the offset cache is invalidated.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
node (Node): Node to delete
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
ValueError if the node does not exist
|
||||||
|
"""
|
||||||
|
CheckErr(self._fdt._fdt_obj.del_node(self.Offset()),
|
||||||
|
"Node '%s': delete" % self.path)
|
||||||
|
parent = self.parent
|
||||||
|
self._fdt.Invalidate()
|
||||||
|
parent.subnodes.remove(self)
|
||||||
|
|
||||||
def Sync(self, auto_resize=False):
|
def Sync(self, auto_resize=False):
|
||||||
"""Sync node changes back to the device tree
|
"""Sync node changes back to the device tree
|
||||||
|
|
||||||
|
@ -539,6 +539,15 @@ class TestProp(unittest.TestCase):
|
|||||||
data = self.fdt.getprop(self.node.Offset(), 'stringlist')
|
data = self.fdt.getprop(self.node.Offset(), 'stringlist')
|
||||||
self.assertEqual(b'123\x00456\0', data)
|
self.assertEqual(b'123\x00456\0', data)
|
||||||
|
|
||||||
|
def test_delete_node(self):
|
||||||
|
"""Test deleting a node"""
|
||||||
|
old_offset = self.fdt.path_offset('/spl-test')
|
||||||
|
self.assertGreater(old_offset, 0)
|
||||||
|
self.node.Delete()
|
||||||
|
self.dtb.Sync()
|
||||||
|
new_offset = self.fdt.path_offset('/spl-test', libfdt.QUIET_NOTFOUND)
|
||||||
|
self.assertEqual(-libfdt.NOTFOUND, new_offset)
|
||||||
|
|
||||||
def testFromData(self):
|
def testFromData(self):
|
||||||
dtb2 = fdt.Fdt.FromData(self.dtb.GetContents())
|
dtb2 = fdt.Fdt.FromData(self.dtb.GetContents())
|
||||||
self.assertEqual(dtb2.GetContents(), self.dtb.GetContents())
|
self.assertEqual(dtb2.GetContents(), self.dtb.GetContents())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user