blob: 8ccabc6d5533249474468c664188ba4a905fb19b [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>
adlr@google.com3defe6a2009-12-04 20:57:17 +000012
Chris Sosad317e402013-06-12 13:47:09 -070013#include "update_engine/action.h"
14
adlr@google.com3defe6a2009-12-04 20:57:17 +000015// InstallPlan is a simple struct that contains relevant info for many
16// parts of the update system about the install that should happen.
adlr@google.com3defe6a2009-12-04 20:57:17 +000017namespace chromeos_update_engine {
18
19struct InstallPlan {
Darin Petkov7ed561b2011-10-04 02:59:03 -070020 InstallPlan(bool is_resume,
Gilad Arnold21504f02013-05-24 08:51:22 -070021 bool is_full_update,
adlr@google.com3defe6a2009-12-04 20:57:17 +000022 const std::string& url,
Jay Srinivasan51dcf262012-09-13 17:24:32 -070023 uint64_t payload_size,
24 const std::string& payload_hash,
Jay Srinivasanf4318702012-09-24 11:56:24 -070025 uint64_t metadata_size,
26 const std::string& metadata_signature,
Andrew de los Reyesf9185172010-05-03 11:07:05 -070027 const std::string& install_path,
David Zeuthene7f89172013-10-31 10:21:04 -070028 const std::string& kernel_install_path,
29 const std::string& public_key_rsa);
Jay Srinivasan738fdf32012-12-07 17:40:54 -080030
31 // Default constructor: Initialize all members which don't have a class
32 // initializer.
Jay Srinivasanae4697c2013-03-18 17:08:08 -070033 InstallPlan();
34
35 bool operator==(const InstallPlan& that) const;
36 bool operator!=(const InstallPlan& that) const;
37
38 void Dump() const;
adlr@google.com3defe6a2009-12-04 20:57:17 +000039
Darin Petkov0406e402010-10-06 21:33:11 -070040 bool is_resume;
Gilad Arnold21504f02013-05-24 08:51:22 -070041 bool is_full_update;
adlr@google.com3defe6a2009-12-04 20:57:17 +000042 std::string download_url; // url to download from
Chris Sosafb1020e2013-07-29 17:27:33 -070043 std::string version; // version we are installing.
Jay Srinivasan51dcf262012-09-13 17:24:32 -070044
45 uint64_t payload_size; // size of the payload
Chris Sosad317e402013-06-12 13:47:09 -070046 std::string payload_hash; // SHA256 hash of the payload
Jay Srinivasanf4318702012-09-24 11:56:24 -070047 uint64_t metadata_size; // size of the metadata
48 std::string metadata_signature; // signature of the metadata
Jay Srinivasan51dcf262012-09-13 17:24:32 -070049 std::string install_path; // path to install device
50 std::string kernel_install_path; // path to kernel install device
Darin Petkov3aefa862010-12-07 14:45:00 -080051
52 // The fields below are used for kernel and rootfs verification. The flow is:
53 //
54 // 1. FilesystemCopierAction(verify_hash=false) computes and fills in the
55 // source partition sizes and hashes.
56 //
57 // 2. DownloadAction verifies the source partition sizes and hashes against
58 // the expected values transmitted in the update manifest. It fills in the
59 // expected applied partition sizes and hashes based on the manifest.
60 //
61 // 4. FilesystemCopierAction(verify_hashes=true) computes and verifies the
62 // applied partition sizes and hashes against the expected values.
63 uint64_t kernel_size;
64 uint64_t rootfs_size;
65 std::vector<char> kernel_hash;
66 std::vector<char> rootfs_hash;
adlr@google.com3defe6a2009-12-04 20:57:17 +000067
Jay Srinivasan738fdf32012-12-07 17:40:54 -080068 // True if payload hash checks are mandatory based on the system state and
69 // the Omaha response.
70 bool hash_checks_mandatory;
71
Jay Srinivasanae4697c2013-03-18 17:08:08 -070072 // True if Powerwash is required on reboot after applying the payload.
73 // False otherwise.
74 bool powerwash_required;
David Zeuthene7f89172013-10-31 10:21:04 -070075
76 // If not blank, a base-64 encoded representation of the PEM-encoded
77 // public key in the response.
78 std::string public_key_rsa;
adlr@google.com3defe6a2009-12-04 20:57:17 +000079};
80
Chris Sosad317e402013-06-12 13:47:09 -070081class InstallPlanAction;
82
83template<>
84class ActionTraits<InstallPlanAction> {
85 public:
86 // Takes the install plan as input
87 typedef InstallPlan InputObjectType;
88 // Passes the install plan as output
89 typedef InstallPlan OutputObjectType;
90};
91
92// Basic action that only receives and sends Install Plans.
93// Can be used to construct an Install Plan to send to any other Action that
94// accept an InstallPlan.
95class InstallPlanAction : public Action<InstallPlanAction> {
96 public:
97 InstallPlanAction() {}
Alex Vakulenkod2779df2014-06-16 13:19:00 -070098 explicit InstallPlanAction(const InstallPlan& install_plan):
Chris Sosad317e402013-06-12 13:47:09 -070099 install_plan_(install_plan) {}
100
101 virtual void PerformAction() {
102 if (HasOutputPipe()) {
103 SetOutputObject(install_plan_);
104 }
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700105 processor_->ActionComplete(this, ErrorCode::kSuccess);
Chris Sosad317e402013-06-12 13:47:09 -0700106 }
107
Chris Sosa76a29ae2013-07-11 17:59:24 -0700108 InstallPlan* install_plan() { return &install_plan_; }
109
110 static std::string StaticType() { return "InstallPlanAction"; }
111 virtual std::string Type() const { return StaticType(); }
Chris Sosad317e402013-06-12 13:47:09 -0700112
113 typedef ActionTraits<InstallPlanAction>::InputObjectType InputObjectType;
114 typedef ActionTraits<InstallPlanAction>::OutputObjectType OutputObjectType;
115
116 private:
117 InstallPlan install_plan_;
118
Alex Vakulenkod2779df2014-06-16 13:19:00 -0700119 DISALLOW_COPY_AND_ASSIGN(InstallPlanAction);
Chris Sosad317e402013-06-12 13:47:09 -0700120};
121
adlr@google.com3defe6a2009-12-04 20:57:17 +0000122} // namespace chromeos_update_engine
123
Gilad Arnoldcf175a02014-07-10 16:48:47 -0700124#endif // UPDATE_ENGINE_INSTALL_PLAN_H_