2018-05-06 21:58:06 +00:00
|
|
|
# SPDX-License-Identifier: GPL-2.0+
|
2016-11-26 03:15:51 +00:00
|
|
|
# Copyright (c) 2016 Google, Inc
|
|
|
|
# Written by Simon Glass <sjg@chromium.org>
|
|
|
|
#
|
|
|
|
# Test for the fdt modules
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import tempfile
|
|
|
|
import unittest
|
|
|
|
|
2020-04-18 00:09:03 +00:00
|
|
|
from dtoc import fdt
|
|
|
|
from dtoc import fdt_util
|
|
|
|
from dtoc.fdt import FdtScan
|
2023-02-24 01:18:04 +00:00
|
|
|
from u_boot_pylib import tools
|
2016-11-26 03:15:51 +00:00
|
|
|
|
|
|
|
class TestFdt(unittest.TestCase):
|
|
|
|
@classmethod
|
|
|
|
def setUpClass(self):
|
|
|
|
self._binman_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
|
|
|
|
self._indir = tempfile.mkdtemp(prefix='binmant.')
|
2022-01-29 21:14:04 +00:00
|
|
|
tools.prepare_output_dir(self._indir, True)
|
2016-11-26 03:15:51 +00:00
|
|
|
|
2018-10-02 03:12:41 +00:00
|
|
|
@classmethod
|
|
|
|
def tearDownClass(self):
|
2022-01-29 21:14:04 +00:00
|
|
|
tools._finalise_for_test()
|
2018-10-02 03:12:41 +00:00
|
|
|
|
2016-11-26 03:15:51 +00:00
|
|
|
def TestFile(self, fname):
|
|
|
|
return os.path.join(self._binman_dir, 'test', fname)
|
|
|
|
|
|
|
|
def GetCompiled(self, fname):
|
|
|
|
return fdt_util.EnsureCompiled(self.TestFile(fname))
|
|
|
|
|
2017-05-27 13:38:20 +00:00
|
|
|
def _DeleteProp(self, dt):
|
|
|
|
node = dt.GetNode('/microcode/update@0')
|
2016-11-26 03:15:51 +00:00
|
|
|
node.DeleteProp('data')
|
|
|
|
|
|
|
|
def testFdtNormal(self):
|
2018-10-01 18:22:30 +00:00
|
|
|
fname = self.GetCompiled('034_x86_ucode.dts')
|
2017-05-27 13:38:20 +00:00
|
|
|
dt = FdtScan(fname)
|
|
|
|
self._DeleteProp(dt)
|
2016-11-26 03:15:51 +00:00
|
|
|
|
2017-05-27 13:38:21 +00:00
|
|
|
def testFdtNormalProp(self):
|
2018-10-01 18:22:30 +00:00
|
|
|
fname = self.GetCompiled('045_prop_test.dts')
|
2017-05-27 13:38:21 +00:00
|
|
|
dt = FdtScan(fname)
|
|
|
|
node = dt.GetNode('/binman/intel-me')
|
|
|
|
self.assertEquals('intel-me', node.name)
|
|
|
|
val = fdt_util.GetString(node, 'filename')
|
|
|
|
self.assertEquals(str, type(val))
|
|
|
|
self.assertEquals('me.bin', val)
|
|
|
|
|
|
|
|
prop = node.props['intval']
|
2020-11-09 03:36:17 +00:00
|
|
|
self.assertEquals(fdt.Type.INT, prop.type)
|
2017-05-27 13:38:21 +00:00
|
|
|
self.assertEquals(3, fdt_util.GetInt(node, 'intval'))
|
|
|
|
|
|
|
|
prop = node.props['intarray']
|
2020-11-09 03:36:17 +00:00
|
|
|
self.assertEquals(fdt.Type.INT, prop.type)
|
2017-05-27 13:38:21 +00:00
|
|
|
self.assertEquals(list, type(prop.value))
|
|
|
|
self.assertEquals(2, len(prop.value))
|
|
|
|
self.assertEquals([5, 6],
|
|
|
|
[fdt_util.fdt32_to_cpu(val) for val in prop.value])
|
|
|
|
|
|
|
|
prop = node.props['byteval']
|
2020-11-09 03:36:17 +00:00
|
|
|
self.assertEquals(fdt.Type.BYTE, prop.type)
|
2017-05-27 13:38:21 +00:00
|
|
|
self.assertEquals(chr(8), prop.value)
|
|
|
|
|
|
|
|
prop = node.props['bytearray']
|
2020-11-09 03:36:17 +00:00
|
|
|
self.assertEquals(fdt.Type.BYTE, prop.type)
|
2017-05-27 13:38:21 +00:00
|
|
|
self.assertEquals(list, type(prop.value))
|
|
|
|
self.assertEquals(str, type(prop.value[0]))
|
|
|
|
self.assertEquals(3, len(prop.value))
|
|
|
|
self.assertEquals([chr(1), '#', '4'], prop.value)
|
|
|
|
|
|
|
|
prop = node.props['longbytearray']
|
2020-11-09 03:36:17 +00:00
|
|
|
self.assertEquals(fdt.Type.INT, prop.type)
|
2017-05-27 13:38:21 +00:00
|
|
|
self.assertEquals(0x090a0b0c, fdt_util.GetInt(node, 'longbytearray'))
|
|
|
|
|
|
|
|
prop = node.props['stringval']
|
2020-11-09 03:36:17 +00:00
|
|
|
self.assertEquals(fdt.Type.STRING, prop.type)
|
2017-05-27 13:38:21 +00:00
|
|
|
self.assertEquals('message2', fdt_util.GetString(node, 'stringval'))
|
|
|
|
|
|
|
|
prop = node.props['stringarray']
|
2020-11-09 03:36:17 +00:00
|
|
|
self.assertEquals(fdt.Type.STRING, prop.type)
|
2017-05-27 13:38:21 +00:00
|
|
|
self.assertEquals(list, type(prop.value))
|
|
|
|
self.assertEquals(3, len(prop.value))
|
|
|
|
self.assertEquals(['another', 'multi-word', 'message'], prop.value)
|