summaryrefslogtreecommitdiff
path: root/tools/dtoc
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2016-07-25 18:59:14 -0600
committerSimon Glass <sjg@chromium.org>2016-09-18 21:04:39 -0600
commit2a70d897ed68fd521411a10831ac05e1ffdd3d41 (patch)
treee3923ef5b91172f52da3627b6370e9fbee6b5bc2 /tools/dtoc
parent0170804f60b19a2033ac39964fcd192a0c7eda42 (diff)
dtoc: Support deleting device tree properties
Add support for deleting a device tree property. With the fallback implementation this uses fdtput. With libfdt it uses the API call and updates the offsets afterwards. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/dtoc')
-rw-r--r--tools/dtoc/fdt.py10
-rw-r--r--tools/dtoc/fdt_fallback.py13
-rw-r--r--tools/dtoc/fdt_normal.py20
3 files changed, 43 insertions, 0 deletions
diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py
index c0ce5af8ac..f01c7b18ea 100644
--- a/tools/dtoc/fdt.py
+++ b/tools/dtoc/fdt.py
@@ -184,6 +184,16 @@ class NodeBase:
"""
raise NotImplementedError()
+ def DeleteProp(self, prop_name):
+ """Delete a property of a node
+
+ This should be implemented by subclasses
+
+ Args:
+ prop_name: Name of the property to delete
+ """
+ raise NotImplementedError()
+
class Fdt:
"""Provides simple access to a flat device tree blob.
diff --git a/tools/dtoc/fdt_fallback.py b/tools/dtoc/fdt_fallback.py
index 1c8c9c7a6d..0c0ebbcf47 100644
--- a/tools/dtoc/fdt_fallback.py
+++ b/tools/dtoc/fdt_fallback.py
@@ -70,6 +70,19 @@ class Node(NodeBase):
node.Scan()
+ def DeleteProp(self, prop_name):
+ """Delete a property of a node
+
+ The property is deleted using fdtput.
+
+ Args:
+ prop_name: Name of the property to delete
+ Raises:
+ CommandError if the property does not exist
+ """
+ args = [self._fdt._fname, '-d', self.path, prop_name]
+ command.Output('fdtput', *args)
+ del self.props[prop_name]
class FdtFallback(Fdt):
"""Provides simple access to a flat device tree blob using fdtget/fdtput
diff --git a/tools/dtoc/fdt_normal.py b/tools/dtoc/fdt_normal.py
index eb45742a10..52d80555ab 100644
--- a/tools/dtoc/fdt_normal.py
+++ b/tools/dtoc/fdt_normal.py
@@ -20,6 +20,11 @@ import libfdt
# This implementation uses a libfdt Python library to access the device tree,
# so it is fairly efficient.
+def CheckErr(errnum, msg):
+ if errnum:
+ raise ValueError('Error %d: %s: %s' %
+ (errnum, libfdt.fdt_strerror(errnum), msg))
+
class Prop(PropBase):
"""A device tree property
@@ -95,6 +100,21 @@ class Node(NodeBase):
subnode.Refresh(offset)
offset = libfdt.fdt_next_subnode(self._fdt.GetFdt(), offset)
+ def DeleteProp(self, prop_name):
+ """Delete a property of a node
+
+ The property is deleted and the offset cache is invalidated.
+
+ Args:
+ prop_name: Name of the property to delete
+ Raises:
+ ValueError if the property does not exist
+ """
+ CheckErr(libfdt.fdt_delprop(self._fdt.GetFdt(), self.Offset(), prop_name),
+ "Node '%s': delete property: '%s'" % (self.path, prop_name))
+ del self.props[prop_name]
+ self._fdt.Invalidate()
+
class FdtNormal(Fdt):
"""Provides simple access to a flat device tree blob using libfdt.