blob: ba7c6188f6d90597585d537b62ca9fd779875804 [file] [log] [blame]
Gunnar Millsec1b41c2017-05-02 12:20:36 -05001#pragma once
2
Saqib Khanb0774702017-05-23 16:02:41 -05003#include <sdbusplus/server.hpp>
Gunnar Millsec1b41c2017-05-02 12:20:36 -05004#include <xyz/openbmc_project/Software/Activation/server.hpp>
Saqib Khanb0774702017-05-23 16:02:41 -05005#include <xyz/openbmc_project/Software/ActivationBlocksTransition/server.hpp>
Adriana Kobylak9f89e2e2018-05-30 13:16:20 -05006#include "flash.hpp"
Saqib Khan4c1aec02017-07-06 11:46:13 -05007#include "xyz/openbmc_project/Software/RedundancyPriority/server.hpp"
Michael Tritz0edd4ad2017-07-26 14:27:42 -05008#include "xyz/openbmc_project/Software/ActivationProgress/server.hpp"
Gunnar Millsf5eaf392017-08-22 16:36:55 -05009#include "org/openbmc/Associations/server.hpp"
Gunnar Millsec1b41c2017-05-02 12:20:36 -050010
11namespace phosphor
12{
13namespace software
14{
15namespace updater
16{
17
Gunnar Millsb60add12017-08-24 16:41:42 -050018using AssociationList =
Adriana Kobylak2285fe02018-02-27 15:36:59 -060019 std::vector<std::tuple<std::string, std::string, std::string>>;
Gunnar Millsec1b41c2017-05-02 12:20:36 -050020using ActivationInherit = sdbusplus::server::object::object<
Gunnar Millsf5eaf392017-08-22 16:36:55 -050021 sdbusplus::xyz::openbmc_project::Software::server::Activation,
Michael Tritz4254bec2017-10-03 17:18:22 -050022 sdbusplus::org::openbmc::server::Associations>;
Saqib Khanb0774702017-05-23 16:02:41 -050023using ActivationBlocksTransitionInherit = sdbusplus::server::object::object<
Adriana Kobylak2285fe02018-02-27 15:36:59 -060024 sdbusplus::xyz::openbmc_project::Software::server::
25 ActivationBlocksTransition>;
Saqib Khan4c1aec02017-07-06 11:46:13 -050026using RedundancyPriorityInherit = sdbusplus::server::object::object<
27 sdbusplus::xyz::openbmc_project::Software::server::RedundancyPriority>;
Michael Tritz0edd4ad2017-07-26 14:27:42 -050028using ActivationProgressInherit = sdbusplus::server::object::object<
29 sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>;
Saqib Khan4c1aec02017-07-06 11:46:13 -050030
Michael Tritzbed88af2017-07-19 16:00:06 -050031namespace sdbusRule = sdbusplus::bus::match::rules;
32
Saqib Khan4c1aec02017-07-06 11:46:13 -050033class ItemUpdater;
34class Activation;
35class RedundancyPriority;
36
37/** @class RedundancyPriority
38 * @brief OpenBMC RedundancyPriority implementation
39 * @details A concrete implementation for
40 * xyz.openbmc_project.Software.RedundancyPriority DBus API.
41 */
42class RedundancyPriority : public RedundancyPriorityInherit
43{
Adriana Kobylak2285fe02018-02-27 15:36:59 -060044 public:
45 /** @brief Constructs RedundancyPriority.
46 *
47 * @param[in] bus - The Dbus bus object
48 * @param[in] path - The Dbus object path
49 * @param[in] parent - Parent object.
50 * @param[in] value - The redundancyPriority value
51 * @param[in] freePriority - Call freePriorioty, default to true
52 */
53 RedundancyPriority(sdbusplus::bus::bus& bus, const std::string& path,
54 Activation& parent, uint8_t value,
55 bool freePriority = true) :
56 RedundancyPriorityInherit(bus, path.c_str(), true),
57 parent(parent), bus(bus), path(path)
58 {
59 // Set Property
60 if (freePriority)
Saqib Khan4c1aec02017-07-06 11:46:13 -050061 {
Adriana Kobylak2285fe02018-02-27 15:36:59 -060062 priority(value);
63 }
64 else
65 {
66 sdbusPriority(value);
Saqib Khan140fcb12017-08-07 09:06:57 -050067 }
68
Adriana Kobylak2285fe02018-02-27 15:36:59 -060069 std::vector<std::string> interfaces({interface});
70 bus.emit_interfaces_added(path.c_str(), interfaces);
71 }
Saqib Khan4c1aec02017-07-06 11:46:13 -050072
Adriana Kobylak2285fe02018-02-27 15:36:59 -060073 ~RedundancyPriority()
74 {
75 std::vector<std::string> interfaces({interface});
76 bus.emit_interfaces_removed(path.c_str(), interfaces);
77 }
Saqib Khan4c1aec02017-07-06 11:46:13 -050078
Gunnar Millse11a2022018-03-23 12:04:48 -050079 /** @brief Overridden Priority property set function, calls freePriority
Adriana Kobylak2285fe02018-02-27 15:36:59 -060080 * to bump the duplicated priority values.
81 *
82 * @param[in] value - uint8_t
83 *
84 * @return Success or exception thrown
85 */
86 uint8_t priority(uint8_t value) override;
Adriana Kobylakb77551c2017-10-27 12:46:23 -050087
Adriana Kobylak2285fe02018-02-27 15:36:59 -060088 /** @brief Non-Overriden Priority property set function
89 *
90 * @param[in] value - uint8_t
91 *
92 * @return Success or exception thrown
93 */
94 uint8_t sdbusPriority(uint8_t value);
Saqib Khan4c1aec02017-07-06 11:46:13 -050095
Adriana Kobylak2285fe02018-02-27 15:36:59 -060096 /** @brief Priority property get function
97 *
98 * @returns uint8_t - The Priority value
99 */
100 using RedundancyPriorityInherit::priority;
Saqib Khan140fcb12017-08-07 09:06:57 -0500101
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600102 /** @brief Parent Object. */
103 Activation& parent;
104
105 private:
106 // TODO Remove once openbmc/openbmc#1975 is resolved
107 static constexpr auto interface =
108 "xyz.openbmc_project.Software.RedundancyPriority";
109 sdbusplus::bus::bus& bus;
110 std::string path;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500111};
Saqib Khanb0774702017-05-23 16:02:41 -0500112
113/** @class ActivationBlocksTransition
114 * @brief OpenBMC ActivationBlocksTransition implementation.
115 * @details A concrete implementation for
116 * xyz.openbmc_project.Software.ActivationBlocksTransition DBus API.
117 */
118class ActivationBlocksTransition : public ActivationBlocksTransitionInherit
119{
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600120 public:
121 /** @brief Constructs ActivationBlocksTransition.
122 *
123 * @param[in] bus - The Dbus bus object
124 * @param[in] path - The Dbus object path
125 */
126 ActivationBlocksTransition(sdbusplus::bus::bus& bus,
127 const std::string& path) :
128 ActivationBlocksTransitionInherit(bus, path.c_str(), true),
129 bus(bus), path(path)
130 {
131 std::vector<std::string> interfaces({interface});
132 bus.emit_interfaces_added(path.c_str(), interfaces);
133 enableRebootGuard();
134 }
Saqib Khan140fcb12017-08-07 09:06:57 -0500135
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600136 ~ActivationBlocksTransition()
137 {
138 std::vector<std::string> interfaces({interface});
139 bus.emit_interfaces_removed(path.c_str(), interfaces);
140 disableRebootGuard();
141 }
Saqib Khan140fcb12017-08-07 09:06:57 -0500142
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600143 private:
144 // TODO Remove once openbmc/openbmc#1975 is resolved
145 static constexpr auto interface =
146 "xyz.openbmc_project.Software.ActivationBlocksTransition";
147 sdbusplus::bus::bus& bus;
148 std::string path;
Saqib Khanf37cefc2017-09-12 08:44:41 -0500149
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600150 /** @brief Enables a Guard that blocks any BMC reboot commands */
151 void enableRebootGuard();
Saqib Khanf37cefc2017-09-12 08:44:41 -0500152
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600153 /** @brief Disables any guard that was blocking the BMC reboot */
154 void disableRebootGuard();
Saqib Khanb0774702017-05-23 16:02:41 -0500155};
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500156
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500157class ActivationProgress : public ActivationProgressInherit
158{
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600159 public:
160 /** @brief Constructs ActivationProgress.
161 *
162 * @param[in] bus - The Dbus bus object
163 * @param[in] path - The Dbus object path
164 */
165 ActivationProgress(sdbusplus::bus::bus& bus, const std::string& path) :
166 ActivationProgressInherit(bus, path.c_str(), true), bus(bus), path(path)
167 {
168 progress(0);
169 std::vector<std::string> interfaces({interface});
170 bus.emit_interfaces_added(path.c_str(), interfaces);
171 }
Saqib Khan140fcb12017-08-07 09:06:57 -0500172
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600173 ~ActivationProgress()
174 {
175 std::vector<std::string> interfaces({interface});
176 bus.emit_interfaces_removed(path.c_str(), interfaces);
177 }
Saqib Khan140fcb12017-08-07 09:06:57 -0500178
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600179 private:
180 // TODO Remove once openbmc/openbmc#1975 is resolved
181 static constexpr auto interface =
182 "xyz.openbmc_project.Software.ActivationProgress";
183 sdbusplus::bus::bus& bus;
184 std::string path;
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500185};
186
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500187/** @class Activation
188 * @brief OpenBMC activation software management implementation.
189 * @details A concrete implementation for
190 * xyz.openbmc_project.Software.Activation DBus API.
191 */
Adriana Kobylak9f89e2e2018-05-30 13:16:20 -0500192class Activation : public ActivationInherit, Flash
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500193{
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600194 public:
195 /** @brief Constructs Activation Software Manager
196 *
197 * @param[in] bus - The Dbus bus object
198 * @param[in] path - The Dbus object path
199 * @param[in] parent - Parent object.
200 * @param[in] versionId - The software version id
201 * @param[in] activationStatus - The status of Activation
202 * @param[in] assocs - Association objects
203 */
204 Activation(sdbusplus::bus::bus& bus, const std::string& path,
205 ItemUpdater& parent, std::string& versionId,
206 sdbusplus::xyz::openbmc_project::Software::server::Activation::
207 Activations activationStatus,
208 AssociationList& assocs) :
209 ActivationInherit(bus, path.c_str(), true),
210 bus(bus), path(path), parent(parent), versionId(versionId),
211 systemdSignals(
212 bus,
213 sdbusRule::type::signal() + sdbusRule::member("JobRemoved") +
214 sdbusRule::path("/org/freedesktop/systemd1") +
215 sdbusRule::interface("org.freedesktop.systemd1.Manager"),
216 std::bind(std::mem_fn(&Activation::unitStateChange), this,
217 std::placeholders::_1))
218 {
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600219 // Set Properties.
220 activation(activationStatus);
221 associations(assocs);
Gunnar Millsb60add12017-08-24 16:41:42 -0500222
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600223 // Emit deferred signal.
224 emit_object_added();
225 }
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500226
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600227 /** @brief Overloaded Activation property setter function
228 *
229 * @param[in] value - One of Activation::Activations
230 *
231 * @return Success or exception thrown
232 */
233 Activations activation(Activations value) override;
Saqib Khanb0774702017-05-23 16:02:41 -0500234
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600235 /** @brief Activation */
236 using ActivationInherit::activation;
Leonel Gonzaleze4233682017-07-07 14:38:25 -0500237
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600238 /** @brief Overloaded requestedActivation property setter function
239 *
240 * @param[in] value - One of Activation::RequestedActivations
241 *
242 * @return Success or exception thrown
243 */
244 RequestedActivations
245 requestedActivation(RequestedActivations value) override;
Saqib Khanb0774702017-05-23 16:02:41 -0500246
Adriana Kobylak9f89e2e2018-05-30 13:16:20 -0500247 /** @brief Overloaded write flash function */
248 void flashWrite() override;
249
Adriana Kobylak3ce563a2018-06-06 16:41:15 -0500250 /** @brief Overloaded function that acts on service file state changes */
251 void onStateChanges(sdbusplus::message::message&) override;
252
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600253 /** @brief Check if systemd state change is relevant to this object
254 *
255 * Instance specific interface to handle the detected systemd state
256 * change
257 *
258 * @param[in] msg - Data associated with subscribed signal
259 *
260 */
261 void unitStateChange(sdbusplus::message::message& msg);
Michael Tritzbed88af2017-07-19 16:00:06 -0500262
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600263 /**
264 * @brief subscribe to the systemd signals
265 *
266 * This object needs to capture when it's systemd targets complete
267 * so it can keep it's state updated
268 *
269 */
270 void subscribeToSystemdSignals();
Michael Tritzbed88af2017-07-19 16:00:06 -0500271
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600272 /**
273 * @brief unsubscribe from the systemd signals
274 *
275 * systemd signals are only of interest during the activation process.
276 * Once complete, we want to unsubscribe to avoid unnecessary calls of
277 * unitStateChange().
278 *
279 */
280 void unsubscribeFromSystemdSignals();
Michael Tritzf2b5e0d2017-07-25 14:39:34 -0500281
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600282 /**
283 * @brief Deletes the version from Image Manager and the
284 * untar image from image upload dir.
285 */
286 void deleteImageManagerObject();
Saqib Khanee13e832017-10-23 12:53:11 -0500287
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600288 /** @brief Persistent sdbusplus DBus bus connection */
289 sdbusplus::bus::bus& bus;
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500290
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600291 /** @brief Persistent DBus object path */
292 std::string path;
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500293
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600294 /** @brief Parent Object. */
295 ItemUpdater& parent;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500296
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600297 /** @brief Version id */
298 std::string versionId;
Saqib Khanb0774702017-05-23 16:02:41 -0500299
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600300 /** @brief Persistent ActivationBlocksTransition dbus object */
301 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500302
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600303 /** @brief Persistent RedundancyPriority dbus object */
304 std::unique_ptr<RedundancyPriority> redundancyPriority;
Michael Tritzbed88af2017-07-19 16:00:06 -0500305
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600306 /** @brief Persistent ActivationProgress dbus object */
307 std::unique_ptr<ActivationProgress> activationProgress;
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500308
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600309 /** @brief Used to subscribe to dbus systemd signals **/
310 sdbusplus::bus::match_t systemdSignals;
Michael Tritzbed88af2017-07-19 16:00:06 -0500311
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600312 /** @brief Tracks whether the read-write volume has been created as
313 * part of the activation process. **/
314 bool rwVolumeCreated = false;
Michael Tritzbed88af2017-07-19 16:00:06 -0500315
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600316 /** @brief Tracks whether the read-only volume has been created as
317 * part of the activation process. **/
318 bool roVolumeCreated = false;
Adriana Kobylak166bdf32018-04-09 14:24:06 -0500319
320 /** @brief Tracks if the service that updates the U-Boot environment
321 * variables has completed. **/
322 bool ubootEnvVarsUpdated = false;
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500323};
324
325} // namespace updater
326} // namespace software
327} // namespace phosphor