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 | |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 17 | #include <errno.h> |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 18 | #include <fcntl.h> |
Alex Deymo | 161c4a1 | 2014-05-16 15:56:21 -0700 | [diff] [blame] | 19 | #include <sys/stat.h> |
| 20 | #include <sys/types.h> |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 21 | #include <unistd.h> |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 22 | |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 23 | #include <set> |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 24 | #include <string> |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 25 | #include <vector> |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 26 | |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 27 | #include <base/logging.h> |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 28 | #include <base/strings/string_number_conversions.h> |
| 29 | #include <base/strings/string_split.h> |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 30 | #include <brillo/flag_helper.h> |
Sen Jiang | 05feee0 | 2015-11-11 15:59:49 -0800 | [diff] [blame] | 31 | #include <brillo/key_value_store.h> |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 32 | |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 33 | #include "update_engine/common/prefs.h" |
| 34 | #include "update_engine/common/terminator.h" |
| 35 | #include "update_engine/common/utils.h" |
| 36 | #include "update_engine/payload_consumer/delta_performer.h" |
| 37 | #include "update_engine/payload_consumer/payload_constants.h" |
Alex Deymo | 161c4a1 | 2014-05-16 15:56:21 -0700 | [diff] [blame] | 38 | #include "update_engine/payload_generator/delta_diff_generator.h" |
Alex Deymo | 1415857 | 2015-06-13 03:37:08 -0700 | [diff] [blame] | 39 | #include "update_engine/payload_generator/delta_diff_utils.h" |
Alex Deymo | f1cbe17 | 2015-03-05 15:58:37 -0800 | [diff] [blame] | 40 | #include "update_engine/payload_generator/payload_generation_config.h" |
Alex Deymo | 923d8fa | 2014-07-15 17:58:51 -0700 | [diff] [blame] | 41 | #include "update_engine/payload_generator/payload_signer.h" |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 42 | #include "update_engine/update_metadata.pb.h" |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 43 | |
| 44 | // This file contains a simple program that takes an old path, a new path, |
| 45 | // and an output file as arguments and the path to an output file and |
| 46 | // generates a delta that can be sent to Chrome OS clients. |
| 47 | |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 48 | using std::set; |
| 49 | using std::string; |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 50 | using std::vector; |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 51 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 52 | namespace chromeos_update_engine { |
| 53 | |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 54 | namespace { |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 55 | |
Don Garrett | c2e9f5f | 2013-10-18 16:42:40 -0700 | [diff] [blame] | 56 | void ParseSignatureSizes(const string& signature_sizes_flag, |
| 57 | vector<int>* signature_sizes) { |
| 58 | signature_sizes->clear(); |
Alex Vakulenko | 0103c36 | 2016-01-20 07:56:15 -0800 | [diff] [blame] | 59 | vector<string> split_strings = |
| 60 | base::SplitString(signature_sizes_flag, ":", base::TRIM_WHITESPACE, |
| 61 | base::SPLIT_WANT_ALL); |
Alex Deymo | 020600d | 2014-11-05 21:05:55 -0800 | [diff] [blame] | 62 | for (const string& str : split_strings) { |
Jay Srinivasan | f431870 | 2012-09-24 11:56:24 -0700 | [diff] [blame] | 63 | int size = 0; |
Alex Deymo | 020600d | 2014-11-05 21:05:55 -0800 | [diff] [blame] | 64 | bool parsing_successful = base::StringToInt(str, &size); |
Jay Srinivasan | f431870 | 2012-09-24 11:56:24 -0700 | [diff] [blame] | 65 | LOG_IF(FATAL, !parsing_successful) |
Alex Deymo | 020600d | 2014-11-05 21:05:55 -0800 | [diff] [blame] | 66 | << "Invalid signature size: " << str; |
Don Garrett | c2e9f5f | 2013-10-18 16:42:40 -0700 | [diff] [blame] | 67 | |
| 68 | LOG_IF(FATAL, size != (2048 / 8)) << |
| 69 | "Only signature sizes of 256 bytes are supported."; |
| 70 | |
| 71 | signature_sizes->push_back(size); |
Jay Srinivasan | f431870 | 2012-09-24 11:56:24 -0700 | [diff] [blame] | 72 | } |
| 73 | } |
| 74 | |
Don Garrett | 0dd3985 | 2013-04-03 16:55:42 -0700 | [diff] [blame] | 75 | bool ParseImageInfo(const string& channel, |
| 76 | const string& board, |
| 77 | const string& version, |
| 78 | const string& key, |
| 79 | const string& build_channel, |
| 80 | const string& build_version, |
| 81 | ImageInfo* image_info) { |
Don Garrett | 0dd3985 | 2013-04-03 16:55:42 -0700 | [diff] [blame] | 82 | // All of these arguments should be present or missing. |
| 83 | bool empty = channel.empty(); |
| 84 | |
| 85 | CHECK_EQ(channel.empty(), empty); |
| 86 | CHECK_EQ(board.empty(), empty); |
| 87 | CHECK_EQ(version.empty(), empty); |
| 88 | CHECK_EQ(key.empty(), empty); |
| 89 | |
| 90 | if (empty) |
| 91 | return false; |
| 92 | |
| 93 | image_info->set_channel(channel); |
| 94 | image_info->set_board(board); |
| 95 | image_info->set_version(version); |
| 96 | image_info->set_key(key); |
| 97 | |
| 98 | image_info->set_build_channel( |
| 99 | build_channel.empty() ? channel : build_channel); |
| 100 | |
| 101 | image_info->set_build_version( |
| 102 | build_version.empty() ? version : build_version); |
| 103 | |
| 104 | return true; |
| 105 | } |
| 106 | |
Sen Jiang | 720df3e | 2015-10-01 13:10:44 -0700 | [diff] [blame] | 107 | void CalculateHashForSigning(const vector<int> &sizes, |
| 108 | const string& out_hash_file, |
| 109 | const string& out_metadata_hash_file, |
| 110 | const string& in_file) { |
| 111 | LOG(INFO) << "Calculating hash for signing."; |
Steve Fung | 97b6f5a | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 112 | LOG_IF(FATAL, in_file.empty()) |
Darin Petkov | da8c136 | 2011-01-13 14:04:24 -0800 | [diff] [blame] | 113 | << "Must pass --in_file to calculate hash for signing."; |
Don Garrett | c2e9f5f | 2013-10-18 16:42:40 -0700 | [diff] [blame] | 114 | LOG_IF(FATAL, out_hash_file.empty()) |
Darin Petkov | da8c136 | 2011-01-13 14:04:24 -0800 | [diff] [blame] | 115 | << "Must pass --out_hash_file to calculate hash for signing."; |
Jay Srinivasan | f431870 | 2012-09-24 11:56:24 -0700 | [diff] [blame] | 116 | |
Sen Jiang | 720df3e | 2015-10-01 13:10:44 -0700 | [diff] [blame] | 117 | brillo::Blob payload_hash, metadata_hash; |
| 118 | CHECK(PayloadSigner::HashPayloadForSigning(in_file, sizes, &payload_hash, |
| 119 | &metadata_hash)); |
| 120 | CHECK(utils::WriteFile(out_hash_file.c_str(), payload_hash.data(), |
| 121 | payload_hash.size())); |
| 122 | if (!out_metadata_hash_file.empty()) |
| 123 | CHECK(utils::WriteFile(out_metadata_hash_file.c_str(), metadata_hash.data(), |
| 124 | metadata_hash.size())); |
Jay Srinivasan | f431870 | 2012-09-24 11:56:24 -0700 | [diff] [blame] | 125 | |
Sen Jiang | 720df3e | 2015-10-01 13:10:44 -0700 | [diff] [blame] | 126 | LOG(INFO) << "Done calculating hash for signing."; |
Jay Srinivasan | f431870 | 2012-09-24 11:56:24 -0700 | [diff] [blame] | 127 | } |
| 128 | |
Sen Jiang | 644f618 | 2015-10-06 16:45:57 -0700 | [diff] [blame] | 129 | void SignatureFileFlagToBlobs(const string& signature_file_flag, |
| 130 | vector<brillo::Blob>* signatures) { |
Alex Vakulenko | 0103c36 | 2016-01-20 07:56:15 -0800 | [diff] [blame] | 131 | vector<string> signature_files = |
| 132 | base::SplitString(signature_file_flag, ":", base::TRIM_WHITESPACE, |
| 133 | base::SPLIT_WANT_ALL); |
Sen Jiang | 644f618 | 2015-10-06 16:45:57 -0700 | [diff] [blame] | 134 | for (const string& signature_file : signature_files) { |
| 135 | brillo::Blob signature; |
| 136 | CHECK(utils::ReadFile(signature_file, &signature)); |
| 137 | signatures->push_back(signature); |
| 138 | } |
| 139 | } |
| 140 | |
Steve Fung | 97b6f5a | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 141 | void SignPayload(const string& in_file, |
| 142 | const string& out_file, |
Sen Jiang | 644f618 | 2015-10-06 16:45:57 -0700 | [diff] [blame] | 143 | const string& payload_signature_file, |
| 144 | const string& metadata_signature_file, |
Sen Jiang | d8ae872 | 2015-10-08 15:21:09 -0700 | [diff] [blame] | 145 | const string& out_metadata_size_file) { |
Darin Petkov | da8c136 | 2011-01-13 14:04:24 -0800 | [diff] [blame] | 146 | LOG(INFO) << "Signing payload."; |
Steve Fung | 97b6f5a | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 147 | LOG_IF(FATAL, in_file.empty()) |
Darin Petkov | da8c136 | 2011-01-13 14:04:24 -0800 | [diff] [blame] | 148 | << "Must pass --in_file to sign payload."; |
Steve Fung | 97b6f5a | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 149 | LOG_IF(FATAL, out_file.empty()) |
Darin Petkov | da8c136 | 2011-01-13 14:04:24 -0800 | [diff] [blame] | 150 | << "Must pass --out_file to sign payload."; |
Sen Jiang | 644f618 | 2015-10-06 16:45:57 -0700 | [diff] [blame] | 151 | LOG_IF(FATAL, payload_signature_file.empty()) |
Darin Petkov | da8c136 | 2011-01-13 14:04:24 -0800 | [diff] [blame] | 152 | << "Must pass --signature_file to sign payload."; |
Sen Jiang | 644f618 | 2015-10-06 16:45:57 -0700 | [diff] [blame] | 153 | vector<brillo::Blob> signatures, metadata_signatures; |
| 154 | SignatureFileFlagToBlobs(payload_signature_file, &signatures); |
| 155 | SignatureFileFlagToBlobs(metadata_signature_file, &metadata_signatures); |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 156 | uint64_t final_metadata_size; |
Sen Jiang | 644f618 | 2015-10-06 16:45:57 -0700 | [diff] [blame] | 157 | CHECK(PayloadSigner::AddSignatureToPayload(in_file, signatures, |
| 158 | metadata_signatures, out_file, &final_metadata_size)); |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 159 | LOG(INFO) << "Done signing payload. Final metadata size = " |
| 160 | << final_metadata_size; |
Sen Jiang | d8ae872 | 2015-10-08 15:21:09 -0700 | [diff] [blame] | 161 | if (!out_metadata_size_file.empty()) { |
| 162 | string metadata_size_string = std::to_string(final_metadata_size); |
| 163 | CHECK(utils::WriteFile(out_metadata_size_file.c_str(), |
| 164 | metadata_size_string.data(), |
| 165 | metadata_size_string.size())); |
| 166 | } |
Darin Petkov | da8c136 | 2011-01-13 14:04:24 -0800 | [diff] [blame] | 167 | } |
| 168 | |
Steve Fung | 97b6f5a | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 169 | void VerifySignedPayload(const string& in_file, |
Alex Deymo | b552a68 | 2015-09-30 09:36:49 -0700 | [diff] [blame] | 170 | const string& public_key) { |
Darin Petkov | adb3cef | 2011-01-13 16:16:08 -0800 | [diff] [blame] | 171 | LOG(INFO) << "Verifying signed payload."; |
Steve Fung | 97b6f5a | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 172 | LOG_IF(FATAL, in_file.empty()) |
Darin Petkov | adb3cef | 2011-01-13 16:16:08 -0800 | [diff] [blame] | 173 | << "Must pass --in_file to verify signed payload."; |
Steve Fung | 97b6f5a | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 174 | LOG_IF(FATAL, public_key.empty()) |
Darin Petkov | adb3cef | 2011-01-13 16:16:08 -0800 | [diff] [blame] | 175 | << "Must pass --public_key to verify signed payload."; |
Sen Jiang | aef1c6f | 2015-10-07 10:05:32 -0700 | [diff] [blame] | 176 | CHECK(PayloadSigner::VerifySignedPayload(in_file, public_key)); |
Darin Petkov | adb3cef | 2011-01-13 16:16:08 -0800 | [diff] [blame] | 177 | LOG(INFO) << "Done verifying signed payload."; |
| 178 | } |
| 179 | |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 180 | // TODO(deymo): This function is likely broken for deltas minor version 2 or |
| 181 | // newer. Move this function to a new file and make the delta_performer |
| 182 | // integration tests use this instead. |
Steve Fung | 97b6f5a | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 183 | void ApplyDelta(const string& in_file, |
| 184 | const string& old_kernel, |
Alex Deymo | 35589c2 | 2015-06-07 17:33:18 +0200 | [diff] [blame] | 185 | const string& old_rootfs, |
Steve Fung | 97b6f5a | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 186 | const string& prefs_dir) { |
Darin Petkov | da8c136 | 2011-01-13 14:04:24 -0800 | [diff] [blame] | 187 | LOG(INFO) << "Applying delta."; |
Alex Deymo | 35589c2 | 2015-06-07 17:33:18 +0200 | [diff] [blame] | 188 | LOG_IF(FATAL, old_rootfs.empty()) |
Darin Petkov | da8c136 | 2011-01-13 14:04:24 -0800 | [diff] [blame] | 189 | << "Must pass --old_image to apply delta."; |
| 190 | Prefs prefs; |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 191 | InstallPlan install_plan; |
Steve Fung | 97b6f5a | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 192 | LOG(INFO) << "Setting up preferences under: " << prefs_dir; |
| 193 | LOG_IF(ERROR, !prefs.Init(base::FilePath(prefs_dir))) |
Darin Petkov | da8c136 | 2011-01-13 14:04:24 -0800 | [diff] [blame] | 194 | << "Failed to initialize preferences."; |
| 195 | // Get original checksums |
| 196 | LOG(INFO) << "Calculating original checksums"; |
Alex Deymo | 35589c2 | 2015-06-07 17:33:18 +0200 | [diff] [blame] | 197 | ImageConfig old_image; |
Sen Jiang | 981eb11 | 2015-08-25 17:03:18 -0700 | [diff] [blame] | 198 | old_image.partitions.emplace_back(kLegacyPartitionNameRoot); |
| 199 | old_image.partitions.back().path = old_rootfs; |
| 200 | old_image.partitions.emplace_back(kLegacyPartitionNameKernel); |
| 201 | old_image.partitions.back().path = old_kernel; |
Alex Deymo | 35589c2 | 2015-06-07 17:33:18 +0200 | [diff] [blame] | 202 | CHECK(old_image.LoadImageSize()); |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 203 | for (const auto& old_part : old_image.partitions) { |
| 204 | PartitionInfo part_info; |
| 205 | CHECK(diff_utils::InitializePartitionInfo(old_part, &part_info)); |
| 206 | InstallPlan::Partition part; |
| 207 | part.name = old_part.name; |
| 208 | part.source_hash.assign(part_info.hash().begin(), |
| 209 | part_info.hash().end()); |
| 210 | part.source_path = old_part.path; |
| 211 | // Apply the delta in-place to the old_part. |
| 212 | part.target_path = old_part.path; |
| 213 | install_plan.partitions.push_back(part); |
| 214 | } |
| 215 | |
Alex Deymo | 542c19b | 2015-12-03 07:43:31 -0300 | [diff] [blame] | 216 | DeltaPerformer performer(&prefs, nullptr, nullptr, nullptr, &install_plan); |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 217 | brillo::Blob buf(1024 * 1024); |
Steve Fung | 97b6f5a | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 218 | int fd = open(in_file.c_str(), O_RDONLY, 0); |
Darin Petkov | da8c136 | 2011-01-13 14:04:24 -0800 | [diff] [blame] | 219 | CHECK_GE(fd, 0); |
| 220 | ScopedFdCloser fd_closer(&fd); |
| 221 | for (off_t offset = 0;; offset += buf.size()) { |
| 222 | ssize_t bytes_read; |
Alex Vakulenko | f68bbbc | 2015-02-09 12:53:18 -0800 | [diff] [blame] | 223 | CHECK(utils::PReadAll(fd, buf.data(), buf.size(), offset, &bytes_read)); |
Darin Petkov | da8c136 | 2011-01-13 14:04:24 -0800 | [diff] [blame] | 224 | if (bytes_read == 0) |
| 225 | break; |
Alex Vakulenko | f68bbbc | 2015-02-09 12:53:18 -0800 | [diff] [blame] | 226 | CHECK_EQ(performer.Write(buf.data(), bytes_read), bytes_read); |
Darin Petkov | da8c136 | 2011-01-13 14:04:24 -0800 | [diff] [blame] | 227 | } |
| 228 | CHECK_EQ(performer.Close(), 0); |
| 229 | DeltaPerformer::ResetUpdateProgress(&prefs, false); |
| 230 | LOG(INFO) << "Done applying delta."; |
| 231 | } |
| 232 | |
Alex Deymo | 98e691c | 2016-02-04 21:05:45 -0800 | [diff] [blame] | 233 | int ExtractProperties(const string& payload_path, const string& props_file) { |
| 234 | brillo::KeyValueStore properties; |
| 235 | TEST_AND_RETURN_FALSE( |
| 236 | PayloadSigner::ExtractPayloadProperties(payload_path, &properties)); |
| 237 | if (props_file == "-") { |
| 238 | printf("%s", properties.SaveToString().c_str()); |
| 239 | } else { |
| 240 | properties.Save(base::FilePath(props_file)); |
| 241 | LOG(INFO) << "Generated properties file at " << props_file; |
| 242 | } |
| 243 | return true; |
| 244 | } |
| 245 | |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 246 | int Main(int argc, char** argv) { |
Steve Fung | 97b6f5a | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 247 | DEFINE_string(old_image, "", "Path to the old rootfs"); |
| 248 | DEFINE_string(new_image, "", "Path to the new rootfs"); |
| 249 | DEFINE_string(old_kernel, "", "Path to the old kernel partition image"); |
| 250 | DEFINE_string(new_kernel, "", "Path to the new kernel partition image"); |
Sen Jiang | 5df6836 | 2015-09-22 11:35:51 -0700 | [diff] [blame] | 251 | DEFINE_string(old_partitions, "", |
| 252 | "Path to the old partitions. To pass multiple partitions, use " |
| 253 | "a single argument with a colon between paths, e.g. " |
| 254 | "/path/to/part:/path/to/part2::/path/to/last_part . Path can " |
| 255 | "be empty, but it has to match the order of partition_names."); |
| 256 | DEFINE_string(new_partitions, "", |
| 257 | "Path to the new partitions. To pass multiple partitions, use " |
| 258 | "a single argument with a colon between paths, e.g. " |
| 259 | "/path/to/part:/path/to/part2:/path/to/last_part . Path has " |
| 260 | "to match the order of partition_names."); |
| 261 | DEFINE_string(partition_names, |
| 262 | string(kLegacyPartitionNameRoot) + ":" + |
| 263 | kLegacyPartitionNameKernel, |
| 264 | "Names of the partitions. To pass multiple names, use a single " |
| 265 | "argument with a colon between names, e.g. " |
| 266 | "name:name2:name3:last_name . Name can not be empty, and it " |
| 267 | "has to match the order of partitions."); |
Steve Fung | 97b6f5a | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 268 | DEFINE_string(in_file, "", |
| 269 | "Path to input delta payload file used to hash/sign payloads " |
| 270 | "and apply delta over old_image (for debugging)"); |
| 271 | DEFINE_string(out_file, "", "Path to output delta payload file"); |
| 272 | DEFINE_string(out_hash_file, "", "Path to output hash file"); |
| 273 | DEFINE_string(out_metadata_hash_file, "", |
| 274 | "Path to output metadata hash file"); |
Sen Jiang | d8ae872 | 2015-10-08 15:21:09 -0700 | [diff] [blame] | 275 | DEFINE_string(out_metadata_size_file, "", |
| 276 | "Path to output metadata size file"); |
Steve Fung | 97b6f5a | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 277 | DEFINE_string(private_key, "", "Path to private key in .pem format"); |
| 278 | DEFINE_string(public_key, "", "Path to public key in .pem format"); |
Alex Deymo | b552a68 | 2015-09-30 09:36:49 -0700 | [diff] [blame] | 279 | DEFINE_int32(public_key_version, -1, |
| 280 | "DEPRECATED. Key-check version # of client"); |
Steve Fung | 97b6f5a | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 281 | DEFINE_string(prefs_dir, "/tmp/update_engine_prefs", |
| 282 | "Preferences directory, used with apply_delta"); |
| 283 | DEFINE_string(signature_size, "", |
| 284 | "Raw signature size used for hash calculation. " |
| 285 | "You may pass in multiple sizes by colon separating them. E.g. " |
| 286 | "2048:2048:4096 will assume 3 signatures, the first two with " |
| 287 | "2048 size and the last 4096."); |
| 288 | DEFINE_string(signature_file, "", |
| 289 | "Raw signature file to sign payload with. To pass multiple " |
| 290 | "signatures, use a single argument with a colon between paths, " |
| 291 | "e.g. /path/to/sig:/path/to/next:/path/to/last_sig . Each " |
| 292 | "signature will be assigned a client version, starting from " |
| 293 | "kSignatureOriginalVersion."); |
Alex Deymo | ef366e1 | 2015-09-10 18:06:46 -0700 | [diff] [blame] | 294 | DEFINE_string(metadata_signature_file, "", |
| 295 | "Raw signature file with the signature of the metadata hash. " |
| 296 | "To pass multiple signatures, use a single argument with a " |
| 297 | "colon between paths, " |
| 298 | "e.g. /path/to/sig:/path/to/next:/path/to/last_sig ."); |
Alex Deymo | cfe8c15 | 2015-07-17 18:56:37 -0700 | [diff] [blame] | 299 | DEFINE_int32(chunk_size, 200 * 1024 * 1024, |
| 300 | "Payload chunk size (-1 for whole files)"); |
Alex Deymo | 9b244df | 2015-03-11 21:51:18 -0700 | [diff] [blame] | 301 | DEFINE_uint64(rootfs_partition_size, |
Steve Fung | 97b6f5a | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 302 | chromeos_update_engine::kRootFSPartitionSize, |
| 303 | "RootFS partition size for the image once installed"); |
Sen Jiang | 46e9b17 | 2015-08-31 14:11:01 -0700 | [diff] [blame] | 304 | DEFINE_uint64(major_version, 1, |
| 305 | "The major version of the payload being generated."); |
Alex Deymo | b42b98d | 2015-07-06 17:42:38 -0700 | [diff] [blame] | 306 | DEFINE_int32(minor_version, -1, |
| 307 | "The minor version of the payload being generated " |
| 308 | "(-1 means autodetect)."); |
Alex Deymo | 98e691c | 2016-02-04 21:05:45 -0800 | [diff] [blame] | 309 | DEFINE_string(properties_file, "", |
| 310 | "If passed, dumps the payload properties of the payload passed " |
| 311 | "in --in_file and exits."); |
Steve Fung | 97b6f5a | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 312 | |
| 313 | DEFINE_string(old_channel, "", |
| 314 | "The channel for the old image. 'dev-channel', 'npo-channel', " |
| 315 | "etc. Ignored, except during delta generation."); |
| 316 | DEFINE_string(old_board, "", |
| 317 | "The board for the old image. 'x86-mario', 'lumpy', " |
| 318 | "etc. Ignored, except during delta generation."); |
| 319 | DEFINE_string(old_version, "", |
| 320 | "The build version of the old image. 1.2.3, etc."); |
| 321 | DEFINE_string(old_key, "", |
| 322 | "The key used to sign the old image. 'premp', 'mp', 'mp-v3'," |
| 323 | " etc"); |
| 324 | DEFINE_string(old_build_channel, "", |
| 325 | "The channel for the build of the old image. 'dev-channel', " |
| 326 | "etc, but will never contain special channels such as " |
| 327 | "'npo-channel'. Ignored, except during delta generation."); |
| 328 | DEFINE_string(old_build_version, "", |
| 329 | "The version of the build containing the old image."); |
| 330 | |
| 331 | DEFINE_string(new_channel, "", |
| 332 | "The channel for the new image. 'dev-channel', 'npo-channel', " |
| 333 | "etc. Ignored, except during delta generation."); |
| 334 | DEFINE_string(new_board, "", |
| 335 | "The board for the new image. 'x86-mario', 'lumpy', " |
| 336 | "etc. Ignored, except during delta generation."); |
| 337 | DEFINE_string(new_version, "", |
| 338 | "The build version of the new image. 1.2.3, etc."); |
| 339 | DEFINE_string(new_key, "", |
| 340 | "The key used to sign the new image. 'premp', 'mp', 'mp-v3'," |
| 341 | " etc"); |
| 342 | DEFINE_string(new_build_channel, "", |
| 343 | "The channel for the build of the new image. 'dev-channel', " |
| 344 | "etc, but will never contain special channels such as " |
| 345 | "'npo-channel'. Ignored, except during delta generation."); |
| 346 | DEFINE_string(new_build_version, "", |
| 347 | "The version of the build containing the new image."); |
Sen Jiang | 05feee0 | 2015-11-11 15:59:49 -0800 | [diff] [blame] | 348 | DEFINE_string(new_postinstall_config_file, "", |
| 349 | "A config file specifying postinstall related metadata. " |
| 350 | "Only allowed in major version 2 or newer."); |
Steve Fung | 97b6f5a | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 351 | |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 352 | brillo::FlagHelper::Init(argc, argv, |
Alex Deymo | 1f02371 | 2014-05-20 19:19:23 -0700 | [diff] [blame] | 353 | "Generates a payload to provide to ChromeOS' update_engine.\n\n" |
| 354 | "This tool can create full payloads and also delta payloads if the src\n" |
| 355 | "image is provided. It also provides debugging options to apply, sign\n" |
| 356 | "and verify payloads."); |
Darin Petkov | 9c0baf8 | 2010-10-07 13:44:48 -0700 | [diff] [blame] | 357 | Terminator::Init(); |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 358 | |
| 359 | logging::LoggingSettings log_settings; |
| 360 | log_settings.log_file = "delta_generator.log"; |
| 361 | log_settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
Alex Deymo | 7fad7b7 | 2015-07-21 22:22:47 -0700 | [diff] [blame] | 362 | log_settings.lock_log = logging::LOCK_LOG_FILE; |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 363 | log_settings.delete_old = logging::APPEND_TO_OLD_LOG_FILE; |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 364 | |
| 365 | logging::InitLogging(log_settings); |
Don Garrett | c2e9f5f | 2013-10-18 16:42:40 -0700 | [diff] [blame] | 366 | |
| 367 | vector<int> signature_sizes; |
| 368 | ParseSignatureSizes(FLAGS_signature_size, &signature_sizes); |
| 369 | |
| 370 | if (!FLAGS_out_hash_file.empty() || !FLAGS_out_metadata_hash_file.empty()) { |
Sen Jiang | d8ae872 | 2015-10-08 15:21:09 -0700 | [diff] [blame] | 371 | CHECK(FLAGS_out_metadata_size_file.empty()); |
Sen Jiang | 720df3e | 2015-10-01 13:10:44 -0700 | [diff] [blame] | 372 | CalculateHashForSigning(signature_sizes, FLAGS_out_hash_file, |
| 373 | FLAGS_out_metadata_hash_file, FLAGS_in_file); |
Darin Petkov | da8c136 | 2011-01-13 14:04:24 -0800 | [diff] [blame] | 374 | return 0; |
| 375 | } |
| 376 | if (!FLAGS_signature_file.empty()) { |
Sen Jiang | d8ae872 | 2015-10-08 15:21:09 -0700 | [diff] [blame] | 377 | SignPayload(FLAGS_in_file, FLAGS_out_file, FLAGS_signature_file, |
Sen Jiang | 644f618 | 2015-10-06 16:45:57 -0700 | [diff] [blame] | 378 | FLAGS_metadata_signature_file, FLAGS_out_metadata_size_file); |
Darin Petkov | da8c136 | 2011-01-13 14:04:24 -0800 | [diff] [blame] | 379 | return 0; |
| 380 | } |
Darin Petkov | adb3cef | 2011-01-13 16:16:08 -0800 | [diff] [blame] | 381 | if (!FLAGS_public_key.empty()) { |
Alex Deymo | b552a68 | 2015-09-30 09:36:49 -0700 | [diff] [blame] | 382 | LOG_IF(WARNING, FLAGS_public_key_version != -1) |
| 383 | << "--public_key_version is deprecated and ignored."; |
| 384 | VerifySignedPayload(FLAGS_in_file, FLAGS_public_key); |
Darin Petkov | adb3cef | 2011-01-13 16:16:08 -0800 | [diff] [blame] | 385 | return 0; |
| 386 | } |
Alex Deymo | 98e691c | 2016-02-04 21:05:45 -0800 | [diff] [blame] | 387 | if (!FLAGS_properties_file.empty()) { |
| 388 | return ExtractProperties(FLAGS_in_file, FLAGS_properties_file) ? 0 : 1; |
| 389 | } |
Darin Petkov | da8c136 | 2011-01-13 14:04:24 -0800 | [diff] [blame] | 390 | if (!FLAGS_in_file.empty()) { |
Steve Fung | 97b6f5a | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 391 | ApplyDelta(FLAGS_in_file, FLAGS_old_kernel, FLAGS_old_image, |
| 392 | FLAGS_prefs_dir); |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 393 | return 0; |
| 394 | } |
Alex Deymo | f1cbe17 | 2015-03-05 15:58:37 -0800 | [diff] [blame] | 395 | |
| 396 | // A payload generation was requested. Convert the flags to a |
| 397 | // PayloadGenerationConfig. |
| 398 | PayloadGenerationConfig payload_config; |
Sen Jiang | 5df6836 | 2015-09-22 11:35:51 -0700 | [diff] [blame] | 399 | vector<string> partition_names, old_partitions, new_partitions; |
Alex Deymo | f1cbe17 | 2015-03-05 15:58:37 -0800 | [diff] [blame] | 400 | |
Alex Vakulenko | 0103c36 | 2016-01-20 07:56:15 -0800 | [diff] [blame] | 401 | partition_names = |
| 402 | base::SplitString(FLAGS_partition_names, ":", base::TRIM_WHITESPACE, |
| 403 | base::SPLIT_WANT_ALL); |
Sen Jiang | 5df6836 | 2015-09-22 11:35:51 -0700 | [diff] [blame] | 404 | CHECK(!partition_names.empty()); |
| 405 | if (FLAGS_major_version == kChromeOSMajorPayloadVersion || |
| 406 | FLAGS_new_partitions.empty()) { |
| 407 | LOG_IF(FATAL, partition_names.size() != 2) |
| 408 | << "To support more than 2 partitions, please use the " |
| 409 | << "--new_partitions flag and major version 2."; |
| 410 | LOG_IF(FATAL, partition_names[0] != kLegacyPartitionNameRoot || |
| 411 | partition_names[1] != kLegacyPartitionNameKernel) |
| 412 | << "To support non-default partition name, please use the " |
| 413 | << "--new_partitions flag and major version 2."; |
Sen Jiang | 981eb11 | 2015-08-25 17:03:18 -0700 | [diff] [blame] | 414 | } |
| 415 | |
Sen Jiang | 5df6836 | 2015-09-22 11:35:51 -0700 | [diff] [blame] | 416 | if (!FLAGS_new_partitions.empty()) { |
| 417 | LOG_IF(FATAL, !FLAGS_new_image.empty() || !FLAGS_new_kernel.empty()) |
| 418 | << "--new_image and --new_kernel are deprecated, please use " |
| 419 | << "--new_partitions for all partitions."; |
Alex Vakulenko | 0103c36 | 2016-01-20 07:56:15 -0800 | [diff] [blame] | 420 | new_partitions = |
| 421 | base::SplitString(FLAGS_new_partitions, ":", base::TRIM_WHITESPACE, |
| 422 | base::SPLIT_WANT_ALL); |
Sen Jiang | 5df6836 | 2015-09-22 11:35:51 -0700 | [diff] [blame] | 423 | CHECK(partition_names.size() == new_partitions.size()); |
| 424 | |
| 425 | payload_config.is_delta = !FLAGS_old_partitions.empty(); |
| 426 | LOG_IF(FATAL, !FLAGS_old_image.empty() || !FLAGS_old_kernel.empty()) |
| 427 | << "--old_image and --old_kernel are deprecated, please use " |
| 428 | << "--old_partitions if you are using --new_partitions."; |
| 429 | } else { |
| 430 | new_partitions = {FLAGS_new_image, FLAGS_new_kernel}; |
| 431 | LOG(WARNING) << "--new_partitions is empty, using deprecated --new_image " |
| 432 | << "and --new_kernel flags."; |
| 433 | |
| 434 | payload_config.is_delta = !FLAGS_old_image.empty() || |
| 435 | !FLAGS_old_kernel.empty(); |
| 436 | LOG_IF(FATAL, !FLAGS_old_partitions.empty()) |
| 437 | << "Please use --new_partitions if you are using --old_partitions."; |
| 438 | } |
| 439 | for (size_t i = 0; i < partition_names.size(); i++) { |
| 440 | LOG_IF(FATAL, partition_names[i].empty()) |
| 441 | << "Partition name can't be empty, see --partition_names."; |
| 442 | payload_config.target.partitions.emplace_back(partition_names[i]); |
| 443 | payload_config.target.partitions.back().path = new_partitions[i]; |
| 444 | } |
| 445 | |
| 446 | if (payload_config.is_delta) { |
| 447 | if (!FLAGS_old_partitions.empty()) { |
Alex Vakulenko | 0103c36 | 2016-01-20 07:56:15 -0800 | [diff] [blame] | 448 | old_partitions = |
| 449 | base::SplitString(FLAGS_old_partitions, ":", base::TRIM_WHITESPACE, |
| 450 | base::SPLIT_WANT_ALL); |
Sen Jiang | 5df6836 | 2015-09-22 11:35:51 -0700 | [diff] [blame] | 451 | CHECK(old_partitions.size() == new_partitions.size()); |
| 452 | } else { |
| 453 | old_partitions = {FLAGS_old_image, FLAGS_old_kernel}; |
| 454 | LOG(WARNING) << "--old_partitions is empty, using deprecated --old_image " |
| 455 | << "and --old_kernel flags."; |
| 456 | } |
| 457 | for (size_t i = 0; i < partition_names.size(); i++) { |
| 458 | payload_config.source.partitions.emplace_back(partition_names[i]); |
| 459 | payload_config.source.partitions.back().path = old_partitions[i]; |
| 460 | } |
| 461 | } |
Alex Deymo | f1cbe17 | 2015-03-05 15:58:37 -0800 | [diff] [blame] | 462 | |
Sen Jiang | 05feee0 | 2015-11-11 15:59:49 -0800 | [diff] [blame] | 463 | if (!FLAGS_new_postinstall_config_file.empty()) { |
| 464 | LOG_IF(FATAL, FLAGS_major_version == kChromeOSMajorPayloadVersion) |
| 465 | << "Postinstall config is only allowed in major version 2 or newer."; |
| 466 | brillo::KeyValueStore store; |
| 467 | CHECK(store.Load(base::FilePath(FLAGS_new_postinstall_config_file))); |
| 468 | CHECK(payload_config.target.LoadPostInstallConfig(store)); |
| 469 | } |
| 470 | |
Alex Deymo | 2d3b2d6 | 2015-07-17 17:34:36 -0700 | [diff] [blame] | 471 | // Use the default soft_chunk_size defined in the config. |
| 472 | payload_config.hard_chunk_size = FLAGS_chunk_size; |
Alex Deymo | f1cbe17 | 2015-03-05 15:58:37 -0800 | [diff] [blame] | 473 | payload_config.block_size = kBlockSize; |
| 474 | |
Sen Jiang | 5df6836 | 2015-09-22 11:35:51 -0700 | [diff] [blame] | 475 | // The partition size is never passed to the delta_generator, so we |
Alex Deymo | f1cbe17 | 2015-03-05 15:58:37 -0800 | [diff] [blame] | 476 | // need to detect those from the provided files. |
Sen Jiang | 5df6836 | 2015-09-22 11:35:51 -0700 | [diff] [blame] | 477 | if (payload_config.is_delta) { |
Alex Deymo | f1cbe17 | 2015-03-05 15:58:37 -0800 | [diff] [blame] | 478 | CHECK(payload_config.source.LoadImageSize()); |
| 479 | } |
Sen Jiang | 5df6836 | 2015-09-22 11:35:51 -0700 | [diff] [blame] | 480 | CHECK(payload_config.target.LoadImageSize()); |
Alex Deymo | f1cbe17 | 2015-03-05 15:58:37 -0800 | [diff] [blame] | 481 | |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 482 | CHECK(!FLAGS_out_file.empty()); |
Don Garrett | 0dd3985 | 2013-04-03 16:55:42 -0700 | [diff] [blame] | 483 | |
Don Garrett | 60fc59c | 2013-10-18 11:43:52 -0700 | [diff] [blame] | 484 | // Ignore failures. These are optional arguments. |
Don Garrett | 0dd3985 | 2013-04-03 16:55:42 -0700 | [diff] [blame] | 485 | ParseImageInfo(FLAGS_new_channel, |
| 486 | FLAGS_new_board, |
| 487 | FLAGS_new_version, |
| 488 | FLAGS_new_key, |
| 489 | FLAGS_new_build_channel, |
| 490 | FLAGS_new_build_version, |
Alex Deymo | f1cbe17 | 2015-03-05 15:58:37 -0800 | [diff] [blame] | 491 | &payload_config.target.image_info); |
Don Garrett | 0dd3985 | 2013-04-03 16:55:42 -0700 | [diff] [blame] | 492 | |
Don Garrett | 60fc59c | 2013-10-18 11:43:52 -0700 | [diff] [blame] | 493 | // Ignore failures. These are optional arguments. |
| 494 | ParseImageInfo(FLAGS_old_channel, |
| 495 | FLAGS_old_board, |
| 496 | FLAGS_old_version, |
| 497 | FLAGS_old_key, |
| 498 | FLAGS_old_build_channel, |
| 499 | FLAGS_old_build_version, |
Alex Deymo | f1cbe17 | 2015-03-05 15:58:37 -0800 | [diff] [blame] | 500 | &payload_config.source.image_info); |
Don Garrett | 0dd3985 | 2013-04-03 16:55:42 -0700 | [diff] [blame] | 501 | |
Alex Deymo | 9b244df | 2015-03-11 21:51:18 -0700 | [diff] [blame] | 502 | payload_config.rootfs_partition_size = FLAGS_rootfs_partition_size; |
Allie Wood | b8ccad0 | 2015-02-09 14:33:40 -0800 | [diff] [blame] | 503 | |
Alex Deymo | f1cbe17 | 2015-03-05 15:58:37 -0800 | [diff] [blame] | 504 | if (payload_config.is_delta) { |
Alex Deymo | b42b98d | 2015-07-06 17:42:38 -0700 | [diff] [blame] | 505 | // Avoid opening the filesystem interface for full payloads. |
Sen Jiang | 981eb11 | 2015-08-25 17:03:18 -0700 | [diff] [blame] | 506 | for (PartitionConfig& part : payload_config.target.partitions) |
| 507 | CHECK(part.OpenFilesystem()); |
| 508 | for (PartitionConfig& part : payload_config.source.partitions) |
| 509 | CHECK(part.OpenFilesystem()); |
Alex Deymo | b42b98d | 2015-07-06 17:42:38 -0700 | [diff] [blame] | 510 | } |
| 511 | |
Sen Jiang | 46e9b17 | 2015-08-31 14:11:01 -0700 | [diff] [blame] | 512 | payload_config.major_version = FLAGS_major_version; |
| 513 | LOG(INFO) << "Using provided major_version=" << FLAGS_major_version; |
| 514 | |
Alex Deymo | b42b98d | 2015-07-06 17:42:38 -0700 | [diff] [blame] | 515 | if (FLAGS_minor_version == -1) { |
| 516 | // Autodetect minor_version by looking at the update_engine.conf in the old |
| 517 | // image. |
| 518 | if (payload_config.is_delta) { |
Sen Jiang | 981eb11 | 2015-08-25 17:03:18 -0700 | [diff] [blame] | 519 | payload_config.minor_version = kInPlaceMinorPayloadVersion; |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 520 | brillo::KeyValueStore store; |
Alex Deymo | b42b98d | 2015-07-06 17:42:38 -0700 | [diff] [blame] | 521 | uint32_t minor_version; |
Sen Jiang | 981eb11 | 2015-08-25 17:03:18 -0700 | [diff] [blame] | 522 | for (const PartitionConfig& part : payload_config.source.partitions) { |
| 523 | if (part.fs_interface && part.fs_interface->LoadSettings(&store) && |
| 524 | utils::GetMinorVersion(store, &minor_version)) { |
| 525 | payload_config.minor_version = minor_version; |
| 526 | break; |
| 527 | } |
Alex Deymo | b42b98d | 2015-07-06 17:42:38 -0700 | [diff] [blame] | 528 | } |
| 529 | } else { |
Alex Deymo | cbf0989 | 2015-09-11 16:13:16 -0700 | [diff] [blame] | 530 | payload_config.minor_version = kFullPayloadMinorVersion; |
Alex Deymo | b42b98d | 2015-07-06 17:42:38 -0700 | [diff] [blame] | 531 | } |
| 532 | LOG(INFO) << "Auto-detected minor_version=" << payload_config.minor_version; |
| 533 | } else { |
| 534 | payload_config.minor_version = FLAGS_minor_version; |
| 535 | LOG(INFO) << "Using provided minor_version=" << FLAGS_minor_version; |
| 536 | } |
| 537 | |
Sen Jiang | 55c4f9b | 2016-02-10 11:26:20 -0800 | [diff] [blame] | 538 | if (payload_config.minor_version >= kImgdiffMinorPayloadVersion) { |
| 539 | // TODO(senj): Check if the zlib version in source and target are the same. |
| 540 | payload_config.imgdiff_allowed = true; |
| 541 | } |
| 542 | |
Alex Deymo | b42b98d | 2015-07-06 17:42:38 -0700 | [diff] [blame] | 543 | if (payload_config.is_delta) { |
Alex Deymo | f1cbe17 | 2015-03-05 15:58:37 -0800 | [diff] [blame] | 544 | LOG(INFO) << "Generating delta update"; |
Allie Wood | b8ccad0 | 2015-02-09 14:33:40 -0800 | [diff] [blame] | 545 | } else { |
Alex Deymo | f1cbe17 | 2015-03-05 15:58:37 -0800 | [diff] [blame] | 546 | LOG(INFO) << "Generating full update"; |
| 547 | } |
| 548 | |
| 549 | // From this point, all the options have been parsed. |
| 550 | if (!payload_config.Validate()) { |
Alex Deymo | a26432a | 2015-03-12 16:08:04 -0700 | [diff] [blame] | 551 | LOG(ERROR) << "Invalid options passed. See errors above."; |
| 552 | return 1; |
Alex Deymo | f1cbe17 | 2015-03-05 15:58:37 -0800 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | uint64_t metadata_size; |
Alex Deymo | 477aec2 | 2015-03-24 23:40:48 -0700 | [diff] [blame] | 556 | if (!GenerateUpdatePayloadFile(payload_config, |
| 557 | FLAGS_out_file, |
| 558 | FLAGS_private_key, |
| 559 | &metadata_size)) { |
Alex Deymo | f1cbe17 | 2015-03-05 15:58:37 -0800 | [diff] [blame] | 560 | return 1; |
Allie Wood | b8ccad0 | 2015-02-09 14:33:40 -0800 | [diff] [blame] | 561 | } |
Sen Jiang | d8ae872 | 2015-10-08 15:21:09 -0700 | [diff] [blame] | 562 | if (!FLAGS_out_metadata_size_file.empty()) { |
| 563 | string metadata_size_string = std::to_string(metadata_size); |
| 564 | CHECK(utils::WriteFile(FLAGS_out_metadata_size_file.c_str(), |
| 565 | metadata_size_string.data(), |
| 566 | metadata_size_string.size())); |
| 567 | } |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 568 | return 0; |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 569 | } |
| 570 | |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 571 | } // namespace |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 572 | |
| 573 | } // namespace chromeos_update_engine |
| 574 | |
| 575 | int main(int argc, char** argv) { |
| 576 | return chromeos_update_engine::Main(argc, argv); |
| 577 | } |