Lines Matching refs:IMAGE
619 """Abstraction for image I/O with support for Android sparse images.
621 This class provides an interface for working with image files that
622 may be using the Android Sparse Image format. When an instance is
649 """Initializes an image handler.
682 # Not a sparse image, our job here is done.
685 raise ValueError('Encountered sparse image format version {}.{} but '
702 # image.
779 """Helper function to update the image header.
1190 image_size: Size of the image, after rounding up to |block_size|.
1210 'Q' # image size (bytes)
1288 o.write(' Image Size: {} bytes\n'.format(self.image_size))
1341 image = ImageHandler(image_filename)
1347 root_digest, hash_tree = generate_hash_tree(image, self.image_size,
1359 image.seek(self.tree_offset)
1360 hash_tree_ondisk = image.read(self.tree_size)
1365 # TODO: we could also verify that the FEC stored in the image is
1369 print ('{}: Successfully verified {} hashtree of {} for image of {} bytes'
1381 image_size: Image size, in bytes.
1393 'Q' # image size (bytes)
1452 o.write(' Image Size: {} bytes\n'.format(self.image_size))
1493 image = ImageHandler(image_filename)
1494 data = image.read(self.image_size)
1504 print ('{}: Successfully verified {} hash of {} for image of {} bytes'
1760 the image before AVB information was added.
1766 original_image_size: Original image size.
1777 'Q' # Original image size.
1874 raise AvbError('Given image does not look like a vbmeta image.')
1971 AvbError: If there's no footer in the image.
1974 image = ImageHandler(image_filename)
1976 (footer, _, descriptors, _) = self._parse_image(image)
1979 raise AvbError('Given image does not have a footer.')
1993 # If the image has FEC codes, also keep those.
2003 image.truncate(new_image_size)
2010 partition_size: The new size of the image.
2013 AvbError: If there's no footer in the image.
2016 image = ImageHandler(image_filename)
2018 if partition_size % image.block_size != 0:
2019 raise AvbError('Partition size of {} is not a multiple of the image '
2021 image.block_size))
2023 (footer, vbmeta_header, descriptors, _) = self._parse_image(image)
2026 raise AvbError('Given image does not have a footer.')
2029 # image amounts to just moving the footer around.
2032 if vbmeta_end_offset % image.block_size != 0:
2033 vbmeta_end_offset += image.block_size - (vbmeta_end_offset % image.block_size)
2035 if partition_size < vbmeta_end_offset + 1*image.block_size:
2036 raise AvbError('Requested size of {} is too small for an image '
2039 vbmeta_end_offset + 1*image.block_size))
2044 image.truncate(vbmeta_end_offset)
2045 image.append_dont_care(partition_size - vbmeta_end_offset -
2046 1*image.block_size)
2051 footer_blob_with_padding = ('\0'*(image.block_size - AvbFooter.SIZE) +
2053 image.append_raw(footer_blob_with_padding)
2062 misc_image: The misc image to write to.
2093 image_filename: Image file to get information from (file object).
2097 image = ImageHandler(image_filename)
2101 (footer, header, descriptors, image_size) = self._parse_image(image)
2106 o.write('Image size: {} bytes\n'.format(image_size))
2107 o.write('Original image size: {} bytes\n'.format(
2118 ' (Sparse)' if image.is_sparse else ''))
2143 image_filename: Image file to get information from (file object).
2166 print 'Verifying image {} using key at {}'.format(image_filename, key_path)
2169 print 'Verifying image {} using embedded public key'.format(image_filename)
2171 image = ImageHandler(image_filename)
2172 (footer, header, descriptors, image_size) = self._parse_image(image)
2178 image.seek(offset)
2179 vbmeta_blob = image.read(size)
2207 def _parse_image(self, image):
2208 """Gets information about an image.
2210 The image can either be a vbmeta or an image with a footer.
2213 image: An ImageHandler (vbmeta or footer) with a hashtree descriptor.
2217 is no footer on the image), the second argument is a
2220 size of |image|.
2222 assert isinstance(image, ImageHandler)
2224 image.seek(image.image_size - AvbFooter.SIZE)
2226 footer = AvbFooter(image.read(AvbFooter.SIZE))
2229 image.seek(0)
2235 image.seek(vbmeta_offset)
2236 h = AvbVBMetaHeader(image.read(AvbVBMetaHeader.SIZE))
2241 image.seek(desc_start_offset)
2242 descriptors = parse_descriptors(image.read(h.descriptors_size))
2244 return footer, h, descriptors, image.image_size
2246 def _load_vbmeta_blob(self, image):
2249 The image can either be a vbmeta.img or an image
2252 image: An ImageHandler (vbmeta or footer).
2257 assert isinstance(image, ImageHandler)
2259 image.seek(image.image_size - AvbFooter.SIZE)
2261 footer = AvbFooter(image.read(AvbFooter.SIZE))
2264 image.seek(0)
2270 image.seek(vbmeta_offset)
2271 h = AvbVBMetaHeader(image.read(AvbVBMetaHeader.SIZE))
2273 image.seek(vbmeta_offset)
2277 return image.read(data_size)
2337 def _get_cmdline_descriptors_for_dm_verity(self, image):
2341 image: An ImageHandler (vbmeta or footer) with a hashtree descriptor.
2349 AvbError: If |image| doesn't have a hashtree descriptor.
2353 (_, _, descriptors, _) = self._parse_image(image)
2362 raise AvbError('No hashtree descriptor in given image')
2380 output: File to write the image to.
2386 flags: Flags value to use in the image.
2409 for image in include_descriptors_from_image:
2410 (_, image_header, _, _) = self._parse_image(ImageHandler(image.name))
2469 flags: Flags to use in the image.
2556 # Add AvbKernelCmdline descriptor for dm-verity from an image, if requested.
2580 for image in include_descriptors_from_image:
2581 image_handler = ImageHandler(image.name)
2699 image = ImageHandler(image_filename)
2701 if partition_size % image.block_size != 0:
2702 raise AvbError('Partition size of {} is not a multiple of the image '
2704 image.block_size))
2706 # If there's already a footer, truncate the image to its original
2708 if image.image_size >= AvbFooter.SIZE:
2709 image.seek(image.image_size - AvbFooter.SIZE)
2711 footer = AvbFooter(image.read(AvbFooter.SIZE))
2714 image.truncate(footer.original_image_size)
2716 original_image_size = image.image_size
2718 # Image size is too small to possibly contain a footer.
2719 original_image_size = image.image_size
2721 # If anything goes wrong from here-on, restore the image back to
2727 # If the image isn't sparse, its size might not be a multiple of
2729 if image.image_size % image.block_size != 0:
2730 assert not image.is_sparse
2731 padding_needed = image.block_size - (image.image_size%image.block_size)
2732 image.truncate(image.image_size + padding_needed)
2738 vbmeta_offset = image.image_size
2739 padding_needed = (round_to_multiple(len(vbmeta_blob), image.block_size) -
2744 image.append_raw(vbmeta_blob_with_padding)
2749 image.append_dont_care(partition_size - vbmeta_end_offset -
2750 1*image.block_size)
2760 footer_blob_with_padding = ('\0'*(image.block_size - AvbFooter.SIZE) +
2762 image.append_raw(footer_blob_with_padding)
2766 image.truncate(original_image_size)
2794 flags: Flags value to use in the image.
2803 maximum image size leaving enough room for metadata with the
2828 # First, calculate the maximum image size such that an image
2838 # If we're asked to only calculate the maximum image size, we're done.
2843 image = ImageHandler(image_filename)
2845 if partition_size % image.block_size != 0:
2846 raise AvbError('Partition size of {} is not a multiple of the image '
2848 image.block_size))
2850 # If there's already a footer, truncate the image to its original
2853 if image.image_size >= AvbFooter.SIZE:
2854 image.seek(image.image_size - AvbFooter.SIZE)
2856 footer = AvbFooter(image.read(AvbFooter.SIZE))
2859 image.truncate(footer.original_image_size)
2861 original_image_size = image.image_size
2863 # Image size is too small to possibly contain a footer.
2864 original_image_size = image.image_size
2866 # If anything goes wrong from here-on, restore the image back to
2869 # If image size exceeds the maximum image size, fail.
2870 if image.image_size > max_image_size:
2871 raise AvbError('Image size of {} exceeds maximum image '
2873 'size of {}.'.format(image.image_size, max_image_size,
2892 image.seek(0)
2893 hasher.update(image.read(image.image_size))
2897 h_desc.image_size = image.image_size
2923 # If the image isn't sparse, its size might not be a multiple of
2925 if image.image_size % image.block_size != 0:
2926 assert not image.is_sparse
2927 padding_needed = image.block_size - (
2928 image.image_size % image.block_size)
2929 image.truncate(image.image_size + padding_needed)
2935 vbmeta_offset = image.image_size
2937 round_to_multiple(len(vbmeta_blob), image.block_size) -
2941 image.append_raw(vbmeta_blob_with_padding)
2946 image.append_dont_care(partition_size - vbmeta_end_offset -
2947 1*image.block_size)
2957 footer_blob_with_padding = ('\0'*(image.block_size - AvbFooter.SIZE) +
2959 image.append_raw(footer_blob_with_padding)
2963 image.truncate(original_image_size)
3000 flags: Flags value to use in the image.
3011 calculate the maximum image size leaving enough room for hashtree
3039 # First, calculate the maximum image size such that an image
3053 # If we're asked to only calculate the maximum image size, we're done.
3058 image = ImageHandler(image_filename)
3060 if partition_size % image.block_size != 0:
3061 raise AvbError('Partition size of {} is not a multiple of the image '
3063 image.block_size))
3065 # If there's already a footer, truncate the image to its original
3068 if image.image_size >= AvbFooter.SIZE:
3069 image.seek(image.image_size - AvbFooter.SIZE)
3071 footer = AvbFooter(image.read(AvbFooter.SIZE))
3074 image.truncate(footer.original_image_size)
3076 original_image_size = image.image_size
3078 # Image size is too small to possibly contain a footer.
3079 original_image_size = image.image_size
3081 # If anything goes wrong from here-on, restore the image back to
3084 # Ensure image is multiple of block_size.
3085 rounded_image_size = round_to_multiple(image.image_size, block_size)
3086 if rounded_image_size > image.image_size:
3087 image.append_raw('\0' * (rounded_image_size - image.image_size))
3089 # If image size exceeds the maximum image size, fail.
3090 if image.image_size > max_image_size:
3091 raise AvbError('Image size of {} exceeds maximum image '
3093 'size of {}.'.format(image.image_size, max_image_size,
3110 image.image_size, block_size, digest_size + digest_padding)
3112 # If the image isn't sparse, its size might not be a multiple of
3114 if image.image_size % image.block_size != 0:
3115 assert not image.is_sparse
3116 padding_needed = image.block_size - (image.image_size%image.block_size)
3117 image.truncate(image.image_size + padding_needed)
3120 tree_offset = image.image_size
3121 root_digest, hash_tree = generate_hash_tree(image, image.image_size,
3132 ht_desc.image_size = image.image_size
3146 padding_needed = (round_to_multiple(len(hash_tree), image.block_size) -
3149 image.append_raw(hash_tree_with_padding)
3155 padding_needed = (round_to_multiple(len(fec_data), image.block_size) -
3158 fec_offset = image.image_size
3159 image.append_raw(fec_data_with_padding)
3179 padding_needed = (round_to_multiple(len(vbmeta_blob), image.block_size) -
3189 image.append_raw(vbmeta_blob_with_padding)
3193 image.append_dont_care(partition_size - image.image_size -
3194 1*image.block_size)
3204 footer_blob_with_padding = ('\0'*(image.block_size - AvbFooter.SIZE) +
3206 image.append_raw(footer_blob_with_padding)
3210 image.truncate(original_image_size)
3329 image_size: The size of the image to calculate a Merkle-tree for.
3371 image_size: The size of the image.
3375 The number of bytes needed for FEC for an image of the given size
3394 """Generate FEC codes for an image.
3397 image_filename: The filename of the image.
3421 def generate_hash_tree(image, image_size, block_size, hash_alg_name, salt,
3426 image: The image, as a file.
3427 image_size: The size of the image.
3451 image.seek(hash_src_offset + hash_src_size - remaining)
3452 data = image.read(min(remaining, block_size))
3544 metavar='IMAGE',
3545 help='Adds kernel cmdline to set up IMAGE',
3548 help='Include descriptors from image',
3549 metavar='IMAGE',
3627 help='Makes a vbmeta image.')
3641 help='Add hashes and footer to image.')
3642 sub_parser.add_argument('--image',
3643 help='Image to add hashes to',
3658 'instead calculate the maximum image size '
3667 'to the image'),
3674 help='Append vbmeta image to image.')
3675 sub_parser.add_argument('--image',
3676 help='Image to append vbmeta blob to',
3683 help='Image with vbmeta blob to append',
3688 help='Add hashtree and footer to image.')
3689 sub_parser.add_argument('--image',
3690 help='Image to add hashtree to',
3724 'instead calculate the maximum image size '
3734 'to the image'),
3737 # it doesn't take an IMAGE, the generated cmdline will be for the
3747 help='Erase footer from an image.')
3748 sub_parser.add_argument('--image',
3749 help='Image with a footer',
3753 help='Keep the hashtree and FEC in the image',
3758 help='Resize image with a footer.')
3759 sub_parser.add_argument('--image',
3760 help='Image with a footer',
3771 sub_parser.add_argument('--image',
3772 help='Image to show information about',
3783 help='Verify an image.')
3784 sub_parser.add_argument('--image',
3785 help='Image to verify',
3801 help=('The misc image to modify. If the image does '
3920 self.avb.append_vbmeta_image(args.image.name, args.vbmeta_image.name,
3926 self.avb.add_hash_footer(args.image.name if args.image else None,
3956 self.avb.add_hashtree_footer(args.image.name if args.image else None,
3982 self.avb.erase_footer(args.image.name, args.keep_hashtree)
3986 self.avb.resize_image(args.image.name, args.partition_size)
3994 self.avb.info_image(args.image.name, args.output)
3998 self.avb.verify_image(args.image.name, args.key,