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 | |
Alex Deymo | 64d9878 | 2016-02-05 18:03:48 -0800 | [diff] [blame] | 30 | string InstallPayloadTypeToString(InstallPayloadType type) { |
| 31 | switch (type) { |
| 32 | case InstallPayloadType::kUnknown: |
| 33 | return "unknown"; |
| 34 | case InstallPayloadType::kFull: |
| 35 | return "full"; |
| 36 | case InstallPayloadType::kDelta: |
| 37 | return "delta"; |
| 38 | } |
| 39 | return "invalid type"; |
| 40 | } |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 41 | |
| 42 | bool InstallPlan::operator==(const InstallPlan& that) const { |
| 43 | return ((is_resume == that.is_resume) && |
Alex Deymo | 64d9878 | 2016-02-05 18:03:48 -0800 | [diff] [blame] | 44 | (payload_type == that.payload_type) && |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 45 | (download_url == that.download_url) && |
| 46 | (payload_size == that.payload_size) && |
| 47 | (payload_hash == that.payload_hash) && |
| 48 | (metadata_size == that.metadata_size) && |
| 49 | (metadata_signature == that.metadata_signature) && |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 50 | (source_slot == that.source_slot) && |
| 51 | (target_slot == that.target_slot) && |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 52 | (partitions == that.partitions)); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | bool InstallPlan::operator!=(const InstallPlan& that) const { |
| 56 | return !((*this) == that); |
| 57 | } |
| 58 | |
| 59 | void InstallPlan::Dump() const { |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 60 | string partitions_str; |
| 61 | for (const auto& partition : partitions) { |
| 62 | partitions_str += base::StringPrintf( |
| 63 | ", part: %s (source_size: %" PRIu64 ", target_size %" PRIu64 ")", |
| 64 | partition.name.c_str(), partition.source_size, partition.target_size); |
| 65 | } |
| 66 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 67 | LOG(INFO) << "InstallPlan: " |
Gilad Arnold | 21504f0 | 2013-05-24 08:51:22 -0700 | [diff] [blame] | 68 | << (is_resume ? "resume" : "new_update") |
Alex Deymo | 64d9878 | 2016-02-05 18:03:48 -0800 | [diff] [blame] | 69 | << ", payload type: " << InstallPayloadTypeToString(payload_type) |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 70 | << ", source_slot: " << BootControlInterface::SlotName(source_slot) |
| 71 | << ", target_slot: " << BootControlInterface::SlotName(target_slot) |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 72 | << ", url: " << download_url |
| 73 | << ", payload size: " << payload_size |
| 74 | << ", payload hash: " << payload_hash |
| 75 | << ", metadata size: " << metadata_size |
| 76 | << ", metadata signature: " << metadata_signature |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 77 | << partitions_str |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 78 | << ", hash_checks_mandatory: " << utils::ToString( |
| 79 | hash_checks_mandatory) |
Alex Deymo | 64d9878 | 2016-02-05 18:03:48 -0800 | [diff] [blame] | 80 | << ", powerwash_required: " << utils::ToString(powerwash_required); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Alex Deymo | 706a5ab | 2015-11-23 17:48:30 -0300 | [diff] [blame] | 83 | bool InstallPlan::LoadPartitionsFromSlots(BootControlInterface* boot_control) { |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 84 | bool result = true; |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 85 | for (Partition& partition : partitions) { |
| 86 | if (source_slot != BootControlInterface::kInvalidSlot) { |
Alex Deymo | 706a5ab | 2015-11-23 17:48:30 -0300 | [diff] [blame] | 87 | result = boot_control->GetPartitionDevice( |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 88 | partition.name, source_slot, &partition.source_path) && result; |
| 89 | } else { |
| 90 | partition.source_path.clear(); |
| 91 | } |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 92 | |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 93 | if (target_slot != BootControlInterface::kInvalidSlot) { |
Alex Deymo | 706a5ab | 2015-11-23 17:48:30 -0300 | [diff] [blame] | 94 | result = boot_control->GetPartitionDevice( |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 95 | partition.name, target_slot, &partition.target_path) && result; |
| 96 | } else { |
| 97 | partition.target_path.clear(); |
| 98 | } |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 99 | } |
| 100 | return result; |
| 101 | } |
| 102 | |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 103 | bool InstallPlan::Partition::operator==( |
| 104 | const InstallPlan::Partition& that) const { |
| 105 | return (name == that.name && |
| 106 | source_path == that.source_path && |
| 107 | source_size == that.source_size && |
| 108 | source_hash == that.source_hash && |
| 109 | target_path == that.target_path && |
| 110 | target_size == that.target_size && |
| 111 | target_hash == that.target_hash && |
| 112 | run_postinstall == that.run_postinstall); |
| 113 | } |
| 114 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 115 | } // namespace chromeos_update_engine |