blob: 239d8ae5db2266b785c04e4d7f0a54685ff51561 [file] [log] [blame]
# Copyright 2018 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Script to generate a Chromium OS update for use by the update engine.
If a source .bin is specified, the update is assumed to be a delta update.
"""
import logging
from chromite.lib import chroot_lib
from chromite.lib import commandline
from chromite.lib.paygen import paygen_payload_lib
def ParseArguments(argv):
"""Returns a namespace for the CLI arguments."""
parser = commandline.ArgumentParser(description=__doc__)
parser.add_argument(
"--tgt-image",
help="The path (to local disk or Google Storage Bucket)"
" of the target image to build the payload for.",
)
parser.add_argument(
"--src-image",
help="The path (to local disk or Google Storage Bucket)"
" of the source image. If specified, this makes a delta"
" update payload.",
)
parser.add_argument("--output", type="str_path", help="Output file.")
parser.add_argument(
"--private-key",
type="str_path",
help="Path to private key in .pem format.",
)
parser.add_argument(
"--check",
action="store_true",
help="If passed, verifies the integrity of the payload",
)
parser.add_argument(
"--extract",
action="store_true",
help="If set, extract old/new kernel/rootfs to "
"[old|new]_[kern|root].dat. Useful for debugging.",
)
parser.add_argument(
"--minios",
action="store_true",
help="If set, extract the miniOS partition, otherwise "
"extract the kernel and rootfs partitions.",
)
parser.add_argument(
"--work-dir",
type="str_path",
help="Path to a temporary directory in the chroot.",
)
parser.add_argument(
"--payload",
type="str_path",
help="Path to the input payload file. Only used when "
"trying to generate the payload properties file using "
"the given payload. If --output is not passed, the "
"payload properties file path will be generated by "
"appending .json to the payload filename itself.",
)
opts = parser.parse_args(argv)
opts.Freeze()
return opts
def main(argv):
opts = ParseArguments(argv)
chroot = chroot_lib.Chroot()
if opts.payload:
# We only want the payload's metadata. Create it and exit.
logging.info("Generating payload properties file.")
paygen_payload_lib.GenerateUpdatePayloadPropertiesFile(
opts.payload, opts.output
)
return
return paygen_payload_lib.GenerateUpdatePayload(
chroot,
opts.tgt_image,
opts.output,
src_image=opts.src_image,
work_dir=opts.work_dir,
private_key=opts.private_key,
check=opts.check,
minios=opts.minios,
)