#
# Copyright (C) 2016 Google, Inc
# Written by Simon Glass <sjg@chromium.org>
#
#
# Copyright (C) 2016 Google, Inc
# Written by Simon Glass <sjg@chromium.org>
#
# This deals with a device tree, presenting it as an assortment of Node and
# Prop objects, representing nodes and properties, respectively. This file
# This deals with a device tree, presenting it as an assortment of Node and
# Prop objects, representing nodes and properties, respectively. This file
-(TYPE_BYTE, TYPE_INT, TYPE_STRING, TYPE_BOOL) = range(4)
+(TYPE_BYTE, TYPE_INT, TYPE_STRING, TYPE_BOOL, TYPE_INT64) = range(5)
def GetEmpty(self, type):
"""Get an empty / zero value of the given type
def GetEmpty(self, type):
"""Get an empty / zero value of the given type
- def __init__(self, fdt, offset, name, path):
+ def __init__(self, fdt, parent, offset, name, path):
This fills in the props and subnodes properties, recursively
searching into subnodes so that the entire tree is built.
"""
This fills in the props and subnodes properties, recursively
searching into subnodes so that the entire tree is built.
"""
- node = Node(self._fdt, offset, name, path)
+ node = Node(self._fdt, self, offset, name, path)
def Refresh(self, my_offset):
"""Fix up the _offset for each node, recursively
def Refresh(self, my_offset):
"""Fix up the _offset for each node, recursively
def DeleteProp(self, prop_name):
"""Delete a property of a node
def DeleteProp(self, prop_name):
"""Delete a property of a node
- CheckErr(libfdt.fdt_delprop(self._fdt.GetFdt(), self.Offset(), prop_name),
+ CheckErr(self._fdt._fdt_obj.delprop(self.Offset(), prop_name),
"Node '%s': delete property: '%s'" % (self.path, prop_name))
del self.props[prop_name]
self._fdt.Invalidate()
"Node '%s': delete property: '%s'" % (self.path, prop_name))
del self.props[prop_name]
self._fdt.Invalidate()
def __init__(self, fname):
self._fname = fname
self._cached_offsets = False
def __init__(self, fname):
self._fname = fname
self._cached_offsets = False
def Scan(self, root='/'):
"""Scan a device tree, building up a tree of Node objects
def Scan(self, root='/'):
"""Scan a device tree, building up a tree of Node objects
- self._root = self.Node(self, 0, '/', '/')
+ self._root = self.Node(self, None, 0, '/', '/')
If the device tree has changed in memory, write it back to the file.
"""
with open(self._fname, 'wb') as fd:
If the device tree has changed in memory, write it back to the file.
"""
with open(self._fname, 'wb') as fd:
When nodes and properties shrink or are deleted, wasted space can
build up in the device tree binary.
"""
When nodes and properties shrink or are deleted, wasted space can
build up in the device tree binary.
"""
- CheckErr(libfdt.fdt_pack(self._fdt), 'pack')
- fdt_len = libfdt.fdt_totalsize(self._fdt)
- del self._fdt[fdt_len:]
+ CheckErr(self._fdt_obj.pack(), 'pack')
+ self.Invalidate()
if errnum:
raise ValueError('Error %d: %s: %s' %
(errnum, libfdt.fdt_strerror(errnum), msg))
if errnum:
raise ValueError('Error %d: %s: %s' %
(errnum, libfdt.fdt_strerror(errnum), msg))
def GetProps(self, node):
"""Get all properties from a node.
def GetProps(self, node):
"""Get all properties from a node.
- prop = Prop(node, poffset, p.name, p.value)
+ prop = Prop(node, poffset, p.name, p)
- def Node(self, fdt, offset, name, path):
+ def Node(self, fdt, parent, offset, name, path):
- node = Node(fdt, offset, name, path)
+ node = Node(fdt, parent, offset, name, path)