Merge "releasetools: Stop copying images from RADIO/ to IMAGES/."

This commit is contained in:
Tao Bao
2018-04-20 21:20:47 +00:00
committed by Gerrit Code Review
3 changed files with 46 additions and 74 deletions

View File

@@ -485,18 +485,15 @@ def AddCache(output_zip):
img.Write() img.Write()
def AddRadioImagesForAbOta(output_zip, ab_partitions): def CheckAbOtaImages(output_zip, ab_partitions):
"""Adds the radio images needed for A/B OTA to the output file. """Checks that all the listed A/B partitions have their images available.
It parses the list of A/B partitions, looks for the missing ones from RADIO/, The images need to be available under IMAGES/ or RADIO/, with the former takes
and copies them to IMAGES/ of the output file (or dir). a priority.
It also ensures that on returning from the function all the listed A/B
partitions must have their images available under IMAGES/.
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 images to OPTIONS.input_tmp/. find images in OPTIONS.input_tmp/.
ab_partitions: The list of A/B partitions. ab_partitions: The list of A/B partitions.
Raises: Raises:
@@ -504,27 +501,20 @@ def AddRadioImagesForAbOta(output_zip, ab_partitions):
""" """
for partition in ab_partitions: for partition in ab_partitions:
img_name = partition.strip() + ".img" img_name = partition.strip() + ".img"
prebuilt_path = os.path.join(OPTIONS.input_tmp, "IMAGES", img_name)
if os.path.exists(prebuilt_path):
print("%s already exists, no need to overwrite..." % (img_name,))
continue
img_radio_path = os.path.join(OPTIONS.input_tmp, "RADIO", img_name)
if os.path.exists(img_radio_path):
if output_zip:
common.ZipWrite(output_zip, img_radio_path, "IMAGES/" + img_name)
else:
shutil.copy(img_radio_path, prebuilt_path)
continue
# Assert that the image is present under IMAGES/ now. # Assert that the image is present under IMAGES/ now.
if output_zip: if output_zip:
# Zip spec says: All slashes MUST be forward slashes. # Zip spec says: All slashes MUST be forward slashes.
img_path = 'IMAGES/' + img_name images_path = "IMAGES/" + img_name
assert img_path in output_zip.namelist(), "cannot find " + img_name radio_path = "RADIO/" + img_name
available = (images_path in output_zip.namelist() or
radio_path in output_zip.namelist())
else: else:
img_path = os.path.join(OPTIONS.input_tmp, "IMAGES", img_name) images_path = os.path.join(OPTIONS.input_tmp, "IMAGES", img_name)
assert os.path.exists(img_path), "cannot find " + img_name radio_path = os.path.join(OPTIONS.input_tmp, "RADIO", img_name)
available = os.path.exists(images_path) or os.path.exists(radio_path)
assert available, "Failed to find " + img_name
def AddCareMapTxtForAbOta(output_zip, ab_partitions, image_paths): def AddCareMapTxtForAbOta(output_zip, ab_partitions, image_paths):
@@ -751,10 +741,9 @@ def AddImagesToTargetFiles(filename):
with open(ab_partitions_txt, 'r') as f: with open(ab_partitions_txt, 'r') as f:
ab_partitions = f.readlines() ab_partitions = f.readlines()
# For devices using A/B update, copy over images from RADIO/ to IMAGES/ and # For devices using A/B update, make sure we have all the needed images
# make sure we have all the needed images ready under IMAGES/. All images # ready under IMAGES/ or RADIO/.
# should have '.img' as extension. CheckAbOtaImages(output_zip, ab_partitions)
AddRadioImagesForAbOta(output_zip, ab_partitions)
# Generate care_map.txt for system and vendor partitions (if present), then # Generate care_map.txt for system and vendor partitions (if present), then
# write this file to target_files package. # write this file to target_files package.

View File

