Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <sdbusplus/server.hpp> |
| 4 | #include "activation.hpp" |
Michael Tritz | dd961b6 | 2017-05-17 14:07:03 -0500 | [diff] [blame] | 5 | #include <xyz/openbmc_project/Common/FactoryReset/server.hpp> |
Adriana Kobylak | 7cb480e | 2017-11-07 13:22:59 -0600 | [diff] [blame] | 6 | #include <xyz/openbmc_project/Object/Enable/server.hpp> |
Saqib Khan | ce14870 | 2017-06-11 12:01:58 -0500 | [diff] [blame] | 7 | #include "version.hpp" |
Gunnar Mills | 9741cd1 | 2017-08-28 15:09:00 -0500 | [diff] [blame] | 8 | #include "org/openbmc/Associations/server.hpp" |
Michael Tritz | 234a07e | 2017-09-21 00:53:06 -0500 | [diff] [blame] | 9 | #include "xyz/openbmc_project/Collection/DeleteAll/server.hpp" |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 10 | |
| 11 | namespace openpower |
| 12 | { |
| 13 | namespace software |
| 14 | { |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 15 | namespace updater |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 16 | { |
| 17 | |
Michael Tritz | dd961b6 | 2017-05-17 14:07:03 -0500 | [diff] [blame] | 18 | using ItemUpdaterInherit = sdbusplus::server::object::object< |
Gunnar Mills | 139cf1a | 2017-09-21 16:25:37 -0500 | [diff] [blame] | 19 | sdbusplus::xyz::openbmc_project::Common::server::FactoryReset, |
| 20 | sdbusplus::org::openbmc::server::Associations, |
| 21 | sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll>; |
Michael Tritz | b541f1b | 2017-10-15 15:10:21 -0500 | [diff] [blame] | 22 | using GardResetInherit = sdbusplus::server::object::object< |
| 23 | sdbusplus::xyz::openbmc_project::Common::server::FactoryReset>; |
Adriana Kobylak | 7cb480e | 2017-11-07 13:22:59 -0600 | [diff] [blame] | 24 | using ObjectEnable = sdbusplus::server::object::object< |
| 25 | sdbusplus::xyz::openbmc_project::Object::server::Enable>; |
Patrick Williams | 3accb32 | 2017-05-30 16:29:52 -0500 | [diff] [blame] | 26 | namespace MatchRules = sdbusplus::bus::match::rules; |
Michael Tritz | dd961b6 | 2017-05-17 14:07:03 -0500 | [diff] [blame] | 27 | |
Gunnar Mills | 9741cd1 | 2017-08-28 15:09:00 -0500 | [diff] [blame] | 28 | using AssociationList = |
| 29 | std::vector<std::tuple<std::string, std::string, std::string>>; |
| 30 | |
Michael Tritz | 4ecea0f | 2017-12-05 17:51:31 -0600 | [diff] [blame] | 31 | constexpr auto GARD_PATH = "/org/open_power/control/gard"; |
Adriana Kobylak | 7cb480e | 2017-11-07 13:22:59 -0600 | [diff] [blame] | 32 | constexpr static auto volatilePath = "/org/open_power/control/volatile"; |
Michael Tritz | b541f1b | 2017-10-15 15:10:21 -0500 | [diff] [blame] | 33 | |
| 34 | /** @class GardReset |
| 35 | * @brief OpenBMC GARD factory reset implementation. |
| 36 | * @details An implementation of xyz.openbmc_project.Common.FactoryReset under |
| 37 | * /org/openpower/control/gard. |
| 38 | */ |
| 39 | class GardReset : public GardResetInherit |
| 40 | { |
| 41 | public: |
| 42 | /** @brief Constructs GardReset. |
| 43 | * |
| 44 | * @param[in] bus - The Dbus bus object |
| 45 | * @param[in] path - The Dbus object path |
| 46 | */ |
| 47 | GardReset(sdbusplus::bus::bus& bus, |
| 48 | const std::string& path) : |
| 49 | GardResetInherit(bus, path.c_str(), true), |
| 50 | bus(bus), |
| 51 | path(path) |
| 52 | { |
| 53 | std::vector<std::string> interfaces({interface}); |
| 54 | bus.emit_interfaces_added(path.c_str(), interfaces); |
| 55 | } |
| 56 | |
| 57 | ~GardReset() |
| 58 | { |
| 59 | std::vector<std::string> interfaces({interface}); |
| 60 | bus.emit_interfaces_removed(path.c_str(), interfaces); |
| 61 | } |
| 62 | |
| 63 | private: |
| 64 | // TODO Remove once openbmc/openbmc#1975 is resolved |
| 65 | static constexpr auto interface = |
| 66 | "xyz.openbmc_project.Common.FactoryReset"; |
| 67 | sdbusplus::bus::bus& bus; |
| 68 | std::string path; |
| 69 | |
| 70 | /** |
| 71 | * @brief GARD factory reset - clears the PNOR GARD partition. |
| 72 | */ |
| 73 | void reset() override; |
| 74 | }; |
| 75 | |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 76 | /** @class ItemUpdater |
Gunnar Mills | 139cf1a | 2017-09-21 16:25:37 -0500 | [diff] [blame] | 77 | * @brief Manages the activation of the host version items. |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 78 | */ |
Michael Tritz | dd961b6 | 2017-05-17 14:07:03 -0500 | [diff] [blame] | 79 | class ItemUpdater : public ItemUpdaterInherit |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 80 | { |
| 81 | public: |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 82 | /** @brief Constructs ItemUpdater |
| 83 | * |
Gunnar Mills | 139cf1a | 2017-09-21 16:25:37 -0500 | [diff] [blame] | 84 | * @param[in] bus - The D-Bus bus object |
| 85 | * @param[in] path - The D-Bus path |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 86 | */ |
Michael Tritz | dd961b6 | 2017-05-17 14:07:03 -0500 | [diff] [blame] | 87 | ItemUpdater(sdbusplus::bus::bus& bus, const std::string& path) : |
| 88 | ItemUpdaterInherit(bus, path.c_str()), |
Adriana Kobylak | d6a549e | 2017-05-10 16:23:01 -0500 | [diff] [blame] | 89 | bus(bus), |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 90 | versionMatch( |
| 91 | bus, |
Patrick Williams | 3accb32 | 2017-05-30 16:29:52 -0500 | [diff] [blame] | 92 | MatchRules::interfacesAdded() + |
| 93 | MatchRules::path("/xyz/openbmc_project/software"), |
| 94 | std::bind( |
| 95 | std::mem_fn(&ItemUpdater::createActivation), |
| 96 | this, |
| 97 | std::placeholders::_1)) |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 98 | { |
Saqib Khan | 167601b | 2017-06-18 23:33:46 -0500 | [diff] [blame] | 99 | processPNORImage(); |
Michael Tritz | b541f1b | 2017-10-15 15:10:21 -0500 | [diff] [blame] | 100 | gardReset = std::make_unique<GardReset>(bus, GARD_PATH); |
Adriana Kobylak | 7cb480e | 2017-11-07 13:22:59 -0600 | [diff] [blame] | 101 | volatileEnable = std::make_unique<ObjectEnable>(bus, volatilePath); |
Michael Tritz | b541f1b | 2017-10-15 15:10:21 -0500 | [diff] [blame] | 102 | |
| 103 | // Emit deferred signal. |
| 104 | emit_object_added(); |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 105 | } |
| 106 | |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 107 | /** @brief Sets the given priority free by incrementing |
| 108 | * any existing priority with the same value by 1 |
| 109 | * |
| 110 | * @param[in] value - The priority that needs to be set free. |
Saqib Khan | b8e7f31 | 2017-08-12 10:24:10 -0500 | [diff] [blame] | 111 | * @param[in] versionId - The Id of the version for which we |
| 112 | * are trying to free up the priority. |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 113 | * @return None |
| 114 | */ |
Saqib Khan | b8e7f31 | 2017-08-12 10:24:10 -0500 | [diff] [blame] | 115 | void freePriority(uint8_t value, const std::string& versionId); |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 116 | |
Saqib Khan | 2af5c49 | 2017-07-17 16:15:13 -0500 | [diff] [blame] | 117 | /** @brief Determine is the given priority is the lowest |
| 118 | * |
| 119 | * @param[in] value - The priority that needs to be checked. |
| 120 | * |
| 121 | * @return boolean corresponding to whether the given |
| 122 | * priority is lowest. |
| 123 | */ |
| 124 | bool isLowestPriority(uint8_t value); |
| 125 | |
Saqib Khan | 167601b | 2017-06-18 23:33:46 -0500 | [diff] [blame] | 126 | /** |
| 127 | * @brief Create and populate the active PNOR Version. |
| 128 | */ |
| 129 | void processPNORImage(); |
| 130 | |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 131 | /** @brief Deletes version |
| 132 | * |
| 133 | * @param[in] entryId - Id of the version to delete |
| 134 | * |
| 135 | * @return None |
| 136 | */ |
| 137 | void erase(std::string entryId); |
| 138 | |
Michael Tritz | 234a07e | 2017-09-21 00:53:06 -0500 | [diff] [blame] | 139 | /** |
| 140 | * @brief Erases any non-active pnor versions. |
| 141 | */ |
| 142 | void deleteAll(); |
| 143 | |
Gunnar Mills | fedbf3d | 2018-01-17 11:17:31 -0600 | [diff] [blame^] | 144 | /** @brief Brings the total number of active PNOR versions to |
| 145 | * ACTIVE_PNOR_MAX_ALLOWED -1. This function is intended to be |
| 146 | * run before activating a new PNOR version. If this function |
| 147 | * needs to delete any PNOR version(s) it will delete the |
| 148 | * version(s) with the highest priority, skipping the |
| 149 | * functional PNOR version. |
Saqib Khan | 2cbfa03 | 2017-08-17 14:52:37 -0500 | [diff] [blame] | 150 | */ |
| 151 | void freeSpace(); |
| 152 | |
Gunnar Mills | 2badd7a | 2017-09-20 12:51:28 -0500 | [diff] [blame] | 153 | /** @brief Determine the software version id |
| 154 | * from the symlink target (e.g. /media/ro-2a1022fe). |
| 155 | * |
| 156 | * @param[in] symlinkPath - The path of the symlink. |
| 157 | * @param[out] id - The version id as a string. |
| 158 | */ |
| 159 | static std::string determineId(const std::string& symlinkPath); |
| 160 | |
Gunnar Mills | 9741cd1 | 2017-08-28 15:09:00 -0500 | [diff] [blame] | 161 | /** @brief Creates an active association to the |
| 162 | * newly active software image |
| 163 | * |
| 164 | * @param[in] path - The path to create the association to. |
| 165 | */ |
Gunnar Mills | 61010b2 | 2017-09-20 15:25:26 -0500 | [diff] [blame] | 166 | void createActiveAssociation(const std::string& path); |
Gunnar Mills | 9741cd1 | 2017-08-28 15:09:00 -0500 | [diff] [blame] | 167 | |
Gunnar Mills | 833e4f3 | 2017-09-14 12:30:27 -0500 | [diff] [blame] | 168 | /** @brief Updates the functional association to the |
| 169 | * new "running" PNOR image |
| 170 | * |
| 171 | * @param[in] path - The path to update the association to. |
| 172 | */ |
| 173 | void updateFunctionalAssociation(const std::string& path); |
| 174 | |
Gunnar Mills | 9741cd1 | 2017-08-28 15:09:00 -0500 | [diff] [blame] | 175 | /** @brief Removes an active association to the software image |
| 176 | * |
| 177 | * @param[in] path - The path to remove the association from. |
| 178 | */ |
Gunnar Mills | 61010b2 | 2017-09-20 15:25:26 -0500 | [diff] [blame] | 179 | void removeActiveAssociation(const std::string& path); |
Gunnar Mills | 9741cd1 | 2017-08-28 15:09:00 -0500 | [diff] [blame] | 180 | |
Michael Tritz | b541f1b | 2017-10-15 15:10:21 -0500 | [diff] [blame] | 181 | /** @brief Persistent GardReset dbus object */ |
| 182 | std::unique_ptr<GardReset> gardReset; |
| 183 | |
Michael Tritz | 5b75651 | 2017-10-06 16:52:01 -0500 | [diff] [blame] | 184 | /** @brief Check whether the provided image id is the functional one |
| 185 | * |
| 186 | * @param[in] - versionId - The id of the image to check. |
| 187 | * |
| 188 | * @return - Returns true if this version is currently functional. |
| 189 | */ |
| 190 | static bool isVersionFunctional(const std::string& versionId); |
| 191 | |
Adriana Kobylak | 7cb480e | 2017-11-07 13:22:59 -0600 | [diff] [blame] | 192 | /** @brief Persistent ObjectEnable D-Bus object */ |
| 193 | std::unique_ptr<ObjectEnable> volatileEnable; |
| 194 | |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 195 | private: |
| 196 | /** @brief Callback function for Software.Version match. |
Gunnar Mills | 139cf1a | 2017-09-21 16:25:37 -0500 | [diff] [blame] | 197 | * @details Creates an Activation D-Bus object. |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 198 | * |
| 199 | * @param[in] msg - Data associated with subscribed signal |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 200 | */ |
Patrick Williams | 3accb32 | 2017-05-30 16:29:52 -0500 | [diff] [blame] | 201 | void createActivation(sdbusplus::message::message& msg); |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 202 | |
Saqib Khan | 7254f0e | 2017-04-10 21:45:37 -0500 | [diff] [blame] | 203 | /** |
Gunnar Mills | 139cf1a | 2017-09-21 16:25:37 -0500 | [diff] [blame] | 204 | * @brief Validates the presence of SquashFS image in the image dir. |
Saqib Khan | a8ade7e | 2017-04-12 10:27:56 -0500 | [diff] [blame] | 205 | * |
Gunnar Mills | 139cf1a | 2017-09-21 16:25:37 -0500 | [diff] [blame] | 206 | * @param[in] filePath - The path to the SquashFS image. |
Saqib Khan | a8ade7e | 2017-04-12 10:27:56 -0500 | [diff] [blame] | 207 | * @param[out] result - 0 --> if validation was successful |
| 208 | * - -1--> Otherwise |
| 209 | */ |
Adriana Kobylak | 5ba6b10 | 2017-05-19 09:41:27 -0500 | [diff] [blame] | 210 | static int validateSquashFSImage(const std::string& filePath); |
Saqib Khan | 7254f0e | 2017-04-10 21:45:37 -0500 | [diff] [blame] | 211 | |
Gunnar Mills | 139cf1a | 2017-09-21 16:25:37 -0500 | [diff] [blame] | 212 | /** @brief Persistent sdbusplus D-Bus bus connection. */ |
Adriana Kobylak | d6a549e | 2017-05-10 16:23:01 -0500 | [diff] [blame] | 213 | sdbusplus::bus::bus& bus; |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 214 | |
Gunnar Mills | 139cf1a | 2017-09-21 16:25:37 -0500 | [diff] [blame] | 215 | /** @brief Persistent map of Activation D-Bus objects and their |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 216 | * version id */ |
Adriana Kobylak | 268616b | 2017-04-05 15:23:30 -0500 | [diff] [blame] | 217 | std::map<std::string, std::unique_ptr<Activation>> activations; |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 218 | |
Gunnar Mills | 139cf1a | 2017-09-21 16:25:37 -0500 | [diff] [blame] | 219 | /** @brief Persistent map of Version D-Bus objects and their |
Saqib Khan | ce14870 | 2017-06-11 12:01:58 -0500 | [diff] [blame] | 220 | * version id */ |
| 221 | std::map<std::string, std::unique_ptr<Version>> versions; |
| 222 | |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 223 | /** @brief sdbusplus signal match for Software.Version */ |
Patrick Williams | 3accb32 | 2017-05-30 16:29:52 -0500 | [diff] [blame] | 224 | sdbusplus::bus::match_t versionMatch; |
Michael Tritz | dd961b6 | 2017-05-17 14:07:03 -0500 | [diff] [blame] | 225 | |
Gunnar Mills | 9741cd1 | 2017-08-28 15:09:00 -0500 | [diff] [blame] | 226 | /** @brief This entry's associations */ |
| 227 | AssociationList assocs = {}; |
| 228 | |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 229 | /** @brief Clears read only PNOR partition for |
Gunnar Mills | 139cf1a | 2017-09-21 16:25:37 -0500 | [diff] [blame] | 230 | * given Activation D-Bus object |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 231 | * |
| 232 | * @param[in] versionId - The id of the ro partition to remove. |
| 233 | */ |
| 234 | void removeReadOnlyPartition(std::string versionId); |
| 235 | |
| 236 | /** @brief Clears read write PNOR partition for |
Gunnar Mills | 139cf1a | 2017-09-21 16:25:37 -0500 | [diff] [blame] | 237 | * given Activation D-Bus object |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 238 | * |
Saqib Khan | 1e0aa5c | 2017-08-31 11:04:17 -0500 | [diff] [blame] | 239 | * @param[in] versionId - The id of the rw partition to remove. |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 240 | */ |
| 241 | void removeReadWritePartition(std::string versionId); |
| 242 | |
| 243 | /** @brief Clears preserved PNOR partition */ |
| 244 | void removePreservedPartition(); |
| 245 | |
Michael Tritz | dd961b6 | 2017-05-17 14:07:03 -0500 | [diff] [blame] | 246 | /** @brief Host factory reset - clears PNOR partitions for each |
Gunnar Mills | 139cf1a | 2017-09-21 16:25:37 -0500 | [diff] [blame] | 247 | * Activation D-Bus object */ |
Michael Tritz | dd961b6 | 2017-05-17 14:07:03 -0500 | [diff] [blame] | 248 | void reset() override; |
Eddie James | 13fc66a | 2017-08-31 15:36:44 -0500 | [diff] [blame] | 249 | |
Eddie James | 13fc66a | 2017-08-31 15:36:44 -0500 | [diff] [blame] | 250 | /** @brief Check whether the host is running |
| 251 | * |
| 252 | * @return - Returns true if the Chassis is powered on. |
| 253 | */ |
| 254 | bool isChassisOn(); |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 255 | }; |
| 256 | |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 257 | } // namespace updater |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 258 | } // namespace software |
| 259 | } // namespace openpower |