update_metadata.proto 15 KB

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