blob: 27dfdd46c852d0a7f555fee244af2d9063efe154 [file] [log] [blame]
Gunnar Millsec1b41c2017-05-02 12:20:36 -05001#pragma once
2
Gunnar Millsb0ce9962018-09-07 13:39:10 -05003#include "config.h"
4
5#include "flash.hpp"
6#include "org/openbmc/Associations/server.hpp"
7#include "xyz/openbmc_project/Software/ActivationProgress/server.hpp"
8#include "xyz/openbmc_project/Software/RedundancyPriority/server.hpp"
9
Saqib Khanb0774702017-05-23 16:02:41 -050010#include <sdbusplus/server.hpp>
Gunnar Millsec1b41c2017-05-02 12:20:36 -050011#include <xyz/openbmc_project/Software/Activation/server.hpp>
Saqib Khanb0774702017-05-23 16:02:41 -050012#include <xyz/openbmc_project/Software/ActivationBlocksTransition/server.hpp>
Lei YU90532252018-05-24 11:15:24 +080013
14#ifdef WANT_SIGNATURE_VERIFY
15#include <experimental/filesystem>
16#endif
17
Gunnar Millsec1b41c2017-05-02 12:20:36 -050018namespace phosphor
19{
20namespace software
21{
22namespace updater
23{
24
Lei YU90532252018-05-24 11:15:24 +080025#ifdef WANT_SIGNATURE_VERIFY
26namespace fs = std::experimental::filesystem;
27#endif
28
Gunnar Millsb60add12017-08-24 16:41:42 -050029using AssociationList =
Adriana Kobylak2285fe02018-02-27 15:36:59 -060030 std::vector<std::tuple<std::string, std::string, std::string>>;
Gunnar Millsec1b41c2017-05-02 12:20:36 -050031using ActivationInherit = sdbusplus::server::object::object<
Gunnar Millsf5eaf392017-08-22 16:36:55 -050032 sdbusplus::xyz::openbmc_project::Software::server::Activation,
Michael Tritz4254bec2017-10-03 17:18:22 -050033 sdbusplus::org::openbmc::server::Associations>;
Saqib Khanb0774702017-05-23 16:02:41 -050034using ActivationBlocksTransitionInherit = sdbusplus::server::object::object<
Adriana Kobylak2285fe02018-02-27 15:36:59 -060035 sdbusplus::xyz::openbmc_project::Software::server::
36 ActivationBlocksTransition>;
Saqib Khan4c1aec02017-07-06 11:46:13 -050037using RedundancyPriorityInherit = sdbusplus::server::object::object<
38 sdbusplus::xyz::openbmc_project::Software::server::RedundancyPriority>;
Michael Tritz0edd4ad2017-07-26 14:27:42 -050039using ActivationProgressInherit = sdbusplus::server::object::object<
40 sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>;
Saqib Khan4c1aec02017-07-06 11:46:13 -050041
Michael Tritzbed88af2017-07-19 16:00:06 -050042namespace sdbusRule = sdbusplus::bus::match::rules;
43
Saqib Khan4c1aec02017-07-06 11:46:13 -050044class ItemUpdater;
45class Activation;
46class RedundancyPriority;
47
48/** @class RedundancyPriority
49 * @brief OpenBMC RedundancyPriority implementation
50 * @details A concrete implementation for
51 * xyz.openbmc_project.Software.RedundancyPriority DBus API.
52 */
53class RedundancyPriority : public RedundancyPriorityInherit
54{
Adriana Kobylak2285fe02018-02-27 15:36:59 -060055 public:
56 /** @brief Constructs RedundancyPriority.
57 *
58 * @param[in] bus - The Dbus bus object
59 * @param[in] path - The Dbus object path
60 * @param[in] parent - Parent object.
61 * @param[in] value - The redundancyPriority value
62 * @param[in] freePriority - Call freePriorioty, default to true
63 */
64 RedundancyPriority(sdbusplus::bus::bus& bus, const std::string& path,
65 Activation& parent, uint8_t value,
66 bool freePriority = true) :
67 RedundancyPriorityInherit(bus, path.c_str(), true),
68 parent(parent), bus(bus), path(path)
69 {
70 // Set Property
71 if (freePriority)
Saqib Khan4c1aec02017-07-06 11:46:13 -050072 {
Adriana Kobylak2285fe02018-02-27 15:36:59 -060073 priority(value);
74 }
75 else
76 {
77 sdbusPriority(value);
Saqib Khan140fcb12017-08-07 09:06:57 -050078 }
79
Adriana Kobylak2285fe02018-02-27 15:36:59 -060080 std::vector<std::string> interfaces({interface});
81 bus.emit_interfaces_added(path.c_str(), interfaces);
82 }
Saqib Khan4c1aec02017-07-06 11:46:13 -050083
Adriana Kobylak2285fe02018-02-27 15:36:59 -060084 ~RedundancyPriority()
85 {
86 std::vector<std::string> interfaces({interface});
87 bus.emit_interfaces_removed(path.c_str(), interfaces);
88 }
Saqib Khan4c1aec02017-07-06 11:46:13 -050089
Gunnar Millse11a2022018-03-23 12:04:48 -050090 /** @brief Overridden Priority property set function, calls freePriority
Adriana Kobylak2285fe02018-02-27 15:36:59 -060091 * to bump the duplicated priority values.
92 *
93 * @param[in] value - uint8_t
94 *
95 * @return Success or exception thrown
96 */
97 uint8_t priority(uint8_t value) override;
Adriana Kobylakb77551c2017-10-27 12:46:23 -050098
Adriana Kobylak2285fe02018-02-27 15:36:59 -060099 /** @brief Non-Overriden Priority property set function
100 *
101 * @param[in] value - uint8_t
102 *
103 * @return Success or exception thrown
104 */
105 uint8_t sdbusPriority(uint8_t value);
Saqib Khan4c1aec02017-07-06 11:46:13 -0500106
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600107 /** @brief Priority property get function
108 *
109 * @returns uint8_t - The Priority value
110 */
111 using RedundancyPriorityInherit::priority;
Saqib Khan140fcb12017-08-07 09:06:57 -0500112
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600113 /** @brief Parent Object. */
114 Activation& parent;
115
116 private:
117 // TODO Remove once openbmc/openbmc#1975 is resolved
118 static constexpr auto interface =
119 "xyz.openbmc_project.Software.RedundancyPriority";
120 sdbusplus::bus::bus& bus;
121 std::string path;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500122};
Saqib Khanb0774702017-05-23 16:02:41 -0500123
124/** @class ActivationBlocksTransition
125 * @brief OpenBMC ActivationBlocksTransition implementation.
126 * @details A concrete implementation for
127 * xyz.openbmc_project.Software.ActivationBlocksTransition DBus API.
128 */
129class ActivationBlocksTransition : public ActivationBlocksTransitionInherit
130{
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600131 public:
132 /** @brief Constructs ActivationBlocksTransition.
133 *
134 * @param[in] bus - The Dbus bus object
135 * @param[in] path - The Dbus object path
136 */
137 ActivationBlocksTransition(sdbusplus::bus::bus& bus,
138 const std::string& path) :
139 ActivationBlocksTransitionInherit(bus, path.c_str(), true),
140 bus(bus), path(path)
141 {
142 std::vector<std::string> interfaces({interface});
143 bus.emit_interfaces_added(path.c_str(), interfaces);
144 enableRebootGuard();
145 }
Saqib Khan140fcb12017-08-07 09:06:57 -0500146
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600147 ~ActivationBlocksTransition()
148 {
149 std::vector<std::string> interfaces({interface});
150 bus.emit_interfaces_removed(path.c_str(), interfaces);
151 disableRebootGuard();
152 }
Saqib Khan140fcb12017-08-07 09:06:57 -0500153
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600154 private:
155 // TODO Remove once openbmc/openbmc#1975 is resolved
156 static constexpr auto interface =
157 "xyz.openbmc_project.Software.ActivationBlocksTransition";
158 sdbusplus::bus::bus& bus;
159 std::string path;
Saqib Khanf37cefc2017-09-12 08:44:41 -0500160
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600161 /** @brief Enables a Guard that blocks any BMC reboot commands */
162 void enableRebootGuard();
Saqib Khanf37cefc2017-09-12 08:44:41 -0500163
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600164 /** @brief Disables any guard that was blocking the BMC reboot */
165 void disableRebootGuard();
Saqib Khanb0774702017-05-23 16:02:41 -0500166};
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500167
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500168class ActivationProgress : public ActivationProgressInherit
169{
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600170 public:
171 /** @brief Constructs ActivationProgress.
172 *
173 * @param[in] bus - The Dbus bus object
174 * @param[in] path - The Dbus object path
175 */
176 ActivationProgress(sdbusplus::bus::bus& bus, const std::string& path) :
177 ActivationProgressInherit(bus, path.c_str(), true), bus(bus), path(path)
178 {
179 progress(0);
180 std::vector<std::string> interfaces({interface});
181 bus.emit_interfaces_added(path.c_str(), interfaces);
182 }
Saqib Khan140fcb12017-08-07 09:06:57 -0500183
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600184 ~ActivationProgress()
185 {
186 std::vector<std::string> interfaces({interface});
187 bus.emit_interfaces_removed(path.c_str(), interfaces);
188 }
Saqib Khan140fcb12017-08-07 09:06:57 -0500189
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600190 private:
191 // TODO Remove once openbmc/openbmc#1975 is resolved
192 static constexpr auto interface =
193 "xyz.openbmc_project.Software.ActivationProgress";
194 sdbusplus::bus::bus& bus;
195 std::string path;
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500196};
197
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500198/** @class Activation
199 * @brief OpenBMC activation software management implementation.
200 * @details A concrete implementation for
201 * xyz.openbmc_project.Software.Activation DBus API.
202 */
Lei YU1be8d502018-06-20 11:48:36 +0800203class Activation : public ActivationInherit, public Flash
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500204{
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600205 public:
206 /** @brief Constructs Activation Software Manager
207 *
208 * @param[in] bus - The Dbus bus object
209 * @param[in] path - The Dbus object path
210 * @param[in] parent - Parent object.
211 * @param[in] versionId - The software version id
212 * @param[in] activationStatus - The status of Activation
213 * @param[in] assocs - Association objects
214 */
215 Activation(sdbusplus::bus::bus& bus, const std::string& path,
216 ItemUpdater& parent, std::string& versionId,
217 sdbusplus::xyz::openbmc_project::Software::server::Activation::
218 Activations activationStatus,
219 AssociationList& assocs) :
220 ActivationInherit(bus, path.c_str(), true),
221 bus(bus), path(path), parent(parent), versionId(versionId),
222 systemdSignals(
223 bus,
224 sdbusRule::type::signal() + sdbusRule::member("JobRemoved") +
225 sdbusRule::path("/org/freedesktop/systemd1") +
226 sdbusRule::interface("org.freedesktop.systemd1.Manager"),
227 std::bind(std::mem_fn(&Activation::unitStateChange), this,
228 std::placeholders::_1))
229 {
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600230 // Set Properties.
231 activation(activationStatus);
232 associations(assocs);
Gunnar Millsb60add12017-08-24 16:41:42 -0500233
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600234 // Emit deferred signal.
235 emit_object_added();
236 }
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500237
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600238 /** @brief Overloaded Activation property setter function
239 *
240 * @param[in] value - One of Activation::Activations
241 *
242 * @return Success or exception thrown
243 */
244 Activations activation(Activations value) override;
Saqib Khanb0774702017-05-23 16:02:41 -0500245
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600246 /** @brief Activation */
247 using ActivationInherit::activation;
Leonel Gonzaleze4233682017-07-07 14:38:25 -0500248
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600249 /** @brief Overloaded requestedActivation property setter function
250 *
251 * @param[in] value - One of Activation::RequestedActivations
252 *
253 * @return Success or exception thrown
254 */
255 RequestedActivations
256 requestedActivation(RequestedActivations value) override;
Saqib Khanb0774702017-05-23 16:02:41 -0500257
Adriana Kobylak9f89e2e2018-05-30 13:16:20 -0500258 /** @brief Overloaded write flash function */
259 void flashWrite() override;
260
Adriana Kobylak3ce563a2018-06-06 16:41:15 -0500261 /** @brief Overloaded function that acts on service file state changes */
262 void onStateChanges(sdbusplus::message::message&) override;
263
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600264 /** @brief Check if systemd state change is relevant to this object
265 *
266 * Instance specific interface to handle the detected systemd state
267 * change
268 *
269 * @param[in] msg - Data associated with subscribed signal
270 *
271 */
272 void unitStateChange(sdbusplus::message::message& msg);
Michael Tritzbed88af2017-07-19 16:00:06 -0500273
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600274 /**
275 * @brief subscribe to the systemd signals
276 *
277 * This object needs to capture when it's systemd targets complete
278 * so it can keep it's state updated
279 *
280 */
281 void subscribeToSystemdSignals();
Michael Tritzbed88af2017-07-19 16:00:06 -0500282
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600283 /**
284 * @brief unsubscribe from the systemd signals
285 *
286 * systemd signals are only of interest during the activation process.
287 * Once complete, we want to unsubscribe to avoid unnecessary calls of
288 * unitStateChange().
289 *
290 */
291 void unsubscribeFromSystemdSignals();
Michael Tritzf2b5e0d2017-07-25 14:39:34 -0500292
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600293 /**
294 * @brief Deletes the version from Image Manager and the
295 * untar image from image upload dir.
296 */
297 void deleteImageManagerObject();
Saqib Khanee13e832017-10-23 12:53:11 -0500298
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600299 /** @brief Persistent sdbusplus DBus bus connection */
300 sdbusplus::bus::bus& bus;
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500301
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600302 /** @brief Persistent DBus object path */
303 std::string path;
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500304
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600305 /** @brief Parent Object. */
306 ItemUpdater& parent;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500307
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600308 /** @brief Version id */
309 std::string versionId;
Saqib Khanb0774702017-05-23 16:02:41 -0500310
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600311 /** @brief Persistent ActivationBlocksTransition dbus object */
312 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500313
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600314 /** @brief Persistent RedundancyPriority dbus object */
315 std::unique_ptr<RedundancyPriority> redundancyPriority;
Michael Tritzbed88af2017-07-19 16:00:06 -0500316
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600317 /** @brief Persistent ActivationProgress dbus object */
318 std::unique_ptr<ActivationProgress> activationProgress;
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500319
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600320 /** @brief Used to subscribe to dbus systemd signals **/
321 sdbusplus::bus::match_t systemdSignals;
Michael Tritzbed88af2017-07-19 16:00:06 -0500322
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600323 /** @brief Tracks whether the read-write volume has been created as
324 * part of the activation process. **/
325 bool rwVolumeCreated = false;
Michael Tritzbed88af2017-07-19 16:00:06 -0500326
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600327 /** @brief Tracks whether the read-only volume has been created as
328 * part of the activation process. **/
329 bool roVolumeCreated = false;
Adriana Kobylak166bdf32018-04-09 14:24:06 -0500330
331 /** @brief Tracks if the service that updates the U-Boot environment
332 * variables has completed. **/
333 bool ubootEnvVarsUpdated = false;
Lei YU90532252018-05-24 11:15:24 +0800334
335#ifdef WANT_SIGNATURE_VERIFY
336 private:
337 /** @brief Verify signature of the images.
338 *
339 * @param[in] imageDir - The path of images to verify
340 * @param[in] confDir - The path of configs for verification
341 *
342 * @return true if verification successful and false otherwise
343 */
344 bool verifySignature(const fs::path& imageDir, const fs::path& confDir);
345
346 /** @brief Called when image verification fails. */
347 void onVerifyFailed();
348#endif
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500349};
350
351} // namespace updater
352} // namespace software
353} // namespace phosphor