blob: ec2ee93d72eb4f768a87a338e009cd0c49e07e64 [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
17#include "update_engine/install_plan.h"
18
Alex Deymo8427b4a2014-11-05 14:00:32 -080019#include <base/logging.h>
Jay Srinivasanae4697c2013-03-18 17:08:08 -070020
Sen Jiang70a6ab02015-08-28 13:23:27 -070021#include "update_engine/payload_constants.h"
Jay Srinivasanae4697c2013-03-18 17:08:08 -070022#include "update_engine/utils.h"
23
24using std::string;
25
26namespace chromeos_update_engine {
27
28InstallPlan::InstallPlan(bool is_resume,
Gilad Arnold21504f02013-05-24 08:51:22 -070029 bool is_full_update,
Jay Srinivasanae4697c2013-03-18 17:08:08 -070030 const string& url,
31 uint64_t payload_size,
32 const string& payload_hash,
33 uint64_t metadata_size,
34 const string& metadata_signature,
35 const string& install_path,
David Zeuthene7f89172013-10-31 10:21:04 -070036 const string& kernel_install_path,
Allie Woodfdf00512015-03-02 13:34:55 -080037 const string& source_path,
38 const string& kernel_source_path,
Alex Deymof329b932014-10-30 01:37:48 -070039 const string& public_key_rsa)
Jay Srinivasanae4697c2013-03-18 17:08:08 -070040 : is_resume(is_resume),
Gilad Arnold21504f02013-05-24 08:51:22 -070041 is_full_update(is_full_update),
Jay Srinivasanae4697c2013-03-18 17:08:08 -070042 download_url(url),
43 payload_size(payload_size),
44 payload_hash(payload_hash),
45 metadata_size(metadata_size),
46 metadata_signature(metadata_signature),
47 install_path(install_path),
48 kernel_install_path(kernel_install_path),
Allie Woodfdf00512015-03-02 13:34:55 -080049 source_path(source_path),
50 kernel_source_path(kernel_source_path),
Jay Srinivasanae4697c2013-03-18 17:08:08 -070051 kernel_size(0),
52 rootfs_size(0),
53 hash_checks_mandatory(false),
David Zeuthene7f89172013-10-31 10:21:04 -070054 powerwash_required(false),
55 public_key_rsa(public_key_rsa) {}
Jay Srinivasanae4697c2013-03-18 17:08:08 -070056
Jay Srinivasanae4697c2013-03-18 17:08:08 -070057
58bool InstallPlan::operator==(const InstallPlan& that) const {
59 return ((is_resume == that.is_resume) &&
Gilad Arnold21504f02013-05-24 08:51:22 -070060 (is_full_update == that.is_full_update) &&
Jay Srinivasanae4697c2013-03-18 17:08:08 -070061 (download_url == that.download_url) &&
62 (payload_size == that.payload_size) &&
63 (payload_hash == that.payload_hash) &&
64 (metadata_size == that.metadata_size) &&
65 (metadata_signature == that.metadata_signature) &&
Alex Deymo763e7db2015-08-27 21:08:08 -070066 (source_slot == that.source_slot) &&
67 (target_slot == that.target_slot) &&
Jay Srinivasanae4697c2013-03-18 17:08:08 -070068 (install_path == that.install_path) &&
Allie Woodfdf00512015-03-02 13:34:55 -080069 (kernel_install_path == that.kernel_install_path) &&
70 (source_path == that.source_path) &&
71 (kernel_source_path == that.kernel_source_path));
Jay Srinivasanae4697c2013-03-18 17:08:08 -070072}
73
74bool InstallPlan::operator!=(const InstallPlan& that) const {
75 return !((*this) == that);
76}
77
78void InstallPlan::Dump() const {
79 LOG(INFO) << "InstallPlan: "
Gilad Arnold21504f02013-05-24 08:51:22 -070080 << (is_resume ? "resume" : "new_update")
81 << ", payload type: " << (is_full_update ? "full" : "delta")
Alex Deymo763e7db2015-08-27 21:08:08 -070082 << ", source_slot: " << BootControlInterface::SlotName(source_slot)
83 << ", target_slot: " << BootControlInterface::SlotName(target_slot)
Jay Srinivasanae4697c2013-03-18 17:08:08 -070084 << ", url: " << download_url
85 << ", payload size: " << payload_size
86 << ", payload hash: " << payload_hash
87 << ", metadata size: " << metadata_size
88 << ", metadata signature: " << metadata_signature
89 << ", install_path: " << install_path
90 << ", kernel_install_path: " << kernel_install_path
Allie Woodfdf00512015-03-02 13:34:55 -080091 << ", source_path: " << source_path
92 << ", kernel_source_path: " << kernel_source_path
Jay Srinivasanae4697c2013-03-18 17:08:08 -070093 << ", hash_checks_mandatory: " << utils::ToString(
94 hash_checks_mandatory)
95 << ", powerwash_required: " << utils::ToString(
96 powerwash_required);
97}
98
Alex Deymo763e7db2015-08-27 21:08:08 -070099bool InstallPlan::LoadPartitionsFromSlots(SystemState* system_state) {
100 bool result = true;
101 if (source_slot != BootControlInterface::kInvalidSlot) {
102 result = system_state->boot_control()->GetPartitionDevice(
103 kLegacyPartitionNameRoot, source_slot, &source_path) && result;
104 result = system_state->boot_control()->GetPartitionDevice(
105 kLegacyPartitionNameKernel, source_slot, &kernel_source_path) && result;
106 } else {
107 source_path.clear();
108 kernel_source_path.clear();
109 }
110
111 if (target_slot != BootControlInterface::kInvalidSlot) {
112 result = system_state->boot_control()->GetPartitionDevice(
113 kLegacyPartitionNameRoot, target_slot, &install_path) && result;
114 result = system_state->boot_control()->GetPartitionDevice(
115 kLegacyPartitionNameKernel, target_slot, &kernel_install_path) && result;
116 } else {
117 install_path.clear();
118 kernel_install_path.clear();
119 }
120 return result;
121}
122
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700123} // namespace chromeos_update_engine