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 "version.hpp" |
| 5 | #include "xyz/openbmc_project/Collection/DeleteAll/server.hpp" |
| 6 | |
| 7 | #include <sdbusplus/server.hpp> |
John Wang | d05d472 | 2019-09-11 15:18:15 +0800 | [diff] [blame] | 8 | #include <xyz/openbmc_project/Association/Definitions/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 | |
Brad Bishop | 8facccf | 2020-11-04 09:44:58 -0500 | [diff] [blame] | 12 | #include <string> |
| 13 | |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 14 | namespace openpower |
| 15 | { |
| 16 | namespace software |
| 17 | { |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 18 | namespace updater |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 19 | { |
| 20 | |
Patrick Williams | 0dea199 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 21 | using ItemUpdaterInherit = sdbusplus::server::object_t< |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 22 | sdbusplus::xyz::openbmc_project::Common::server::FactoryReset, |
John Wang | d05d472 | 2019-09-11 15:18:15 +0800 | [diff] [blame] | 23 | sdbusplus::xyz::openbmc_project::Association::server::Definitions, |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 24 | sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll>; |
Patrick Williams | 0dea199 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 25 | using GardResetInherit = sdbusplus::server::object_t< |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 26 | sdbusplus::xyz::openbmc_project::Common::server::FactoryReset>; |
Patrick Williams | 0dea199 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 27 | using ObjectEnable = sdbusplus::server::object_t< |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 28 | sdbusplus::xyz::openbmc_project::Object::server::Enable>; |
Patrick Williams | 3accb32 | 2017-05-30 16:29:52 -0500 | [diff] [blame] | 29 | namespace MatchRules = sdbusplus::bus::match::rules; |
Michael Tritz | dd961b6 | 2017-05-17 14:07:03 -0500 | [diff] [blame] | 30 | |
Gunnar Mills | 9741cd1 | 2017-08-28 15:09:00 -0500 | [diff] [blame] | 31 | using AssociationList = |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 32 | std::vector<std::tuple<std::string, std::string, std::string>>; |
Gunnar Mills | 9741cd1 | 2017-08-28 15:09:00 -0500 | [diff] [blame] | 33 | |
Michael Tritz | 4ecea0f | 2017-12-05 17:51:31 -0600 | [diff] [blame] | 34 | constexpr auto GARD_PATH = "/org/open_power/control/gard"; |
Adriana Kobylak | 7cb480e | 2017-11-07 13:22:59 -0600 | [diff] [blame] | 35 | constexpr static auto volatilePath = "/org/open_power/control/volatile"; |
Michael Tritz | b541f1b | 2017-10-15 15:10:21 -0500 | [diff] [blame] | 36 | |
| 37 | /** @class GardReset |
| 38 | * @brief OpenBMC GARD factory reset implementation. |
| 39 | * @details An implementation of xyz.openbmc_project.Common.FactoryReset under |
| 40 | * /org/openpower/control/gard. |
| 41 | */ |
| 42 | class GardReset : public GardResetInherit |
| 43 | { |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 44 | public: |
| 45 | /** @brief Constructs GardReset. |
| 46 | * |
| 47 | * @param[in] bus - The Dbus bus object |
| 48 | * @param[in] path - The Dbus object path |
| 49 | */ |
Patrick Williams | 0dea199 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 50 | GardReset(sdbusplus::bus_t& bus, const std::string& path) : |
Patrick Williams | 9c887d1 | 2022-04-05 21:39:40 -0500 | [diff] [blame] | 51 | GardResetInherit(bus, path.c_str(), |
| 52 | GardResetInherit::action::emit_interface_added), |
| 53 | bus(bus), path(path) |
| 54 | {} |
Michael Tritz | b541f1b | 2017-10-15 15:10:21 -0500 | [diff] [blame] | 55 | |
Patrick Williams | 7fb6c34 | 2023-05-10 07:50:18 -0500 | [diff] [blame^] | 56 | virtual ~GardReset() {} |
Michael Tritz | b541f1b | 2017-10-15 15:10:21 -0500 | [diff] [blame] | 57 | |
Marri Devender Rao | 2b31497 | 2022-07-01 05:37:30 -0500 | [diff] [blame] | 58 | /** |
| 59 | * @brief GARD factory reset - clears the PNOR GARD partition. |
| 60 | */ |
| 61 | virtual void reset() = 0; |
| 62 | |
Lei YU | 716de5b | 2019-03-01 16:03:53 +0800 | [diff] [blame] | 63 | protected: |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 64 | // TODO Remove once openbmc/openbmc#1975 is resolved |
| 65 | static constexpr auto interface = "xyz.openbmc_project.Common.FactoryReset"; |
Patrick Williams | 0dea199 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 66 | sdbusplus::bus_t& bus; |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 67 | std::string path; |
Michael Tritz | b541f1b | 2017-10-15 15:10:21 -0500 | [diff] [blame] | 68 | }; |
| 69 | |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 70 | /** @class ItemUpdater |
Gunnar Mills | 139cf1a | 2017-09-21 16:25:37 -0500 | [diff] [blame] | 71 | * @brief Manages the activation of the host version items. |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 72 | */ |
Michael Tritz | dd961b6 | 2017-05-17 14:07:03 -0500 | [diff] [blame] | 73 | class ItemUpdater : public ItemUpdaterInherit |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 74 | { |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 75 | public: |
| 76 | /** @brief Constructs ItemUpdater |
| 77 | * |
| 78 | * @param[in] bus - The D-Bus bus object |
| 79 | * @param[in] path - The D-Bus path |
| 80 | */ |
Patrick Williams | 0dea199 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 81 | ItemUpdater(sdbusplus::bus_t& bus, const std::string& path) : |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 82 | ItemUpdaterInherit(bus, path.c_str()), bus(bus), |
| 83 | versionMatch(bus, |
| 84 | MatchRules::interfacesAdded() + |
| 85 | MatchRules::path("/xyz/openbmc_project/software"), |
| 86 | std::bind(std::mem_fn(&ItemUpdater::createActivation), |
| 87 | this, std::placeholders::_1)) |
Brad Bishop | 8facccf | 2020-11-04 09:44:58 -0500 | [diff] [blame] | 88 | {} |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 89 | |
Lei YU | f3ce433 | 2019-02-21 14:09:49 +0800 | [diff] [blame] | 90 | virtual ~ItemUpdater() = default; |
| 91 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 92 | /** @brief Sets the given priority free by incrementing |
Adriana Kobylak | abe862a | 2019-07-17 16:09:00 -0500 | [diff] [blame] | 93 | * any existing priority with the same value by 1. It will then continue |
| 94 | * to resolve duplicate priorities caused by this increase, by increasing |
| 95 | * the priority by 1 until there are no more duplicate values. |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 96 | * |
| 97 | * @param[in] value - The priority that needs to be set free. |
| 98 | * @param[in] versionId - The Id of the version for which we |
| 99 | * are trying to free up the priority. |
| 100 | * @return None |
| 101 | */ |
Lei YU | f3ce433 | 2019-02-21 14:09:49 +0800 | [diff] [blame] | 102 | virtual void freePriority(uint8_t value, const std::string& versionId) = 0; |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 103 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 104 | /** |
| 105 | * @brief Create and populate the active PNOR Version. |
| 106 | */ |
Lei YU | f3ce433 | 2019-02-21 14:09:49 +0800 | [diff] [blame] | 107 | virtual void processPNORImage() = 0; |
Saqib Khan | 167601b | 2017-06-18 23:33:46 -0500 | [diff] [blame] | 108 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 109 | /** @brief Deletes version |
| 110 | * |
| 111 | * @param[in] entryId - Id of the version to delete |
| 112 | * |
Lei YU | f3ce433 | 2019-02-21 14:09:49 +0800 | [diff] [blame] | 113 | * @return - Returns true if the version is deleted. |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 114 | */ |
Lei YU | f3ce433 | 2019-02-21 14:09:49 +0800 | [diff] [blame] | 115 | virtual bool erase(std::string entryId); |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 116 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 117 | /** |
| 118 | * @brief Erases any non-active pnor versions. |
| 119 | */ |
Lei YU | f3ce433 | 2019-02-21 14:09:49 +0800 | [diff] [blame] | 120 | virtual void deleteAll() = 0; |
Michael Tritz | 234a07e | 2017-09-21 00:53:06 -0500 | [diff] [blame] | 121 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 122 | /** @brief Brings the total number of active PNOR versions to |
| 123 | * ACTIVE_PNOR_MAX_ALLOWED -1. This function is intended to be |
| 124 | * run before activating a new PNOR version. If this function |
| 125 | * needs to delete any PNOR version(s) it will delete the |
| 126 | * version(s) with the highest priority, skipping the |
| 127 | * functional PNOR version. |
Lei YU | 6da3dae | 2019-02-28 14:26:37 +0800 | [diff] [blame] | 128 | * |
| 129 | * @return - Return if space is freed or not |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 130 | */ |
Lei YU | 6da3dae | 2019-02-28 14:26:37 +0800 | [diff] [blame] | 131 | virtual bool freeSpace() = 0; |
Saqib Khan | 2cbfa03 | 2017-08-17 14:52:37 -0500 | [diff] [blame] | 132 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 133 | /** @brief Creates an active association to the |
| 134 | * newly active software image |
| 135 | * |
| 136 | * @param[in] path - The path to create the association to. |
| 137 | */ |
Lei YU | f3ce433 | 2019-02-21 14:09:49 +0800 | [diff] [blame] | 138 | virtual void createActiveAssociation(const std::string& path); |
Gunnar Mills | 9741cd1 | 2017-08-28 15:09:00 -0500 | [diff] [blame] | 139 | |
Adriana Kobylak | 3c81037 | 2020-07-15 16:47:03 -0500 | [diff] [blame] | 140 | /** @brief Creates a updateable association to the |
| 141 | * "running" BMC software image |
| 142 | * |
| 143 | * @param[in] path - The path to create the association. |
| 144 | */ |
| 145 | virtual void createUpdateableAssociation(const std::string& path); |
| 146 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 147 | /** @brief Updates the functional association to the |
| 148 | * new "running" PNOR image |
| 149 | * |
Lei YU | f3ce433 | 2019-02-21 14:09:49 +0800 | [diff] [blame] | 150 | * @param[in] versionId - The id of the image to update the association to. |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 151 | */ |
Lei YU | f3ce433 | 2019-02-21 14:09:49 +0800 | [diff] [blame] | 152 | virtual void updateFunctionalAssociation(const std::string& versionId); |
Gunnar Mills | 833e4f3 | 2017-09-14 12:30:27 -0500 | [diff] [blame] | 153 | |
Adriana Kobylak | b523717 | 2018-10-30 14:51:53 -0500 | [diff] [blame] | 154 | /** @brief Removes the associations from the provided software image path |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 155 | * |
| 156 | * @param[in] path - The path to remove the association from. |
| 157 | */ |
Lei YU | f3ce433 | 2019-02-21 14:09:49 +0800 | [diff] [blame] | 158 | virtual void removeAssociation(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 Persistent GardReset dbus object */ |
| 161 | std::unique_ptr<GardReset> gardReset; |
Michael Tritz | b541f1b | 2017-10-15 15:10:21 -0500 | [diff] [blame] | 162 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 163 | /** @brief Check whether the provided image id is the functional one |
| 164 | * |
| 165 | * @param[in] - versionId - The id of the image to check. |
| 166 | * |
| 167 | * @return - Returns true if this version is currently functional. |
| 168 | */ |
Lei YU | f3ce433 | 2019-02-21 14:09:49 +0800 | [diff] [blame] | 169 | virtual bool isVersionFunctional(const std::string& versionId) = 0; |
Michael Tritz | 5b75651 | 2017-10-06 16:52:01 -0500 | [diff] [blame] | 170 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 171 | /** @brief Persistent ObjectEnable D-Bus object */ |
| 172 | std::unique_ptr<ObjectEnable> volatileEnable; |
Adriana Kobylak | 7cb480e | 2017-11-07 13:22:59 -0600 | [diff] [blame] | 173 | |
Lei YU | f3ce433 | 2019-02-21 14:09:49 +0800 | [diff] [blame] | 174 | protected: |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 175 | /** @brief Callback function for Software.Version match. |
| 176 | * @details Creates an Activation D-Bus object. |
| 177 | * |
| 178 | * @param[in] msg - Data associated with subscribed signal |
| 179 | */ |
Patrick Williams | 0dea199 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 180 | virtual void createActivation(sdbusplus::message_t& msg); |
Lei YU | a9ac927 | 2019-02-22 16:38:35 +0800 | [diff] [blame] | 181 | |
| 182 | /** @brief Create Activation object */ |
| 183 | virtual std::unique_ptr<Activation> createActivationObject( |
| 184 | const std::string& path, const std::string& versionId, |
| 185 | const std::string& extVersion, |
| 186 | sdbusplus::xyz::openbmc_project::Software::server::Activation:: |
| 187 | Activations activationStatus, |
| 188 | AssociationList& assocs) = 0; |
| 189 | |
| 190 | /** @brief Create Version object */ |
| 191 | virtual std::unique_ptr<Version> |
| 192 | createVersionObject(const std::string& objPath, |
| 193 | const std::string& versionId, |
| 194 | const std::string& versionString, |
| 195 | sdbusplus::xyz::openbmc_project::Software::server:: |
| 196 | Version::VersionPurpose versionPurpose, |
| 197 | const std::string& filePath) = 0; |
| 198 | |
| 199 | /** @brief Validate if image is valid or not */ |
| 200 | virtual bool validateImage(const std::string& path) = 0; |
Saqib Khan | 7254f0e | 2017-04-10 21:45:37 -0500 | [diff] [blame] | 201 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 202 | /** @brief Persistent sdbusplus D-Bus bus connection. */ |
Patrick Williams | 0dea199 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 203 | sdbusplus::bus_t& bus; |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 204 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 205 | /** @brief Persistent map of Activation D-Bus objects and their |
| 206 | * version id */ |
| 207 | std::map<std::string, std::unique_ptr<Activation>> activations; |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 208 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 209 | /** @brief Persistent map of Version D-Bus objects and their |
| 210 | * version id */ |
| 211 | std::map<std::string, std::unique_ptr<Version>> versions; |
Saqib Khan | ce14870 | 2017-06-11 12:01:58 -0500 | [diff] [blame] | 212 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 213 | /** @brief sdbusplus signal match for Software.Version */ |
| 214 | sdbusplus::bus::match_t versionMatch; |
Michael Tritz | dd961b6 | 2017-05-17 14:07:03 -0500 | [diff] [blame] | 215 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 216 | /** @brief This entry's associations */ |
| 217 | AssociationList assocs = {}; |
Gunnar Mills | 9741cd1 | 2017-08-28 15:09:00 -0500 | [diff] [blame] | 218 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 219 | /** @brief Host factory reset - clears PNOR partitions for each |
| 220 | * Activation D-Bus object */ |
Lei YU | f3ce433 | 2019-02-21 14:09:49 +0800 | [diff] [blame] | 221 | void reset() override = 0; |
Eddie James | 13fc66a | 2017-08-31 15:36:44 -0500 | [diff] [blame] | 222 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 223 | /** @brief Check whether the host is running |
| 224 | * |
| 225 | * @return - Returns true if the Chassis is powered on. |
| 226 | */ |
| 227 | bool isChassisOn(); |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 228 | }; |
| 229 | |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 230 | } // namespace updater |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 231 | } // namespace software |
| 232 | } // namespace openpower |