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> |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 7 | |
| 8 | namespace phosphor |
| 9 | { |
| 10 | namespace software |
| 11 | { |
| 12 | namespace updater |
| 13 | { |
| 14 | |
Michael Tritz | 37a5904 | 2017-07-12 13:44:53 -0500 | [diff] [blame] | 15 | using ItemUpdaterInherit = sdbusplus::server::object::object< |
| 16 | sdbusplus::xyz::openbmc_project::Common::server::FactoryReset>; |
| 17 | |
Patrick Williams | e75d10f | 2017-05-30 16:56:32 -0500 | [diff] [blame] | 18 | namespace MatchRules = sdbusplus::bus::match::rules; |
| 19 | |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 20 | /** @class ItemUpdater |
| 21 | * @brief Manages the activation of the BMC version items. |
| 22 | */ |
Michael Tritz | 37a5904 | 2017-07-12 13:44:53 -0500 | [diff] [blame] | 23 | class ItemUpdater : public ItemUpdaterInherit |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 24 | { |
| 25 | public: |
Saqib Khan | 35e83f3 | 2017-05-22 11:37:32 -0500 | [diff] [blame] | 26 | /* |
| 27 | * @brief Types of Activation status for image validation. |
| 28 | */ |
| 29 | enum class ActivationStatus |
| 30 | { |
| 31 | ready, |
| 32 | invalid, |
| 33 | active |
| 34 | }; |
| 35 | |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 36 | /** @brief Constructs ItemUpdater |
| 37 | * |
| 38 | * @param[in] bus - The Dbus bus object |
| 39 | */ |
Michael Tritz | 37a5904 | 2017-07-12 13:44:53 -0500 | [diff] [blame] | 40 | ItemUpdater(sdbusplus::bus::bus& bus, const std::string& path) : |
| 41 | ItemUpdaterInherit(bus, path.c_str()), |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 42 | bus(bus), |
| 43 | versionMatch( |
| 44 | bus, |
Patrick Williams | e75d10f | 2017-05-30 16:56:32 -0500 | [diff] [blame] | 45 | MatchRules::interfacesAdded() + |
| 46 | MatchRules::path("/xyz/openbmc_project/software"), |
| 47 | std::bind( |
| 48 | std::mem_fn(&ItemUpdater::createActivation), |
| 49 | this, |
| 50 | std::placeholders::_1)) |
| 51 | { |
Saqib Khan | ba23988 | 2017-05-26 08:41:54 -0500 | [diff] [blame] | 52 | processBMCImage(); |
Patrick Williams | e75d10f | 2017-05-30 16:56:32 -0500 | [diff] [blame] | 53 | }; |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 54 | |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 55 | /** @brief Sets the given priority free by incrementing |
| 56 | * any existing priority with the same value by 1 |
| 57 | * |
| 58 | * @param[in] value - The priority that needs to be set free. |
| 59 | * |
| 60 | * @return None |
| 61 | */ |
| 62 | void freePriority(uint8_t value); |
| 63 | |
Saqib Khan | ba23988 | 2017-05-26 08:41:54 -0500 | [diff] [blame] | 64 | /** |
| 65 | * @brief Create and populate the active BMC Version. |
| 66 | */ |
| 67 | void processBMCImage(); |
| 68 | |
Leonel Gonzalez | 3526ef7 | 2017-07-07 14:38:25 -0500 | [diff] [blame] | 69 | /** |
| 70 | * @brief Erase specified entry d-bus object |
| 71 | * if Action property is not set to Active |
| 72 | * |
| 73 | * @param[in] entryId - unique identifier of the entry |
| 74 | */ |
| 75 | void erase(std::string entryId); |
| 76 | |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 77 | private: |
| 78 | /** @brief Callback function for Software.Version match. |
| 79 | * @details Creates an Activation dbus object. |
| 80 | * |
| 81 | * @param[in] msg - Data associated with subscribed signal |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 82 | */ |
Patrick Williams | e75d10f | 2017-05-30 16:56:32 -0500 | [diff] [blame] | 83 | void createActivation(sdbusplus::message::message& msg); |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 84 | |
Saqib Khan | 35e83f3 | 2017-05-22 11:37:32 -0500 | [diff] [blame] | 85 | /** |
| 86 | * @brief Validates the presence of SquashFS iamge in the image dir. |
| 87 | * |
Saqib Khan | 19177d3 | 2017-06-20 08:11:49 -0500 | [diff] [blame] | 88 | * @param[in] filePath - The path to the image dir. |
Saqib Khan | 35e83f3 | 2017-05-22 11:37:32 -0500 | [diff] [blame] | 89 | * @param[out] result - ActivationStatus Enum. |
| 90 | * ready if validation was successful. |
| 91 | * invalid if validation fail. |
| 92 | * active if image is the current version. |
| 93 | * |
| 94 | */ |
Saqib Khan | 19177d3 | 2017-06-20 08:11:49 -0500 | [diff] [blame] | 95 | ActivationStatus validateSquashFSImage(const std::string& filePath); |
Saqib Khan | 35e83f3 | 2017-05-22 11:37:32 -0500 | [diff] [blame] | 96 | |
Michael Tritz | 37a5904 | 2017-07-12 13:44:53 -0500 | [diff] [blame] | 97 | /** @brief BMC factory reset - marks the read-write partition for |
| 98 | * recreation upon reboot. */ |
| 99 | void reset() override; |
| 100 | |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 101 | /** @brief Persistent sdbusplus DBus bus connection. */ |
| 102 | sdbusplus::bus::bus& bus; |
| 103 | |
| 104 | /** @brief Persistent map of Activation dbus objects and their |
| 105 | * version id */ |
| 106 | std::map<std::string, std::unique_ptr<Activation>> activations; |
| 107 | |
Saqib Khan | 705f1bf | 2017-06-09 23:58:38 -0500 | [diff] [blame] | 108 | /** @brief Persistent map of Version dbus objects and their |
| 109 | * version id */ |
| 110 | std::map<std::string, std::unique_ptr<phosphor::software:: |
| 111 | manager::Version>> versions; |
| 112 | |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 113 | /** @brief sdbusplus signal match for Software.Version */ |
Patrick Williams | e75d10f | 2017-05-30 16:56:32 -0500 | [diff] [blame] | 114 | sdbusplus::bus::match_t versionMatch; |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 115 | |
Leonel Gonzalez | 3526ef7 | 2017-07-07 14:38:25 -0500 | [diff] [blame] | 116 | /** @brief Clears read only partition for |
| 117 | * given Activation dbus object. |
| 118 | * |
| 119 | * @param[in] versionId - The version id. |
| 120 | */ |
| 121 | void removeReadOnlyPartition(std::string versionId); |
| 122 | |
| 123 | /** @brief Clears read write partition for |
| 124 | * given Activation dbus object. |
| 125 | * |
| 126 | * @param[in] versionId - The version id. |
| 127 | */ |
| 128 | void removeReadWritePartition(std::string versionId); |
| 129 | |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 130 | }; |
| 131 | |
| 132 | |
| 133 | |
| 134 | } // namespace updater |
| 135 | } // namespace software |
| 136 | } // namespace phosphor |