예제 #1
0
    else:
        log_to_file = None
        log_file = None
    if args.block_size:
        block_size = args.block_size
    else:
        block_size = get_peb_size(path)
    perms = args.permissions
    quiet = args.quiet
    if not os.path.exists(output_path):
        os.makedirs(output_path)
    ufile = ubi_file(path, block_size)
    uubi = ubi(ufile)
    for image in uubi.images:
        for volume in image.volumes:
            vol_out_path = os.path.join(output_path, volume)
            if not os.path.exists(vol_out_path):
                os.makedirs(vol_out_path)
            elif os.listdir(vol_out_path):
                parser.error('Volume output directory is not empty. %s' %
                             vol_out_path)
            ufsfile = leb_virtual_file(uubi, image.volumes[volume])
            uubifs = ubifs(ufsfile)
            uubifs.log.log_file = log_file
            uubifs.log.log_to_file = log_to_file
            uubifs.log.quiet = quiet
            print 'Wait almost over ...\nLoading the image to: %s' % vol_out_path
            extract_files(uubifs, vol_out_path, perms)

    sys.exit(0)
예제 #2
0
def get_ubi_params(ubi):
    """Get UBI utils params

    Arguments:
    Obj:ubi    -- UBI object.

    Returns:
    Dict       -- Dict keyed to volume with Dict of args and flags.
    """
    ubi_flags = {
        'min_io_size': '-m',
        'max_bud_bytes': '-j',
        'leb_size': '-e',
        'default_compr': '-x',
        'sub_page_size': '-s',
        'fanout': '-f',
        'key_hash': '-k',
        'orph_lebs': '-p',
        'log_lebs': '-l',
        'max_leb_cnt': '-c',
        'peb_size': '-p',
        'sub_page_size': '-s',
        'vid_hdr_offset': '-O',
        'version': '-x',
        'image_seq': '-Q',
        'alignment': '-a',
        'vol_id': '-n',
        'name': '-N'
    }

    ubi_params = {}
    ubi_args = {}
    ini_params = {}
    for image in ubi.images:
        img_seq = image.image_seq
        ubi_params[img_seq] = {}
        ubi_args[img_seq] = {}
        ini_params[img_seq] = {}
        for volume in image.volumes:
            ubi_args[img_seq][volume] = {}
            ini_params[img_seq][volume] = {}

            # Get ubinize.ini settings
            ini_params[img_seq][volume]['vol_type'] = PRINT_VOL_TYPE_LIST[
                image.volumes[volume].vol_rec.vol_type]

            if image.volumes[volume].vol_rec.flags == UBI_VTBL_AUTORESIZE_FLG:
                ini_params[img_seq][volume]['vol_flags'] = 'autoresize'
            else:
                ini_params[img_seq][volume]['vol_flags'] = image.volumes[
                    volume].vol_rec.flags

            ini_params[img_seq][volume]['vol_id'] = image.volumes[
                volume].vol_id
            ini_params[img_seq][volume]['vol_name'] = image.volumes[
                volume].name.rstrip('\x00')
            ini_params[img_seq][volume]['vol_alignment'] = image.volumes[
                volume].vol_rec.alignment

            ini_params[img_seq][volume]['vol_size'] = image.volumes[
                volume].vol_rec.reserved_pebs * ubi.leb_size

            # Create file object backed by UBI blocks.
            ufsfile = leb_virtual_file(ubi, image.volumes[volume])
            # Create UBIFS object
            uubifs = ubifs(ufsfile)
            for key, value in uubifs.superblock_node:
                if key == 'key_hash':
                    value = PRINT_UBIFS_KEY_HASH[value]
                elif key == 'default_compr':
                    value = PRINT_UBIFS_COMPR[value]

                if key in ubi_flags:
                    ubi_args[img_seq][volume][key] = value

            for key, value in image.volumes[volume].vol_rec:
                if key == 'name':
                    value = value.rstrip('\x00')

                if key in ubi_flags:
                    ubi_args[img_seq][volume][key] = value

            ubi_args[img_seq][volume]['version'] = image.version
            ubi_args[img_seq][volume]['vid_hdr_offset'] = image.vid_hdr_offset
            ubi_args[img_seq][volume]['sub_page_size'] = ubi_args[img_seq][
                volume]['vid_hdr_offset']
            ubi_args[img_seq][volume]['sub_page_size'] = ubi_args[img_seq][
                volume]['vid_hdr_offset']
            ubi_args[img_seq][volume]['image_seq'] = image.image_seq
            ubi_args[img_seq][volume]['peb_size'] = ubi.peb_size
            ubi_args[img_seq][volume]['vol_id'] = image.volumes[volume].vol_id

            ubi_params[img_seq][volume] = {
                'flags': ubi_flags,
                'args': ubi_args[img_seq][volume],
                'ini': ini_params[img_seq][volume]
            }

    return ubi_params
