+ def testSplBssPad(self):
+ """Test that we can pad SPL's BSS with zeros"""
+ # ELF file with a '__bss_size' symbol
+ with open(self.TestFile('bss_data')) as fd:
+ TestFunctional._MakeInputFile('spl/u-boot-spl', fd.read())
+ data = self._DoReadFile('47_spl_bss_pad.dts')
+ self.assertEqual(U_BOOT_SPL_DATA + (chr(0) * 10) + U_BOOT_DATA, data)
+
+ with open(self.TestFile('u_boot_ucode_ptr')) as fd:
+ TestFunctional._MakeInputFile('spl/u-boot-spl', fd.read())
+ with self.assertRaises(ValueError) as e:
+ data = self._DoReadFile('47_spl_bss_pad.dts')
+ self.assertIn('Expected __bss_size symbol in spl/u-boot-spl',
+ str(e.exception))
+
+ def testPackStart16Spl(self):
+ """Test that an image with an x86 start16 region can be created"""
+ data = self._DoReadFile('48_x86-start16-spl.dts')
+ self.assertEqual(X86_START16_SPL_DATA, data[:len(X86_START16_SPL_DATA)])
+
+ def _PackUbootSplMicrocode(self, dts, ucode_second=False):
+ """Helper function for microcode tests
+
+ We expect to see the following in the image, in order:
+ u-boot-spl-nodtb.bin with a microcode pointer inserted at the
+ correct place
+ u-boot.dtb with the microcode removed
+ the microcode
+
+ Args:
+ dts: Device tree file to use for test
+ ucode_second: True if the microsecond entry is second instead of
+ third
+ """
+ # ELF file with a '_dt_ucode_base_size' symbol
+ with open(self.TestFile('u_boot_ucode_ptr')) as fd:
+ TestFunctional._MakeInputFile('spl/u-boot-spl', fd.read())
+ first, pos_and_size = self._RunMicrocodeTest(dts, U_BOOT_SPL_NODTB_DATA,
+ ucode_second=ucode_second)
+ self.assertEqual('splnodtb with microc' + pos_and_size +
+ 'ter somewhere in here', first)
+
+ def testPackUbootSplMicrocode(self):
+ """Test that x86 microcode can be handled correctly in SPL"""
+ self._PackUbootSplMicrocode('49_x86_ucode_spl.dts')
+
+ def testPackUbootSplMicrocodeReorder(self):
+ """Test that order doesn't matter for microcode entries
+
+ This is the same as testPackUbootSplMicrocode but when we process the
+ u-boot-ucode entry we have not yet seen the u-boot-dtb-with-ucode
+ entry, so we reply on binman to try later.
+ """
+ self._PackUbootSplMicrocode('58_x86_ucode_spl_needs_retry.dts',
+ ucode_second=True)
+
+ def testPackMrc(self):
+ """Test that an image with an MRC binary can be created"""
+ data = self._DoReadFile('50_intel_mrc.dts')
+ self.assertEqual(MRC_DATA, data[:len(MRC_DATA)])
+
+ def testSplDtb(self):
+ """Test that an image with spl/u-boot-spl.dtb can be created"""
+ data = self._DoReadFile('51_u_boot_spl_dtb.dts')
+ self.assertEqual(U_BOOT_SPL_DTB_DATA, data[:len(U_BOOT_SPL_DTB_DATA)])
+
+ def testSplNoDtb(self):
+ """Test that an image with spl/u-boot-spl-nodtb.bin can be created"""
+ data = self._DoReadFile('52_u_boot_spl_nodtb.dts')
+ self.assertEqual(U_BOOT_SPL_NODTB_DATA, data[:len(U_BOOT_SPL_NODTB_DATA)])
+
+ def testSymbols(self):
+ """Test binman can assign symbols embedded in U-Boot"""
+ elf_fname = self.TestFile('u_boot_binman_syms')
+ syms = elf.GetSymbols(elf_fname, ['binman', 'image'])
+ addr = elf.GetSymbolAddress(elf_fname, '__image_copy_start')
+ self.assertEqual(syms['_binman_u_boot_spl_prop_pos'].address, addr)
+
+ with open(self.TestFile('u_boot_binman_syms')) as fd:
+ TestFunctional._MakeInputFile('spl/u-boot-spl', fd.read())
+ data = self._DoReadFile('53_symbols.dts')
+ sym_values = struct.pack('<LQL', 0x24 + 0, 0x24 + 24, 0x24 + 20)
+ expected = (sym_values + U_BOOT_SPL_DATA[16:] + chr(0xff) +
+ U_BOOT_DATA +
+ sym_values + U_BOOT_SPL_DATA[16:])
+ self.assertEqual(expected, data)
+
+ def testPackUnitAddress(self):
+ """Test that we support multiple binaries with the same name"""
+ data = self._DoReadFile('54_unit_address.dts')
+ self.assertEqual(U_BOOT_DATA + U_BOOT_DATA, data)
+
+ def testSections(self):
+ """Basic test of sections"""
+ data = self._DoReadFile('55_sections.dts')
+ expected = U_BOOT_DATA + '!' * 12 + U_BOOT_DATA + 'a' * 12 + '&' * 8
+ self.assertEqual(expected, data)
+
+ def testMap(self):
+ """Tests outputting a map of the images"""
+ _, _, map_data = self._DoReadFileDtb('55_sections.dts', map=True)
+ self.assertEqual('''Position Size Name
+00000000 00000010 section@0
+ 00000000 00000004 u-boot
+00000010 00000010 section@1
+ 00000000 00000004 u-boot
+''', map_data)
+
+ def testNamePrefix(self):
+ """Tests that name prefixes are used"""
+ _, _, map_data = self._DoReadFileDtb('56_name_prefix.dts', map=True)
+ self.assertEqual('''Position Size Name
+00000000 00000010 section@0
+ 00000000 00000004 ro-u-boot
+00000010 00000010 section@1
+ 00000000 00000004 rw-u-boot
+''', map_data)
+
+ def testUnknownContents(self):
+ """Test that obtaining the contents works as expected"""
+ with self.assertRaises(ValueError) as e:
+ self._DoReadFile('57_unknown_contents.dts', True)
+ self.assertIn("Section '/binman': Internal error: Could not complete "
+ "processing of contents: remaining [<_testing.Entry__testing ",
+ str(e.exception))
+
+ def testBadChangeSize(self):
+ """Test that trying to change the size of an entry fails"""
+ with self.assertRaises(ValueError) as e:
+ self._DoReadFile('59_change_size.dts', True)
+ self.assertIn("Node '/binman/_testing': Cannot update entry size from "
+ '2 to 1', str(e.exception))
+