Calculate the vbmeta digest when building images

Calculate the vbmeta digest if the device builds vbmeta image. The
digest will used later to determine the build fingerprint in new
format.

One sample usage is the ota package generation, where we put the
build fingerprint in the ota metadata. But we don't have the runtime
vbmeta digest provided the bootloader.

Bug: 186786987
Test: unit tests
Change-Id: If572e2b973e295a6c95a9e23a65bb20b3afbf1b0
This commit is contained in:
Tianjie
2021-05-03 21:18:56 -07:00
committed by Tianjie Xu
parent bf7d6d78c7
commit bbde59f9eb
4 changed files with 76 additions and 3 deletions

View File

@@ -26,6 +26,7 @@ import logging
import os.path
import shlex
import struct
import sys
import common
import sparse_img
@@ -739,6 +740,30 @@ def GetDiskUsage(path):
return int(output.split()[0]) * 1024
def CalculateVbmetaDigest(extracted_dir, avbtool):
"""Calculates the vbmeta digest of the images in the extracted target_file"""
images_dir = common.MakeTempDir()
for name in ("PREBUILT_IMAGES", "RADIO", "IMAGES"):
path = os.path.join(extracted_dir, name)
if not os.path.exists(path):
continue
# Create symlink for image files under PREBUILT_IMAGES, RADIO and IMAGES,
# and put them into one directory.
for filename in os.listdir(path):
if not filename.endswith(".img"):
continue
symlink_path = os.path.join(images_dir, filename)
# The files in latter directory overwrite the existing links
common.RunAndCheckOutput(
['ln', '-sf', os.path.join(path, filename), symlink_path])
cmd = [avbtool, "calculate_vbmeta_digest", "--image",
os.path.join(images_dir, 'vbmeta.img')]
return common.RunAndCheckOutput(cmd)
def main(argv):
if len(argv) != 2:
print(__doc__)