Beispiel #1
0
 def tearDownClass(cls):
     tools.finalise_output_dir()
Beispiel #2
0
 def tearDownClass(cls):
     """Remove the temporary input directory and its contents"""
     if cls._indir:
         shutil.rmtree(cls._indir)
     cls._indir = None
     tools.finalise_output_dir()
Beispiel #3
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
    """
    global Image
    global state

    if args.full_help:
        tools.print_full_help(
            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', 'tool']:
        try:
            tout.init(args.verbosity)
            tools.prepare_output_dir(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, args.format)

            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)

            if args.cmd == 'tool':
                tools.set_tool_paths(args.toolpath)
                if args.list:
                    bintool.Bintool.list_all()
                elif args.fetch:
                    if not args.bintools:
                        raise ValueError(
                            "Please specify bintools to fetch or 'all' or 'missing'"
                        )
                    bintool.Bintool.fetch_tools(bintool.FETCH_ANY,
                                                args.bintools)
                else:
                    raise ValueError("Invalid arguments to 'tool' subcommand")
        except:
            raise
        finally:
            tools.finalise_output_dir()
        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.set_input_dirs(args.indir)
            tools.prepare_output_dir(args.outdir, args.preserve)
            tools.set_tool_paths(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
            bintool.Bintool.set_missing_list(
                args.force_missing_bintools.split(',') if args.
                force_missing_bintools else None)
            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.write_file(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.finalise_output_dir()
    finally:
        tout.uninit()

    return 0
Beispiel #4
0
 def tearDown(self):
     tools.finalise_output_dir()
Beispiel #5
0
 def tearDown(self):
     """Remove the temporary input directory and its contents"""
     if self._indir:
         shutil.rmtree(self._indir)
     self._indir = None
     tools.finalise_output_dir()