def ScanDtb(self): """Scan the device tree to obtain a tree of notes and properties Once this is done, self.fdt.GetRoot() can be called to obtain the device tree root node, and progress from there. """ self.fdt = fdt_select.FdtScan(self._dtb_fname)
def ObtainContents(self): Entry_blob.ObtainContents(self) # If the image does not need microcode, there is nothing to do ucode_dest_entry = self.image.FindEntryType( 'u-boot-spl-with-ucode-ptr') if not ucode_dest_entry or not ucode_dest_entry.target_pos: ucode_dest_entry = self.image.FindEntryType( 'u-boot-with-ucode-ptr') if not ucode_dest_entry or not ucode_dest_entry.target_pos: return True # Create a new file to hold the copied device tree dtb_name = 'u-boot-dtb-with-ucode.dtb' fname = tools.GetOutputFilename(dtb_name) with open(fname, 'wb') as fd: fd.write(self.data) # Remove the microcode fdt = fdt_select.FdtScan(fname) fdt.Scan() ucode = fdt.GetNode('/microcode') if not ucode: raise self.Raise("No /microcode node found in '%s'" % fname) # There's no need to collate it (move all microcode into one place) # if we only have one chunk of microcode. self.collate = len(ucode.subnodes) > 1 for node in ucode.subnodes: 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') if self.collate: fdt.Pack() fdt.Flush() # Make this file the contents of this entry self._pathname = fname self.ReadContents() return True
def testPackUbootMicrocode(self): """Test that x86 microcode can be handled correctly We expect to see the following in the image, in order: u-boot-nodtb.bin with a microcode pointer inserted at the correct place u-boot.dtb with the microcode removed the microcode """ data = self._DoReadFile('34_x86_ucode.dts', True) # Now check the device tree has no microcode second = data[len(U_BOOT_NODTB_DATA):] fname = tools.GetOutputFilename('test.dtb') with open(fname, 'wb') as fd: fd.write(second) fdt = fdt_select.FdtScan(fname) ucode = fdt.GetNode('/microcode') self.assertTrue(ucode) for node in ucode.subnodes: self.assertFalse(node.props.get('data')) fdt_len = self.GetFdtLen(second) third = second[fdt_len:] # Check that the microcode appears immediately after the Fdt # This matches the concatenation of the data properties in # the /microcode/update@xxx nodes in x86_ucode.dts. ucode_data = struct.pack('>4L', 0x12345678, 0x12345679, 0xabcd0000, 0x78235609) self.assertEqual(ucode_data, third[:len(ucode_data)]) ucode_pos = len(U_BOOT_NODTB_DATA) + fdt_len # 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 Binman(options, args): """The main control code for binman This assumes that help and test options have already been dealt with. It deals with the core task of building images. Args: options: Command line options object args: Command line arguments (list of strings) """ global images if options.full_help: pager = os.getenv('PAGER') if not pager: pager = 'more' fname = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), 'README') command.Run(pager, fname) return 0 # Try to figure out which device tree contains our image description if options.dt: dtb_fname = options.dt else: board = options.board if not board: raise ValueError( 'Must provide a board to process (use -b <board>)') board_pathname = os.path.join(options.build_dir, board) dtb_fname = os.path.join(board_pathname, 'u-boot.dtb') if not options.indir: options.indir = ['.'] options.indir.append(board_pathname) try: tout.Init(options.verbosity) try: tools.SetInputDirs(options.indir) tools.PrepareOutputDir(options.outdir, options.preserve) fdt = fdt_select.FdtScan(dtb_fname) node = _FindBinmanNode(fdt) if not node: raise ValueError("Device tree '%s' does not have a 'binman' " "node" % dtb_fname) images = _ReadImageDesc(node) for image in images.values(): # Perform all steps for this image, including checking and # writing it. This means that errors found with a later # image will be reported after earlier images are already # completed and written, but that does not seem important. image.GetEntryContents() image.GetEntryPositions() image.PackEntries() image.CheckSize() image.CheckEntries() image.ProcessEntryContents() image.BuildImage() finally: tools.FinaliseOutputDir() finally: tout.Uninit() return 0