@@ -22,8 +22,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, AddRadioImagesForAbOta, AddCareMapTxtForAbOta, AddPackRadioImages, CheckAbOtaImages, GetCareMap)
GetCareMap)
from rangelib import RangeSet from rangelib import RangeSet
@@ -55,49 +54,25 @@ class AddImagesToTargetFilesTest(unittest.TestCase):
os.mkdir(images_path) os.mkdir(images_path)
return images, images_path return images, images_path
def test_AddRadioImagesForAbOta_imageExists(self): def test_CheckAbOtaImages_imageExistsUnderImages(self):
"""Tests the case with existing images under IMAGES/.""" """Tests the case with existing images under IMAGES/."""
images, images_path = self._create_images(['aboot', 'xbl'], 'IMAGES') images, _ = self._create_images(['aboot', 'xbl'], 'IMAGES')
AddRadioImagesForAbOta(None, images) CheckAbOtaImages(None, images)
for image in images: def test_CheckAbOtaImages_imageExistsUnderRadio(self):
self.assertTrue( """Tests the case with some image under RADIO/."""
os.path.exists(os.path.join(images_path, image + '.img'))) images, _ = self._create_images(['system', 'vendor'], 'IMAGES')
radio_path = os.path.join(OPTIONS.input_tmp, 'RADIO')
if not os.path.exists(radio_path):
os.mkdir(radio_path)
with open(os.path.join(radio_path, 'modem.img'), 'wb') as image_fp:
image_fp.write('modem'.encode())
CheckAbOtaImages(None, images + ['modem'])
def test_AddRadioImagesForAbOta_copyFromRadio(self): def test_CheckAbOtaImages_missingImages(self):
"""Tests the case that copies images from RADIO/."""
images, images_path = self._create_images(['aboot', 'xbl'], 'RADIO')
AddRadioImagesForAbOta(None, images)
for image in images:
self.assertTrue(
os.path.exists(os.path.join(images_path, image + '.img')))
def test_AddRadioImagesForAbOta_copyFromRadio_zipOutput(self):
images, _ = self._create_images(['aboot', 'xbl'], 'RADIO') images, _ = self._create_images(['aboot', 'xbl'], 'RADIO')
self.assertRaises(
# Set up the output zip. AssertionError, CheckAbOtaImages, None, images + ['baz'])
output_file = common.MakeTempFile(suffix='.zip')
with zipfile.ZipFile(output_file, 'w') as output_zip:
AddRadioImagesForAbOta(output_zip, images)
with zipfile.ZipFile(output_file, 'r') as verify_zip:
for image in images:
self.assertIn('IMAGES/' + image + '.img', verify_zip.namelist())
def test_AddRadioImagesForAbOta_missingImages(self):
images, _ = self._create_images(['aboot', 'xbl'], 'RADIO')
self.assertRaises(AssertionError, AddRadioImagesForAbOta, None,
images + ['baz'])
def test_AddRadioImagesForAbOta_missingImages_zipOutput(self):
images, _ = self._create_images(['aboot', 'xbl'], 'RADIO')
# Set up the output zip.
output_file = common.MakeTempFile(suffix='.zip')
with zipfile.ZipFile(output_file, 'w') as output_zip:
self.assertRaises(AssertionError, AddRadioImagesForAbOta, output_zip,
images + ['baz'])
def test_AddPackRadioImages(self): def test_AddPackRadioImages(self):
images, images_path = self._create_images(['foo', 'bar'], 'RADIO') images, images_path = self._create_images(['foo', 'bar'], 'RADIO')

View File

@@ -50,17 +50,25 @@ def construct_target_files(secondary=False):
"POSTINSTALL_OPTIONAL_system=true", "POSTINSTALL_OPTIONAL_system=true",
])) ]))
ab_partitions = [
('IMAGES', 'boot'),
('IMAGES', 'system'),
('IMAGES', 'vendor'),
('RADIO', 'bootloader'),
('RADIO', 'modem'),
]
# META/ab_partitions.txt # META/ab_partitions.txt
ab_partitions = ['boot', 'system', 'vendor']
target_files_zip.writestr( target_files_zip.writestr(
'META/ab_partitions.txt', 'META/ab_partitions.txt',
'\n'.join(ab_partitions)) '\n'.join([partition[1] for partition in ab_partitions]))
# Create dummy images for each of them. # Create dummy images for each of them.
for partition in ab_partitions: for path, partition in ab_partitions:
target_files_zip.writestr('IMAGES/' + partition + '.img', target_files_zip.writestr(
os.urandom(len(partition))) '{}/{}.img'.format(path, partition),
os.urandom(len(partition)))
# system_other shouldn't appear in META/ab_partitions.txt.
if secondary: if secondary:
target_files_zip.writestr('IMAGES/system_other.img', target_files_zip.writestr('IMAGES/system_other.img',
os.urandom(len("system_other"))) os.urandom(len("system_other")))