diff options
author | Yifan Hong <elsk@google.com> | 2020-08-28 18:51:00 -0700 |
---|---|---|
committer | Yifan Hong <elsk@google.com> | 2020-09-01 14:29:28 -0700 |
commit | 480d183425d6d2ce98b79a43b4674f6eb72a30cf (patch) | |
tree | cd4ff923eb422aeba1e3725ec1fdc2a64c248df8 | |
parent | 370a397ab453f214a0611bb82cdeafcb0f4a0681 (diff) | |
download | extras-480d183425d6d2ce98b79a43b4674f6eb72a30cf.tar.gz |
Add GKI kernel release to PartitionUpdate.version
so that update_engine can use this field to prevent downgrade of GKI.
Test: ota_from_raw_image_test
Test: apply GKI APEX update
Bug: 162623577
Change-Id: Ifdef2b2da795ceb52ac378306a032e311fbc806c
-rw-r--r-- | gki/Android.bp | 37 | ||||
-rw-r--r-- | gki/TEST_MAPPING | 8 | ||||
-rw-r--r-- | gki/ota_from_raw_image.py | 32 | ||||
-rw-r--r-- | gki/ota_from_raw_image_test.py | 35 |
4 files changed, 103 insertions, 9 deletions
diff --git a/gki/Android.bp b/gki/Android.bp index 1d907cdd..a56bf0f8 100644 --- a/gki/Android.bp +++ b/gki/Android.bp @@ -14,12 +14,23 @@ // limitations under the License. // -python_binary_host { - name: "ota_from_raw_image", - srcs: ["ota_from_raw_image.py",], +python_defaults { + name: "ota_from_raw_image_defaults", libs: [ "releasetools_ota_from_target_files", ], + target: { + darwin: { + // required module "brillo_update_payload" is disabled on darwin + enabled: false, + }, + }, +} + +python_binary_host { + name: "ota_from_raw_image", + defaults: ["ota_from_raw_image_defaults"], + srcs: ["ota_from_raw_image.py"], required: [ "brillo_update_payload", ], @@ -28,10 +39,22 @@ python_binary_host { embedded_launcher: true, }, }, - target: { - darwin: { - // required module "brillo_update_payload" is disabled on darwin - enabled: false, +} + +python_test_host { + name: "ota_from_raw_image_test", + defaults: ["ota_from_raw_image_defaults"], + test_suites: ["general-tests"], + srcs: [ + "ota_from_raw_image.py", + "ota_from_raw_image_test.py", + ], + version: { + py3: { + // When using embedded launcher, atest will try (but may fail) to load libc++.so from + // host, because the test executable won't be able to find the needed libs via its + // runpath. + embedded_launcher: false, }, }, } diff --git a/gki/TEST_MAPPING b/gki/TEST_MAPPING new file mode 100644 index 00000000..1479c90d --- /dev/null +++ b/gki/TEST_MAPPING @@ -0,0 +1,8 @@ +{ + "presubmit": [ + { + "name": "ota_from_raw_image_test", + "host": true + } + ] +} diff --git a/gki/ota_from_raw_image.py b/gki/ota_from_raw_image.py index f545a686..c6b4ea07 100644 --- a/gki/ota_from_raw_image.py +++ b/gki/ota_from_raw_image.py @@ -21,6 +21,7 @@ Generate payload.bin from a single image. import argparse import logging import os +import re import shutil import sys from zipfile import ZipFile @@ -39,6 +40,9 @@ def _ParseArgs(): parser.add_argument("--key", type=str, help="Key to use to sign the package. If unspecified, script does not sign " "the package and payload_properties.txt is not generated.") + parser.add_argument("--kernel-release-file", type=str, + help="If boot is in input, a file containing the kernel release of the boot " + "image. Create the file with `extract_kernel --output-release`.") parser.add_argument("--out", type=str, required=True, help="Required output directory to payload.bin and payload_properties.txt") parser.add_argument("input", metavar="NAME:IMAGE", nargs="+", @@ -60,10 +64,31 @@ def _PrepareEnvironment(args): os.environ["GENERATOR"] = path +def _GetKernelRelease(line): + """ + Get GKI kernel release string from the given line. + """ + PATTERN = r"^(\d+[.]\d+[.]\d+-android\d+-\d+).*$" + mo = re.match(PATTERN, line) + assert mo, "Kernel release '{}' does not match regex r'{}'".format(line, PATTERN) + return mo.group(1) + + +def _GetKernelReleaseFromFile(filename): + """ + Get GKI kernel release string from the given text file. + """ + assert filename, "--kernel-release-file must be specified if boot is in input" + with open(filename) as f: + line = f.read().strip() + return _GetKernelRelease(line) + + def CreateOtaFromRawImages(args): _PrepareEnvironment(args) tf = common.MakeTempFile("target_files", ".zip") + payload_additional_args = ["--is_partial_update", "true"] with ZipFile(tf, "w") as zip: names = [] for pair_str in args.input: @@ -72,6 +97,10 @@ def CreateOtaFromRawImages(args): name, img_path = tuple(pair) zip.write(img_path, arcname=os.path.join("IMAGES", name + ".img")) names.append(name) + if name == "boot": + payload_additional_args += ["--partition_timestamps", + "boot:" + _GetKernelReleaseFromFile(args.kernel_release_file)] + zip.writestr("META/ab_partitions.txt", "\n".join(names) + "\n") zip.writestr("META/dynamic_partitions_info.txt", """ virtual_ab=true @@ -79,8 +108,7 @@ super_partition_groups= """) payload = Payload() - additional_args = ["--is_partial_update", "true"] - payload.Generate(tf, None, additional_args) + payload.Generate(tf, None, payload_additional_args) if args.key: OPTIONS.package_key = args.key diff --git a/gki/ota_from_raw_image_test.py b/gki/ota_from_raw_image_test.py new file mode 100644 index 00000000..0151547f --- /dev/null +++ b/gki/ota_from_raw_image_test.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2020 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest +from ota_from_raw_image import _GetKernelRelease + + +class OtaFromRawImageTest(unittest.TestCase): + def test_get_kernel_release_trivial(self): + self.assertEqual("5.4.42-android12-15", _GetKernelRelease("5.4.42-android12-15")) + + def test_get_kernel_release_suffix(self): + self.assertEqual("5.4.42-android12-15", _GetKernelRelease("5.4.42-android12-15-something")) + + def test_get_kernel_release_invalid(self): + with self.assertRaises(AssertionError): + _GetKernelRelease("5.4-android12-15") + + +if __name__ == '__main__': + # atest needs a verbosity level of >= 2 to correctly parse the result. + unittest.main(verbosity=2) |