blob: d104dc47311d111d461c391deb566f4f094deaee [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
Michael Tritzdd961b62017-05-17 14:07:03 -050021using ItemUpdaterInherit = sdbusplus::server::object::object<
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>;
Michael Tritzb541f1b2017-10-15 15:10:21 -050025using GardResetInherit = sdbusplus::server::object::object<
Adriana Kobylak70dcb632018-02-27 15:46:52 -060026 sdbusplus::xyz::openbmc_project::Common::server::FactoryReset>;
Adriana Kobylak7cb480e2017-11-07 13:22:59 -060027using ObjectEnable = sdbusplus::server::object::object<
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 */
50 GardReset(sdbusplus::bus::bus& 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
Lei YU716de5b2019-03-01 16:03:53 +080056 virtual ~GardReset()
Patrick Williams9c887d12022-04-05 21:39:40 -050057 {}
Michael Tritzb541f1b2017-10-15 15:10:21 -050058
Lei YU716de5b2019-03-01 16:03:53 +080059 protected:
Adriana Kobylak70dcb632018-02-27 15:46:52 -060060 // TODO Remove once openbmc/openbmc#1975 is resolved
61 static constexpr auto interface = "xyz.openbmc_project.Common.FactoryReset";
62 sdbusplus::bus::bus& bus;
63 std::string path;
Michael Tritzb541f1b2017-10-15 15:10:21 -050064
Adriana Kobylak70dcb632018-02-27 15:46:52 -060065 /**
66 * @brief GARD factory reset - clears the PNOR GARD partition.
67 */
Lei YU716de5b2019-03-01 16:03:53 +080068 virtual void reset() = 0;
Michael Tritzb541f1b2017-10-15 15:10:21 -050069};
70
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050071/** @class ItemUpdater
Gunnar Mills139cf1a2017-09-21 16:25:37 -050072 * @brief Manages the activation of the host version items.
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050073 */
Michael Tritzdd961b62017-05-17 14:07:03 -050074class ItemUpdater : public ItemUpdaterInherit
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050075{
Adriana Kobylak70dcb632018-02-27 15:46:52 -060076 public:
77 /** @brief Constructs ItemUpdater
78 *
79 * @param[in] bus - The D-Bus bus object
80 * @param[in] path - The D-Bus path
81 */
82 ItemUpdater(sdbusplus::bus::bus& bus, const std::string& path) :
83 ItemUpdaterInherit(bus, path.c_str()), bus(bus),
84 versionMatch(bus,
85 MatchRules::interfacesAdded() +
86 MatchRules::path("/xyz/openbmc_project/software"),
87 std::bind(std::mem_fn(&ItemUpdater::createActivation),
88 this, std::placeholders::_1))
Brad Bishop8facccf2020-11-04 09:44:58 -050089 {}
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050090
Lei YUf3ce4332019-02-21 14:09:49 +080091 virtual ~ItemUpdater() = default;
92
Adriana Kobylak70dcb632018-02-27 15:46:52 -060093 /** @brief Sets the given priority free by incrementing
Adriana Kobylakabe862a2019-07-17 16:09:00 -050094 * any existing priority with the same value by 1. It will then continue
95 * to resolve duplicate priorities caused by this increase, by increasing
96 * the priority by 1 until there are no more duplicate values.
Adriana Kobylak70dcb632018-02-27 15:46:52 -060097 *
98 * @param[in] value - The priority that needs to be set free.
99 * @param[in] versionId - The Id of the version for which we
100 * are trying to free up the priority.
101 * @return None
102 */
Lei YUf3ce4332019-02-21 14:09:49 +0800103 virtual void freePriority(uint8_t value, const std::string& versionId) = 0;
Saqib Khan81bac882017-06-08 12:17:01 -0500104
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600105 /**
106 * @brief Create and populate the active PNOR Version.
107 */
Lei YUf3ce4332019-02-21 14:09:49 +0800108 virtual void processPNORImage() = 0;
Saqib Khan167601b2017-06-18 23:33:46 -0500109
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600110 /** @brief Deletes version
111 *
112 * @param[in] entryId - Id of the version to delete
113 *
Lei YUf3ce4332019-02-21 14:09:49 +0800114 * @return - Returns true if the version is deleted.
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600115 */
Lei YUf3ce4332019-02-21 14:09:49 +0800116 virtual bool erase(std::string entryId);
Leonel Gonzalez9c8adfa2017-07-12 11:08:40 -0500117
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600118 /**
119 * @brief Erases any non-active pnor versions.
120 */
Lei YUf3ce4332019-02-21 14:09:49 +0800121 virtual void deleteAll() = 0;
Michael Tritz234a07e2017-09-21 00:53:06 -0500122
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600123 /** @brief Brings the total number of active PNOR versions to
124 * ACTIVE_PNOR_MAX_ALLOWED -1. This function is intended to be
125 * run before activating a new PNOR version. If this function
126 * needs to delete any PNOR version(s) it will delete the
127 * version(s) with the highest priority, skipping the
128 * functional PNOR version.
Lei YU6da3dae2019-02-28 14:26:37 +0800129 *
130 * @return - Return if space is freed or not
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600131 */
Lei YU6da3dae2019-02-28 14:26:37 +0800132 virtual bool freeSpace() = 0;
Saqib Khan2cbfa032017-08-17 14:52:37 -0500133
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600134 /** @brief Creates an active association to the
135 * newly active software image
136 *
137 * @param[in] path - The path to create the association to.
138 */
Lei YUf3ce4332019-02-21 14:09:49 +0800139 virtual void createActiveAssociation(const std::string& path);
Gunnar Mills9741cd12017-08-28 15:09:00 -0500140
Adriana Kobylak3c810372020-07-15 16:47:03 -0500141 /** @brief Creates a updateable association to the
142 * "running" BMC software image
143 *
144 * @param[in] path - The path to create the association.
145 */
146 virtual void createUpdateableAssociation(const std::string& path);
147
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600148 /** @brief Updates the functional association to the
149 * new "running" PNOR image
150 *
Lei YUf3ce4332019-02-21 14:09:49 +0800151 * @param[in] versionId - The id of the image to update the association to.
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600152 */
Lei YUf3ce4332019-02-21 14:09:49 +0800153 virtual void updateFunctionalAssociation(const std::string& versionId);
Gunnar Mills833e4f32017-09-14 12:30:27 -0500154
Adriana Kobylakb5237172018-10-30 14:51:53 -0500155 /** @brief Removes the associations from the provided software image path
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600156 *
157 * @param[in] path - The path to remove the association from.
158 */
Lei YUf3ce4332019-02-21 14:09:49 +0800159 virtual void removeAssociation(const std::string& path);
Gunnar Mills9741cd12017-08-28 15:09:00 -0500160
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600161 /** @brief Persistent GardReset dbus object */
162 std::unique_ptr<GardReset> gardReset;
Michael Tritzb541f1b2017-10-15 15:10:21 -0500163
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600164 /** @brief Check whether the provided image id is the functional one
165 *
166 * @param[in] - versionId - The id of the image to check.
167 *
168 * @return - Returns true if this version is currently functional.
169 */
Lei YUf3ce4332019-02-21 14:09:49 +0800170 virtual bool isVersionFunctional(const std::string& versionId) = 0;
Michael Tritz5b756512017-10-06 16:52:01 -0500171
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600172 /** @brief Persistent ObjectEnable D-Bus object */
173 std::unique_ptr<ObjectEnable> volatileEnable;
Adriana Kobylak7cb480e2017-11-07 13:22:59 -0600174
Lei YUf3ce4332019-02-21 14:09:49 +0800175 protected:
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600176 /** @brief Callback function for Software.Version match.
177 * @details Creates an Activation D-Bus object.
178 *
179 * @param[in] msg - Data associated with subscribed signal
180 */
Lei YUa9ac9272019-02-22 16:38:35 +0800181 virtual void createActivation(sdbusplus::message::message& msg);
182
183 /** @brief Create Activation object */
184 virtual std::unique_ptr<Activation> createActivationObject(
185 const std::string& path, const std::string& versionId,
186 const std::string& extVersion,
187 sdbusplus::xyz::openbmc_project::Software::server::Activation::
188 Activations activationStatus,
189 AssociationList& assocs) = 0;
190
191 /** @brief Create Version object */
192 virtual std::unique_ptr<Version>
193 createVersionObject(const std::string& objPath,
194 const std::string& versionId,
195 const std::string& versionString,
196 sdbusplus::xyz::openbmc_project::Software::server::
197 Version::VersionPurpose versionPurpose,
198 const std::string& filePath) = 0;
199
200 /** @brief Validate if image is valid or not */
201 virtual bool validateImage(const std::string& path) = 0;
Saqib Khan7254f0e2017-04-10 21:45:37 -0500202
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600203 /** @brief Persistent sdbusplus D-Bus bus connection. */
204 sdbusplus::bus::bus& bus;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500205
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600206 /** @brief Persistent map of Activation D-Bus objects and their
207 * version id */
208 std::map<std::string, std::unique_ptr<Activation>> activations;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500209
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600210 /** @brief Persistent map of Version D-Bus objects and their
211 * version id */
212 std::map<std::string, std::unique_ptr<Version>> versions;
Saqib Khance148702017-06-11 12:01:58 -0500213
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600214 /** @brief sdbusplus signal match for Software.Version */
215 sdbusplus::bus::match_t versionMatch;
Michael Tritzdd961b62017-05-17 14:07:03 -0500216
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600217 /** @brief This entry's associations */
218 AssociationList assocs = {};
Gunnar Mills9741cd12017-08-28 15:09:00 -0500219
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600220 /** @brief Host factory reset - clears PNOR partitions for each
221 * Activation D-Bus object */
Lei YUf3ce4332019-02-21 14:09:49 +0800222 void reset() override = 0;
Eddie James13fc66a2017-08-31 15:36:44 -0500223
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600224 /** @brief Check whether the host is running
225 *
226 * @return - Returns true if the Chassis is powered on.
227 */
228 bool isChassisOn();
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500229};
230
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500231} // namespace updater
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500232} // namespace software
233} // namespace openpower