| #!/usr/bin/env python3 |
| # |
| # Copyright 2021, 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. |
| # |
| |
| """Generate a Generic Boot Image certificate suitable for VTS verification.""" |
| |
| from argparse import ArgumentParser |
| import subprocess |
| |
| |
| def generate_gki_certificate(image, avbtool, name, algorithm, key, salt, |
| additional_avb_args, output): |
| """Shell out to avbtool to generate a GKI certificate.""" |
| |
| # Need to specify a value of --partition_size for avbtool to work. |
| # We use 64 MB below, but avbtool will not resize the boot image to |
| # this size because --do_not_append_vbmeta_image is also specified. |
| avbtool_cmd = [ |
| avbtool, 'add_hash_footer', |
| '--partition_name', name, |
| '--partition_size', str(64 * 1024 * 1024), |
| '--image', image, |
| '--algorithm', algorithm, |
| '--key', key, |
| '--do_not_append_vbmeta_image', |
| '--output_vbmeta_image', output, |
| ] |
| |
| if salt is not None: |
| avbtool_cmd += ['--salt', salt] |
| |
| avbtool_cmd += additional_avb_args |
| |
| subprocess.check_call(avbtool_cmd) |