Mike Frysinger | f1ba7ad | 2022-09-12 09:42:57 | [diff] [blame] | 1 | # Copyright 2018 The ChromiumOS Authors |
Tudor Brindus | 3e03eba | 2018-07-18 18:27:13 | [diff] [blame] | 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 21:29:28 | [diff] [blame] | 10 | import logging |
| 11 | |
Brian Norris | 85e0fd2 | 2023-06-27 16:49:18 | [diff] [blame] | 12 | from chromite.lib import chroot_lib |
Tudor Brindus | 3e03eba | 2018-07-18 18:27:13 | [diff] [blame] | 13 | from chromite.lib import commandline |
Amin Hassani | 6bc73a1 | 2018-11-30 05:07:12 | [diff] [blame] | 14 | from chromite.lib.paygen import paygen_payload_lib |
Tudor Brindus | 3e03eba | 2018-07-18 18:27:13 | [diff] [blame] | 15 | |
| 16 | |
| 17 | def ParseArguments(argv): |
Alex Klein | 1699fab | 2022-09-08 14:46:06 | [diff] [blame] | 18 | """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 Frysinger | bb5f021 | 2023-12-20 20:45:09 | [diff] [blame] | 31 | parser.add_argument("--output", type="str_path", help="Output file.") |
Alex Klein | 1699fab | 2022-09-08 14:46:06 | [diff] [blame] | 32 | parser.add_argument( |
Mike Frysinger | bb5f021 | 2023-12-20 20:45:09 | [diff] [blame] | 33 | "--private-key", |
| 34 | type="str_path", |
| 35 | help="Path to private key in .pem format.", |
Alex Klein | 1699fab | 2022-09-08 14:46:06 | [diff] [blame] | 36 | ) |
| 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 Frysinger | bb5f021 | 2023-12-20 20:45:09 | [diff] [blame] | 56 | type="str_path", |
Alex Klein | 1699fab | 2022-09-08 14:46:06 | [diff] [blame] | 57 | help="Path to a temporary directory in the chroot.", |
| 58 | ) |
| 59 | parser.add_argument( |
| 60 | "--payload", |
Mike Frysinger | bb5f021 | 2023-12-20 20:45:09 | [diff] [blame] | 61 | type="str_path", |
Alex Klein | 1699fab | 2022-09-08 14:46:06 | [diff] [blame] | 62 | 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 Brindus | 3e03eba | 2018-07-18 18:27:13 | [diff] [blame] | 68 | |
Alex Klein | 1699fab | 2022-09-08 14:46:06 | [diff] [blame] | 69 | opts = parser.parse_args(argv) |
| 70 | opts.Freeze() |
Tudor Brindus | 3e03eba | 2018-07-18 18:27:13 | [diff] [blame] | 71 | |
Alex Klein | 1699fab | 2022-09-08 14:46:06 | [diff] [blame] | 72 | return opts |
Tudor Brindus | 3e03eba | 2018-07-18 18:27:13 | [diff] [blame] | 73 | |
| 74 | |
| 75 | def main(argv): |
Alex Klein | 1699fab | 2022-09-08 14:46:06 | [diff] [blame] | 76 | opts = ParseArguments(argv) |
Brian Norris | 85e0fd2 | 2023-06-27 16:49:18 | [diff] [blame] | 77 | chroot = chroot_lib.Chroot() |
Tudor Brindus | 3e03eba | 2018-07-18 18:27:13 | [diff] [blame] | 78 | |
Alex Klein | 1699fab | 2022-09-08 14:46:06 | [diff] [blame] | 79 | 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 Hassani | ff61884 | 2019-06-03 04:43:14 | [diff] [blame] | 86 | |
Alex Klein | 1699fab | 2022-09-08 14:46:06 | [diff] [blame] | 87 | return paygen_payload_lib.GenerateUpdatePayload( |
Brian Norris | 85e0fd2 | 2023-06-27 16:49:18 | [diff] [blame] | 88 | chroot, |
Alex Klein | 1699fab | 2022-09-08 14:46:06 | [diff] [blame] | 89 | 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 | ) |