def ProcessFdt(self, fdt): # So the module can be loaded without it from dtoc import fdt # If the section does not need microcode, there is nothing to do ucode_dest_entry = self.section.FindEntryType( 'u-boot-spl-with-ucode-ptr') if not ucode_dest_entry or not ucode_dest_entry.target_offset: ucode_dest_entry = self.section.FindEntryType( 'u-boot-tpl-with-ucode-ptr') if not ucode_dest_entry or not ucode_dest_entry.target_offset: ucode_dest_entry = self.section.FindEntryType( 'u-boot-with-ucode-ptr') if not ucode_dest_entry or not ucode_dest_entry.target_offset: return True # Remove the microcode etype = self.GetFdtEtype() fdt = state.GetFdtForEtype(etype) self.ucode = fdt.GetNode('/microcode') if not self.ucode: raise self.Raise("No /microcode node found in '%s'" % etype) # There's no need to collate it (move all microcode into one place) # if we only have one chunk of microcode. self.collate = len(self.ucode.subnodes) > 1 for node in self.ucode.subnodes: data_prop = node.props.get('data') if data_prop: self.ucode_data += data_prop.bytes if self.collate: node.DeleteProp('data') return True
def Binman(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: args: Command line arguments Namespace object """ global Image global state if args.full_help: tools.PrintFullHelp( os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), 'README.rst')) return 0 # Put these here so that we can import this module without libfdt from binman.image import Image from binman import state if args.cmd in ['ls', 'extract', 'replace']: try: tout.Init(args.verbosity) tools.PrepareOutputDir(None) if args.cmd == 'ls': ListEntries(args.image, args.paths) if args.cmd == 'extract': ExtractEntries(args.image, args.filename, args.outdir, args.paths, not args.uncompressed) if args.cmd == 'replace': ReplaceEntries(args.image, args.filename, args.indir, args.paths, do_compress=not args.compressed, allow_resize=not args.fix_size, write_map=args.map) except: raise finally: tools.FinaliseOutputDir() return 0 elf_params = None if args.update_fdt_in_elf: elf_params = args.update_fdt_in_elf.split(',') if len(elf_params) != 4: raise ValueError( 'Invalid args %s to --update-fdt-in-elf: expected infile,outfile,begin_sym,end_sym' % elf_params) # Try to figure out which device tree contains our image description if args.dt: dtb_fname = args.dt else: board = args.board if not board: raise ValueError( 'Must provide a board to process (use -b <board>)') board_pathname = os.path.join(args.build_dir, board) dtb_fname = os.path.join(board_pathname, 'u-boot.dtb') if not args.indir: args.indir = ['.'] args.indir.append(board_pathname) try: tout.Init(args.verbosity) elf.debug = args.debug cbfs_util.VERBOSE = args.verbosity > 2 state.use_fake_dtb = args.fake_dtb # Normally we replace the 'u-boot' etype with 'u-boot-expanded', etc. # When running tests this can be disabled using this flag. When not # updating the FDT in image, it is not needed by binman, but we use it # for consistency, so that the images look the same to U-Boot at # runtime. use_expanded = not args.no_expanded try: tools.SetInputDirs(args.indir) tools.PrepareOutputDir(args.outdir, args.preserve) tools.SetToolPaths(args.toolpath) state.SetEntryArgs(args.entry_arg) state.SetThreads(args.threads) images = PrepareImagesAndDtbs(dtb_fname, args.image, args.update_fdt, use_expanded) if args.test_section_timeout: # Set the first image to timeout, used in testThreadTimeout() images[list(images.keys())[0]].test_section_timeout = True invalid = False for image in images.values(): invalid |= ProcessImage(image, args.update_fdt, args.map, allow_missing=args.allow_missing, allow_fake_blobs=args.fake_ext_blobs) # Write the updated FDTs to our output files for dtb_item in state.GetAllFdts(): tools.WriteFile(dtb_item._fname, dtb_item.GetContents()) if elf_params: data = state.GetFdtForEtype('u-boot-dtb').GetContents() elf.UpdateFile(*elf_params, data) if invalid: tout.Warning("\nSome images are invalid") # Use this to debug the time take to pack the image #state.TimingShow() finally: tools.FinaliseOutputDir() finally: tout.Uninit() return 0