1 #pragma once 2 3 #include "item_updater.hpp" 4 5 #include <string> 6 7 namespace openpower 8 { 9 namespace software 10 { 11 namespace updater 12 { 13 14 class GardResetUbi : public GardReset 15 { 16 public: 17 using GardReset::GardReset; 18 virtual ~GardResetUbi() = default; 19 20 protected: 21 /** 22 * @brief GUARD factory reset - clears the PNOR GUARD partition. 23 */ 24 void reset() override; 25 }; 26 27 /** @class ItemUpdaterUbi 28 * @brief Manages the activation of the host version items for ubi layout 29 */ 30 class ItemUpdaterUbi : public ItemUpdater 31 { 32 public: ItemUpdaterUbi(sdbusplus::bus_t & bus,const std::string & path)33 ItemUpdaterUbi(sdbusplus::bus_t& bus, const std::string& path) : 34 ItemUpdater(bus, path) 35 { 36 processPNORImage(); 37 gardReset = std::make_unique<GardResetUbi>(bus, GARD_PATH); 38 volatileEnable = std::make_unique<ObjectEnable>(bus, volatilePath); 39 40 // Emit deferred signal. 41 emit_object_added(); 42 } 43 virtual ~ItemUpdaterUbi() = default; 44 45 void freePriority(uint8_t value, const std::string& versionId) override; 46 47 void processPNORImage() override; 48 49 bool erase(std::string entryId) override; 50 51 void deleteAll() override; 52 53 bool freeSpace() override; 54 55 bool isVersionFunctional(const std::string& versionId) override; 56 57 /** @brief Determine the software version id 58 * from the symlink target (e.g. /media/ro-2a1022fe). 59 * 60 * @param[in] symlinkPath - The path of the symlink. 61 * @param[out] id - The version id as a string. 62 */ 63 static std::string determineId(const std::string& symlinkPath); 64 65 private: 66 std::unique_ptr<Activation> createActivationObject( 67 const std::string& path, const std::string& versionId, 68 const std::string& extVersion, 69 sdbusplus::xyz::openbmc_project::Software::server::Activation:: 70 Activations activationStatus, 71 AssociationList& assocs) override; 72 73 std::unique_ptr<Version> createVersionObject( 74 const std::string& objPath, const std::string& versionId, 75 const std::string& versionString, 76 sdbusplus::xyz::openbmc_project::Software::server::Version:: 77 VersionPurpose versionPurpose, 78 const std::string& filePath) override; 79 80 bool validateImage(const std::string& path) override; 81 82 /** @brief Host factory reset - clears PNOR partitions for each 83 * Activation D-Bus object */ 84 void reset() override; 85 86 /** 87 * @brief Validates the presence of SquashFS image in the image dir. 88 * 89 * @param[in] filePath - The path to the SquashFS image. 90 * @param[out] result - 0 --> if validation was successful 91 * - -1--> Otherwise 92 */ 93 static int validateSquashFSImage(const std::string& filePath); 94 95 /** @brief Clears read only PNOR partition for 96 * given Activation D-Bus object 97 * 98 * @param[in] versionId - The id of the ro partition to remove. 99 */ 100 void removeReadOnlyPartition(const std::string& versionId); 101 102 /** @brief Clears read write PNOR partition for 103 * given Activation D-Bus object 104 * 105 * @param[in] versionId - The id of the rw partition to remove. 106 */ 107 void removeReadWritePartition(const std::string& versionId); 108 109 /** @brief Clears preserved PNOR partition */ 110 void removePreservedPartition(); 111 }; 112 113 } // namespace updater 114 } // namespace software 115 } // namespace openpower 116