• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
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 //
16 
17 #ifndef UPDATE_ENGINE_PAYLOAD_CONSUMER_INSTALL_PLAN_H_
18 #define UPDATE_ENGINE_PAYLOAD_CONSUMER_INSTALL_PLAN_H_
19 
20 #include <string>
21 #include <vector>
22 
23 #include <base/macros.h>
24 #include <brillo/secure_blob.h>
25 
26 #include "update_engine/common/action.h"
27 #include "update_engine/common/boot_control_interface.h"
28 
29 // InstallPlan is a simple struct that contains relevant info for many
30 // parts of the update system about the install that should happen.
31 namespace chromeos_update_engine {
32 
33 enum class InstallPayloadType {
34   kUnknown,
35   kFull,
36   kDelta,
37 };
38 
39 std::string InstallPayloadTypeToString(InstallPayloadType type);
40 
41 struct InstallPlan {
42   InstallPlan() = default;
43 
44   bool operator==(const InstallPlan& that) const;
45   bool operator!=(const InstallPlan& that) const;
46 
47   void Dump() const;
48 
49   // 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.
52   bool LoadPartitionsFromSlots(BootControlInterface* boot_control);
53 
54   bool is_resume{false};
55   std::string download_url;  // url to download from
56   std::string version;       // version we are installing.
57 
58   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
63     InstallPayloadType type{InstallPayloadType::kUnknown};
64     // 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;
68 
69     bool operator==(const Payload& that) const {
70       return size == that.size && metadata_size == that.metadata_size &&
71              metadata_signature == that.metadata_signature &&
72              hash == that.hash && type == that.type &&
73              already_applied == that.already_applied;
74     }
75   };
76   std::vector<Payload> payloads;
77 
78   // The partition slots used for the update.
79   BootControlInterface::Slot source_slot{BootControlInterface::kInvalidSlot};
80   BootControlInterface::Slot target_slot{BootControlInterface::kInvalidSlot};
81 
82   // The vector below is used for partition verification. The flow is:
83   //
84   // 1. DownloadAction fills in the expected source and target partition sizes
85   // and hashes based on the manifest.
86   //
87   // 2. FilesystemVerifierAction computes and verifies the partition sizes and
88   // hashes against the expected values.
89   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};
97     brillo::Blob source_hash;
98 
99     std::string target_path;
100     uint64_t target_size{0};
101     brillo::Blob target_hash;
102 
103     // Whether we should run the postinstall script from this partition and the
104     // postinstall parameters.
105     bool run_postinstall{false};
106     std::string postinstall_path;
107     std::string filesystem_type;
108     bool postinstall_optional{false};
109   };
110   std::vector<Partition> partitions;
111 
112   // True if payload hash checks are mandatory based on the system state and
113   // the Omaha response.
114   bool hash_checks_mandatory{false};
115 
116   // True if Powerwash is required on reboot after applying the payload.
117   // False otherwise.
118   bool powerwash_required{false};
119 
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;
123 };
124 
125 class InstallPlanAction;
126 
127 template<>
128 class 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.
139 class InstallPlanAction : public Action<InstallPlanAction> {
140  public:
InstallPlanAction()141   InstallPlanAction() {}
InstallPlanAction(const InstallPlan & install_plan)142   explicit InstallPlanAction(const InstallPlan& install_plan):
143     install_plan_(install_plan) {}
144 
PerformAction()145   void PerformAction() override {
146     if (HasOutputPipe()) {
147       SetOutputObject(install_plan_);
148     }
149     processor_->ActionComplete(this, ErrorCode::kSuccess);
150   }
151 
install_plan()152   InstallPlan* install_plan() { return &install_plan_; }
153 
StaticType()154   static std::string StaticType() { return "InstallPlanAction"; }
Type()155   std::string Type() const override { return StaticType(); }
156 
157   typedef ActionTraits<InstallPlanAction>::InputObjectType InputObjectType;
158   typedef ActionTraits<InstallPlanAction>::OutputObjectType OutputObjectType;
159 
160  private:
161   InstallPlan install_plan_;
162 
163   DISALLOW_COPY_AND_ASSIGN(InstallPlanAction);
164 };
165 
166 }  // namespace chromeos_update_engine
167 
168 #endif  // UPDATE_ENGINE_PAYLOAD_CONSUMER_INSTALL_PLAN_H_
169