blob: 55377b13532920c6bb3d24bcd4690da4aa395c9c [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 {
219 // Enable systemd signals
220 subscribeToSystemdSignals();
221 // Set Properties.
222 activation(activationStatus);
223 associations(assocs);
Gunnar Millsb60add12017-08-24 16:41:42 -0500224
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600225 // Emit deferred signal.
226 emit_object_added();
227 }
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500228
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600229 /** @brief Overloaded Activation property setter function
230 *
231 * @param[in] value - One of Activation::Activations
232 *
233 * @return Success or exception thrown
234 */
235 Activations activation(Activations value) override;
Saqib Khanb0774702017-05-23 16:02:41 -0500236
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600237 /** @brief Activation */
238 using ActivationInherit::activation;
Leonel Gonzaleze4233682017-07-07 14:38:25 -0500239
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600240 /** @brief Overloaded requestedActivation property setter function
241 *
242 * @param[in] value - One of Activation::RequestedActivations
243 *
244 * @return Success or exception thrown
245 */
246 RequestedActivations
247 requestedActivation(RequestedActivations value) override;
Saqib Khanb0774702017-05-23 16:02:41 -0500248
Adriana Kobylak9f89e2e2018-05-30 13:16:20 -0500249 /** @brief Overloaded write flash function */
250 void flashWrite() override;
251
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600252 /** @brief Check if systemd state change is relevant to this object
253 *
254 * Instance specific interface to handle the detected systemd state
255 * change
256 *
257 * @param[in] msg - Data associated with subscribed signal
258 *
259 */
260 void unitStateChange(sdbusplus::message::message& msg);
Michael Tritzbed88af2017-07-19 16:00:06 -0500261
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600262 /**
263 * @brief subscribe to the systemd signals
264 *
265 * This object needs to capture when it's systemd targets complete
266 * so it can keep it's state updated
267 *
268 */
269 void subscribeToSystemdSignals();
Michael Tritzbed88af2017-07-19 16:00:06 -0500270
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600271 /**
272 * @brief unsubscribe from the systemd signals
273 *
274 * systemd signals are only of interest during the activation process.
275 * Once complete, we want to unsubscribe to avoid unnecessary calls of
276 * unitStateChange().
277 *
278 */
279 void unsubscribeFromSystemdSignals();
Michael Tritzf2b5e0d2017-07-25 14:39:34 -0500280
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600281 /**
282 * @brief Deletes the version from Image Manager and the
283 * untar image from image upload dir.
284 */
285 void deleteImageManagerObject();
Saqib Khanee13e832017-10-23 12:53:11 -0500286
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600287 /** @brief Persistent sdbusplus DBus bus connection */
288 sdbusplus::bus::bus& bus;
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500289
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600290 /** @brief Persistent DBus object path */
291 std::string path;
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500292
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600293 /** @brief Parent Object. */
294 ItemUpdater& parent;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500295
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600296 /** @brief Version id */
297 std::string versionId;
Saqib Khanb0774702017-05-23 16:02:41 -0500298
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600299 /** @brief Persistent ActivationBlocksTransition dbus object */
300 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500301
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600302 /** @brief Persistent RedundancyPriority dbus object */
303 std::unique_ptr<RedundancyPriority> redundancyPriority;
Michael Tritzbed88af2017-07-19 16:00:06 -0500304
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600305 /** @brief Persistent ActivationProgress dbus object */
306 std::unique_ptr<ActivationProgress> activationProgress;
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500307
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600308 /** @brief Used to subscribe to dbus systemd signals **/
309 sdbusplus::bus::match_t systemdSignals;
Michael Tritzbed88af2017-07-19 16:00:06 -0500310
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600311 /** @brief Tracks whether the read-write volume has been created as
312 * part of the activation process. **/
313 bool rwVolumeCreated = false;
Michael Tritzbed88af2017-07-19 16:00:06 -0500314
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600315 /** @brief Tracks whether the read-only volume has been created as
316 * part of the activation process. **/
317 bool roVolumeCreated = false;
Adriana Kobylak166bdf32018-04-09 14:24:06 -0500318
319 /** @brief Tracks if the service that updates the U-Boot environment
320 * variables has completed. **/
321 bool ubootEnvVarsUpdated = false;
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500322};
323
324} // namespace updater
325} // namespace software
326} // namespace phosphor