def GetIncrementalBlockDifferenceForPartition(name): if not HasPartition(source_zip, name): raise RuntimeError( "can't generate incremental that adds {}".format(name)) partition_src = common.GetUserImage(name, OPTIONS.source_tmp, source_zip, info_dict=source_info, allow_shared_blocks=allow_shared_blocks) hashtree_info_generator = verity_utils.CreateHashtreeInfoGenerator( name, 4096, target_info) partition_tgt = common.GetUserImage(name, OPTIONS.target_tmp, target_zip, info_dict=target_info, allow_shared_blocks=allow_shared_blocks, hashtree_info_generator=hashtree_info_generator) # Check the first block of the source system partition for remount R/W only # if the filesystem is ext4. partition_source_info = source_info["fstab"]["/" + name] check_first_block = partition_source_info.fs_type == "ext4" # Disable using imgdiff for squashfs. 'imgdiff -z' expects input files to be # in zip formats. However with squashfs, a) all files are compressed in LZ4; # b) the blocks listed in block map may not contain all the bytes for a # given file (because they're rounded to be 4K-aligned). partition_target_info = target_info["fstab"]["/" + name] disable_imgdiff = (partition_source_info.fs_type == "squashfs" or partition_target_info.fs_type == "squashfs") return common.BlockDifference(name, partition_tgt, partition_src, check_first_block, version=blockimgdiff_version, disable_imgdiff=disable_imgdiff)
def BuildCustomerImage(info): print "amlogic extensions:BuildCustomerImage" if info.info_dict.get("update_user_parts") == "true": partsList = info.info_dict.get("user_parts_list") for list_i in partsList.split(' '): tmp_tgt = GetImage(list_i, info.input_tmp, info.info_dict) tmp_tgt.ResetFileMap() tmp_diff = common.BlockDifference(list_i, tmp_tgt, src=None) tmp_diff.WriteScript(info.script, info.output_zip)
def WriteIncrementalModemPartition(info, target_modem_image, source_modem_image): tf = target_modem_image sf = source_modem_image b = common.BlockDifference("modem", common.DataImage(tf.data), common.DataImage(sf.data)) b.WriteScript(info.script, info.output_zip)
def IncrementalOTA_GetBlockDifferences(info): source_images = GetUserImages(info.source_tmp, info.source_zip) target_images = GetUserImages(info.target_tmp, info.target_zip) # Use EmptyImage() as a placeholder for partitions that will be deleted. for partition in source_images: target_images.setdefault(partition, common.EmptyImage()) # Use source_images.get() because new partitions are not in source_images. return [ common.BlockDifference(partition, target_image, source_images.get(partition)) for partition, target_image in target_images.items() ]
def WriteIncrementalModemPartition(info, target_modem_image, source_modem_image): tf = target_modem_image sf = source_modem_image pad_tf = False pad_sf = False blocksize = 4096 partial_tf = len(tf.data) % blocksize partial_sf = len(sf.data) % blocksize if partial_tf: pad_tf = True if partial_sf: pad_sf = True b = common.BlockDifference("modem", common.DataImage(tf.data,False, pad_tf), common.DataImage(sf.data,False, pad_sf)) b.WriteScript(info.script, info.output_zip)
def GetBlockDifferences(target_zip, source_zip, target_info, source_info, device_specific): """Returns a ordered dict of block differences with partition name as key.""" def GetIncrementalBlockDifferenceForPartition(name): if not HasPartition(source_zip, name): raise RuntimeError( "can't generate incremental that adds {}".format(name)) partition_src = common.GetUserImage(name, OPTIONS.source_tmp, source_zip, info_dict=source_info, allow_shared_blocks=allow_shared_blocks) hashtree_info_generator = verity_utils.CreateHashtreeInfoGenerator( name, 4096, target_info) partition_tgt = common.GetUserImage(name, OPTIONS.target_tmp, target_zip, info_dict=target_info, allow_shared_blocks=allow_shared_blocks, hashtree_info_generator=hashtree_info_generator) # Check the first block of the source system partition for remount R/W only # if the filesystem is ext4. partition_source_info = source_info["fstab"]["/" + name] check_first_block = partition_source_info.fs_type == "ext4" # Disable using imgdiff for squashfs. 'imgdiff -z' expects input files to be # in zip formats. However with squashfs, a) all files are compressed in LZ4; # b) the blocks listed in block map may not contain all the bytes for a # given file (because they're rounded to be 4K-aligned). partition_target_info = target_info["fstab"]["/" + name] disable_imgdiff = (partition_source_info.fs_type == "squashfs" or partition_target_info.fs_type == "squashfs") return common.BlockDifference(name, partition_tgt, partition_src, check_first_block, version=blockimgdiff_version, disable_imgdiff=disable_imgdiff) if source_zip: # See notes in common.GetUserImage() allow_shared_blocks = (source_info.get('ext4_share_dup_blocks') == "true" or target_info.get('ext4_share_dup_blocks') == "true") blockimgdiff_version = max( int(i) for i in target_info.get( "blockimgdiff_versions", "1").split(",")) assert blockimgdiff_version >= 3 block_diff_dict = collections.OrderedDict() partition_names = ["system", "vendor", "product", "odm", "system_ext", "vendor_dlkm", "odm_dlkm"] for partition in partition_names: if not HasPartition(target_zip, partition): continue # Full OTA update. if not source_zip: tgt = common.GetUserImage(partition, OPTIONS.input_tmp, target_zip, info_dict=target_info, reset_file_map=True) block_diff_dict[partition] = common.BlockDifference(partition, tgt, src=None) # Incremental OTA update. else: block_diff_dict[partition] = GetIncrementalBlockDifferenceForPartition( partition) assert "system" in block_diff_dict # Get the block diffs from the device specific script. If there is a # duplicate block diff for a partition, ignore the diff in the generic script # and use the one in the device specific script instead. if source_zip: device_specific_diffs = device_specific.IncrementalOTA_GetBlockDifferences() function_name = "IncrementalOTA_GetBlockDifferences" else: device_specific_diffs = device_specific.FullOTA_GetBlockDifferences() function_name = "FullOTA_GetBlockDifferences" if device_specific_diffs: assert all(isinstance(diff, common.BlockDifference) for diff in device_specific_diffs), \ "{} is not returning a list of BlockDifference objects".format( function_name) for diff in device_specific_diffs: if diff.partition in block_diff_dict: logger.warning("Duplicate block difference found. Device specific block" " diff for partition '%s' overrides the one in generic" " script.", diff.partition) block_diff_dict[diff.partition] = diff return block_diff_dict
def FullOTA_GetBlockDifferences(info): images = GetUserImages(info.input_tmp, info.input_zip) return [ common.BlockDifference(partition, image) for partition, image in images.items() ]