dtoc: Decode val if it's a byte string
authorGeorge McCollister <george.mccollister@gmail.com>
Thu, 30 Mar 2017 14:44:25 +0000 (09:44 -0500)
committerSimon Glass <sjg@chromium.org>
Thu, 13 Apr 2017 17:43:49 +0000 (11:43 -0600)
With Python 3.5.2 encode will throw an exception if val is a byte array.
Decode it to a string first. This assumes it's utf-8, if it's not valid
utf-8 it will throw an exception.

Signed-off-by: George McCollister <george.mccollister@gmail.com>
Acked-by: Simon Glass <sjg@chromium.org>
tools/dtoc/fdt_util.py

index e6d523b9de65699ec08ebf863b1e614699d16b9c..b9dfae8d0e7b606c28fac252f82afcaef801fe49 100644 (file)
@@ -24,6 +24,8 @@ def fdt32_to_cpu(val):
         A native-endian integer value
     """
     if sys.version_info > (3, 0):
+        if isinstance(val, bytes):
+            val = val.decode('utf-8')
         val = val.encode('raw_unicode_escape')
     return struct.unpack('>I', val)[0]