blob: 3200f89dc856c3291e5e8129d5dd9f85a0de7747 [file] [log] [blame]
Tudor Brindus3e03eba2018-07-18 11:27:13 -07001# -*- coding: utf-8 -*-
2# Copyright 2018 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""Script to generate a Chromium OS update for use by the update engine.
7
8If a source .bin is specified, the update is assumed to be a delta update.
9"""
10
11from __future__ import print_function
12
Tudor Brindus3e03eba2018-07-18 11:27:13 -070013from chromite.lib import commandline
Tudor Brindus3e03eba2018-07-18 11:27:13 -070014from chromite.lib import cros_logging as logging
Tudor Brindus3e03eba2018-07-18 11:27:13 -070015
Amin Hassanibdda5e42018-10-10 22:56:11 -070016from chromite.lib.paygen import partition_lib
Amin Hassani6bc73a12018-11-29 21:07:12 -080017from chromite.lib.paygen import paygen_payload_lib
Tudor Brindus3e03eba2018-07-18 11:27:13 -070018
19
20def ParseArguments(argv):
21 """Returns a namespace for the CLI arguments."""
22 parser = commandline.ArgumentParser(description=__doc__)
23 parser.add_argument('--image', type='path',
24 help='The image that should be sent to clients.')
25 parser.add_argument('--src_image', type='path',
26 help='A source image. If specified, this makes a delta '
27 'update.')
28 parser.add_argument('--output', type='path', help='Output file.')
Tudor Brindus3e03eba2018-07-18 11:27:13 -070029 parser.add_argument('--private_key', type='path',
30 help='Path to private key in .pem format.')
Amin Hassani6bc73a12018-11-29 21:07:12 -080031 parser.add_argument('--check', action='store_true',
32 help='If passed, verifies the integrity of the payload')
Tudor Brindus3e03eba2018-07-18 11:27:13 -070033 parser.add_argument('--out_metadata_hash_file', type='path',
34 help='Path to output metadata hash file.')
Tudor Brindus3e03eba2018-07-18 11:27:13 -070035 parser.add_argument('--extract', action='store_true',
36 help='If set, extract old/new kernel/rootfs to '
37 '[old|new]_[kern|root].dat. Useful for debugging.')
Amin Hassani6bc73a12018-11-29 21:07:12 -080038 parser.add_argument('--work_dir', type='path',
39 help='Path to a temporary directory in the chroot.')
Tudor Brindus3e03eba2018-07-18 11:27:13 -070040
41 # Specifying any of the following will cause it to not be cleaned up on exit.
42 parser.add_argument('--kern_path', type='path',
43 help='File path for extracting the kernel partition.')
44 parser.add_argument('--root_path', type='path',
45 help='File path for extracting the rootfs partition.')
46 parser.add_argument('--root_pretruncate_path', type='path',
47 help='File path for extracting the rootfs partition, '
48 'pre-truncation.')
49 parser.add_argument('--src_kern_path', type='path',
50 help='File path for extracting the source kernel '
51 'partition.')
52 parser.add_argument('--src_root_path', type='path',
53 help='File path for extracting the source root '
54 'partition.')
55
56 opts = parser.parse_args(argv)
57 opts.Freeze()
58
59 if not opts.extract and not opts.output:
60 parser.error('You must specify an output filename with --output FILENAME')
61
62 return opts
63
64
65def main(argv):
66 opts = ParseArguments(argv)
67
Amin Hassani6bc73a12018-11-29 21:07:12 -080068 if opts.kern_path:
69 partition_lib.ExtractKernel(opts.image, opts.kern_path)
70 if opts.root_path:
71 partition_lib.ExtractRoot(opts.image, opts.root_path)
72 if opts.root_pretruncate_path:
73 partition_lib.ExtractRoot(opts.image, opts.root_pretruncate_path,
74 truncate=False)
75
76 if opts.src_image:
77 if opts.src_kern_path:
78 partition_lib.ExtractKernel(opts.src_image, opts.src_kern_path)
79 if opts.src_root_path:
80 partition_lib.ExtractRoot(opts.src_image, opts.src_root_path)
81
82 if opts.extract:
83 # If we just wanted extraction, we did it, just return.
84 logging.info('Done extracting kernel/root.')
85 return
86
87 return paygen_payload_lib.GenerateUpdatePayload(
88 opts.image, opts.output, src_image=opts.src_image, work_dir=opts.work_dir,
89 private_key=opts.private_key, check=opts.check,
90 out_metadata_hash_file=opts.out_metadata_hash_file)