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}; 5564d9878470aa7b388e971862181daf6260851602Alex Deymo InstallPayloadType payload_type{InstallPayloadType::kUnknown}; 563defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com std::string download_url; // url to download from 57fb1020e30511825c1c39f3764f07ef237a6f668eChris Sosa std::string version; // version we are installing. 5851dcf260754837962dd22db3b7babee181471e7dJay Srinivasan 59763e7dbaac735da0ae802933a1015b6b7874bce2Alex Deymo uint64_t payload_size{0}; // size of the payload 60763e7dbaac735da0ae802933a1015b6b7874bce2Alex Deymo std::string payload_hash; // SHA256 hash of the payload 61763e7dbaac735da0ae802933a1015b6b7874bce2Alex Deymo uint64_t metadata_size{0}; // size of the metadata 62f4318709ff5bd808a5fb8dd360acd9b66253a24eJay Srinivasan std::string metadata_signature; // signature of the metadata 63763e7dbaac735da0ae802933a1015b6b7874bce2Alex Deymo 64763e7dbaac735da0ae802933a1015b6b7874bce2Alex Deymo // The partition slots used for the update. 65763e7dbaac735da0ae802933a1015b6b7874bce2Alex Deymo BootControlInterface::Slot source_slot{BootControlInterface::kInvalidSlot}; 66763e7dbaac735da0ae802933a1015b6b7874bce2Alex Deymo BootControlInterface::Slot target_slot{BootControlInterface::kInvalidSlot}; 67763e7dbaac735da0ae802933a1015b6b7874bce2Alex Deymo 68e5e5fe926e9ea45b1a381af1bee91a86643ffd72Alex Deymo // The vector below is used for partition verification. The flow is: 693aefa8634c9e9f31b9fdae5a57444c70c2f03928Darin Petkov // 70fef85fd9ece49941db274559a938fe8b2c5157bfSen Jiang // 1. DownloadAction fills in the expected source and target partition sizes 71fef85fd9ece49941db274559a938fe8b2c5157bfSen Jiang // and hashes based on the manifest. 723aefa8634c9e9f31b9fdae5a57444c70c2f03928Darin Petkov // 73fef85fd9ece49941db274559a938fe8b2c5157bfSen Jiang // 2. FilesystemVerifierAction computes and verifies the partition sizes and 74fef85fd9ece49941db274559a938fe8b2c5157bfSen Jiang // hashes against the expected values. 75e5e5fe926e9ea45b1a381af1bee91a86643ffd72Alex Deymo struct Partition { 76e5e5fe926e9ea45b1a381af1bee91a86643ffd72Alex Deymo bool operator==(const Partition& that) const; 77e5e5fe926e9ea45b1a381af1bee91a86643ffd72Alex Deymo 78e5e5fe926e9ea45b1a381af1bee91a86643ffd72Alex Deymo // The name of the partition. 79e5e5fe926e9ea45b1a381af1bee91a86643ffd72Alex Deymo std::string name; 80e5e5fe926e9ea45b1a381af1bee91a86643ffd72Alex Deymo 81e5e5fe926e9ea45b1a381af1bee91a86643ffd72Alex Deymo std::string source_path; 82e5e5fe926e9ea45b1a381af1bee91a86643ffd72Alex Deymo uint64_t source_size{0}; 833f39d5cc753905874d8d93bef94f857b8808f19eAlex Vakulenko brillo::Blob source_hash; 84e5e5fe926e9ea45b1a381af1bee91a86643ffd72Alex Deymo 85e5e5fe926e9ea45b1a381af1bee91a86643ffd72Alex Deymo std::string target_path; 86e5e5fe926e9ea45b1a381af1bee91a86643ffd72Alex Deymo uint64_t target_size{0}; 873f39d5cc753905874d8d93bef94f857b8808f19eAlex Vakulenko brillo::Blob target_hash; 88e5e5fe926e9ea45b1a381af1bee91a86643ffd72Alex Deymo 89390efedcb7e17587da765b6d682077cb7fa46ee1Alex Deymo // Whether we should run the postinstall script from this partition and the 90390efedcb7e17587da765b6d682077cb7fa46ee1Alex Deymo // postinstall parameters. 91e5e5fe926e9ea45b1a381af1bee91a86643ffd72Alex Deymo bool run_postinstall{false}; 92390efedcb7e17587da765b6d682077cb7fa46ee1Alex Deymo std::string postinstall_path; 93390efedcb7e17587da765b6d682077cb7fa46ee1Alex Deymo std::string filesystem_type; 945b91c6b141970c2b0095775a61e3f941417aa1ffAlex Deymo bool postinstall_optional{false}; 95e5e5fe926e9ea45b1a381af1bee91a86643ffd72Alex Deymo }; 96e5e5fe926e9ea45b1a381af1bee91a86643ffd72Alex Deymo std::vector<Partition> partitions; 973defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com 98738fdf37c15284b60dac703408b8de19eef9c6a3Jay Srinivasan // True if payload hash checks are mandatory based on the system state and 99738fdf37c15284b60dac703408b8de19eef9c6a3Jay Srinivasan // the Omaha response. 100763e7dbaac735da0ae802933a1015b6b7874bce2Alex Deymo bool hash_checks_mandatory{false}; 101738fdf37c15284b60dac703408b8de19eef9c6a3Jay Srinivasan 102ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan // True if Powerwash is required on reboot after applying the payload. 103ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan // False otherwise. 104763e7dbaac735da0ae802933a1015b6b7874bce2Alex Deymo bool powerwash_required{false}; 105e7f8917f378773fbfee0b2d21f1cb6b3ba8bdcabDavid Zeuthen 106e7f8917f378773fbfee0b2d21f1cb6b3ba8bdcabDavid Zeuthen // If not blank, a base-64 encoded representation of the PEM-encoded 107e7f8917f378773fbfee0b2d21f1cb6b3ba8bdcabDavid Zeuthen // public key in the response. 108e7f8917f378773fbfee0b2d21f1cb6b3ba8bdcabDavid Zeuthen std::string public_key_rsa; 1093defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com}; 1103defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com 111d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosaclass InstallPlanAction; 112d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa 113d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosatemplate<> 114d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosaclass ActionTraits<InstallPlanAction> { 115d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa public: 116d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa // Takes the install plan as input 117d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa typedef InstallPlan InputObjectType; 118d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa // Passes the install plan as output 119d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa typedef InstallPlan OutputObjectType; 120d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa}; 121d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa 122d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa// Basic action that only receives and sends Install Plans. 123d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa// Can be used to construct an Install Plan to send to any other Action that 124d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa// accept an InstallPlan. 125d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosaclass InstallPlanAction : public Action<InstallPlanAction> { 126d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa public: 127d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa InstallPlanAction() {} 128d2779df63aaad8b65fc5d4badee7dbc9bed7f2b6Alex Vakulenko explicit InstallPlanAction(const InstallPlan& install_plan): 129d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa install_plan_(install_plan) {} 130d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa 131610277efc6f7e5239158dfa4bb3b1021804326e0Alex Deymo void PerformAction() override { 132d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa if (HasOutputPipe()) { 133d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa SetOutputObject(install_plan_); 134d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa } 135d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold processor_->ActionComplete(this, ErrorCode::kSuccess); 136d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa } 137d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa 13876a29aef71c1602d6dcec6fc7062d2162b03c9ecChris Sosa InstallPlan* install_plan() { return &install_plan_; } 13976a29aef71c1602d6dcec6fc7062d2162b03c9ecChris Sosa 14076a29aef71c1602d6dcec6fc7062d2162b03c9ecChris Sosa static std::string StaticType() { return "InstallPlanAction"; } 141610277efc6f7e5239158dfa4bb3b1021804326e0Alex Deymo std::string Type() const override { return StaticType(); } 142d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa 143d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa typedef ActionTraits<InstallPlanAction>::InputObjectType InputObjectType; 144d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa typedef ActionTraits<InstallPlanAction>::OutputObjectType OutputObjectType; 145d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa 146d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa private: 147d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa InstallPlan install_plan_; 148d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa 149d2779df63aaad8b65fc5d4badee7dbc9bed7f2b6Alex Vakulenko DISALLOW_COPY_AND_ASSIGN(InstallPlanAction); 150d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa}; 151d317e40be46e1b69f624a8165472c99fe6346a1eChris Sosa 1523defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com} // namespace chromeos_update_engine 1533defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com 15439910dcd1d68987ccee7c3031dc269233a8490bbAlex Deymo#endif // UPDATE_ENGINE_PAYLOAD_CONSUMER_INSTALL_PLAN_H_ 155