blob: d0585ea73e86850bfcdbedafc2bfe3bf4c09c0a0 [file] [log] [blame]
Amin Hassanic7febef2021-05-04 11:26:22 -07001# 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
7And inserting them into the Chromium OS images.
8"""
9
10import tempfile
11
12from chromite.lib import commandline
Jae Hoon Kimd99d9e02021-06-15 13:56:30 -070013from chromite.lib import constants
Amin Hassanic7febef2021-05-04 11:26:22 -070014from chromite.lib import minios
15
16
17def 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.')
Jae Hoon Kim2f8c62a2021-06-22 15:10:43 -070022 parser.add_argument('--image', type='path', required=True,
Amin Hassanic7febef2021-05-04 11:26:22 -070023 help='The path to the chromium os image.')
Jae Hoon Kimd99d9e02021-06-15 13:56:30 -070024 parser.add_argument('--keys-dir', type='path',
25 help='The path to keyset.',
26 default=constants.VBOOT_DEVKEYS_DIR)
Jae Hoon Kim2f8c62a2021-06-22 15:10:43 -070027 parser.add_argument('--public-key',
Jae Hoon Kimd99d9e02021-06-15 13:56:30 -070028 help='Filename to the public key whose private part '\
29 'signed the keyblock.',
30 default=constants.RECOVERY_PUBLIC_KEY )
Jae Hoon Kim2f8c62a2021-06-22 15:10:43 -070031 parser.add_argument('--private-key',
Jae Hoon Kimd99d9e02021-06-15 13:56:30 -070032 help='Filename to the private key whose public part is '\
33 'baked into the keyblock.',
34 default=constants.RECOVERY_DATA_PRIVATE_KEY )
Jae Hoon Kim2f8c62a2021-06-22 15:10:43 -070035 parser.add_argument('--keyblock',
Jae Hoon Kimd99d9e02021-06-15 13:56:30 -070036 help='Filename to the kernel keyblock.',
37 default=constants.RECOVERY_KEYBLOCK)
Jae Hoon Kim39c62d82021-06-16 17:25:19 -070038 parser.add_argument('--serial', type=str,
39 help='Serial port for the kernel console (e.g. printks)')
Amin Hassanic7febef2021-05-04 11:26:22 -070040 return parser
41
42
43def main(argv):
44 parser = GetParser()
45 opts = parser.parse_args(argv)
46 opts.Freeze()
47
48 with tempfile.TemporaryDirectory() as work_dir:
Jae Hoon Kimd99d9e02021-06-15 13:56:30 -070049 kernel = minios.CreateMiniOsKernelImage(opts.board, work_dir,
50 opts.keys_dir, opts.public_key,
Jae Hoon Kim39c62d82021-06-16 17:25:19 -070051 opts.private_key, opts.keyblock,
52 opts.serial)
Amin Hassanic7febef2021-05-04 11:26:22 -070053 minios.InsertMiniOsKernelImage(opts.image, kernel)