Amin Hassani | c7febef | 2021-05-04 11:26:22 -0700 | [diff] [blame] | 1 | # Copyright 2021 The Chromium OS Authors. All rights reserved. |
| 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(): |
| 18 | """Creates an argument parser and returns it.""" |
| 19 | parser = commandline.ArgumentParser(description=__doc__) |
| 20 | parser.add_argument('--board', '-b', '--build-target', required=True, |
| 21 | help='The board name.') |
Vyshu | 9215390 | 2021-06-16 13:31:53 -0400 | [diff] [blame] | 22 | parser.add_argument('--version', required=True, |
| 23 | help='The chromeos version string.') |
Jae Hoon Kim | 2f8c62a | 2021-06-22 15:10:43 -0700 | [diff] [blame] | 24 | parser.add_argument('--image', type='path', required=True, |
Amin Hassani | c7febef | 2021-05-04 11:26:22 -0700 | [diff] [blame] | 25 | help='The path to the chromium os image.') |
Jae Hoon Kim | d99d9e0 | 2021-06-15 13:56:30 -0700 | [diff] [blame] | 26 | parser.add_argument('--keys-dir', type='path', |
| 27 | help='The path to keyset.', |
| 28 | default=constants.VBOOT_DEVKEYS_DIR) |
Jae Hoon Kim | 2f8c62a | 2021-06-22 15:10:43 -0700 | [diff] [blame] | 29 | parser.add_argument('--public-key', |
Jae Hoon Kim | d99d9e0 | 2021-06-15 13:56:30 -0700 | [diff] [blame] | 30 | help='Filename to the public key whose private part '\ |
| 31 | 'signed the keyblock.', |
| 32 | default=constants.RECOVERY_PUBLIC_KEY ) |
Jae Hoon Kim | 2f8c62a | 2021-06-22 15:10:43 -0700 | [diff] [blame] | 33 | parser.add_argument('--private-key', |
Jae Hoon Kim | d99d9e0 | 2021-06-15 13:56:30 -0700 | [diff] [blame] | 34 | help='Filename to the private key whose public part is '\ |
| 35 | 'baked into the keyblock.', |
Jae Hoon Kim | 4e35db8 | 2021-06-16 13:05:44 -0700 | [diff] [blame^] | 36 | default=constants.MINIOS_DATA_PRIVATE_KEY ) |
Jae Hoon Kim | 2f8c62a | 2021-06-22 15:10:43 -0700 | [diff] [blame] | 37 | parser.add_argument('--keyblock', |
Jae Hoon Kim | d99d9e0 | 2021-06-15 13:56:30 -0700 | [diff] [blame] | 38 | help='Filename to the kernel keyblock.', |
Jae Hoon Kim | 4e35db8 | 2021-06-16 13:05:44 -0700 | [diff] [blame^] | 39 | default=constants.MINIOS_KEYBLOCK) |
Jae Hoon Kim | 39c62d8 | 2021-06-16 17:25:19 -0700 | [diff] [blame] | 40 | parser.add_argument('--serial', type=str, |
| 41 | help='Serial port for the kernel console (e.g. printks)') |
Amin Hassani | c7febef | 2021-05-04 11:26:22 -0700 | [diff] [blame] | 42 | return parser |
| 43 | |
| 44 | |
| 45 | def main(argv): |
| 46 | parser = GetParser() |
| 47 | opts = parser.parse_args(argv) |
| 48 | opts.Freeze() |
| 49 | |
| 50 | with tempfile.TemporaryDirectory() as work_dir: |
Vyshu | 9215390 | 2021-06-16 13:31:53 -0400 | [diff] [blame] | 51 | kernel = minios.CreateMiniOsKernelImage(opts.board, opts.version, work_dir, |
Jae Hoon Kim | d99d9e0 | 2021-06-15 13:56:30 -0700 | [diff] [blame] | 52 | opts.keys_dir, opts.public_key, |
Jae Hoon Kim | 39c62d8 | 2021-06-16 17:25:19 -0700 | [diff] [blame] | 53 | opts.private_key, opts.keyblock, |
| 54 | opts.serial) |
Amin Hassani | c7febef | 2021-05-04 11:26:22 -0700 | [diff] [blame] | 55 | minios.InsertMiniOsKernelImage(opts.image, kernel) |