Mike Frysinger | f1ba7ad | 2022-09-12 05:42:57 -0400 | [diff] [blame^] | 1 | # Copyright 2021 The ChromiumOS Authors |
Amin Hassani | c7febef | 2021-05-04 11:26:22 -0700 | [diff] [blame] | 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """A script to generate MiniOS kernel images. |
| 6 | |
| 7 | And inserting them into the Chromium OS images. |
| 8 | """ |
| 9 | |
| 10 | import tempfile |
| 11 | |
| 12 | from chromite.lib import commandline |
Jae Hoon Kim | d99d9e0 | 2021-06-15 13:56:30 -0700 | [diff] [blame] | 13 | from chromite.lib import constants |
Amin Hassani | c7febef | 2021-05-04 11:26:22 -0700 | [diff] [blame] | 14 | from chromite.lib import minios |
| 15 | |
| 16 | |
| 17 | def GetParser(): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 18 | """Creates an argument parser and returns it.""" |
| 19 | parser = commandline.ArgumentParser(description=__doc__) |
| 20 | parser.add_argument( |
| 21 | "--board", "-b", "--build-target", required=True, help="The board name." |
| 22 | ) |
| 23 | parser.add_argument( |
| 24 | "--version", required=True, help="The chromeos version string." |
| 25 | ) |
| 26 | parser.add_argument( |
| 27 | "--image", |
| 28 | type="path", |
| 29 | required=True, |
| 30 | help="The path to the chromium os image.", |
| 31 | ) |
| 32 | parser.add_argument( |
| 33 | "--keys-dir", |
| 34 | type="path", |
| 35 | help="The path to keyset.", |
| 36 | default=constants.VBOOT_DEVKEYS_DIR, |
| 37 | ) |
| 38 | parser.add_argument( |
| 39 | "--public-key", |
| 40 | help="Filename to the public key whose private part " |
| 41 | "signed the keyblock.", |
| 42 | default=constants.RECOVERY_PUBLIC_KEY, |
| 43 | ) |
| 44 | parser.add_argument( |
| 45 | "--private-key", |
| 46 | help="Filename to the private key whose public part is " |
| 47 | "baked into the keyblock.", |
| 48 | default=constants.MINIOS_DATA_PRIVATE_KEY, |
| 49 | ) |
| 50 | parser.add_argument( |
| 51 | "--keyblock", |
| 52 | help="Filename to the kernel keyblock.", |
| 53 | default=constants.MINIOS_KEYBLOCK, |
| 54 | ) |
| 55 | parser.add_argument( |
| 56 | "--serial", |
| 57 | type=str, |
| 58 | help="Serial port for the kernel console (e.g. printks)", |
| 59 | ) |
| 60 | parser.add_argument( |
| 61 | "--mod-for-dev", |
| 62 | action="store_true", |
| 63 | help="Repack the MiniOS image with debug flags.", |
| 64 | ) |
| 65 | parser.add_argument( |
| 66 | "--force-build", |
| 67 | action="store_true", |
| 68 | help="Force the kernel to be rebuilt when repacking with " |
| 69 | "debug flags. Use with --mod-for-dev in case kernel is " |
| 70 | "not already built or needs to be rebuilt.", |
| 71 | ) |
| 72 | return parser |
Amin Hassani | c7febef | 2021-05-04 11:26:22 -0700 | [diff] [blame] | 73 | |
| 74 | |
| 75 | def main(argv): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 76 | parser = GetParser() |
| 77 | opts = parser.parse_args(argv) |
| 78 | opts.Freeze() |
Amin Hassani | c7febef | 2021-05-04 11:26:22 -0700 | [diff] [blame] | 79 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 80 | with tempfile.TemporaryDirectory() as work_dir: |
| 81 | build_kernel = opts.force_build if opts.mod_for_dev else True |
| 82 | kernel = minios.CreateMiniOsKernelImage( |
| 83 | opts.board, |
| 84 | opts.version, |
| 85 | work_dir, |
| 86 | opts.keys_dir, |
| 87 | opts.public_key, |
| 88 | opts.private_key, |
| 89 | opts.keyblock, |
| 90 | opts.serial, |
| 91 | build_kernel, |
| 92 | opts.mod_for_dev, |
| 93 | ) |
| 94 | minios.InsertMiniOsKernelImage(opts.image, kernel) |