blob: 6e6f7aeddefd025c674109443e2a53349ce6e759 [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
Alex Deymo763e7db2015-08-27 21:08:08 -070034// TODO(deymo): Remove these constants from this interface once the InstallPlan
35// doesn't list the partitions explicitly.
36extern const char* kLegacyPartitionNameKernel;
37extern const char* kLegacyPartitionNameRoot;
38
adlr@google.com3defe6a2009-12-04 20:57:17 +000039struct InstallPlan {
Darin Petkov7ed561b2011-10-04 02:59:03 -070040 InstallPlan(bool is_resume,
Gilad Arnold21504f02013-05-24 08:51:22 -070041 bool is_full_update,
adlr@google.com3defe6a2009-12-04 20:57:17 +000042 const std::string& url,
Jay Srinivasan51dcf262012-09-13 17:24:32 -070043 uint64_t payload_size,
44 const std::string& payload_hash,
Jay Srinivasanf4318702012-09-24 11:56:24 -070045 uint64_t metadata_size,
46 const std::string& metadata_signature,
Andrew de los Reyesf9185172010-05-03 11:07:05 -070047 const std::string& install_path,
David Zeuthene7f89172013-10-31 10:21:04 -070048 const std::string& kernel_install_path,
Allie Woodfdf00512015-03-02 13:34:55 -080049 const std::string& source_path,
50 const std::string& kernel_source_path,
David Zeuthene7f89172013-10-31 10:21:04 -070051 const std::string& public_key_rsa);
Jay Srinivasan738fdf32012-12-07 17:40:54 -080052
Alex Deymo763e7db2015-08-27 21:08:08 -070053 // Default constructor.
54 InstallPlan() = default;
Jay Srinivasanae4697c2013-03-18 17:08:08 -070055
56 bool operator==(const InstallPlan& that) const;
57 bool operator!=(const InstallPlan& that) const;
58
59 void Dump() const;
adlr@google.com3defe6a2009-12-04 20:57:17 +000060
Alex Deymo763e7db2015-08-27 21:08:08 -070061 bool LoadPartitionsFromSlots(SystemState* system_state);
62
63 bool is_resume{false};
64 bool is_full_update{false};
adlr@google.com3defe6a2009-12-04 20:57:17 +000065 std::string download_url; // url to download from
Chris Sosafb1020e2013-07-29 17:27:33 -070066 std::string version; // version we are installing.
Jay Srinivasan51dcf262012-09-13 17:24:32 -070067
Alex Deymo763e7db2015-08-27 21:08:08 -070068 uint64_t payload_size{0}; // size of the payload
69 std::string payload_hash; // SHA256 hash of the payload
70 uint64_t metadata_size{0}; // size of the metadata
Jay Srinivasanf4318702012-09-24 11:56:24 -070071 std::string metadata_signature; // signature of the metadata
Alex Deymo763e7db2015-08-27 21:08:08 -070072
73 // The partition slots used for the update.
74 BootControlInterface::Slot source_slot{BootControlInterface::kInvalidSlot};
75 BootControlInterface::Slot target_slot{BootControlInterface::kInvalidSlot};
76
77 // TODO(deymo): Deprecate these fields and use the slots instead.
Jay Srinivasan51dcf262012-09-13 17:24:32 -070078 std::string install_path; // path to install device
79 std::string kernel_install_path; // path to kernel install device
Allie Woodfdf00512015-03-02 13:34:55 -080080 std::string source_path; // path to source device
81 std::string kernel_source_path; // path to source kernel device
Darin Petkov3aefa862010-12-07 14:45:00 -080082
83 // The fields below are used for kernel and rootfs verification. The flow is:
84 //
Allie Woodeb9e6d82015-04-17 13:55:30 -070085 // 1. FilesystemVerifierAction computes and fills in the source partition
86 // sizes and hashes.
Darin Petkov3aefa862010-12-07 14:45:00 -080087 //
88 // 2. DownloadAction verifies the source partition sizes and hashes against
89 // the expected values transmitted in the update manifest. It fills in the
90 // expected applied partition sizes and hashes based on the manifest.
91 //
Allie Woodeb9e6d82015-04-17 13:55:30 -070092 // 3. FilesystemVerifierAction computes and verifies the applied and source
93 // partition sizes and hashes against the expected values.
Alex Deymo763e7db2015-08-27 21:08:08 -070094 uint64_t kernel_size{0};
95 uint64_t rootfs_size{0};
Alex Vakulenkof68bbbc2015-02-09 12:53:18 -080096 chromeos::Blob kernel_hash;
97 chromeos::Blob rootfs_hash;
Allie Woodeb9e6d82015-04-17 13:55:30 -070098 chromeos::Blob source_kernel_hash;
99 chromeos::Blob source_rootfs_hash;
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_