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 GARD factory reset - clears the PNOR GARD 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: 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> 74 createVersionObject(const std::string& objPath, 75 const std::string& versionId, 76 const std::string& versionString, 77 sdbusplus::xyz::openbmc_project::Software::server:: 78 Version::VersionPurpose versionPurpose, 79 const std::string& filePath) override; 80 81 bool validateImage(const std::string& path) override; 82 83 /** @brief Host factory reset - clears PNOR partitions for each 84 * Activation D-Bus object */ 85 void reset() override; 86 87 /** 88 * @brief Validates the presence of SquashFS image in the image dir. 89 * 90 * @param[in] filePath - The path to the SquashFS image. 91 * @param[out] result - 0 --> if validation was successful 92 * - -1--> Otherwise 93 */ 94 static int validateSquashFSImage(const std::string& filePath); 95 96 /** @brief Clears read only PNOR partition for 97 * given Activation D-Bus object 98 * 99 * @param[in] versionId - The id of the ro partition to remove. 100 */ 101 void removeReadOnlyPartition(const std::string& versionId); 102 103 /** @brief Clears read write PNOR partition for 104 * given Activation D-Bus object 105 * 106 * @param[in] versionId - The id of the rw partition to remove. 107 */ 108 void removeReadWritePartition(const std::string& versionId); 109 110 /** @brief Clears preserved PNOR partition */ 111 void removePreservedPartition(); 112 }; 113 114 } // namespace updater 115 } // namespace software 116 } // namespace openpower 117