1*5a923131SAndroid Build Coastguard Worker // 2*5a923131SAndroid Build Coastguard Worker // Copyright (C) 2011 The Android Open Source Project 3*5a923131SAndroid Build Coastguard Worker // 4*5a923131SAndroid Build Coastguard Worker // Licensed under the Apache License, Version 2.0 (the "License"); 5*5a923131SAndroid Build Coastguard Worker // you may not use this file except in compliance with the License. 6*5a923131SAndroid Build Coastguard Worker // You may obtain a copy of the License at 7*5a923131SAndroid Build Coastguard Worker // 8*5a923131SAndroid Build Coastguard Worker // http://www.apache.org/licenses/LICENSE-2.0 9*5a923131SAndroid Build Coastguard Worker // 10*5a923131SAndroid Build Coastguard Worker // Unless required by applicable law or agreed to in writing, software 11*5a923131SAndroid Build Coastguard Worker // distributed under the License is distributed on an "AS IS" BASIS, 12*5a923131SAndroid Build Coastguard Worker // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*5a923131SAndroid Build Coastguard Worker // See the License for the specific language governing permissions and 14*5a923131SAndroid Build Coastguard Worker // limitations under the License. 15*5a923131SAndroid Build Coastguard Worker // 16*5a923131SAndroid Build Coastguard Worker 17*5a923131SAndroid Build Coastguard Worker #ifndef UPDATE_ENGINE_PAYLOAD_CONSUMER_INSTALL_PLAN_H_ 18*5a923131SAndroid Build Coastguard Worker #define UPDATE_ENGINE_PAYLOAD_CONSUMER_INSTALL_PLAN_H_ 19*5a923131SAndroid Build Coastguard Worker 20*5a923131SAndroid Build Coastguard Worker #include <string> 21*5a923131SAndroid Build Coastguard Worker #include <vector> 22*5a923131SAndroid Build Coastguard Worker 23*5a923131SAndroid Build Coastguard Worker #include <android-base/macros.h> 24*5a923131SAndroid Build Coastguard Worker #include <brillo/secure_blob.h> 25*5a923131SAndroid Build Coastguard Worker 26*5a923131SAndroid Build Coastguard Worker #include "update_engine/common/action.h" 27*5a923131SAndroid Build Coastguard Worker #include "update_engine/common/boot_control_interface.h" 28*5a923131SAndroid Build Coastguard Worker 29*5a923131SAndroid Build Coastguard Worker // InstallPlan is a simple struct that contains relevant info for many 30*5a923131SAndroid Build Coastguard Worker // parts of the update system about the install that should happen. 31*5a923131SAndroid Build Coastguard Worker namespace chromeos_update_engine { 32*5a923131SAndroid Build Coastguard Worker 33*5a923131SAndroid Build Coastguard Worker enum class InstallPayloadType { 34*5a923131SAndroid Build Coastguard Worker kUnknown, 35*5a923131SAndroid Build Coastguard Worker kFull, 36*5a923131SAndroid Build Coastguard Worker kDelta, 37*5a923131SAndroid Build Coastguard Worker }; 38*5a923131SAndroid Build Coastguard Worker 39*5a923131SAndroid Build Coastguard Worker std::string InstallPayloadTypeToString(InstallPayloadType type); 40*5a923131SAndroid Build Coastguard Worker 41*5a923131SAndroid Build Coastguard Worker struct InstallPlan { 42*5a923131SAndroid Build Coastguard Worker InstallPlan() = default; 43*5a923131SAndroid Build Coastguard Worker 44*5a923131SAndroid Build Coastguard Worker bool operator==(const InstallPlan& that) const; 45*5a923131SAndroid Build Coastguard Worker bool operator!=(const InstallPlan& that) const; 46*5a923131SAndroid Build Coastguard Worker 47*5a923131SAndroid Build Coastguard Worker void Dump() const; 48*5a923131SAndroid Build Coastguard Worker std::string ToString() const; 49*5a923131SAndroid Build Coastguard Worker 50*5a923131SAndroid Build Coastguard Worker private: 51*5a923131SAndroid Build Coastguard Worker // Loads the |source_path| and |target_path| of all |partitions| based on the 52*5a923131SAndroid Build Coastguard Worker // |source_slot| and |target_slot| if available. Returns whether it succeeded 53*5a923131SAndroid Build Coastguard Worker // to load all the partitions for the valid slots. 54*5a923131SAndroid Build Coastguard Worker bool LoadPartitionsFromSlots(BootControlInterface* boot_control); 55*5a923131SAndroid Build Coastguard Worker template <typename PartitinoUpdateArray> 56*5a923131SAndroid Build Coastguard Worker static bool ParseManifestToInstallPlan(const PartitinoUpdateArray& partitions, 57*5a923131SAndroid Build Coastguard Worker BootControlInterface* boot_control, 58*5a923131SAndroid Build Coastguard Worker size_t block_size, 59*5a923131SAndroid Build Coastguard Worker InstallPlan* install_plan, 60*5a923131SAndroid Build Coastguard Worker ErrorCode* error); 61*5a923131SAndroid Build Coastguard Worker 62*5a923131SAndroid Build Coastguard Worker public: 63*5a923131SAndroid Build Coastguard Worker // Load all partitions in |partitions| into this install plan, will also 64*5a923131SAndroid Build Coastguard Worker // populate |source_path|, |target_pathh|, fec information, partition sizes. 65*5a923131SAndroid Build Coastguard Worker bool ParsePartitions(const std::vector<PartitionUpdate>& partitions, 66*5a923131SAndroid Build Coastguard Worker BootControlInterface* boot_control, 67*5a923131SAndroid Build Coastguard Worker size_t block_size, 68*5a923131SAndroid Build Coastguard Worker ErrorCode* error); 69*5a923131SAndroid Build Coastguard Worker bool ParsePartitions( 70*5a923131SAndroid Build Coastguard Worker const google::protobuf::RepeatedPtrField<PartitionUpdate>& partitions, 71*5a923131SAndroid Build Coastguard Worker BootControlInterface* boot_control, 72*5a923131SAndroid Build Coastguard Worker size_t block_size, 73*5a923131SAndroid Build Coastguard Worker ErrorCode* error); 74*5a923131SAndroid Build Coastguard Worker 75*5a923131SAndroid Build Coastguard Worker bool is_resume{false}; 76*5a923131SAndroid Build Coastguard Worker bool vabc_none{false}; 77*5a923131SAndroid Build Coastguard Worker bool disable_vabc{false}; 78*5a923131SAndroid Build Coastguard Worker std::string download_url; // url to download from 79*5a923131SAndroid Build Coastguard Worker std::string version; // version we are installing. 80*5a923131SAndroid Build Coastguard Worker 81*5a923131SAndroid Build Coastguard Worker struct Payload { 82*5a923131SAndroid Build Coastguard Worker std::vector<std::string> payload_urls; // URLs to download the payload 83*5a923131SAndroid Build Coastguard Worker uint64_t size = 0; // size of the payload 84*5a923131SAndroid Build Coastguard Worker uint64_t metadata_size = 0; // size of the metadata 85*5a923131SAndroid Build Coastguard Worker std::string metadata_signature; // signature of the metadata in base64 86*5a923131SAndroid Build Coastguard Worker brillo::Blob hash; // SHA256 hash of the payload 87*5a923131SAndroid Build Coastguard Worker InstallPayloadType type{InstallPayloadType::kUnknown}; 88*5a923131SAndroid Build Coastguard Worker std::string fp; // fingerprint value unique to the payload 89*5a923131SAndroid Build Coastguard Worker std::string app_id; // App ID of the payload 90*5a923131SAndroid Build Coastguard Worker // Only download manifest and fill in partitions in install plan without 91*5a923131SAndroid Build Coastguard Worker // apply the payload if true. Will be set by DownloadAction when resuming 92*5a923131SAndroid Build Coastguard Worker // multi-payload. 93*5a923131SAndroid Build Coastguard Worker bool already_applied = false; 94*5a923131SAndroid Build Coastguard Worker 95*5a923131SAndroid Build Coastguard Worker bool operator==(const Payload& that) const { 96*5a923131SAndroid Build Coastguard Worker return payload_urls == that.payload_urls && size == that.size && 97*5a923131SAndroid Build Coastguard Worker metadata_size == that.metadata_size && 98*5a923131SAndroid Build Coastguard Worker metadata_signature == that.metadata_signature && 99*5a923131SAndroid Build Coastguard Worker hash == that.hash && type == that.type && 100*5a923131SAndroid Build Coastguard Worker already_applied == that.already_applied && fp == that.fp && 101*5a923131SAndroid Build Coastguard Worker app_id == that.app_id; 102*5a923131SAndroid Build Coastguard Worker } 103*5a923131SAndroid Build Coastguard Worker }; 104*5a923131SAndroid Build Coastguard Worker std::vector<Payload> payloads; 105*5a923131SAndroid Build Coastguard Worker 106*5a923131SAndroid Build Coastguard Worker // The partition slots used for the update. 107*5a923131SAndroid Build Coastguard Worker BootControlInterface::Slot source_slot{BootControlInterface::kInvalidSlot}; 108*5a923131SAndroid Build Coastguard Worker BootControlInterface::Slot target_slot{BootControlInterface::kInvalidSlot}; 109*5a923131SAndroid Build Coastguard Worker 110*5a923131SAndroid Build Coastguard Worker // The vector below is used for partition verification. The flow is: 111*5a923131SAndroid Build Coastguard Worker // 112*5a923131SAndroid Build Coastguard Worker // 1. DownloadAction fills in the expected source and target partition sizes 113*5a923131SAndroid Build Coastguard Worker // and hashes based on the manifest. 114*5a923131SAndroid Build Coastguard Worker // 115*5a923131SAndroid Build Coastguard Worker // 2. FilesystemVerifierAction computes and verifies the partition sizes and 116*5a923131SAndroid Build Coastguard Worker // hashes against the expected values. 117*5a923131SAndroid Build Coastguard Worker struct Partition { 118*5a923131SAndroid Build Coastguard Worker bool operator==(const Partition& that) const; 119*5a923131SAndroid Build Coastguard Worker 120*5a923131SAndroid Build Coastguard Worker // The name of the partition. 121*5a923131SAndroid Build Coastguard Worker std::string name; 122*5a923131SAndroid Build Coastguard Worker 123*5a923131SAndroid Build Coastguard Worker std::string source_path; 124*5a923131SAndroid Build Coastguard Worker uint64_t source_size{0}; 125*5a923131SAndroid Build Coastguard Worker brillo::Blob source_hash; 126*5a923131SAndroid Build Coastguard Worker 127*5a923131SAndroid Build Coastguard Worker // |target_path| is intended to be a path to block device, which you can 128*5a923131SAndroid Build Coastguard Worker // open with |open| syscall and perform regular unix style read/write. 129*5a923131SAndroid Build Coastguard Worker // For VABC, this will be empty. As you can't read/write VABC devices with 130*5a923131SAndroid Build Coastguard Worker // regular syscall. 131*5a923131SAndroid Build Coastguard Worker std::string target_path; 132*5a923131SAndroid Build Coastguard Worker // |mountable_target_device| is intended to be a path to block device which 133*5a923131SAndroid Build Coastguard Worker // can be used for mounting this block device's underlying filesystem. 134*5a923131SAndroid Build Coastguard Worker std::string readonly_target_path; 135*5a923131SAndroid Build Coastguard Worker uint64_t target_size{0}; 136*5a923131SAndroid Build Coastguard Worker brillo::Blob target_hash; 137*5a923131SAndroid Build Coastguard Worker 138*5a923131SAndroid Build Coastguard Worker uint32_t block_size{0}; 139*5a923131SAndroid Build Coastguard Worker 140*5a923131SAndroid Build Coastguard Worker // Whether we should run the postinstall script from this partition and the 141*5a923131SAndroid Build Coastguard Worker // postinstall parameters. 142*5a923131SAndroid Build Coastguard Worker bool run_postinstall{false}; 143*5a923131SAndroid Build Coastguard Worker std::string postinstall_path; 144*5a923131SAndroid Build Coastguard Worker std::string filesystem_type; 145*5a923131SAndroid Build Coastguard Worker bool postinstall_optional{false}; 146*5a923131SAndroid Build Coastguard Worker 147*5a923131SAndroid Build Coastguard Worker // Verity hash tree and FEC config. See update_metadata.proto for details. 148*5a923131SAndroid Build Coastguard Worker // All offsets and sizes are in bytes. 149*5a923131SAndroid Build Coastguard Worker uint64_t hash_tree_data_offset{0}; 150*5a923131SAndroid Build Coastguard Worker uint64_t hash_tree_data_size{0}; 151*5a923131SAndroid Build Coastguard Worker uint64_t hash_tree_offset{0}; 152*5a923131SAndroid Build Coastguard Worker uint64_t hash_tree_size{0}; 153*5a923131SAndroid Build Coastguard Worker std::string hash_tree_algorithm; 154*5a923131SAndroid Build Coastguard Worker brillo::Blob hash_tree_salt; 155*5a923131SAndroid Build Coastguard Worker 156*5a923131SAndroid Build Coastguard Worker uint64_t fec_data_offset{0}; 157*5a923131SAndroid Build Coastguard Worker uint64_t fec_data_size{0}; 158*5a923131SAndroid Build Coastguard Worker uint64_t fec_offset{0}; 159*5a923131SAndroid Build Coastguard Worker uint64_t fec_size{0}; 160*5a923131SAndroid Build Coastguard Worker uint32_t fec_roots{0}; 161*5a923131SAndroid Build Coastguard Worker 162*5a923131SAndroid Build Coastguard Worker bool ParseVerityConfig(const PartitionUpdate&); 163*5a923131SAndroid Build Coastguard Worker }; 164*5a923131SAndroid Build Coastguard Worker std::vector<Partition> partitions; 165*5a923131SAndroid Build Coastguard Worker 166*5a923131SAndroid Build Coastguard Worker // True if payload hash checks are mandatory based on the system state and 167*5a923131SAndroid Build Coastguard Worker // the Omaha response. 168*5a923131SAndroid Build Coastguard Worker bool hash_checks_mandatory{false}; 169*5a923131SAndroid Build Coastguard Worker 170*5a923131SAndroid Build Coastguard Worker // True if Powerwash is required on reboot after applying the payload. 171*5a923131SAndroid Build Coastguard Worker // False otherwise. 172*5a923131SAndroid Build Coastguard Worker bool powerwash_required{false}; 173*5a923131SAndroid Build Coastguard Worker 174*5a923131SAndroid Build Coastguard Worker // True if and only if this is an SPL downgrade OTA 175*5a923131SAndroid Build Coastguard Worker bool spl_downgrade{false}; 176*5a923131SAndroid Build Coastguard Worker 177*5a923131SAndroid Build Coastguard Worker // True if the updated slot should be marked active on success. 178*5a923131SAndroid Build Coastguard Worker // False otherwise. 179*5a923131SAndroid Build Coastguard Worker bool switch_slot_on_reboot{true}; 180*5a923131SAndroid Build Coastguard Worker 181*5a923131SAndroid Build Coastguard Worker // True if the update should run its post-install step. 182*5a923131SAndroid Build Coastguard Worker // False otherwise. 183*5a923131SAndroid Build Coastguard Worker bool run_post_install{true}; 184*5a923131SAndroid Build Coastguard Worker 185*5a923131SAndroid Build Coastguard Worker // True if the update should write verity. 186*5a923131SAndroid Build Coastguard Worker // False otherwise. 187*5a923131SAndroid Build Coastguard Worker bool write_verity{true}; 188*5a923131SAndroid Build Coastguard Worker 189*5a923131SAndroid Build Coastguard Worker // If not blank, a base-64 encoded representation of the PEM-encoded 190*5a923131SAndroid Build Coastguard Worker // public key in the response. 191*5a923131SAndroid Build Coastguard Worker std::string public_key_rsa; 192*5a923131SAndroid Build Coastguard Worker 193*5a923131SAndroid Build Coastguard Worker // The name of dynamic partitions not included in the payload. Only used 194*5a923131SAndroid Build Coastguard Worker // for partial updates. 195*5a923131SAndroid Build Coastguard Worker std::vector<std::string> untouched_dynamic_partitions; 196*5a923131SAndroid Build Coastguard Worker 197*5a923131SAndroid Build Coastguard Worker // Whether to batch write operations for COW 198*5a923131SAndroid Build Coastguard Worker bool batched_writes = false; 199*5a923131SAndroid Build Coastguard Worker 200*5a923131SAndroid Build Coastguard Worker // Whether to enable multi-threaded compression on COW writes 201*5a923131SAndroid Build Coastguard Worker std::optional<bool> enable_threading; 202*5a923131SAndroid Build Coastguard Worker }; 203*5a923131SAndroid Build Coastguard Worker 204*5a923131SAndroid Build Coastguard Worker class InstallPlanAction; 205*5a923131SAndroid Build Coastguard Worker 206*5a923131SAndroid Build Coastguard Worker template <> 207*5a923131SAndroid Build Coastguard Worker class ActionTraits<InstallPlanAction> { 208*5a923131SAndroid Build Coastguard Worker public: 209*5a923131SAndroid Build Coastguard Worker // Takes the install plan as input 210*5a923131SAndroid Build Coastguard Worker typedef InstallPlan InputObjectType; 211*5a923131SAndroid Build Coastguard Worker // Passes the install plan as output 212*5a923131SAndroid Build Coastguard Worker typedef InstallPlan OutputObjectType; 213*5a923131SAndroid Build Coastguard Worker }; 214*5a923131SAndroid Build Coastguard Worker 215*5a923131SAndroid Build Coastguard Worker // Basic action that only receives and sends Install Plans. 216*5a923131SAndroid Build Coastguard Worker // Can be used to construct an Install Plan to send to any other Action that 217*5a923131SAndroid Build Coastguard Worker // accept an InstallPlan. 218*5a923131SAndroid Build Coastguard Worker class InstallPlanAction : public Action<InstallPlanAction> { 219*5a923131SAndroid Build Coastguard Worker public: InstallPlanAction()220*5a923131SAndroid Build Coastguard Worker InstallPlanAction() {} InstallPlanAction(const InstallPlan & install_plan)221*5a923131SAndroid Build Coastguard Worker explicit InstallPlanAction(const InstallPlan& install_plan) 222*5a923131SAndroid Build Coastguard Worker : install_plan_(install_plan) {} 223*5a923131SAndroid Build Coastguard Worker PerformAction()224*5a923131SAndroid Build Coastguard Worker void PerformAction() override { 225*5a923131SAndroid Build Coastguard Worker if (HasOutputPipe()) { 226*5a923131SAndroid Build Coastguard Worker SetOutputObject(install_plan_); 227*5a923131SAndroid Build Coastguard Worker } 228*5a923131SAndroid Build Coastguard Worker processor_->ActionComplete(this, ErrorCode::kSuccess); 229*5a923131SAndroid Build Coastguard Worker } 230*5a923131SAndroid Build Coastguard Worker install_plan()231*5a923131SAndroid Build Coastguard Worker InstallPlan* install_plan() { return &install_plan_; } 232*5a923131SAndroid Build Coastguard Worker StaticType()233*5a923131SAndroid Build Coastguard Worker static std::string StaticType() { return "InstallPlanAction"; } Type()234*5a923131SAndroid Build Coastguard Worker std::string Type() const override { return StaticType(); } 235*5a923131SAndroid Build Coastguard Worker 236*5a923131SAndroid Build Coastguard Worker typedef ActionTraits<InstallPlanAction>::InputObjectType InputObjectType; 237*5a923131SAndroid Build Coastguard Worker typedef ActionTraits<InstallPlanAction>::OutputObjectType OutputObjectType; 238*5a923131SAndroid Build Coastguard Worker 239*5a923131SAndroid Build Coastguard Worker protected: 240*5a923131SAndroid Build Coastguard Worker InstallPlan install_plan_; 241*5a923131SAndroid Build Coastguard Worker 242*5a923131SAndroid Build Coastguard Worker private: 243*5a923131SAndroid Build Coastguard Worker DISALLOW_COPY_AND_ASSIGN(InstallPlanAction); 244*5a923131SAndroid Build Coastguard Worker }; 245*5a923131SAndroid Build Coastguard Worker 246*5a923131SAndroid Build Coastguard Worker } // namespace chromeos_update_engine 247*5a923131SAndroid Build Coastguard Worker 248*5a923131SAndroid Build Coastguard Worker #endif // UPDATE_ENGINE_PAYLOAD_CONSUMER_INSTALL_PLAN_H_ 249