diff options
author | Simon Glass <sjg@chromium.org> | 2019-05-17 22:00:36 -0600 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2019-07-10 16:52:58 -0600 |
commit | f6b64815dda947090f112bd4f7e0e430a16b48d7 (patch) | |
tree | b5c766842c96dfec029dcef48251e0462c6f913f /tools/dtoc/fdt.py | |
parent | 2b6ed5e92e3b29fbfa3a966433d4bbc2ec1e9c58 (diff) | |
download | u-boot-f6b64815dda947090f112bd4f7e0e430a16b48d7.tar.gz |
dtoc: Use byte type instead of str in fdt
In Python 3 bytes and str are separate types. Use bytes to ensure that
the code functions correctly with Python 3.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/dtoc/fdt.py')
-rw-r--r-- | tools/dtoc/fdt.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py index 2e74bc15be..956e0c9800 100644 --- a/tools/dtoc/fdt.py +++ b/tools/dtoc/fdt.py @@ -193,7 +193,7 @@ class Prop: Args: bytes: New property value to set """ - self.bytes = str(bytes) + self.bytes = bytes self.type, self.value = BytesToValue(bytes) self.dirty = True @@ -398,7 +398,9 @@ class Node: prop_name: Name of property to set val: String value to set (will be \0-terminated in DT) """ - self.props[prop_name].SetData(val + chr(0)) + if sys.version_info[0] >= 3: # pragma: no cover + val = bytes(val, 'utf-8') + self.props[prop_name].SetData(val + b'\0') def AddString(self, prop_name, val): """Add a new string property to a node @@ -410,7 +412,9 @@ class Node: prop_name: Name of property to add val: String value of property """ - self.props[prop_name] = Prop(self, None, prop_name, val + chr(0)) + if sys.version_info[0] >= 3: # pragma: no cover + val = bytes(val, 'utf-8') + self.props[prop_name] = Prop(self, None, prop_name, val + b'\0') def AddSubnode(self, name): """Add a new subnode to the node @@ -496,7 +500,7 @@ class Fdt: Fdt object containing the data """ fdt = Fdt(None) - fdt._fdt_obj = libfdt.Fdt(bytearray(data)) + fdt._fdt_obj = libfdt.Fdt(bytes(data)) return fdt def LookupPhandle(self, phandle): @@ -586,7 +590,7 @@ class Fdt: Returns: The FDT contents as a string of bytes """ - return self._fdt_obj.as_bytearray() + return bytes(self._fdt_obj.as_bytearray()) def GetFdtObj(self): """Get the contents of the FDT |