mirror of
https://github.com/u-boot/u-boot.git
synced 2024-11-26 13:44:29 +08:00
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>
This commit is contained in:
parent
0170804f60
commit
2a70d897ed
@ -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);
|
const char *fdt_string(const void *fdt, int stroffset);
|
||||||
int fdt_first_subnode(const void *fdt, int offset);
|
int fdt_first_subnode(const void *fdt, int offset);
|
||||||
int fdt_next_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);
|
||||||
|
@ -184,6 +184,16 @@ class NodeBase:
|
|||||||
"""
|
"""
|
||||||
raise NotImplementedError()
|
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:
|
class Fdt:
|
||||||
"""Provides simple access to a flat device tree blob.
|
"""Provides simple access to a flat device tree blob.
|
||||||
|
|
||||||
|
@ -70,6 +70,19 @@ class Node(NodeBase):
|
|||||||
|
|
||||||
node.Scan()
|
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):
|
class FdtFallback(Fdt):
|
||||||
"""Provides simple access to a flat device tree blob using fdtget/fdtput
|
"""Provides simple access to a flat device tree blob using fdtget/fdtput
|
||||||
|
@ -20,6 +20,11 @@ import libfdt
|
|||||||
# This implementation uses a libfdt Python library to access the device tree,
|
# This implementation uses a libfdt Python library to access the device tree,
|
||||||
# so it is fairly efficient.
|
# 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):
|
class Prop(PropBase):
|
||||||
"""A device tree property
|
"""A device tree property
|
||||||
|
|
||||||
@ -95,6 +100,21 @@ class Node(NodeBase):
|
|||||||
subnode.Refresh(offset)
|
subnode.Refresh(offset)
|
||||||
offset = libfdt.fdt_next_subnode(self._fdt.GetFdt(), 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):
|
class FdtNormal(Fdt):
|
||||||
"""Provides simple access to a flat device tree blob using libfdt.
|
"""Provides simple access to a flat device tree blob using libfdt.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user