blob: 654d21ffc70fdf5d4a22155d45edfccdeff19501 [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
Lei YU90532252018-05-24 11:15:24 +080011#include "config.h"
12
13#ifdef WANT_SIGNATURE_VERIFY
14#include <experimental/filesystem>
15#endif
16
Gunnar Millsec1b41c2017-05-02 12:20:36 -050017namespace phosphor
18{
19namespace software
20{
21namespace updater
22{
23
Lei YU90532252018-05-24 11:15:24 +080024#ifdef WANT_SIGNATURE_VERIFY
25namespace fs = std::experimental::filesystem;
26#endif
27
Gunnar Millsb60add12017-08-24 16:41:42 -050028using AssociationList =
Adriana Kobylak2285fe02018-02-27 15:36:59 -060029 std::vector<std::tuple<std::string, std::string, std::string>>;
Gunnar Millsec1b41c2017-05-02 12:20:36 -050030using ActivationInherit = sdbusplus::server::object::object<
Gunnar Millsf5eaf392017-08-22 16:36:55 -050031 sdbusplus::xyz::openbmc_project::Software::server::Activation,
Michael Tritz4254bec2017-10-03 17:18:22 -050032 sdbusplus::org::openbmc::server::Associations>;
Saqib Khanb0774702017-05-23 16:02:41 -050033using ActivationBlocksTransitionInherit = sdbusplus::server::object::object<
Adriana Kobylak2285fe02018-02-27 15:36:59 -060034 sdbusplus::xyz::openbmc_project::Software::server::
35 ActivationBlocksTransition>;
Saqib Khan4c1aec02017-07-06 11:46:13 -050036using RedundancyPriorityInherit = sdbusplus::server::object::object<
37 sdbusplus::xyz::openbmc_project::Software::server::RedundancyPriority>;
Michael Tritz0edd4ad2017-07-26 14:27:42 -050038using ActivationProgressInherit = sdbusplus::server::object::object<
39 sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>;
Saqib Khan4c1aec02017-07-06 11:46:13 -050040
Michael Tritzbed88af2017-07-19 16:00:06 -050041namespace sdbusRule = sdbusplus::bus::match::rules;
42
Saqib Khan4c1aec02017-07-06 11:46:13 -050043class ItemUpdater;
44class Activation;
45class RedundancyPriority;
46
47/** @class RedundancyPriority
48 * @brief OpenBMC RedundancyPriority implementation
49 * @details A concrete implementation for
50 * xyz.openbmc_project.Software.RedundancyPriority DBus API.
51 */
52class RedundancyPriority : public RedundancyPriorityInherit
53{
Adriana Kobylak2285fe02018-02-27 15:36:59 -060054 public:
55 /** @brief Constructs RedundancyPriority.
56 *
57 * @param[in] bus - The Dbus bus object
58 * @param[in] path - The Dbus object path
59 * @param[in] parent - Parent object.
60 * @param[in] value - The redundancyPriority value
61 * @param[in] freePriority - Call freePriorioty, default to true
62 */
63 RedundancyPriority(sdbusplus::bus::bus& bus, const std::string& path,
64 Activation& parent, uint8_t value,
65 bool freePriority = true) :
66 RedundancyPriorityInherit(bus, path.c_str(), true),
67 parent(parent), bus(bus), path(path)
68 {
69 // Set Property
70 if (freePriority)
Saqib Khan4c1aec02017-07-06 11:46:13 -050071 {
Adriana Kobylak2285fe02018-02-27 15:36:59 -060072 priority(value);
73 }
74 else
75 {
76 sdbusPriority(value);
Saqib Khan140fcb12017-08-07 09:06:57 -050077 }
78
Adriana Kobylak2285fe02018-02-27 15:36:59 -060079 std::vector<std::string> interfaces({interface});
80 bus.emit_interfaces_added(path.c_str(), interfaces);
81 }
Saqib Khan4c1aec02017-07-06 11:46:13 -050082
Adriana Kobylak2285fe02018-02-27 15:36:59 -060083 ~RedundancyPriority()
84 {
85 std::vector<std::string> interfaces({interface});
86 bus.emit_interfaces_removed(path.c_str(), interfaces);
87 }
Saqib Khan4c1aec02017-07-06 11:46:13 -050088
Gunnar Millse11a2022018-03-23 12:04:48 -050089 /** @brief Overridden Priority property set function, calls freePriority
Adriana Kobylak2285fe02018-02-27 15:36:59 -060090 * to bump the duplicated priority values.
91 *
92 * @param[in] value - uint8_t
93 *
94 * @return Success or exception thrown
95 */
96 uint8_t priority(uint8_t value) override;
Adriana Kobylakb77551c2017-10-27 12:46:23 -050097
Adriana Kobylak2285fe02018-02-27 15:36:59 -060098 /** @brief Non-Overriden Priority property set function
99 *
100 * @param[in] value - uint8_t
101 *
102 * @return Success or exception thrown
103 */
104 uint8_t sdbusPriority(uint8_t value);
Saqib Khan4c1aec02017-07-06 11:46:13 -0500105
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600106 /** @brief Priority property get function
107 *
108 * @returns uint8_t - The Priority value
109 */
110 using RedundancyPriorityInherit::priority;
Saqib Khan140fcb12017-08-07 09:06:57 -0500111
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600112 /** @brief Parent Object. */
113 Activation& parent;
114
115 private:
116 // TODO Remove once openbmc/openbmc#1975 is resolved
117 static constexpr auto interface =
118 "xyz.openbmc_project.Software.RedundancyPriority";
119 sdbusplus::bus::bus& bus;
120 std::string path;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500121};
Saqib Khanb0774702017-05-23 16:02:41 -0500122
123/** @class ActivationBlocksTransition
124 * @brief OpenBMC ActivationBlocksTransition implementation.
125 * @details A concrete implementation for
126 * xyz.openbmc_project.Software.ActivationBlocksTransition DBus API.
127 */
128class ActivationBlocksTransition : public ActivationBlocksTransitionInherit
129{
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600130 public:
131 /** @brief Constructs ActivationBlocksTransition.
132 *
133 * @param[in] bus - The Dbus bus object
134 * @param[in] path - The Dbus object path
135 */
136 ActivationBlocksTransition(sdbusplus::bus::bus& bus,
137 const std::string& path) :
138 ActivationBlocksTransitionInherit(bus, path.c_str(), true),
139 bus(bus), path(path)
140 {
141 std::vector<std::string> interfaces({interface});
142 bus.emit_interfaces_added(path.c_str(), interfaces);
143 enableRebootGuard();
144 }
Saqib Khan140fcb12017-08-07 09:06:57 -0500145
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600146 ~ActivationBlocksTransition()
147 {
148 std::vector<std::string> interfaces({interface});
149 bus.emit_interfaces_removed(path.c_str(), interfaces);
150 disableRebootGuard();
151 }
Saqib Khan140fcb12017-08-07 09:06:57 -0500152
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600153 private:
154 // TODO Remove once openbmc/openbmc#1975 is resolved
155 static constexpr auto interface =
156 "xyz.openbmc_project.Software.ActivationBlocksTransition";
157 sdbusplus::bus::bus& bus;
158 std::string path;
Saqib Khanf37cefc2017-09-12 08:44:41 -0500159
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600160 /** @brief Enables a Guard that blocks any BMC reboot commands */
161 void enableRebootGuard();
Saqib Khanf37cefc2017-09-12 08:44:41 -0500162
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600163 /** @brief Disables any guard that was blocking the BMC reboot */
164 void disableRebootGuard();
Saqib Khanb0774702017-05-23 16:02:41 -0500165};
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500166
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500167class ActivationProgress : public ActivationProgressInherit
168{
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600169 public:
170 /** @brief Constructs ActivationProgress.
171 *
172 * @param[in] bus - The Dbus bus object
173 * @param[in] path - The Dbus object path
174 */
175 ActivationProgress(sdbusplus::bus::bus& bus, const std::string& path) :
176 ActivationProgressInherit(bus, path.c_str(), true), bus(bus), path(path)
177 {
178 progress(0);
179 std::vector<std::string> interfaces({interface});
180 bus.emit_interfaces_added(path.c_str(), interfaces);
181 }
Saqib Khan140fcb12017-08-07 09:06:57 -0500182
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600183 ~ActivationProgress()
184 {
185 std::vector<std::string> interfaces({interface});
186 bus.emit_interfaces_removed(path.c_str(), interfaces);
187 }
Saqib Khan140fcb12017-08-07 09:06:57 -0500188
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600189 private:
190 // TODO Remove once openbmc/openbmc#1975 is resolved
191 static constexpr auto interface =
192 "xyz.openbmc_project.Software.ActivationProgress";
193 sdbusplus::bus::bus& bus;
194 std::string path;
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500195};
196
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500197/** @class Activation
198 * @brief OpenBMC activation software management implementation.
199 * @details A concrete implementation for
200 * xyz.openbmc_project.Software.Activation DBus API.
201 */
Lei YU1be8d502018-06-20 11:48:36 +0800202class Activation : public ActivationInherit, public Flash
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500203{
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600204 public:
205 /** @brief Constructs Activation Software Manager
206 *
207 * @param[in] bus - The Dbus bus object
208 * @param[in] path - The Dbus object path
209 * @param[in] parent - Parent object.
210 * @param[in] versionId - The software version id
211 * @param[in] activationStatus - The status of Activation
212 * @param[in] assocs - Association objects
213 */
214 Activation(sdbusplus::bus::bus& bus, const std::string& path,
215 ItemUpdater& parent, std::string& versionId,
216 sdbusplus::xyz::openbmc_project::Software::server::Activation::
217 Activations activationStatus,
218 AssociationList& assocs) :
219 ActivationInherit(bus, path.c_str(), true),
220 bus(bus), path(path), parent(parent), versionId(versionId),
221 systemdSignals(
222 bus,
223 sdbusRule::type::signal() + sdbusRule::member("JobRemoved") +
224 sdbusRule::path("/org/freedesktop/systemd1") +
225 sdbusRule::interface("org.freedesktop.systemd1.Manager"),
226 std::bind(std::mem_fn(&Activation::unitStateChange), this,
227 std::placeholders::_1))
228 {
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600229 // Set Properties.
230 activation(activationStatus);
231 associations(assocs);
Gunnar Millsb60add12017-08-24 16:41:42 -0500232
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600233 // Emit deferred signal.
234 emit_object_added();
235 }
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500236
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600237 /** @brief Overloaded Activation property setter function
238 *
239 * @param[in] value - One of Activation::Activations
240 *
241 * @return Success or exception thrown
242 */
243 Activations activation(Activations value) override;
Saqib Khanb0774702017-05-23 16:02:41 -0500244
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600245 /** @brief Activation */
246 using ActivationInherit::activation;
Leonel Gonzaleze4233682017-07-07 14:38:25 -0500247
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600248 /** @brief Overloaded requestedActivation property setter function
249 *
250 * @param[in] value - One of Activation::RequestedActivations
251 *
252 * @return Success or exception thrown
253 */
254 RequestedActivations
255 requestedActivation(RequestedActivations value) override;
Saqib Khanb0774702017-05-23 16:02:41 -0500256
Adriana Kobylak9f89e2e2018-05-30 13:16:20 -0500257 /** @brief Overloaded write flash function */
258 void flashWrite() override;
259
Adriana Kobylak3ce563a2018-06-06 16:41:15 -0500260 /** @brief Overloaded function that acts on service file state changes */
261 void onStateChanges(sdbusplus::message::message&) override;
262
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600263 /** @brief Check if systemd state change is relevant to this object
264 *
265 * Instance specific interface to handle the detected systemd state
266 * change
267 *
268 * @param[in] msg - Data associated with subscribed signal
269 *
270 */
271 void unitStateChange(sdbusplus::message::message& msg);
Michael Tritzbed88af2017-07-19 16:00:06 -0500272
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600273 /**
274 * @brief subscribe to the systemd signals
275 *
276 * This object needs to capture when it's systemd targets complete
277 * so it can keep it's state updated
278 *
279 */
280 void subscribeToSystemdSignals();
Michael Tritzbed88af2017-07-19 16:00:06 -0500281
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600282 /**
283 * @brief unsubscribe from the systemd signals
284 *
285 * systemd signals are only of interest during the activation process.
286 * Once complete, we want to unsubscribe to avoid unnecessary calls of
287 * unitStateChange().
288 *
289 */
290 void unsubscribeFromSystemdSignals();
Michael Tritzf2b5e0d2017-07-25 14:39:34 -0500291
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600292 /**
293 * @brief Deletes the version from Image Manager and the
294 * untar image from image upload dir.
295 */
296 void deleteImageManagerObject();
Saqib Khanee13e832017-10-23 12:53:11 -0500297
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600298 /** @brief Persistent sdbusplus DBus bus connection */
299 sdbusplus::bus::bus& bus;
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500300
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600301 /** @brief Persistent DBus object path */
302 std::string path;
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500303
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600304 /** @brief Parent Object. */
305 ItemUpdater& parent;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500306
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600307 /** @brief Version id */
308 std::string versionId;
Saqib Khanb0774702017-05-23 16:02:41 -0500309
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600310 /** @brief Persistent ActivationBlocksTransition dbus object */
311 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500312
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600313 /** @brief Persistent RedundancyPriority dbus object */
314 std::unique_ptr<RedundancyPriority> redundancyPriority;
Michael Tritzbed88af2017-07-19 16:00:06 -0500315
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600316 /** @brief Persistent ActivationProgress dbus object */
317 std::unique_ptr<ActivationProgress> activationProgress;
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500318
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600319 /** @brief Used to subscribe to dbus systemd signals **/
320 sdbusplus::bus::match_t systemdSignals;
Michael Tritzbed88af2017-07-19 16:00:06 -0500321
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600322 /** @brief Tracks whether the read-write volume has been created as
323 * part of the activation process. **/
324 bool rwVolumeCreated = false;
Michael Tritzbed88af2017-07-19 16:00:06 -0500325
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600326 /** @brief Tracks whether the read-only volume has been created as
327 * part of the activation process. **/
328 bool roVolumeCreated = false;
Adriana Kobylak166bdf32018-04-09 14:24:06 -0500329
330 /** @brief Tracks if the service that updates the U-Boot environment
331 * variables has completed. **/
332 bool ubootEnvVarsUpdated = false;
Lei YU90532252018-05-24 11:15:24 +0800333
334#ifdef WANT_SIGNATURE_VERIFY
335 private:
336 /** @brief Verify signature of the images.
337 *
338 * @param[in] imageDir - The path of images to verify
339 * @param[in] confDir - The path of configs for verification
340 *
341 * @return true if verification successful and false otherwise
342 */
343 bool verifySignature(const fs::path& imageDir, const fs::path& confDir);
344
345 /** @brief Called when image verification fails. */
346 void onVerifyFailed();
347#endif
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500348};
349
350} // namespace updater
351} // namespace software
352} // namespace phosphor