blob: 239d8ae5db2266b785c04e4d7f0a54685ff51561 [file] [log] [blame]
Mike Frysingerf1ba7ad2022-09-12 09:42:571# Copyright 2018 The ChromiumOS Authors
Tudor Brindus3e03eba2018-07-18 18:27:132# 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 21:29:2810import logging
11
Brian Norris85e0fd22023-06-27 16:49:1812from chromite.lib import chroot_lib
Tudor Brindus3e03eba2018-07-18 18:27:1313from chromite.lib import commandline
Amin Hassani6bc73a12018-11-30 05:07:1214from chromite.lib.paygen import paygen_payload_lib
Tudor Brindus3e03eba2018-07-18 18:27:1315
16
17def ParseArguments(argv):
Alex Klein1699fab2022-09-08 14:46:0618 """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 )
Mike Frysingerbb5f0212023-12-20 20:45:0931 parser.add_argument("--output", type="str_path", help="Output file.")
Alex Klein1699fab2022-09-08 14:46:0632 parser.add_argument(
Mike Frysingerbb5f0212023-12-20 20:45:0933 "--private-key",
34 type="str_path",
35 help="Path to private key in .pem format.",
Alex Klein1699fab2022-09-08 14:46:0636 )
37 parser.add_argument(
38 "--check",
39 action="store_true",
40 help="If passed, verifies the integrity of the payload",
41 )
42 parser.add_argument(
43 "--extract",
44 action="store_true",
45 help="If set, extract old/new kernel/rootfs to "
46 "[old|new]_[kern|root].dat. Useful for debugging.",
47 )
48 parser.add_argument(
49 "--minios",
50 action="store_true",
51 help="If set, extract the miniOS partition, otherwise "
52 "extract the kernel and rootfs partitions.",
53 )
54 parser.add_argument(
55 "--work-dir",
Mike Frysingerbb5f0212023-12-20 20:45:0956 type="str_path",
Alex Klein1699fab2022-09-08 14:46:0657 help="Path to a temporary directory in the chroot.",
58 )
59 parser.add_argument(
60 "--payload",
Mike Frysingerbb5f0212023-12-20 20:45:0961 type="str_path",
Alex Klein1699fab2022-09-08 14:46:0662 help="Path to the input payload file. Only used when "
63 "trying to generate the payload properties file using "
64 "the given payload. If --output is not passed, the "
65 "payload properties file path will be generated by "
66 "appending .json to the payload filename itself.",
67 )
Tudor Brindus3e03eba2018-07-18 18:27:1368
Alex Klein1699fab2022-09-08 14:46:0669 opts = parser.parse_args(argv)
70 opts.Freeze()
Tudor Brindus3e03eba2018-07-18 18:27:1371
Alex Klein1699fab2022-09-08 14:46:0672 return opts
Tudor Brindus3e03eba2018-07-18 18:27:1373
74
75def main(argv):
Alex Klein1699fab2022-09-08 14:46:0676 opts = ParseArguments(argv)
Brian Norris85e0fd22023-06-27 16:49:1877 chroot = chroot_lib.Chroot()
Tudor Brindus3e03eba2018-07-18 18:27:1378
Alex Klein1699fab2022-09-08 14:46:0679 if opts.payload:
80 # We only want the payload's metadata. Create it and exit.
81 logging.info("Generating payload properties file.")
82 paygen_payload_lib.GenerateUpdatePayloadPropertiesFile(
83 opts.payload, opts.output
84 )
85 return
Amin Hassaniff618842019-06-03 04:43:1486
Alex Klein1699fab2022-09-08 14:46:0687 return paygen_payload_lib.GenerateUpdatePayload(
Brian Norris85e0fd22023-06-27 16:49:1888 chroot,
Alex Klein1699fab2022-09-08 14:46:0689 opts.tgt_image,
90 opts.output,
91 src_image=opts.src_image,
92 work_dir=opts.work_dir,
93 private_key=opts.private_key,
94 check=opts.check,
95 minios=opts.minios,
96 )