示例#1
0
def search_for_fv(inputfile, ipname):
    """Search for the firmware volume."""

    # use to find the name of the firmware to locate the firmware volume
    build_list = IP_OPTIONS.get(ipname)

    ui_name = build_list[0][1]

    logger.info("\nFinding the Firmware Volume")
    fw_vol = None

    command = [FMMT, "-v", os.path.abspath(inputfile), ">", "tmp.fmmt.txt"]

    try:
        os.environ["PATH"] += os.pathsep + TOOLS_DIR
        logger.info("\n{}".format(" ".join(command)))
        subprocess.check_call(" ".join(command), shell=True, timeout=60)
    except subprocess.CalledProcessError as status:
        logger.warning("\nError using FMMT: {}".format(status))
        return 1, fw_vol
    except subprocess.TimeoutExpired:
        logger.warning(
            "\nFMMT timed out viewing {}! Check input file for correct format".
            format(inputfile))

        if sys.platform == 'win32':
            result = os.system("taskkill /f /im FMMT.exe")
        elif sys.platform == 'linux':
            result = os.system("killall FMMT")
        if result == 0:
            return 1, fw_vol
        sys.exit("\nError Must kill process")

    # search FFS by name in firmware volumes
    fwvol_found = False

    with open("tmp.fmmt.txt", "r") as searchfile:
        for line in searchfile:
            match_fv = re.match(r"(^FV\d+) :", line)
            if match_fv:
                fwvol_found = True
                fw_vol = match_fv.groups()[0]
                continue
            if fwvol_found:
                match_name = re.match(r'File "(%s)"' % ui_name, line.lstrip())
                if match_name:
                    break
        else:
            fw_vol = None  # firmware volume was not found.
            logger.warning("\nCould not find file {} in {}".format(
                ui_name, inputfile))

    return 0, fw_vol
示例#2
0
def create_commands(filenames, ipname, fwvol):
    """Create Commands for the merge and replace of firmware section."""

    inputfiles, num_replace_files = sbrgn_image.ip_inputfiles(
        filenames, ipname)
    build_list = IP_OPTIONS.get(ipname)

    # get the file name to be used to replace firmware volume
    ui_name = build_list[0][1]

    cmd_list = sbrgn_image.build_command_list(build_list, inputfiles,
                                              num_replace_files)

    cmd = replace_ip(filenames[len(filenames) - 1], fwvol, ui_name,
                     filenames[0])
    cmd_list.append(cmd)

    return cmd_list