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 | |
Jae Hoon Kim | 9f0c939 | 2023-02-08 06:27:48 +0000 | [diff] [blame^] | 10 | import os |
Amin Hassani | c7febef | 2021-05-04 11:26:22 -0700 | [diff] [blame] | 11 | import tempfile |
| 12 | |
| 13 | from chromite.lib import commandline |
Jae Hoon Kim | d99d9e0 | 2021-06-15 13:56:30 -0700 | [diff] [blame] | 14 | from chromite.lib import constants |
Amin Hassani | c7febef | 2021-05-04 11:26:22 -0700 | [diff] [blame] | 15 | from chromite.lib import minios |
| 16 | |
| 17 | |
| 18 | def GetParser(): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 19 | """Creates an argument parser and returns it.""" |
| 20 | parser = commandline.ArgumentParser(description=__doc__) |
| 21 | parser.add_argument( |
| 22 | "--board", "-b", "--build-target", required=True, help="The board name." |
| 23 | ) |
| 24 | parser.add_argument( |
| 25 | "--version", required=True, help="The chromeos version string." |
| 26 | ) |
| 27 | parser.add_argument( |
| 28 | "--image", |
| 29 | type="path", |
| 30 | required=True, |
| 31 | help="The path to the chromium os image.", |
| 32 | ) |
| 33 | parser.add_argument( |
| 34 | "--keys-dir", |
| 35 | type="path", |
| 36 | help="The path to keyset.", |
| 37 | default=constants.VBOOT_DEVKEYS_DIR, |
| 38 | ) |
| 39 | parser.add_argument( |
| 40 | "--public-key", |
| 41 | help="Filename to the public key whose private part " |
| 42 | "signed the keyblock.", |
| 43 | default=constants.RECOVERY_PUBLIC_KEY, |
| 44 | ) |
| 45 | parser.add_argument( |
| 46 | "--private-key", |
| 47 | help="Filename to the private key whose public part is " |
| 48 | "baked into the keyblock.", |
| 49 | default=constants.MINIOS_DATA_PRIVATE_KEY, |
| 50 | ) |
| 51 | parser.add_argument( |
| 52 | "--keyblock", |
| 53 | help="Filename to the kernel keyblock.", |
| 54 | default=constants.MINIOS_KEYBLOCK, |
| 55 | ) |
| 56 | parser.add_argument( |
| 57 | "--serial", |
| 58 | type=str, |
| 59 | help="Serial port for the kernel console (e.g. printks)", |
| 60 | ) |
| 61 | parser.add_argument( |
| 62 | "--mod-for-dev", |
| 63 | action="store_true", |
| 64 | help="Repack the MiniOS image with debug flags.", |
| 65 | ) |
| 66 | parser.add_argument( |
| 67 | "--force-build", |
| 68 | action="store_true", |
| 69 | help="Force the kernel to be rebuilt when repacking with " |
| 70 | "debug flags. Use with --mod-for-dev in case kernel is " |
| 71 | "not already built or needs to be rebuilt.", |
| 72 | ) |
Jae Hoon Kim | 9f0c939 | 2023-02-08 06:27:48 +0000 | [diff] [blame^] | 73 | parser.add_argument( |
| 74 | "--jobs", |
| 75 | type=int, |
| 76 | default=os.cpu_count(), |
| 77 | help="Number of packages to build in parallel. " |
| 78 | "(Default: %(default)s)", |
| 79 | ) |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 80 | return parser |
Amin Hassani | c7febef | 2021-05-04 11:26:22 -0700 | [diff] [blame] | 81 | |
| 82 | |
| 83 | def main(argv): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 84 | parser = GetParser() |
| 85 | opts = parser.parse_args(argv) |
| 86 | opts.Freeze() |
Amin Hassani | c7febef | 2021-05-04 11:26:22 -0700 | [diff] [blame] | 87 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 88 | with tempfile.TemporaryDirectory() as work_dir: |
| 89 | build_kernel = opts.force_build if opts.mod_for_dev else True |
| 90 | kernel = minios.CreateMiniOsKernelImage( |
| 91 | opts.board, |
| 92 | opts.version, |
| 93 | work_dir, |
| 94 | opts.keys_dir, |
| 95 | opts.public_key, |
| 96 | opts.private_key, |
| 97 | opts.keyblock, |
| 98 | opts.serial, |
Jae Hoon Kim | 9f0c939 | 2023-02-08 06:27:48 +0000 | [diff] [blame^] | 99 | opts.jobs, |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 100 | build_kernel, |
| 101 | opts.mod_for_dev, |
| 102 | ) |
| 103 | minios.InsertMiniOsKernelImage(opts.image, kernel) |