blob: 5f004bf3061dad8bcc1a89e157f1a234e69c7ad4 [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
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 Srinivasanae4697c2013-03-18 17:08:08 -070016
Alex Deymo39910dc2015-11-09 17:04:30 -080017#include "update_engine/payload_consumer/install_plan.h"
Jay Srinivasanae4697c2013-03-18 17:08:08 -070018
Alex Deymoe5e5fe92015-10-05 09:28:19 -070019#include <base/format_macros.h>
Alex Deymo8427b4a2014-11-05 14:00:32 -080020#include <base/logging.h>
Sen Jiang2703ef42017-03-16 13:36:21 -070021#include <base/strings/string_number_conversions.h>
Alex Deymoe5e5fe92015-10-05 09:28:19 -070022#include <base/strings/stringprintf.h>
Jay Srinivasanae4697c2013-03-18 17:08:08 -070023
Alex Deymo39910dc2015-11-09 17:04:30 -080024#include "update_engine/common/utils.h"
25#include "update_engine/payload_consumer/payload_constants.h"
Jay Srinivasanae4697c2013-03-18 17:08:08 -070026
27using std::string;
28
29namespace chromeos_update_engine {
30
Alex Deymo64d98782016-02-05 18:03:48 -080031string 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 Srinivasanae4697c2013-03-18 17:08:08 -070042
43bool InstallPlan::operator==(const InstallPlan& that) const {
44 return ((is_resume == that.is_resume) &&
Alex Deymo64d98782016-02-05 18:03:48 -080045 (payload_type == that.payload_type) &&
Sen Jiang0affc2c2017-02-10 15:55:05 -080046 (download_url == that.download_url) && (payloads == that.payloads) &&
Alex Deymo763e7db2015-08-27 21:08:08 -070047 (source_slot == that.source_slot) &&
Sen Jiang0affc2c2017-02-10 15:55:05 -080048 (target_slot == that.target_slot) && (partitions == that.partitions));
Jay Srinivasanae4697c2013-03-18 17:08:08 -070049}
50
51bool InstallPlan::operator!=(const InstallPlan& that) const {
52 return !((*this) == that);
53}
54
55void InstallPlan::Dump() const {
Alex Deymoe5e5fe92015-10-05 09:28:19 -070056 string partitions_str;
57 for (const auto& partition : partitions) {
Alex Deymo390efed2016-02-18 11:00:40 -080058 partitions_str +=
59 base::StringPrintf(", part: %s (source_size: %" PRIu64
60 ", target_size %" PRIu64 ", postinst:%s)",
61 partition.name.c_str(),
62 partition.source_size,
63 partition.target_size,
64 utils::ToString(partition.run_postinstall).c_str());
Alex Deymoe5e5fe92015-10-05 09:28:19 -070065 }
Sen Jiang0affc2c2017-02-10 15:55:05 -080066 string payloads_str;
67 for (const auto& payload : payloads) {
68 payloads_str += base::StringPrintf(
69 ", payload: (size: %" PRIu64 ", metadata_size: %" PRIu64
70 ", metadata signature: %s, hash: %s)",
71 payload.size,
72 payload.metadata_size,
73 payload.metadata_signature.c_str(),
74 base::HexEncode(payload.hash.data(), payload.hash.size()).c_str());
75 }
Alex Deymoe5e5fe92015-10-05 09:28:19 -070076
Sen Jiang2703ef42017-03-16 13:36:21 -070077 LOG(INFO) << "InstallPlan: " << (is_resume ? "resume" : "new_update")
Alex Deymo64d98782016-02-05 18:03:48 -080078 << ", payload type: " << InstallPayloadTypeToString(payload_type)
Alex Deymo763e7db2015-08-27 21:08:08 -070079 << ", source_slot: " << BootControlInterface::SlotName(source_slot)
80 << ", target_slot: " << BootControlInterface::SlotName(target_slot)
Sen Jiang0affc2c2017-02-10 15:55:05 -080081 << ", url: " << download_url << payloads_str << partitions_str
Sen Jiang2703ef42017-03-16 13:36:21 -070082 << ", hash_checks_mandatory: "
83 << utils::ToString(hash_checks_mandatory)
Alex Deymo64d98782016-02-05 18:03:48 -080084 << ", powerwash_required: " << utils::ToString(powerwash_required);
Jay Srinivasanae4697c2013-03-18 17:08:08 -070085}
86
Alex Deymo706a5ab2015-11-23 17:48:30 -030087bool InstallPlan::LoadPartitionsFromSlots(BootControlInterface* boot_control) {
Alex Deymo763e7db2015-08-27 21:08:08 -070088 bool result = true;
Alex Deymoe5e5fe92015-10-05 09:28:19 -070089 for (Partition& partition : partitions) {
90 if (source_slot != BootControlInterface::kInvalidSlot) {
Alex Deymo706a5ab2015-11-23 17:48:30 -030091 result = boot_control->GetPartitionDevice(
Alex Deymoe5e5fe92015-10-05 09:28:19 -070092 partition.name, source_slot, &partition.source_path) && result;
93 } else {
94 partition.source_path.clear();
95 }
Alex Deymo763e7db2015-08-27 21:08:08 -070096
Alex Deymoe5e5fe92015-10-05 09:28:19 -070097 if (target_slot != BootControlInterface::kInvalidSlot) {
Alex Deymo706a5ab2015-11-23 17:48:30 -030098 result = boot_control->GetPartitionDevice(
Alex Deymoe5e5fe92015-10-05 09:28:19 -070099 partition.name, target_slot, &partition.target_path) && result;
100 } else {
101 partition.target_path.clear();
102 }
Alex Deymo763e7db2015-08-27 21:08:08 -0700103 }
104 return result;
105}
106
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700107bool InstallPlan::Partition::operator==(
108 const InstallPlan::Partition& that) const {
109 return (name == that.name &&
110 source_path == that.source_path &&
111 source_size == that.source_size &&
112 source_hash == that.source_hash &&
113 target_path == that.target_path &&
114 target_size == that.target_size &&
115 target_hash == that.target_hash &&
Alex Deymo390efed2016-02-18 11:00:40 -0800116 run_postinstall == that.run_postinstall &&
117 postinstall_path == that.postinstall_path &&
Alex Deymo5b91c6b2016-08-04 20:33:36 -0700118 filesystem_type == that.filesystem_type &&
119 postinstall_optional == that.postinstall_optional);
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700120}
121
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700122} // namespace chromeos_update_engine