Merge "releasetools: Specify SWITCH_SLOT_ON_REBOOT for secondary payload." am: 4f0b725439
am: 78eef74e03
Change-Id: I02007c63b6a7398afe8b5304e48c01589842a876
This commit is contained in:
commit
55e571f0b6
2 changed files with 24 additions and 9 deletions
|
@ -386,11 +386,17 @@ class Payload(object):
|
||||||
SECONDARY_PAYLOAD_BIN = 'secondary/payload.bin'
|
SECONDARY_PAYLOAD_BIN = 'secondary/payload.bin'
|
||||||
SECONDARY_PAYLOAD_PROPERTIES_TXT = 'secondary/payload_properties.txt'
|
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.
|
# The place where the output from the subprocess should go.
|
||||||
self._log_file = sys.stdout if OPTIONS.verbose else subprocess.PIPE
|
self._log_file = sys.stdout if OPTIONS.verbose else subprocess.PIPE
|
||||||
self.payload_file = None
|
self.payload_file = None
|
||||||
self.payload_properties = None
|
self.payload_properties = None
|
||||||
|
self.secondary = secondary
|
||||||
|
|
||||||
def Generate(self, target_file, source_file=None, additional_args=None):
|
def Generate(self, target_file, source_file=None, additional_args=None):
|
||||||
"""Generates a payload from the given target-files zip(s).
|
"""Generates a payload from the given target-files zip(s).
|
||||||
|
@ -470,6 +476,10 @@ class Payload(object):
|
||||||
p1.communicate()
|
p1.communicate()
|
||||||
assert p1.returncode == 0, "brillo_update_payload properties failed"
|
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:
|
if OPTIONS.wipe_user_data:
|
||||||
with open(properties_file, "a") as f:
|
with open(properties_file, "a") as f:
|
||||||
f.write("POWERWASH=1\n")
|
f.write("POWERWASH=1\n")
|
||||||
|
@ -477,18 +487,16 @@ class Payload(object):
|
||||||
self.payload_file = signed_payload_file
|
self.payload_file = signed_payload_file
|
||||||
self.payload_properties = properties_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.
|
"""Writes the payload to the given zip.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
output_zip: The output ZipFile instance.
|
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_file is not None
|
||||||
assert self.payload_properties is not None
|
assert self.payload_properties is not None
|
||||||
|
|
||||||
if secondary:
|
if self.secondary:
|
||||||
payload_arcname = Payload.SECONDARY_PAYLOAD_BIN
|
payload_arcname = Payload.SECONDARY_PAYLOAD_BIN
|
||||||
payload_properties_arcname = Payload.SECONDARY_PAYLOAD_PROPERTIES_TXT
|
payload_properties_arcname = Payload.SECONDARY_PAYLOAD_PROPERTIES_TXT
|
||||||
else:
|
else:
|
||||||
|
@ -1327,10 +1335,10 @@ def WriteABOTAPackageWithBrilloScript(target_file, output_file,
|
||||||
# We always include a full payload for the secondary slot, even when
|
# We always include a full payload for the secondary slot, even when
|
||||||
# building an incremental OTA. See the comments for "--include_secondary".
|
# building an incremental OTA. See the comments for "--include_secondary".
|
||||||
secondary_target_file = GetTargetFilesZipForSecondaryImages(target_file)
|
secondary_target_file = GetTargetFilesZipForSecondaryImages(target_file)
|
||||||
secondary_payload = Payload()
|
secondary_payload = Payload(secondary=True)
|
||||||
secondary_payload.Generate(secondary_target_file)
|
secondary_payload.Generate(secondary_target_file)
|
||||||
secondary_payload.Sign(payload_signer)
|
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
|
# If dm-verity is supported for the device, copy contents of care_map
|
||||||
# into A/B OTA package.
|
# into A/B OTA package.
|
||||||
|
|
|
@ -643,7 +643,7 @@ class PayloadTest(unittest.TestCase):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _create_payload_full(secondary=False):
|
def _create_payload_full(secondary=False):
|
||||||
target_file = construct_target_files(secondary)
|
target_file = construct_target_files(secondary)
|
||||||
payload = Payload()
|
payload = Payload(secondary)
|
||||||
payload.Generate(target_file)
|
payload.Generate(target_file)
|
||||||
return payload
|
return payload
|
||||||
|
|
||||||
|
@ -713,6 +713,13 @@ class PayloadTest(unittest.TestCase):
|
||||||
with open(payload.payload_properties) as properties_fp:
|
with open(payload.payload_properties) as properties_fp:
|
||||||
self.assertIn("POWERWASH=1", properties_fp.read())
|
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):
|
def test_Sign_badSigner(self):
|
||||||
"""Tests that signing failure can be captured."""
|
"""Tests that signing failure can be captured."""
|
||||||
payload = self._create_payload_full()
|
payload = self._create_payload_full()
|
||||||
|
@ -762,7 +769,7 @@ class PayloadTest(unittest.TestCase):
|
||||||
|
|
||||||
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:
|
||||||
payload.WriteToZip(output_zip, secondary=True)
|
payload.WriteToZip(output_zip)
|
||||||
|
|
||||||
with zipfile.ZipFile(output_file) as verify_zip:
|
with zipfile.ZipFile(output_file) as verify_zip:
|
||||||
# First make sure we have the essential entries.
|
# First make sure we have the essential entries.
|
||||||
|
|
Loading…
Reference in a new issue