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 | |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 69 | private: |
| 70 | /** @brief Callback function for Software.Version match. |
| 71 | * @details Creates an Activation dbus object. |
| 72 | * |
| 73 | * @param[in] msg - Data associated with subscribed signal |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 74 | */ |
Patrick Williams | e75d10f | 2017-05-30 16:56:32 -0500 | [diff] [blame] | 75 | void createActivation(sdbusplus::message::message& msg); |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 76 | |
Saqib Khan | 35e83f3 | 2017-05-22 11:37:32 -0500 | [diff] [blame] | 77 | /** |
| 78 | * @brief Validates the presence of SquashFS iamge in the image dir. |
| 79 | * |
Saqib Khan | 19177d3 | 2017-06-20 08:11:49 -0500 | [diff] [blame] | 80 | * @param[in] filePath - The path to the image dir. |
Saqib Khan | 35e83f3 | 2017-05-22 11:37:32 -0500 | [diff] [blame] | 81 | * @param[out] result - ActivationStatus Enum. |
| 82 | * ready if validation was successful. |
| 83 | * invalid if validation fail. |
| 84 | * active if image is the current version. |
| 85 | * |
| 86 | */ |
Saqib Khan | 19177d3 | 2017-06-20 08:11:49 -0500 | [diff] [blame] | 87 | ActivationStatus validateSquashFSImage(const std::string& filePath); |
Saqib Khan | 35e83f3 | 2017-05-22 11:37:32 -0500 | [diff] [blame] | 88 | |
Michael Tritz | 37a5904 | 2017-07-12 13:44:53 -0500 | [diff] [blame] | 89 | /** @brief BMC factory reset - marks the read-write partition for |
| 90 | * recreation upon reboot. */ |
| 91 | void reset() override; |
| 92 | |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 93 | /** @brief Persistent sdbusplus DBus bus connection. */ |
| 94 | sdbusplus::bus::bus& bus; |
| 95 | |
| 96 | /** @brief Persistent map of Activation dbus objects and their |
| 97 | * version id */ |
| 98 | std::map<std::string, std::unique_ptr<Activation>> activations; |
| 99 | |
Saqib Khan | 705f1bf | 2017-06-09 23:58:38 -0500 | [diff] [blame] | 100 | /** @brief Persistent map of Version dbus objects and their |
| 101 | * version id */ |
| 102 | std::map<std::string, std::unique_ptr<phosphor::software:: |
| 103 | manager::Version>> versions; |
| 104 | |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 105 | /** @brief sdbusplus signal match for Software.Version */ |
Patrick Williams | e75d10f | 2017-05-30 16:56:32 -0500 | [diff] [blame] | 106 | sdbusplus::bus::match_t versionMatch; |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 107 | |
| 108 | }; |
| 109 | |
| 110 | |
| 111 | |
| 112 | } // namespace updater |
| 113 | } // namespace software |
| 114 | } // namespace phosphor |