Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 667ff572 authored by Tao Bao's avatar Tao Bao
Browse files

releasetools: Specify SWITCH_SLOT_ON_REBOOT for secondary payload.

The secondary payload should always be applied with
SWITCH_SLOT_ON_REBOOT=0. This CL moves the 'secondary' parameter from
Payload.WriteToZip() to Payload.__init__(). So it can append the flag to
secondary/payload_properties.txt.

Bug: 35724498
Test: Generate an A/B OTA with --include_secondary. Check
      secondary/payload_properties.txt entry in the generated ZIP.
Test: `python -m unittest test_ota_from_target_files`
Change-Id: I816c07ab57a1c8a52eff785801634b8b1cb134d4
parent bec8be51
Loading
Loading
Loading
Loading
+15 −7
Original line number Diff line number Diff line
@@ -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:
@@ -1319,10 +1327,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.
+9 −2
Original line number Diff line number Diff line
@@ -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.