blob: b5a5be1661140f8999ff018b190584ea6f2a4f18 [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"
27
adlr@google.com3defe6a2009-12-04 20:57:17 +000028// InstallPlan is a simple struct that contains relevant info for many
29// parts of the update system about the install that should happen.
adlr@google.com3defe6a2009-12-04 20:57:17 +000030namespace chromeos_update_engine {
31
32struct InstallPlan {
Darin Petkov7ed561b2011-10-04 02:59:03 -070033 InstallPlan(bool is_resume,
Gilad Arnold21504f02013-05-24 08:51:22 -070034 bool is_full_update,
adlr@google.com3defe6a2009-12-04 20:57:17 +000035 const std::string& url,
Jay Srinivasan51dcf262012-09-13 17:24:32 -070036 uint64_t payload_size,
37 const std::string& payload_hash,
Jay Srinivasanf4318702012-09-24 11:56:24 -070038 uint64_t metadata_size,
39 const std::string& metadata_signature,
Andrew de los Reyesf9185172010-05-03 11:07:05 -070040 const std::string& install_path,
David Zeuthene7f89172013-10-31 10:21:04 -070041 const std::string& kernel_install_path,
Allie Woodfdf00512015-03-02 13:34:55 -080042 const std::string& source_path,
43 const std::string& kernel_source_path,
David Zeuthene7f89172013-10-31 10:21:04 -070044 const std::string& public_key_rsa);
Jay Srinivasan738fdf32012-12-07 17:40:54 -080045
46 // Default constructor: Initialize all members which don't have a class
47 // initializer.
Jay Srinivasanae4697c2013-03-18 17:08:08 -070048 InstallPlan();
49
50 bool operator==(const InstallPlan& that) const;
51 bool operator!=(const InstallPlan& that) const;
52
53 void Dump() const;
adlr@google.com3defe6a2009-12-04 20:57:17 +000054
Darin Petkov0406e402010-10-06 21:33:11 -070055 bool is_resume;
Gilad Arnold21504f02013-05-24 08:51:22 -070056 bool is_full_update;
adlr@google.com3defe6a2009-12-04 20:57:17 +000057 std::string download_url; // url to download from
Chris Sosafb1020e2013-07-29 17:27:33 -070058 std::string version; // version we are installing.
Jay Srinivasan51dcf262012-09-13 17:24:32 -070059
60 uint64_t payload_size; // size of the payload
Chris Sosad317e402013-06-12 13:47:09 -070061 std::string payload_hash; // SHA256 hash of the payload
Jay Srinivasanf4318702012-09-24 11:56:24 -070062 uint64_t metadata_size; // size of the metadata
63 std::string metadata_signature; // signature of the metadata
Jay Srinivasan51dcf262012-09-13 17:24:32 -070064 std::string install_path; // path to install device
65 std::string kernel_install_path; // path to kernel install device
Allie Woodfdf00512015-03-02 13:34:55 -080066 std::string source_path; // path to source device
67 std::string kernel_source_path; // path to source kernel device
Darin Petkov3aefa862010-12-07 14:45:00 -080068
69 // The fields below are used for kernel and rootfs verification. The flow is:
70 //
Allie Woodeb9e6d82015-04-17 13:55:30 -070071 // 1. FilesystemVerifierAction computes and fills in the source partition
72 // sizes and hashes.
Darin Petkov3aefa862010-12-07 14:45:00 -080073 //
74 // 2. DownloadAction verifies the source partition sizes and hashes against
75 // the expected values transmitted in the update manifest. It fills in the
76 // expected applied partition sizes and hashes based on the manifest.
77 //
Allie Woodeb9e6d82015-04-17 13:55:30 -070078 // 3. FilesystemVerifierAction computes and verifies the applied and source
79 // partition sizes and hashes against the expected values.
Darin Petkov3aefa862010-12-07 14:45:00 -080080 uint64_t kernel_size;
81 uint64_t rootfs_size;
Alex Vakulenkof68bbbc2015-02-09 12:53:18 -080082 chromeos::Blob kernel_hash;
83 chromeos::Blob rootfs_hash;
Allie Woodeb9e6d82015-04-17 13:55:30 -070084 chromeos::Blob source_kernel_hash;
85 chromeos::Blob source_rootfs_hash;
adlr@google.com3defe6a2009-12-04 20:57:17 +000086
Jay Srinivasan738fdf32012-12-07 17:40:54 -080087 // True if payload hash checks are mandatory based on the system state and
88 // the Omaha response.
89 bool hash_checks_mandatory;
90
Jay Srinivasanae4697c2013-03-18 17:08:08 -070091 // True if Powerwash is required on reboot after applying the payload.
92 // False otherwise.
93 bool powerwash_required;
David Zeuthene7f89172013-10-31 10:21:04 -070094
95 // If not blank, a base-64 encoded representation of the PEM-encoded
96 // public key in the response.
97 std::string public_key_rsa;
adlr@google.com3defe6a2009-12-04 20:57:17 +000098};
99
Chris Sosad317e402013-06-12 13:47:09 -0700100class InstallPlanAction;
101
102template<>
103class ActionTraits<InstallPlanAction> {
104 public:
105 // Takes the install plan as input
106 typedef InstallPlan InputObjectType;
107 // Passes the install plan as output
108 typedef InstallPlan OutputObjectType;
109};
110
111// Basic action that only receives and sends Install Plans.
112// Can be used to construct an Install Plan to send to any other Action that
113// accept an InstallPlan.
114class InstallPlanAction : public Action<InstallPlanAction> {
115 public:
116 InstallPlanAction() {}
Alex Vakulenkod2779df2014-06-16 13:19:00 -0700117 explicit InstallPlanAction(const InstallPlan& install_plan):
Chris Sosad317e402013-06-12 13:47:09 -0700118 install_plan_(install_plan) {}
119
Alex Deymo610277e2014-11-11 21:18:11 -0800120 void PerformAction() override {
Chris Sosad317e402013-06-12 13:47:09 -0700121 if (HasOutputPipe()) {
122 SetOutputObject(install_plan_);
123 }
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700124 processor_->ActionComplete(this, ErrorCode::kSuccess);
Chris Sosad317e402013-06-12 13:47:09 -0700125 }
126
Chris Sosa76a29ae2013-07-11 17:59:24 -0700127 InstallPlan* install_plan() { return &install_plan_; }
128
129 static std::string StaticType() { return "InstallPlanAction"; }
Alex Deymo610277e2014-11-11 21:18:11 -0800130 std::string Type() const override { return StaticType(); }
Chris Sosad317e402013-06-12 13:47:09 -0700131
132 typedef ActionTraits<InstallPlanAction>::InputObjectType InputObjectType;
133 typedef ActionTraits<InstallPlanAction>::OutputObjectType OutputObjectType;
134
135 private:
136 InstallPlan install_plan_;
137
Alex Vakulenkod2779df2014-06-16 13:19:00 -0700138 DISALLOW_COPY_AND_ASSIGN(InstallPlanAction);
Chris Sosad317e402013-06-12 13:47:09 -0700139};
140
adlr@google.com3defe6a2009-12-04 20:57:17 +0000141} // namespace chromeos_update_engine
142
Gilad Arnoldcf175a02014-07-10 16:48:47 -0700143#endif // UPDATE_ENGINE_INSTALL_PLAN_H_