blob: 6eb52fc489f4506fb9fbc3f141242e5c97864c46 [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
2// Copyright (C) 2011 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//
adlr@google.com3defe6a2009-12-04 20:57:17 +000016
Gilad Arnoldcf175a02014-07-10 16:48:47 -070017#ifndef UPDATE_ENGINE_INSTALL_PLAN_H_
18#define UPDATE_ENGINE_INSTALL_PLAN_H_
adlr@google.com3defe6a2009-12-04 20:57:17 +000019
20#include <string>
Darin Petkov698d0412010-10-13 10:59:44 -070021#include <vector>
22
Ben Chan05735a12014-09-03 07:48:22 -070023#include <base/macros.h>
Alex Vakulenkof68bbbc2015-02-09 12:53:18 -080024#include <chromeos/secure_blob.h>
adlr@google.com3defe6a2009-12-04 20:57:17 +000025
Chris Sosad317e402013-06-12 13:47:09 -070026#include "update_engine/action.h"
Alex Deymo763e7db2015-08-27 21:08:08 -070027#include "update_engine/boot_control_interface.h"
28#include "update_engine/system_state.h"
Chris Sosad317e402013-06-12 13:47:09 -070029
adlr@google.com3defe6a2009-12-04 20:57:17 +000030// InstallPlan is a simple struct that contains relevant info for many
31// parts of the update system about the install that should happen.
adlr@google.com3defe6a2009-12-04 20:57:17 +000032namespace chromeos_update_engine {
33
34struct InstallPlan {
Darin Petkov7ed561b2011-10-04 02:59:03 -070035 InstallPlan(bool is_resume,
Gilad Arnold21504f02013-05-24 08:51:22 -070036 bool is_full_update,
adlr@google.com3defe6a2009-12-04 20:57:17 +000037 const std::string& url,
Jay Srinivasan51dcf262012-09-13 17:24:32 -070038 uint64_t payload_size,
39 const std::string& payload_hash,
Jay Srinivasanf4318702012-09-24 11:56:24 -070040 uint64_t metadata_size,
41 const std::string& metadata_signature,
Andrew de los Reyesf9185172010-05-03 11:07:05 -070042 const std::string& install_path,
David Zeuthene7f89172013-10-31 10:21:04 -070043 const std::string& kernel_install_path,
Allie Woodfdf00512015-03-02 13:34:55 -080044 const std::string& source_path,
45 const std::string& kernel_source_path,
David Zeuthene7f89172013-10-31 10:21:04 -070046 const std::string& public_key_rsa);
Jay Srinivasan738fdf32012-12-07 17:40:54 -080047
Alex Deymo763e7db2015-08-27 21:08:08 -070048 // Default constructor.
49 InstallPlan() = default;
Jay Srinivasanae4697c2013-03-18 17:08:08 -070050
51 bool operator==(const InstallPlan& that) const;
52 bool operator!=(const InstallPlan& that) const;
53
54 void Dump() const;
adlr@google.com3defe6a2009-12-04 20:57:17 +000055
Alex Deymo763e7db2015-08-27 21:08:08 -070056 bool LoadPartitionsFromSlots(SystemState* system_state);
57
58 bool is_resume{false};
59 bool is_full_update{false};
adlr@google.com3defe6a2009-12-04 20:57:17 +000060 std::string download_url; // url to download from
Chris Sosafb1020e2013-07-29 17:27:33 -070061 std::string version; // version we are installing.
Jay Srinivasan51dcf262012-09-13 17:24:32 -070062
Alex Deymo763e7db2015-08-27 21:08:08 -070063 uint64_t payload_size{0}; // size of the payload
64 std::string payload_hash; // SHA256 hash of the payload
65 uint64_t metadata_size{0}; // size of the metadata
Jay Srinivasanf4318702012-09-24 11:56:24 -070066 std::string metadata_signature; // signature of the metadata
Alex Deymo763e7db2015-08-27 21:08:08 -070067
68 // The partition slots used for the update.
69 BootControlInterface::Slot source_slot{BootControlInterface::kInvalidSlot};
70 BootControlInterface::Slot target_slot{BootControlInterface::kInvalidSlot};
71
72 // TODO(deymo): Deprecate these fields and use the slots instead.
Jay Srinivasan51dcf262012-09-13 17:24:32 -070073 std::string install_path; // path to install device
74 std::string kernel_install_path; // path to kernel install device
Allie Woodfdf00512015-03-02 13:34:55 -080075 std::string source_path; // path to source device
76 std::string kernel_source_path; // path to source kernel device
Darin Petkov3aefa862010-12-07 14:45:00 -080077
78 // The fields below are used for kernel and rootfs verification. The flow is:
79 //
Allie Woodeb9e6d82015-04-17 13:55:30 -070080 // 1. FilesystemVerifierAction computes and fills in the source partition
81 // sizes and hashes.
Darin Petkov3aefa862010-12-07 14:45:00 -080082 //
83 // 2. DownloadAction verifies the source partition sizes and hashes against
84 // the expected values transmitted in the update manifest. It fills in the
85 // expected applied partition sizes and hashes based on the manifest.
86 //
Allie Woodeb9e6d82015-04-17 13:55:30 -070087 // 3. FilesystemVerifierAction computes and verifies the applied and source
88 // partition sizes and hashes against the expected values.
Alex Deymo763e7db2015-08-27 21:08:08 -070089 uint64_t kernel_size{0};
90 uint64_t rootfs_size{0};
Alex Vakulenkof68bbbc2015-02-09 12:53:18 -080091 chromeos::Blob kernel_hash;
92 chromeos::Blob rootfs_hash;
Allie Woodeb9e6d82015-04-17 13:55:30 -070093 chromeos::Blob source_kernel_hash;
94 chromeos::Blob source_rootfs_hash;
adlr@google.com3defe6a2009-12-04 20:57:17 +000095
Jay Srinivasan738fdf32012-12-07 17:40:54 -080096 // True if payload hash checks are mandatory based on the system state and
97 // the Omaha response.
Alex Deymo763e7db2015-08-27 21:08:08 -070098 bool hash_checks_mandatory{false};
Jay Srinivasan738fdf32012-12-07 17:40:54 -080099
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700100 // True if Powerwash is required on reboot after applying the payload.
101 // False otherwise.
Alex Deymo763e7db2015-08-27 21:08:08 -0700102 bool powerwash_required{false};
David Zeuthene7f89172013-10-31 10:21:04 -0700103
104 // If not blank, a base-64 encoded representation of the PEM-encoded
105 // public key in the response.
106 std::string public_key_rsa;
adlr@google.com3defe6a2009-12-04 20:57:17 +0000107};
108
Chris Sosad317e402013-06-12 13:47:09 -0700109class InstallPlanAction;
110
111template<>
112class ActionTraits<InstallPlanAction> {
113 public:
114 // Takes the install plan as input
115 typedef InstallPlan InputObjectType;
116 // Passes the install plan as output
117 typedef InstallPlan OutputObjectType;
118};
119
120// Basic action that only receives and sends Install Plans.
121// Can be used to construct an Install Plan to send to any other Action that
122// accept an InstallPlan.
123class InstallPlanAction : public Action<InstallPlanAction> {
124 public:
125 InstallPlanAction() {}
Alex Vakulenkod2779df2014-06-16 13:19:00 -0700126 explicit InstallPlanAction(const InstallPlan& install_plan):
Chris Sosad317e402013-06-12 13:47:09 -0700127 install_plan_(install_plan) {}
128
Alex Deymo610277e2014-11-11 21:18:11 -0800129 void PerformAction() override {
Chris Sosad317e402013-06-12 13:47:09 -0700130 if (HasOutputPipe()) {
131 SetOutputObject(install_plan_);
132 }
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700133 processor_->ActionComplete(this, ErrorCode::kSuccess);
Chris Sosad317e402013-06-12 13:47:09 -0700134 }
135
Chris Sosa76a29ae2013-07-11 17:59:24 -0700136 InstallPlan* install_plan() { return &install_plan_; }
137
138 static std::string StaticType() { return "InstallPlanAction"; }
Alex Deymo610277e2014-11-11 21:18:11 -0800139 std::string Type() const override { return StaticType(); }
Chris Sosad317e402013-06-12 13:47:09 -0700140
141 typedef ActionTraits<InstallPlanAction>::InputObjectType InputObjectType;
142 typedef ActionTraits<InstallPlanAction>::OutputObjectType OutputObjectType;
143
144 private:
145 InstallPlan install_plan_;
146
Alex Vakulenkod2779df2014-06-16 13:19:00 -0700147 DISALLOW_COPY_AND_ASSIGN(InstallPlanAction);
Chris Sosad317e402013-06-12 13:47:09 -0700148};
149
adlr@google.com3defe6a2009-12-04 20:57:17 +0000150} // namespace chromeos_update_engine
151
Gilad Arnoldcf175a02014-07-10 16:48:47 -0700152#endif // UPDATE_ENGINE_INSTALL_PLAN_H_