Merge "Rename care map in pb format to care_map.pb"

This commit is contained in:
Tianjie Xu
2018-09-21 00:03:40 +00:00
committed by Gerrit Code Review
5 changed files with 61 additions and 54 deletions

View File

@@ -72,7 +72,7 @@ OPTIONS.replace_verity_public_key = False
OPTIONS.replace_verity_private_key = False OPTIONS.replace_verity_private_key = False
OPTIONS.is_signing = False OPTIONS.is_signing = False
# Partitions that should have their care_map added to META/care_map.txt. # Partitions that should have their care_map added to META/care_map.pb
PARTITIONS_WITH_CARE_MAP = ('system', 'vendor', 'product', 'product_services', PARTITIONS_WITH_CARE_MAP = ('system', 'vendor', 'product', 'product_services',
'odm') 'odm')
# Use a fixed timestamp (01/01/2009 00:00:00 UTC) for files when packaging # Use a fixed timestamp (01/01/2009 00:00:00 UTC) for files when packaging
@@ -556,12 +556,12 @@ def CheckAbOtaImages(output_zip, ab_partitions):
assert available, "Failed to find " + img_name assert available, "Failed to find " + img_name
def AddCareMapTxtForAbOta(output_zip, ab_partitions, image_paths): def AddCareMapForAbOta(output_zip, ab_partitions, image_paths):
"""Generates and adds care_map.txt for system and vendor partitions. """Generates and adds care_map.pb for system and vendor partitions.
Args: Args:
output_zip: The output zip file (needs to be already open), or None to output_zip: The output zip file (needs to be already open), or None to
write care_map.txt to OPTIONS.input_tmp/. write care_map.pb to OPTIONS.input_tmp/.
ab_partitions: The list of A/B partitions. ab_partitions: The list of A/B partitions.
image_paths: A map from the partition name to the image path. image_paths: A map from the partition name to the image path.
""" """
@@ -594,11 +594,11 @@ def AddCareMapTxtForAbOta(output_zip, ab_partitions, image_paths):
p = common.Run(care_map_gen_cmd, stdout=subprocess.PIPE, p = common.Run(care_map_gen_cmd, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT) stderr=subprocess.STDOUT)
output, _ = p.communicate() output, _ = p.communicate()
assert p.returncode == 0, "Failed to generate the care_map proto message." assert p.returncode == 0, "Failed to generate the care_map.pb message."
if OPTIONS.verbose: if OPTIONS.verbose:
print(output.rstrip()) print(output.rstrip())
care_map_path = "META/care_map.txt" care_map_path = "META/care_map.pb"
if output_zip and care_map_path not in output_zip.namelist(): if output_zip and care_map_path not in output_zip.namelist():
common.ZipWrite(output_zip, temp_care_map, arcname=care_map_path) common.ZipWrite(output_zip, temp_care_map, arcname=care_map_path)
else: else:
@@ -658,7 +658,7 @@ def AddSuperEmpty(output_zip):
def ReplaceUpdatedFiles(zip_filename, files_list): def ReplaceUpdatedFiles(zip_filename, files_list):
"""Updates all the ZIP entries listed in files_list. """Updates all the ZIP entries listed in files_list.
For now the list includes META/care_map.txt, and the related files under For now the list includes META/care_map.pb, and the related files under
SYSTEM/ after rebuilding recovery. SYSTEM/ after rebuilding recovery.
""" """
common.ZipDelete(zip_filename, files_list) common.ZipDelete(zip_filename, files_list)
@@ -863,9 +863,9 @@ def AddImagesToTargetFiles(filename):
# ready under IMAGES/ or RADIO/. # ready under IMAGES/ or RADIO/.
CheckAbOtaImages(output_zip, ab_partitions) CheckAbOtaImages(output_zip, ab_partitions)
# Generate care_map.txt for system and vendor partitions (if present), then # Generate care_map.pb for system and vendor partitions (if present),
# write this file to target_files package. # then write this file to target_files package.
AddCareMapTxtForAbOta(output_zip, ab_partitions, partitions) AddCareMapForAbOta(output_zip, ab_partitions, partitions)
# Radio images that need to be packed into IMAGES/, and product-img.zip. # Radio images that need to be packed into IMAGES/, and product-img.zip.
pack_radioimages_txt = os.path.join( pack_radioimages_txt = os.path.join(

View File

@@ -1167,7 +1167,8 @@ class StreamingPropertyFiles(PropertyFiles):
'payload_properties.txt', 'payload_properties.txt',
) )
self.optional = ( self.optional = (
# care_map.txt is available only if dm-verity is enabled. # care_map is available only if dm-verity is enabled.
'care_map.pb',
'care_map.txt', 'care_map.txt',
# compatibility.zip is available only if target supports Treble. # compatibility.zip is available only if target supports Treble.
'compatibility.zip', 'compatibility.zip',
@@ -1786,13 +1787,16 @@ def WriteABOTAPackageWithBrilloScript(target_file, output_file,
target_zip = zipfile.ZipFile(target_file, "r") target_zip = zipfile.ZipFile(target_file, "r")
if (target_info.get("verity") == "true" or if (target_info.get("verity") == "true" or
target_info.get("avb_enable") == "true"): target_info.get("avb_enable") == "true"):
care_map_path = "META/care_map.txt" care_map_list = [x for x in ["care_map.pb", "care_map.txt"] if
namelist = target_zip.namelist() "META/" + x in target_zip.namelist()]
if care_map_path in namelist:
care_map_data = target_zip.read(care_map_path) # Adds care_map if either the protobuf format or the plain text one exists.
# In order to support streaming, care_map.txt needs to be packed as if care_map_list:
care_map_name = care_map_list[0]
care_map_data = target_zip.read("META/" + care_map_name)
# In order to support streaming, care_map needs to be packed as
# ZIP_STORED. # ZIP_STORED.
common.ZipWriteStr(output_zip, "care_map.txt", care_map_data, common.ZipWriteStr(output_zip, care_map_name, care_map_data,
compress_type=zipfile.ZIP_STORED) compress_type=zipfile.ZIP_STORED)
else: else:
print("Warning: cannot find care map file in target_file package") print("Warning: cannot find care map file in target_file package")

View File

@@ -395,7 +395,7 @@ def ProcessTargetFiles(input_tf_zip, output_tf_zip, misc_info,
pass pass
# Skip the care_map as we will regenerate the system/vendor images. # Skip the care_map as we will regenerate the system/vendor images.
elif filename == "META/care_map.txt": elif filename == "META/care_map.pb" or filename == "META/care_map.txt":
pass pass
# A non-APK file; copy it verbatim. # A non-APK file; copy it verbatim.

View File

@@ -23,7 +23,7 @@ import zipfile
import common import common
import test_utils import test_utils
from add_img_to_target_files import ( from add_img_to_target_files import (
AddCareMapTxtForAbOta, AddPackRadioImages, AppendVBMetaArgsForPartition, AddCareMapForAbOta, AddPackRadioImages, AppendVBMetaArgsForPartition,
CheckAbOtaImages, GetCareMap) CheckAbOtaImages, GetCareMap)
from rangelib import RangeSet from rangelib import RangeSet
@@ -40,7 +40,7 @@ class AddImagesToTargetFilesTest(unittest.TestCase):
common.Cleanup() common.Cleanup()
def _verifyCareMap(self, expected, file_name): def _verifyCareMap(self, expected, file_name):
"""Parses the care_map proto; and checks the content in plain text.""" """Parses the care_map.pb; and checks the content in plain text."""
text_file = common.MakeTempFile(prefix="caremap-", suffix=".txt") text_file = common.MakeTempFile(prefix="caremap-", suffix=".txt")
# Calls an external binary to convert the proto message. # Calls an external binary to convert the proto message.
@@ -139,8 +139,8 @@ class AddImagesToTargetFilesTest(unittest.TestCase):
images + ['baz']) images + ['baz'])
@staticmethod @staticmethod
def _test_AddCareMapTxtForAbOta(): def _test_AddCareMapForAbOta():
"""Helper function to set up the test for test_AddCareMapTxtForAbOta().""" """Helper function to set up the test for test_AddCareMapForAbOta()."""
OPTIONS.info_dict = { OPTIONS.info_dict = {
'system_verity_block_device' : '/dev/block/system', 'system_verity_block_device' : '/dev/block/system',
'vendor_verity_block_device' : '/dev/block/vendor', 'vendor_verity_block_device' : '/dev/block/vendor',
@@ -164,71 +164,71 @@ class AddImagesToTargetFilesTest(unittest.TestCase):
} }
return image_paths return image_paths
def test_AddCareMapTxtForAbOta(self): def test_AddCareMapForAbOta(self):
image_paths = self._test_AddCareMapTxtForAbOta() image_paths = self._test_AddCareMapForAbOta()
AddCareMapTxtForAbOta(None, ['system', 'vendor'], image_paths) AddCareMapForAbOta(None, ['system', 'vendor'], image_paths)
care_map_file = os.path.join(OPTIONS.input_tmp, 'META', 'care_map.txt') care_map_file = os.path.join(OPTIONS.input_tmp, 'META', 'care_map.pb')
expected = ['system', RangeSet("0-5 10-15").to_string_raw(), 'vendor', expected = ['system', RangeSet("0-5 10-15").to_string_raw(), 'vendor',
RangeSet("0-9").to_string_raw()] RangeSet("0-9").to_string_raw()]
self._verifyCareMap(expected, care_map_file) self._verifyCareMap(expected, care_map_file)
def test_AddCareMapTxtForAbOta_withNonCareMapPartitions(self): def test_AddCareMapForAbOta_withNonCareMapPartitions(self):
"""Partitions without care_map should be ignored.""" """Partitions without care_map should be ignored."""
image_paths = self._test_AddCareMapTxtForAbOta() image_paths = self._test_AddCareMapForAbOta()
AddCareMapTxtForAbOta( AddCareMapForAbOta(
None, ['boot', 'system', 'vendor', 'vbmeta'], image_paths) None, ['boot', 'system', 'vendor', 'vbmeta'], image_paths)
care_map_file = os.path.join(OPTIONS.input_tmp, 'META', 'care_map.txt') care_map_file = os.path.join(OPTIONS.input_tmp, 'META', 'care_map.pb')
expected = ['system', RangeSet("0-5 10-15").to_string_raw(), 'vendor', expected = ['system', RangeSet("0-5 10-15").to_string_raw(), 'vendor',
RangeSet("0-9").to_string_raw()] RangeSet("0-9").to_string_raw()]
self._verifyCareMap(expected, care_map_file) self._verifyCareMap(expected, care_map_file)
def test_AddCareMapTxtForAbOta_withAvb(self): def test_AddCareMapForAbOta_withAvb(self):
"""Tests the case for device using AVB.""" """Tests the case for device using AVB."""
image_paths = self._test_AddCareMapTxtForAbOta() image_paths = self._test_AddCareMapForAbOta()
OPTIONS.info_dict = { OPTIONS.info_dict = {
'avb_system_hashtree_enable' : 'true', 'avb_system_hashtree_enable' : 'true',
'avb_vendor_hashtree_enable' : 'true', 'avb_vendor_hashtree_enable' : 'true',
} }
AddCareMapTxtForAbOta(None, ['system', 'vendor'], image_paths) AddCareMapForAbOta(None, ['system', 'vendor'], image_paths)
care_map_file = os.path.join(OPTIONS.input_tmp, 'META', 'care_map.txt') care_map_file = os.path.join(OPTIONS.input_tmp, 'META', 'care_map.pb')
expected = ['system', RangeSet("0-5 10-15").to_string_raw(), 'vendor', expected = ['system', RangeSet("0-5 10-15").to_string_raw(), 'vendor',
RangeSet("0-9").to_string_raw()] RangeSet("0-9").to_string_raw()]
self._verifyCareMap(expected, care_map_file) self._verifyCareMap(expected, care_map_file)
def test_AddCareMapTxtForAbOta_verityNotEnabled(self): def test_AddCareMapForAbOta_verityNotEnabled(self):
"""No care_map.txt should be generated if verity not enabled.""" """No care_map.pb should be generated if verity not enabled."""
image_paths = self._test_AddCareMapTxtForAbOta() image_paths = self._test_AddCareMapForAbOta()
OPTIONS.info_dict = {} OPTIONS.info_dict = {}
AddCareMapTxtForAbOta(None, ['system', 'vendor'], image_paths) AddCareMapForAbOta(None, ['system', 'vendor'], image_paths)
care_map_file = os.path.join(OPTIONS.input_tmp, 'META', 'care_map.txt') care_map_file = os.path.join(OPTIONS.input_tmp, 'META', 'care_map.pb')
self.assertFalse(os.path.exists(care_map_file)) self.assertFalse(os.path.exists(care_map_file))
def test_AddCareMapTxtForAbOta_missingImageFile(self): def test_AddCareMapForAbOta_missingImageFile(self):
"""Missing image file should be considered fatal.""" """Missing image file should be considered fatal."""
image_paths = self._test_AddCareMapTxtForAbOta() image_paths = self._test_AddCareMapForAbOta()
image_paths['vendor'] = '' image_paths['vendor'] = ''
self.assertRaises(AssertionError, AddCareMapTxtForAbOta, None, self.assertRaises(AssertionError, AddCareMapForAbOta, None,
['system', 'vendor'], image_paths) ['system', 'vendor'], image_paths)
def test_AddCareMapTxtForAbOta_zipOutput(self): def test_AddCareMapForAbOta_zipOutput(self):
"""Tests the case with ZIP output.""" """Tests the case with ZIP output."""
image_paths = self._test_AddCareMapTxtForAbOta() image_paths = self._test_AddCareMapForAbOta()
output_file = common.MakeTempFile(suffix='.zip') output_file = common.MakeTempFile(suffix='.zip')
with zipfile.ZipFile(output_file, 'w') as output_zip: with zipfile.ZipFile(output_file, 'w') as output_zip:
AddCareMapTxtForAbOta(output_zip, ['system', 'vendor'], image_paths) AddCareMapForAbOta(output_zip, ['system', 'vendor'], image_paths)
care_map_name = "META/care_map.txt" care_map_name = "META/care_map.pb"
temp_dir = common.MakeTempDir() temp_dir = common.MakeTempDir()
with zipfile.ZipFile(output_file, 'r') as verify_zip: with zipfile.ZipFile(output_file, 'r') as verify_zip:
self.assertTrue(care_map_name in verify_zip.namelist()) self.assertTrue(care_map_name in verify_zip.namelist())
@@ -238,27 +238,28 @@ class AddImagesToTargetFilesTest(unittest.TestCase):
RangeSet("0-9").to_string_raw()] RangeSet("0-9").to_string_raw()]
self._verifyCareMap(expected, os.path.join(temp_dir, care_map_name)) self._verifyCareMap(expected, os.path.join(temp_dir, care_map_name))
def test_AddCareMapTxtForAbOta_zipOutput_careMapEntryExists(self): def test_AddCareMapForAbOta_zipOutput_careMapEntryExists(self):
"""Tests the case with ZIP output which already has care_map entry.""" """Tests the case with ZIP output which already has care_map entry."""
image_paths = self._test_AddCareMapTxtForAbOta() image_paths = self._test_AddCareMapForAbOta()
output_file = common.MakeTempFile(suffix='.zip') output_file = common.MakeTempFile(suffix='.zip')
with zipfile.ZipFile(output_file, 'w') as output_zip: with zipfile.ZipFile(output_file, 'w') as output_zip:
# Create an existing META/care_map.txt entry. # Create an existing META/care_map.pb entry.
common.ZipWriteStr(output_zip, 'META/care_map.txt', 'dummy care_map.txt') common.ZipWriteStr(output_zip, 'META/care_map.pb',
'dummy care_map.pb')
# Request to add META/care_map.txt again. # Request to add META/care_map.pb again.
AddCareMapTxtForAbOta(output_zip, ['system', 'vendor'], image_paths) AddCareMapForAbOta(output_zip, ['system', 'vendor'], image_paths)
# The one under OPTIONS.input_tmp must have been replaced. # The one under OPTIONS.input_tmp must have been replaced.
care_map_file = os.path.join(OPTIONS.input_tmp, 'META', 'care_map.txt') care_map_file = os.path.join(OPTIONS.input_tmp, 'META', 'care_map.pb')
expected = ['system', RangeSet("0-5 10-15").to_string_raw(), 'vendor', expected = ['system', RangeSet("0-5 10-15").to_string_raw(), 'vendor',
RangeSet("0-9").to_string_raw()] RangeSet("0-9").to_string_raw()]
self._verifyCareMap(expected, care_map_file) self._verifyCareMap(expected, care_map_file)
# The existing entry should be scheduled to be replaced. # The existing entry should be scheduled to be replaced.
self.assertIn('META/care_map.txt', OPTIONS.replace_updated_files_list) self.assertIn('META/care_map.pb', OPTIONS.replace_updated_files_list)
def test_AppendVBMetaArgsForPartition(self): def test_AppendVBMetaArgsForPartition(self):
OPTIONS.info_dict = {} OPTIONS.info_dict = {}

View File

@@ -889,6 +889,7 @@ class StreamingPropertyFilesTest(PropertyFilesTest):
property_files.required) property_files.required)
self.assertEqual( self.assertEqual(
( (
'care_map.pb',
'care_map.txt', 'care_map.txt',
'compatibility.zip', 'compatibility.zip',
), ),
@@ -984,6 +985,7 @@ class AbOtaPropertyFilesTest(PropertyFilesTest):
property_files.required) property_files.required)
self.assertEqual( self.assertEqual(
( (
'care_map.pb',
'care_map.txt', 'care_map.txt',
'compatibility.zip', 'compatibility.zip',
), ),