Mike Frysinger | f1ba7ad | 2022-09-12 05:42:57 -0400 | [diff] [blame] | 1 | # Copyright 2018 The ChromiumOS Authors |
Tudor Brindus | 3e03eba | 2018-07-18 11:27:13 -0700 | [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 15:29:28 -0600 | [diff] [blame] | 10 | import logging |
| 11 | |
Brian Norris | 85e0fd2 | 2023-06-27 09:49:18 -0700 | [diff] [blame] | 12 | from chromite.lib import chroot_lib |
Tudor Brindus | 3e03eba | 2018-07-18 11:27:13 -0700 | [diff] [blame] | 13 | from chromite.lib import commandline |
Amin Hassani | 6bc73a1 | 2018-11-29 21:07:12 -0800 | [diff] [blame] | 14 | from chromite.lib.paygen import paygen_payload_lib |
Tudor Brindus | 3e03eba | 2018-07-18 11:27:13 -0700 | [diff] [blame] | 15 | |
| 16 | |
| 17 | def ParseArguments(argv): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [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 | ) |
| 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 Brindus | 3e03eba | 2018-07-18 11:27:13 -0700 | [diff] [blame] | 66 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 67 | opts = parser.parse_args(argv) |
| 68 | opts.Freeze() |
Tudor Brindus | 3e03eba | 2018-07-18 11:27:13 -0700 | [diff] [blame] | 69 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 70 | return opts |
Tudor Brindus | 3e03eba | 2018-07-18 11:27:13 -0700 | [diff] [blame] | 71 | |
| 72 | |
| 73 | def main(argv): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 74 | opts = ParseArguments(argv) |
Brian Norris | 85e0fd2 | 2023-06-27 09:49:18 -0700 | [diff] [blame] | 75 | chroot = chroot_lib.Chroot() |
Tudor Brindus | 3e03eba | 2018-07-18 11:27:13 -0700 | [diff] [blame] | 76 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 77 | 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 Hassani | ff61884 | 2019-06-02 21:43:14 -0700 | [diff] [blame] | 84 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 85 | return paygen_payload_lib.GenerateUpdatePayload( |
Brian Norris | 85e0fd2 | 2023-06-27 09:49:18 -0700 | [diff] [blame] | 86 | chroot, |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 87 | 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 | ) |