Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Amin Hassani | 1352093 | 2017-07-26 11:26:05 -0700 | [diff] [blame] | 3 | # |
| 4 | # Copyright (C) 2015 The Android Open Source Project |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | # you may not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | # |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 18 | |
| 19 | # Script to generate a Brillo update for use by the update engine. |
| 20 | # |
| 21 | # usage: brillo_update_payload COMMAND [ARGS] |
| 22 | # The following commands are supported: |
| 23 | # generate generate an unsigned payload |
| 24 | # hash generate a payload or metadata hash |
| 25 | # sign generate a signed payload |
Alex Deymo | 98e691c | 2016-02-04 21:05:45 -0800 | [diff] [blame] | 26 | # properties generate a properties file from a payload |
Amin Hassani | 1352093 | 2017-07-26 11:26:05 -0700 | [diff] [blame] | 27 | # verify verify a payload by recreating a target image. |
Tudor Brindus | b432db8 | 2018-06-29 13:13:27 -0700 | [diff] [blame] | 28 | # check verify a payload using paycheck (static testing) |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 29 | # |
| 30 | # Generate command arguments: |
Tianjie Xu | 72d512c | 2019-08-21 15:20:35 -0700 | [diff] [blame] | 31 | # --payload generated unsigned payload output file |
| 32 | # --source_image if defined, generate a delta payload from the |
| 33 | # specified image to the target_image |
| 34 | # --target_image the target image that should be sent to clients |
| 35 | # --metadata_size_file if defined, generate a file containing the size |
| 36 | # of the ayload metadata in bytes to the specified |
| 37 | # file |
| 38 | # --disable_fec_computation Disable the on device fec data computation for |
| 39 | # incremental update. This feature is enabled by |
| 40 | # default |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 41 | # |
| 42 | # Hash command arguments: |
| 43 | # --unsigned_payload the input unsigned payload to generate the hash from |
| 44 | # --signature_size signature sizes in bytes in the following format: |
Alex Deymo | 89ff9e3 | 2015-09-15 19:29:01 -0700 | [diff] [blame] | 45 | # "size1:size2[:...]" |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 46 | # --payload_hash_file if defined, generate a payload hash and output to the |
| 47 | # specified file |
| 48 | # --metadata_hash_file if defined, generate a metadata hash and output to the |
| 49 | # specified file |
| 50 | # |
| 51 | # Sign command arguments: |
Alex Deymo | 89ff9e3 | 2015-09-15 19:29:01 -0700 | [diff] [blame] | 52 | # --unsigned_payload the input unsigned payload to insert the signatures |
| 53 | # --payload the output signed payload |
| 54 | # --signature_size signature sizes in bytes in the following format: |
| 55 | # "size1:size2[:...]" |
| 56 | # --payload_signature_file the payload signature files in the following |
| 57 | # format: |
| 58 | # "payload_signature1:payload_signature2[:...]" |
| 59 | # --metadata_signature_file the metadata signature files in the following |
| 60 | # format: |
| 61 | # "metadata_signature1:metadata_signature2[:...]" |
Jason Kusuma | 9a4cae2 | 2015-10-08 18:17:57 -0700 | [diff] [blame] | 62 | # --metadata_size_file if defined, generate a file containing the size of |
| 63 | # the signed payload metadata in bytes to the |
| 64 | # specified file |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 65 | # Note that the number of signature sizes and payload signatures have to match. |
Alex Deymo | 98e691c | 2016-02-04 21:05:45 -0800 | [diff] [blame] | 66 | # |
| 67 | # Properties command arguments: |
| 68 | # --payload the input signed or unsigned payload |
| 69 | # --properties_file the output path where to write the properties, or |
| 70 | # '-' for stdout. |
Amin Hassani | 1352093 | 2017-07-26 11:26:05 -0700 | [diff] [blame] | 71 | # Verify command arguments: |
| 72 | # --payload payload input file |
| 73 | # --source_image verify payload to the specified source image. |
| 74 | # --target_image the target image to verify upon. |
Tudor Brindus | b432db8 | 2018-06-29 13:13:27 -0700 | [diff] [blame] | 75 | # |
| 76 | # Check command arguments: |
| 77 | # Symmetrical with the verify command. |
Alex Deymo | 98e691c | 2016-02-04 21:05:45 -0800 | [diff] [blame] | 78 | |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 79 | |
Alex Deymo | 61e1fa8 | 2016-01-19 15:16:34 -0800 | [diff] [blame] | 80 | # Exit codes: |
| 81 | EX_UNSUPPORTED_DELTA=100 |
| 82 | |
Jason Kusuma | f514c54 | 2015-11-05 18:43:45 -0800 | [diff] [blame] | 83 | warn() { |
| 84 | echo "brillo_update_payload: warning: $*" >&2 |
| 85 | } |
| 86 | |
Gilad Arnold | 957ce12 | 2015-10-14 16:02:55 -0700 | [diff] [blame] | 87 | die() { |
| 88 | echo "brillo_update_payload: error: $*" >&2 |
| 89 | exit 1 |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Gilad Arnold | 957ce12 | 2015-10-14 16:02:55 -0700 | [diff] [blame] | 92 | # Loads shflags. We first look at the default install location; then look for |
Amin Hassani | 2a14d41 | 2018-05-31 13:01:09 -0700 | [diff] [blame] | 93 | # crosutils (chroot); finally check our own directory. |
Gilad Arnold | 957ce12 | 2015-10-14 16:02:55 -0700 | [diff] [blame] | 94 | load_shflags() { |
| 95 | local my_dir="$(dirname "$(readlink -f "$0")")" |
| 96 | local path |
Mike Frysinger | 26bb865 | 2018-10-12 02:15:09 -0400 | [diff] [blame] | 97 | for path in /usr/share/misc "${my_dir}"/lib/shflags; do |
Gilad Arnold | 957ce12 | 2015-10-14 16:02:55 -0700 | [diff] [blame] | 98 | if [[ -r "${path}/shflags" ]]; then |
| 99 | . "${path}/shflags" || die "Could not load ${path}/shflags." |
| 100 | return |
| 101 | fi |
| 102 | done |
| 103 | die "Could not find shflags." |
| 104 | } |
| 105 | |
| 106 | load_shflags |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 107 | |
Alex Deymo | c64ffd5 | 2015-09-25 18:10:07 -0700 | [diff] [blame] | 108 | HELP_GENERATE="generate: Generate an unsigned update payload." |
| 109 | HELP_HASH="hash: Generate the hashes of the unsigned payload and metadata used \ |
| 110 | for signing." |
| 111 | HELP_SIGN="sign: Insert the signatures into the unsigned payload." |
Alex Deymo | 98e691c | 2016-02-04 21:05:45 -0800 | [diff] [blame] | 112 | HELP_PROPERTIES="properties: Extract payload properties to a file." |
Tudor Brindus | b432db8 | 2018-06-29 13:13:27 -0700 | [diff] [blame] | 113 | HELP_VERIFY="verify: Verify a (signed) update payload using delta_generator." |
| 114 | HELP_CHECK="check: Check a (signed) update payload using paycheck (static \ |
| 115 | testing)." |
Alex Deymo | c64ffd5 | 2015-09-25 18:10:07 -0700 | [diff] [blame] | 116 | |
| 117 | usage() { |
| 118 | echo "Supported commands:" |
| 119 | echo |
| 120 | echo "${HELP_GENERATE}" |
| 121 | echo "${HELP_HASH}" |
| 122 | echo "${HELP_SIGN}" |
Alex Deymo | 98e691c | 2016-02-04 21:05:45 -0800 | [diff] [blame] | 123 | echo "${HELP_PROPERTIES}" |
Amin Hassani | 1352093 | 2017-07-26 11:26:05 -0700 | [diff] [blame] | 124 | echo "${HELP_VERIFY}" |
Tudor Brindus | b432db8 | 2018-06-29 13:13:27 -0700 | [diff] [blame] | 125 | echo "${HELP_CHECK}" |
Alex Deymo | c64ffd5 | 2015-09-25 18:10:07 -0700 | [diff] [blame] | 126 | echo |
| 127 | echo "Use: \"$0 <command> --help\" for more options." |
| 128 | } |
| 129 | |
| 130 | # Check that a command is specified. |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 131 | if [[ $# -lt 1 ]]; then |
Tudor Brindus | b432db8 | 2018-06-29 13:13:27 -0700 | [diff] [blame] | 132 | echo "Please specify a command [generate|hash|sign|properties|verify|check]" |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 133 | exit 1 |
| 134 | fi |
| 135 | |
Alex Deymo | c64ffd5 | 2015-09-25 18:10:07 -0700 | [diff] [blame] | 136 | # Parse command. |
| 137 | COMMAND="${1:-}" |
| 138 | shift |
| 139 | |
| 140 | case "${COMMAND}" in |
| 141 | generate) |
| 142 | FLAGS_HELP="${HELP_GENERATE}" |
| 143 | ;; |
| 144 | |
| 145 | hash) |
| 146 | FLAGS_HELP="${HELP_HASH}" |
| 147 | ;; |
| 148 | |
| 149 | sign) |
| 150 | FLAGS_HELP="${HELP_SIGN}" |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 151 | ;; |
Alex Deymo | 98e691c | 2016-02-04 21:05:45 -0800 | [diff] [blame] | 152 | |
| 153 | properties) |
| 154 | FLAGS_HELP="${HELP_PROPERTIES}" |
| 155 | ;; |
Amin Hassani | 1352093 | 2017-07-26 11:26:05 -0700 | [diff] [blame] | 156 | |
| 157 | verify) |
| 158 | FLAGS_HELP="${HELP_VERIFY}" |
| 159 | ;; |
| 160 | |
Tudor Brindus | b432db8 | 2018-06-29 13:13:27 -0700 | [diff] [blame] | 161 | check) |
| 162 | FLAGS_HELP="${HELP_CHECK}" |
| 163 | ;; |
| 164 | |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 165 | *) |
Alex Deymo | c64ffd5 | 2015-09-25 18:10:07 -0700 | [diff] [blame] | 166 | echo "Unrecognized command: \"${COMMAND}\"" >&2 |
| 167 | usage >&2 |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 168 | exit 1 |
| 169 | ;; |
| 170 | esac |
| 171 | |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 172 | # Flags |
Alex Deymo | c64ffd5 | 2015-09-25 18:10:07 -0700 | [diff] [blame] | 173 | FLAGS_HELP="Usage: $0 ${COMMAND} [flags] |
| 174 | ${FLAGS_HELP}" |
| 175 | |
| 176 | if [[ "${COMMAND}" == "generate" ]]; then |
| 177 | DEFINE_string payload "" \ |
| 178 | "Path to output the generated unsigned payload file." |
| 179 | DEFINE_string target_image "" \ |
| 180 | "Path to the target image that should be sent to clients." |
| 181 | DEFINE_string source_image "" \ |
| 182 | "Optional: Path to a source image. If specified, this makes a delta update." |
Jason Kusuma | 9a4cae2 | 2015-10-08 18:17:57 -0700 | [diff] [blame] | 183 | DEFINE_string metadata_size_file "" \ |
| 184 | "Optional: Path to output metadata size." |
Sen Jiang | 8e768e9 | 2017-06-28 17:13:19 -0700 | [diff] [blame] | 185 | DEFINE_string max_timestamp "" \ |
| 186 | "Optional: The maximum unix timestamp of the OS allowed to apply this \ |
| 187 | payload, should be set to a number higher than the build timestamp of the \ |
| 188 | system running on the device, 0 if not specified." |
Kelvin Zhang | 1f49642 | 2020-08-11 17:18:23 -0400 | [diff] [blame] | 189 | DEFINE_string partition_timestamps "" \ |
| 190 | "Optional: Per-partition maximum unix timestamp of the OS allowed to \ |
| 191 | apply this payload. Should be a comma separated key value pairs. e.x.\ |
| 192 | system:1234,vendor:456" |
Tianjie Xu | 72d512c | 2019-08-21 15:20:35 -0700 | [diff] [blame] | 193 | DEFINE_string disable_fec_computation "" \ |
| 194 | "Optional: Disables the on device fec data computation for incremental \ |
| 195 | update. This feature is enabled by default." |
Kelvin Zhang | 098e79a | 2020-11-19 17:40:56 -0500 | [diff] [blame] | 196 | DEFINE_string disable_verity_computation "" \ |
| 197 | "Optional: Disables the on device verity computation for incremental \ |
| 198 | update. This feature is enabled by default." |
Tianjie | f5baff4 | 2020-07-17 21:43:22 -0700 | [diff] [blame] | 199 | DEFINE_string is_partial_update "" \ |
| 200 | "Optional: True if the payload is for partial update. i.e. it only updates \ |
| 201 | a subset of partitions on device." |
Kelvin Zhang | dde2ef4 | 2020-11-20 12:26:19 -0500 | [diff] [blame] | 202 | DEFINE_string full_boot "" "Will include full boot image" |
Kelvin Zhang | 9101ff3 | 2021-01-19 15:48:53 -0500 | [diff] [blame] | 203 | DEFINE_string disable_vabc "" \ |
| 204 | "Optional: Disables Virtual AB Compression when installing the OTA" |
Kelvin Zhang | 02df21b | 2021-01-07 14:55:18 -0500 | [diff] [blame^] | 205 | DEFINE_string enable_vabc_xor "" \ |
| 206 | "Optional: Enable the use of Virtual AB Compression XOR feature" |
Alex Deymo | c64ffd5 | 2015-09-25 18:10:07 -0700 | [diff] [blame] | 207 | fi |
| 208 | if [[ "${COMMAND}" == "hash" || "${COMMAND}" == "sign" ]]; then |
| 209 | DEFINE_string unsigned_payload "" "Path to the input unsigned payload." |
| 210 | DEFINE_string signature_size "" \ |
| 211 | "Signature sizes in bytes in the following format: size1:size2[:...]" |
| 212 | fi |
| 213 | if [[ "${COMMAND}" == "hash" ]]; then |
| 214 | DEFINE_string metadata_hash_file "" \ |
| 215 | "Optional: Path to output metadata hash file." |
| 216 | DEFINE_string payload_hash_file "" \ |
| 217 | "Optional: Path to output payload hash file." |
| 218 | fi |
| 219 | if [[ "${COMMAND}" == "sign" ]]; then |
| 220 | DEFINE_string payload "" \ |
| 221 | "Path to output the generated unsigned payload file." |
| 222 | DEFINE_string metadata_signature_file "" \ |
| 223 | "The metatada signatures in the following format: \ |
| 224 | metadata_signature1:metadata_signature2[:...]" |
| 225 | DEFINE_string payload_signature_file "" \ |
| 226 | "The payload signatures in the following format: \ |
| 227 | payload_signature1:payload_signature2[:...]" |
Jason Kusuma | 9a4cae2 | 2015-10-08 18:17:57 -0700 | [diff] [blame] | 228 | DEFINE_string metadata_size_file "" \ |
| 229 | "Optional: Path to output metadata size." |
Alex Deymo | c64ffd5 | 2015-09-25 18:10:07 -0700 | [diff] [blame] | 230 | fi |
Alex Deymo | 98e691c | 2016-02-04 21:05:45 -0800 | [diff] [blame] | 231 | if [[ "${COMMAND}" == "properties" ]]; then |
| 232 | DEFINE_string payload "" \ |
| 233 | "Path to the input signed or unsigned payload file." |
| 234 | DEFINE_string properties_file "-" \ |
| 235 | "Path to output the extracted property files. If '-' is passed stdout will \ |
| 236 | be used." |
| 237 | fi |
Tudor Brindus | b432db8 | 2018-06-29 13:13:27 -0700 | [diff] [blame] | 238 | if [[ "${COMMAND}" == "verify" || "${COMMAND}" == "check" ]]; then |
Amin Hassani | 1352093 | 2017-07-26 11:26:05 -0700 | [diff] [blame] | 239 | DEFINE_string payload "" \ |
| 240 | "Path to the input payload file." |
| 241 | DEFINE_string target_image "" \ |
| 242 | "Path to the target image to verify upon." |
| 243 | DEFINE_string source_image "" \ |
| 244 | "Optional: Path to a source image. If specified, the delta update is \ |
| 245 | applied to this." |
| 246 | fi |
Alex Deymo | 98e691c | 2016-02-04 21:05:45 -0800 | [diff] [blame] | 247 | |
Alex Deymo | 5fbb110 | 2017-01-12 13:55:52 -0800 | [diff] [blame] | 248 | DEFINE_string work_dir "${TMPDIR:-/tmp}" "Where to dump temporary files." |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 249 | |
| 250 | # Parse command line flag arguments |
| 251 | FLAGS "$@" || exit 1 |
| 252 | eval set -- "${FLAGS_ARGV}" |
Alex Deymo | 89ff9e3 | 2015-09-15 19:29:01 -0700 | [diff] [blame] | 253 | set -e |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 254 | |
Alex Deymo | 5fbb110 | 2017-01-12 13:55:52 -0800 | [diff] [blame] | 255 | # Override the TMPDIR with the passed work_dir flags, which anyway defaults to |
| 256 | # ${TMPDIR}. |
| 257 | TMPDIR="${FLAGS_work_dir}" |
| 258 | export TMPDIR |
| 259 | |
Alex Deymo | 89ff9e3 | 2015-09-15 19:29:01 -0700 | [diff] [blame] | 260 | # Associative arrays from partition name to file in the source and target |
| 261 | # images. The size of the updated area must be the size of the file. |
| 262 | declare -A SRC_PARTITIONS |
| 263 | declare -A DST_PARTITIONS |
| 264 | |
Alex Deymo | 20bdc70 | 2016-12-07 21:07:11 -0800 | [diff] [blame] | 265 | # Associative arrays for the .map files associated with each src/dst partition |
| 266 | # file in SRC_PARTITIONS and DST_PARTITIONS. |
| 267 | declare -A SRC_PARTITIONS_MAP |
| 268 | declare -A DST_PARTITIONS_MAP |
| 269 | |
Sen Jiang | 788c2d9 | 2016-03-09 12:48:40 -0800 | [diff] [blame] | 270 | # List of partition names in order. |
| 271 | declare -a PARTITIONS_ORDER |
| 272 | |
Tao Bao | 9648990 | 2019-04-02 16:25:03 -0700 | [diff] [blame] | 273 | # A list of PIDs of the extract_image workers. |
| 274 | EXTRACT_IMAGE_PIDS=() |
| 275 | |
Alex Deymo | 89ff9e3 | 2015-09-15 19:29:01 -0700 | [diff] [blame] | 276 | # A list of temporary files to remove during cleanup. |
| 277 | CLEANUP_FILES=() |
| 278 | |
Alex Deymo | 48b502a | 2015-09-17 19:00:18 -0700 | [diff] [blame] | 279 | # Global options to force the version of the payload. |
| 280 | FORCE_MAJOR_VERSION="" |
| 281 | FORCE_MINOR_VERSION="" |
| 282 | |
Sen Jiang | 6f7b22c | 2015-11-12 15:50:39 -0800 | [diff] [blame] | 283 | # Path to the postinstall config file in target image if exists. |
| 284 | POSTINSTALL_CONFIG_FILE="" |
| 285 | |
Yifan Hong | 398cb54 | 2018-10-18 11:29:40 -0700 | [diff] [blame] | 286 | # Path to the dynamic partition info file in target image if exists. |
| 287 | DYNAMIC_PARTITION_INFO_FILE="" |
| 288 | |
Kelvin Zhang | deb3445 | 2021-01-21 11:54:36 -0500 | [diff] [blame] | 289 | # Path to the META/apex_info.pb found in target build |
| 290 | APEX_INFO_FILE="" |
| 291 | |
Alex Deymo | c97df43 | 2015-09-25 17:23:52 -0700 | [diff] [blame] | 292 | # read_option_int <file.txt> <option_key> [default_value] |
| 293 | # |
| 294 | # Reads the unsigned integer value associated with |option_key| in a key=value |
| 295 | # file |file.txt|. Prints the read value if found and valid, otherwise prints |
| 296 | # the |default_value|. |
| 297 | read_option_uint() { |
| 298 | local file_txt="$1" |
| 299 | local option_key="$2" |
| 300 | local default_value="${3:-}" |
| 301 | local value |
Tao Bao | c288d5b | 2019-10-03 13:47:06 -0700 | [diff] [blame] | 302 | if value=$(grep "^${option_key}=" "${file_txt}" | tail -n 1); then |
Alex Deymo | c97df43 | 2015-09-25 17:23:52 -0700 | [diff] [blame] | 303 | if value=$(echo "${value}" | cut -f 2- -d "=" | grep -E "^[0-9]+$"); then |
| 304 | echo "${value}" |
| 305 | return |
| 306 | fi |
| 307 | fi |
| 308 | echo "${default_value}" |
| 309 | } |
| 310 | |
Sen Jiang | d0e9a89 | 2016-07-22 16:28:07 -0700 | [diff] [blame] | 311 | # truncate_file <file_path> <file_size> |
| 312 | # |
Dan Willemsen | 3271186 | 2018-10-04 21:25:50 -0700 | [diff] [blame] | 313 | # Truncate the given |file_path| to |file_size| using python. |
Sen Jiang | d0e9a89 | 2016-07-22 16:28:07 -0700 | [diff] [blame] | 314 | # The truncate binary might not be available. |
| 315 | truncate_file() { |
| 316 | local file_path="$1" |
| 317 | local file_size="$2" |
Dan Willemsen | 3271186 | 2018-10-04 21:25:50 -0700 | [diff] [blame] | 318 | python -c "open(\"${file_path}\", 'a').truncate(${file_size})" |
Sen Jiang | d0e9a89 | 2016-07-22 16:28:07 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Alex Deymo | 89ff9e3 | 2015-09-15 19:29:01 -0700 | [diff] [blame] | 321 | # Create a temporary file in the work_dir with an optional pattern name. |
| 322 | # Prints the name of the newly created file. |
| 323 | create_tempfile() { |
| 324 | local pattern="${1:-tempfile.XXXXXX}" |
| 325 | mktemp --tmpdir="${FLAGS_work_dir}" "${pattern}" |
| 326 | } |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 327 | |
| 328 | cleanup() { |
| 329 | local err="" |
Alex Deymo | 89ff9e3 | 2015-09-15 19:29:01 -0700 | [diff] [blame] | 330 | rm -f "${CLEANUP_FILES[@]}" || err=1 |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 331 | |
| 332 | # If we are cleaning up after an error, or if we got an error during |
| 333 | # cleanup (even if we eventually succeeded) return a non-zero exit |
| 334 | # code. This triggers additional logging in most environments that call |
| 335 | # this script. |
| 336 | if [[ -n "${err}" ]]; then |
| 337 | die "Cleanup encountered an error." |
| 338 | fi |
| 339 | } |
| 340 | |
| 341 | cleanup_on_error() { |
| 342 | trap - INT TERM ERR EXIT |
| 343 | cleanup |
| 344 | die "Cleanup success after an error." |
| 345 | } |
| 346 | |
| 347 | cleanup_on_exit() { |
| 348 | trap - INT TERM ERR EXIT |
| 349 | cleanup |
| 350 | } |
| 351 | |
| 352 | trap cleanup_on_error INT TERM ERR |
| 353 | trap cleanup_on_exit EXIT |
| 354 | |
Tianjie Xu | 14715ce | 2019-08-06 17:24:43 -0700 | [diff] [blame] | 355 | # extract_file <zip_file> <entry_name> <destination> |
| 356 | # |
| 357 | # Extracts |entry_name| from |zip_file| to |destination|. |
| 358 | extract_file() { |
| 359 | local zip_file="$1" |
| 360 | local entry_name="$2" |
| 361 | local destination="$3" |
| 362 | |
| 363 | # unzip -p won't report error upon ENOSPC. Therefore, create a temp directory |
| 364 | # as the destination of the unzip, and move the file to the intended |
| 365 | # destination. |
| 366 | local output_directory=$( |
| 367 | mktemp --directory --tmpdir="${FLAGS_work_dir}" "TEMP.XXXXXX") |
| 368 | unzip "${zip_file}" "${entry_name}" -d "${output_directory}" || |
| 369 | { rm -rf "${output_directory}"; die "Failed to extract ${entry_name}"; } |
| 370 | |
| 371 | mv "${output_directory}/${entry_name}" "${destination}" |
| 372 | rm -rf "${output_directory}" |
| 373 | } |
Alex Deymo | 48b502a | 2015-09-17 19:00:18 -0700 | [diff] [blame] | 374 | |
Sen Jiang | 788c2d9 | 2016-03-09 12:48:40 -0800 | [diff] [blame] | 375 | # extract_image <image> <partitions_array> [partitions_order] |
Alex Deymo | 48b502a | 2015-09-17 19:00:18 -0700 | [diff] [blame] | 376 | # |
| 377 | # Detect the format of the |image| file and extract its updatable partitions |
| 378 | # into new temporary files. Add the list of partition names and its files to the |
Sen Jiang | 788c2d9 | 2016-03-09 12:48:40 -0800 | [diff] [blame] | 379 | # associative array passed in |partitions_array|. If |partitions_order| is |
| 380 | # passed, set it to list of partition names in order. |
Alex Deymo | 48b502a | 2015-09-17 19:00:18 -0700 | [diff] [blame] | 381 | extract_image() { |
| 382 | local image="$1" |
| 383 | |
| 384 | # Brillo images are zip files. We detect the 4-byte magic header of the zip |
| 385 | # file. |
Elliott Hughes | 5df503c | 2018-11-27 16:57:34 -0800 | [diff] [blame] | 386 | local magic=$(xxd -p -l4 "${image}") |
Alex Deymo | 48b502a | 2015-09-17 19:00:18 -0700 | [diff] [blame] | 387 | if [[ "${magic}" == "504b0304" ]]; then |
| 388 | echo "Detected .zip file, extracting Brillo image." |
| 389 | extract_image_brillo "$@" |
| 390 | return |
| 391 | fi |
| 392 | |
| 393 | # Chrome OS images are GPT partitioned disks. We should have the cgpt binary |
| 394 | # bundled here and we will use it to extract the partitions, so the GPT |
| 395 | # headers must be valid. |
| 396 | if cgpt show -q -n "${image}" >/dev/null; then |
| 397 | echo "Detected GPT image, extracting Chrome OS image." |
| 398 | extract_image_cros "$@" |
| 399 | return |
| 400 | fi |
| 401 | |
| 402 | die "Couldn't detect the image format of ${image}" |
| 403 | } |
| 404 | |
Sen Jiang | 788c2d9 | 2016-03-09 12:48:40 -0800 | [diff] [blame] | 405 | # extract_image_cros <image.bin> <partitions_array> [partitions_order] |
Alex Deymo | 89ff9e3 | 2015-09-15 19:29:01 -0700 | [diff] [blame] | 406 | # |
Alex Deymo | 48b502a | 2015-09-17 19:00:18 -0700 | [diff] [blame] | 407 | # Extract Chromium OS recovery images into new temporary files. |
Alex Deymo | 89ff9e3 | 2015-09-15 19:29:01 -0700 | [diff] [blame] | 408 | extract_image_cros() { |
| 409 | local image="$1" |
| 410 | local partitions_array="$2" |
Sen Jiang | 788c2d9 | 2016-03-09 12:48:40 -0800 | [diff] [blame] | 411 | local partitions_order="${3:-}" |
Alex Deymo | 89ff9e3 | 2015-09-15 19:29:01 -0700 | [diff] [blame] | 412 | |
| 413 | local kernel root |
| 414 | kernel=$(create_tempfile "kernel.bin.XXXXXX") |
| 415 | CLEANUP_FILES+=("${kernel}") |
| 416 | root=$(create_tempfile "root.bin.XXXXXX") |
| 417 | CLEANUP_FILES+=("${root}") |
| 418 | |
| 419 | cros_generate_update_payload --extract \ |
| 420 | --image "${image}" \ |
Amin Hassani | 58e01d6 | 2018-09-19 14:56:15 -0700 | [diff] [blame] | 421 | --kern_path "${kernel}" --root_path "${root}" |
Alex Deymo | 89ff9e3 | 2015-09-15 19:29:01 -0700 | [diff] [blame] | 422 | |
Amin Hassani | 58e01d6 | 2018-09-19 14:56:15 -0700 | [diff] [blame] | 423 | # Chrome OS now uses major_version 2 payloads for all boards. |
| 424 | # See crbug.com/794404 for more information. |
| 425 | FORCE_MAJOR_VERSION="2" |
Alex Deymo | 83f2f70 | 2015-10-14 14:49:33 -0700 | [diff] [blame] | 426 | |
Tudor Brindus | dda79e2 | 2018-06-28 18:03:21 -0700 | [diff] [blame] | 427 | eval ${partitions_array}[kernel]=\""${kernel}"\" |
| 428 | eval ${partitions_array}[root]=\""${root}"\" |
Alex Deymo | 89ff9e3 | 2015-09-15 19:29:01 -0700 | [diff] [blame] | 429 | |
Sen Jiang | 788c2d9 | 2016-03-09 12:48:40 -0800 | [diff] [blame] | 430 | if [[ -n "${partitions_order}" ]]; then |
Tudor Brindus | dda79e2 | 2018-06-28 18:03:21 -0700 | [diff] [blame] | 431 | eval "${partitions_order}=( \"root\" \"kernel\" )" |
Sen Jiang | 788c2d9 | 2016-03-09 12:48:40 -0800 | [diff] [blame] | 432 | fi |
| 433 | |
Alex Deymo | 89ff9e3 | 2015-09-15 19:29:01 -0700 | [diff] [blame] | 434 | local part varname |
Tudor Brindus | dda79e2 | 2018-06-28 18:03:21 -0700 | [diff] [blame] | 435 | for part in kernel root; do |
Alex Deymo | 89ff9e3 | 2015-09-15 19:29:01 -0700 | [diff] [blame] | 436 | varname="${partitions_array}[${part}]" |
| 437 | printf "md5sum of %s: " "${varname}" |
| 438 | md5sum "${!varname}" |
| 439 | done |
| 440 | } |
| 441 | |
Sen Jiang | 3e5804d | 2018-09-06 15:53:00 -0700 | [diff] [blame] | 442 | # extract_partition_brillo <target_files.zip> <partitions_array> <partition> |
| 443 | # <part_file> <part_map_file> |
| 444 | # |
| 445 | # Extract the <partition> from target_files zip file into <part_file> and its |
| 446 | # map file into <part_map_file>. |
| 447 | extract_partition_brillo() { |
| 448 | local image="$1" |
| 449 | local partitions_array="$2" |
| 450 | local part="$3" |
| 451 | local part_file="$4" |
| 452 | local part_map_file="$5" |
| 453 | |
| 454 | # For each partition, we in turn look for its image file under IMAGES/ and |
| 455 | # RADIO/ in the given target_files zip file. |
| 456 | local path path_in_zip |
| 457 | for path in IMAGES RADIO; do |
| 458 | if unzip -l "${image}" "${path}/${part}.img" >/dev/null; then |
| 459 | path_in_zip="${path}" |
| 460 | break |
| 461 | fi |
| 462 | done |
| 463 | [[ -n "${path_in_zip}" ]] || die "Failed to find ${part}.img" |
Tianjie Xu | 14715ce | 2019-08-06 17:24:43 -0700 | [diff] [blame] | 464 | extract_file "${image}" "${path_in_zip}/${part}.img" "${part_file}" |
Sen Jiang | 3e5804d | 2018-09-06 15:53:00 -0700 | [diff] [blame] | 465 | |
| 466 | # If the partition is stored as an Android sparse image file, we need to |
| 467 | # convert them to a raw image for the update. |
Yifan Hong | 4b821d7 | 2018-12-07 17:26:04 -0800 | [diff] [blame] | 468 | local magic=$(xxd -p -l4 "${part_file}") |
Sen Jiang | 3e5804d | 2018-09-06 15:53:00 -0700 | [diff] [blame] | 469 | if [[ "${magic}" == "3aff26ed" ]]; then |
| 470 | local temp_sparse=$(create_tempfile "${part}.sparse.XXXXXX") |
| 471 | echo "Converting Android sparse image ${part}.img to RAW." |
| 472 | mv "${part_file}" "${temp_sparse}" |
| 473 | simg2img "${temp_sparse}" "${part_file}" |
| 474 | rm -f "${temp_sparse}" |
| 475 | fi |
| 476 | |
| 477 | # Extract the .map file (if one is available). |
Tianjie Xu | 14715ce | 2019-08-06 17:24:43 -0700 | [diff] [blame] | 478 | if unzip -l "${image}" "${path_in_zip}/${part}.map" > /dev/null; then |
| 479 | extract_file "${image}" "${path_in_zip}/${part}.map" "${part_map_file}" |
| 480 | fi |
Sen Jiang | 3e5804d | 2018-09-06 15:53:00 -0700 | [diff] [blame] | 481 | |
| 482 | # delta_generator only supports images multiple of 4 KiB. For target images |
| 483 | # we pad the data with zeros if needed, but for source images we truncate |
| 484 | # down the data since the last block of the old image could be padded on |
| 485 | # disk with unknown data. |
| 486 | local filesize=$(stat -c%s "${part_file}") |
| 487 | if [[ $(( filesize % 4096 )) -ne 0 ]]; then |
| 488 | if [[ "${partitions_array}" == "SRC_PARTITIONS" ]]; then |
| 489 | echo "Rounding DOWN partition ${part}.img to a multiple of 4 KiB." |
| 490 | : $(( filesize = filesize & -4096 )) |
| 491 | else |
| 492 | echo "Rounding UP partition ${part}.img to a multiple of 4 KiB." |
| 493 | : $(( filesize = (filesize + 4095) & -4096 )) |
| 494 | fi |
| 495 | truncate_file "${part_file}" "${filesize}" |
| 496 | fi |
| 497 | |
| 498 | echo "Extracted ${partitions_array}[${part}]: ${filesize} bytes" |
| 499 | } |
| 500 | |
Sen Jiang | 788c2d9 | 2016-03-09 12:48:40 -0800 | [diff] [blame] | 501 | # extract_image_brillo <target_files.zip> <partitions_array> [partitions_order] |
Alex Deymo | 48b502a | 2015-09-17 19:00:18 -0700 | [diff] [blame] | 502 | # |
| 503 | # Extract the A/B updated partitions from a Brillo target_files zip file into |
| 504 | # new temporary files. |
| 505 | extract_image_brillo() { |
| 506 | local image="$1" |
| 507 | local partitions_array="$2" |
Sen Jiang | 788c2d9 | 2016-03-09 12:48:40 -0800 | [diff] [blame] | 508 | local partitions_order="${3:-}" |
Alex Deymo | 48b502a | 2015-09-17 19:00:18 -0700 | [diff] [blame] | 509 | |
Alex Deymo | 48b502a | 2015-09-17 19:00:18 -0700 | [diff] [blame] | 510 | local partitions=( "boot" "system" ) |
Alex Deymo | 168b535 | 2015-11-04 13:51:52 -0800 | [diff] [blame] | 511 | local ab_partitions_list |
| 512 | ab_partitions_list=$(create_tempfile "ab_partitions_list.XXXXXX") |
| 513 | CLEANUP_FILES+=("${ab_partitions_list}") |
Tianjie Xu | 14715ce | 2019-08-06 17:24:43 -0700 | [diff] [blame] | 514 | if unzip -l "${image}" "META/ab_partitions.txt" > /dev/null; then |
| 515 | extract_file "${image}" "META/ab_partitions.txt" "${ab_partitions_list}" |
Alex Deymo | 168b535 | 2015-11-04 13:51:52 -0800 | [diff] [blame] | 516 | if grep -v -E '^[a-zA-Z0-9_-]*$' "${ab_partitions_list}" >&2; then |
| 517 | die "Invalid partition names found in the partition list." |
| 518 | fi |
Sen Jiang | 34c711a | 2017-10-25 17:25:21 -0700 | [diff] [blame] | 519 | # Get partition list without duplicates. |
| 520 | partitions=($(awk '!seen[$0]++' "${ab_partitions_list}")) |
Alex Deymo | 168b535 | 2015-11-04 13:51:52 -0800 | [diff] [blame] | 521 | if [[ ${#partitions[@]} -eq 0 ]]; then |
| 522 | die "The list of partitions is empty. Can't generate a payload." |
| 523 | fi |
| 524 | else |
| 525 | warn "No ab_partitions.txt found. Using default." |
| 526 | fi |
Sen Jiang | 3e5804d | 2018-09-06 15:53:00 -0700 | [diff] [blame] | 527 | echo "List of A/B partitions for ${partitions_array}: ${partitions[@]}" |
Alex Deymo | 48b502a | 2015-09-17 19:00:18 -0700 | [diff] [blame] | 528 | |
Sen Jiang | 788c2d9 | 2016-03-09 12:48:40 -0800 | [diff] [blame] | 529 | if [[ -n "${partitions_order}" ]]; then |
| 530 | eval "${partitions_order}=(${partitions[@]})" |
| 531 | fi |
| 532 | |
Alex Deymo | 83f2f70 | 2015-10-14 14:49:33 -0700 | [diff] [blame] | 533 | # All Brillo updaters support major version 2. |
| 534 | FORCE_MAJOR_VERSION="2" |
| 535 | |
Alex Deymo | 48b502a | 2015-09-17 19:00:18 -0700 | [diff] [blame] | 536 | if [[ "${partitions_array}" == "SRC_PARTITIONS" ]]; then |
Sen Jiang | 6f7b22c | 2015-11-12 15:50:39 -0800 | [diff] [blame] | 537 | # Source image |
| 538 | local ue_config=$(create_tempfile "ue_config.XXXXXX") |
Alex Deymo | c97df43 | 2015-09-25 17:23:52 -0700 | [diff] [blame] | 539 | CLEANUP_FILES+=("${ue_config}") |
Tianjie Xu | 14715ce | 2019-08-06 17:24:43 -0700 | [diff] [blame] | 540 | if unzip -l "${image}" "META/update_engine_config.txt" > /dev/null; then |
| 541 | extract_file "${image}" "META/update_engine_config.txt" "${ue_config}" |
| 542 | else |
Alex Deymo | c97df43 | 2015-09-25 17:23:52 -0700 | [diff] [blame] | 543 | warn "No update_engine_config.txt found. Assuming pre-release image, \ |
| 544 | using payload minor version 2" |
| 545 | fi |
Alex Deymo | 83f2f70 | 2015-10-14 14:49:33 -0700 | [diff] [blame] | 546 | # For delta payloads, we use the major and minor version supported by the |
| 547 | # old updater. |
Alex Deymo | c97df43 | 2015-09-25 17:23:52 -0700 | [diff] [blame] | 548 | FORCE_MINOR_VERSION=$(read_option_uint "${ue_config}" \ |
| 549 | "PAYLOAD_MINOR_VERSION" 2) |
Alex Deymo | 83f2f70 | 2015-10-14 14:49:33 -0700 | [diff] [blame] | 550 | FORCE_MAJOR_VERSION=$(read_option_uint "${ue_config}" \ |
| 551 | "PAYLOAD_MAJOR_VERSION" 2) |
Alex Deymo | 61e1fa8 | 2016-01-19 15:16:34 -0800 | [diff] [blame] | 552 | |
| 553 | # Brillo support for deltas started with minor version 3. |
| 554 | if [[ "${FORCE_MINOR_VERSION}" -le 2 ]]; then |
| 555 | warn "No delta support from minor version ${FORCE_MINOR_VERSION}. \ |
| 556 | Disabling deltas for this source version." |
| 557 | exit ${EX_UNSUPPORTED_DELTA} |
| 558 | fi |
Sen Jiang | 6f7b22c | 2015-11-12 15:50:39 -0800 | [diff] [blame] | 559 | else |
| 560 | # Target image |
| 561 | local postinstall_config=$(create_tempfile "postinstall_config.XXXXXX") |
| 562 | CLEANUP_FILES+=("${postinstall_config}") |
Tianjie Xu | 14715ce | 2019-08-06 17:24:43 -0700 | [diff] [blame] | 563 | if unzip -l "${image}" "META/postinstall_config.txt" > /dev/null; then |
| 564 | extract_file "${image}" "META/postinstall_config.txt" \ |
| 565 | "${postinstall_config}" |
Sen Jiang | 6f7b22c | 2015-11-12 15:50:39 -0800 | [diff] [blame] | 566 | POSTINSTALL_CONFIG_FILE="${postinstall_config}" |
| 567 | fi |
Yifan Hong | 398cb54 | 2018-10-18 11:29:40 -0700 | [diff] [blame] | 568 | local dynamic_partitions_info=$(create_tempfile "dynamic_partitions_info.XXXXXX") |
| 569 | CLEANUP_FILES+=("${dynamic_partitions_info}") |
Tianjie Xu | 14715ce | 2019-08-06 17:24:43 -0700 | [diff] [blame] | 570 | if unzip -l "${image}" "META/dynamic_partitions_info.txt" > /dev/null; then |
| 571 | extract_file "${image}" "META/dynamic_partitions_info.txt" \ |
| 572 | "${dynamic_partitions_info}" |
Yifan Hong | 398cb54 | 2018-10-18 11:29:40 -0700 | [diff] [blame] | 573 | DYNAMIC_PARTITION_INFO_FILE="${dynamic_partitions_info}" |
| 574 | fi |
Kelvin Zhang | deb3445 | 2021-01-21 11:54:36 -0500 | [diff] [blame] | 575 | local apex_info=$(create_tempfile "apex_info.XXXXXX") |
| 576 | CLEANUP_FILES+=("${apex_info}") |
| 577 | if unzip -l "${image}" "META/apex_info.pb" > /dev/null; then |
| 578 | extract_file "${image}" "META/apex_info.pb" \ |
| 579 | "${apex_info}" |
| 580 | APEX_INFO_FILE="${apex_info}" |
| 581 | fi |
Alex Deymo | 48b502a | 2015-09-17 19:00:18 -0700 | [diff] [blame] | 582 | fi |
| 583 | |
Sen Jiang | 3e5804d | 2018-09-06 15:53:00 -0700 | [diff] [blame] | 584 | local part |
Alex Deymo | 48b502a | 2015-09-17 19:00:18 -0700 | [diff] [blame] | 585 | for part in "${partitions[@]}"; do |
Sen Jiang | 3e5804d | 2018-09-06 15:53:00 -0700 | [diff] [blame] | 586 | local part_file=$(create_tempfile "${part}.img.XXXXXX") |
| 587 | local part_map_file=$(create_tempfile "${part}.map.XXXXXX") |
| 588 | CLEANUP_FILES+=("${part_file}" "${part_map_file}") |
| 589 | # Extract partitions in background. |
| 590 | extract_partition_brillo "${image}" "${partitions_array}" "${part}" \ |
| 591 | "${part_file}" "${part_map_file}" & |
Tao Bao | 9648990 | 2019-04-02 16:25:03 -0700 | [diff] [blame] | 592 | EXTRACT_IMAGE_PIDS+=("$!") |
Alex Deymo | 48b502a | 2015-09-17 19:00:18 -0700 | [diff] [blame] | 593 | eval "${partitions_array}[\"${part}\"]=\"${part_file}\"" |
Alex Deymo | 20bdc70 | 2016-12-07 21:07:11 -0800 | [diff] [blame] | 594 | eval "${partitions_array}_MAP[\"${part}\"]=\"${part_map_file}\"" |
Sen Jiang | 3e5804d | 2018-09-06 15:53:00 -0700 | [diff] [blame] | 595 | done |
| 596 | } |
| 597 | |
| 598 | # cleanup_partition_array <partitions_array> |
| 599 | # |
| 600 | # Remove all empty files in <partitions_array>. |
| 601 | cleanup_partition_array() { |
| 602 | local partitions_array="$1" |
| 603 | # Have to use eval to iterate over associative array keys with variable array |
| 604 | # names, we should change it to use nameref once bash 4.3 is available |
| 605 | # everywhere. |
| 606 | for part in $(eval "echo \${!${partitions_array}[@]}"); do |
| 607 | local path="${partitions_array}[$part]" |
| 608 | if [[ ! -s "${!path}" ]]; then |
| 609 | eval "unset ${partitions_array}[${part}]" |
| 610 | fi |
Alex Deymo | 48b502a | 2015-09-17 19:00:18 -0700 | [diff] [blame] | 611 | done |
| 612 | } |
| 613 | |
Tudor Brindus | b432db8 | 2018-06-29 13:13:27 -0700 | [diff] [blame] | 614 | extract_payload_images() { |
| 615 | local payload_type=$1 |
| 616 | echo "Extracting images for ${payload_type} update." |
| 617 | |
| 618 | if [[ "${payload_type}" == "delta" ]]; then |
| 619 | extract_image "${FLAGS_source_image}" SRC_PARTITIONS |
| 620 | fi |
| 621 | extract_image "${FLAGS_target_image}" DST_PARTITIONS PARTITIONS_ORDER |
Tao Bao | 9648990 | 2019-04-02 16:25:03 -0700 | [diff] [blame] | 622 | # Wait for all subprocesses to finish. Not using `wait` since it doesn't die |
| 623 | # on non-zero subprocess exit code. Not using `wait ${EXTRACT_IMAGE_PIDS[@]}` |
| 624 | # as it gives the status of the last process it has waited for. |
| 625 | for pid in ${EXTRACT_IMAGE_PIDS[@]}; do |
| 626 | wait ${pid} |
| 627 | done |
Sen Jiang | 3e5804d | 2018-09-06 15:53:00 -0700 | [diff] [blame] | 628 | cleanup_partition_array SRC_PARTITIONS |
| 629 | cleanup_partition_array SRC_PARTITIONS_MAP |
| 630 | cleanup_partition_array DST_PARTITIONS |
| 631 | cleanup_partition_array DST_PARTITIONS_MAP |
Tudor Brindus | b432db8 | 2018-06-29 13:13:27 -0700 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | get_payload_type() { |
| 635 | if [[ -z "${FLAGS_source_image}" ]]; then |
| 636 | echo "full" |
| 637 | else |
| 638 | echo "delta" |
| 639 | fi |
| 640 | } |
| 641 | |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 642 | validate_generate() { |
| 643 | [[ -n "${FLAGS_payload}" ]] || |
Sen Jiang | 53f04d7 | 2016-07-13 16:43:39 -0700 | [diff] [blame] | 644 | die "You must specify an output filename with --payload FILENAME" |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 645 | |
| 646 | [[ -n "${FLAGS_target_image}" ]] || |
Sen Jiang | 53f04d7 | 2016-07-13 16:43:39 -0700 | [diff] [blame] | 647 | die "You must specify a target image with --target_image FILENAME" |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | cmd_generate() { |
Sen Jiang | 3e5804d | 2018-09-06 15:53:00 -0700 | [diff] [blame] | 651 | local payload_type=$(get_payload_type) |
| 652 | extract_payload_images ${payload_type} |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 653 | |
Alex Deymo | 48b502a | 2015-09-17 19:00:18 -0700 | [diff] [blame] | 654 | echo "Generating ${payload_type} update." |
Alex Deymo | 168b535 | 2015-11-04 13:51:52 -0800 | [diff] [blame] | 655 | # Common payload args: |
Tudor Brindus | 5ec5bd1 | 2018-07-11 11:02:44 -0700 | [diff] [blame] | 656 | GENERATOR_ARGS=( --out_file="${FLAGS_payload}" ) |
Alex Deymo | 168b535 | 2015-11-04 13:51:52 -0800 | [diff] [blame] | 657 | |
| 658 | local part old_partitions="" new_partitions="" partition_names="" |
Alex Deymo | 20bdc70 | 2016-12-07 21:07:11 -0800 | [diff] [blame] | 659 | local old_mapfiles="" new_mapfiles="" |
Sen Jiang | 788c2d9 | 2016-03-09 12:48:40 -0800 | [diff] [blame] | 660 | for part in "${PARTITIONS_ORDER[@]}"; do |
Alex Deymo | 168b535 | 2015-11-04 13:51:52 -0800 | [diff] [blame] | 661 | if [[ -n "${partition_names}" ]]; then |
| 662 | partition_names+=":" |
| 663 | new_partitions+=":" |
| 664 | old_partitions+=":" |
Alex Deymo | 20bdc70 | 2016-12-07 21:07:11 -0800 | [diff] [blame] | 665 | new_mapfiles+=":" |
| 666 | old_mapfiles+=":" |
Alex Deymo | 168b535 | 2015-11-04 13:51:52 -0800 | [diff] [blame] | 667 | fi |
| 668 | partition_names+="${part}" |
| 669 | new_partitions+="${DST_PARTITIONS[${part}]}" |
Kelvin Zhang | 999705e | 2020-11-03 10:07:09 -0500 | [diff] [blame] | 670 | if [ "${FLAGS_full_boot}" == "true" ] && [ "${part}" == "boot" ]; then |
| 671 | # Skip boot partition. |
| 672 | old_partitions+="" |
| 673 | else |
| 674 | old_partitions+="${SRC_PARTITIONS[${part}]:-}" |
| 675 | fi |
Alex Deymo | 20bdc70 | 2016-12-07 21:07:11 -0800 | [diff] [blame] | 676 | new_mapfiles+="${DST_PARTITIONS_MAP[${part}]:-}" |
| 677 | old_mapfiles+="${SRC_PARTITIONS_MAP[${part}]:-}" |
Alex Deymo | 168b535 | 2015-11-04 13:51:52 -0800 | [diff] [blame] | 678 | done |
| 679 | |
| 680 | # Target image args: |
| 681 | GENERATOR_ARGS+=( |
Tudor Brindus | 5ec5bd1 | 2018-07-11 11:02:44 -0700 | [diff] [blame] | 682 | --partition_names="${partition_names}" |
| 683 | --new_partitions="${new_partitions}" |
| 684 | --new_mapfiles="${new_mapfiles}" |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 685 | ) |
| 686 | |
Tianjie | f5baff4 | 2020-07-17 21:43:22 -0700 | [diff] [blame] | 687 | if [[ "${FLAGS_is_partial_update}" == "true" ]]; then |
| 688 | GENERATOR_ARGS+=( --is_partial_update="true" ) |
| 689 | # Need at least minor version 7 for partial update, so generate with minor |
| 690 | # version 7 if we don't have a source image. Let the delta_generator to fail |
| 691 | # the other incompatiable minor versions. |
| 692 | if [[ -z "${FORCE_MINOR_VERSION}" ]]; then |
| 693 | FORCE_MINOR_VERSION="7" |
| 694 | fi |
| 695 | fi |
| 696 | |
Alex Deymo | 89ff9e3 | 2015-09-15 19:29:01 -0700 | [diff] [blame] | 697 | if [[ "${payload_type}" == "delta" ]]; then |
Alex Deymo | 168b535 | 2015-11-04 13:51:52 -0800 | [diff] [blame] | 698 | # Source image args: |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 699 | GENERATOR_ARGS+=( |
Tudor Brindus | 5ec5bd1 | 2018-07-11 11:02:44 -0700 | [diff] [blame] | 700 | --old_partitions="${old_partitions}" |
| 701 | --old_mapfiles="${old_mapfiles}" |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 702 | ) |
Tianjie Xu | 72d512c | 2019-08-21 15:20:35 -0700 | [diff] [blame] | 703 | if [[ -n "${FLAGS_disable_fec_computation}" ]]; then |
| 704 | GENERATOR_ARGS+=( |
| 705 | --disable_fec_computation="${FLAGS_disable_fec_computation}" ) |
| 706 | fi |
Kelvin Zhang | 098e79a | 2020-11-19 17:40:56 -0500 | [diff] [blame] | 707 | if [[ -n "${FLAGS_disable_verity_computation}" ]]; then |
| 708 | GENERATOR_ARGS+=( |
| 709 | --disable_verity_computation="${FLAGS_disable_verity_computation}" ) |
| 710 | fi |
Kelvin Zhang | 413982e | 2021-03-02 15:34:50 -0500 | [diff] [blame] | 711 | fi |
| 712 | |
Kelvin Zhang | 02df21b | 2021-01-07 14:55:18 -0500 | [diff] [blame^] | 713 | if [[ -n "${FLAGS_enable_vabc_xor}" ]]; then |
| 714 | GENERATOR_ARGS+=( |
| 715 | --enable_vabc_xor="${FLAGS_enable_vabc_xor}" ) |
| 716 | fi |
| 717 | |
Kelvin Zhang | 413982e | 2021-03-02 15:34:50 -0500 | [diff] [blame] | 718 | if [[ -n "${FLAGS_disable_vabc}" ]]; then |
| 719 | GENERATOR_ARGS+=( |
| 720 | --disable_vabc="${FLAGS_disable_vabc}" ) |
Alex Deymo | 48b502a | 2015-09-17 19:00:18 -0700 | [diff] [blame] | 721 | fi |
| 722 | |
Tianjie | f5baff4 | 2020-07-17 21:43:22 -0700 | [diff] [blame] | 723 | # minor version is set only for delta or partial payload. |
| 724 | if [[ -n "${FORCE_MINOR_VERSION}" ]]; then |
| 725 | GENERATOR_ARGS+=( --minor_version="${FORCE_MINOR_VERSION}" ) |
| 726 | fi |
| 727 | |
Alex Deymo | 48b502a | 2015-09-17 19:00:18 -0700 | [diff] [blame] | 728 | if [[ -n "${FORCE_MAJOR_VERSION}" ]]; then |
| 729 | GENERATOR_ARGS+=( --major_version="${FORCE_MAJOR_VERSION}" ) |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 730 | fi |
| 731 | |
Jason Kusuma | 9a4cae2 | 2015-10-08 18:17:57 -0700 | [diff] [blame] | 732 | if [[ -n "${FLAGS_metadata_size_file}" ]]; then |
| 733 | GENERATOR_ARGS+=( --out_metadata_size_file="${FLAGS_metadata_size_file}" ) |
| 734 | fi |
| 735 | |
Sen Jiang | 8e768e9 | 2017-06-28 17:13:19 -0700 | [diff] [blame] | 736 | if [[ -n "${FLAGS_max_timestamp}" ]]; then |
| 737 | GENERATOR_ARGS+=( --max_timestamp="${FLAGS_max_timestamp}" ) |
| 738 | fi |
| 739 | |
Kelvin Zhang | 1f49642 | 2020-08-11 17:18:23 -0400 | [diff] [blame] | 740 | if [[ -n "${FLAGS_partition_timestamps}" ]]; then |
| 741 | GENERATOR_ARGS+=( --partition_timestamps="${FLAGS_partition_timestamps}" ) |
| 742 | fi |
| 743 | |
Sen Jiang | 6f7b22c | 2015-11-12 15:50:39 -0800 | [diff] [blame] | 744 | if [[ -n "${POSTINSTALL_CONFIG_FILE}" ]]; then |
| 745 | GENERATOR_ARGS+=( |
| 746 | --new_postinstall_config_file="${POSTINSTALL_CONFIG_FILE}" |
| 747 | ) |
| 748 | fi |
| 749 | |
Yifan Hong | 398cb54 | 2018-10-18 11:29:40 -0700 | [diff] [blame] | 750 | if [[ -n "{DYNAMIC_PARTITION_INFO_FILE}" ]]; then |
| 751 | GENERATOR_ARGS+=( |
| 752 | --dynamic_partition_info_file="${DYNAMIC_PARTITION_INFO_FILE}" |
| 753 | ) |
| 754 | fi |
Kelvin Zhang | deb3445 | 2021-01-21 11:54:36 -0500 | [diff] [blame] | 755 | if [[ -n "{APEX_INFO_FILE}" ]]; then |
| 756 | GENERATOR_ARGS+=( |
| 757 | --apex_info_file="${APEX_INFO_FILE}" |
| 758 | ) |
| 759 | fi |
Yifan Hong | 398cb54 | 2018-10-18 11:29:40 -0700 | [diff] [blame] | 760 | |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 761 | echo "Running delta_generator with args: ${GENERATOR_ARGS[@]}" |
Jason Kusuma | 9a4cae2 | 2015-10-08 18:17:57 -0700 | [diff] [blame] | 762 | "${GENERATOR}" "${GENERATOR_ARGS[@]}" |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 763 | |
Alex Deymo | 89ff9e3 | 2015-09-15 19:29:01 -0700 | [diff] [blame] | 764 | echo "Done generating ${payload_type} update." |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | validate_hash() { |
| 768 | [[ -n "${FLAGS_signature_size}" ]] || |
Sen Jiang | 53f04d7 | 2016-07-13 16:43:39 -0700 | [diff] [blame] | 769 | die "You must specify signature size with --signature_size SIZES" |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 770 | |
| 771 | [[ -n "${FLAGS_unsigned_payload}" ]] || |
Sen Jiang | 53f04d7 | 2016-07-13 16:43:39 -0700 | [diff] [blame] | 772 | die "You must specify the input unsigned payload with \ |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 773 | --unsigned_payload FILENAME" |
| 774 | |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 775 | [[ -n "${FLAGS_payload_hash_file}" ]] || |
Sen Jiang | 53f04d7 | 2016-07-13 16:43:39 -0700 | [diff] [blame] | 776 | die "You must specify --payload_hash_file FILENAME" |
Jason Kusuma | f514c54 | 2015-11-05 18:43:45 -0800 | [diff] [blame] | 777 | |
| 778 | [[ -n "${FLAGS_metadata_hash_file}" ]] || |
Sen Jiang | 53f04d7 | 2016-07-13 16:43:39 -0700 | [diff] [blame] | 779 | die "You must specify --metadata_hash_file FILENAME" |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | cmd_hash() { |
Sen Jiang | bf1266f | 2015-10-26 11:29:24 -0700 | [diff] [blame] | 783 | "${GENERATOR}" \ |
Tudor Brindus | 5ec5bd1 | 2018-07-11 11:02:44 -0700 | [diff] [blame] | 784 | --in_file="${FLAGS_unsigned_payload}" \ |
| 785 | --signature_size="${FLAGS_signature_size}" \ |
| 786 | --out_hash_file="${FLAGS_payload_hash_file}" \ |
| 787 | --out_metadata_hash_file="${FLAGS_metadata_hash_file}" |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 788 | |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 789 | echo "Done generating hash." |
| 790 | } |
| 791 | |
| 792 | validate_sign() { |
| 793 | [[ -n "${FLAGS_signature_size}" ]] || |
Sen Jiang | 53f04d7 | 2016-07-13 16:43:39 -0700 | [diff] [blame] | 794 | die "You must specify signature size with --signature_size SIZES" |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 795 | |
| 796 | [[ -n "${FLAGS_unsigned_payload}" ]] || |
Sen Jiang | 53f04d7 | 2016-07-13 16:43:39 -0700 | [diff] [blame] | 797 | die "You must specify the input unsigned payload with \ |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 798 | --unsigned_payload FILENAME" |
| 799 | |
| 800 | [[ -n "${FLAGS_payload}" ]] || |
Sen Jiang | 53f04d7 | 2016-07-13 16:43:39 -0700 | [diff] [blame] | 801 | die "You must specify the output signed payload with --payload FILENAME" |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 802 | |
| 803 | [[ -n "${FLAGS_payload_signature_file}" ]] || |
Sen Jiang | 53f04d7 | 2016-07-13 16:43:39 -0700 | [diff] [blame] | 804 | die "You must specify the payload signature file with \ |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 805 | --payload_signature_file SIGNATURES" |
Alex Deymo | 89ff9e3 | 2015-09-15 19:29:01 -0700 | [diff] [blame] | 806 | |
| 807 | [[ -n "${FLAGS_metadata_signature_file}" ]] || |
Sen Jiang | 53f04d7 | 2016-07-13 16:43:39 -0700 | [diff] [blame] | 808 | die "You must specify the metadata signature file with \ |
Alex Deymo | 89ff9e3 | 2015-09-15 19:29:01 -0700 | [diff] [blame] | 809 | --metadata_signature_file SIGNATURES" |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | cmd_sign() { |
Jason Kusuma | 9a4cae2 | 2015-10-08 18:17:57 -0700 | [diff] [blame] | 813 | GENERATOR_ARGS=( |
Tudor Brindus | 5ec5bd1 | 2018-07-11 11:02:44 -0700 | [diff] [blame] | 814 | --in_file="${FLAGS_unsigned_payload}" |
| 815 | --signature_size="${FLAGS_signature_size}" |
| 816 | --payload_signature_file="${FLAGS_payload_signature_file}" |
| 817 | --metadata_signature_file="${FLAGS_metadata_signature_file}" |
| 818 | --out_file="${FLAGS_payload}" |
Jason Kusuma | 9a4cae2 | 2015-10-08 18:17:57 -0700 | [diff] [blame] | 819 | ) |
| 820 | |
| 821 | if [[ -n "${FLAGS_metadata_size_file}" ]]; then |
| 822 | GENERATOR_ARGS+=( --out_metadata_size_file="${FLAGS_metadata_size_file}" ) |
| 823 | fi |
| 824 | |
| 825 | "${GENERATOR}" "${GENERATOR_ARGS[@]}" |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 826 | echo "Done signing payload." |
| 827 | } |
| 828 | |
Alex Deymo | 98e691c | 2016-02-04 21:05:45 -0800 | [diff] [blame] | 829 | validate_properties() { |
| 830 | [[ -n "${FLAGS_payload}" ]] || |
Sen Jiang | 53f04d7 | 2016-07-13 16:43:39 -0700 | [diff] [blame] | 831 | die "You must specify the payload file with --payload FILENAME" |
Alex Deymo | 98e691c | 2016-02-04 21:05:45 -0800 | [diff] [blame] | 832 | |
| 833 | [[ -n "${FLAGS_properties_file}" ]] || |
Sen Jiang | 53f04d7 | 2016-07-13 16:43:39 -0700 | [diff] [blame] | 834 | die "You must specify a non empty --properties_file FILENAME" |
Alex Deymo | 98e691c | 2016-02-04 21:05:45 -0800 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | cmd_properties() { |
| 838 | "${GENERATOR}" \ |
Tudor Brindus | 5ec5bd1 | 2018-07-11 11:02:44 -0700 | [diff] [blame] | 839 | --in_file="${FLAGS_payload}" \ |
| 840 | --properties_file="${FLAGS_properties_file}" |
Alex Deymo | 98e691c | 2016-02-04 21:05:45 -0800 | [diff] [blame] | 841 | } |
| 842 | |
Tudor Brindus | b432db8 | 2018-06-29 13:13:27 -0700 | [diff] [blame] | 843 | validate_verify_and_check() { |
Amin Hassani | 1352093 | 2017-07-26 11:26:05 -0700 | [diff] [blame] | 844 | [[ -n "${FLAGS_payload}" ]] || |
| 845 | die "Error: you must specify an input filename with --payload FILENAME" |
| 846 | |
| 847 | [[ -n "${FLAGS_target_image}" ]] || |
| 848 | die "Error: you must specify a target image with --target_image FILENAME" |
| 849 | } |
| 850 | |
| 851 | cmd_verify() { |
Tudor Brindus | b432db8 | 2018-06-29 13:13:27 -0700 | [diff] [blame] | 852 | local payload_type=$(get_payload_type) |
| 853 | extract_payload_images ${payload_type} |
Amin Hassani | 1352093 | 2017-07-26 11:26:05 -0700 | [diff] [blame] | 854 | |
| 855 | declare -A TMP_PARTITIONS |
| 856 | for part in "${PARTITIONS_ORDER[@]}"; do |
| 857 | local tmp_part=$(create_tempfile "tmp_part.bin.XXXXXX") |
| 858 | echo "Creating temporary target partition ${tmp_part} for ${part}" |
| 859 | CLEANUP_FILES+=("${tmp_part}") |
| 860 | TMP_PARTITIONS[${part}]=${tmp_part} |
| 861 | local FILESIZE=$(stat -c%s "${DST_PARTITIONS[${part}]}") |
| 862 | echo "Truncating ${TMP_PARTITIONS[${part}]} to ${FILESIZE}" |
| 863 | truncate_file "${TMP_PARTITIONS[${part}]}" "${FILESIZE}" |
| 864 | done |
| 865 | |
| 866 | echo "Verifying ${payload_type} update." |
| 867 | # Common payload args: |
Tudor Brindus | 5ec5bd1 | 2018-07-11 11:02:44 -0700 | [diff] [blame] | 868 | GENERATOR_ARGS=( --in_file="${FLAGS_payload}" ) |
Amin Hassani | 1352093 | 2017-07-26 11:26:05 -0700 | [diff] [blame] | 869 | |
| 870 | local part old_partitions="" new_partitions="" partition_names="" |
| 871 | for part in "${PARTITIONS_ORDER[@]}"; do |
| 872 | if [[ -n "${partition_names}" ]]; then |
| 873 | partition_names+=":" |
| 874 | new_partitions+=":" |
| 875 | old_partitions+=":" |
| 876 | fi |
| 877 | partition_names+="${part}" |
| 878 | new_partitions+="${TMP_PARTITIONS[${part}]}" |
| 879 | old_partitions+="${SRC_PARTITIONS[${part}]:-}" |
| 880 | done |
| 881 | |
| 882 | # Target image args: |
| 883 | GENERATOR_ARGS+=( |
Tudor Brindus | 5ec5bd1 | 2018-07-11 11:02:44 -0700 | [diff] [blame] | 884 | --partition_names="${partition_names}" |
| 885 | --new_partitions="${new_partitions}" |
Amin Hassani | 1352093 | 2017-07-26 11:26:05 -0700 | [diff] [blame] | 886 | ) |
| 887 | |
| 888 | if [[ "${payload_type}" == "delta" ]]; then |
| 889 | # Source image args: |
| 890 | GENERATOR_ARGS+=( |
Tudor Brindus | 5ec5bd1 | 2018-07-11 11:02:44 -0700 | [diff] [blame] | 891 | --old_partitions="${old_partitions}" |
Amin Hassani | 1352093 | 2017-07-26 11:26:05 -0700 | [diff] [blame] | 892 | ) |
| 893 | fi |
| 894 | |
Amin Hassani | a566cb6 | 2017-08-23 12:36:55 -0700 | [diff] [blame] | 895 | if [[ -n "${FORCE_MAJOR_VERSION}" ]]; then |
| 896 | GENERATOR_ARGS+=( --major_version="${FORCE_MAJOR_VERSION}" ) |
| 897 | fi |
| 898 | |
Amin Hassani | 1352093 | 2017-07-26 11:26:05 -0700 | [diff] [blame] | 899 | echo "Running delta_generator to verify ${payload_type} payload with args: \ |
| 900 | ${GENERATOR_ARGS[@]}" |
Sen Jiang | 6feb15c | 2018-08-31 15:45:17 -0700 | [diff] [blame] | 901 | "${GENERATOR}" "${GENERATOR_ARGS[@]}" || true |
Amin Hassani | 1352093 | 2017-07-26 11:26:05 -0700 | [diff] [blame] | 902 | |
Sen Jiang | 6feb15c | 2018-08-31 15:45:17 -0700 | [diff] [blame] | 903 | echo "Done applying ${payload_type} update." |
| 904 | echo "Checking the newly generated partitions against the target partitions" |
| 905 | local need_pause=false |
| 906 | for part in "${PARTITIONS_ORDER[@]}"; do |
| 907 | local not_str="" |
| 908 | if ! cmp "${TMP_PARTITIONS[${part}]}" "${DST_PARTITIONS[${part}]}"; then |
| 909 | not_str="in" |
| 910 | need_pause=true |
| 911 | fi |
| 912 | echo "The new partition (${part}) is ${not_str}valid." |
| 913 | done |
| 914 | # All images will be cleaned up when script exits, pause here to give a chance |
| 915 | # to inspect the images. |
| 916 | if [[ "$need_pause" == true ]]; then |
| 917 | read -n1 -r -s -p "Paused to investigate invalid partitions, \ |
| 918 | press any key to exit." |
Amin Hassani | 1352093 | 2017-07-26 11:26:05 -0700 | [diff] [blame] | 919 | fi |
| 920 | } |
| 921 | |
Tudor Brindus | b432db8 | 2018-06-29 13:13:27 -0700 | [diff] [blame] | 922 | cmd_check() { |
| 923 | local payload_type=$(get_payload_type) |
| 924 | extract_payload_images ${payload_type} |
| 925 | |
| 926 | local part dst_partitions="" src_partitions="" |
| 927 | for part in "${PARTITIONS_ORDER[@]}"; do |
| 928 | if [[ -n "${dst_partitions}" ]]; then |
| 929 | dst_partitions+=" " |
| 930 | src_partitions+=" " |
| 931 | fi |
| 932 | dst_partitions+="${DST_PARTITIONS[${part}]}" |
| 933 | src_partitions+="${SRC_PARTITIONS[${part}]:-}" |
| 934 | done |
| 935 | |
| 936 | # Common payload args: |
| 937 | PAYCHECK_ARGS=( "${FLAGS_payload}" --type ${payload_type} \ |
| 938 | --part_names ${PARTITIONS_ORDER[@]} \ |
| 939 | --dst_part_paths ${dst_partitions} ) |
| 940 | |
| 941 | if [[ ! -z "${SRC_PARTITIONS[@]}" ]]; then |
| 942 | PAYCHECK_ARGS+=( --src_part_paths ${src_partitions} ) |
| 943 | fi |
| 944 | |
| 945 | echo "Checking ${payload_type} update." |
| 946 | check_update_payload ${PAYCHECK_ARGS[@]} --check |
| 947 | } |
| 948 | |
Tianjie | e283ce4 | 2020-07-29 11:37:51 -0700 | [diff] [blame] | 949 | # Check that the real generator exists: |
Yifan Hong | 3756c3e | 2020-07-24 20:25:51 -0700 | [diff] [blame] | 950 | [[ -x "${GENERATOR}" ]] || GENERATOR="$(which delta_generator || true)" |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 951 | [[ -x "${GENERATOR}" ]] || die "can't find delta_generator" |
| 952 | |
| 953 | case "$COMMAND" in |
| 954 | generate) validate_generate |
| 955 | cmd_generate |
| 956 | ;; |
| 957 | hash) validate_hash |
| 958 | cmd_hash |
| 959 | ;; |
| 960 | sign) validate_sign |
| 961 | cmd_sign |
| 962 | ;; |
Alex Deymo | 98e691c | 2016-02-04 21:05:45 -0800 | [diff] [blame] | 963 | properties) validate_properties |
| 964 | cmd_properties |
| 965 | ;; |
Tudor Brindus | b432db8 | 2018-06-29 13:13:27 -0700 | [diff] [blame] | 966 | verify) validate_verify_and_check |
Amin Hassani | 1352093 | 2017-07-26 11:26:05 -0700 | [diff] [blame] | 967 | cmd_verify |
| 968 | ;; |
Tudor Brindus | b432db8 | 2018-06-29 13:13:27 -0700 | [diff] [blame] | 969 | check) validate_verify_and_check |
| 970 | cmd_check |
| 971 | ;; |
Jason Kusuma | be998f4 | 2015-09-03 15:53:13 -0700 | [diff] [blame] | 972 | esac |