summaryrefslogtreecommitdiff
path: root/tools/releasetools/common.py
diff options
context:
space:
mode:
author Kelvin Zhang <zhangkelvin@google.com> 2022-09-23 10:06:03 -0700
committer Kelvin Zhang <zhangkelvin@google.com> 2022-10-10 13:12:50 -0700
commit1caead09f94c2fefa2eea6df5168f338d217709e (patch)
tree5b830e0933cc9d38e1dff3c67f3b156abd1b68f2 /tools/releasetools/common.py
parentc6ea3aa6e08a410655b0aaf6c8c89247897467cc (diff)
Use AVB footer to determine caremap
Care maps need to store the original image size, which excludes bytes used by hash tree or FEC code. We used to propagate original image size using the global OPTIONS dictionary. This is bad coding practice, and also fragile because we have to make sure what's stored in dictionary and what's on disk are consistent. Instead, let's read the content of images on disk, and parse the AVB footer. The AVB footer contains the ground truth original image size. Test: build OTA, make sure the care maps have valid range Bug: 246504616 Change-Id: I9250b478ab34dda60578a6b8c23ae6d7a9385788
Diffstat (limited to 'tools/releasetools/common.py')
-rw-r--r--tools/releasetools/common.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py
index cc75d2c9cd..bbdff6e50b 100644
--- a/tools/releasetools/common.py
+++ b/tools/releasetools/common.py
@@ -2865,7 +2865,7 @@ def ZipWriteStr(zip_file, zinfo_or_arcname, data, perms=None,
zipfile.ZIP64_LIMIT = saved_zip64_limit
-def ZipDelete(zip_filename, entries):
+def ZipDelete(zip_filename, entries, force=False):
"""Deletes entries from a ZIP file.
Since deleting entries from a ZIP file is not supported, it shells out to
@@ -2883,8 +2883,15 @@ def ZipDelete(zip_filename, entries):
# If list is empty, nothing to do
if not entries:
return
- cmd = ["zip", "-d", zip_filename] + entries
- RunAndCheckOutput(cmd)
+ if force:
+ cmd = ["zip", "-q", "-d", zip_filename] + entries
+ else:
+ cmd = ["zip", "-d", zip_filename] + entries
+ if force:
+ p = Run(cmd)
+ p.wait()
+ else:
+ RunAndCheckOutput(cmd)
def ZipClose(zip_file):
@@ -3979,6 +3986,8 @@ def GetBootImageTimestamp(boot_img):
def IsSparseImage(filepath):
+ if not os.path.exists(filepath):
+ return False
with open(filepath, 'rb') as fp:
# Magic for android sparse image format
# https://source.android.com/devices/bootloader/images