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> |
Sen Jiang | 2703ef4 | 2017-03-16 13:36:21 -0700 | [diff] [blame] | 21 | #include <base/strings/string_number_conversions.h> |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 22 | #include <base/strings/stringprintf.h> |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 23 | |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 24 | #include "update_engine/common/utils.h" |
| 25 | #include "update_engine/payload_consumer/payload_constants.h" |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 26 | |
| 27 | using std::string; |
| 28 | |
| 29 | namespace chromeos_update_engine { |
| 30 | |
Alex Deymo | 64d9878 | 2016-02-05 18:03:48 -0800 | [diff] [blame] | 31 | string InstallPayloadTypeToString(InstallPayloadType type) { |
| 32 | switch (type) { |
| 33 | case InstallPayloadType::kUnknown: |
| 34 | return "unknown"; |
| 35 | case InstallPayloadType::kFull: |
| 36 | return "full"; |
| 37 | case InstallPayloadType::kDelta: |
| 38 | return "delta"; |
| 39 | } |
| 40 | return "invalid type"; |
| 41 | } |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 42 | |
| 43 | bool InstallPlan::operator==(const InstallPlan& that) const { |
| 44 | return ((is_resume == that.is_resume) && |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 45 | (download_url == that.download_url) && (payloads == that.payloads) && |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 46 | (source_slot == that.source_slot) && |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 47 | (target_slot == that.target_slot) && (partitions == that.partitions)); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | bool InstallPlan::operator!=(const InstallPlan& that) const { |
| 51 | return !((*this) == that); |
| 52 | } |
| 53 | |
| 54 | void InstallPlan::Dump() const { |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 55 | string partitions_str; |
| 56 | for (const auto& partition : partitions) { |
Alex Deymo | 390efed | 2016-02-18 11:00:40 -0800 | [diff] [blame] | 57 | partitions_str += |
| 58 | base::StringPrintf(", part: %s (source_size: %" PRIu64 |
| 59 | ", target_size %" PRIu64 ", postinst:%s)", |
| 60 | partition.name.c_str(), |
| 61 | partition.source_size, |
| 62 | partition.target_size, |
| 63 | utils::ToString(partition.run_postinstall).c_str()); |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 64 | } |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 65 | string payloads_str; |
| 66 | for (const auto& payload : payloads) { |
| 67 | payloads_str += base::StringPrintf( |
| 68 | ", payload: (size: %" PRIu64 ", metadata_size: %" PRIu64 |
Sen Jiang | cdd5206 | 2017-05-18 15:33:10 -0700 | [diff] [blame] | 69 | ", metadata signature: %s, hash: %s, payload type: %s)", |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 70 | payload.size, |
| 71 | payload.metadata_size, |
| 72 | payload.metadata_signature.c_str(), |
Sen Jiang | cdd5206 | 2017-05-18 15:33:10 -0700 | [diff] [blame] | 73 | base::HexEncode(payload.hash.data(), payload.hash.size()).c_str(), |
| 74 | InstallPayloadTypeToString(payload.type).c_str()); |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 75 | } |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 76 | |
Aaron Wood | 7dcdedf | 2017-09-06 17:17:41 -0700 | [diff] [blame] | 77 | string version_str = base::StringPrintf(", version: %s", version.c_str()); |
| 78 | if (!system_version.empty()) { |
| 79 | version_str += |
| 80 | base::StringPrintf(", system_version: %s", system_version.c_str()); |
| 81 | } |
| 82 | |
Sen Jiang | 2703ef4 | 2017-03-16 13:36:21 -0700 | [diff] [blame] | 83 | LOG(INFO) << "InstallPlan: " << (is_resume ? "resume" : "new_update") |
Aaron Wood | 7dcdedf | 2017-09-06 17:17:41 -0700 | [diff] [blame] | 84 | << version_str |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 85 | << ", source_slot: " << BootControlInterface::SlotName(source_slot) |
| 86 | << ", target_slot: " << BootControlInterface::SlotName(target_slot) |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 87 | << ", url: " << download_url << payloads_str << partitions_str |
Sen Jiang | 2703ef4 | 2017-03-16 13:36:21 -0700 | [diff] [blame] | 88 | << ", hash_checks_mandatory: " |
| 89 | << utils::ToString(hash_checks_mandatory) |
Sen Jiang | 02c4942 | 2017-10-31 15:14:11 -0700 | [diff] [blame] | 90 | << ", powerwash_required: " << utils::ToString(powerwash_required) |
| 91 | << ", switch_slot_on_reboot: " |
| 92 | << utils::ToString(switch_slot_on_reboot) |
Sen Jiang | 3eeaf7d | 2018-10-11 13:55:32 -0700 | [diff] [blame] | 93 | << ", run_post_install: " << utils::ToString(run_post_install) |
| 94 | << ", is_rollback: " << utils::ToString(is_rollback) |
| 95 | << ", write_verity: " << utils::ToString(write_verity); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Alex Deymo | 706a5ab | 2015-11-23 17:48:30 -0300 | [diff] [blame] | 98 | bool InstallPlan::LoadPartitionsFromSlots(BootControlInterface* boot_control) { |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 99 | bool result = true; |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 100 | for (Partition& partition : partitions) { |
| 101 | if (source_slot != BootControlInterface::kInvalidSlot) { |
Alex Deymo | 706a5ab | 2015-11-23 17:48:30 -0300 | [diff] [blame] | 102 | result = boot_control->GetPartitionDevice( |
Yifan Hong | 1d9077f | 2018-12-07 12:09:37 -0800 | [diff] [blame] | 103 | partition.name, source_slot, &partition.source_path) && |
| 104 | result; |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 105 | } else { |
| 106 | partition.source_path.clear(); |
| 107 | } |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 108 | |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 109 | if (target_slot != BootControlInterface::kInvalidSlot && |
| 110 | partition.target_size > 0) { |
Alex Deymo | 706a5ab | 2015-11-23 17:48:30 -0300 | [diff] [blame] | 111 | result = boot_control->GetPartitionDevice( |
Yifan Hong | 1d9077f | 2018-12-07 12:09:37 -0800 | [diff] [blame] | 112 | partition.name, target_slot, &partition.target_path) && |
| 113 | result; |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 114 | } else { |
| 115 | partition.target_path.clear(); |
| 116 | } |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 117 | } |
| 118 | return result; |
| 119 | } |
| 120 | |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 121 | bool InstallPlan::Partition::operator==( |
| 122 | const InstallPlan::Partition& that) const { |
Amin Hassani | 008c458 | 2019-01-13 16:22:47 -0800 | [diff] [blame^] | 123 | return (name == that.name && source_path == that.source_path && |
| 124 | source_size == that.source_size && source_hash == that.source_hash && |
| 125 | target_path == that.target_path && target_size == that.target_size && |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 126 | target_hash == that.target_hash && |
Alex Deymo | 390efed | 2016-02-18 11:00:40 -0800 | [diff] [blame] | 127 | run_postinstall == that.run_postinstall && |
| 128 | postinstall_path == that.postinstall_path && |
Alex Deymo | 5b91c6b | 2016-08-04 20:33:36 -0700 | [diff] [blame] | 129 | filesystem_type == that.filesystem_type && |
| 130 | postinstall_optional == that.postinstall_optional); |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 133 | } // namespace chromeos_update_engine |