mirror of
https://github.com/brain-hackers/u-boot-brain
synced 2024-06-09 23:36:03 +09:00
dtoc: Update fdt_util for Python 3
Since we are now using the bytes type in Python 3, the conversion in fdt32_to_cpu() is not necessary, so drop it. Also use 'int' instead of 'long' to convert the integer value, since 'long' is not present in Python 3. With this, test_fdt passes with both Python 2 and 3: PYTHONPATH=/tmp/b/sandbox_spl/scripts/dtc/pylibfdt python \ ./tools/dtoc/test_fdt -t PYTHONPATH=~/cosarm/dtc/pylibfdt:tools/patman python3 \ ./tools/dtoc/test_fdt -t Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
b5f0dafd4b
commit
209a55976b
|
@ -16,14 +16,6 @@ import tempfile
|
||||||
import command
|
import command
|
||||||
import tools
|
import tools
|
||||||
|
|
||||||
VERSION3 = sys.version_info > (3, 0)
|
|
||||||
|
|
||||||
def get_plain_bytes(val):
|
|
||||||
"""Handle Python 3 strings"""
|
|
||||||
if isinstance(val, bytes):
|
|
||||||
val = val.decode('utf-8')
|
|
||||||
return val.encode('raw_unicode_escape')
|
|
||||||
|
|
||||||
def fdt32_to_cpu(val):
|
def fdt32_to_cpu(val):
|
||||||
"""Convert a device tree cell to an integer
|
"""Convert a device tree cell to an integer
|
||||||
|
|
||||||
|
@ -33,9 +25,6 @@ def fdt32_to_cpu(val):
|
||||||
Return:
|
Return:
|
||||||
A native-endian integer value
|
A native-endian integer value
|
||||||
"""
|
"""
|
||||||
if VERSION3:
|
|
||||||
# This code is not reached in Python 2
|
|
||||||
val = get_plain_bytes(val) # pragma: no cover
|
|
||||||
return struct.unpack('>I', val)[0]
|
return struct.unpack('>I', val)[0]
|
||||||
|
|
||||||
def fdt_cells_to_cpu(val, cells):
|
def fdt_cells_to_cpu(val, cells):
|
||||||
|
@ -45,11 +34,11 @@ def fdt_cells_to_cpu(val, cells):
|
||||||
Value to convert (array of one or more 4-character strings)
|
Value to convert (array of one or more 4-character strings)
|
||||||
|
|
||||||
Return:
|
Return:
|
||||||
A native-endian long value
|
A native-endian integer value
|
||||||
"""
|
"""
|
||||||
if not cells:
|
if not cells:
|
||||||
return 0
|
return 0
|
||||||
out = long(fdt32_to_cpu(val[0]))
|
out = int(fdt32_to_cpu(val[0]))
|
||||||
if cells == 2:
|
if cells == 2:
|
||||||
out = out << 32 | fdt32_to_cpu(val[1])
|
out = out << 32 | fdt32_to_cpu(val[1])
|
||||||
return out
|
return out
|
||||||
|
|
|
@ -518,9 +518,6 @@ class TestFdtUtil(unittest.TestCase):
|
||||||
dtb = fdt_util.EnsureCompiled('tools/dtoc/dtoc_test_simple.dts')
|
dtb = fdt_util.EnsureCompiled('tools/dtoc/dtoc_test_simple.dts')
|
||||||
self.assertEqual(dtb, fdt_util.EnsureCompiled(dtb))
|
self.assertEqual(dtb, fdt_util.EnsureCompiled(dtb))
|
||||||
|
|
||||||
def testGetPlainBytes(self):
|
|
||||||
self.assertEqual(b'fred', fdt_util.get_plain_bytes('fred'))
|
|
||||||
|
|
||||||
|
|
||||||
def RunTestCoverage():
|
def RunTestCoverage():
|
||||||
"""Run the tests and check that we get 100% coverage"""
|
"""Run the tests and check that we get 100% coverage"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user