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 | |
| 17 | #include "update_engine/install_plan.h" |
| 18 | |
Alex Deymo | 8427b4a | 2014-11-05 14:00:32 -0800 | [diff] [blame] | 19 | #include <base/logging.h> |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 20 | |
| 21 | #include "update_engine/utils.h" |
| 22 | |
| 23 | using std::string; |
| 24 | |
| 25 | namespace chromeos_update_engine { |
| 26 | |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame^] | 27 | const char* kLegacyPartitionNameKernel = "KERNEL"; |
| 28 | const char* kLegacyPartitionNameRoot = "ROOT"; |
| 29 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 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, |
| 37 | const string& install_path, |
David Zeuthen | e7f8917 | 2013-10-31 10:21:04 -0700 | [diff] [blame] | 38 | const string& kernel_install_path, |
Allie Wood | fdf0051 | 2015-03-02 13:34:55 -0800 | [diff] [blame] | 39 | const string& source_path, |
| 40 | const string& kernel_source_path, |
Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame] | 41 | const string& public_key_rsa) |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 42 | : is_resume(is_resume), |
Gilad Arnold | 21504f0 | 2013-05-24 08:51:22 -0700 | [diff] [blame] | 43 | is_full_update(is_full_update), |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 44 | download_url(url), |
| 45 | payload_size(payload_size), |
| 46 | payload_hash(payload_hash), |
| 47 | metadata_size(metadata_size), |
| 48 | metadata_signature(metadata_signature), |
| 49 | install_path(install_path), |
| 50 | kernel_install_path(kernel_install_path), |
Allie Wood | fdf0051 | 2015-03-02 13:34:55 -0800 | [diff] [blame] | 51 | source_path(source_path), |
| 52 | kernel_source_path(kernel_source_path), |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 53 | kernel_size(0), |
| 54 | rootfs_size(0), |
| 55 | hash_checks_mandatory(false), |
David Zeuthen | e7f8917 | 2013-10-31 10:21:04 -0700 | [diff] [blame] | 56 | powerwash_required(false), |
| 57 | public_key_rsa(public_key_rsa) {} |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 58 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 59 | |
| 60 | bool InstallPlan::operator==(const InstallPlan& that) const { |
| 61 | return ((is_resume == that.is_resume) && |
Gilad Arnold | 21504f0 | 2013-05-24 08:51:22 -0700 | [diff] [blame] | 62 | (is_full_update == that.is_full_update) && |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 63 | (download_url == that.download_url) && |
| 64 | (payload_size == that.payload_size) && |
| 65 | (payload_hash == that.payload_hash) && |
| 66 | (metadata_size == that.metadata_size) && |
| 67 | (metadata_signature == that.metadata_signature) && |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame^] | 68 | (source_slot == that.source_slot) && |
| 69 | (target_slot == that.target_slot) && |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 70 | (install_path == that.install_path) && |
Allie Wood | fdf0051 | 2015-03-02 13:34:55 -0800 | [diff] [blame] | 71 | (kernel_install_path == that.kernel_install_path) && |
| 72 | (source_path == that.source_path) && |
| 73 | (kernel_source_path == that.kernel_source_path)); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | bool InstallPlan::operator!=(const InstallPlan& that) const { |
| 77 | return !((*this) == that); |
| 78 | } |
| 79 | |
| 80 | void InstallPlan::Dump() const { |
| 81 | LOG(INFO) << "InstallPlan: " |
Gilad Arnold | 21504f0 | 2013-05-24 08:51:22 -0700 | [diff] [blame] | 82 | << (is_resume ? "resume" : "new_update") |
| 83 | << ", payload type: " << (is_full_update ? "full" : "delta") |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame^] | 84 | << ", source_slot: " << BootControlInterface::SlotName(source_slot) |
| 85 | << ", target_slot: " << BootControlInterface::SlotName(target_slot) |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 86 | << ", url: " << download_url |
| 87 | << ", payload size: " << payload_size |
| 88 | << ", payload hash: " << payload_hash |
| 89 | << ", metadata size: " << metadata_size |
| 90 | << ", metadata signature: " << metadata_signature |
| 91 | << ", install_path: " << install_path |
| 92 | << ", kernel_install_path: " << kernel_install_path |
Allie Wood | fdf0051 | 2015-03-02 13:34:55 -0800 | [diff] [blame] | 93 | << ", source_path: " << source_path |
| 94 | << ", kernel_source_path: " << kernel_source_path |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 95 | << ", hash_checks_mandatory: " << utils::ToString( |
| 96 | hash_checks_mandatory) |
| 97 | << ", powerwash_required: " << utils::ToString( |
| 98 | powerwash_required); |
| 99 | } |
| 100 | |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame^] | 101 | bool InstallPlan::LoadPartitionsFromSlots(SystemState* system_state) { |
| 102 | bool result = true; |
| 103 | if (source_slot != BootControlInterface::kInvalidSlot) { |
| 104 | result = system_state->boot_control()->GetPartitionDevice( |
| 105 | kLegacyPartitionNameRoot, source_slot, &source_path) && result; |
| 106 | result = system_state->boot_control()->GetPartitionDevice( |
| 107 | kLegacyPartitionNameKernel, source_slot, &kernel_source_path) && result; |
| 108 | } else { |
| 109 | source_path.clear(); |
| 110 | kernel_source_path.clear(); |
| 111 | } |
| 112 | |
| 113 | if (target_slot != BootControlInterface::kInvalidSlot) { |
| 114 | result = system_state->boot_control()->GetPartitionDevice( |
| 115 | kLegacyPartitionNameRoot, target_slot, &install_path) && result; |
| 116 | result = system_state->boot_control()->GetPartitionDevice( |
| 117 | kLegacyPartitionNameKernel, target_slot, &kernel_install_path) && result; |
| 118 | } else { |
| 119 | install_path.clear(); |
| 120 | kernel_install_path.clear(); |
| 121 | } |
| 122 | return result; |
| 123 | } |
| 124 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 125 | } // namespace chromeos_update_engine |