blob: 1fcb2d0b5524657331749e4bf315fb6dbaff4a69 [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>
Andrew Geisslerab139ce2020-05-16 13:22:09 -05008#include <string>
John Wangd05d4722019-09-11 15:18:15 +08009#include <xyz/openbmc_project/Association/Definitions/server.hpp>
Michael Tritzdd961b62017-05-17 14:07:03 -050010#include <xyz/openbmc_project/Common/FactoryReset/server.hpp>
Adriana Kobylak7cb480e2017-11-07 13:22:59 -060011#include <xyz/openbmc_project/Object/Enable/server.hpp>
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050012
13namespace openpower
14{
15namespace software
16{
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -050017namespace updater
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050018{
19
Michael Tritzdd961b62017-05-17 14:07:03 -050020using ItemUpdaterInherit = sdbusplus::server::object::object<
Adriana Kobylak70dcb632018-02-27 15:46:52 -060021 sdbusplus::xyz::openbmc_project::Common::server::FactoryReset,
John Wangd05d4722019-09-11 15:18:15 +080022 sdbusplus::xyz::openbmc_project::Association::server::Definitions,
Adriana Kobylak70dcb632018-02-27 15:46:52 -060023 sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll>;
Michael Tritzb541f1b2017-10-15 15:10:21 -050024using GardResetInherit = sdbusplus::server::object::object<
Adriana Kobylak70dcb632018-02-27 15:46:52 -060025 sdbusplus::xyz::openbmc_project::Common::server::FactoryReset>;
Adriana Kobylak7cb480e2017-11-07 13:22:59 -060026using ObjectEnable = sdbusplus::server::object::object<
Adriana Kobylak70dcb632018-02-27 15:46:52 -060027 sdbusplus::xyz::openbmc_project::Object::server::Enable>;
Patrick Williams3accb322017-05-30 16:29:52 -050028namespace MatchRules = sdbusplus::bus::match::rules;
Michael Tritzdd961b62017-05-17 14:07:03 -050029
Gunnar Mills9741cd12017-08-28 15:09:00 -050030using AssociationList =
Adriana Kobylak70dcb632018-02-27 15:46:52 -060031 std::vector<std::tuple<std::string, std::string, std::string>>;
Gunnar Mills9741cd12017-08-28 15:09:00 -050032
Michael Tritz4ecea0f2017-12-05 17:51:31 -060033constexpr auto GARD_PATH = "/org/open_power/control/gard";
Adriana Kobylak7cb480e2017-11-07 13:22:59 -060034constexpr static auto volatilePath = "/org/open_power/control/volatile";
Michael Tritzb541f1b2017-10-15 15:10:21 -050035
36/** @class GardReset
37 * @brief OpenBMC GARD factory reset implementation.
38 * @details An implementation of xyz.openbmc_project.Common.FactoryReset under
39 * /org/openpower/control/gard.
40 */
41class GardReset : public GardResetInherit
42{
Adriana Kobylak70dcb632018-02-27 15:46:52 -060043 public:
44 /** @brief Constructs GardReset.
45 *
46 * @param[in] bus - The Dbus bus object
47 * @param[in] path - The Dbus object path
48 */
49 GardReset(sdbusplus::bus::bus& bus, const std::string& path) :
50 GardResetInherit(bus, path.c_str(), true), bus(bus), path(path)
51 {
52 std::vector<std::string> interfaces({interface});
53 bus.emit_interfaces_added(path.c_str(), interfaces);
54 }
Michael Tritzb541f1b2017-10-15 15:10:21 -050055
Lei YU716de5b2019-03-01 16:03:53 +080056 virtual ~GardReset()
Adriana Kobylak70dcb632018-02-27 15:46:52 -060057 {
58 std::vector<std::string> interfaces({interface});
59 bus.emit_interfaces_removed(path.c_str(), interfaces);
60 }
Michael Tritzb541f1b2017-10-15 15:10:21 -050061
Lei YU716de5b2019-03-01 16:03:53 +080062 protected:
Adriana Kobylak70dcb632018-02-27 15:46:52 -060063 // TODO Remove once openbmc/openbmc#1975 is resolved
64 static constexpr auto interface = "xyz.openbmc_project.Common.FactoryReset";
65 sdbusplus::bus::bus& bus;
66 std::string path;
Michael Tritzb541f1b2017-10-15 15:10:21 -050067
Adriana Kobylak70dcb632018-02-27 15:46:52 -060068 /**
69 * @brief GARD factory reset - clears the PNOR GARD partition.
70 */
Lei YU716de5b2019-03-01 16:03:53 +080071 virtual void reset() = 0;
Michael Tritzb541f1b2017-10-15 15:10:21 -050072};
73
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050074/** @class ItemUpdater
Gunnar Mills139cf1a2017-09-21 16:25:37 -050075 * @brief Manages the activation of the host version items.
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050076 */
Michael Tritzdd961b62017-05-17 14:07:03 -050077class ItemUpdater : public ItemUpdaterInherit
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050078{
Adriana Kobylak70dcb632018-02-27 15:46:52 -060079 public:
80 /** @brief Constructs ItemUpdater
81 *
82 * @param[in] bus - The D-Bus bus object
83 * @param[in] path - The D-Bus path
84 */
85 ItemUpdater(sdbusplus::bus::bus& bus, const std::string& path) :
86 ItemUpdaterInherit(bus, path.c_str()), bus(bus),
87 versionMatch(bus,
88 MatchRules::interfacesAdded() +
89 MatchRules::path("/xyz/openbmc_project/software"),
90 std::bind(std::mem_fn(&ItemUpdater::createActivation),
91 this, std::placeholders::_1))
92 {
Adriana Kobylak70dcb632018-02-27 15:46:52 -060093 }
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050094
Lei YUf3ce4332019-02-21 14:09:49 +080095 virtual ~ItemUpdater() = default;
96
Adriana Kobylak70dcb632018-02-27 15:46:52 -060097 /** @brief Sets the given priority free by incrementing
Adriana Kobylakabe862a2019-07-17 16:09:00 -050098 * any existing priority with the same value by 1. It will then continue
99 * to resolve duplicate priorities caused by this increase, by increasing
100 * the priority by 1 until there are no more duplicate values.
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600101 *
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 */
Lei YUf3ce4332019-02-21 14:09:49 +0800107 virtual void freePriority(uint8_t value, const std::string& versionId) = 0;
Saqib Khan81bac882017-06-08 12:17:01 -0500108
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600109 /**
110 * @brief Create and populate the active PNOR Version.
111 */
Lei YUf3ce4332019-02-21 14:09:49 +0800112 virtual void processPNORImage() = 0;
Saqib Khan167601b2017-06-18 23:33:46 -0500113
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600114 /** @brief Deletes version
115 *
116 * @param[in] entryId - Id of the version to delete
117 *
Lei YUf3ce4332019-02-21 14:09:49 +0800118 * @return - Returns true if the version is deleted.
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600119 */
Lei YUf3ce4332019-02-21 14:09:49 +0800120 virtual bool erase(std::string entryId);
Leonel Gonzalez9c8adfa2017-07-12 11:08:40 -0500121
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600122 /**
123 * @brief Erases any non-active pnor versions.
124 */
Lei YUf3ce4332019-02-21 14:09:49 +0800125 virtual void deleteAll() = 0;
Michael Tritz234a07e2017-09-21 00:53:06 -0500126
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600127 /** @brief Brings the total number of active PNOR versions to
128 * ACTIVE_PNOR_MAX_ALLOWED -1. This function is intended to be
129 * run before activating a new PNOR version. If this function
130 * needs to delete any PNOR version(s) it will delete the
131 * version(s) with the highest priority, skipping the
132 * functional PNOR version.
Lei YU6da3dae2019-02-28 14:26:37 +0800133 *
134 * @return - Return if space is freed or not
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600135 */
Lei YU6da3dae2019-02-28 14:26:37 +0800136 virtual bool freeSpace() = 0;
Saqib Khan2cbfa032017-08-17 14:52:37 -0500137
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600138 /** @brief Creates an active association to the
139 * newly active software image
140 *
141 * @param[in] path - The path to create the association to.
142 */
Lei YUf3ce4332019-02-21 14:09:49 +0800143 virtual void createActiveAssociation(const std::string& path);
Gunnar Mills9741cd12017-08-28 15:09:00 -0500144
Adriana Kobylak3c810372020-07-15 16:47:03 -0500145 /** @brief Creates a updateable association to the
146 * "running" BMC software image
147 *
148 * @param[in] path - The path to create the association.
149 */
150 virtual void createUpdateableAssociation(const std::string& path);
151
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600152 /** @brief Updates the functional association to the
153 * new "running" PNOR image
154 *
Lei YUf3ce4332019-02-21 14:09:49 +0800155 * @param[in] versionId - The id of the image to update the association to.
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600156 */
Lei YUf3ce4332019-02-21 14:09:49 +0800157 virtual void updateFunctionalAssociation(const std::string& versionId);
Gunnar Mills833e4f32017-09-14 12:30:27 -0500158
Adriana Kobylakb5237172018-10-30 14:51:53 -0500159 /** @brief Removes the associations from the provided software image path
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600160 *
161 * @param[in] path - The path to remove the association from.
162 */
Lei YUf3ce4332019-02-21 14:09:49 +0800163 virtual void removeAssociation(const std::string& path);
Gunnar Mills9741cd12017-08-28 15:09:00 -0500164
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600165 /** @brief Persistent GardReset dbus object */
166 std::unique_ptr<GardReset> gardReset;
Michael Tritzb541f1b2017-10-15 15:10:21 -0500167
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600168 /** @brief Check whether the provided image id is the functional one
169 *
170 * @param[in] - versionId - The id of the image to check.
171 *
172 * @return - Returns true if this version is currently functional.
173 */
Lei YUf3ce4332019-02-21 14:09:49 +0800174 virtual bool isVersionFunctional(const std::string& versionId) = 0;
Michael Tritz5b756512017-10-06 16:52:01 -0500175
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600176 /** @brief Persistent ObjectEnable D-Bus object */
177 std::unique_ptr<ObjectEnable> volatileEnable;
Adriana Kobylak7cb480e2017-11-07 13:22:59 -0600178
Lei YUf3ce4332019-02-21 14:09:49 +0800179 protected:
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600180 /** @brief Callback function for Software.Version match.
181 * @details Creates an Activation D-Bus object.
182 *
183 * @param[in] msg - Data associated with subscribed signal
184 */
Lei YUa9ac9272019-02-22 16:38:35 +0800185 virtual void createActivation(sdbusplus::message::message& msg);
186
187 /** @brief Create Activation object */
188 virtual std::unique_ptr<Activation> createActivationObject(
189 const std::string& path, const std::string& versionId,
190 const std::string& extVersion,
191 sdbusplus::xyz::openbmc_project::Software::server::Activation::
192 Activations activationStatus,
193 AssociationList& assocs) = 0;
194
195 /** @brief Create Version object */
196 virtual std::unique_ptr<Version>
197 createVersionObject(const std::string& objPath,
198 const std::string& versionId,
199 const std::string& versionString,
200 sdbusplus::xyz::openbmc_project::Software::server::
201 Version::VersionPurpose versionPurpose,
202 const std::string& filePath) = 0;
203
204 /** @brief Validate if image is valid or not */
205 virtual bool validateImage(const std::string& path) = 0;
Saqib Khan7254f0e2017-04-10 21:45:37 -0500206
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600207 /** @brief Persistent sdbusplus D-Bus bus connection. */
208 sdbusplus::bus::bus& bus;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500209
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600210 /** @brief Persistent map of Activation D-Bus objects and their
211 * version id */
212 std::map<std::string, std::unique_ptr<Activation>> activations;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500213
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600214 /** @brief Persistent map of Version D-Bus objects and their
215 * version id */
216 std::map<std::string, std::unique_ptr<Version>> versions;
Saqib Khance148702017-06-11 12:01:58 -0500217
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600218 /** @brief sdbusplus signal match for Software.Version */
219 sdbusplus::bus::match_t versionMatch;
Michael Tritzdd961b62017-05-17 14:07:03 -0500220
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600221 /** @brief This entry's associations */
222 AssociationList assocs = {};
Gunnar Mills9741cd12017-08-28 15:09:00 -0500223
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600224 /** @brief Host factory reset - clears PNOR partitions for each
225 * Activation D-Bus object */
Lei YUf3ce4332019-02-21 14:09:49 +0800226 void reset() override = 0;
Eddie James13fc66a2017-08-31 15:36:44 -0500227
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600228 /** @brief Check whether the host is running
229 *
230 * @return - Returns true if the Chassis is powered on.
231 */
232 bool isChassisOn();
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500233};
234
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500235} // namespace updater
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500236} // namespace software
237} // namespace openpower