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