def main(argv): # This allows modifying the value from inner function. bootable_only_array = [False] def option_handler(o, _): if o in ("-z", "--bootable_zip"): bootable_only_array[0] = True else: return False return True args = common.ParseOptions(argv, __doc__, extra_opts="z", extra_long_opts=["bootable_zip"], extra_option_handler=option_handler) OPTIONS.bootable_only = bootable_only_array[0] if len(args) != 2: common.Usage(__doc__) sys.exit(1) common.InitLogging() ImgFromTargetFiles(args[0], args[1]) logger.info("done.")
def main(argv): def option_handler(o, a): if o in ("-c", "--compare_with"): OPTIONS.compare_with = a elif o in ("-l", "--local_cert_dirs"): OPTIONS.local_cert_dirs = [i.strip() for i in a.split(",")] elif o in ("-t", "--text"): OPTIONS.text = True else: return False return True args = common.ParseOptions(argv, __doc__, extra_opts="c:l:t", extra_long_opts=["compare_with=", "local_cert_dirs="], extra_option_handler=option_handler) if len(args) != 1: common.Usage(__doc__) sys.exit(1) common.InitLogging() ALL_CERTS.FindLocalCerts() Push("input target_files:") try: target_files = TargetFiles() target_files.LoadZipFile(args[0]) finally: Pop() compare_files = None if OPTIONS.compare_with: Push("comparison target_files:") try: compare_files = TargetFiles() compare_files.LoadZipFile(OPTIONS.compare_with) finally: Pop() if OPTIONS.text or not compare_files: Banner("target files") target_files.PrintCerts() target_files.CheckSharedUids() target_files.CheckExternalSignatures() if compare_files: if OPTIONS.text: Banner("comparison files") compare_files.PrintCerts() target_files.CompareWith(compare_files) if PROBLEMS: print("%d problem(s) found:\n" % (len(PROBLEMS),)) for p in PROBLEMS: print(p) return 1 return 0
def main(argv): if len(argv) != 2: print(__doc__) sys.exit(1) common.InitLogging() dict_file = argv[0] out_file = argv[1] prop_dict = {} with open(dict_file, 'r') as f: for line in f: line = line.strip() if not line or line.startswith("#"): continue k, v = line.split("=", 1) prop_dict[k] = v builder = CreateVerityImageBuilder(prop_dict) if "partition_size" not in prop_dict: image_size = GetDiskUsage(out_file) # make sure that the image is big enough to hold vbmeta and footer image_size = image_size + (MAX_VBMETA_SIZE + MAX_FOOTER_SIZE) size = builder.CalculateDynamicPartitionSize(image_size) prop_dict["partition_size"] = size builder.Build(out_file)
def main(): common.InitLogging() def option_handler(o, a): if o == '--qssi-dpm-file': OPTIONS.qssi_dynamic_partition_metadata_file = a elif o == '--target-dpm-file': OPTIONS.target_dynamic_partition_metadata_file = a elif o == '--merged-dpm-file': OPTIONS.merged_dynamic_partition_metadata_file = a else: return False return True args = common.ParseOptions(sys.argv[1:], __doc__, extra_long_opts=[ 'qssi-dpm-file=', 'target-dpm-file=', 'merged-dpm-file=', ], extra_option_handler=option_handler) if (len(args) != 0 or OPTIONS.qssi_dynamic_partition_metadata_file is None or OPTIONS.target_dynamic_partition_metadata_file is None or OPTIONS.merged_dynamic_partition_metadata_file is None): common.Usage(__doc__) sys.exit(1) merge_dynamic_partition_metadata( OPTIONS.qssi_dynamic_partition_metadata_file, OPTIONS.target_dynamic_partition_metadata_file, OPTIONS.merged_dynamic_partition_metadata_file)
def main(): common.InitLogging() def option_handler(o, a): if o == "--framework_images": OPTIONS.framework_images = [i.strip() for i in a.split(",")] elif o == "--product_out_framework": OPTIONS.product_out_framework = a elif o == "--product_out_vendor": OPTIONS.product_out_vendor = a elif o == "--build_vbmeta": OPTIONS.build_vbmeta = True elif o == "--framework_misc_info_keys": OPTIONS.framework_misc_info_keys = a else: return False return True args = common.ParseOptions(sys.argv[1:], __doc__, extra_long_opts=[ "framework_images=", "product_out_framework=", "product_out_vendor=", "build_vbmeta", "framework_misc_info_keys=", ], extra_option_handler=option_handler) if (args or OPTIONS.product_out_framework is None or OPTIONS.product_out_vendor is None): common.Usage(__doc__) sys.exit(1) MergeBuilds()
def main(argv): def option_handler(o, a): if o in ("-a", "--add_missing"): OPTIONS.add_missing = True elif o in ("-r", "--rebuild_recovery",): OPTIONS.rebuild_recovery = True elif o == "--replace_verity_private_key": OPTIONS.replace_verity_private_key = (True, a) elif o == "--replace_verity_public_key": OPTIONS.replace_verity_public_key = (True, a) elif o == "--is_signing": OPTIONS.is_signing = True else: return False return True args = common.ParseOptions( argv, __doc__, extra_opts="ar", extra_long_opts=["add_missing", "rebuild_recovery", "replace_verity_public_key=", "replace_verity_private_key=", "is_signing"], extra_option_handler=option_handler) if len(args) != 1: common.Usage(__doc__) sys.exit(1) common.InitLogging() AddImagesToTargetFiles(args[0]) logger.info("done.")
def main(argv): args = common.ParseOptions(argv, __doc__) input_dir, output_dir = args common.InitLogging() OPTIONS.info_dict = common.LoadInfoDict(input_dir) recovery_img = common.GetBootableImage("recovery.img", "recovery.img", input_dir, "RECOVERY") boot_img = common.GetBootableImage("boot.img", "boot.img", input_dir, "BOOT") if not recovery_img or not boot_img: sys.exit(0) board_uses_vendorimage = OPTIONS.info_dict.get( "board_uses_vendorimage") == "true" board_builds_vendorimage = OPTIONS.info_dict.get( "board_builds_vendorimage") == "true" target_files_dir = None if board_builds_vendorimage: target_files_dir = "VENDOR" elif not board_uses_vendorimage: target_files_dir = "SYSTEM/vendor" def output_sink(fn, data): if target_files_dir is None: return with open(os.path.join(output_dir, target_files_dir, *fn.split("/")), "wb") as f: f.write(data)
def main(argv): def option_handler(o, a): if o in ('-z', '--bootable_zip'): OPTIONS.bootable_only = True elif o == '--additional': OPTIONS.additional_entries.append(a) else: return False return True args = common.ParseOptions(argv, __doc__, extra_opts='z', extra_long_opts=[ 'additional=', 'bootable_zip', ], extra_option_handler=option_handler) if len(args) != 2: common.Usage(__doc__) sys.exit(1) common.InitLogging() ImgFromTargetFiles(args[0], args[1]) logger.info('done.')
def main(argv): args = common.ParseOptions(argv, __doc__) if len(args) != 1: common.Usage(__doc__) sys.exit(1) common.InitLogging() CheckPartitionSizes(args[0])
def main(argv): args = common.ParseOptions(argv, __doc__) if len(args) != 1: common.Usage(__doc__) sys.exit(1) common.InitLogging() if not CheckVintf(args[0]): sys.exit(1)
def main(argv): options = {} def option_handler(o, a): if o == '--avbtool': options['avbtool'] = a elif o == '--container_key': # Strip the suffix if any, as common.SignFile expects no suffix. DEFAULT_CONTAINER_KEY_SUFFIX = '.x509.pem' if a.endswith(DEFAULT_CONTAINER_KEY_SUFFIX): a = a[:-len(DEFAULT_CONTAINER_KEY_SUFFIX)] options['container_key'] = a elif o == '--payload_key': options['payload_key'] = a elif o == '--payload_extra_args': options['payload_extra_args'] = a elif o in ("-e", "--extra_apks"): names, key = a.split("=") names = names.split(",") for n in names: if 'extra_apks' not in options: options['extra_apks'] = {} options['extra_apks'].update({n: key}) else: return False return True args = common.ParseOptions(argv, __doc__, extra_opts='e:', extra_long_opts=[ 'avbtool=', 'container_key=', 'payload_extra_args=', 'payload_key=', 'extra_apks=', ], extra_option_handler=option_handler) if (len(args) != 2 or 'container_key' not in options or 'payload_key' not in options): common.Usage(__doc__) sys.exit(1) common.InitLogging() signed_apex = SignApexFile(options.get('avbtool', 'avbtool'), args[0], options['payload_key'], options['container_key'], no_hashtree=False, apk_keys=options.get('extra_apks', {}), signing_args=options.get('payload_extra_args')) shutil.copyfile(signed_apex, args[1]) logger.info("done.")
def main(): parser = argparse.ArgumentParser() parser.add_argument('certificate', help='The certificate to be used.') parser.add_argument('package', help='The OTA package to be verified.') args = parser.parse_args() common.InitLogging() VerifyPackage(args.certificate, args.package) VerifyAbOtaPayload(args.certificate, args.package)
def main(argv): if len(argv) < 4 or len(argv) > 5: print(__doc__) sys.exit(1) common.InitLogging() in_dir = argv[0] glob_dict_file = argv[1] out_file = argv[2] target_out = argv[3] prop_file_out = argv[4] if len(argv) >= 5 else None glob_dict = LoadGlobalDict(glob_dict_file) if "mount_point" in glob_dict: # The caller knows the mount point and provides a dictionary needed by # BuildImage(). image_properties = glob_dict else: image_filename = os.path.basename(out_file) mount_point = "" if image_filename == "system.img": mount_point = "system" ExtractSystemOtherAvbKey(in_dir, glob_dict) elif image_filename == "system_other.img": mount_point = "system_other" elif image_filename == "userdata.img": mount_point = "data" elif image_filename == "cache.img": mount_point = "cache" elif image_filename == "vendor.img": mount_point = "vendor" elif image_filename == "odm.img": mount_point = "odm" elif image_filename == "oem.img": mount_point = "oem" elif image_filename == "product.img": mount_point = "product" elif image_filename == "product_services.img": mount_point = "product_services" else: logger.error("Unknown image file name %s", image_filename) sys.exit(1) image_properties = ImagePropFromGlobalDict(glob_dict, mount_point) try: BuildImage(in_dir, image_properties, out_file, target_out) except: logger.error("Failed to build %s from %s", out_file, in_dir) raise if prop_file_out: glob_dict_out = GlobalDictFromImageProp(image_properties, mount_point) SaveGlobalDict(prop_file_out, glob_dict_out)
def main(argv): if len(argv) != 4: print(__doc__) sys.exit(1) common.InitLogging() in_dir = argv[0] glob_dict_file = argv[1] out_file = argv[2] target_out = argv[3] glob_dict = LoadGlobalDict(glob_dict_file) if "mount_point" in glob_dict: # The caller knows the mount point and provides a dictionary needed by # BuildImage(). image_properties = glob_dict else: image_filename = os.path.basename(out_file) mount_point = "" if image_filename == "system.img": mount_point = "system" elif image_filename == "system_other.img": mount_point = "system_other" elif image_filename == "userdata.img": mount_point = "data" elif image_filename == "cache.img": mount_point = "cache" elif image_filename == "vendor.img": mount_point = "vendor" elif image_filename == "odm.img": mount_point = "odm" elif image_filename == "vendor_dlkm.img": mount_point = "vendor_dlkm" elif image_filename == "odm_dlkm.img": mount_point = "odm_dlkm" elif image_filename == "oem.img": mount_point = "oem" elif image_filename == "product.img": mount_point = "product" elif image_filename == "system_ext.img": mount_point = "system_ext" elif image_filename == "modules.img": mount_point = "modules" else: logger.error("Unknown image file name %s", image_filename) sys.exit(1) image_properties = ImagePropFromGlobalDict(glob_dict, mount_point) try: BuildImage(in_dir, image_properties, out_file, target_out) except: logger.error("Failed to build %s from %s", out_file, in_dir) raise
def main(argv): # This allows modifying the value from inner function. bootable_only_array = [False] def option_handler(o, _): if o in ("-z", "--bootable_zip"): bootable_only_array[0] = True else: return False return True args = common.ParseOptions(argv, __doc__, extra_opts="z", extra_long_opts=["bootable_zip"], extra_option_handler=option_handler) bootable_only = bootable_only_array[0] if len(args) != 2: common.Usage(__doc__) sys.exit(1) common.InitLogging() target_files = args[0] if os.path.isdir(target_files): logger.info("Building image zip from extracted target files.") OPTIONS.input_tmp = target_files elif zipfile.is_zipfile(target_files): logger.info("Building image zip from target files zip.") OPTIONS.input_tmp = common.UnzipTemp(args[0], ["IMAGES/*", "OTA/*"]) else: raise ValueError("%s is not a valid path." % target_files) output_zip = zipfile.ZipFile(args[1], "w", compression=zipfile.ZIP_DEFLATED) CopyInfo(output_zip) try: images_path = os.path.join(OPTIONS.input_tmp, "IMAGES") # A target-files zip must contain the images since Lollipop. assert os.path.exists(images_path) for image in sorted(os.listdir(images_path)): if bootable_only and image not in ("boot.img", "recovery.img"): continue if not image.endswith(".img"): continue if image == "recovery-two-step.img": continue common.ZipWrite(output_zip, os.path.join(images_path, image), image) finally: logger.info("cleaning up...") common.ZipClose(output_zip) logger.info("done.")
def main(argv): args = common.ParseOptions(argv, __doc__) if len(args) != 2: common.Usage(__doc__) sys.exit(1) common.InitLogging() BuildSuperImage(args[0], args[1])
def main(argv): # This allows modifying the value from inner function. bootable_only_array = [False] def option_handler(o, _): if o in ("-z", "--bootable_zip"): bootable_only_array[0] = True else: return False return True args = common.ParseOptions(argv, __doc__, extra_opts="z", extra_long_opts=["bootable_zip"], extra_option_handler=option_handler) OPTIONS.bootable_only = bootable_only_array[0] if len(args) != 2: common.Usage(__doc__) sys.exit(1) common.InitLogging() target_files = args[0] if os.path.isdir(target_files): logger.info("Building image zip from extracted target files.") OPTIONS.input_tmp = target_files elif zipfile.is_zipfile(target_files): logger.info("Building image zip from target files zip.") # We need files under IMAGES/, OTA/, META/ for img_from_target_files.py. # However, common.LoadInfoDict() may read additional files under BOOT/, # RECOVERY/ and ROOT/. So unzip everything from the target_files.zip. OPTIONS.input_tmp = common.UnzipTemp(target_files) else: raise ValueError("%s is not a valid path." % target_files) LoadOptions(OPTIONS.input_tmp) output_zip = zipfile.ZipFile(args[1], "w", compression=zipfile.ZIP_DEFLATED, allowZip64=not OPTIONS.sparse_userimages) try: CopyInfo(OPTIONS.input_tmp, output_zip) CopyUserImages(OPTIONS.input_tmp, output_zip) WriteSuperImages(OPTIONS.input_tmp, output_zip) finally: logger.info("cleaning up...") common.ZipClose(output_zip) logger.info("done.")
def main(argv): options = {} def option_handler(o, a): if o == '--container_key': # Strip the suffix if any, as common.SignFile expects no suffix. DEFAULT_CONTAINER_KEY_SUFFIX = '.x509.pem' if a.endswith(DEFAULT_CONTAINER_KEY_SUFFIX): a = a[:-len(DEFAULT_CONTAINER_KEY_SUFFIX)] options['container_key'] = a elif o == '--payload_key': options['payload_key'] = a elif o == '--payload_extra_args': options['payload_extra_args'] = a else: return False return True args = common.ParseOptions(argv, __doc__, extra_opts='', extra_long_opts=[ 'container_key=', 'payload_extra_args=', 'payload_key=', ], extra_option_handler=option_handler) if (len(args) != 2 or 'container_key' not in options or 'payload_key' not in options): common.Usage(__doc__) sys.exit(1) common.InitLogging() input_zip = args[0] output_zip = args[1] with open(input_zip) as input_fp: apex_data = input_fp.read() signed_apex = apex_utils.SignApex( apex_data, payload_key=options['payload_key'], container_key=options['container_key'], container_pw=None, codename_to_api_level_map=None, signing_args=options.get('payload_extra_args')) shutil.copyfile(signed_apex, output_zip) logger.info("done.")
def main(): """The main function. Process command line arguments, then call merge_target_files_with_temp_dir to perform the heavy lifting. Returns: On success, 0. Otherwise, a non-zero exit code. """ common.InitLogging() def option_handler(o, a): if o == '--system-target-files': OPTIONS.system_target_files = a elif o == '--other-target-files': OPTIONS.other_target_files = a elif o == '--output-target-files': OPTIONS.output_target_files = a elif o == '--keep_tmp': OPTIONS.keep_tmp = True else: return False return True args = common.ParseOptions(sys.argv[1:], __doc__, extra_long_opts=[ 'system-target-files=', 'other-target-files=', 'output-target-files=', "keep_tmp", ], extra_option_handler=option_handler) if (len(args) != 0 or OPTIONS.system_target_files is None or OPTIONS.other_target_files is None or OPTIONS.output_target_files is None): common.Usage(__doc__) return 1 return merge_target_files_with_temp_dir( system_target_files=OPTIONS.system_target_files, other_target_files=OPTIONS.other_target_files, output_target_files=OPTIONS.output_target_files, keep_tmp=OPTIONS.keep_tmp)
def main(): common.InitLogging() def option_handler(o, a): if o == "--product_out": OPTIONS.product_out = a elif o == "--aapt": OPTIONS.aapt = a elif o == "--copy_out_system": OPTIONS.copy_out_system = a elif o == "--copy_out_vendor": OPTIONS.copy_out_vendor = a elif o == "--copy_out_product": OPTIONS.copy_out_product = a elif o == "--copy_out_system_ext": OPTIONS.copy_out_system_ext = a else: return False return True args = common.ParseOptions( sys.argv[1:], __doc__, extra_long_opts=[ "product_out=", "aapt=", "copy_out_system=", "copy_out_vendor=", "copy_out_product=", "copy_out_system_ext=", ], extra_option_handler=option_handler) if args: common.Usage(__doc__) sys.exit(1) partition_map = { "system": OPTIONS.copy_out_system, "vendor": OPTIONS.copy_out_vendor, "product": OPTIONS.copy_out_product, "system_ext": OPTIONS.copy_out_system_ext, } print( FindShareduidViolation(OPTIONS.product_out, partition_map, OPTIONS.aapt))
def main(argv): args = common.ParseOptions(argv, __doc__) input_dir, output_dir = args common.InitLogging() OPTIONS.info_dict = common.LoadInfoDict(input_dir) recovery_img = common.GetBootableImage("recovery.img", "recovery.img", input_dir, "RECOVERY") boot_img = common.GetBootableImage("boot.img", "boot.img", input_dir, "BOOT") if not recovery_img or not boot_img: sys.exit(0) def output_sink(fn, data): with open(os.path.join(output_dir, "SYSTEM", *fn.split("/")), "wb") as f: f.write(data)
def main(): """The main function. Process command line arguments, then call merge_target_files to perform the heavy lifting. """ common.InitLogging() def option_handler(o, a): if o == '--system-target-files': OPTIONS.system_target_files = a elif o == '--system-item-list': OPTIONS.system_item_list = a elif o == '--system-misc-info-keys': OPTIONS.system_misc_info_keys = a elif o == '--other-target-files': OPTIONS.other_target_files = a elif o == '--other-item-list': OPTIONS.other_item_list = a elif o == '--output-target-files': OPTIONS.output_target_files = a elif o == '--keep_tmp': OPTIONS.keep_tmp = True else: return False return True args = common.ParseOptions(sys.argv[1:], __doc__, extra_long_opts=[ 'system-target-files=', 'system-item-list=', 'system-misc-info-keys=', 'other-target-files=', 'other-item-list=', 'output-target-files=', "keep_tmp", ], extra_option_handler=option_handler) if (len(args) != 0 or OPTIONS.system_target_files is None or OPTIONS.other_target_files is None or OPTIONS.output_target_files is None): common.Usage(__doc__) sys.exit(1) if OPTIONS.system_item_list: system_item_list = read_config_list(OPTIONS.system_item_list) else: system_item_list = default_system_item_list if OPTIONS.system_misc_info_keys: system_misc_info_keys = read_config_list(OPTIONS.system_misc_info_keys) else: system_misc_info_keys = default_system_misc_info_keys if OPTIONS.other_item_list: other_item_list = read_config_list(OPTIONS.other_item_list) else: other_item_list = default_other_item_list call_func_with_temp_dir( lambda temp_dir: merge_target_files( temp_dir=temp_dir, system_target_files=OPTIONS.system_target_files, system_item_list=system_item_list, system_misc_info_keys=system_misc_info_keys, other_target_files=OPTIONS.other_target_files, other_item_list=other_item_list, output_target_files=OPTIONS.output_target_files), OPTIONS.keep_tmp)
def main(): """The main function. Process command line arguments, then call merge_target_files to perform the heavy lifting. """ common.InitLogging() def option_handler(o, a): if o == '--system-target-files': logger.warning( '--system-target-files has been renamed to --framework-target-files' ) OPTIONS.framework_target_files = a elif o == '--framework-target-files': OPTIONS.framework_target_files = a elif o == '--system-item-list': logger.warning( '--system-item-list has been renamed to --framework-item-list') OPTIONS.framework_item_list = a elif o == '--framework-item-list': OPTIONS.framework_item_list = a elif o == '--system-misc-info-keys': logger.warning('--system-misc-info-keys has been renamed to ' '--framework-misc-info-keys') OPTIONS.framework_misc_info_keys = a elif o == '--framework-misc-info-keys': OPTIONS.framework_misc_info_keys = a elif o == '--other-target-files': logger.warning( '--other-target-files has been renamed to --vendor-target-files' ) OPTIONS.vendor_target_files = a elif o == '--vendor-target-files': OPTIONS.vendor_target_files = a elif o == '--other-item-list': logger.warning( '--other-item-list has been renamed to --vendor-item-list') OPTIONS.vendor_item_list = a elif o == '--vendor-item-list': OPTIONS.vendor_item_list = a elif o == '--output-target-files': OPTIONS.output_target_files = a elif o == '--output-dir': OPTIONS.output_dir = a elif o == '--output-item-list': OPTIONS.output_item_list = a elif o == '--output-ota': OPTIONS.output_ota = a elif o == '--output-img': OPTIONS.output_img = a elif o == '--output-super-empty': OPTIONS.output_super_empty = a elif o == '--rebuild_recovery': OPTIONS.rebuild_recovery = True elif o == '--keep-tmp': OPTIONS.keep_tmp = True else: return False return True args = common.ParseOptions(sys.argv[1:], __doc__, extra_long_opts=[ 'system-target-files=', 'framework-target-files=', 'system-item-list=', 'framework-item-list=', 'system-misc-info-keys=', 'framework-misc-info-keys=', 'other-target-files=', 'vendor-target-files=', 'other-item-list=', 'vendor-item-list=', 'output-target-files=', 'output-dir=', 'output-item-list=', 'output-ota=', 'output-img=', 'output-super-empty=', 'rebuild_recovery', 'keep-tmp', ], extra_option_handler=option_handler) # pylint: disable=too-many-boolean-expressions if (args or OPTIONS.framework_target_files is None or OPTIONS.vendor_target_files is None or (OPTIONS.output_target_files is None and OPTIONS.output_dir is None) or (OPTIONS.output_dir is not None and OPTIONS.output_item_list is None)): common.Usage(__doc__) sys.exit(1) # Always turn on verbose logging. OPTIONS.verbose = True if OPTIONS.framework_item_list: framework_item_list = common.LoadListFromFile( OPTIONS.framework_item_list) else: framework_item_list = DEFAULT_FRAMEWORK_ITEM_LIST if OPTIONS.framework_misc_info_keys: framework_misc_info_keys = common.LoadListFromFile( OPTIONS.framework_misc_info_keys) else: framework_misc_info_keys = DEFAULT_FRAMEWORK_MISC_INFO_KEYS if OPTIONS.vendor_item_list: vendor_item_list = common.LoadListFromFile(OPTIONS.vendor_item_list) else: vendor_item_list = DEFAULT_VENDOR_ITEM_LIST if OPTIONS.output_item_list: output_item_list = common.LoadListFromFile(OPTIONS.output_item_list) else: output_item_list = None if not validate_config_lists( framework_item_list=framework_item_list, framework_misc_info_keys=framework_misc_info_keys, vendor_item_list=vendor_item_list): sys.exit(1) call_func_with_temp_dir( lambda temp_dir: merge_target_files( temp_dir=temp_dir, framework_target_files=OPTIONS.framework_target_files, framework_item_list=framework_item_list, framework_misc_info_keys=framework_misc_info_keys, vendor_target_files=OPTIONS.vendor_target_files, vendor_item_list=vendor_item_list, output_target_files=OPTIONS.output_target_files, output_dir=OPTIONS.output_dir, output_item_list=output_item_list, output_ota=OPTIONS.output_ota, output_img=OPTIONS.output_img, output_super_empty=OPTIONS.output_super_empty, rebuild_recovery=OPTIONS.rebuild_recovery), OPTIONS.keep_tmp)
def main(argv): key_mapping_options = [] def option_handler(o, a): if o in ("-e", "--extra_apks"): names, key = a.split("=") names = names.split(",") for n in names: OPTIONS.extra_apks[n] = key elif o == "--extra_apex_payload_key": apex_name, key = a.split("=") OPTIONS.extra_apex_payload_keys[apex_name] = key elif o == "--skip_apks_with_path_prefix": # Sanity check the prefix, which must be in all upper case. prefix = a.split('/')[0] if not prefix or prefix != prefix.upper(): raise ValueError("Invalid path prefix '%s'" % (a,)) OPTIONS.skip_apks_with_path_prefix.add(a) elif o in ("-d", "--default_key_mappings"): key_mapping_options.append((None, a)) elif o in ("-k", "--key_mapping"): key_mapping_options.append(a.split("=", 1)) elif o in ("-o", "--replace_ota_keys"): OPTIONS.replace_ota_keys = True elif o in ("-t", "--tag_changes"): new = [] for i in a.split(","): i = i.strip() if not i or i[0] not in "-+": raise ValueError("Bad tag change '%s'" % (i,)) new.append(i[0] + i[1:].strip()) OPTIONS.tag_changes = tuple(new) elif o == "--replace_verity_public_key": OPTIONS.replace_verity_public_key = (True, a) elif o == "--replace_verity_private_key": OPTIONS.replace_verity_private_key = (True, a) elif o == "--replace_verity_keyid": OPTIONS.replace_verity_keyid = (True, a) elif o == "--avb_vbmeta_key": OPTIONS.avb_keys['vbmeta'] = a elif o == "--avb_vbmeta_algorithm": OPTIONS.avb_algorithms['vbmeta'] = a elif o == "--avb_vbmeta_extra_args": OPTIONS.avb_extra_args['vbmeta'] = a elif o == "--avb_boot_key": OPTIONS.avb_keys['boot'] = a elif o == "--avb_boot_algorithm": OPTIONS.avb_algorithms['boot'] = a elif o == "--avb_boot_extra_args": OPTIONS.avb_extra_args['boot'] = a elif o == "--avb_dtbo_key": OPTIONS.avb_keys['dtbo'] = a elif o == "--avb_dtbo_algorithm": OPTIONS.avb_algorithms['dtbo'] = a elif o == "--avb_dtbo_extra_args": OPTIONS.avb_extra_args['dtbo'] = a elif o == "--avb_system_key": OPTIONS.avb_keys['system'] = a elif o == "--avb_system_algorithm": OPTIONS.avb_algorithms['system'] = a elif o == "--avb_system_extra_args": OPTIONS.avb_extra_args['system'] = a elif o == "--avb_system_other_key": OPTIONS.avb_keys['system_other'] = a elif o == "--avb_system_other_algorithm": OPTIONS.avb_algorithms['system_other'] = a elif o == "--avb_system_other_extra_args": OPTIONS.avb_extra_args['system_other'] = a elif o == "--avb_vendor_key": OPTIONS.avb_keys['vendor'] = a elif o == "--avb_vendor_algorithm": OPTIONS.avb_algorithms['vendor'] = a elif o == "--avb_vendor_extra_args": OPTIONS.avb_extra_args['vendor'] = a elif o == "--avb_vbmeta_system_key": OPTIONS.avb_keys['vbmeta_system'] = a elif o == "--avb_vbmeta_system_algorithm": OPTIONS.avb_algorithms['vbmeta_system'] = a elif o == "--avb_vbmeta_system_extra_args": OPTIONS.avb_extra_args['vbmeta_system'] = a elif o == "--avb_vbmeta_vendor_key": OPTIONS.avb_keys['vbmeta_vendor'] = a elif o == "--avb_vbmeta_vendor_algorithm": OPTIONS.avb_algorithms['vbmeta_vendor'] = a elif o == "--avb_vbmeta_vendor_extra_args": OPTIONS.avb_extra_args['vbmeta_vendor'] = a elif o == "--avb_apex_extra_args": OPTIONS.avb_extra_args['apex'] = a else: return False return True args = common.ParseOptions( argv, __doc__, extra_opts="e:d:k:ot:", extra_long_opts=[ "extra_apks=", "extra_apex_payload_key=", "skip_apks_with_path_prefix=", "default_key_mappings=", "key_mapping=", "replace_ota_keys", "tag_changes=", "replace_verity_public_key=", "replace_verity_private_key=", "replace_verity_keyid=", "avb_apex_extra_args=", "avb_vbmeta_algorithm=", "avb_vbmeta_key=", "avb_vbmeta_extra_args=", "avb_boot_algorithm=", "avb_boot_key=", "avb_boot_extra_args=", "avb_dtbo_algorithm=", "avb_dtbo_key=", "avb_dtbo_extra_args=", "avb_system_algorithm=", "avb_system_key=", "avb_system_extra_args=", "avb_system_other_algorithm=", "avb_system_other_key=", "avb_system_other_extra_args=", "avb_vendor_algorithm=", "avb_vendor_key=", "avb_vendor_extra_args=", "avb_vbmeta_system_algorithm=", "avb_vbmeta_system_key=", "avb_vbmeta_system_extra_args=", "avb_vbmeta_vendor_algorithm=", "avb_vbmeta_vendor_key=", "avb_vbmeta_vendor_extra_args=", ], extra_option_handler=option_handler) if len(args) != 2: common.Usage(__doc__) sys.exit(1) common.InitLogging() input_zip = zipfile.ZipFile(args[0], "r") output_zip = zipfile.ZipFile(args[1], "w", compression=zipfile.ZIP_DEFLATED, allowZip64=True) misc_info = common.LoadInfoDict(input_zip) BuildKeyMap(misc_info, key_mapping_options) apk_keys_info, compressed_extension = common.ReadApkCerts(input_zip) apk_keys = GetApkCerts(apk_keys_info) apex_keys_info = ReadApexKeysInfo(input_zip) apex_keys = GetApexKeys(apex_keys_info, apk_keys) CheckApkAndApexKeysAvailable( input_zip, set(apk_keys.keys()) | set(apex_keys.keys()), compressed_extension, apex_keys) key_passwords = common.GetKeyPasswords( set(apk_keys.values()) | set(itertools.chain(*apex_keys.values()))) platform_api_level, _ = GetApiLevelAndCodename(input_zip) codename_to_api_level_map = GetCodenameToApiLevelMap(input_zip) ProcessTargetFiles(input_zip, output_zip, misc_info, apk_keys, apex_keys, key_passwords, platform_api_level, codename_to_api_level_map, compressed_extension) common.ZipClose(input_zip) common.ZipClose(output_zip) # Skip building userdata.img and cache.img when signing the target files. new_args = ["--is_signing"] # add_img_to_target_files builds the system image from scratch, so the # recovery patch is guaranteed to be regenerated there. if OPTIONS.rebuild_recovery: new_args.append("--rebuild_recovery") new_args.append(args[1]) add_img_to_target_files.main(new_args) print("done.")
def main(argv): def option_handler(o, a): if o in ("-k", "--package_key"): OPTIONS.package_key = a elif o in ("-i", "--incremental_from"): OPTIONS.incremental_source = a elif o == "--full_radio": OPTIONS.full_radio = True elif o == "--full_bootloader": OPTIONS.full_bootloader = True elif o == "--wipe_user_data": OPTIONS.wipe_user_data = True elif o == "--downgrade": OPTIONS.downgrade = True OPTIONS.wipe_user_data = True elif o == "--override_timestamp": OPTIONS.downgrade = True elif o in ("-o", "--oem_settings"): OPTIONS.oem_source = a.split(',') elif o == "--oem_no_mount": OPTIONS.oem_no_mount = True elif o in ("-e", "--extra_script"): OPTIONS.extra_script = a elif o in ("-t", "--worker_threads"): if a.isdigit(): OPTIONS.worker_threads = int(a) else: raise ValueError("Cannot parse value %r for option %r - only " "integers are allowed." % (a, o)) elif o in ("-2", "--two_step"): OPTIONS.two_step = True elif o == "--include_secondary": OPTIONS.include_secondary = True elif o == "--no_signing": OPTIONS.no_signing = True elif o == "--verify": OPTIONS.verify = True elif o == "--block": OPTIONS.block_based = True elif o in ("-b", "--binary"): OPTIONS.updater_binary = a elif o == "--stash_threshold": try: OPTIONS.stash_threshold = float(a) except ValueError: raise ValueError( "Cannot parse value %r for option %r - expecting " "a float" % (a, o)) elif o == "--log_diff": OPTIONS.log_diff = a elif o == "--payload_signer": OPTIONS.payload_signer = a elif o == "--payload_signer_args": OPTIONS.payload_signer_args = shlex.split(a) elif o == "--payload_signer_maximum_signature_size": OPTIONS.payload_signer_maximum_signature_size = a elif o == "--payload_signer_key_size": # TODO(Xunchang) remove this option after cleaning up the callers. logger.warning( "The option '--payload_signer_key_size' is deprecated." " Use '--payload_signer_maximum_signature_size' instead.") OPTIONS.payload_signer_maximum_signature_size = a elif o == "--extracted_input_target_files": OPTIONS.extracted_input = a elif o == "--skip_postinstall": OPTIONS.skip_postinstall = True elif o == "--retrofit_dynamic_partitions": OPTIONS.retrofit_dynamic_partitions = True elif o == "--skip_compatibility_check": OPTIONS.skip_compatibility_check = True elif o == "--output_metadata_path": OPTIONS.output_metadata_path = a elif o == "--disable_fec_computation": OPTIONS.disable_fec_computation = True elif o == "--force_non_ab": OPTIONS.force_non_ab = True elif o == "--boot_variable_file": OPTIONS.boot_variable_file = a else: return False return True args = common.ParseOptions(argv, __doc__, extra_opts="b:k:i:d:e:t:2o:", extra_long_opts=[ "package_key=", "incremental_from=", "full_radio", "full_bootloader", "wipe_user_data", "downgrade", "override_timestamp", "extra_script=", "worker_threads=", "two_step", "include_secondary", "no_signing", "block", "binary=", "oem_settings=", "oem_no_mount", "verify", "stash_threshold=", "log_diff=", "payload_signer=", "payload_signer_args=", "payload_signer_maximum_signature_size=", "payload_signer_key_size=", "extracted_input_target_files=", "skip_postinstall", "retrofit_dynamic_partitions", "skip_compatibility_check", "output_metadata_path=", "disable_fec_computation", "force_non_ab", "boot_variable_file=", ], extra_option_handler=option_handler) if len(args) != 2: common.Usage(__doc__) sys.exit(1) common.InitLogging() if OPTIONS.downgrade: # We should only allow downgrading incrementals (as opposed to full). # Otherwise the device may go back from arbitrary build with this full # OTA package. if OPTIONS.incremental_source is None: raise ValueError("Cannot generate downgradable full OTAs") # Load the build info dicts from the zip directly or the extracted input # directory. We don't need to unzip the entire target-files zips, because they # won't be needed for A/B OTAs (brillo_update_payload does that on its own). # When loading the info dicts, we don't need to provide the second parameter # to common.LoadInfoDict(). Specifying the second parameter allows replacing # some properties with their actual paths, such as 'selinux_fc', # 'ramdisk_dir', which won't be used during OTA generation. if OPTIONS.extracted_input is not None: OPTIONS.info_dict = common.LoadInfoDict(OPTIONS.extracted_input) else: with zipfile.ZipFile(args[0], 'r') as input_zip: OPTIONS.info_dict = common.LoadInfoDict(input_zip) logger.info("--- target info ---") common.DumpInfoDict(OPTIONS.info_dict) # Load the source build dict if applicable. if OPTIONS.incremental_source is not None: OPTIONS.target_info_dict = OPTIONS.info_dict with zipfile.ZipFile(OPTIONS.incremental_source, 'r') as source_zip: OPTIONS.source_info_dict = common.LoadInfoDict(source_zip) logger.info("--- source info ---") common.DumpInfoDict(OPTIONS.source_info_dict) # Load OEM dicts if provided. OPTIONS.oem_dicts = _LoadOemDicts(OPTIONS.oem_source) # Assume retrofitting dynamic partitions when base build does not set # use_dynamic_partitions but target build does. if (OPTIONS.source_info_dict and OPTIONS.source_info_dict.get("use_dynamic_partitions") != "true" and OPTIONS.target_info_dict.get("use_dynamic_partitions") == "true"): if OPTIONS.target_info_dict.get( "dynamic_partition_retrofit") != "true": raise common.ExternalError( "Expect to generate incremental OTA for retrofitting dynamic " "partitions, but dynamic_partition_retrofit is not set in target " "build.") logger.info("Implicitly generating retrofit incremental OTA.") OPTIONS.retrofit_dynamic_partitions = True # Skip postinstall for retrofitting dynamic partitions. if OPTIONS.retrofit_dynamic_partitions: OPTIONS.skip_postinstall = True ab_update = OPTIONS.info_dict.get("ab_update") == "true" allow_non_ab = OPTIONS.info_dict.get("allow_non_ab") == "true" if OPTIONS.force_non_ab: assert allow_non_ab, "--force_non_ab only allowed on devices that supports non-A/B" assert ab_update, "--force_non_ab only allowed on A/B devices" generate_ab = not OPTIONS.force_non_ab and ab_update # Use the default key to sign the package if not specified with package_key. # package_keys are needed on ab_updates, so always define them if an # A/B update is getting created. if not OPTIONS.no_signing or generate_ab: if OPTIONS.package_key is None: OPTIONS.package_key = OPTIONS.info_dict.get( "default_system_dev_certificate", "build/make/target/product/security/testkey") # Get signing keys OPTIONS.key_passwords = common.GetKeyPasswords([OPTIONS.package_key]) if generate_ab: GenerateAbOtaPackage(target_file=args[0], output_file=args[1], source_file=OPTIONS.incremental_source) else: GenerateNonAbOtaPackage(target_file=args[0], output_file=args[1], source_file=OPTIONS.incremental_source) # Post OTA generation works. if OPTIONS.incremental_source is not None and OPTIONS.log_diff: logger.info("Generating diff logs...") logger.info("Unzipping target-files for diffing...") target_dir = common.UnzipTemp(args[0], TARGET_DIFFING_UNZIP_PATTERN) source_dir = common.UnzipTemp(OPTIONS.incremental_source, TARGET_DIFFING_UNZIP_PATTERN) with open(OPTIONS.log_diff, 'w') as out_file: target_files_diff.recursiveDiff('', source_dir, target_dir, out_file) logger.info("done.")
def main(): """The main function. Process command line arguments, then call merge_target_files to perform the heavy lifting. """ common.InitLogging() def option_handler(o, a): if o == '--system-target-files': OPTIONS.system_target_files = a elif o == '--system-item-list': OPTIONS.system_item_list = a elif o == '--system-misc-info-keys': OPTIONS.system_misc_info_keys = a elif o == '--other-target-files': OPTIONS.other_target_files = a elif o == '--other-item-list': OPTIONS.other_item_list = a elif o == '--output-target-files': OPTIONS.output_target_files = a elif o == '--output-dir': OPTIONS.output_dir = a elif o == '--output-item-list': OPTIONS.output_item_list = a elif o == '--output-ota': OPTIONS.output_ota = a elif o == '--output-img': OPTIONS.output_img = a elif o == '--output-super-empty': OPTIONS.output_super_empty = a elif o == '--rebuild_recovery': OPTIONS.rebuild_recovery = True elif o == '--keep-tmp': OPTIONS.keep_tmp = True else: return False return True args = common.ParseOptions(sys.argv[1:], __doc__, extra_long_opts=[ 'system-target-files=', 'system-item-list=', 'system-misc-info-keys=', 'other-target-files=', 'other-item-list=', 'output-target-files=', 'output-dir=', 'output-item-list=', 'output-ota=', 'output-img=', 'output-super-empty=', 'rebuild_recovery', 'keep-tmp', ], extra_option_handler=option_handler) if (args or OPTIONS.system_target_files is None or OPTIONS.other_target_files is None or (OPTIONS.output_target_files is None and OPTIONS.output_dir is None) or (OPTIONS.output_dir is not None and OPTIONS.output_item_list is None)): common.Usage(__doc__) sys.exit(1) if OPTIONS.system_item_list: system_item_list = read_config_list(OPTIONS.system_item_list) else: system_item_list = default_system_item_list if OPTIONS.system_misc_info_keys: system_misc_info_keys = read_config_list(OPTIONS.system_misc_info_keys) else: system_misc_info_keys = default_system_misc_info_keys if OPTIONS.other_item_list: other_item_list = read_config_list(OPTIONS.other_item_list) else: other_item_list = default_other_item_list if OPTIONS.output_item_list: output_item_list = read_config_list(OPTIONS.output_item_list) else: output_item_list = None if not validate_config_lists(system_item_list=system_item_list, system_misc_info_keys=system_misc_info_keys, other_item_list=other_item_list): sys.exit(1) call_func_with_temp_dir( lambda temp_dir: merge_target_files( temp_dir=temp_dir, system_target_files=OPTIONS.system_target_files, system_item_list=system_item_list, system_misc_info_keys=system_misc_info_keys, other_target_files=OPTIONS.other_target_files, other_item_list=other_item_list, output_target_files=OPTIONS.output_target_files, output_dir=OPTIONS.output_dir, output_item_list=output_item_list, output_ota=OPTIONS.output_ota, output_img=OPTIONS.output_img, output_super_empty=OPTIONS.output_super_empty, rebuild_recovery=OPTIONS.rebuild_recovery), OPTIONS.keep_tmp)