blob: 0aa3a5d0816f240da4c84cd9f5e697d1d261dcaf [file] [log] [blame]
Adriana Kobylak2d8fa222017-03-15 12:34:32 -05001#pragma once
2
Adriana Kobylak2d8fa222017-03-15 12:34:32 -05003#include "activation.hpp"
Gunnar Millsf6ed5892018-09-07 17:08:02 -05004#include "version.hpp"
5#include "xyz/openbmc_project/Collection/DeleteAll/server.hpp"
6
7#include <sdbusplus/server.hpp>
John Wangd05d4722019-09-11 15:18:15 +08008#include <xyz/openbmc_project/Association/Definitions/server.hpp>
Michael Tritzdd961b62017-05-17 14:07:03 -05009#include <xyz/openbmc_project/Common/FactoryReset/server.hpp>
Adriana Kobylak7cb480e2017-11-07 13:22:59 -060010#include <xyz/openbmc_project/Object/Enable/server.hpp>
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050011
Brad Bishop8facccf2020-11-04 09:44:58 -050012#include <string>
13
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050014namespace openpower
15{
16namespace software
17{
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -050018namespace updater
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050019{
20
Patrick Williams0dea1992022-07-22 19:26:52 -050021using ItemUpdaterInherit = sdbusplus::server::object_t<
Adriana Kobylak70dcb632018-02-27 15:46:52 -060022 sdbusplus::xyz::openbmc_project::Common::server::FactoryReset,
John Wangd05d4722019-09-11 15:18:15 +080023 sdbusplus::xyz::openbmc_project::Association::server::Definitions,
Adriana Kobylak70dcb632018-02-27 15:46:52 -060024 sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll>;
Patrick Williams0dea1992022-07-22 19:26:52 -050025using GardResetInherit = sdbusplus::server::object_t<
Adriana Kobylak70dcb632018-02-27 15:46:52 -060026 sdbusplus::xyz::openbmc_project::Common::server::FactoryReset>;
Patrick Williams0dea1992022-07-22 19:26:52 -050027using ObjectEnable = sdbusplus::server::object_t<
Adriana Kobylak70dcb632018-02-27 15:46:52 -060028 sdbusplus::xyz::openbmc_project::Object::server::Enable>;
Patrick Williams3accb322017-05-30 16:29:52 -050029namespace MatchRules = sdbusplus::bus::match::rules;
Michael Tritzdd961b62017-05-17 14:07:03 -050030
Gunnar Mills9741cd12017-08-28 15:09:00 -050031using AssociationList =
Adriana Kobylak70dcb632018-02-27 15:46:52 -060032 std::vector<std::tuple<std::string, std::string, std::string>>;
Gunnar Mills9741cd12017-08-28 15:09:00 -050033
Michael Tritz4ecea0f2017-12-05 17:51:31 -060034constexpr auto GARD_PATH = "/org/open_power/control/gard";
Adriana Kobylak7cb480e2017-11-07 13:22:59 -060035constexpr static auto volatilePath = "/org/open_power/control/volatile";
Michael Tritzb541f1b2017-10-15 15:10:21 -050036
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 */
42class GardReset : public GardResetInherit
43{
Adriana Kobylak70dcb632018-02-27 15:46:52 -060044 public:
45 /** @brief Constructs GardReset.
46 *
47 * @param[in] bus - The Dbus bus object
48 * @param[in] path - The Dbus object path
49 */
Patrick Williams0dea1992022-07-22 19:26:52 -050050 GardReset(sdbusplus::bus_t& bus, const std::string& path) :
Patrick Williams9c887d12022-04-05 21:39:40 -050051 GardResetInherit(bus, path.c_str(),
52 GardResetInherit::action::emit_interface_added),
53 bus(bus), path(path)
54 {}
Michael Tritzb541f1b2017-10-15 15:10:21 -050055
Patrick Williams7fb6c342023-05-10 07:50:18 -050056 virtual ~GardReset() {}
Michael Tritzb541f1b2017-10-15 15:10:21 -050057
Marri Devender Rao2b314972022-07-01 05:37:30 -050058 /**
59 * @brief GARD factory reset - clears the PNOR GARD partition.
60 */
61 virtual void reset() = 0;
62
Lei YU716de5b2019-03-01 16:03:53 +080063 protected:
Adriana Kobylak70dcb632018-02-27 15:46:52 -060064 // TODO Remove once openbmc/openbmc#1975 is resolved
65 static constexpr auto interface = "xyz.openbmc_project.Common.FactoryReset";
Patrick Williams0dea1992022-07-22 19:26:52 -050066 sdbusplus::bus_t& bus;
Adriana Kobylak70dcb632018-02-27 15:46:52 -060067 std::string path;
Michael Tritzb541f1b2017-10-15 15:10:21 -050068};
69
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050070/** @class ItemUpdater
Gunnar Mills139cf1a2017-09-21 16:25:37 -050071 * @brief Manages the activation of the host version items.
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050072 */
Michael Tritzdd961b62017-05-17 14:07:03 -050073class ItemUpdater : public ItemUpdaterInherit
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050074{
Adriana Kobylak70dcb632018-02-27 15:46:52 -060075 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 Williams0dea1992022-07-22 19:26:52 -050081 ItemUpdater(sdbusplus::bus_t& bus, const std::string& path) :
Adriana Kobylak70dcb632018-02-27 15:46:52 -060082 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 Bishop8facccf2020-11-04 09:44:58 -050088 {}
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050089
Lei YUf3ce4332019-02-21 14:09:49 +080090 virtual ~ItemUpdater() = default;
91
Adriana Kobylak70dcb632018-02-27 15:46:52 -060092 /** @brief Sets the given priority free by incrementing
Adriana Kobylakabe862a2019-07-17 16:09:00 -050093 * 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 Kobylak70dcb632018-02-27 15:46:52 -060096 *
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 YUf3ce4332019-02-21 14:09:49 +0800102 virtual void freePriority(uint8_t value, const std::string& versionId) = 0;
Saqib Khan81bac882017-06-08 12:17:01 -0500103
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600104 /**
105 * @brief Create and populate the active PNOR Version.
106 */
Lei YUf3ce4332019-02-21 14:09:49 +0800107 virtual void processPNORImage() = 0;
Saqib Khan167601b2017-06-18 23:33:46 -0500108
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600109 /** @brief Deletes version
110 *
111 * @param[in] entryId - Id of the version to delete
112 *
Lei YUf3ce4332019-02-21 14:09:49 +0800113 * @return - Returns true if the version is deleted.
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600114 */
Lei YUf3ce4332019-02-21 14:09:49 +0800115 virtual bool erase(std::string entryId);
Leonel Gonzalez9c8adfa2017-07-12 11:08:40 -0500116
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600117 /**
118 * @brief Erases any non-active pnor versions.
119 */
Lei YUf3ce4332019-02-21 14:09:49 +0800120 virtual void deleteAll() = 0;
Michael Tritz234a07e2017-09-21 00:53:06 -0500121
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600122 /** @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 YU6da3dae2019-02-28 14:26:37 +0800128 *
129 * @return - Return if space is freed or not
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600130 */
Lei YU6da3dae2019-02-28 14:26:37 +0800131 virtual bool freeSpace() = 0;
Saqib Khan2cbfa032017-08-17 14:52:37 -0500132
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600133 /** @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 YUf3ce4332019-02-21 14:09:49 +0800138 virtual void createActiveAssociation(const std::string& path);
Gunnar Mills9741cd12017-08-28 15:09:00 -0500139
Adriana Kobylak3c810372020-07-15 16:47:03 -0500140 /** @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 Kobylak70dcb632018-02-27 15:46:52 -0600147 /** @brief Updates the functional association to the
148 * new "running" PNOR image
149 *
Lei YUf3ce4332019-02-21 14:09:49 +0800150 * @param[in] versionId - The id of the image to update the association to.
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600151 */
Lei YUf3ce4332019-02-21 14:09:49 +0800152 virtual void updateFunctionalAssociation(const std::string& versionId);
Gunnar Mills833e4f32017-09-14 12:30:27 -0500153
Adriana Kobylakb5237172018-10-30 14:51:53 -0500154 /** @brief Removes the associations from the provided software image path
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600155 *
156 * @param[in] path - The path to remove the association from.
157 */
Lei YUf3ce4332019-02-21 14:09:49 +0800158 virtual void removeAssociation(const std::string& path);
Gunnar Mills9741cd12017-08-28 15:09:00 -0500159
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600160 /** @brief Persistent GardReset dbus object */
161 std::unique_ptr<GardReset> gardReset;
Michael Tritzb541f1b2017-10-15 15:10:21 -0500162
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600163 /** @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 YUf3ce4332019-02-21 14:09:49 +0800169 virtual bool isVersionFunctional(const std::string& versionId) = 0;
Michael Tritz5b756512017-10-06 16:52:01 -0500170
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600171 /** @brief Persistent ObjectEnable D-Bus object */
172 std::unique_ptr<ObjectEnable> volatileEnable;
Adriana Kobylak7cb480e2017-11-07 13:22:59 -0600173
Lei YUf3ce4332019-02-21 14:09:49 +0800174 protected:
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600175 /** @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 Williams0dea1992022-07-22 19:26:52 -0500180 virtual void createActivation(sdbusplus::message_t& msg);
Lei YUa9ac9272019-02-22 16:38:35 +0800181
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 Khan7254f0e2017-04-10 21:45:37 -0500201
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600202 /** @brief Persistent sdbusplus D-Bus bus connection. */
Patrick Williams0dea1992022-07-22 19:26:52 -0500203 sdbusplus::bus_t& bus;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500204
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600205 /** @brief Persistent map of Activation D-Bus objects and their
206 * version id */
207 std::map<std::string, std::unique_ptr<Activation>> activations;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500208
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600209 /** @brief Persistent map of Version D-Bus objects and their
210 * version id */
211 std::map<std::string, std::unique_ptr<Version>> versions;
Saqib Khance148702017-06-11 12:01:58 -0500212
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600213 /** @brief sdbusplus signal match for Software.Version */
214 sdbusplus::bus::match_t versionMatch;
Michael Tritzdd961b62017-05-17 14:07:03 -0500215
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600216 /** @brief This entry's associations */
217 AssociationList assocs = {};
Gunnar Mills9741cd12017-08-28 15:09:00 -0500218
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600219 /** @brief Host factory reset - clears PNOR partitions for each
220 * Activation D-Bus object */
Lei YUf3ce4332019-02-21 14:09:49 +0800221 void reset() override = 0;
Eddie James13fc66a2017-08-31 15:36:44 -0500222
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600223 /** @brief Check whether the host is running
224 *
225 * @return - Returns true if the Chassis is powered on.
226 */
227 bool isChassisOn();
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500228};
229
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500230} // namespace updater
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500231} // namespace software
232} // namespace openpower