blob: 14e5c5aae4c7b79124d92da1e487973377fd17df [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 Vakulenko3f39d5c2015-10-13 09:27:13 -070024#include <brillo/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,
David Zeuthene7f89172013-10-31 10:21:04 -070042 const std::string& public_key_rsa);
Jay Srinivasan738fdf32012-12-07 17:40:54 -080043
Alex Deymo763e7db2015-08-27 21:08:08 -070044 // Default constructor.
45 InstallPlan() = default;
Jay Srinivasanae4697c2013-03-18 17:08:08 -070046
47 bool operator==(const InstallPlan& that) const;
48 bool operator!=(const InstallPlan& that) const;
49
50 void Dump() const;
adlr@google.com3defe6a2009-12-04 20:57:17 +000051
Alex Deymoe5e5fe92015-10-05 09:28:19 -070052 // Load the |source_path| and |target_path| of all |partitions| based on the
53 // |source_slot| and |target_slot| if available. Returns whether it succeeded
54 // to load all the partitions for the valid slots.
Alex Deymo763e7db2015-08-27 21:08:08 -070055 bool LoadPartitionsFromSlots(SystemState* system_state);
56
57 bool is_resume{false};
58 bool is_full_update{false};
adlr@google.com3defe6a2009-12-04 20:57:17 +000059 std::string download_url; // url to download from
Chris Sosafb1020e2013-07-29 17:27:33 -070060 std::string version; // version we are installing.
Jay Srinivasan51dcf262012-09-13 17:24:32 -070061
Alex Deymo763e7db2015-08-27 21:08:08 -070062 uint64_t payload_size{0}; // size of the payload
63 std::string payload_hash; // SHA256 hash of the payload
64 uint64_t metadata_size{0}; // size of the metadata
Jay Srinivasanf4318702012-09-24 11:56:24 -070065 std::string metadata_signature; // signature of the metadata
Alex Deymo763e7db2015-08-27 21:08:08 -070066
67 // The partition slots used for the update.
68 BootControlInterface::Slot source_slot{BootControlInterface::kInvalidSlot};
69 BootControlInterface::Slot target_slot{BootControlInterface::kInvalidSlot};
70
Alex Deymoe5e5fe92015-10-05 09:28:19 -070071 // The vector below is used for partition verification. The flow is:
Darin Petkov3aefa862010-12-07 14:45:00 -080072 //
Allie Woodeb9e6d82015-04-17 13:55:30 -070073 // 1. FilesystemVerifierAction computes and fills in the source partition
Alex Deymoe5e5fe92015-10-05 09:28:19 -070074 // hash based on the guessed source size for delta major version 1 updates.
Darin Petkov3aefa862010-12-07 14:45:00 -080075 //
76 // 2. DownloadAction verifies the source partition sizes and hashes against
77 // the expected values transmitted in the update manifest. It fills in the
Alex Deymoe5e5fe92015-10-05 09:28:19 -070078 // expected target partition sizes and hashes based on the manifest.
Darin Petkov3aefa862010-12-07 14:45:00 -080079 //
Alex Deymoe5e5fe92015-10-05 09:28:19 -070080 // 3. FilesystemVerifierAction computes and verifies the applied partition
81 // sizes and hashes against the expected values in target_partition_hashes.
82 struct Partition {
83 bool operator==(const Partition& that) const;
84
85 // The name of the partition.
86 std::string name;
87
88 std::string source_path;
89 uint64_t source_size{0};
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070090 brillo::Blob source_hash;
Alex Deymoe5e5fe92015-10-05 09:28:19 -070091
92 std::string target_path;
93 uint64_t target_size{0};
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070094 brillo::Blob target_hash;
Alex Deymoe5e5fe92015-10-05 09:28:19 -070095
96 // Whether we should run the postinstall script from this partition.
97 bool run_postinstall{false};
98 };
99 std::vector<Partition> partitions;
adlr@google.com3defe6a2009-12-04 20:57:17 +0000100
Jay Srinivasan738fdf32012-12-07 17:40:54 -0800101 // True if payload hash checks are mandatory based on the system state and
102 // the Omaha response.
Alex Deymo763e7db2015-08-27 21:08:08 -0700103 bool hash_checks_mandatory{false};
Jay Srinivasan738fdf32012-12-07 17:40:54 -0800104
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700105 // True if Powerwash is required on reboot after applying the payload.
106 // False otherwise.
Alex Deymo763e7db2015-08-27 21:08:08 -0700107 bool powerwash_required{false};
David Zeuthene7f89172013-10-31 10:21:04 -0700108
109 // If not blank, a base-64 encoded representation of the PEM-encoded
110 // public key in the response.
111 std::string public_key_rsa;
adlr@google.com3defe6a2009-12-04 20:57:17 +0000112};
113
Chris Sosad317e402013-06-12 13:47:09 -0700114class InstallPlanAction;
115
116template<>
117class ActionTraits<InstallPlanAction> {
118 public:
119 // Takes the install plan as input
120 typedef InstallPlan InputObjectType;
121 // Passes the install plan as output
122 typedef InstallPlan OutputObjectType;
123};
124
125// Basic action that only receives and sends Install Plans.
126// Can be used to construct an Install Plan to send to any other Action that
127// accept an InstallPlan.
128class InstallPlanAction : public Action<InstallPlanAction> {
129 public:
130 InstallPlanAction() {}
Alex Vakulenkod2779df2014-06-16 13:19:00 -0700131 explicit InstallPlanAction(const InstallPlan& install_plan):
Chris Sosad317e402013-06-12 13:47:09 -0700132 install_plan_(install_plan) {}
133
Alex Deymo610277e2014-11-11 21:18:11 -0800134 void PerformAction() override {
Chris Sosad317e402013-06-12 13:47:09 -0700135 if (HasOutputPipe()) {
136 SetOutputObject(install_plan_);
137 }
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700138 processor_->ActionComplete(this, ErrorCode::kSuccess);
Chris Sosad317e402013-06-12 13:47:09 -0700139 }
140
Chris Sosa76a29ae2013-07-11 17:59:24 -0700141 InstallPlan* install_plan() { return &install_plan_; }
142
143 static std::string StaticType() { return "InstallPlanAction"; }
Alex Deymo610277e2014-11-11 21:18:11 -0800144 std::string Type() const override { return StaticType(); }
Chris Sosad317e402013-06-12 13:47:09 -0700145
146 typedef ActionTraits<InstallPlanAction>::InputObjectType InputObjectType;
147 typedef ActionTraits<InstallPlanAction>::OutputObjectType OutputObjectType;
148
149 private:
150 InstallPlan install_plan_;
151
Alex Vakulenkod2779df2014-06-16 13:19:00 -0700152 DISALLOW_COPY_AND_ASSIGN(InstallPlanAction);
Chris Sosad317e402013-06-12 13:47:09 -0700153};
154
adlr@google.com3defe6a2009-12-04 20:57:17 +0000155} // namespace chromeos_update_engine
156
Gilad Arnoldcf175a02014-07-10 16:48:47 -0700157#endif // UPDATE_ENGINE_INSTALL_PLAN_H_