Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2010 The Android Open Source Project |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | // |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 16 | |
| 17 | // Update file format: A delta update file contains all the deltas needed |
| 18 | // to update a system from one specific version to another specific |
| 19 | // version. The update format is represented by this struct pseudocode: |
| 20 | // struct delta_update_file { |
| 21 | // char magic[4] = "CrAU"; |
Alex Deymo | c1d7f12 | 2015-09-10 15:15:42 -0700 | [diff] [blame] | 22 | // uint64 file_format_version; |
Andrew de los Reyes | 1e338b8 | 2010-01-22 14:57:27 -0800 | [diff] [blame] | 23 | // uint64 manifest_size; // Size of protobuf DeltaArchiveManifest |
Alex Deymo | c1d7f12 | 2015-09-10 15:15:42 -0700 | [diff] [blame] | 24 | // |
| 25 | // // Only present if format_version > 1: |
| 26 | // uint32 metadata_signature_size; |
| 27 | // |
Andrew de los Reyes | 1e338b8 | 2010-01-22 14:57:27 -0800 | [diff] [blame] | 28 | // // The Bzip2 compressed DeltaArchiveManifest |
| 29 | // char manifest[]; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 30 | // |
Alex Deymo | c1d7f12 | 2015-09-10 15:15:42 -0700 | [diff] [blame] | 31 | // // The signature of the metadata (from the beginning of the payload up to |
| 32 | // // this location, not including the signature itself). This is a serialized |
| 33 | // // Signatures message. |
| 34 | // char medatada_signature_message[metadata_signature_size]; |
| 35 | // |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 36 | // // Data blobs for files, no specific format. The specific offset |
| 37 | // // and length of each data blob is recorded in the DeltaArchiveManifest. |
| 38 | // struct { |
| 39 | // char data[]; |
| 40 | // } blobs[]; |
| 41 | // |
Andrew de los Reyes | 94f025d | 2010-08-16 17:17:27 -0700 | [diff] [blame] | 42 | // // These two are not signed: |
Alex Deymo | c1d7f12 | 2015-09-10 15:15:42 -0700 | [diff] [blame] | 43 | // uint64 payload_signatures_message_size; |
| 44 | // char payload_signatures_message[]; |
Andrew de los Reyes | 94f025d | 2010-08-16 17:17:27 -0700 | [diff] [blame] | 45 | // |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 46 | // }; |
| 47 | |
Andrew de los Reyes | 1e338b8 | 2010-01-22 14:57:27 -0800 | [diff] [blame] | 48 | // The DeltaArchiveManifest protobuf is an ordered list of InstallOperation |
| 49 | // objects. These objects are stored in a linear array in the |
| 50 | // DeltaArchiveManifest. Each operation is applied in order by the client. |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 51 | |
Andrew de los Reyes | 1e338b8 | 2010-01-22 14:57:27 -0800 | [diff] [blame] | 52 | // The DeltaArchiveManifest also contains the initial and final |
| 53 | // checksums for the device. |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 54 | |
Andrew de los Reyes | 1e338b8 | 2010-01-22 14:57:27 -0800 | [diff] [blame] | 55 | // The client will perform each InstallOperation in order, beginning even |
| 56 | // before the entire delta file is downloaded (but after at least the |
| 57 | // protobuf is downloaded). The types of operations are explained: |
| 58 | // - REPLACE: Replace the dst_extents on the drive with the attached data, |
| 59 | // zero padding out to block size. |
| 60 | // - REPLACE_BZ: bzip2-uncompress the attached data and write it into |
| 61 | // dst_extents on the drive, zero padding to block size. |
| 62 | // - MOVE: Copy the data in src_extents to dst_extents. Extents may overlap, |
| 63 | // so it may be desirable to read all src_extents data into memory before |
| 64 | // writing it out. |
Alex Deymo | c1d7f12 | 2015-09-10 15:15:42 -0700 | [diff] [blame] | 65 | // - SOURCE_COPY: Copy the data in src_extents in the old partition to |
| 66 | // dst_extents in the new partition. There's no overlapping of data because |
| 67 | // the extents are in different partitions. |
Andrew de los Reyes | 1e338b8 | 2010-01-22 14:57:27 -0800 | [diff] [blame] | 68 | // - BSDIFF: Read src_length bytes from src_extents into memory, perform |
| 69 | // bspatch with attached data, write new data to dst_extents, zero padding |
| 70 | // to block size. |
Alex Deymo | c1d7f12 | 2015-09-10 15:15:42 -0700 | [diff] [blame] | 71 | // - SOURCE_BSDIFF: Read the data in src_extents in the old partition, perform |
| 72 | // bspatch with the attached data and write the new data to dst_extents in the |
| 73 | // new partition. |
| 74 | // - ZERO: Write zeros to the destination dst_extents. |
| 75 | // - DISCARD: Discard the destination dst_extents blocks on the physical medium. |
| 76 | // the data read from those block is undefined. |
| 77 | // - REPLACE_XZ: Replace the dst_extents with the contents of the attached |
| 78 | // xz file after decompression. The xz file should only use crc32 or no crc at |
| 79 | // all to be compatible with xz-embedded. |
| 80 | // |
| 81 | // The operations allowed in the payload (supported by the client) depend on the |
| 82 | // major and minor version. See InstallOperation.Type bellow for details. |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 83 | |
Amin Hassani | 489875a | 2017-08-04 13:20:52 -0700 | [diff] [blame] | 84 | syntax = "proto2"; |
| 85 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 86 | package chromeos_update_engine; |
Alex Deymo | b8f16a1 | 2014-06-10 18:59:22 -0700 | [diff] [blame] | 87 | option optimize_for = LITE_RUNTIME; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 88 | |
Andrew de los Reyes | 1e338b8 | 2010-01-22 14:57:27 -0800 | [diff] [blame] | 89 | // Data is packed into blocks on disk, always starting from the beginning |
| 90 | // of the block. If a file's data is too large for one block, it overflows |
| 91 | // into another block, which may or may not be the following block on the |
| 92 | // physical partition. An ordered list of extents is another |
| 93 | // representation of an ordered list of blocks. For example, a file stored |
| 94 | // in blocks 9, 10, 11, 2, 18, 12 (in that order) would be stored in |
| 95 | // extents { {9, 3}, {2, 1}, {18, 1}, {12, 1} } (in that order). |
| 96 | // In general, files are stored sequentially on disk, so it's more efficient |
| 97 | // to use extents to encode the block lists (this is effectively |
| 98 | // run-length encoding). |
| 99 | // A sentinel value (kuint64max) as the start block denotes a sparse-hole |
| 100 | // in a file whose block-length is specified by num_blocks. |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 101 | |
Andrew de los Reyes | 94f025d | 2010-08-16 17:17:27 -0700 | [diff] [blame] | 102 | // Signatures: Updates may be signed by the OS vendor. The client verifies |
| 103 | // an update's signature by hashing the entire download. The section of the |
Jay Srinivasan | 74475bf | 2012-09-13 19:26:26 -0700 | [diff] [blame] | 104 | // download that contains the signature is at the end of the file, so when |
Andrew de los Reyes | 94f025d | 2010-08-16 17:17:27 -0700 | [diff] [blame] | 105 | // signing a file, only the part up to the signature part is signed. |
| 106 | // Then, the client looks inside the download's Signatures message for a |
| 107 | // Signature message that it knows how to handle. Generally, a client will |
| 108 | // only know how to handle one type of signature, but an update may contain |
| 109 | // many signatures to support many different types of client. Then client |
| 110 | // selects a Signature message and uses that, along with a known public key, |
| 111 | // to verify the download. The public key is expected to be part of the |
| 112 | // client. |
| 113 | |
Andrew de los Reyes | 1e338b8 | 2010-01-22 14:57:27 -0800 | [diff] [blame] | 114 | message Extent { |
| 115 | optional uint64 start_block = 1; |
| 116 | optional uint64 num_blocks = 2; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 117 | } |
| 118 | |
Andrew de los Reyes | 94f025d | 2010-08-16 17:17:27 -0700 | [diff] [blame] | 119 | message Signatures { |
| 120 | message Signature { |
| 121 | optional uint32 version = 1; |
Andrew de los Reyes | 0c44005 | 2010-08-20 11:25:54 -0700 | [diff] [blame] | 122 | optional bytes data = 2; |
Andrew de los Reyes | 94f025d | 2010-08-16 17:17:27 -0700 | [diff] [blame] | 123 | } |
| 124 | repeated Signature signatures = 1; |
| 125 | } |
| 126 | |
Darin Petkov | 36a5822 | 2010-10-07 22:00:09 -0700 | [diff] [blame] | 127 | message PartitionInfo { |
| 128 | optional uint64 size = 1; |
| 129 | optional bytes hash = 2; |
| 130 | } |
| 131 | |
Don Garrett | 0dd3985 | 2013-04-03 16:55:42 -0700 | [diff] [blame] | 132 | // Describe an image we are based on in a human friendly way. |
| 133 | // Examples: |
| 134 | // dev-channel, x86-alex, 1.2.3, mp-v3 |
| 135 | // nplusone-channel, x86-alex, 1.2.4, mp-v3, dev-channel, 1.2.3 |
| 136 | // |
| 137 | // All fields will be set, if this message is present. |
| 138 | message ImageInfo { |
| 139 | optional string board = 1; |
| 140 | optional string key = 2; |
| 141 | optional string channel = 3; |
| 142 | optional string version = 4; |
| 143 | |
| 144 | // If these values aren't present, they should be assumed to match |
| 145 | // the equivalent value above. They are normally only different for |
| 146 | // special image types such as nplusone images. |
| 147 | optional string build_channel = 5; |
| 148 | optional string build_version = 6; |
| 149 | } |
| 150 | |
Alex Deymo | a12ee11 | 2015-08-12 22:19:32 -0700 | [diff] [blame] | 151 | message InstallOperation { |
| 152 | enum Type { |
| 153 | REPLACE = 0; // Replace destination extents w/ attached data |
| 154 | REPLACE_BZ = 1; // Replace destination extents w/ attached bzipped data |
| 155 | MOVE = 2; // Move source extents to destination extents |
| 156 | BSDIFF = 3; // The data is a bsdiff binary diff |
Alex Deymo | ac6246a | 2015-08-13 14:00:22 -0700 | [diff] [blame] | 157 | |
Alex Deymo | c1d7f12 | 2015-09-10 15:15:42 -0700 | [diff] [blame] | 158 | // On minor version 2 or newer, these operations are supported: |
Alex Deymo | a12ee11 | 2015-08-12 22:19:32 -0700 | [diff] [blame] | 159 | SOURCE_COPY = 4; // Copy from source to target partition |
| 160 | SOURCE_BSDIFF = 5; // Like BSDIFF, but read from source partition |
Alex Deymo | ac6246a | 2015-08-13 14:00:22 -0700 | [diff] [blame] | 161 | |
Alex Deymo | c1d7f12 | 2015-09-10 15:15:42 -0700 | [diff] [blame] | 162 | // On minor version 3 or newer and on major version 2 or newer, these |
| 163 | // operations are supported: |
Alex Deymo | ac6246a | 2015-08-13 14:00:22 -0700 | [diff] [blame] | 164 | ZERO = 6; // Write zeros in the destination. |
| 165 | DISCARD = 7; // Discard the destination blocks, reading as undefined. |
Alex Deymo | c1d7f12 | 2015-09-10 15:15:42 -0700 | [diff] [blame] | 166 | REPLACE_XZ = 8; // Replace destination extents w/ attached xz data. |
Sen Jiang | 3317b88 | 2016-01-08 17:48:57 +0800 | [diff] [blame] | 167 | |
| 168 | // On minor version 4 or newer, these operations are supported: |
Amin Hassani | 5ef5d45 | 2017-08-04 13:10:59 -0700 | [diff] [blame] | 169 | PUFFDIFF = 9; // The data is in puffdiff format. |
Andrew de los Reyes | 1e338b8 | 2010-01-22 14:57:27 -0800 | [diff] [blame] | 170 | } |
Alex Deymo | a12ee11 | 2015-08-12 22:19:32 -0700 | [diff] [blame] | 171 | required Type type = 1; |
| 172 | // The offset into the delta file (after the protobuf) |
| 173 | // where the data (if any) is stored |
| 174 | optional uint32 data_offset = 2; |
| 175 | // The length of the data in the delta file |
| 176 | optional uint32 data_length = 3; |
| 177 | |
| 178 | // Ordered list of extents that are read from (if any) and written to. |
| 179 | repeated Extent src_extents = 4; |
| 180 | // Byte length of src, equal to the number of blocks in src_extents * |
Amin Hassani | f5a06d8 | 2017-10-19 15:06:38 -0700 | [diff] [blame^] | 181 | // block_size. It is used for BSDIFF and SOURCE_BSDIFF, because we need to |
| 182 | // pass that external program the number of bytes to read from the blocks we |
| 183 | // pass it. This is not used in any other operation. |
Alex Deymo | a12ee11 | 2015-08-12 22:19:32 -0700 | [diff] [blame] | 184 | optional uint64 src_length = 5; |
| 185 | |
| 186 | repeated Extent dst_extents = 6; |
| 187 | // Byte length of dst, equal to the number of blocks in dst_extents * |
Amin Hassani | f5a06d8 | 2017-10-19 15:06:38 -0700 | [diff] [blame^] | 188 | // block_size. Used for BSDIFF and SOURCE_BSDIFF, but not in any other |
| 189 | // operation. |
Alex Deymo | a12ee11 | 2015-08-12 22:19:32 -0700 | [diff] [blame] | 190 | optional uint64 dst_length = 7; |
| 191 | |
| 192 | // Optional SHA 256 hash of the blob associated with this operation. |
| 193 | // This is used as a primary validation for http-based downloads and |
| 194 | // as a defense-in-depth validation for https-based downloads. If |
| 195 | // the operation doesn't refer to any blob, this field will have |
| 196 | // zero bytes. |
| 197 | optional bytes data_sha256_hash = 8; |
Alex Deymo | ac6246a | 2015-08-13 14:00:22 -0700 | [diff] [blame] | 198 | |
| 199 | // Indicates the SHA 256 hash of the source data referenced in src_extents at |
| 200 | // the time of applying the operation. If present, the update_engine daemon |
| 201 | // MUST read and verify the source data before applying the operation. |
| 202 | optional bytes src_sha256_hash = 9; |
| 203 | } |
| 204 | |
| 205 | // Describes the update to apply to a single partition. |
| 206 | message PartitionUpdate { |
| 207 | // A platform-specific name to identify the partition set being updated. For |
| 208 | // example, in Chrome OS this could be "ROOT" or "KERNEL". |
| 209 | required string partition_name = 1; |
| 210 | |
Alex Deymo | eb86e55 | 2015-09-21 16:00:38 -0700 | [diff] [blame] | 211 | // Whether this partition carries a filesystem with post-install program that |
| 212 | // must be run to finalize the update process. See also |postinstall_path| and |
| 213 | // |filesystem_type|. |
Alex Deymo | ac6246a | 2015-08-13 14:00:22 -0700 | [diff] [blame] | 214 | optional bool run_postinstall = 2; |
| 215 | |
Alex Deymo | eb86e55 | 2015-09-21 16:00:38 -0700 | [diff] [blame] | 216 | // The path of the executable program to run during the post-install step, |
| 217 | // relative to the root of this filesystem. If not set, the default "postinst" |
| 218 | // will be used. This setting is only used when |run_postinstall| is set and |
| 219 | // true. |
| 220 | optional string postinstall_path = 3; |
| 221 | |
| 222 | // The filesystem type as passed to the mount(2) syscall when mounting the new |
| 223 | // filesystem to run the post-install program. If not set, a fixed list of |
| 224 | // filesystems will be attempted. This setting is only used if |
| 225 | // |run_postinstall| is set and true. |
| 226 | optional string filesystem_type = 4; |
| 227 | |
Alex Deymo | ac6246a | 2015-08-13 14:00:22 -0700 | [diff] [blame] | 228 | // If present, a list of signatures of the new_partition_info.hash signed with |
| 229 | // different keys. If the update_engine daemon requires vendor-signed images |
| 230 | // and has its public key installed, one of the signatures should be valid |
| 231 | // for /postinstall to run. |
Alex Deymo | eb86e55 | 2015-09-21 16:00:38 -0700 | [diff] [blame] | 232 | repeated Signatures.Signature new_partition_signature = 5; |
Alex Deymo | ac6246a | 2015-08-13 14:00:22 -0700 | [diff] [blame] | 233 | |
Alex Deymo | eb86e55 | 2015-09-21 16:00:38 -0700 | [diff] [blame] | 234 | optional PartitionInfo old_partition_info = 6; |
| 235 | optional PartitionInfo new_partition_info = 7; |
Alex Deymo | ac6246a | 2015-08-13 14:00:22 -0700 | [diff] [blame] | 236 | |
| 237 | // The list of operations to be performed to apply this PartitionUpdate. The |
| 238 | // associated operation blobs (in operations[i].data_offset, data_length) |
| 239 | // should be stored contiguously and in the same order. |
Alex Deymo | eb86e55 | 2015-09-21 16:00:38 -0700 | [diff] [blame] | 240 | repeated InstallOperation operations = 8; |
Alex Deymo | 5b91c6b | 2016-08-04 20:33:36 -0700 | [diff] [blame] | 241 | |
| 242 | // Whether a failure in the postinstall step for this partition should be |
| 243 | // ignored. |
| 244 | optional bool postinstall_optional = 9; |
Alex Deymo | a12ee11 | 2015-08-12 22:19:32 -0700 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | message DeltaArchiveManifest { |
Alex Deymo | c1d7f12 | 2015-09-10 15:15:42 -0700 | [diff] [blame] | 248 | // Only present in major version = 1. List of install operations for the |
| 249 | // kernel and rootfs partitions. For major version = 2 see the |partitions| |
| 250 | // field. |
Andrew de los Reyes | 1e338b8 | 2010-01-22 14:57:27 -0800 | [diff] [blame] | 251 | repeated InstallOperation install_operations = 1; |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 252 | repeated InstallOperation kernel_install_operations = 2; |
Andrew de los Reyes | 1e338b8 | 2010-01-22 14:57:27 -0800 | [diff] [blame] | 253 | |
| 254 | // (At time of writing) usually 4096 |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 255 | optional uint32 block_size = 3 [default = 4096]; |
Andrew de los Reyes | 94f025d | 2010-08-16 17:17:27 -0700 | [diff] [blame] | 256 | |
| 257 | // If signatures are present, the offset into the blobs, generally |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 258 | // tacked onto the end of the file, and the length. We use an offset |
| 259 | // rather than a bool to allow for more flexibility in future file formats. |
| 260 | // If either is absent, it means signatures aren't supported in this |
Andrew de los Reyes | 94f025d | 2010-08-16 17:17:27 -0700 | [diff] [blame] | 261 | // file. |
| 262 | optional uint64 signatures_offset = 4; |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 263 | optional uint64 signatures_size = 5; |
Darin Petkov | 36a5822 | 2010-10-07 22:00:09 -0700 | [diff] [blame] | 264 | |
Alex Deymo | c1d7f12 | 2015-09-10 15:15:42 -0700 | [diff] [blame] | 265 | // Only present in major version = 1. Partition metadata used to validate the |
| 266 | // update. For major version = 2 see the |partitions| field. |
Darin Petkov | 36a5822 | 2010-10-07 22:00:09 -0700 | [diff] [blame] | 267 | optional PartitionInfo old_kernel_info = 6; |
| 268 | optional PartitionInfo new_kernel_info = 7; |
| 269 | optional PartitionInfo old_rootfs_info = 8; |
| 270 | optional PartitionInfo new_rootfs_info = 9; |
Don Garrett | 0dd3985 | 2013-04-03 16:55:42 -0700 | [diff] [blame] | 271 | |
| 272 | // old_image_info will only be present for delta images. |
| 273 | optional ImageInfo old_image_info = 10; |
| 274 | |
| 275 | optional ImageInfo new_image_info = 11; |
Don Garrett | b8dd1d9 | 2013-11-22 17:40:02 -0800 | [diff] [blame] | 276 | |
Alex Deymo | c1d7f12 | 2015-09-10 15:15:42 -0700 | [diff] [blame] | 277 | // The minor version, also referred as "delta version", of the payload. |
Don Garrett | b8dd1d9 | 2013-11-22 17:40:02 -0800 | [diff] [blame] | 278 | optional uint32 minor_version = 12 [default = 0]; |
Alex Deymo | ac6246a | 2015-08-13 14:00:22 -0700 | [diff] [blame] | 279 | |
Alex Deymo | c1d7f12 | 2015-09-10 15:15:42 -0700 | [diff] [blame] | 280 | // Only present in major version >= 2. List of partitions that will be |
| 281 | // updated, in the order they will be updated. This field replaces the |
| 282 | // |install_operations|, |kernel_install_operations| and the |
| 283 | // |{old,new}_{kernel,rootfs}_info| fields used in major version = 1. This |
| 284 | // array can have more than two partitions if needed, and they are identified |
| 285 | // by the partition name. |
Alex Deymo | ac6246a | 2015-08-13 14:00:22 -0700 | [diff] [blame] | 286 | repeated PartitionUpdate partitions = 13; |
Andrew de los Reyes | 1e338b8 | 2010-01-22 14:57:27 -0800 | [diff] [blame] | 287 | } |