def setUpClass(cls): tools.PrepareOutputDir(None)
def setUp(self): tools.PrepareOutputDir(None)
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: # Import these here in case libfdt.py is not available, in which case # the above help option still works. import fdt import fdt_util tout.Init(options.verbosity) elf.debug = options.debug state.use_fake_dtb = options.fake_dtb try: tools.SetInputDirs(options.indir) tools.PrepareOutputDir(options.outdir, options.preserve) state.SetEntryArgs(options.entry_arg) # Get the device tree ready by compiling it and copying the compiled # output into a file in our output directly. Then scan it for use # in binman. dtb_fname = fdt_util.EnsureCompiled(dtb_fname) fname = tools.GetOutputFilename('u-boot.dtb.out') tools.WriteFile(fname, tools.ReadFile(dtb_fname)) dtb = fdt.FdtScan(fname) node = _FindBinmanNode(dtb) if not node: raise ValueError("Device tree '%s' does not have a 'binman' " "node" % dtb_fname) images = _ReadImageDesc(node) if options.image: skip = [] for name, image in images.iteritems(): if name not in options.image: del images[name] skip.append(name) if skip: print 'Skipping images: %s\n' % ', '.join(skip) state.Prepare(images, dtb) # Prepare the device tree by making sure that any missing # properties are added (e.g. 'pos' and 'size'). The values of these # may not be correct yet, but we add placeholders so that the # size of the device tree is correct. Later, in # SetCalculatedProperties() we will insert the correct values # without changing the device-tree size, thus ensuring that our # entry offsets remain the same. for image in images.values(): image.ExpandEntries() if options.update_fdt: image.AddMissingProperties() image.ProcessFdt(dtb) for dtb_item in state.GetFdts(): dtb_item.Sync(auto_resize=True) dtb_item.Pack() dtb_item.Flush() 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.GetEntryOffsets() try: image.PackEntries() image.CheckSize() image.CheckEntries() except Exception as e: if options.map: fname = image.WriteMap() print "Wrote map file '%s' to show errors" % fname raise image.SetImagePos() if options.update_fdt: image.SetCalculatedProperties() for dtb_item in state.GetFdts(): dtb_item.Sync() image.ProcessEntryContents() image.WriteSymbols() image.BuildImage() if options.map: image.WriteMap() # Write the updated FDTs to our output files for dtb_item in state.GetFdts(): tools.WriteFile(dtb_item._fname, dtb_item.GetContents()) finally: tools.FinaliseOutputDir() finally: tout.Uninit() return 0
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) elf.debug = options.debug try: tools.SetInputDirs(options.indir) tools.PrepareOutputDir(options.outdir, options.preserve) # Get the device tree ready by compiling it and copying the compiled # output into a file in our output directly. Then scan it for use # in binman. dtb_fname = fdt_util.EnsureCompiled(dtb_fname) fname = tools.GetOutputFilename('u-boot-out.dtb') with open(dtb_fname) as infd: with open(fname, 'wb') as outfd: outfd.write(infd.read()) dtb = fdt.FdtScan(fname) # Note the file so that GetFdt() can find it fdt_files['u-boot.dtb'] = dtb node = _FindBinmanNode(dtb) if not node: raise ValueError("Device tree '%s' does not have a 'binman' " "node" % dtb_fname) images = _ReadImageDesc(node) # Prepare the device tree by making sure that any missing # properties are added (e.g. 'pos' and 'size'). The values of these # may not be correct yet, but we add placeholders so that the # size of the device tree is correct. Later, in # SetCalculatedProperties() we will insert the correct values # without changing the device-tree size, thus ensuring that our # entry positions remain the same. for image in images.values(): if options.update_fdt: image.AddMissingProperties() image.ProcessFdt(dtb) dtb.Pack() dtb.Flush() 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() if options.update_fdt: image.SetCalculatedProperties() image.ProcessEntryContents() image.WriteSymbols() image.BuildImage() if options.map: image.WriteMap() with open(fname, 'wb') as outfd: outfd.write(dtb.GetContents()) finally: tools.FinaliseOutputDir() finally: tout.Uninit() return 0
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 """ if args.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 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 # 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 try: tools.SetInputDirs(args.indir) tools.PrepareOutputDir(args.outdir, args.preserve) tools.SetToolPaths(args.toolpath) state.SetEntryArgs(args.entry_arg) images = PrepareImagesAndDtbs(dtb_fname, args.image, args.update_fdt) for image in images.values(): ProcessImage(image, args.update_fdt, args.map) # Write the updated FDTs to our output files for dtb_item in state.GetAllFdts(): tools.WriteFile(dtb_item._fname, dtb_item.GetContents()) finally: tools.FinaliseOutputDir() finally: tout.Uninit() return 0
def setUpClass(self): self._binman_dir = os.path.dirname(os.path.realpath(sys.argv[0])) self._indir = tempfile.mkdtemp(prefix='binmant.') tools.PrepareOutputDir(self._indir, True)