blob: 756822a4f8d2e065c4e398ee56ec37489aca5692 [file] [log] [blame]
Darin Petkov7ed561b2011-10-04 02:59:03 -07001// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
adlr@google.com3defe6a2009-12-04 20:57:17 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Gilad Arnoldcf175a02014-07-10 16:48:47 -07005#ifndef UPDATE_ENGINE_INSTALL_PLAN_H_
6#define UPDATE_ENGINE_INSTALL_PLAN_H_
adlr@google.com3defe6a2009-12-04 20:57:17 +00007
8#include <string>
Darin Petkov698d0412010-10-13 10:59:44 -07009#include <vector>
10
Ben Chan05735a12014-09-03 07:48:22 -070011#include <base/macros.h>
Alex Vakulenkof68bbbc2015-02-09 12:53:18 -080012#include <chromeos/secure_blob.h>
adlr@google.com3defe6a2009-12-04 20:57:17 +000013
Chris Sosad317e402013-06-12 13:47:09 -070014#include "update_engine/action.h"
15
adlr@google.com3defe6a2009-12-04 20:57:17 +000016// InstallPlan is a simple struct that contains relevant info for many
17// parts of the update system about the install that should happen.
adlr@google.com3defe6a2009-12-04 20:57:17 +000018namespace chromeos_update_engine {
19
20struct InstallPlan {
Darin Petkov7ed561b2011-10-04 02:59:03 -070021 InstallPlan(bool is_resume,
Gilad Arnold21504f02013-05-24 08:51:22 -070022 bool is_full_update,
adlr@google.com3defe6a2009-12-04 20:57:17 +000023 const std::string& url,
Jay Srinivasan51dcf262012-09-13 17:24:32 -070024 uint64_t payload_size,
25 const std::string& payload_hash,
Jay Srinivasanf4318702012-09-24 11:56:24 -070026 uint64_t metadata_size,
27 const std::string& metadata_signature,
Andrew de los Reyesf9185172010-05-03 11:07:05 -070028 const std::string& install_path,
David Zeuthene7f89172013-10-31 10:21:04 -070029 const std::string& kernel_install_path,
Allie Woodfdf00512015-03-02 13:34:55 -080030 const std::string& source_path,
31 const std::string& kernel_source_path,
David Zeuthene7f89172013-10-31 10:21:04 -070032 const std::string& public_key_rsa);
Jay Srinivasan738fdf32012-12-07 17:40:54 -080033
34 // Default constructor: Initialize all members which don't have a class
35 // initializer.
Jay Srinivasanae4697c2013-03-18 17:08:08 -070036 InstallPlan();
37
38 bool operator==(const InstallPlan& that) const;
39 bool operator!=(const InstallPlan& that) const;
40
41 void Dump() const;
adlr@google.com3defe6a2009-12-04 20:57:17 +000042
Darin Petkov0406e402010-10-06 21:33:11 -070043 bool is_resume;
Gilad Arnold21504f02013-05-24 08:51:22 -070044 bool is_full_update;
adlr@google.com3defe6a2009-12-04 20:57:17 +000045 std::string download_url; // url to download from
Chris Sosafb1020e2013-07-29 17:27:33 -070046 std::string version; // version we are installing.
Jay Srinivasan51dcf262012-09-13 17:24:32 -070047
48 uint64_t payload_size; // size of the payload
Chris Sosad317e402013-06-12 13:47:09 -070049 std::string payload_hash; // SHA256 hash of the payload
Jay Srinivasanf4318702012-09-24 11:56:24 -070050 uint64_t metadata_size; // size of the metadata
51 std::string metadata_signature; // signature of the metadata
Jay Srinivasan51dcf262012-09-13 17:24:32 -070052 std::string install_path; // path to install device
53 std::string kernel_install_path; // path to kernel install device
Allie Woodfdf00512015-03-02 13:34:55 -080054 std::string source_path; // path to source device
55 std::string kernel_source_path; // path to source kernel device
Darin Petkov3aefa862010-12-07 14:45:00 -080056
57 // The fields below are used for kernel and rootfs verification. The flow is:
58 //
Allie Woodeb9e6d82015-04-17 13:55:30 -070059 // 1. FilesystemVerifierAction computes and fills in the source partition
60 // sizes and hashes.
Darin Petkov3aefa862010-12-07 14:45:00 -080061 //
62 // 2. DownloadAction verifies the source partition sizes and hashes against
63 // the expected values transmitted in the update manifest. It fills in the
64 // expected applied partition sizes and hashes based on the manifest.
65 //
Allie Woodeb9e6d82015-04-17 13:55:30 -070066 // 3. FilesystemVerifierAction computes and verifies the applied and source
67 // partition sizes and hashes against the expected values.
Darin Petkov3aefa862010-12-07 14:45:00 -080068 uint64_t kernel_size;
69 uint64_t rootfs_size;
Alex Vakulenkof68bbbc2015-02-09 12:53:18 -080070 chromeos::Blob kernel_hash;
71 chromeos::Blob rootfs_hash;
Allie Woodeb9e6d82015-04-17 13:55:30 -070072 chromeos::Blob source_kernel_hash;
73 chromeos::Blob source_rootfs_hash;
adlr@google.com3defe6a2009-12-04 20:57:17 +000074
Jay Srinivasan738fdf32012-12-07 17:40:54 -080075 // True if payload hash checks are mandatory based on the system state and
76 // the Omaha response.
77 bool hash_checks_mandatory;
78
Jay Srinivasanae4697c2013-03-18 17:08:08 -070079 // True if Powerwash is required on reboot after applying the payload.
80 // False otherwise.
81 bool powerwash_required;
David Zeuthene7f89172013-10-31 10:21:04 -070082
83 // If not blank, a base-64 encoded representation of the PEM-encoded
84 // public key in the response.
85 std::string public_key_rsa;
adlr@google.com3defe6a2009-12-04 20:57:17 +000086};
87
Chris Sosad317e402013-06-12 13:47:09 -070088class InstallPlanAction;
89
90template<>
91class ActionTraits<InstallPlanAction> {
92 public:
93 // Takes the install plan as input
94 typedef InstallPlan InputObjectType;
95 // Passes the install plan as output
96 typedef InstallPlan OutputObjectType;
97};
98
99// Basic action that only receives and sends Install Plans.
100// Can be used to construct an Install Plan to send to any other Action that
101// accept an InstallPlan.
102class InstallPlanAction : public Action<InstallPlanAction> {
103 public:
104 InstallPlanAction() {}
Alex Vakulenkod2779df2014-06-16 13:19:00 -0700105 explicit InstallPlanAction(const InstallPlan& install_plan):
Chris Sosad317e402013-06-12 13:47:09 -0700106 install_plan_(install_plan) {}
107
Alex Deymo610277e2014-11-11 21:18:11 -0800108 void PerformAction() override {
Chris Sosad317e402013-06-12 13:47:09 -0700109 if (HasOutputPipe()) {
110 SetOutputObject(install_plan_);
111 }
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700112 processor_->ActionComplete(this, ErrorCode::kSuccess);
Chris Sosad317e402013-06-12 13:47:09 -0700113 }
114
Chris Sosa76a29ae2013-07-11 17:59:24 -0700115 InstallPlan* install_plan() { return &install_plan_; }
116
117 static std::string StaticType() { return "InstallPlanAction"; }
Alex Deymo610277e2014-11-11 21:18:11 -0800118 std::string Type() const override { return StaticType(); }
Chris Sosad317e402013-06-12 13:47:09 -0700119
120 typedef ActionTraits<InstallPlanAction>::InputObjectType InputObjectType;
121 typedef ActionTraits<InstallPlanAction>::OutputObjectType OutputObjectType;
122
123 private:
124 InstallPlan install_plan_;
125
Alex Vakulenkod2779df2014-06-16 13:19:00 -0700126 DISALLOW_COPY_AND_ASSIGN(InstallPlanAction);
Chris Sosad317e402013-06-12 13:47:09 -0700127};
128
adlr@google.com3defe6a2009-12-04 20:57:17 +0000129} // namespace chromeos_update_engine
130
Gilad Arnoldcf175a02014-07-10 16:48:47 -0700131#endif // UPDATE_ENGINE_INSTALL_PLAN_H_