blob: 6dd5a73bc42ed705ed1c63669729b8f59ecba88c [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
Alex Deymo39910dc2015-11-09 17:04:30 -080017#ifndef UPDATE_ENGINE_PAYLOAD_CONSUMER_INSTALL_PLAN_H_
18#define UPDATE_ENGINE_PAYLOAD_CONSUMER_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
Alex Deymo39910dc2015-11-09 17:04:30 -080026#include "update_engine/common/action.h"
27#include "update_engine/common/boot_control_interface.h"
Chris Sosad317e402013-06-12 13:47:09 -070028
adlr@google.com3defe6a2009-12-04 20:57:17 +000029// InstallPlan is a simple struct that contains relevant info for many
30// parts of the update system about the install that should happen.
adlr@google.com3defe6a2009-12-04 20:57:17 +000031namespace chromeos_update_engine {
32
Alex Deymo64d98782016-02-05 18:03:48 -080033enum class InstallPayloadType {
34 kUnknown,
35 kFull,
36 kDelta,
37};
Jay Srinivasan738fdf32012-12-07 17:40:54 -080038
Alex Deymo64d98782016-02-05 18:03:48 -080039std::string InstallPayloadTypeToString(InstallPayloadType type);
40
41struct InstallPlan {
Alex Deymo763e7db2015-08-27 21:08:08 -070042 InstallPlan() = default;
Jay Srinivasanae4697c2013-03-18 17:08:08 -070043
44 bool operator==(const InstallPlan& that) const;
45 bool operator!=(const InstallPlan& that) const;
46
47 void Dump() const;
adlr@google.com3defe6a2009-12-04 20:57:17 +000048
Alex Deymoe5e5fe92015-10-05 09:28:19 -070049 // Load the |source_path| and |target_path| of all |partitions| based on the
50 // |source_slot| and |target_slot| if available. Returns whether it succeeded
51 // to load all the partitions for the valid slots.
Alex Deymo706a5ab2015-11-23 17:48:30 -030052 bool LoadPartitionsFromSlots(BootControlInterface* boot_control);
Alex Deymo763e7db2015-08-27 21:08:08 -070053
54 bool is_resume{false};
adlr@google.com3defe6a2009-12-04 20:57:17 +000055 std::string download_url; // url to download from
Chris Sosafb1020e2013-07-29 17:27:33 -070056 std::string version; // version we are installing.
Jay Srinivasan51dcf262012-09-13 17:24:32 -070057
Sen Jiang0affc2c2017-02-10 15:55:05 -080058 struct Payload {
59 uint64_t size = 0; // size of the payload
60 uint64_t metadata_size = 0; // size of the metadata
61 std::string metadata_signature; // signature of the metadata in base64
62 brillo::Blob hash; // SHA256 hash of the payload
Sen Jiangcdd52062017-05-18 15:33:10 -070063 InstallPayloadType type{InstallPayloadType::kUnknown};
Sen Jiang5ae865b2017-04-18 14:24:40 -070064 // Only download manifest and fill in partitions in install plan without
65 // apply the payload if true. Will be set by DownloadAction when resuming
66 // multi-payload.
67 bool already_applied = false;
Sen Jiang0affc2c2017-02-10 15:55:05 -080068
69 bool operator==(const Payload& that) const {
70 return size == that.size && metadata_size == that.metadata_size &&
Sen Jiang5ae865b2017-04-18 14:24:40 -070071 metadata_signature == that.metadata_signature &&
Sen Jiangcdd52062017-05-18 15:33:10 -070072 hash == that.hash && type == that.type &&
73 already_applied == that.already_applied;
Sen Jiang0affc2c2017-02-10 15:55:05 -080074 }
75 };
76 std::vector<Payload> payloads;
Alex Deymo763e7db2015-08-27 21:08:08 -070077
78 // The partition slots used for the update.
79 BootControlInterface::Slot source_slot{BootControlInterface::kInvalidSlot};
80 BootControlInterface::Slot target_slot{BootControlInterface::kInvalidSlot};
81
Alex Deymoe5e5fe92015-10-05 09:28:19 -070082 // The vector below is used for partition verification. The flow is:
Darin Petkov3aefa862010-12-07 14:45:00 -080083 //
Sen Jiangfef85fd2016-03-25 15:32:49 -070084 // 1. DownloadAction fills in the expected source and target partition sizes
85 // and hashes based on the manifest.
Darin Petkov3aefa862010-12-07 14:45:00 -080086 //
Sen Jiangfef85fd2016-03-25 15:32:49 -070087 // 2. FilesystemVerifierAction computes and verifies the partition sizes and
88 // hashes against the expected values.
Alex Deymoe5e5fe92015-10-05 09:28:19 -070089 struct Partition {
90 bool operator==(const Partition& that) const;
91
92 // The name of the partition.
93 std::string name;
94
95 std::string source_path;
96 uint64_t source_size{0};
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070097 brillo::Blob source_hash;
Alex Deymoe5e5fe92015-10-05 09:28:19 -070098
99 std::string target_path;
100 uint64_t target_size{0};
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700101 brillo::Blob target_hash;
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700102
Alex Deymo390efed2016-02-18 11:00:40 -0800103 // Whether we should run the postinstall script from this partition and the
104 // postinstall parameters.
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700105 bool run_postinstall{false};
Alex Deymo390efed2016-02-18 11:00:40 -0800106 std::string postinstall_path;
107 std::string filesystem_type;
Alex Deymo5b91c6b2016-08-04 20:33:36 -0700108 bool postinstall_optional{false};
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700109 };
110 std::vector<Partition> partitions;
adlr@google.com3defe6a2009-12-04 20:57:17 +0000111
Jay Srinivasan738fdf32012-12-07 17:40:54 -0800112 // True if payload hash checks are mandatory based on the system state and
113 // the Omaha response.
Alex Deymo763e7db2015-08-27 21:08:08 -0700114 bool hash_checks_mandatory{false};
Jay Srinivasan738fdf32012-12-07 17:40:54 -0800115
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700116 // True if Powerwash is required on reboot after applying the payload.
117 // False otherwise.
Alex Deymo763e7db2015-08-27 21:08:08 -0700118 bool powerwash_required{false};
David Zeuthene7f89172013-10-31 10:21:04 -0700119
120 // If not blank, a base-64 encoded representation of the PEM-encoded
121 // public key in the response.
122 std::string public_key_rsa;
adlr@google.com3defe6a2009-12-04 20:57:17 +0000123};
124
Chris Sosad317e402013-06-12 13:47:09 -0700125class InstallPlanAction;
126
127template<>
128class ActionTraits<InstallPlanAction> {
129 public:
130 // Takes the install plan as input
131 typedef InstallPlan InputObjectType;
132 // Passes the install plan as output
133 typedef InstallPlan OutputObjectType;
134};
135
136// Basic action that only receives and sends Install Plans.
137// Can be used to construct an Install Plan to send to any other Action that
138// accept an InstallPlan.
139class InstallPlanAction : public Action<InstallPlanAction> {
140 public:
141 InstallPlanAction() {}
Alex Vakulenkod2779df2014-06-16 13:19:00 -0700142 explicit InstallPlanAction(const InstallPlan& install_plan):
Chris Sosad317e402013-06-12 13:47:09 -0700143 install_plan_(install_plan) {}
144
Alex Deymo610277e2014-11-11 21:18:11 -0800145 void PerformAction() override {
Chris Sosad317e402013-06-12 13:47:09 -0700146 if (HasOutputPipe()) {
147 SetOutputObject(install_plan_);
148 }
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700149 processor_->ActionComplete(this, ErrorCode::kSuccess);
Chris Sosad317e402013-06-12 13:47:09 -0700150 }
151
Chris Sosa76a29ae2013-07-11 17:59:24 -0700152 InstallPlan* install_plan() { return &install_plan_; }
153
154 static std::string StaticType() { return "InstallPlanAction"; }
Alex Deymo610277e2014-11-11 21:18:11 -0800155 std::string Type() const override { return StaticType(); }
Chris Sosad317e402013-06-12 13:47:09 -0700156
157 typedef ActionTraits<InstallPlanAction>::InputObjectType InputObjectType;
158 typedef ActionTraits<InstallPlanAction>::OutputObjectType OutputObjectType;
159
160 private:
161 InstallPlan install_plan_;
162
Alex Vakulenkod2779df2014-06-16 13:19:00 -0700163 DISALLOW_COPY_AND_ASSIGN(InstallPlanAction);
Chris Sosad317e402013-06-12 13:47:09 -0700164};
165
adlr@google.com3defe6a2009-12-04 20:57:17 +0000166} // namespace chromeos_update_engine
167
Alex Deymo39910dc2015-11-09 17:04:30 -0800168#endif // UPDATE_ENGINE_PAYLOAD_CONSUMER_INSTALL_PLAN_H_