blob: fc234cffd2ba10ce2cd8e6855d21216b003ba9f8 [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
Tudor Brindus3e03eba2018-07-18 11:27:13 -070012from chromite.lib import commandline
Amin Hassani6bc73a12018-11-29 21:07:12 -080013from chromite.lib.paygen import paygen_payload_lib
Tudor Brindus3e03eba2018-07-18 11:27:13 -070014
15
16def ParseArguments(argv):
Alex Klein1699fab2022-09-08 08:46:06 -060017 """Returns a namespace for the CLI arguments."""
18 parser = commandline.ArgumentParser(description=__doc__)
19 parser.add_argument(
20 "--tgt-image",
21 help="The path (to local disk or Google Storage Bucket)"
22 " of the target image to build the payload for.",
23 )
24 parser.add_argument(
25 "--src-image",
26 help="The path (to local disk or Google Storage Bucket)"
27 " of the source image. If specified, this makes a delta"
28 " update payload.",
29 )
30 parser.add_argument("--output", type="path", help="Output file.")
31 parser.add_argument(
32 "--private-key", type="path", help="Path to private key in .pem format."
33 )
34 parser.add_argument(
35 "--check",
36 action="store_true",
37 help="If passed, verifies the integrity of the payload",
38 )
39 parser.add_argument(
40 "--extract",
41 action="store_true",
42 help="If set, extract old/new kernel/rootfs to "
43 "[old|new]_[kern|root].dat. Useful for debugging.",
44 )
45 parser.add_argument(
46 "--minios",
47 action="store_true",
48 help="If set, extract the miniOS partition, otherwise "
49 "extract the kernel and rootfs partitions.",
50 )
51 parser.add_argument(
52 "--work-dir",
53 type="path",
54 help="Path to a temporary directory in the chroot.",
55 )
56 parser.add_argument(
57 "--payload",
58 type="path",
59 help="Path to the input payload file. Only used when "
60 "trying to generate the payload properties file using "
61 "the given payload. If --output is not passed, the "
62 "payload properties file path will be generated by "
63 "appending .json to the payload filename itself.",
64 )
Tudor Brindus3e03eba2018-07-18 11:27:13 -070065
Alex Klein1699fab2022-09-08 08:46:06 -060066 opts = parser.parse_args(argv)
67 opts.Freeze()
Tudor Brindus3e03eba2018-07-18 11:27:13 -070068
Alex Klein1699fab2022-09-08 08:46:06 -060069 return opts
Tudor Brindus3e03eba2018-07-18 11:27:13 -070070
71
72def main(argv):
Alex Klein1699fab2022-09-08 08:46:06 -060073 opts = ParseArguments(argv)
Tudor Brindus3e03eba2018-07-18 11:27:13 -070074
Alex Klein1699fab2022-09-08 08:46:06 -060075 if opts.payload:
76 # We only want the payload's metadata. Create it and exit.
77 logging.info("Generating payload properties file.")
78 paygen_payload_lib.GenerateUpdatePayloadPropertiesFile(
79 opts.payload, opts.output
80 )
81 return
Amin Hassaniff618842019-06-02 21:43:14 -070082
Alex Klein1699fab2022-09-08 08:46:06 -060083 return paygen_payload_lib.GenerateUpdatePayload(
84 opts.tgt_image,
85 opts.output,
86 src_image=opts.src_image,
87 work_dir=opts.work_dir,
88 private_key=opts.private_key,
89 check=opts.check,
90 minios=opts.minios,
91 )