blob: 966a8111fb4d5ae78c88103bdbaa4e3cfd102a6b [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.')
Vyshu92153902021-06-16 13:31:53 -040022 parser.add_argument('--version', required=True,
23 help='The chromeos version string.')
Jae Hoon Kim2f8c62a2021-06-22 15:10:43 -070024 parser.add_argument('--image', type='path', required=True,
Amin Hassanic7febef2021-05-04 11:26:22 -070025 help='The path to the chromium os image.')
Jae Hoon Kimd99d9e02021-06-15 13:56:30 -070026 parser.add_argument('--keys-dir', type='path',
27 help='The path to keyset.',
28 default=constants.VBOOT_DEVKEYS_DIR)
Jae Hoon Kim2f8c62a2021-06-22 15:10:43 -070029 parser.add_argument('--public-key',
Henry Barnor38b98f12022-02-15 23:55:34 -080030 help='Filename to the public key whose private part '
Jae Hoon Kimd99d9e02021-06-15 13:56:30 -070031 'signed the keyblock.',
Henry Barnor38b98f12022-02-15 23:55:34 -080032 default=constants.RECOVERY_PUBLIC_KEY)
Jae Hoon Kim2f8c62a2021-06-22 15:10:43 -070033 parser.add_argument('--private-key',
Henry Barnor38b98f12022-02-15 23:55:34 -080034 help='Filename to the private key whose public part is '
Jae Hoon Kimd99d9e02021-06-15 13:56:30 -070035 'baked into the keyblock.',
Henry Barnor38b98f12022-02-15 23:55:34 -080036 default=constants.MINIOS_DATA_PRIVATE_KEY)
Jae Hoon Kim2f8c62a2021-06-22 15:10:43 -070037 parser.add_argument('--keyblock',
Jae Hoon Kimd99d9e02021-06-15 13:56:30 -070038 help='Filename to the kernel keyblock.',
Jae Hoon Kim4e35db82021-06-16 13:05:44 -070039 default=constants.MINIOS_KEYBLOCK)
Jae Hoon Kim39c62d82021-06-16 17:25:19 -070040 parser.add_argument('--serial', type=str,
41 help='Serial port for the kernel console (e.g. printks)')
Henry Barnore0dfd562022-02-16 10:01:54 -080042 parser.add_argument('--mod-for-dev', action='store_true',
43 help='Repack the MiniOS image with debug flags.')
44 parser.add_argument('--force-build', action='store_true',
45 help='Force the kernel to be rebuilt when repacking with '
46 'debug flags. Use with --mod-for-dev in case kernel is '
47 'not already built or needs to be rebuilt.')
Amin Hassanic7febef2021-05-04 11:26:22 -070048 return parser
49
50
51def main(argv):
52 parser = GetParser()
53 opts = parser.parse_args(argv)
54 opts.Freeze()
55
56 with tempfile.TemporaryDirectory() as work_dir:
Henry Barnore0dfd562022-02-16 10:01:54 -080057 build_kernel = opts.force_build if opts.mod_for_dev else True
Vyshu92153902021-06-16 13:31:53 -040058 kernel = minios.CreateMiniOsKernelImage(opts.board, opts.version, work_dir,
Jae Hoon Kimd99d9e02021-06-15 13:56:30 -070059 opts.keys_dir, opts.public_key,
Jae Hoon Kim39c62d82021-06-16 17:25:19 -070060 opts.private_key, opts.keyblock,
Henry Barnore0dfd562022-02-16 10:01:54 -080061 opts.serial, build_kernel,
62 opts.mod_for_dev)
Amin Hassanic7febef2021-05-04 11:26:22 -070063 minios.InsertMiniOsKernelImage(opts.image, kernel)