diff --git a/lib/libfdt/libfdt.swig b/lib/libfdt/libfdt.swig index 26d42fc5d69e4393d70a721d9b67514284566b4b..ce516fddf22613b51f7f73ec7a314bb5a597409d 100644 --- a/lib/libfdt/libfdt.swig +++ b/lib/libfdt/libfdt.swig @@ -95,3 +95,15 @@ const char *fdt_get_name(const void *fdt, int nodeoffset, int *OUTPUT); const char *fdt_string(const void *fdt, int stroffset); int fdt_first_subnode(const void *fdt, int offset); int fdt_next_subnode(const void *fdt, int offset); + +%typemap(in) (void *) { + if (!PyByteArray_Check($input)) { + SWIG_exception_fail(SWIG_TypeError, "in method '" "$symname" "', argument " + "$argnum"" of type '" "$type""'"); + } + $1 = PyByteArray_AsString($input); +} + +int fdt_delprop(void *fdt, int nodeoffset, const char *name); + +const char *fdt_strerror(int errval); diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py index c0ce5af8ac50ee74bd758c17779747611fd16e48..f01c7b18ea9c8d8df0caf3e8979aa8c24eb5a384 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 1c8c9c7a6dc3d328ecd15c01e6a4a2030ab93cf0..0c0ebbcf47a1217f42bebc529a69e76367cf9c5b 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 eb45742a10d46c5bc8c143f416496571e2ee6847..52d80555ab9c8eec53ce3a710684084846f5b0c1 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.