1aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// 2aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// Copyright (C) 2011 The Android Open Source Project 3aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// 4aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// Licensed under the Apache License, Version 2.0 (the "License"); 5aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// you may not use this file except in compliance with the License. 6aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// You may obtain a copy of the License at 7aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// 8aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// http://www.apache.org/licenses/LICENSE-2.0 9aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// 10aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// Unless required by applicable law or agreed to in writing, software 11aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// distributed under the License is distributed on an "AS IS" BASIS, 12aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// See the License for the specific language governing permissions and 14aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// limitations under the License. 15aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// 163defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com 1739910dcd1d68987ccee7c3031dc269233a8490bbAlex Deymo#ifndef UPDATE_ENGINE_PAYLOAD_CONSUMER_INSTALL_PLAN_H_ 1839910dcd1d68987ccee7c3031dc269233a8490bbAlex Deymo#define UPDATE_ENGINE_PAYLOAD_CONSUMER_INSTALL_PLAN_H_ 193defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com 203defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com#include <string> 21698d04196deec8374ff148291db0afc7fec9cdccDarin Petkov#include <vector> 22698d04196deec8374ff148291db0afc7fec9cdccDarin Petkov 2305735a1879a553153458aae0a25fa5d42e3e408fBen Chan#include <base/macros.h> 243f39d5cc753905874d8d93bef94f857b8808f19eAlex Vakulenko#include <brillo/secure_blob.h> 253defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com 2639910dcd1d68987ccee7c3031dc269233a8490bbAlex Deymo#include "update_engine/common/action.h" 2739910dcd1d68987ccee7c3031dc269233a8490bbAlex Deymo#include "update_engine/common/boot_control_interface.h" 28d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa 293defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com// InstallPlan is a simple struct that contains relevant info for many 303defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com// parts of the update system about the install that should happen. 313defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.comnamespace chromeos_update_engine { 323defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com 3364d9878470aa7b388e971862181daf6260851602Alex Deymoenum class InstallPayloadType { 3464d9878470aa7b388e971862181daf6260851602Alex Deymo kUnknown, 3564d9878470aa7b388e971862181daf6260851602Alex Deymo kFull, 3664d9878470aa7b388e971862181daf6260851602Alex Deymo kDelta, 3764d9878470aa7b388e971862181daf6260851602Alex Deymo}; 3864d9878470aa7b388e971862181daf6260851602Alex Deymo 3964d9878470aa7b388e971862181daf6260851602Alex Deymostd::string InstallPayloadTypeToString(InstallPayloadType type); 4064d9878470aa7b388e971862181daf6260851602Alex Deymo 413defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.comstruct InstallPlan { 42763e7dbaac735da0ae802933a1015b6b7874bce2Alex Deymo InstallPlan() = default; 43ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan 44ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan bool operator==(const InstallPlan& that) const; 45ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan bool operator!=(const InstallPlan& that) const; 46ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan 47ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan void Dump() const; 483defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com 49e5e5fe926e9ea45b1a381af1bee91a86643ffd72Alex Deymo // Load the |source_path| and |target_path| of all |partitions| based on the 50e5e5fe926e9ea45b1a381af1bee91a86643ffd72Alex Deymo // |source_slot| and |target_slot| if available. Returns whether it succeeded 51e5e5fe926e9ea45b1a381af1bee91a86643ffd72Alex Deymo // to load all the partitions for the valid slots. 52706a5abae125b8f5ba58a9b7e1e51570bbaa2089Alex Deymo bool LoadPartitionsFromSlots(BootControlInterface* boot_control); 53763e7dbaac735da0ae802933a1015b6b7874bce2Alex Deymo 54763e7dbaac735da0ae802933a1015b6b7874bce2Alex Deymo bool is_resume{false}; 553defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com std::string download_url; // url to download from 56fb1020e30511825c1c39f3764f07ef237a6f668eChris Sosa std::string version; // version we are installing. 5751dcf260754837962dd22db3b7babee181471e7dJay Srinivasan 580affc2c099fac47b999ba39f8f1bacb418e65a97Sen Jiang struct Payload { 590affc2c099fac47b999ba39f8f1bacb418e65a97Sen Jiang uint64_t size = 0; // size of the payload 600affc2c099fac47b999ba39f8f1bacb418e65a97Sen Jiang uint64_t metadata_size = 0; // size of the metadata 610affc2c099fac47b999ba39f8f1bacb418e65a97Sen Jiang std::string metadata_signature; // signature of the metadata in base64 620affc2c099fac47b999ba39f8f1bacb418e65a97Sen Jiang brillo::Blob hash; // SHA256 hash of the payload 63cdd5206c6507fa5c70344c269053d30777f7d674Sen Jiang InstallPayloadType type{InstallPayloadType::kUnknown}; 645ae865b431cc041feed82f1db28a38e99dbd631fSen Jiang // Only download manifest and fill in partitions in install plan without 655ae865b431cc041feed82f1db28a38e99dbd631fSen Jiang // apply the payload if true. Will be set by DownloadAction when resuming 665ae865b431cc041feed82f1db28a38e99dbd631fSen Jiang // multi-payload. 675ae865b431cc041feed82f1db28a38e99dbd631fSen Jiang bool already_applied = false; 680affc2c099fac47b999ba39f8f1bacb418e65a97Sen Jiang 690affc2c099fac47b999ba39f8f1bacb418e65a97Sen Jiang bool operator==(const Payload& that) const { 700affc2c099fac47b999ba39f8f1bacb418e65a97Sen Jiang return size == that.size && metadata_size == that.metadata_size && 715ae865b431cc041feed82f1db28a38e99dbd631fSen Jiang metadata_signature == that.metadata_signature && 72cdd5206c6507fa5c70344c269053d30777f7d674Sen Jiang hash == that.hash && type == that.type && 73cdd5206c6507fa5c70344c269053d30777f7d674Sen Jiang already_applied == that.already_applied; 740affc2c099fac47b999ba39f8f1bacb418e65a97Sen Jiang } 750affc2c099fac47b999ba39f8f1bacb418e65a97Sen Jiang }; 760affc2c099fac47b999ba39f8f1bacb418e65a97Sen Jiang std::vector<Payload> payloads; 77763e7dbaac735da0ae802933a1015b6b7874bce2Alex Deymo 78763e7dbaac735da0ae802933a1015b6b7874bce2Alex Deymo // The partition slots used for the update. 79763e7dbaac735da0ae802933a1015b6b7874bce2Alex Deymo BootControlInterface::Slot source_slot{BootControlInterface::kInvalidSlot}; 80763e7dbaac735da0ae802933a1015b6b7874bce2Alex Deymo BootControlInterface::Slot target_slot{BootControlInterface::kInvalidSlot}; 81763e7dbaac735da0ae802933a1015b6b7874bce2Alex Deymo 82e5e5fe926e9ea45b1a381af1bee91a86643ffd72Alex Deymo // The vector below is used for partition verification. The flow is: 833aefa8634c9e9f31b9fdae5a57444c70c2f03928Darin Petkov // 84fef85fd9ece49941db274559a938fe8b2c5157bfSen Jiang // 1. DownloadAction fills in the expected source and target partition sizes 85fef85fd9ece49941db274559a938fe8b2c5157bfSen Jiang // and hashes based on the manifest. 863aefa8634c9e9f31b9fdae5a57444c70c2f03928Darin Petkov // 87fef85fd9ece49941db274559a938fe8b2c5157bfSen Jiang // 2. FilesystemVerifierAction computes and verifies the partition sizes and 88fef85fd9ece49941db274559a938fe8b2c5157bfSen Jiang // hashes against the expected values. 89e5e5fe926e9ea45b1a381af1bee91a86643ffd72Alex Deymo struct Partition { 90e5e5fe926e9ea45b1a381af1bee91a86643ffd72Alex Deymo bool operator==(const Partition& that) const; 91e5e5fe926e9ea45b1a381af1bee91a86643ffd72Alex Deymo 92e5e5fe926e9ea45b1a381af1bee91a86643ffd72Alex Deymo // The name of the partition. 93e5e5fe926e9ea45b1a381af1bee91a86643ffd72Alex Deymo std::string name; 94e5e5fe926e9ea45b1a381af1bee91a86643ffd72Alex Deymo 95e5e5fe926e9ea45b1a381af1bee91a86643ffd72Alex Deymo std::string source_path; 96e5e5fe926e9ea45b1a381af1bee91a86643ffd72Alex Deymo uint64_t source_size{0}; 973f39d5cc753905874d8d93bef94f857b8808f19eAlex Vakulenko brillo::Blob source_hash; 98e5e5fe926e9ea45b1a381af1bee91a86643ffd72Alex Deymo 99e5e5fe926e9ea45b1a381af1bee91a86643ffd72Alex Deymo std::string target_path; 100e5e5fe926e9ea45b1a381af1bee91a86643ffd72Alex Deymo uint64_t target_size{0}; 1013f39d5cc753905874d8d93bef94f857b8808f19eAlex Vakulenko brillo::Blob target_hash; 102e5e5fe926e9ea45b1a381af1bee91a86643ffd72Alex Deymo 103390efedcb7e17587da765b6d682077cb7fa46ee1Alex Deymo // Whether we should run the postinstall script from this partition and the 104390efedcb7e17587da765b6d682077cb7fa46ee1Alex Deymo // postinstall parameters. 105e5e5fe926e9ea45b1a381af1bee91a86643ffd72Alex Deymo bool run_postinstall{false}; 106390efedcb7e17587da765b6d682077cb7fa46ee1Alex Deymo std::string postinstall_path; 107390efedcb7e17587da765b6d682077cb7fa46ee1Alex Deymo std::string filesystem_type; 1085b91c6b141970c2b0095775a61e3f941417aa1ffAlex Deymo bool postinstall_optional{false}; 109e5e5fe926e9ea45b1a381af1bee91a86643ffd72Alex Deymo }; 110e5e5fe926e9ea45b1a381af1bee91a86643ffd72Alex Deymo std::vector<Partition> partitions; 1113defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com 112738fdf37c15284b60dac703408b8de19eef9c6a3Jay Srinivasan // True if payload hash checks are mandatory based on the system state and 113738fdf37c15284b60dac703408b8de19eef9c6a3Jay Srinivasan // the Omaha response. 114763e7dbaac735da0ae802933a1015b6b7874bce2Alex Deymo bool hash_checks_mandatory{false}; 115738fdf37c15284b60dac703408b8de19eef9c6a3Jay Srinivasan 116ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan // True if Powerwash is required on reboot after applying the payload. 117ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan // False otherwise. 118763e7dbaac735da0ae802933a1015b6b7874bce2Alex Deymo bool powerwash_required{false}; 119e7f8917f378773fbfee0b2d21f1cb6b3ba8bdcabDavid Zeuthen 120e7f8917f378773fbfee0b2d21f1cb6b3ba8bdcabDavid Zeuthen // If not blank, a base-64 encoded representation of the PEM-encoded 121e7f8917f378773fbfee0b2d21f1cb6b3ba8bdcabDavid Zeuthen // public key in the response. 122e7f8917f378773fbfee0b2d21f1cb6b3ba8bdcabDavid Zeuthen std::string public_key_rsa; 1233defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com}; 1243defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com 125d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosaclass InstallPlanAction; 126d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa 127d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosatemplate<> 128d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosaclass ActionTraits<InstallPlanAction> { 129d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa public: 130d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa // Takes the install plan as input 131d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa typedef InstallPlan InputObjectType; 132d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa // Passes the install plan as output 133d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa typedef InstallPlan OutputObjectType; 134d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa}; 135d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa 136d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa// Basic action that only receives and sends Install Plans. 137d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa// Can be used to construct an Install Plan to send to any other Action that 138d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa// accept an InstallPlan. 139d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosaclass InstallPlanAction : public Action<InstallPlanAction> { 140d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa public: 141d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa InstallPlanAction() {} 142d2779df63aaad8b65fc5d4badee7dbc9bed7f2b6Alex Vakulenko explicit InstallPlanAction(const InstallPlan& install_plan): 143d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa install_plan_(install_plan) {} 144d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa 145610277efc6f7e5239158dfa4bb3b1021804326e0Alex Deymo void PerformAction() override { 146d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa if (HasOutputPipe()) { 147d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa SetOutputObject(install_plan_); 148d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa } 149d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold processor_->ActionComplete(this, ErrorCode::kSuccess); 150d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa } 151d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa 15276a29aef71c1602d6dcec6fc7062d2162b03c9ecChris Sosa InstallPlan* install_plan() { return &install_plan_; } 15376a29aef71c1602d6dcec6fc7062d2162b03c9ecChris Sosa 15476a29aef71c1602d6dcec6fc7062d2162b03c9ecChris Sosa static std::string StaticType() { return "InstallPlanAction"; } 155610277efc6f7e5239158dfa4bb3b1021804326e0Alex Deymo std::string Type() const override { return StaticType(); } 156d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa 157d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa typedef ActionTraits<InstallPlanAction>::InputObjectType InputObjectType; 158d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa typedef ActionTraits<InstallPlanAction>::OutputObjectType OutputObjectType; 159d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa 160d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa private: 161d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa InstallPlan install_plan_; 162d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa 163d2779df63aaad8b65fc5d4badee7dbc9bed7f2b6Alex Vakulenko DISALLOW_COPY_AND_ASSIGN(InstallPlanAction); 164d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa}; 165d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa 1663defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com} // namespace chromeos_update_engine 1673defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com 16839910dcd1d68987ccee7c3031dc269233a8490bbAlex Deymo#endif // UPDATE_ENGINE_PAYLOAD_CONSUMER_INSTALL_PLAN_H_ 169