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