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 // system version, if present and separate from version 58 std::string system_version; 59 60 struct 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 // Only download manifest and fill in partitions in install plan without 67 // apply the payload if true. Will be set by DownloadAction when resuming 68 // multi-payload. 69 bool already_applied = false; 70 71 bool operator==(const Payload& that) const { 72 return size == that.size && metadata_size == that.metadata_size && 73 metadata_signature == that.metadata_signature && 74 hash == that.hash && type == that.type && 75 already_applied == that.already_applied; 76 } 77 }; 78 std::vector<Payload> payloads; 79 80 // The partition slots used for the update. 81 BootControlInterface::Slot source_slot{BootControlInterface::kInvalidSlot}; 82 BootControlInterface::Slot target_slot{BootControlInterface::kInvalidSlot}; 83 84 // The vector below is used for partition verification. The flow is: 85 // 86 // 1. DownloadAction fills in the expected source and target partition sizes 87 // and hashes based on the manifest. 88 // 89 // 2. FilesystemVerifierAction computes and verifies the partition sizes and 90 // hashes against the expected values. 91 struct Partition { 92 bool operator==(const Partition& that) const; 93 94 // The name of the partition. 95 std::string name; 96 97 std::string source_path; 98 uint64_t source_size{0}; 99 brillo::Blob source_hash; 100 101 std::string target_path; 102 uint64_t target_size{0}; 103 brillo::Blob target_hash; 104 105 // Whether we should run the postinstall script from this partition and the 106 // postinstall parameters. 107 bool run_postinstall{false}; 108 std::string postinstall_path; 109 std::string filesystem_type; 110 bool postinstall_optional{false}; 111 }; 112 std::vector<Partition> partitions; 113 114 // True if payload hash checks are mandatory based on the system state and 115 // the Omaha response. 116 bool hash_checks_mandatory{false}; 117 118 // True if Powerwash is required on reboot after applying the payload. 119 // False otherwise. 120 bool powerwash_required{false}; 121 122 // True if the updated slot should be marked active on success. 123 // False otherwise. 124 bool switch_slot_on_reboot{true}; 125 126 // True if the update should run its post-install step. 127 // False otherwise. 128 bool run_post_install{true}; 129 130 // If not blank, a base-64 encoded representation of the PEM-encoded 131 // public key in the response. 132 std::string public_key_rsa; 133 }; 134 135 class InstallPlanAction; 136 137 template<> 138 class ActionTraits<InstallPlanAction> { 139 public: 140 // Takes the install plan as input 141 typedef InstallPlan InputObjectType; 142 // Passes the install plan as output 143 typedef InstallPlan OutputObjectType; 144 }; 145 146 // Basic action that only receives and sends Install Plans. 147 // Can be used to construct an Install Plan to send to any other Action that 148 // accept an InstallPlan. 149 class InstallPlanAction : public Action<InstallPlanAction> { 150 public: InstallPlanAction()151 InstallPlanAction() {} InstallPlanAction(const InstallPlan & install_plan)152 explicit InstallPlanAction(const InstallPlan& install_plan): 153 install_plan_(install_plan) {} 154 PerformAction()155 void PerformAction() override { 156 if (HasOutputPipe()) { 157 SetOutputObject(install_plan_); 158 } 159 processor_->ActionComplete(this, ErrorCode::kSuccess); 160 } 161 install_plan()162 InstallPlan* install_plan() { return &install_plan_; } 163 StaticType()164 static std::string StaticType() { return "InstallPlanAction"; } Type()165 std::string Type() const override { return StaticType(); } 166 167 typedef ActionTraits<InstallPlanAction>::InputObjectType InputObjectType; 168 typedef ActionTraits<InstallPlanAction>::OutputObjectType OutputObjectType; 169 170 private: 171 InstallPlan install_plan_; 172 173 DISALLOW_COPY_AND_ASSIGN(InstallPlanAction); 174 }; 175 176 } // namespace chromeos_update_engine 177 178 #endif // UPDATE_ENGINE_PAYLOAD_CONSUMER_INSTALL_PLAN_H_ 179