blob: 40ba24f705a150c9e039bd4ab0ff77ba5998f798 [file] [log] [blame]
Darin Petkov36a58222010-10-07 22:00:09 -07001// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
adlr@google.com3defe6a2009-12-04 20:57:17 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Update file format: A delta update file contains all the deltas needed
6// to update a system from one specific version to another specific
7// version. The update format is represented by this struct pseudocode:
8// struct delta_update_file {
9// char magic[4] = "CrAU";
Andrew de los Reyes0c440052010-08-20 11:25:54 -070010// uint64 file_format_version = 1;
Andrew de los Reyes1e338b82010-01-22 14:57:27 -080011// uint64 manifest_size; // Size of protobuf DeltaArchiveManifest
12// // The Bzip2 compressed DeltaArchiveManifest
13// char manifest[];
adlr@google.com3defe6a2009-12-04 20:57:17 +000014//
15// // Data blobs for files, no specific format. The specific offset
16// // and length of each data blob is recorded in the DeltaArchiveManifest.
17// struct {
18// char data[];
19// } blobs[];
20//
Andrew de los Reyes94f025d2010-08-16 17:17:27 -070021// // These two are not signed:
22// uint64 signatures_message_size;
23// char signatures_message[];
24//
adlr@google.com3defe6a2009-12-04 20:57:17 +000025// };
26
Andrew de los Reyes1e338b82010-01-22 14:57:27 -080027// The DeltaArchiveManifest protobuf is an ordered list of InstallOperation
28// objects. These objects are stored in a linear array in the
29// DeltaArchiveManifest. Each operation is applied in order by the client.
adlr@google.com3defe6a2009-12-04 20:57:17 +000030
Andrew de los Reyes1e338b82010-01-22 14:57:27 -080031// The DeltaArchiveManifest also contains the initial and final
32// checksums for the device.
adlr@google.com3defe6a2009-12-04 20:57:17 +000033
Andrew de los Reyes1e338b82010-01-22 14:57:27 -080034// The client will perform each InstallOperation in order, beginning even
35// before the entire delta file is downloaded (but after at least the
36// protobuf is downloaded). The types of operations are explained:
37// - REPLACE: Replace the dst_extents on the drive with the attached data,
38// zero padding out to block size.
39// - REPLACE_BZ: bzip2-uncompress the attached data and write it into
40// dst_extents on the drive, zero padding to block size.
41// - MOVE: Copy the data in src_extents to dst_extents. Extents may overlap,
42// so it may be desirable to read all src_extents data into memory before
43// writing it out.
44// - BSDIFF: Read src_length bytes from src_extents into memory, perform
45// bspatch with attached data, write new data to dst_extents, zero padding
46// to block size.
adlr@google.com3defe6a2009-12-04 20:57:17 +000047
48package chromeos_update_engine;
49
Andrew de los Reyes1e338b82010-01-22 14:57:27 -080050// Data is packed into blocks on disk, always starting from the beginning
51// of the block. If a file's data is too large for one block, it overflows
52// into another block, which may or may not be the following block on the
53// physical partition. An ordered list of extents is another
54// representation of an ordered list of blocks. For example, a file stored
55// in blocks 9, 10, 11, 2, 18, 12 (in that order) would be stored in
56// extents { {9, 3}, {2, 1}, {18, 1}, {12, 1} } (in that order).
57// In general, files are stored sequentially on disk, so it's more efficient
58// to use extents to encode the block lists (this is effectively
59// run-length encoding).
60// A sentinel value (kuint64max) as the start block denotes a sparse-hole
61// in a file whose block-length is specified by num_blocks.
adlr@google.com3defe6a2009-12-04 20:57:17 +000062
Andrew de los Reyes94f025d2010-08-16 17:17:27 -070063// Signatures: Updates may be signed by the OS vendor. The client verifies
64// an update's signature by hashing the entire download. The section of the
65// download the contains the signature is at the end of the file, so when
66// signing a file, only the part up to the signature part is signed.
67// Then, the client looks inside the download's Signatures message for a
68// Signature message that it knows how to handle. Generally, a client will
69// only know how to handle one type of signature, but an update may contain
70// many signatures to support many different types of client. Then client
71// selects a Signature message and uses that, along with a known public key,
72// to verify the download. The public key is expected to be part of the
73// client.
74
Andrew de los Reyes1e338b82010-01-22 14:57:27 -080075message Extent {
76 optional uint64 start_block = 1;
77 optional uint64 num_blocks = 2;
adlr@google.com3defe6a2009-12-04 20:57:17 +000078}
79
Andrew de los Reyes94f025d2010-08-16 17:17:27 -070080message Signatures {
81 message Signature {
82 optional uint32 version = 1;
Andrew de los Reyes0c440052010-08-20 11:25:54 -070083 optional bytes data = 2;
Andrew de los Reyes94f025d2010-08-16 17:17:27 -070084 }
85 repeated Signature signatures = 1;
86}
87
Darin Petkov36a58222010-10-07 22:00:09 -070088message PartitionInfo {
89 optional uint64 size = 1;
90 optional bytes hash = 2;
91}
92
Andrew de los Reyes1e338b82010-01-22 14:57:27 -080093message DeltaArchiveManifest {
94 message InstallOperation {
95 enum Type {
96 REPLACE = 0; // Replace destination extents w/ attached data
97 REPLACE_BZ = 1; // Replace destination extents w/ attached bzipped data
98 MOVE = 2; // Move source extents to destination extents
99 BSDIFF = 3; // The data is a bsdiff binary diff
100 }
101 required Type type = 1;
102 // The offset into the delta file (after the protobuf)
103 // where the data (if any) is stored
104 optional uint32 data_offset = 2;
105 // The length of the data in the delta file
106 optional uint32 data_length = 3;
107
108 // Ordered list of extents that are read from (if any) and written to.
109 repeated Extent src_extents = 4;
110 // Byte length of src, not necessarily block aligned. It's only used for
111 // BSDIFF, because we need to pass that external program the number
112 // of bytes to read from the blocks we pass it.
113 optional uint64 src_length = 5;
114
115 repeated Extent dst_extents = 6;
116 // byte length of dst, not necessarily block aligned. It's only used for
117 // BSDIFF, because we need to fill in the rest of the last block
118 // that bsdiff writes with '\0' bytes.
119 optional uint64 dst_length = 7;
120 }
121 repeated InstallOperation install_operations = 1;
Andrew de los Reyesf4c7ef12010-04-30 10:37:00 -0700122 repeated InstallOperation kernel_install_operations = 2;
Andrew de los Reyes1e338b82010-01-22 14:57:27 -0800123
124 // (At time of writing) usually 4096
Andrew de los Reyesf4c7ef12010-04-30 10:37:00 -0700125 optional uint32 block_size = 3 [default = 4096];
Andrew de los Reyes94f025d2010-08-16 17:17:27 -0700126
127 // If signatures are present, the offset into the blobs, generally
Andrew de los Reyes932bc4c2010-08-23 18:14:09 -0700128 // tacked onto the end of the file, and the length. We use an offset
129 // rather than a bool to allow for more flexibility in future file formats.
130 // If either is absent, it means signatures aren't supported in this
Andrew de los Reyes94f025d2010-08-16 17:17:27 -0700131 // file.
132 optional uint64 signatures_offset = 4;
Andrew de los Reyes932bc4c2010-08-23 18:14:09 -0700133 optional uint64 signatures_size = 5;
Darin Petkov36a58222010-10-07 22:00:09 -0700134
135 // Partition data that can be used to validate the update.
136 optional PartitionInfo old_kernel_info = 6;
137 optional PartitionInfo new_kernel_info = 7;
138 optional PartitionInfo old_rootfs_info = 8;
139 optional PartitionInfo new_rootfs_info = 9;
Andrew de los Reyes1e338b82010-01-22 14:57:27 -0800140}