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