blob: 762a1ac5eac03095c2dd0d6203f47532c19f6d04 [file] [log] [blame]
Mike Frysingerf1ba7ad2022-09-12 05:42:57 -04001# Copyright 2018 The ChromiumOS Authors
Tudor Brindus3e03eba2018-07-18 11:27:13 -07002# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""Script to generate a Chromium OS update for use by the update engine.
6
7If a source .bin is specified, the update is assumed to be a delta update.
8"""
9
Chris McDonald59650c32021-07-20 15:29:28 -060010import logging
11
Brian Norris85e0fd22023-06-27 09:49:18 -070012from chromite.lib import chroot_lib
Tudor Brindus3e03eba2018-07-18 11:27:13 -070013from chromite.lib import commandline
Amin Hassani6bc73a12018-11-29 21:07:12 -080014from chromite.lib.paygen import paygen_payload_lib
Tudor Brindus3e03eba2018-07-18 11:27:13 -070015
16
17def ParseArguments(argv):
Alex Klein1699fab2022-09-08 08:46:06 -060018 """Returns a namespace for the CLI arguments."""
19 parser = commandline.ArgumentParser(description=__doc__)
20 parser.add_argument(
21 "--tgt-image",
22 help="The path (to local disk or Google Storage Bucket)"
23 " of the target image to build the payload for.",
24 )
25 parser.add_argument(
26 "--src-image",
27 help="The path (to local disk or Google Storage Bucket)"
28 " of the source image. If specified, this makes a delta"
29 " update payload.",
30 )
31 parser.add_argument("--output", type="path", help="Output file.")
32 parser.add_argument(
33 "--private-key", type="path", help="Path to private key in .pem format."
34 )
35 parser.add_argument(
36 "--check",
37 action="store_true",
38 help="If passed, verifies the integrity of the payload",
39 )
40 parser.add_argument(
41 "--extract",
42 action="store_true",
43 help="If set, extract old/new kernel/rootfs to "
44 "[old|new]_[kern|root].dat. Useful for debugging.",
45 )
46 parser.add_argument(
47 "--minios",
48 action="store_true",
49 help="If set, extract the miniOS partition, otherwise "
50 "extract the kernel and rootfs partitions.",
51 )
52 parser.add_argument(
53 "--work-dir",
54 type="path",
55 help="Path to a temporary directory in the chroot.",
56 )
57 parser.add_argument(
58 "--payload",
59 type="path",
60 help="Path to the input payload file. Only used when "
61 "trying to generate the payload properties file using "
62 "the given payload. If --output is not passed, the "
63 "payload properties file path will be generated by "
64 "appending .json to the payload filename itself.",
65 )
Tudor Brindus3e03eba2018-07-18 11:27:13 -070066
Alex Klein1699fab2022-09-08 08:46:06 -060067 opts = parser.parse_args(argv)
68 opts.Freeze()
Tudor Brindus3e03eba2018-07-18 11:27:13 -070069
Alex Klein1699fab2022-09-08 08:46:06 -060070 return opts
Tudor Brindus3e03eba2018-07-18 11:27:13 -070071
72
73def main(argv):
Alex Klein1699fab2022-09-08 08:46:06 -060074 opts = ParseArguments(argv)
Brian Norris85e0fd22023-06-27 09:49:18 -070075 chroot = chroot_lib.Chroot()
Tudor Brindus3e03eba2018-07-18 11:27:13 -070076
Alex Klein1699fab2022-09-08 08:46:06 -060077 if opts.payload:
78 # We only want the payload's metadata. Create it and exit.
79 logging.info("Generating payload properties file.")
80 paygen_payload_lib.GenerateUpdatePayloadPropertiesFile(
81 opts.payload, opts.output
82 )
83 return
Amin Hassaniff618842019-06-02 21:43:14 -070084
Alex Klein1699fab2022-09-08 08:46:06 -060085 return paygen_payload_lib.GenerateUpdatePayload(
Brian Norris85e0fd22023-06-27 09:49:18 -070086 chroot,
Alex Klein1699fab2022-09-08 08:46:06 -060087 opts.tgt_image,
88 opts.output,
89 src_image=opts.src_image,
90 work_dir=opts.work_dir,
91 private_key=opts.private_key,
92 check=opts.check,
93 minios=opts.minios,
94 )