Merge "releasetools: Specify SWITCH_SLOT_ON_REBOOT for secondary payload." am: 4f0b725439 am: 78eef74e03

am: 55e571f0b6

Change-Id: I0bb607e9ad51dd8624493a82c3d5c2b2167abd43
This commit is contained in:
Tao Bao 2018-02-13 22:12:24 +00:00 committed by android-build-merger
commit d1239cd452
2 changed files with 24 additions and 9 deletions

View file

@ -386,11 +386,17 @@ class Payload(object):
SECONDARY_PAYLOAD_BIN = 'secondary/payload.bin'
SECONDARY_PAYLOAD_PROPERTIES_TXT = 'secondary/payload_properties.txt'
def __init__(self):
def __init__(self, secondary=False):
"""Initializes a Payload instance.
Args:
secondary: Whether it's generating a secondary payload (default: False).
"""
# The place where the output from the subprocess should go.
self._log_file = sys.stdout if OPTIONS.verbose else subprocess.PIPE
self.payload_file = None
self.payload_properties = None
self.secondary = secondary
def Generate(self, target_file, source_file=None, additional_args=None):
"""Generates a payload from the given target-files zip(s).
@ -470,6 +476,10 @@ class Payload(object):
p1.communicate()
assert p1.returncode == 0, "brillo_update_payload properties failed"
if self.secondary:
with open(properties_file, "a") as f:
f.write("SWITCH_SLOT_ON_REBOOT=0\n")
if OPTIONS.wipe_user_data:
with open(properties_file, "a") as f:
f.write("POWERWASH=1\n")
@ -477,18 +487,16 @@ class Payload(object):
self.payload_file = signed_payload_file
self.payload_properties = properties_file
def WriteToZip(self, output_zip, secondary=False):
def WriteToZip(self, output_zip):
"""Writes the payload to the given zip.
Args:
output_zip: The output ZipFile instance.
secondary: Whether the payload should be packed as secondary payload
(default: False).
"""
assert self.payload_file is not None
assert self.payload_properties is not None
if secondary:
if self.secondary:
payload_arcname = Payload.SECONDARY_PAYLOAD_BIN
payload_properties_arcname = Payload.SECONDARY_PAYLOAD_PROPERTIES_TXT
else:
@ -1327,10 +1335,10 @@ def WriteABOTAPackageWithBrilloScript(target_file, output_file,
# We always include a full payload for the secondary slot, even when
# building an incremental OTA. See the comments for "--include_secondary".
secondary_target_file = GetTargetFilesZipForSecondaryImages(target_file)
secondary_payload = Payload()
secondary_payload = Payload(secondary=True)
secondary_payload.Generate(secondary_target_file)
secondary_payload.Sign(payload_signer)
secondary_payload.WriteToZip(output_zip, secondary=True)
secondary_payload.WriteToZip(output_zip)
# If dm-verity is supported for the device, copy contents of care_map
# into A/B OTA package.

View file

@ -643,7 +643,7 @@ class PayloadTest(unittest.TestCase):
@staticmethod
def _create_payload_full(secondary=False):
target_file = construct_target_files(secondary)
payload = Payload()
payload = Payload(secondary)
payload.Generate(target_file)
return payload
@ -713,6 +713,13 @@ class PayloadTest(unittest.TestCase):
with open(payload.payload_properties) as properties_fp:
self.assertIn("POWERWASH=1", properties_fp.read())
def test_Sign_secondary(self):
payload = self._create_payload_full(secondary=True)
payload.Sign(PayloadSigner())
with open(payload.payload_properties) as properties_fp:
self.assertIn("SWITCH_SLOT_ON_REBOOT=0", properties_fp.read())
def test_Sign_badSigner(self):
"""Tests that signing failure can be captured."""
payload = self._create_payload_full()
@ -762,7 +769,7 @@ class PayloadTest(unittest.TestCase):
output_file = common.MakeTempFile(suffix='.zip')
with zipfile.ZipFile(output_file, 'w') as output_zip:
payload.WriteToZip(output_zip, secondary=True)
payload.WriteToZip(output_zip)
with zipfile.ZipFile(output_file) as verify_zip:
# First make sure we have the essential entries.