diff options
Diffstat (limited to 'tools/binman')
-rwxr-xr-x | tools/binman/binman.py | 3 | ||||
-rw-r--r-- | tools/binman/control.py | 12 | ||||
-rw-r--r-- | tools/binman/etype/u_boot_dtb_with_ucode.py | 24 | ||||
-rw-r--r-- | tools/binman/fdt_test.py | 64 | ||||
-rw-r--r-- | tools/binman/func_test.py | 48 | ||||
-rw-r--r-- | tools/binman/test/45_prop_test.dts | 23 |
6 files changed, 107 insertions, 67 deletions
diff --git a/tools/binman/binman.py b/tools/binman/binman.py index 857d698b4c..95d3a048d8 100755 --- a/tools/binman/binman.py +++ b/tools/binman/binman.py @@ -21,6 +21,9 @@ sys.path.append(os.path.join(our_path, '../patman')) sys.path.append(os.path.join(our_path, '../dtoc')) sys.path.append(os.path.join(our_path, '../')) +# Bring in the libfdt module +sys.path.append('tools') + # Also allow entry-type modules to be brought in from the etype directory. sys.path.append(os.path.join(our_path, 'etype')) diff --git a/tools/binman/control.py b/tools/binman/control.py index e90967807c..e9d48df030 100644 --- a/tools/binman/control.py +++ b/tools/binman/control.py @@ -12,7 +12,7 @@ import sys import tools import command -import fdt_select +import fdt import fdt_util from image import Image import tout @@ -40,15 +40,15 @@ def _ReadImageDesc(binman_node): images['image'] = Image('image', binman_node) return images -def _FindBinmanNode(fdt): +def _FindBinmanNode(dtb): """Find the 'binman' node in the device tree Args: - fdt: Fdt object to scan + dtb: Fdt object to scan Returns: Node object of /binman node, or None if not found """ - for node in fdt.GetRoot().subnodes: + for node in dtb.GetRoot().subnodes: if node.name == 'binman': return node return None @@ -92,8 +92,8 @@ def Binman(options, args): try: tools.SetInputDirs(options.indir) tools.PrepareOutputDir(options.outdir, options.preserve) - fdt = fdt_select.FdtScan(dtb_fname) - node = _FindBinmanNode(fdt) + dtb = fdt.FdtScan(dtb_fname) + node = _FindBinmanNode(dtb) if not node: raise ValueError("Device tree '%s' does not have a 'binman' " "node" % dtb_fname) diff --git a/tools/binman/etype/u_boot_dtb_with_ucode.py b/tools/binman/etype/u_boot_dtb_with_ucode.py index fc02c67c14..a384a759c4 100644 --- a/tools/binman/etype/u_boot_dtb_with_ucode.py +++ b/tools/binman/etype/u_boot_dtb_with_ucode.py @@ -6,7 +6,7 @@ # Entry-type module for U-Boot device tree with the microcode removed # -import fdt_select +import fdt from entry import Entry from blob import Entry_blob import tools @@ -44,9 +44,8 @@ class Entry_u_boot_dtb_with_ucode(Entry_blob): fd.write(self.data) # Remove the microcode - fdt = fdt_select.FdtScan(fname) - fdt.Scan() - ucode = fdt.GetNode('/microcode') + dtb = fdt.FdtScan(fname) + ucode = dtb.GetNode('/microcode') if not ucode: raise self.Raise("No /microcode node found in '%s'" % fname) @@ -57,20 +56,15 @@ class Entry_u_boot_dtb_with_ucode(Entry_blob): data_prop = node.props.get('data') if data_prop: self.ucode_data += ''.join(data_prop.bytes) - if not self.collate: - poffset = data_prop.GetOffset() - if poffset is None: - # We cannot obtain a property offset. Collate instead. - self.collate = True - else: - # Find the offset in the device tree of the ucode data - self.ucode_offset = poffset + 12 - self.ucode_size = len(data_prop.bytes) if self.collate: prop = node.DeleteProp('data') + else: + # Find the offset in the device tree of the ucode data + self.ucode_offset = data_prop.GetOffset() + 12 + self.ucode_size = len(data_prop.bytes) if self.collate: - fdt.Pack() - fdt.Flush() + dtb.Pack() + dtb.Flush() # Make this file the contents of this entry self._pathname = fname diff --git a/tools/binman/fdt_test.py b/tools/binman/fdt_test.py index 1d9494e52f..249a9ea388 100644 --- a/tools/binman/fdt_test.py +++ b/tools/binman/fdt_test.py @@ -11,7 +11,8 @@ import sys import tempfile import unittest -from fdt_select import FdtScan +import fdt +from fdt import FdtScan import fdt_util import tools @@ -28,21 +29,56 @@ class TestFdt(unittest.TestCase): def GetCompiled(self, fname): return fdt_util.EnsureCompiled(self.TestFile(fname)) - def _DeleteProp(self, fdt): - node = fdt.GetNode('/microcode/update@0') + def _DeleteProp(self, dt): + node = dt.GetNode('/microcode/update@0') node.DeleteProp('data') def testFdtNormal(self): fname = self.GetCompiled('34_x86_ucode.dts') - fdt = FdtScan(fname) - self._DeleteProp(fdt) + dt = FdtScan(fname) + self._DeleteProp(dt) - def testFdtFallback(self): - fname = self.GetCompiled('34_x86_ucode.dts') - fdt = FdtScan(fname, True) - fdt.GetProp('/microcode/update@0', 'data') - self.assertEqual('fred', - fdt.GetProp('/microcode/update@0', 'none', default='fred')) - self.assertEqual('12345678 12345679', - fdt.GetProp('/microcode/update@0', 'data', typespec='x')) - self._DeleteProp(fdt) + def testFdtNormalProp(self): + fname = self.GetCompiled('45_prop_test.dts') + 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'] + self.assertEquals(fdt.TYPE_INT, prop.type) + self.assertEquals(3, fdt_util.GetInt(node, 'intval')) + + prop = node.props['intarray'] + self.assertEquals(fdt.TYPE_INT, prop.type) + 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'] + self.assertEquals(fdt.TYPE_BYTE, prop.type) + self.assertEquals(chr(8), prop.value) + + prop = node.props['bytearray'] + self.assertEquals(fdt.TYPE_BYTE, prop.type) + 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'] + self.assertEquals(fdt.TYPE_INT, prop.type) + self.assertEquals(0x090a0b0c, fdt_util.GetInt(node, 'longbytearray')) + + prop = node.props['stringval'] + self.assertEquals(fdt.TYPE_STRING, prop.type) + self.assertEquals('message2', fdt_util.GetString(node, 'stringval')) + + prop = node.props['stringarray'] + self.assertEquals(fdt.TYPE_STRING, prop.type) + self.assertEquals(list, type(prop.value)) + self.assertEquals(3, len(prop.value)) + self.assertEquals(['another', 'multi-word', 'message'], prop.value) diff --git a/tools/binman/func_test.py b/tools/binman/func_test.py index 740fa9e4e2..8b4db41659 100644 --- a/tools/binman/func_test.py +++ b/tools/binman/func_test.py @@ -21,7 +21,7 @@ import cmdline import command import control import entry -import fdt_select +import fdt import fdt_util import tools import tout @@ -658,8 +658,8 @@ class TestFunctional(unittest.TestCase): fname = tools.GetOutputFilename('test.dtb') with open(fname, 'wb') as fd: fd.write(second) - fdt = fdt_select.FdtScan(fname) - ucode = fdt.GetNode('/microcode') + dtb = fdt.FdtScan(fname) + ucode = dtb.GetNode('/microcode') self.assertTrue(ucode) for node in ucode.subnodes: self.assertFalse(node.props.get('data')) @@ -683,7 +683,7 @@ class TestFunctional(unittest.TestCase): self.assertEqual('nodtb with microcode' + pos_and_size + ' somewhere in here', first) - def _RunPackUbootSingleMicrocode(self, collate): + def _RunPackUbootSingleMicrocode(self): """Test that x86 microcode can be handled correctly We expect to see the following in the image, in order: @@ -695,8 +695,6 @@ class TestFunctional(unittest.TestCase): # We need the libfdt library to run this test since only that allows # finding the offset of a property. This is required by # Entry_u_boot_dtb_with_ucode.ObtainContents(). - if not fdt_select.have_libfdt: - return data = self._DoReadFile('35_x86_single_ucode.dts', True) second = data[len(U_BOOT_NODTB_DATA):] @@ -705,34 +703,22 @@ class TestFunctional(unittest.TestCase): third = second[fdt_len:] second = second[:fdt_len] - if not collate: - ucode_data = struct.pack('>2L', 0x12345678, 0x12345679) - self.assertIn(ucode_data, second) - ucode_pos = second.find(ucode_data) + len(U_BOOT_NODTB_DATA) + ucode_data = struct.pack('>2L', 0x12345678, 0x12345679) + self.assertIn(ucode_data, second) + ucode_pos = second.find(ucode_data) + len(U_BOOT_NODTB_DATA) - # Check that the microcode pointer was inserted. It should match the - # expected position and size - pos_and_size = struct.pack('<2L', 0xfffffe00 + ucode_pos, - len(ucode_data)) - first = data[:len(U_BOOT_NODTB_DATA)] - self.assertEqual('nodtb with microcode' + pos_and_size + - ' somewhere in here', first) + # Check that the microcode pointer was inserted. It should match the + # expected position and size + pos_and_size = struct.pack('<2L', 0xfffffe00 + ucode_pos, + len(ucode_data)) + first = data[:len(U_BOOT_NODTB_DATA)] + self.assertEqual('nodtb with microcode' + pos_and_size + + ' somewhere in here', first) def testPackUbootSingleMicrocode(self): """Test that x86 microcode can be handled correctly with fdt_normal. """ - self._RunPackUbootSingleMicrocode(False) - - def testPackUbootSingleMicrocodeFallback(self): - """Test that x86 microcode can be handled correctly with fdt_fallback. - - This only supports collating the microcode. - """ - try: - old_val = fdt_select.UseFallback(True) - self._RunPackUbootSingleMicrocode(True) - finally: - fdt_select.UseFallback(old_val) + self._RunPackUbootSingleMicrocode() def testUBootImg(self): """Test that u-boot.img can be put in a file""" @@ -763,14 +749,12 @@ class TestFunctional(unittest.TestCase): def testMicrocodeWithoutPtrInElf(self): """Test that a U-Boot binary without the microcode symbol is detected""" # ELF file without a '_dt_ucode_base_size' symbol - if not fdt_select.have_libfdt: - return try: with open(self.TestFile('u_boot_no_ucode_ptr')) as fd: TestFunctional._MakeInputFile('u-boot', fd.read()) with self.assertRaises(ValueError) as e: - self._RunPackUbootSingleMicrocode(False) + self._RunPackUbootSingleMicrocode() self.assertIn("Node '/binman/u-boot-with-ucode-ptr': Cannot locate " "_dt_ucode_base_size symbol in u-boot", str(e.exception)) diff --git a/tools/binman/test/45_prop_test.dts b/tools/binman/test/45_prop_test.dts new file mode 100644 index 0000000000..d22e460d29 --- /dev/null +++ b/tools/binman/test/45_prop_test.dts @@ -0,0 +1,23 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + sort-by-pos; + end-at-4gb; + size = <16>; + intel-me { + filename = "me.bin"; + pos-unset; + intval = <3>; + intarray = <5 6>; + byteval = [08]; + bytearray = [01 23 34]; + longbytearray = [09 0a 0b 0c]; + stringval = "message2"; + stringarray = "another", "multi-word", "message"; + }; + }; +}; |