blob: 8529c623fbe0c50baa0c8ad0230f45c03ff4b1e9 [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():
Alex Klein1699fab2022-09-08 08:46:06 -060018 """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 Hassanic7febef2021-05-04 11:26:22 -070073
74
75def main(argv):
Alex Klein1699fab2022-09-08 08:46:06 -060076 parser = GetParser()
77 opts = parser.parse_args(argv)
78 opts.Freeze()
Amin Hassanic7febef2021-05-04 11:26:22 -070079
Alex Klein1699fab2022-09-08 08:46:06 -060080 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)