Lines Matching +full:self +full:- +full:refresh

6 # SPDX-License-Identifier:      GPL-2.0+
17 # contains the base classes and defines the high-level API. You can use
40 def __init__(self, node, offset, name, bytes): argument
41 self._node = node
42 self._offset = offset
43 self.name = name
44 self.value = None
45 self.bytes = str(bytes)
47 self.type = TYPE_BOOL
48 self.value = True
50 self.type, self.value = self.BytesToValue(bytes)
52 def GetPhandle(self): argument
57 return fdt_util.fdt32_to_cpu(self.value[:4])
59 def Widen(self, newprop): argument
82 if newprop.type < self.type:
83 self.type = newprop.type
85 if type(newprop.value) == list and type(self.value) != list:
86 self.value = [self.value]
88 if type(self.value) == list and len(newprop.value) > len(self.value):
89 val = self.GetEmpty(self.type)
90 while len(self.value) < len(newprop.value):
91 self.value.append(val)
93 def BytesToValue(self, bytes): argument
105 TYPE_INT: a byte-swapped integer stored as a 4-byte string
106 TYPE_BYTE: a byte stored as a single-byte string
112 count = len(strings) - 1
113 if count > 0 and not strings[-1]:
114 for string in strings[:-1]:
128 return TYPE_STRING, strings[:-1]
142 def GetEmpty(self, type): argument
157 def GetOffset(self): argument
163 return self._node._fdt.GetStructOffset(self._offset)
177 def __init__(self, fdt, parent, offset, name, path): argument
178 self._fdt = fdt
179 self.parent = parent
180 self._offset = offset
181 self.name = name
182 self.path = path
183 self.subnodes = []
184 self.props = {}
186 def _FindNode(self, name): argument
194 for subnode in self.subnodes:
199 def Offset(self): argument
202 This should be used instead of self._offset directly, to ensure that
205 self._fdt.CheckCache()
206 return self._offset
208 def Scan(self): argument
214 self.props = self._fdt.GetProps(self)
215 phandle = self.props.get('phandle')
218 self._fdt.phandle_to_node[val] = self
220 offset = libfdt.fdt_first_subnode(self._fdt.GetFdt(), self.Offset())
222 sep = '' if self.path[-1] == '/' else '/'
223 name = self._fdt._fdt_obj.get_name(offset)
224 path = self.path + sep + name
225 node = Node(self._fdt, self, offset, name, path)
226 self.subnodes.append(node)
229 offset = libfdt.fdt_next_subnode(self._fdt.GetFdt(), offset)
231 def Refresh(self, my_offset): member in Node
234 Note: This does not take account of property offsets - these will not
237 if self._offset != my_offset:
238 #print '%s: %d -> %d\n' % (self.path, self._offset, my_offset)
239 self._offset = my_offset
240 offset = libfdt.fdt_first_subnode(self._fdt.GetFdt(), self._offset)
241 for subnode in self.subnodes:
242 subnode.Refresh(offset)
243 offset = libfdt.fdt_next_subnode(self._fdt.GetFdt(), offset)
245 def DeleteProp(self, prop_name): argument
255 CheckErr(libfdt.fdt_delprop(self._fdt.GetFdt(), self.Offset(), prop_name),
256 "Node '%s': delete property: '%s'" % (self.path, prop_name))
257 del self.props[prop_name]
258 self._fdt.Invalidate()
267 def __init__(self, fname): argument
268 self._fname = fname
269 self._cached_offsets = False
270 self.phandle_to_node = {}
271 if self._fname:
272 self._fname = fdt_util.EnsureCompiled(self._fname)
274 with open(self._fname) as fd:
275 self._fdt = bytearray(fd.read())
276 self._fdt_obj = libfdt.Fdt(self._fdt)
278 def Scan(self, root='/'): argument
281 This fills in the self._root property
288 self._root = self.Node(self, None, 0, '/', '/')
289 self._root.Scan()
291 def GetRoot(self): argument
297 return self._root
299 def GetNode(self, path): argument
307 node = self._root
314 def Flush(self): argument
319 with open(self._fname, 'wb') as fd:
320 fd.write(self._fdt)
322 def Pack(self): argument
328 CheckErr(libfdt.fdt_pack(self._fdt), 'pack')
329 fdt_len = libfdt.fdt_totalsize(self._fdt)
330 del self._fdt[fdt_len:]
332 def GetFdt(self): argument
338 return self._fdt
346 def GetProps(self, node): argument
360 poffset = libfdt.fdt_first_property_offset(self._fdt, node._offset)
362 p = self._fdt_obj.get_property_by_offset(poffset)
366 poffset = libfdt.fdt_next_property_offset(self._fdt, poffset)
369 def Invalidate(self): argument
371 self._cached_offsets = False
373 def CheckCache(self): argument
374 """Refresh the offset cache if needed"""
375 if self._cached_offsets:
377 self.Refresh()
378 self._cached_offsets = True
380 def Refresh(self): member in Fdt
381 """Refresh the offset cache"""
382 self._root.Refresh(0)
384 def GetStructOffset(self, offset): argument
392 return libfdt.fdt_off_dt_struct(self._fdt) + offset
395 def Node(self, fdt, parent, offset, name, path): argument