• 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   std::string ToString() const;
49 
50   // Loads the |source_path| and |target_path| of all |partitions| based on the
51   // |source_slot| and |target_slot| if available. Returns whether it succeeded
52   // to load all the partitions for the valid slots.
53   bool LoadPartitionsFromSlots(BootControlInterface* boot_control);
54 
55   bool is_resume{false};
56   std::string download_url;  // url to download from
57   std::string version;       // version we are installing.
58 
59   struct Payload {
60     std::vector<std::string> payload_urls;  // URLs to download the payload
61     uint64_t size = 0;                      // size of the payload
62     uint64_t metadata_size = 0;             // size of the metadata
63     std::string metadata_signature;  // signature of the metadata in base64
64     brillo::Blob hash;               // SHA256 hash of the payload
65     InstallPayloadType type{InstallPayloadType::kUnknown};
66     std::string fp;      // fingerprint value unique to the payload
67     std::string app_id;  // App ID of the payload
68     // Only download manifest and fill in partitions in install plan without
69     // apply the payload if true. Will be set by DownloadAction when resuming
70     // multi-payload.
71     bool already_applied = false;
72 
73     bool operator==(const Payload& that) const {
74       return payload_urls == that.payload_urls && size == that.size &&
75              metadata_size == that.metadata_size &&
76              metadata_signature == that.metadata_signature &&
77              hash == that.hash && type == that.type &&
78              already_applied == that.already_applied && fp == that.fp &&
79              app_id == that.app_id;
80     }
81   };
82   std::vector<Payload> payloads;
83 
84   // The partition slots used for the update.
85   BootControlInterface::Slot source_slot{BootControlInterface::kInvalidSlot};
86   BootControlInterface::Slot target_slot{BootControlInterface::kInvalidSlot};
87 
88   // The vector below is used for partition verification. The flow is:
89   //
90   // 1. DownloadAction fills in the expected source and target partition sizes
91   // and hashes based on the manifest.
92   //
93   // 2. FilesystemVerifierAction computes and verifies the partition sizes and
94   // hashes against the expected values.
95   struct Partition {
96     bool operator==(const Partition& that) const;
97 
98     // The name of the partition.
99     std::string name;
100 
101     std::string source_path;
102     uint64_t source_size{0};
103     brillo::Blob source_hash;
104 
105     // |target_path| is intended to be a path to block device, which you can
106     // open with |open| syscall and perform regular unix style read/write.
107     // For VABC, this will be empty. As you can't read/write VABC devices with
108     // regular syscall.
109     std::string target_path;
110     // |mountable_target_device| is intended to be a path to block device which
111     // can be used for mounting this block device's underlying filesystem.
112     std::string readonly_target_path;
113     uint64_t target_size{0};
114     brillo::Blob target_hash;
115 
116     uint32_t block_size{0};
117 
118     // Whether we should run the postinstall script from this partition and the
119     // postinstall parameters.
120     bool run_postinstall{false};
121     std::string postinstall_path;
122     std::string filesystem_type;
123     bool postinstall_optional{false};
124 
125     // Verity hash tree and FEC config. See update_metadata.proto for details.
126     // All offsets and sizes are in bytes.
127     uint64_t hash_tree_data_offset{0};
128     uint64_t hash_tree_data_size{0};
129     uint64_t hash_tree_offset{0};
130     uint64_t hash_tree_size{0};
131     std::string hash_tree_algorithm;
132     brillo::Blob hash_tree_salt;
133 
134     uint64_t fec_data_offset{0};
135     uint64_t fec_data_size{0};
136     uint64_t fec_offset{0};
137     uint64_t fec_size{0};
138     uint32_t fec_roots{0};
139   };
140   std::vector<Partition> partitions;
141 
142   // True if payload hash checks are mandatory based on the system state and
143   // the Omaha response.
144   bool hash_checks_mandatory{false};
145 
146   // True if Powerwash is required on reboot after applying the payload.
147   // False otherwise.
148   bool powerwash_required{false};
149 
150   // True if the updated slot should be marked active on success.
151   // False otherwise.
152   bool switch_slot_on_reboot{true};
153 
154   // True if the update should run its post-install step.
155   // False otherwise.
156   bool run_post_install{true};
157 
158   // True if this update is a rollback.
159   bool is_rollback{false};
160 
161   // True if this rollback should preserve some system data.
162   bool rollback_data_save_requested{false};
163 
164   // True if the update should write verity.
165   // False otherwise.
166   bool write_verity{true};
167 
168   // If not blank, a base-64 encoded representation of the PEM-encoded
169   // public key in the response.
170   std::string public_key_rsa;
171 
172   // The name of dynamic partitions not included in the payload. Only used
173   // for partial updates.
174   std::vector<std::string> untouched_dynamic_partitions;
175 };
176 
177 class InstallPlanAction;
178 
179 template <>
180 class ActionTraits<InstallPlanAction> {
181  public:
182   // Takes the install plan as input
183   typedef InstallPlan InputObjectType;
184   // Passes the install plan as output
185   typedef InstallPlan OutputObjectType;
186 };
187 
188 // Basic action that only receives and sends Install Plans.
189 // Can be used to construct an Install Plan to send to any other Action that
190 // accept an InstallPlan.
191 class InstallPlanAction : public Action<InstallPlanAction> {
192  public:
InstallPlanAction()193   InstallPlanAction() {}
InstallPlanAction(const InstallPlan & install_plan)194   explicit InstallPlanAction(const InstallPlan& install_plan)
195       : install_plan_(install_plan) {}
196 
PerformAction()197   void PerformAction() override {
198     if (HasOutputPipe()) {
199       SetOutputObject(install_plan_);
200     }
201     processor_->ActionComplete(this, ErrorCode::kSuccess);
202   }
203 
install_plan()204   InstallPlan* install_plan() { return &install_plan_; }
205 
StaticType()206   static std::string StaticType() { return "InstallPlanAction"; }
Type()207   std::string Type() const override { return StaticType(); }
208 
209   typedef ActionTraits<InstallPlanAction>::InputObjectType InputObjectType;
210   typedef ActionTraits<InstallPlanAction>::OutputObjectType OutputObjectType;
211 
212  protected:
213   InstallPlan install_plan_;
214 
215  private:
216   DISALLOW_COPY_AND_ASSIGN(InstallPlanAction);
217 };
218 
219 }  // namespace chromeos_update_engine
220 
221 #endif  // UPDATE_ENGINE_PAYLOAD_CONSUMER_INSTALL_PLAN_H_
222