Loading tools/releasetools/common.py +41 −19 Original line number Diff line number Diff line Loading @@ -138,6 +138,7 @@ PARTITIONS_WITH_BUILD_PROP = PARTITIONS_WITH_CARE_MAP + ['boot'] # existing search paths. RAMDISK_BUILD_PROP_REL_PATHS = ['system/etc/ramdisk/build.prop'] class ErrorCode(object): """Define error_codes for failures that happen during the actual update package installation. Loading Loading @@ -226,6 +227,7 @@ def InitLogging(): def SetHostToolLocation(tool_name, location): OPTIONS.host_tools[tool_name] = location def FindHostToolPath(tool_name): """Finds the path to the host tool. Loading @@ -246,6 +248,7 @@ def FindHostToolPath(tool_name): return tool_name def Run(args, verbose=None, **kwargs): """Creates and returns a subprocess.Popen object. Loading Loading @@ -433,6 +436,13 @@ class BuildInfo(object): def fingerprint(self): return self._fingerprint @property def is_vabc(self): vendor_prop = self.info_dict.get("vendor.build.prop") vabc_enabled = vendor_prop and \ vendor_prop.GetProp("ro.virtual_ab.compression.enabled") == "true" return vabc_enabled @property def oem_props(self): return self._oem_props Loading Loading @@ -652,10 +662,12 @@ def ExtractFromInputFile(input_file, fn): raise KeyError(fn) return file class RamdiskFormat(object): LZ4 = 1 GZ = 2 def _GetRamdiskFormat(info_dict): if info_dict.get('lz4_ramdisks') == 'true': ramdisk_format = RamdiskFormat.LZ4 Loading @@ -663,6 +675,7 @@ def _GetRamdiskFormat(info_dict): ramdisk_format = RamdiskFormat.GZ return ramdisk_format def LoadInfoDict(input_file, repacking=False): """Loads the key/value pairs from the given input target_files. Loading Loading @@ -781,7 +794,8 @@ def LoadInfoDict(input_file, repacking=False): for partition in PARTITIONS_WITH_BUILD_PROP: fingerprint = build_info.GetPartitionFingerprint(partition) if fingerprint: d["avb_{}_salt".format(partition)] = sha256(fingerprint.encode()).hexdigest() d["avb_{}_salt".format(partition)] = sha256( fingerprint.encode()).hexdigest() try: d["ab_partitions"] = read_helper("META/ab_partitions.txt").split("\n") except KeyError: Loading @@ -789,7 +803,6 @@ def LoadInfoDict(input_file, repacking=False): return d def LoadListFromFile(file_path): with open(file_path) as f: return f.read().splitlines() Loading Loading @@ -859,7 +872,8 @@ class PartitionBuildProps(object): """Loads the build.prop file and builds the attributes.""" if name == "boot": data = PartitionBuildProps._ReadBootPropFile(input_file, ramdisk_format=ramdisk_format) data = PartitionBuildProps._ReadBootPropFile( input_file, ramdisk_format=ramdisk_format) else: data = PartitionBuildProps._ReadPartitionPropFile(input_file, name) Loading Loading @@ -1371,7 +1385,8 @@ def AppendGkiSigningArgs(cmd): # Checks key_path exists, before appending --gki_signing_* args. if not os.path.exists(key_path): raise ExternalError('gki_signing_key_path: "{}" not found'.format(key_path)) raise ExternalError( 'gki_signing_key_path: "{}" not found'.format(key_path)) algorithm = OPTIONS.info_dict.get("gki_signing_algorithm") if key_path and algorithm: Loading Loading @@ -1753,14 +1768,17 @@ def _BuildVendorBootImage(sourcedir, info_dict=None): if os.access(fn, os.F_OK): ramdisk_fragments = shlex.split(open(fn).read().rstrip("\n")) for ramdisk_fragment in ramdisk_fragments: fn = os.path.join(sourcedir, "RAMDISK_FRAGMENTS", ramdisk_fragment, "mkbootimg_args") fn = os.path.join(sourcedir, "RAMDISK_FRAGMENTS", ramdisk_fragment, "mkbootimg_args") cmd.extend(shlex.split(open(fn).read().rstrip("\n"))) fn = os.path.join(sourcedir, "RAMDISK_FRAGMENTS", ramdisk_fragment, "prebuilt_ramdisk") fn = os.path.join(sourcedir, "RAMDISK_FRAGMENTS", ramdisk_fragment, "prebuilt_ramdisk") # Use prebuilt image if found, else create ramdisk from supplied files. if os.access(fn, os.F_OK): ramdisk_fragment_pathname = fn else: ramdisk_fragment_root = os.path.join(sourcedir, "RAMDISK_FRAGMENTS", ramdisk_fragment) ramdisk_fragment_root = os.path.join( sourcedir, "RAMDISK_FRAGMENTS", ramdisk_fragment) ramdisk_fragment_img = _MakeRamdisk(ramdisk_fragment_root, ramdisk_format=ramdisk_format) ramdisk_fragment_imgs.append(ramdisk_fragment_img) Loading Loading @@ -3693,7 +3711,8 @@ def GetBootImageBuildProp(boot_img, ramdisk_format=RamdiskFormat.LZ4): """ tmp_dir = MakeTempDir('boot_', suffix='.img') try: RunAndCheckOutput(['unpack_bootimg', '--boot_img', boot_img, '--out', tmp_dir]) RunAndCheckOutput(['unpack_bootimg', '--boot_img', boot_img, '--out', tmp_dir]) ramdisk = os.path.join(tmp_dir, 'ramdisk') if not os.path.isfile(ramdisk): logger.warning('Unable to get boot image timestamp: no ramdisk in boot') Loading @@ -3704,7 +3723,8 @@ def GetBootImageBuildProp(boot_img, ramdisk_format=RamdiskFormat.LZ4): elif ramdisk_format == RamdiskFormat.GZ: with open(ramdisk, 'rb') as input_stream: with open(uncompressed_ramdisk, 'wb') as output_stream: p2 = Run(['minigzip', '-d'], stdin=input_stream.fileno(), stdout=output_stream.fileno()) p2 = Run(['minigzip', '-d'], stdin=input_stream.fileno(), stdout=output_stream.fileno()) p2.wait() else: logger.error('Only support lz4 or minigzip ramdisk format.') Loading @@ -3721,7 +3741,8 @@ def GetBootImageBuildProp(boot_img, ramdisk_format=RamdiskFormat.LZ4): prop_file = os.path.join(extracted_ramdisk, search_path) if os.path.isfile(prop_file): return prop_file logger.warning('Unable to get boot image timestamp: no %s in ramdisk', search_path) logger.warning( 'Unable to get boot image timestamp: no %s in ramdisk', search_path) return None Loading Loading @@ -3754,7 +3775,8 @@ def GetBootImageTimestamp(boot_img): timestamp = props.GetProp('ro.bootimage.build.date.utc') if timestamp: return int(timestamp) logger.warning('Unable to get boot image timestamp: ro.bootimage.build.date.utc is undefined') logger.warning( 'Unable to get boot image timestamp: ro.bootimage.build.date.utc is undefined') return None except ExternalError as e: Loading tools/releasetools/ota_from_target_files.py +8 −5 Original line number Diff line number Diff line Loading @@ -1051,15 +1051,18 @@ def GenerateAbOtaPackage(target_file, output_file, source_file=None): "META/ab_partitions.txt is required for ab_update." target_info = common.BuildInfo(OPTIONS.target_info_dict, OPTIONS.oem_dicts) source_info = common.BuildInfo(OPTIONS.source_info_dict, OPTIONS.oem_dicts) vendor_prop = source_info.info_dict.get("vendor.build.prop") vabc_used = vendor_prop and \ vendor_prop.GetProp("ro.virtual_ab.compression.enabled") == "true" and \ not OPTIONS.disable_vabc if vabc_used: # If source supports VABC, delta_generator/update_engine will attempt to # use VABC. This dangerous, as the target build won't have snapuserd to # serve I/O request when device boots. Therefore, disable VABC if source # build doesn't supports it. if not source_info.is_vabc or not target_info.is_vabc: OPTIONS.disable_vabc = True if not OPTIONS.disable_vabc: # TODO(zhangkelvin) Remove this once FEC on VABC is supported logger.info("Virtual AB Compression enabled, disabling FEC") OPTIONS.disable_fec_computation = True OPTIONS.disable_verity_computation = True else: assert "ab_partitions" in OPTIONS.info_dict, \ "META/ab_partitions.txt is required for ab_update." Loading Loading
tools/releasetools/common.py +41 −19 Original line number Diff line number Diff line Loading @@ -138,6 +138,7 @@ PARTITIONS_WITH_BUILD_PROP = PARTITIONS_WITH_CARE_MAP + ['boot'] # existing search paths. RAMDISK_BUILD_PROP_REL_PATHS = ['system/etc/ramdisk/build.prop'] class ErrorCode(object): """Define error_codes for failures that happen during the actual update package installation. Loading Loading @@ -226,6 +227,7 @@ def InitLogging(): def SetHostToolLocation(tool_name, location): OPTIONS.host_tools[tool_name] = location def FindHostToolPath(tool_name): """Finds the path to the host tool. Loading @@ -246,6 +248,7 @@ def FindHostToolPath(tool_name): return tool_name def Run(args, verbose=None, **kwargs): """Creates and returns a subprocess.Popen object. Loading Loading @@ -433,6 +436,13 @@ class BuildInfo(object): def fingerprint(self): return self._fingerprint @property def is_vabc(self): vendor_prop = self.info_dict.get("vendor.build.prop") vabc_enabled = vendor_prop and \ vendor_prop.GetProp("ro.virtual_ab.compression.enabled") == "true" return vabc_enabled @property def oem_props(self): return self._oem_props Loading Loading @@ -652,10 +662,12 @@ def ExtractFromInputFile(input_file, fn): raise KeyError(fn) return file class RamdiskFormat(object): LZ4 = 1 GZ = 2 def _GetRamdiskFormat(info_dict): if info_dict.get('lz4_ramdisks') == 'true': ramdisk_format = RamdiskFormat.LZ4 Loading @@ -663,6 +675,7 @@ def _GetRamdiskFormat(info_dict): ramdisk_format = RamdiskFormat.GZ return ramdisk_format def LoadInfoDict(input_file, repacking=False): """Loads the key/value pairs from the given input target_files. Loading Loading @@ -781,7 +794,8 @@ def LoadInfoDict(input_file, repacking=False): for partition in PARTITIONS_WITH_BUILD_PROP: fingerprint = build_info.GetPartitionFingerprint(partition) if fingerprint: d["avb_{}_salt".format(partition)] = sha256(fingerprint.encode()).hexdigest() d["avb_{}_salt".format(partition)] = sha256( fingerprint.encode()).hexdigest() try: d["ab_partitions"] = read_helper("META/ab_partitions.txt").split("\n") except KeyError: Loading @@ -789,7 +803,6 @@ def LoadInfoDict(input_file, repacking=False): return d def LoadListFromFile(file_path): with open(file_path) as f: return f.read().splitlines() Loading Loading @@ -859,7 +872,8 @@ class PartitionBuildProps(object): """Loads the build.prop file and builds the attributes.""" if name == "boot": data = PartitionBuildProps._ReadBootPropFile(input_file, ramdisk_format=ramdisk_format) data = PartitionBuildProps._ReadBootPropFile( input_file, ramdisk_format=ramdisk_format) else: data = PartitionBuildProps._ReadPartitionPropFile(input_file, name) Loading Loading @@ -1371,7 +1385,8 @@ def AppendGkiSigningArgs(cmd): # Checks key_path exists, before appending --gki_signing_* args. if not os.path.exists(key_path): raise ExternalError('gki_signing_key_path: "{}" not found'.format(key_path)) raise ExternalError( 'gki_signing_key_path: "{}" not found'.format(key_path)) algorithm = OPTIONS.info_dict.get("gki_signing_algorithm") if key_path and algorithm: Loading Loading @@ -1753,14 +1768,17 @@ def _BuildVendorBootImage(sourcedir, info_dict=None): if os.access(fn, os.F_OK): ramdisk_fragments = shlex.split(open(fn).read().rstrip("\n")) for ramdisk_fragment in ramdisk_fragments: fn = os.path.join(sourcedir, "RAMDISK_FRAGMENTS", ramdisk_fragment, "mkbootimg_args") fn = os.path.join(sourcedir, "RAMDISK_FRAGMENTS", ramdisk_fragment, "mkbootimg_args") cmd.extend(shlex.split(open(fn).read().rstrip("\n"))) fn = os.path.join(sourcedir, "RAMDISK_FRAGMENTS", ramdisk_fragment, "prebuilt_ramdisk") fn = os.path.join(sourcedir, "RAMDISK_FRAGMENTS", ramdisk_fragment, "prebuilt_ramdisk") # Use prebuilt image if found, else create ramdisk from supplied files. if os.access(fn, os.F_OK): ramdisk_fragment_pathname = fn else: ramdisk_fragment_root = os.path.join(sourcedir, "RAMDISK_FRAGMENTS", ramdisk_fragment) ramdisk_fragment_root = os.path.join( sourcedir, "RAMDISK_FRAGMENTS", ramdisk_fragment) ramdisk_fragment_img = _MakeRamdisk(ramdisk_fragment_root, ramdisk_format=ramdisk_format) ramdisk_fragment_imgs.append(ramdisk_fragment_img) Loading Loading @@ -3693,7 +3711,8 @@ def GetBootImageBuildProp(boot_img, ramdisk_format=RamdiskFormat.LZ4): """ tmp_dir = MakeTempDir('boot_', suffix='.img') try: RunAndCheckOutput(['unpack_bootimg', '--boot_img', boot_img, '--out', tmp_dir]) RunAndCheckOutput(['unpack_bootimg', '--boot_img', boot_img, '--out', tmp_dir]) ramdisk = os.path.join(tmp_dir, 'ramdisk') if not os.path.isfile(ramdisk): logger.warning('Unable to get boot image timestamp: no ramdisk in boot') Loading @@ -3704,7 +3723,8 @@ def GetBootImageBuildProp(boot_img, ramdisk_format=RamdiskFormat.LZ4): elif ramdisk_format == RamdiskFormat.GZ: with open(ramdisk, 'rb') as input_stream: with open(uncompressed_ramdisk, 'wb') as output_stream: p2 = Run(['minigzip', '-d'], stdin=input_stream.fileno(), stdout=output_stream.fileno()) p2 = Run(['minigzip', '-d'], stdin=input_stream.fileno(), stdout=output_stream.fileno()) p2.wait() else: logger.error('Only support lz4 or minigzip ramdisk format.') Loading @@ -3721,7 +3741,8 @@ def GetBootImageBuildProp(boot_img, ramdisk_format=RamdiskFormat.LZ4): prop_file = os.path.join(extracted_ramdisk, search_path) if os.path.isfile(prop_file): return prop_file logger.warning('Unable to get boot image timestamp: no %s in ramdisk', search_path) logger.warning( 'Unable to get boot image timestamp: no %s in ramdisk', search_path) return None Loading Loading @@ -3754,7 +3775,8 @@ def GetBootImageTimestamp(boot_img): timestamp = props.GetProp('ro.bootimage.build.date.utc') if timestamp: return int(timestamp) logger.warning('Unable to get boot image timestamp: ro.bootimage.build.date.utc is undefined') logger.warning( 'Unable to get boot image timestamp: ro.bootimage.build.date.utc is undefined') return None except ExternalError as e: Loading
tools/releasetools/ota_from_target_files.py +8 −5 Original line number Diff line number Diff line Loading @@ -1051,15 +1051,18 @@ def GenerateAbOtaPackage(target_file, output_file, source_file=None): "META/ab_partitions.txt is required for ab_update." target_info = common.BuildInfo(OPTIONS.target_info_dict, OPTIONS.oem_dicts) source_info = common.BuildInfo(OPTIONS.source_info_dict, OPTIONS.oem_dicts) vendor_prop = source_info.info_dict.get("vendor.build.prop") vabc_used = vendor_prop and \ vendor_prop.GetProp("ro.virtual_ab.compression.enabled") == "true" and \ not OPTIONS.disable_vabc if vabc_used: # If source supports VABC, delta_generator/update_engine will attempt to # use VABC. This dangerous, as the target build won't have snapuserd to # serve I/O request when device boots. Therefore, disable VABC if source # build doesn't supports it. if not source_info.is_vabc or not target_info.is_vabc: OPTIONS.disable_vabc = True if not OPTIONS.disable_vabc: # TODO(zhangkelvin) Remove this once FEC on VABC is supported logger.info("Virtual AB Compression enabled, disabling FEC") OPTIONS.disable_fec_computation = True OPTIONS.disable_verity_computation = True else: assert "ab_partitions" in OPTIONS.info_dict, \ "META/ab_partitions.txt is required for ab_update." Loading