diff options
author | Simon Glass <sjg@chromium.org> | 2018-06-06 15:37:04 -0600 |
---|---|---|
committer | David Gibson <david@gibson.dropbear.id.au> | 2018-06-09 23:36:33 +1000 |
commit | 5a598671fdbf20355ecbaf59d9f502e689df683f (patch) | |
tree | b371e2f5ecd7679897e4a33adf8444a015de721b /pylibfdt | |
parent | 483e170625e1b6905fc4c40db92ee48d47ee3283 (diff) | |
download | dtc-5a598671fdbf20355ecbaf59d9f502e689df683f.zip dtc-5a598671fdbf20355ecbaf59d9f502e689df683f.tar.gz dtc-5a598671fdbf20355ecbaf59d9f502e689df683f.tar.bz2 |
pylibfdt: Support device-tree creation/expansion
Add support for fdt_open_into() and fdt_create_empty_tree() from the
Python library. The former is named resize() since it better fits with
what the Python binding actually does.
Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'pylibfdt')
-rw-r--r-- | pylibfdt/libfdt.i | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/pylibfdt/libfdt.i b/pylibfdt/libfdt.i index 2074e9b..da32148 100644 --- a/pylibfdt/libfdt.i +++ b/pylibfdt/libfdt.i @@ -434,6 +434,39 @@ class Fdt: return pdata return Property(pdata[0], pdata[1]) + @staticmethod + def create_empty_tree(size, quiet=()): + """Create an empty device tree ready for use + + Args: + size: Size of device tree in bytes + + Returns: + Fdt object containing the device tree + """ + data = bytearray(size) + err = check_err(fdt_create_empty_tree(data, size), quiet) + if err: + return err + return Fdt(data) + + def resize(self, size, quiet=()): + """Move the device tree into a larger or smaller space + + This creates a new device tree of size @size and moves the existing + device tree contents over to that. It can be used to create more space + in a device tree. Note that the Fdt object remains the same, but it + now has a new bytearray holding the contents. + + Args: + size: Required new size of device tree in bytes + """ + fdt = bytearray(size) + err = check_err(fdt_open_into(self._fdt, fdt, size), quiet) + if err: + return err + self._fdt = fdt + def pack(self, quiet=()): """Pack the device tree to remove unused space |