예제 #3
0
def get_ubi_params(ubi):
    """Get UBI utils params

    Arguments:
    Obj:ubi    -- UBI object.

    Returns:
    Dict       -- Dict keyed to volume with Dict of args and flags.
    """
    ubi_flags = {
        "min_io_size": "-m",
        "max_bud_bytes": "-j",
        "leb_size": "-e",
        "default_compr": "-x",
        "sub_page_size": "-s",
        "fanout": "-f",
        "key_hash": "-k",
        "orph_lebs": "-p",
        "log_lebs": "-l",
        "max_leb_cnt": "-c",
        "peb_size": "-p",
        "sub_page_size": "-s",
        "vid_hdr_offset": "-O",
        "version": "-x",
        "image_seq": "-Q",
        "alignment": "-a",
        "vol_id": "-n",
        "name": "-N",
    }

    ubi_params = {}
    ubi_args = {}
    ini_params = {}
    for image in ubi.images:
        img_seq = image.image_seq
        ubi_params[img_seq] = {}
        ubi_args[img_seq] = {}
        ini_params[img_seq] = {}
        for volume in image.volumes:
            ubi_args[img_seq][volume] = {}
            ini_params[img_seq][volume] = {}

            # Get ubinize.ini settings
            ini_params[img_seq][volume]["vol_type"] = PRINT_VOL_TYPE_LIST[image.volumes[volume].vol_rec.vol_type]

            if image.volumes[volume].vol_rec.flags == UBI_VTBL_AUTORESIZE_FLG:
                ini_params[img_seq][volume]["vol_flags"] = "autoresize"
            else:
                ini_params[img_seq][volume]["vol_flags"] = image.volumes[volume].vol_rec.flags

            ini_params[img_seq][volume]["vol_id"] = image.volumes[volume].vol_id
            ini_params[img_seq][volume]["vol_name"] = image.volumes[volume].name.rstrip("\x00")
            ini_params[img_seq][volume]["vol_alignment"] = image.volumes[volume].vol_rec.alignment

            ini_params[img_seq][volume]["vol_size"] = image.volumes[volume].vol_rec.reserved_pebs * ubi.leb_size

            # Create file object backed by UBI blocks.
            ufsfile = leb_virtual_file(ubi, image.volumes[volume])
            # Create UBIFS object
            uubifs = ubifs(ufsfile)
            for key, value in uubifs.superblock_node:
                if key == "key_hash":
                    value = PRINT_UBIFS_KEY_HASH[value]
                elif key == "default_compr":
                    value = PRINT_UBIFS_COMPR[value]

                if key in ubi_flags:
                    ubi_args[img_seq][volume][key] = value

            for key, value in image.volumes[volume].vol_rec:
                if key == "name":
                    value = value.rstrip("\x00")

                if key in ubi_flags:
                    ubi_args[img_seq][volume][key] = value

            ubi_args[img_seq][volume]["version"] = image.version
            ubi_args[img_seq][volume]["vid_hdr_offset"] = image.vid_hdr_offset
            ubi_args[img_seq][volume]["sub_page_size"] = ubi_args[img_seq][volume]["vid_hdr_offset"]
            ubi_args[img_seq][volume]["sub_page_size"] = ubi_args[img_seq][volume]["vid_hdr_offset"]
            ubi_args[img_seq][volume]["image_seq"] = image.image_seq
            ubi_args[img_seq][volume]["peb_size"] = ubi.peb_size
            ubi_args[img_seq][volume]["vol_id"] = image.volumes[volume].vol_id

            ubi_params[img_seq][volume] = {
                "flags": ubi_flags,
                "args": ubi_args[img_seq][volume],
                "ini": ini_params[img_seq][volume],
            }

    return ubi_params
        log_to_file = True
        log_file = args.logpath
    else:
        log_to_file = None
        log_file = None
    if args.block_size:
        block_size = args.block_size
    else:
        block_size = get_peb_size(path)
    perms = args.permissions
    quiet = args.quiet
    if not os.path.exists(output_path):
        os.makedirs(output_path)
    ufile = ubi_file(path, block_size)
    uubi = ubi(ufile)
    for image in uubi.images:
        for volume in image.volumes:
            vol_out_path = os.path.join(output_path, volume)
            if not os.path.exists(vol_out_path):
                os.makedirs(vol_out_path)
            elif os.listdir(vol_out_path):
                parser.error('Volume output directory is not empty. %s' % vol_out_path)
            ufsfile = leb_virtual_file(uubi, image.volumes[volume])
            uubifs = ubifs(ufsfile)
            uubifs.log.log_file = log_file
            uubifs.log.log_to_file = log_to_file
            uubifs.log.quiet = quiet
            print 'Writing to: %s' % vol_out_path
            extract_files(uubifs, vol_out_path, perms)

    sys.exit(0)
