Tudor Brindus | 3e03eba | 2018-07-18 11:27:13 -0700 | [diff] [blame] | 1 | # Copyright 2018 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 | """Script to generate a Chromium OS update for use by the update engine. |
| 6 | |
| 7 | If a source .bin is specified, the update is assumed to be a delta update. |
| 8 | """ |
| 9 | |
Chris McDonald | 59650c3 | 2021-07-20 15:29:28 -0600 | [diff] [blame] | 10 | import logging |
| 11 | |
Tudor Brindus | 3e03eba | 2018-07-18 11:27:13 -0700 | [diff] [blame] | 12 | from chromite.lib import commandline |
Amin Hassani | 6bc73a1 | 2018-11-29 21:07:12 -0800 | [diff] [blame] | 13 | from chromite.lib.paygen import paygen_payload_lib |
Tudor Brindus | 3e03eba | 2018-07-18 11:27:13 -0700 | [diff] [blame] | 14 | |
| 15 | |
| 16 | def ParseArguments(argv): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame^] | 17 | """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 Brindus | 3e03eba | 2018-07-18 11:27:13 -0700 | [diff] [blame] | 65 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame^] | 66 | opts = parser.parse_args(argv) |
| 67 | opts.Freeze() |
Tudor Brindus | 3e03eba | 2018-07-18 11:27:13 -0700 | [diff] [blame] | 68 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame^] | 69 | return opts |
Tudor Brindus | 3e03eba | 2018-07-18 11:27:13 -0700 | [diff] [blame] | 70 | |
| 71 | |
| 72 | def main(argv): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame^] | 73 | opts = ParseArguments(argv) |
Tudor Brindus | 3e03eba | 2018-07-18 11:27:13 -0700 | [diff] [blame] | 74 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame^] | 75 | 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 Hassani | ff61884 | 2019-06-02 21:43:14 -0700 | [diff] [blame] | 82 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame^] | 83 | 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 | ) |