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< |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [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 = |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 27 | std::vector<std::tuple<std::string, std::string, std::string>>; |
Gunnar Mills | ded875d | 2017-08-28 16:44:52 -0500 | [diff] [blame] | 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 | { |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 34 | public: |
| 35 | /* |
| 36 | * @brief Types of Activation status for image validation. |
| 37 | */ |
| 38 | enum class ActivationStatus |
| 39 | { |
| 40 | ready, |
| 41 | invalid, |
| 42 | active |
| 43 | }; |
Saqib Khan | 35e83f3 | 2017-05-22 11:37:32 -0500 | [diff] [blame] | 44 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 45 | /** @brief Constructs ItemUpdater |
| 46 | * |
| 47 | * @param[in] bus - The D-Bus bus object |
| 48 | */ |
| 49 | ItemUpdater(sdbusplus::bus::bus& bus, const std::string& path) : |
| 50 | ItemUpdaterInherit(bus, path.c_str(), false), bus(bus), |
| 51 | versionMatch(bus, |
| 52 | MatchRules::interfacesAdded() + |
| 53 | MatchRules::path("/xyz/openbmc_project/software"), |
| 54 | std::bind(std::mem_fn(&ItemUpdater::createActivation), |
| 55 | this, std::placeholders::_1)) |
| 56 | { |
| 57 | setBMCInventoryPath(); |
| 58 | processBMCImage(); |
| 59 | restoreFieldModeStatus(); |
| 60 | emit_object_added(); |
| 61 | }; |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 62 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 63 | /** @brief Sets the given priority free by incrementing |
| 64 | * any existing priority with the same value by 1 |
| 65 | * |
| 66 | * @param[in] value - The priority that needs to be set free. |
| 67 | * @param[in] versionId - The Id of the version for which we |
| 68 | * are trying to free up the priority. |
| 69 | * @return None |
| 70 | */ |
| 71 | void freePriority(uint8_t value, const std::string& versionId); |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 72 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 73 | /** |
| 74 | * @brief Create and populate the active BMC Version. |
| 75 | */ |
| 76 | void processBMCImage(); |
Saqib Khan | ba23988 | 2017-05-26 08:41:54 -0500 | [diff] [blame] | 77 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 78 | /** |
| 79 | * @brief Erase specified entry D-Bus object |
| 80 | * if Action property is not set to Active |
| 81 | * |
| 82 | * @param[in] entryId - unique identifier of the entry |
| 83 | */ |
| 84 | void erase(std::string entryId); |
Leonel Gonzalez | 3526ef7 | 2017-07-07 14:38:25 -0500 | [diff] [blame] | 85 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 86 | /** |
| 87 | * @brief Deletes all versions except for the current one |
| 88 | */ |
| 89 | void deleteAll(); |
Gunnar Mills | ded875d | 2017-08-28 16:44:52 -0500 | [diff] [blame] | 90 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 91 | /** @brief Creates an active association to the |
| 92 | * newly active software image |
| 93 | * |
| 94 | * @param[in] path - The path to create the association to. |
| 95 | */ |
| 96 | void createActiveAssociation(const std::string& path); |
Gunnar Mills | ded875d | 2017-08-28 16:44:52 -0500 | [diff] [blame] | 97 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 98 | /** @brief Removes an active association to the software image |
| 99 | * |
| 100 | * @param[in] path - The path to remove the association from. |
| 101 | */ |
| 102 | void removeActiveAssociation(const std::string& path); |
Gunnar Mills | ded875d | 2017-08-28 16:44:52 -0500 | [diff] [blame] | 103 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 104 | /** @brief Determine if the given priority is the lowest |
| 105 | * |
| 106 | * @param[in] value - The priority that needs to be checked. |
| 107 | * |
| 108 | * @return boolean corresponding to whether the given |
| 109 | * priority is lowest. |
| 110 | */ |
| 111 | bool isLowestPriority(uint8_t value); |
Saqib Khan | b9da663 | 2017-09-13 09:48:37 -0500 | [diff] [blame] | 112 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 113 | /** |
| 114 | * @brief Updates the U-Boot variables to point to the requested |
| 115 | * versionId, so that the systems boots from this version on |
| 116 | * the next reboot. |
| 117 | * |
| 118 | * @param[in] versionId - The version to point the system to boot from. |
| 119 | */ |
| 120 | void updateUbootEnvVars(const std::string& versionId); |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 121 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 122 | /** |
| 123 | * @brief Updates the uboot variables to point to BMC version with lowest |
| 124 | * priority, so that the system boots from this version on the |
| 125 | * next boot. |
| 126 | */ |
| 127 | void resetUbootEnvVars(); |
Saqib Khan | 49446ae | 2017-10-02 10:54:20 -0500 | [diff] [blame] | 128 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 129 | /** @brief Brings the total number of active BMC versions to |
| 130 | * ACTIVE_BMC_MAX_ALLOWED -1. This function is intended to be |
| 131 | * run before activating a new BMC version. If this function |
| 132 | * needs to delete any BMC version(s) it will delete the |
| 133 | * version(s) with the highest priority, skipping the |
| 134 | * functional BMC version. |
| 135 | */ |
| 136 | void freeSpace(); |
Adriana Kobylak | 204e1e7 | 2018-01-24 16:00:05 -0600 | [diff] [blame] | 137 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 138 | private: |
| 139 | /** @brief Callback function for Software.Version match. |
| 140 | * @details Creates an Activation D-Bus object. |
| 141 | * |
| 142 | * @param[in] msg - Data associated with subscribed signal |
| 143 | */ |
| 144 | void createActivation(sdbusplus::message::message& msg); |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 145 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 146 | /** |
| 147 | * @brief Validates the presence of SquashFS image in the image dir. |
| 148 | * |
| 149 | * @param[in] filePath - The path to the image dir. |
| 150 | * @param[out] result - ActivationStatus Enum. |
| 151 | * ready if validation was successful. |
| 152 | * invalid if validation fail. |
| 153 | * active if image is the current version. |
| 154 | * |
| 155 | */ |
| 156 | ActivationStatus validateSquashFSImage(const std::string& filePath); |
Saqib Khan | 35e83f3 | 2017-05-22 11:37:32 -0500 | [diff] [blame] | 157 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 158 | /** @brief BMC factory reset - marks the read-write partition for |
| 159 | * recreation upon reboot. */ |
| 160 | void reset() override; |
Michael Tritz | 37a5904 | 2017-07-12 13:44:53 -0500 | [diff] [blame] | 161 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 162 | /** |
| 163 | * @brief Enables field mode, if value=true. |
| 164 | * |
| 165 | * @param[in] value - If true, enables field mode. |
| 166 | * @param[out] result - Returns the current state of field mode. |
| 167 | * |
| 168 | */ |
| 169 | bool fieldModeEnabled(bool value) override; |
Michael Tritz | 0129d92 | 2017-08-10 19:33:46 -0500 | [diff] [blame] | 170 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 171 | /** @brief Sets the BMC inventory item path under |
| 172 | * /xyz/openbmc_project/inventory/system/chassis/. */ |
| 173 | void setBMCInventoryPath(); |
Gunnar Mills | b60add1 | 2017-08-24 16:41:42 -0500 | [diff] [blame] | 174 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 175 | /** @brief The path to the BMC inventory item. */ |
| 176 | std::string bmcInventoryPath; |
Gunnar Mills | b60add1 | 2017-08-24 16:41:42 -0500 | [diff] [blame] | 177 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 178 | /** @brief Restores field mode status on reboot. */ |
| 179 | void restoreFieldModeStatus(); |
Michael Tritz | 0129d92 | 2017-08-10 19:33:46 -0500 | [diff] [blame] | 180 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 181 | /** @brief Creates a functional association to the |
| 182 | * "running" BMC software image |
| 183 | * |
| 184 | * @param[in] path - The path to create the association to. |
| 185 | */ |
| 186 | void createFunctionalAssociation(const std::string& path); |
Gunnar Mills | 88e8a32 | 2017-09-13 11:09:28 -0500 | [diff] [blame] | 187 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 188 | /** @brief Persistent sdbusplus D-Bus bus connection. */ |
| 189 | sdbusplus::bus::bus& bus; |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 190 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 191 | /** @brief Persistent map of Activation D-Bus objects and their |
| 192 | * version id */ |
| 193 | std::map<std::string, std::unique_ptr<Activation>> activations; |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 194 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 195 | /** @brief Persistent map of Version D-Bus objects and their |
| 196 | * version id */ |
| 197 | std::map<std::string, std::unique_ptr<VersionClass>> versions; |
Saqib Khan | 705f1bf | 2017-06-09 23:58:38 -0500 | [diff] [blame] | 198 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 199 | /** @brief sdbusplus signal match for Software.Version */ |
| 200 | sdbusplus::bus::match_t versionMatch; |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 201 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 202 | /** @brief This entry's associations */ |
| 203 | AssociationList assocs = {}; |
Gunnar Mills | ded875d | 2017-08-28 16:44:52 -0500 | [diff] [blame] | 204 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 205 | /** @brief Clears read only partition for |
| 206 | * given Activation D-Bus object. |
| 207 | * |
| 208 | * @param[in] versionId - The version id. |
| 209 | */ |
| 210 | void removeReadOnlyPartition(std::string versionId); |
Eddie James | eaa1ee0 | 2018-03-01 10:09:10 -0600 | [diff] [blame^] | 211 | |
| 212 | /** @brief Copies U-Boot from the currently booted BMC chip to the |
| 213 | * alternate chip. |
| 214 | */ |
| 215 | void mirrorUbootToAlt(); |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 216 | }; |
| 217 | |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 218 | } // namespace updater |
| 219 | } // namespace software |
| 220 | } // namespace phosphor |