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