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