blob: c3788609b9f75a1a0ea8d0d4fbd861b0c5bb67dd [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
21#include "update_engine/utils.h"
22
23using std::string;
24
25namespace chromeos_update_engine {
26
Alex Deymo763e7db2015-08-27 21:08:08 -070027const char* kLegacyPartitionNameKernel = "KERNEL";
28const char* kLegacyPartitionNameRoot = "ROOT";
29
Jay Srinivasanae4697c2013-03-18 17:08:08 -070030InstallPlan::InstallPlan(bool is_resume,
Gilad Arnold21504f02013-05-24 08:51:22 -070031 bool is_full_update,
Jay Srinivasanae4697c2013-03-18 17:08:08 -070032 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 Zeuthene7f89172013-10-31 10:21:04 -070038 const string& kernel_install_path,
Allie Woodfdf00512015-03-02 13:34:55 -080039 const string& source_path,
40 const string& kernel_source_path,
Alex Deymof329b932014-10-30 01:37:48 -070041 const string& public_key_rsa)
Jay Srinivasanae4697c2013-03-18 17:08:08 -070042 : is_resume(is_resume),
Gilad Arnold21504f02013-05-24 08:51:22 -070043 is_full_update(is_full_update),
Jay Srinivasanae4697c2013-03-18 17:08:08 -070044 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 Woodfdf00512015-03-02 13:34:55 -080051 source_path(source_path),
52 kernel_source_path(kernel_source_path),
Jay Srinivasanae4697c2013-03-18 17:08:08 -070053 kernel_size(0),
54 rootfs_size(0),
55 hash_checks_mandatory(false),
David Zeuthene7f89172013-10-31 10:21:04 -070056 powerwash_required(false),
57 public_key_rsa(public_key_rsa) {}
Jay Srinivasanae4697c2013-03-18 17:08:08 -070058
Jay Srinivasanae4697c2013-03-18 17:08:08 -070059
60bool InstallPlan::operator==(const InstallPlan& that) const {
61 return ((is_resume == that.is_resume) &&
Gilad Arnold21504f02013-05-24 08:51:22 -070062 (is_full_update == that.is_full_update) &&
Jay Srinivasanae4697c2013-03-18 17:08:08 -070063 (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 Deymo763e7db2015-08-27 21:08:08 -070068 (source_slot == that.source_slot) &&
69 (target_slot == that.target_slot) &&
Jay Srinivasanae4697c2013-03-18 17:08:08 -070070 (install_path == that.install_path) &&
Allie Woodfdf00512015-03-02 13:34:55 -080071 (kernel_install_path == that.kernel_install_path) &&
72 (source_path == that.source_path) &&
73 (kernel_source_path == that.kernel_source_path));
Jay Srinivasanae4697c2013-03-18 17:08:08 -070074}
75
76bool InstallPlan::operator!=(const InstallPlan& that) const {
77 return !((*this) == that);
78}
79
80void InstallPlan::Dump() const {
81 LOG(INFO) << "InstallPlan: "
Gilad Arnold21504f02013-05-24 08:51:22 -070082 << (is_resume ? "resume" : "new_update")
83 << ", payload type: " << (is_full_update ? "full" : "delta")
Alex Deymo763e7db2015-08-27 21:08:08 -070084 << ", source_slot: " << BootControlInterface::SlotName(source_slot)
85 << ", target_slot: " << BootControlInterface::SlotName(target_slot)
Jay Srinivasanae4697c2013-03-18 17:08:08 -070086 << ", 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 Woodfdf00512015-03-02 13:34:55 -080093 << ", source_path: " << source_path
94 << ", kernel_source_path: " << kernel_source_path
Jay Srinivasanae4697c2013-03-18 17:08:08 -070095 << ", hash_checks_mandatory: " << utils::ToString(
96 hash_checks_mandatory)
97 << ", powerwash_required: " << utils::ToString(
98 powerwash_required);
99}
100
Alex Deymo763e7db2015-08-27 21:08:08 -0700101bool 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 Srinivasanae4697c2013-03-18 17:08:08 -0700125} // namespace chromeos_update_engine