Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2013 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 | // |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 16 | |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 17 | #include "update_engine/payload_consumer/install_plan.h" |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 18 | |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 19 | #include <base/format_macros.h> |
Alex Deymo | 8427b4a | 2014-11-05 14:00:32 -0800 | [diff] [blame] | 20 | #include <base/logging.h> |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 21 | #include <base/strings/stringprintf.h> |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 22 | |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 23 | #include "update_engine/common/utils.h" |
| 24 | #include "update_engine/payload_consumer/payload_constants.h" |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 25 | |
| 26 | using std::string; |
| 27 | |
| 28 | namespace chromeos_update_engine { |
| 29 | |
| 30 | InstallPlan::InstallPlan(bool is_resume, |
Gilad Arnold | 21504f0 | 2013-05-24 08:51:22 -0700 | [diff] [blame] | 31 | bool is_full_update, |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 32 | const string& url, |
| 33 | uint64_t payload_size, |
| 34 | const string& payload_hash, |
| 35 | uint64_t metadata_size, |
| 36 | const string& metadata_signature, |
Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame] | 37 | const string& public_key_rsa) |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 38 | : is_resume(is_resume), |
Gilad Arnold | 21504f0 | 2013-05-24 08:51:22 -0700 | [diff] [blame] | 39 | is_full_update(is_full_update), |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 40 | download_url(url), |
| 41 | payload_size(payload_size), |
| 42 | payload_hash(payload_hash), |
| 43 | metadata_size(metadata_size), |
| 44 | metadata_signature(metadata_signature), |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 45 | hash_checks_mandatory(false), |
David Zeuthen | e7f8917 | 2013-10-31 10:21:04 -0700 | [diff] [blame] | 46 | powerwash_required(false), |
| 47 | public_key_rsa(public_key_rsa) {} |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 48 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 49 | |
| 50 | bool InstallPlan::operator==(const InstallPlan& that) const { |
| 51 | return ((is_resume == that.is_resume) && |
Gilad Arnold | 21504f0 | 2013-05-24 08:51:22 -0700 | [diff] [blame] | 52 | (is_full_update == that.is_full_update) && |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 53 | (download_url == that.download_url) && |
| 54 | (payload_size == that.payload_size) && |
| 55 | (payload_hash == that.payload_hash) && |
| 56 | (metadata_size == that.metadata_size) && |
| 57 | (metadata_signature == that.metadata_signature) && |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 58 | (source_slot == that.source_slot) && |
| 59 | (target_slot == that.target_slot) && |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 60 | (partitions == that.partitions)); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | bool InstallPlan::operator!=(const InstallPlan& that) const { |
| 64 | return !((*this) == that); |
| 65 | } |
| 66 | |
| 67 | void InstallPlan::Dump() const { |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 68 | string partitions_str; |
| 69 | for (const auto& partition : partitions) { |
| 70 | partitions_str += base::StringPrintf( |
| 71 | ", part: %s (source_size: %" PRIu64 ", target_size %" PRIu64 ")", |
| 72 | partition.name.c_str(), partition.source_size, partition.target_size); |
| 73 | } |
| 74 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 75 | LOG(INFO) << "InstallPlan: " |
Gilad Arnold | 21504f0 | 2013-05-24 08:51:22 -0700 | [diff] [blame] | 76 | << (is_resume ? "resume" : "new_update") |
| 77 | << ", payload type: " << (is_full_update ? "full" : "delta") |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 78 | << ", source_slot: " << BootControlInterface::SlotName(source_slot) |
| 79 | << ", target_slot: " << BootControlInterface::SlotName(target_slot) |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 80 | << ", url: " << download_url |
| 81 | << ", payload size: " << payload_size |
| 82 | << ", payload hash: " << payload_hash |
| 83 | << ", metadata size: " << metadata_size |
| 84 | << ", metadata signature: " << metadata_signature |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 85 | << partitions_str |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 86 | << ", hash_checks_mandatory: " << utils::ToString( |
| 87 | hash_checks_mandatory) |
| 88 | << ", powerwash_required: " << utils::ToString( |
| 89 | powerwash_required); |
| 90 | } |
| 91 | |
Alex Deymo | 706a5ab | 2015-11-23 17:48:30 -0300 | [diff] [blame^] | 92 | bool InstallPlan::LoadPartitionsFromSlots(BootControlInterface* boot_control) { |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 93 | bool result = true; |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 94 | for (Partition& partition : partitions) { |
| 95 | if (source_slot != BootControlInterface::kInvalidSlot) { |
Alex Deymo | 706a5ab | 2015-11-23 17:48:30 -0300 | [diff] [blame^] | 96 | result = boot_control->GetPartitionDevice( |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 97 | partition.name, source_slot, &partition.source_path) && result; |
| 98 | } else { |
| 99 | partition.source_path.clear(); |
| 100 | } |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 101 | |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 102 | if (target_slot != BootControlInterface::kInvalidSlot) { |
Alex Deymo | 706a5ab | 2015-11-23 17:48:30 -0300 | [diff] [blame^] | 103 | result = boot_control->GetPartitionDevice( |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 104 | partition.name, target_slot, &partition.target_path) && result; |
| 105 | } else { |
| 106 | partition.target_path.clear(); |
| 107 | } |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 108 | } |
| 109 | return result; |
| 110 | } |
| 111 | |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 112 | bool InstallPlan::Partition::operator==( |
| 113 | const InstallPlan::Partition& that) const { |
| 114 | return (name == that.name && |
| 115 | source_path == that.source_path && |
| 116 | source_size == that.source_size && |
| 117 | source_hash == that.source_hash && |
| 118 | target_path == that.target_path && |
| 119 | target_size == that.target_size && |
| 120 | target_hash == that.target_hash && |
| 121 | run_postinstall == that.run_postinstall); |
| 122 | } |
| 123 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 124 | } // namespace chromeos_update_engine |