Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include <sys/types.h> |
| 6 | #include <sys/stat.h> |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 7 | #include <errno.h> |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 8 | #include <fcntl.h> |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 9 | #include <unistd.h> |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 10 | |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 11 | #include <set> |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 12 | #include <string> |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 13 | #include <vector> |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 14 | |
| 15 | #include <base/command_line.h> |
| 16 | #include <base/logging.h> |
Andrew de los Reyes | c24e3f3 | 2011-08-30 15:45:20 -0700 | [diff] [blame] | 17 | #include <base/string_number_conversions.h> |
| 18 | #include <base/string_split.h> |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 19 | #include <gflags/gflags.h> |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 20 | #include <glib.h> |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 21 | |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 22 | #include "update_engine/delta_diff_generator.h" |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 23 | #include "update_engine/delta_performer.h" |
Darin Petkov | da8c136 | 2011-01-13 14:04:24 -0800 | [diff] [blame] | 24 | #include "update_engine/payload_signer.h" |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 25 | #include "update_engine/prefs.h" |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 26 | #include "update_engine/subprocess.h" |
Darin Petkov | 9c0baf8 | 2010-10-07 13:44:48 -0700 | [diff] [blame] | 27 | #include "update_engine/terminator.h" |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 28 | #include "update_engine/update_metadata.pb.h" |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 29 | #include "update_engine/utils.h" |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 30 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 31 | DEFINE_string(old_dir, "", |
| 32 | "Directory where the old rootfs is loop mounted read-only"); |
| 33 | DEFINE_string(new_dir, "", |
| 34 | "Directory where the new rootfs is loop mounted read-only"); |
| 35 | DEFINE_string(old_image, "", "Path to the old rootfs"); |
| 36 | DEFINE_string(new_image, "", "Path to the new rootfs"); |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 37 | DEFINE_string(old_kernel, "", "Path to the old kernel partition image"); |
| 38 | DEFINE_string(new_kernel, "", "Path to the new kernel partition image"); |
Darin Petkov | da8c136 | 2011-01-13 14:04:24 -0800 | [diff] [blame] | 39 | DEFINE_string(in_file, "", |
| 40 | "Path to input delta payload file used to hash/sign payloads " |
| 41 | "and apply delta over old_image (for debugging)"); |
| 42 | DEFINE_string(out_file, "", "Path to output delta payload file"); |
| 43 | DEFINE_string(out_hash_file, "", "Path to output hash file"); |
Jay Srinivasan | f431870 | 2012-09-24 11:56:24 -0700 | [diff] [blame] | 44 | DEFINE_string(out_metadata_hash_file, "", "Path to output metadata hash file"); |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 45 | DEFINE_string(private_key, "", "Path to private key in .pem format"); |
Darin Petkov | adb3cef | 2011-01-13 16:16:08 -0800 | [diff] [blame] | 46 | DEFINE_string(public_key, "", "Path to public key in .pem format"); |
Andrew de los Reyes | c24e3f3 | 2011-08-30 15:45:20 -0700 | [diff] [blame] | 47 | DEFINE_int32(public_key_version, |
| 48 | chromeos_update_engine::kSignatureMessageCurrentVersion, |
| 49 | "Key-check version # of client"); |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 50 | DEFINE_string(prefs_dir, "/tmp/update_engine_prefs", |
Darin Petkov | da8c136 | 2011-01-13 14:04:24 -0800 | [diff] [blame] | 51 | "Preferences directory, used with apply_delta"); |
Andrew de los Reyes | c24e3f3 | 2011-08-30 15:45:20 -0700 | [diff] [blame] | 52 | DEFINE_string(signature_size, "", |
| 53 | "Raw signature size used for hash calculation. " |
| 54 | "You may pass in multiple sizes by colon separating them. E.g. " |
| 55 | "2048:2048:4096 will assume 3 signatures, the first two with " |
| 56 | "2048 size and the last 4096."); |
| 57 | DEFINE_string(signature_file, "", |
| 58 | "Raw signature file to sign payload with. To pass multiple " |
| 59 | "signatures, use a single argument with a colon between paths, " |
| 60 | "e.g. /path/to/sig:/path/to/next:/path/to/last_sig . Each " |
| 61 | "signature will be assigned a client version, starting from " |
| 62 | "kSignatureOriginalVersion."); |
Darin Petkov | 8e447e0 | 2013-04-16 16:23:50 +0200 | [diff] [blame] | 63 | DEFINE_int32(chunk_size, -1, "Payload chunk size (-1 -- no limit/default)"); |
Chris Sosa | d5ae156 | 2013-04-23 13:20:18 -0700 | [diff] [blame] | 64 | DEFINE_int64(rootfs_partition_size, |
| 65 | chromeos_update_engine::kRootFSPartitionSize, |
| 66 | "RootFS partition size for the image once installed"); |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 67 | |
Don Garrett | 0dd3985 | 2013-04-03 16:55:42 -0700 | [diff] [blame] | 68 | DEFINE_string(old_channel, "", |
| 69 | "The channel for the old image. 'dev-channel', 'npo-channel', " |
| 70 | "etc. Ignored, except during delta generation."); |
| 71 | DEFINE_string(old_board, "", |
| 72 | "The board for the old image. 'x86-mario', 'lumpy', " |
| 73 | "etc. Ignored, except during delta generation."); |
| 74 | DEFINE_string(old_version, "", |
| 75 | "The build version of the old image. 1.2.3, etc."); |
| 76 | DEFINE_string(old_key, "", |
| 77 | "The key used to sign the old image. 'premp', 'mp', 'mp-v3'," |
| 78 | " etc"); |
| 79 | DEFINE_string(old_build_channel, "", |
| 80 | "The channel for the build of the old image. 'dev-channel', " |
| 81 | "etc, but will never contain special channels such as " |
| 82 | "'npo-channel'. Ignored, except during delta generation."); |
| 83 | DEFINE_string(old_build_version, "", |
| 84 | "The version of the build containing the old image."); |
| 85 | |
| 86 | DEFINE_string(new_channel, "", |
| 87 | "The channel for the new image. 'dev-channel', 'npo-channel', " |
| 88 | "etc. Ignored, except during delta generation."); |
| 89 | DEFINE_string(new_board, "", |
| 90 | "The board for the new image. 'x86-mario', 'lumpy', " |
| 91 | "etc. Ignored, except during delta generation."); |
| 92 | DEFINE_string(new_version, "", |
| 93 | "The build version of the new image. 1.2.3, etc."); |
| 94 | DEFINE_string(new_key, "", |
| 95 | "The key used to sign the new image. 'premp', 'mp', 'mp-v3'," |
| 96 | " etc"); |
| 97 | DEFINE_string(new_build_channel, "", |
| 98 | "The channel for the build of the new image. 'dev-channel', " |
| 99 | "etc, but will never contain special channels such as " |
| 100 | "'npo-channel'. Ignored, except during delta generation."); |
| 101 | DEFINE_string(new_build_version, "", |
| 102 | "The version of the build containing the new image."); |
| 103 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 104 | // This file contains a simple program that takes an old path, a new path, |
| 105 | // and an output file as arguments and the path to an output file and |
| 106 | // generates a delta that can be sent to Chrome OS clients. |
| 107 | |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 108 | using std::set; |
| 109 | using std::string; |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 110 | using std::vector; |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 111 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 112 | namespace chromeos_update_engine { |
| 113 | |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 114 | namespace { |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 115 | |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 116 | bool IsDir(const char* path) { |
| 117 | struct stat stbuf; |
| 118 | TEST_AND_RETURN_FALSE_ERRNO(lstat(path, &stbuf) == 0); |
| 119 | return S_ISDIR(stbuf.st_mode); |
| 120 | } |
| 121 | |
Jay Srinivasan | f431870 | 2012-09-24 11:56:24 -0700 | [diff] [blame] | 122 | void ParseSignatureSizes(vector<int>* sizes) { |
| 123 | LOG_IF(FATAL, FLAGS_signature_size.empty()) |
| 124 | << "Must pass --signature_size to calculate hash for signing."; |
| 125 | vector<string> strsizes; |
| 126 | base::SplitString(FLAGS_signature_size, ':', &strsizes); |
| 127 | for (vector<string>::iterator it = strsizes.begin(), e = strsizes.end(); |
| 128 | it != e; ++it) { |
| 129 | int size = 0; |
| 130 | bool parsing_successful = base::StringToInt(*it, &size); |
| 131 | LOG_IF(FATAL, !parsing_successful) |
| 132 | << "Invalid signature size: " << *it; |
| 133 | sizes->push_back(size); |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | |
Don Garrett | 0dd3985 | 2013-04-03 16:55:42 -0700 | [diff] [blame] | 138 | bool ParseImageInfo(const string& channel, |
| 139 | const string& board, |
| 140 | const string& version, |
| 141 | const string& key, |
| 142 | const string& build_channel, |
| 143 | const string& build_version, |
| 144 | ImageInfo* image_info) { |
| 145 | |
| 146 | // All of these arguments should be present or missing. |
| 147 | bool empty = channel.empty(); |
| 148 | |
| 149 | CHECK_EQ(channel.empty(), empty); |
| 150 | CHECK_EQ(board.empty(), empty); |
| 151 | CHECK_EQ(version.empty(), empty); |
| 152 | CHECK_EQ(key.empty(), empty); |
| 153 | |
| 154 | if (empty) |
| 155 | return false; |
| 156 | |
| 157 | image_info->set_channel(channel); |
| 158 | image_info->set_board(board); |
| 159 | image_info->set_version(version); |
| 160 | image_info->set_key(key); |
| 161 | |
| 162 | image_info->set_build_channel( |
| 163 | build_channel.empty() ? channel : build_channel); |
| 164 | |
| 165 | image_info->set_build_version( |
| 166 | build_version.empty() ? version : build_version); |
| 167 | |
| 168 | return true; |
| 169 | } |
| 170 | |
| 171 | |
Darin Petkov | da8c136 | 2011-01-13 14:04:24 -0800 | [diff] [blame] | 172 | void CalculatePayloadHashForSigning() { |
| 173 | LOG(INFO) << "Calculating payload hash for signing."; |
| 174 | LOG_IF(FATAL, FLAGS_in_file.empty()) |
| 175 | << "Must pass --in_file to calculate hash for signing."; |
| 176 | LOG_IF(FATAL, FLAGS_out_hash_file.empty()) |
| 177 | << "Must pass --out_hash_file to calculate hash for signing."; |
Andrew de los Reyes | c24e3f3 | 2011-08-30 15:45:20 -0700 | [diff] [blame] | 178 | vector<int> sizes; |
Jay Srinivasan | f431870 | 2012-09-24 11:56:24 -0700 | [diff] [blame] | 179 | ParseSignatureSizes(&sizes); |
| 180 | |
Darin Petkov | da8c136 | 2011-01-13 14:04:24 -0800 | [diff] [blame] | 181 | vector<char> hash; |
Jay Srinivasan | f431870 | 2012-09-24 11:56:24 -0700 | [diff] [blame] | 182 | bool result = PayloadSigner::HashPayloadForSigning(FLAGS_in_file, sizes, |
| 183 | &hash); |
| 184 | CHECK(result); |
| 185 | |
| 186 | result = utils::WriteFile(FLAGS_out_hash_file.c_str(), hash.data(), |
| 187 | hash.size()); |
| 188 | CHECK(result); |
Darin Petkov | da8c136 | 2011-01-13 14:04:24 -0800 | [diff] [blame] | 189 | LOG(INFO) << "Done calculating payload hash for signing."; |
| 190 | } |
| 191 | |
Jay Srinivasan | f431870 | 2012-09-24 11:56:24 -0700 | [diff] [blame] | 192 | |
| 193 | void CalculateMetadataHashForSigning() { |
| 194 | LOG(INFO) << "Calculating metadata hash for signing."; |
| 195 | LOG_IF(FATAL, FLAGS_in_file.empty()) |
| 196 | << "Must pass --in_file to calculate metadata hash for signing."; |
| 197 | LOG_IF(FATAL, FLAGS_out_metadata_hash_file.empty()) |
| 198 | << "Must pass --out_metadata_hash_file to calculate metadata hash."; |
| 199 | vector<int> sizes; |
| 200 | ParseSignatureSizes(&sizes); |
| 201 | |
| 202 | vector<char> hash; |
| 203 | bool result = PayloadSigner::HashMetadataForSigning(FLAGS_in_file, &hash); |
| 204 | CHECK(result); |
| 205 | |
| 206 | result = utils::WriteFile(FLAGS_out_metadata_hash_file.c_str(), hash.data(), |
| 207 | hash.size()); |
| 208 | CHECK(result); |
| 209 | |
| 210 | LOG(INFO) << "Done calculating metadata hash for signing."; |
| 211 | } |
| 212 | |
Darin Petkov | da8c136 | 2011-01-13 14:04:24 -0800 | [diff] [blame] | 213 | void SignPayload() { |
| 214 | LOG(INFO) << "Signing payload."; |
| 215 | LOG_IF(FATAL, FLAGS_in_file.empty()) |
| 216 | << "Must pass --in_file to sign payload."; |
| 217 | LOG_IF(FATAL, FLAGS_out_file.empty()) |
| 218 | << "Must pass --out_file to sign payload."; |
| 219 | LOG_IF(FATAL, FLAGS_signature_file.empty()) |
| 220 | << "Must pass --signature_file to sign payload."; |
Andrew de los Reyes | c24e3f3 | 2011-08-30 15:45:20 -0700 | [diff] [blame] | 221 | vector<vector<char> > signatures; |
| 222 | vector<string> signature_files; |
| 223 | base::SplitString(FLAGS_signature_file, ':', &signature_files); |
| 224 | for (vector<string>::iterator it = signature_files.begin(), |
| 225 | e = signature_files.end(); it != e; ++it) { |
| 226 | vector<char> signature; |
| 227 | CHECK(utils::ReadFile(*it, &signature)); |
| 228 | signatures.push_back(signature); |
| 229 | } |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 230 | uint64_t final_metadata_size; |
Darin Petkov | da8c136 | 2011-01-13 14:04:24 -0800 | [diff] [blame] | 231 | CHECK(PayloadSigner::AddSignatureToPayload( |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 232 | FLAGS_in_file, signatures, FLAGS_out_file, &final_metadata_size)); |
| 233 | LOG(INFO) << "Done signing payload. Final metadata size = " |
| 234 | << final_metadata_size; |
Darin Petkov | da8c136 | 2011-01-13 14:04:24 -0800 | [diff] [blame] | 235 | } |
| 236 | |
Darin Petkov | adb3cef | 2011-01-13 16:16:08 -0800 | [diff] [blame] | 237 | void VerifySignedPayload() { |
| 238 | LOG(INFO) << "Verifying signed payload."; |
| 239 | LOG_IF(FATAL, FLAGS_in_file.empty()) |
| 240 | << "Must pass --in_file to verify signed payload."; |
| 241 | LOG_IF(FATAL, FLAGS_public_key.empty()) |
| 242 | << "Must pass --public_key to verify signed payload."; |
Andrew de los Reyes | c24e3f3 | 2011-08-30 15:45:20 -0700 | [diff] [blame] | 243 | CHECK(PayloadSigner::VerifySignedPayload(FLAGS_in_file, FLAGS_public_key, |
| 244 | FLAGS_public_key_version)); |
Darin Petkov | adb3cef | 2011-01-13 16:16:08 -0800 | [diff] [blame] | 245 | LOG(INFO) << "Done verifying signed payload."; |
| 246 | } |
| 247 | |
Darin Petkov | da8c136 | 2011-01-13 14:04:24 -0800 | [diff] [blame] | 248 | void ApplyDelta() { |
| 249 | LOG(INFO) << "Applying delta."; |
| 250 | LOG_IF(FATAL, FLAGS_old_image.empty()) |
| 251 | << "Must pass --old_image to apply delta."; |
| 252 | Prefs prefs; |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 253 | InstallPlan install_plan; |
Darin Petkov | da8c136 | 2011-01-13 14:04:24 -0800 | [diff] [blame] | 254 | LOG(INFO) << "Setting up preferences under: " << FLAGS_prefs_dir; |
| 255 | LOG_IF(ERROR, !prefs.Init(FilePath(FLAGS_prefs_dir))) |
| 256 | << "Failed to initialize preferences."; |
| 257 | // Get original checksums |
| 258 | LOG(INFO) << "Calculating original checksums"; |
| 259 | PartitionInfo kern_info, root_info; |
| 260 | CHECK(DeltaDiffGenerator::InitializePartitionInfo(true, // is_kernel |
| 261 | FLAGS_old_kernel, |
| 262 | &kern_info)); |
| 263 | CHECK(DeltaDiffGenerator::InitializePartitionInfo(false, // is_kernel |
| 264 | FLAGS_old_image, |
| 265 | &root_info)); |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 266 | install_plan.kernel_hash.assign(kern_info.hash().begin(), |
| 267 | kern_info.hash().end()); |
| 268 | install_plan.rootfs_hash.assign(root_info.hash().begin(), |
| 269 | root_info.hash().end()); |
Jay Srinivasan | f057205 | 2012-10-23 18:12:56 -0700 | [diff] [blame] | 270 | DeltaPerformer performer(&prefs, NULL, &install_plan); |
Darin Petkov | da8c136 | 2011-01-13 14:04:24 -0800 | [diff] [blame] | 271 | CHECK_EQ(performer.Open(FLAGS_old_image.c_str(), 0, 0), 0); |
| 272 | CHECK(performer.OpenKernel(FLAGS_old_kernel.c_str())); |
| 273 | vector<char> buf(1024 * 1024); |
| 274 | int fd = open(FLAGS_in_file.c_str(), O_RDONLY, 0); |
| 275 | CHECK_GE(fd, 0); |
| 276 | ScopedFdCloser fd_closer(&fd); |
| 277 | for (off_t offset = 0;; offset += buf.size()) { |
| 278 | ssize_t bytes_read; |
| 279 | CHECK(utils::PReadAll(fd, &buf[0], buf.size(), offset, &bytes_read)); |
| 280 | if (bytes_read == 0) |
| 281 | break; |
| 282 | CHECK_EQ(performer.Write(&buf[0], bytes_read), bytes_read); |
| 283 | } |
| 284 | CHECK_EQ(performer.Close(), 0); |
| 285 | DeltaPerformer::ResetUpdateProgress(&prefs, false); |
| 286 | LOG(INFO) << "Done applying delta."; |
| 287 | } |
| 288 | |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 289 | int Main(int argc, char** argv) { |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 290 | google::ParseCommandLineFlags(&argc, &argv, true); |
| 291 | CommandLine::Init(argc, argv); |
Darin Petkov | 9c0baf8 | 2010-10-07 13:44:48 -0700 | [diff] [blame] | 292 | Terminator::Init(); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 293 | Subprocess::Init(); |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 294 | logging::InitLogging("delta_generator.log", |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 295 | logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG, |
| 296 | logging::DONT_LOCK_LOG_FILE, |
Chris Masone | d903c3b | 2011-05-12 15:35:46 -0700 | [diff] [blame] | 297 | logging::APPEND_TO_OLD_LOG_FILE, |
| 298 | logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS); |
Jay Srinivasan | f431870 | 2012-09-24 11:56:24 -0700 | [diff] [blame] | 299 | if (!FLAGS_signature_size.empty()) { |
| 300 | bool work_done = false; |
| 301 | if (!FLAGS_out_hash_file.empty()) { |
| 302 | CalculatePayloadHashForSigning(); |
| 303 | work_done = true; |
| 304 | } |
| 305 | if (!FLAGS_out_metadata_hash_file.empty()) { |
| 306 | CalculateMetadataHashForSigning(); |
| 307 | work_done = true; |
| 308 | } |
| 309 | if (!work_done) { |
| 310 | LOG(FATAL) << "Neither payload hash file nor metadata hash file supplied"; |
| 311 | } |
Darin Petkov | da8c136 | 2011-01-13 14:04:24 -0800 | [diff] [blame] | 312 | return 0; |
| 313 | } |
| 314 | if (!FLAGS_signature_file.empty()) { |
| 315 | SignPayload(); |
| 316 | return 0; |
| 317 | } |
Darin Petkov | adb3cef | 2011-01-13 16:16:08 -0800 | [diff] [blame] | 318 | if (!FLAGS_public_key.empty()) { |
| 319 | VerifySignedPayload(); |
| 320 | return 0; |
| 321 | } |
Darin Petkov | da8c136 | 2011-01-13 14:04:24 -0800 | [diff] [blame] | 322 | if (!FLAGS_in_file.empty()) { |
| 323 | ApplyDelta(); |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 324 | return 0; |
| 325 | } |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 326 | CHECK(!FLAGS_new_image.empty()); |
| 327 | CHECK(!FLAGS_out_file.empty()); |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 328 | CHECK(!FLAGS_new_kernel.empty()); |
Don Garrett | 0dd3985 | 2013-04-03 16:55:42 -0700 | [diff] [blame] | 329 | |
| 330 | bool is_delta = !FLAGS_old_image.empty(); |
| 331 | |
| 332 | ImageInfo old_image_info; |
| 333 | ImageInfo new_image_info; |
| 334 | |
Don Garrett | 60fc59c | 2013-10-18 11:43:52 -0700 | [diff] [blame] | 335 | // Ignore failures. These are optional arguments. |
Don Garrett | 0dd3985 | 2013-04-03 16:55:42 -0700 | [diff] [blame] | 336 | ParseImageInfo(FLAGS_new_channel, |
| 337 | FLAGS_new_board, |
| 338 | FLAGS_new_version, |
| 339 | FLAGS_new_key, |
| 340 | FLAGS_new_build_channel, |
| 341 | FLAGS_new_build_version, |
| 342 | &new_image_info); |
| 343 | |
Don Garrett | 60fc59c | 2013-10-18 11:43:52 -0700 | [diff] [blame] | 344 | // Ignore failures. These are optional arguments. |
| 345 | ParseImageInfo(FLAGS_old_channel, |
| 346 | FLAGS_old_board, |
| 347 | FLAGS_old_version, |
| 348 | FLAGS_old_key, |
| 349 | FLAGS_old_build_channel, |
| 350 | FLAGS_old_build_version, |
| 351 | &old_image_info); |
Don Garrett | 0dd3985 | 2013-04-03 16:55:42 -0700 | [diff] [blame] | 352 | |
| 353 | if (is_delta) { |
Andrew de los Reyes | 27f7d37 | 2010-10-07 11:26:07 -0700 | [diff] [blame] | 354 | LOG(INFO) << "Generating delta update"; |
Andrew de los Reyes | 27f7d37 | 2010-10-07 11:26:07 -0700 | [diff] [blame] | 355 | CHECK(!FLAGS_old_dir.empty()); |
| 356 | CHECK(!FLAGS_new_dir.empty()); |
| 357 | if ((!IsDir(FLAGS_old_dir.c_str())) || (!IsDir(FLAGS_new_dir.c_str()))) { |
| 358 | LOG(FATAL) << "old_dir or new_dir not directory"; |
| 359 | } |
Don Garrett | 0dd3985 | 2013-04-03 16:55:42 -0700 | [diff] [blame] | 360 | } else { |
| 361 | LOG(INFO) << "Generating full update"; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 362 | } |
Don Garrett | 0dd3985 | 2013-04-03 16:55:42 -0700 | [diff] [blame] | 363 | |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 364 | uint64_t metadata_size; |
Don Garrett | 0dd3985 | 2013-04-03 16:55:42 -0700 | [diff] [blame] | 365 | if (!DeltaDiffGenerator::GenerateDeltaUpdateFile( |
| 366 | FLAGS_old_dir, |
| 367 | FLAGS_old_image, |
| 368 | FLAGS_new_dir, |
| 369 | FLAGS_new_image, |
| 370 | FLAGS_old_kernel, |
| 371 | FLAGS_new_kernel, |
| 372 | FLAGS_out_file, |
| 373 | FLAGS_private_key, |
| 374 | FLAGS_chunk_size, |
| 375 | FLAGS_rootfs_partition_size, |
| 376 | is_delta ? &old_image_info : NULL, |
| 377 | &new_image_info, |
| 378 | &metadata_size)) { |
Chris Sosa | c7c19cd | 2011-02-08 17:02:12 -0800 | [diff] [blame] | 379 | return 1; |
| 380 | } |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 381 | return 0; |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | } // namespace {} |
| 385 | |
| 386 | } // namespace chromeos_update_engine |
| 387 | |
| 388 | int main(int argc, char** argv) { |
| 389 | return chromeos_update_engine::Main(argc, argv); |
| 390 | } |