blob: 7140ba7f94acdede96b8f0835c58ae6e4e52aaf6 [file] [log] [blame]
Mike Frysingerf1ba7ad2022-09-12 05:42:57 -04001# Copyright 2021 The ChromiumOS Authors
Amin Hassanic7febef2021-05-04 11:26:22 -07002# 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
Jae Hoon Kim9f0c9392023-02-08 06:27:48 +000010import os
Amin Hassanic7febef2021-05-04 11:26:22 -070011import tempfile
12
13from chromite.lib import commandline
Jae Hoon Kimd99d9e02021-06-15 13:56:30 -070014from chromite.lib import constants
Amin Hassanic7febef2021-05-04 11:26:22 -070015from chromite.lib import minios
16
17
18def GetParser():
Alex Klein1699fab2022-09-08 08:46:06 -060019 """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 Kim9f0c9392023-02-08 06:27:48 +000073 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 Klein1699fab2022-09-08 08:46:06 -060080 return parser
Amin Hassanic7febef2021-05-04 11:26:22 -070081
82
83def main(argv):
Alex Klein1699fab2022-09-08 08:46:06 -060084 parser = GetParser()
85 opts = parser.parse_args(argv)
86 opts.Freeze()
Amin Hassanic7febef2021-05-04 11:26:22 -070087
Alex Klein1699fab2022-09-08 08:46:06 -060088 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 Kim9f0c9392023-02-08 06:27:48 +000099 opts.jobs,
Alex Klein1699fab2022-09-08 08:46:06 -0600100 build_kernel,
101 opts.mod_for_dev,
102 )
103 minios.InsertMiniOsKernelImage(opts.image, kernel)