diff options
author | Simon Glass <sjg@chromium.org> | 2021-11-23 11:03:40 -0700 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2021-12-02 09:16:22 -0700 |
commit | 40b4d647c606b6df7394333c1a58c10996c96a78 (patch) | |
tree | dfdc86b06249d510973d4b909155358c2b0862ad /tools/dtoc/fdt_util.py | |
parent | d866e6291739de3da9550f2280574e1c44474dc3 (diff) | |
download | u-boot-40b4d647c606b6df7394333c1a58c10996c96a78.zip u-boot-40b4d647c606b6df7394333c1a58c10996c96a78.tar.gz u-boot-40b4d647c606b6df7394333c1a58c10996c96a78.tar.bz2 |
dtoc: Add support for reading fixed-length bytes properties
Add functions to read a sequence of bytes from the devicetree.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/dtoc/fdt_util.py')
-rw-r--r-- | tools/dtoc/fdt_util.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tools/dtoc/fdt_util.py b/tools/dtoc/fdt_util.py index 51d0eb5..51bdbdc 100644 --- a/tools/dtoc/fdt_util.py +++ b/tools/dtoc/fdt_util.py @@ -202,6 +202,26 @@ def GetByte(node, propname, default=None): (node.name, propname, len(value), 1)) return ord(value[0]) +def GetBytes(node, propname, size, default=None): + """Get a set of bytes from a property + + Args: + node (Node): Node object to read from + propname (str): property name to read + size (int): Number of bytes to expect + default (bytes): Default value or None + + Returns: + bytes: Bytes value read, or default if none + """ + prop = node.props.get(propname) + if not prop: + return default + if len(prop.bytes) != size: + raise ValueError("Node '%s' property '%s' has length %d, expecting %d" % + (node.name, propname, len(prop.bytes), size)) + return prop.bytes + def GetPhandleList(node, propname): """Get a list of phandles from a property |