Snap for 11510257 from f759fc4c18b53485f2dccd0057ed1593be753eca to simpleperf-release
Change-Id: I699f3d24e18bf719af936707c3c0ea9aa82b9d8d
diff --git a/avbtool.py b/avbtool.py
index 5be377f..e46d042 100755
--- a/avbtool.py
+++ b/avbtool.py
@@ -3441,7 +3441,10 @@
print('{}'.format(partition_size - max_metadata_size))
return
- image = ImageHandler(image_filename)
+ # If we aren't appending the vbmeta footer to the input image we can
+ # open it in read-only mode.
+ image = ImageHandler(image_filename,
+ read_only=do_not_append_vbmeta_image)
# If there's already a footer, truncate the image to its original
# size. This way 'avbtool add_hash_footer' is idempotent (modulo
@@ -4382,8 +4385,7 @@
sub_parser = subparsers.add_parser('add_hash_footer',
help='Add hashes and footer to image.')
sub_parser.add_argument('--image',
- help='Image to add hashes to',
- type=argparse.FileType('rb+'))
+ help='Image to add hashes to')
sub_parser.add_argument('--partition_size',
help='Partition size',
type=parse_number)
@@ -4818,7 +4820,7 @@
def add_hash_footer(self, args):
"""Implements the 'add_hash_footer' sub-command."""
args = self._fixup_common_args(args)
- self.avb.add_hash_footer(args.image.name if args.image else None,
+ self.avb.add_hash_footer(args.image,
args.partition_size, args.dynamic_partition_size,
args.partition_name, args.hash_algorithm,
args.salt, args.chain_partition,
diff --git a/test/avbtool_unittest.cc b/test/avbtool_unittest.cc
index 93cae41..753aaca 100644
--- a/test/avbtool_unittest.cc
+++ b/test/avbtool_unittest.cc
@@ -656,6 +656,8 @@
EXPECT_EQ(static_cast<size_t>(erased_footer_file_size), rootfs_size);
// Check that --do_not_append_vbmeta_image works as intended.
+ // In this case we don't modify the input image so it should work read-only.
+ EXPECT_COMMAND(0, "chmod a-w %s", rootfs_path.value().c_str());
EXPECT_COMMAND(0,
"./avbtool.py add_hash_footer --salt d00df00d "
"--hash_algorithm sha256 --image %s "