1 #pragma once 2 3 #include <sdbusplus/server.hpp> 4 #include "activation.hpp" 5 #include "version.hpp" 6 #include <xyz/openbmc_project/Common/FactoryReset/server.hpp> 7 #include <xyz/openbmc_project/Control/FieldMode/server.hpp> 8 9 namespace phosphor 10 { 11 namespace software 12 { 13 namespace updater 14 { 15 16 using ItemUpdaterInherit = sdbusplus::server::object::object< 17 sdbusplus::xyz::openbmc_project::Common::server::FactoryReset, 18 sdbusplus::xyz::openbmc_project::Control::server::FieldMode>; 19 20 namespace MatchRules = sdbusplus::bus::match::rules; 21 22 /** @class ItemUpdater 23 * @brief Manages the activation of the BMC version items. 24 */ 25 class ItemUpdater : public ItemUpdaterInherit 26 { 27 public: 28 /* 29 * @brief Types of Activation status for image validation. 30 */ 31 enum class ActivationStatus 32 { 33 ready, 34 invalid, 35 active 36 }; 37 38 /** @brief Constructs ItemUpdater 39 * 40 * @param[in] bus - The Dbus bus object 41 */ 42 ItemUpdater(sdbusplus::bus::bus& bus, const std::string& path) : 43 ItemUpdaterInherit(bus, path.c_str(), false), 44 bus(bus), 45 versionMatch( 46 bus, 47 MatchRules::interfacesAdded() + 48 MatchRules::path("/xyz/openbmc_project/software"), 49 std::bind( 50 std::mem_fn(&ItemUpdater::createActivation), 51 this, 52 std::placeholders::_1)) 53 { 54 processBMCImage(); 55 restoreFieldModeStatus(); 56 emit_object_added(); 57 }; 58 59 /** @brief Sets the given priority free by incrementing 60 * any existing priority with the same value by 1 61 * 62 * @param[in] value - The priority that needs to be set free. 63 * 64 * @return None 65 */ 66 void freePriority(uint8_t value); 67 68 /** 69 * @brief Create and populate the active BMC Version. 70 */ 71 void processBMCImage(); 72 73 /** 74 * @brief Erase specified entry d-bus object 75 * if Action property is not set to Active 76 * 77 * @param[in] entryId - unique identifier of the entry 78 */ 79 void erase(std::string entryId); 80 81 private: 82 /** @brief Callback function for Software.Version match. 83 * @details Creates an Activation dbus object. 84 * 85 * @param[in] msg - Data associated with subscribed signal 86 */ 87 void createActivation(sdbusplus::message::message& msg); 88 89 /** 90 * @brief Validates the presence of SquashFS iamge in the image dir. 91 * 92 * @param[in] filePath - The path to the image dir. 93 * @param[out] result - ActivationStatus Enum. 94 * ready if validation was successful. 95 * invalid if validation fail. 96 * active if image is the current version. 97 * 98 */ 99 ActivationStatus validateSquashFSImage(const std::string& filePath); 100 101 /** @brief BMC factory reset - marks the read-write partition for 102 * recreation upon reboot. */ 103 void reset() override; 104 105 /** 106 * @brief Enables field mode, if value=true. 107 * 108 * @param[in] value - If true, enables field mode. 109 * @param[out] result - Returns the current state of field mode. 110 * 111 */ 112 bool fieldModeEnabled(bool value) override; 113 114 /** @brief Restores field mode status on reboot. */ 115 void restoreFieldModeStatus(); 116 117 /** @brief Persistent sdbusplus DBus bus connection. */ 118 sdbusplus::bus::bus& bus; 119 120 /** @brief Persistent map of Activation dbus objects and their 121 * version id */ 122 std::map<std::string, std::unique_ptr<Activation>> activations; 123 124 /** @brief Persistent map of Version dbus objects and their 125 * version id */ 126 std::map<std::string, std::unique_ptr<phosphor::software:: 127 manager::Version>> versions; 128 129 /** @brief sdbusplus signal match for Software.Version */ 130 sdbusplus::bus::match_t versionMatch; 131 132 /** @brief Clears read only partition for 133 * given Activation dbus object. 134 * 135 * @param[in] versionId - The version id. 136 */ 137 void removeReadOnlyPartition(std::string versionId); 138 139 /** @brief Clears read write partition for 140 * given Activation dbus object. 141 * 142 * @param[in] versionId - The version id. 143 */ 144 void removeReadWritePartition(std::string versionId); 145 146 }; 147 148 149 150 } // namespace updater 151 } // namespace software 152 } // namespace phosphor 153