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