예제 #5
0
def get_ubi_params(ubi):
    ubi_flags = {'min_io_size': '-m',
     'max_bud_bytes': '-j',
     'leb_size': '-e',
     'default_compr': '-x',
     'sub_page_size': '-s',
     'fanout': '-f',
     'key_hash': '-k',
     'orph_lebs': '-p',
     'log_lebs': '-l',
     'max_leb_cnt': '-c',
     'peb_size': '-p',
     'sub_page_size': '-s',
     'vid_hdr_offset': '-O',
     'version': '-x',
     'image_seq': '-Q',
     'alignment': '-a',
     'vol_id': '-n',
     'name': '-N'}
    ubi_params = {}
    ubi_args = {}
    ini_params = {}
    for image in ubi.images:
        img_seq = image.image_seq
        ubi_params[img_seq] = {}
        ubi_args[img_seq] = {}
        ini_params[img_seq] = {}
        for volume in image.volumes:
            ubi_args[img_seq][volume] = {}
            ini_params[img_seq][volume] = {}
            ini_params[img_seq][volume]['vol_type'] = PRINT_VOL_TYPE_LIST[image.volumes[volume].vol_rec.vol_type]
            if image.volumes[volume].vol_rec.flags == UBI_VTBL_AUTORESIZE_FLG:
                ini_params[img_seq][volume]['vol_flags'] = 'autoresize'
            else:
                ini_params[img_seq][volume]['vol_flags'] = image.volumes[volume].vol_rec.flags
            ini_params[img_seq][volume]['vol_id'] = image.volumes[volume].vol_id
            ini_params[img_seq][volume]['vol_name'] = image.volumes[volume].name.rstrip('\x00')
            ini_params[img_seq][volume]['vol_alignment'] = image.volumes[volume].vol_rec.alignment
            ini_params[img_seq][volume]['vol_size'] = image.volumes[volume].vol_rec.reserved_pebs * ubi.leb_size
            ufsfile = leb_virtual_file(ubi, image.volumes[volume])
            uubifs = ubifs(ufsfile)
            for key, value in uubifs.superblock_node:
                if key == 'key_hash':
                    value = PRINT_UBIFS_KEY_HASH[value]
                elif key == 'default_compr':
                    value = PRINT_UBIFS_COMPR[value]
                if key in ubi_flags:
                    ubi_args[img_seq][volume][key] = value

            for key, value in image.volumes[volume].vol_rec:
                if key == 'name':
                    value = value.rstrip('\x00')
                if key in ubi_flags:
                    ubi_args[img_seq][volume][key] = value

            ubi_args[img_seq][volume]['version'] = image.version
            ubi_args[img_seq][volume]['vid_hdr_offset'] = image.vid_hdr_offset
            ubi_args[img_seq][volume]['sub_page_size'] = ubi_args[img_seq][volume]['vid_hdr_offset']
            ubi_args[img_seq][volume]['sub_page_size'] = ubi_args[img_seq][volume]['vid_hdr_offset']
            ubi_args[img_seq][volume]['image_seq'] = image.image_seq
            ubi_args[img_seq][volume]['peb_size'] = ubi.peb_size
            ubi_args[img_seq][volume]['vol_id'] = image.volumes[volume].vol_id
            ubi_params[img_seq][volume] = {'flags': ubi_flags,
             'args': ubi_args[img_seq][volume],
             'ini': ini_params[img_seq][volume]}

    return ubi_params