Skip to content
Snippets Groups Projects
Commit da5f7499 authored by Simon Glass's avatar Simon Glass
Browse files

dtoc: Support packing the device tree


After any node/property deletion the device tree can be packed to remove
spare space. Add a way to perform this operation.

Note that for fdt_fallback, fdtput automatically packs the device tree after
deletion, so no action is required here.

Signed-off-by: default avatarSimon Glass <sjg@chromium.org>
parent 2a70d897
No related branches found
No related tags found
No related merge requests found
......@@ -107,3 +107,4 @@ int fdt_next_subnode(const void *fdt, int offset);
int fdt_delprop(void *fdt, int nodeoffset, const char *name);
const char *fdt_strerror(int errval);
int fdt_pack(void *fdt);
......@@ -240,3 +240,19 @@ class Fdt:
return None
return node
def Flush(self):
"""Flush device tree changes back to the file
If the device tree has changed in memory, write it back to the file.
Subclasses can implement this if needed.
"""
pass
def Pack(self):
"""Pack the device tree down to its minimum size
When nodes and properties shrink or are deleted, wasted space can
build up in the device tree binary. Subclasses can implement this
to remove that spare space.
"""
pass
......@@ -140,6 +140,17 @@ class FdtNormal(Fdt):
"""
return self._fdt
def Flush(self):
"""Flush device tree changes back to the file"""
with open(self._fname, 'wb') as fd:
fd.write(self._fdt)
def Pack(self):
"""Pack the device tree down to its minimum size"""
CheckErr(libfdt.fdt_pack(self._fdt), 'pack')
fdt_len = libfdt.fdt_totalsize(self._fdt)
del self._fdt[fdt_len:]
def GetProps(self, node, path):
"""Get all properties from a node.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment