blob: 3a00afed3570de40833f69b1aee465fa7438bf2d [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
12namespace openpower
13{
14namespace software
15{
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -050016namespace updater
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050017{
18
Michael Tritzdd961b62017-05-17 14:07:03 -050019using ItemUpdaterInherit = sdbusplus::server::object::object<
Adriana Kobylak70dcb632018-02-27 15:46:52 -060020 sdbusplus::xyz::openbmc_project::Common::server::FactoryReset,
John Wangd05d4722019-09-11 15:18:15 +080021 sdbusplus::xyz::openbmc_project::Association::server::Definitions,
Adriana Kobylak70dcb632018-02-27 15:46:52 -060022 sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll>;
Michael Tritzb541f1b2017-10-15 15:10:21 -050023using GardResetInherit = sdbusplus::server::object::object<
Adriana Kobylak70dcb632018-02-27 15:46:52 -060024 sdbusplus::xyz::openbmc_project::Common::server::FactoryReset>;
Adriana Kobylak7cb480e2017-11-07 13:22:59 -060025using ObjectEnable = sdbusplus::server::object::object<
Adriana Kobylak70dcb632018-02-27 15:46:52 -060026 sdbusplus::xyz::openbmc_project::Object::server::Enable>;
Patrick Williams3accb322017-05-30 16:29:52 -050027namespace MatchRules = sdbusplus::bus::match::rules;
Michael Tritzdd961b62017-05-17 14:07:03 -050028
Gunnar Mills9741cd12017-08-28 15:09:00 -050029using AssociationList =
Adriana Kobylak70dcb632018-02-27 15:46:52 -060030 std::vector<std::tuple<std::string, std::string, std::string>>;
Gunnar Mills9741cd12017-08-28 15:09:00 -050031
Michael Tritz4ecea0f2017-12-05 17:51:31 -060032constexpr auto GARD_PATH = "/org/open_power/control/gard";
Adriana Kobylak7cb480e2017-11-07 13:22:59 -060033constexpr static auto volatilePath = "/org/open_power/control/volatile";
Michael Tritzb541f1b2017-10-15 15:10:21 -050034
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 */
40class GardReset : public GardResetInherit
41{
Adriana Kobylak70dcb632018-02-27 15:46:52 -060042 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 Tritzb541f1b2017-10-15 15:10:21 -050054
Lei YU716de5b2019-03-01 16:03:53 +080055 virtual ~GardReset()
Adriana Kobylak70dcb632018-02-27 15:46:52 -060056 {
57 std::vector<std::string> interfaces({interface});
58 bus.emit_interfaces_removed(path.c_str(), interfaces);
59 }
Michael Tritzb541f1b2017-10-15 15:10:21 -050060
Lei YU716de5b2019-03-01 16:03:53 +080061 protected:
Adriana Kobylak70dcb632018-02-27 15:46:52 -060062 // 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 Tritzb541f1b2017-10-15 15:10:21 -050066
Adriana Kobylak70dcb632018-02-27 15:46:52 -060067 /**
68 * @brief GARD factory reset - clears the PNOR GARD partition.
69 */
Lei YU716de5b2019-03-01 16:03:53 +080070 virtual void reset() = 0;
Michael Tritzb541f1b2017-10-15 15:10:21 -050071};
72
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050073/** @class ItemUpdater
Gunnar Mills139cf1a2017-09-21 16:25:37 -050074 * @brief Manages the activation of the host version items.
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050075 */
Michael Tritzdd961b62017-05-17 14:07:03 -050076class ItemUpdater : public ItemUpdaterInherit
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050077{
Adriana Kobylak70dcb632018-02-27 15:46:52 -060078 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 {
Adriana Kobylak70dcb632018-02-27 15:46:52 -060092 }
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050093
Lei YUf3ce4332019-02-21 14:09:49 +080094 virtual ~ItemUpdater() = default;
95
Adriana Kobylak70dcb632018-02-27 15:46:52 -060096 /** @brief Sets the given priority free by incrementing
Adriana Kobylakabe862a2019-07-17 16:09:00 -050097 * any existing priority with the same value by 1. It will then continue
98 * to resolve duplicate priorities caused by this increase, by increasing
99 * the priority by 1 until there are no more duplicate values.
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600100 *
101 * @param[in] value - The priority that needs to be set free.
102 * @param[in] versionId - The Id of the version for which we
103 * are trying to free up the priority.
104 * @return None
105 */
Lei YUf3ce4332019-02-21 14:09:49 +0800106 virtual void freePriority(uint8_t value, const std::string& versionId) = 0;
Saqib Khan81bac882017-06-08 12:17:01 -0500107
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600108 /**
109 * @brief Create and populate the active PNOR Version.
110 */
Lei YUf3ce4332019-02-21 14:09:49 +0800111 virtual void processPNORImage() = 0;
Saqib Khan167601b2017-06-18 23:33:46 -0500112
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600113 /** @brief Deletes version
114 *
115 * @param[in] entryId - Id of the version to delete
116 *
Lei YUf3ce4332019-02-21 14:09:49 +0800117 * @return - Returns true if the version is deleted.
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600118 */
Lei YUf3ce4332019-02-21 14:09:49 +0800119 virtual bool erase(std::string entryId);
Leonel Gonzalez9c8adfa2017-07-12 11:08:40 -0500120
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600121 /**
122 * @brief Erases any non-active pnor versions.
123 */
Lei YUf3ce4332019-02-21 14:09:49 +0800124 virtual void deleteAll() = 0;
Michael Tritz234a07e2017-09-21 00:53:06 -0500125
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600126 /** @brief Brings the total number of active PNOR versions to
127 * ACTIVE_PNOR_MAX_ALLOWED -1. This function is intended to be
128 * run before activating a new PNOR version. If this function
129 * needs to delete any PNOR version(s) it will delete the
130 * version(s) with the highest priority, skipping the
131 * functional PNOR version.
Lei YU6da3dae2019-02-28 14:26:37 +0800132 *
133 * @return - Return if space is freed or not
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600134 */
Lei YU6da3dae2019-02-28 14:26:37 +0800135 virtual bool freeSpace() = 0;
Saqib Khan2cbfa032017-08-17 14:52:37 -0500136
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600137 /** @brief Creates an active association to the
138 * newly active software image
139 *
140 * @param[in] path - The path to create the association to.
141 */
Lei YUf3ce4332019-02-21 14:09:49 +0800142 virtual void createActiveAssociation(const std::string& path);
Gunnar Mills9741cd12017-08-28 15:09:00 -0500143
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600144 /** @brief Updates the functional association to the
145 * new "running" PNOR image
146 *
Lei YUf3ce4332019-02-21 14:09:49 +0800147 * @param[in] versionId - The id of the image to update the association to.
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600148 */
Lei YUf3ce4332019-02-21 14:09:49 +0800149 virtual void updateFunctionalAssociation(const std::string& versionId);
Gunnar Mills833e4f32017-09-14 12:30:27 -0500150
Adriana Kobylakb5237172018-10-30 14:51:53 -0500151 /** @brief Removes the associations from the provided software image path
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600152 *
153 * @param[in] path - The path to remove the association from.
154 */
Lei YUf3ce4332019-02-21 14:09:49 +0800155 virtual void removeAssociation(const std::string& path);
Gunnar Mills9741cd12017-08-28 15:09:00 -0500156
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600157 /** @brief Persistent GardReset dbus object */
158 std::unique_ptr<GardReset> gardReset;
Michael Tritzb541f1b2017-10-15 15:10:21 -0500159
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600160 /** @brief Check whether the provided image id is the functional one
161 *
162 * @param[in] - versionId - The id of the image to check.
163 *
164 * @return - Returns true if this version is currently functional.
165 */
Lei YUf3ce4332019-02-21 14:09:49 +0800166 virtual bool isVersionFunctional(const std::string& versionId) = 0;
Michael Tritz5b756512017-10-06 16:52:01 -0500167
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600168 /** @brief Persistent ObjectEnable D-Bus object */
169 std::unique_ptr<ObjectEnable> volatileEnable;
Adriana Kobylak7cb480e2017-11-07 13:22:59 -0600170
Lei YUf3ce4332019-02-21 14:09:49 +0800171 protected:
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600172 /** @brief Callback function for Software.Version match.
173 * @details Creates an Activation D-Bus object.
174 *
175 * @param[in] msg - Data associated with subscribed signal
176 */
Lei YUa9ac9272019-02-22 16:38:35 +0800177 virtual void createActivation(sdbusplus::message::message& msg);
178
179 /** @brief Create Activation object */
180 virtual std::unique_ptr<Activation> createActivationObject(
181 const std::string& path, const std::string& versionId,
182 const std::string& extVersion,
183 sdbusplus::xyz::openbmc_project::Software::server::Activation::
184 Activations activationStatus,
185 AssociationList& assocs) = 0;
186
187 /** @brief Create Version object */
188 virtual std::unique_ptr<Version>
189 createVersionObject(const std::string& objPath,
190 const std::string& versionId,
191 const std::string& versionString,
192 sdbusplus::xyz::openbmc_project::Software::server::
193 Version::VersionPurpose versionPurpose,
194 const std::string& filePath) = 0;
195
196 /** @brief Validate if image is valid or not */
197 virtual bool validateImage(const std::string& path) = 0;
Saqib Khan7254f0e2017-04-10 21:45:37 -0500198
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600199 /** @brief Persistent sdbusplus D-Bus bus connection. */
200 sdbusplus::bus::bus& bus;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500201
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600202 /** @brief Persistent map of Activation D-Bus objects and their
203 * version id */
204 std::map<std::string, std::unique_ptr<Activation>> activations;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500205
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600206 /** @brief Persistent map of Version D-Bus objects and their
207 * version id */
208 std::map<std::string, std::unique_ptr<Version>> versions;
Saqib Khance148702017-06-11 12:01:58 -0500209
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600210 /** @brief sdbusplus signal match for Software.Version */
211 sdbusplus::bus::match_t versionMatch;
Michael Tritzdd961b62017-05-17 14:07:03 -0500212
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600213 /** @brief This entry's associations */
214 AssociationList assocs = {};
Gunnar Mills9741cd12017-08-28 15:09:00 -0500215
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600216 /** @brief Host factory reset - clears PNOR partitions for each
217 * Activation D-Bus object */
Lei YUf3ce4332019-02-21 14:09:49 +0800218 void reset() override = 0;
Eddie James13fc66a2017-08-31 15:36:44 -0500219
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600220 /** @brief Check whether the host is running
221 *
222 * @return - Returns true if the Chassis is powered on.
223 */
224 bool isChassisOn();
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500225};
226
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500227} // namespace updater
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500228} // namespace software
229} // namespace openpower