blob: 61c954e8415777d339ef45dcd4d020be46916bda [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"
Jayashankar Padatha0135602019-04-22 16:22:58 +05306#include "utils.hpp"
Gunnar Millsb0ce9962018-09-07 13:39:10 -05007#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>
John Wang85c356f2019-09-11 16:20:13 +080011#include <xyz/openbmc_project/Association/Definitions/server.hpp>
Gunnar Millsec1b41c2017-05-02 12:20:36 -050012#include <xyz/openbmc_project/Software/Activation/server.hpp>
Saqib Khanb0774702017-05-23 16:02:41 -050013#include <xyz/openbmc_project/Software/ActivationBlocksTransition/server.hpp>
Lei YU90532252018-05-24 11:15:24 +080014
15#ifdef WANT_SIGNATURE_VERIFY
Adriana Kobylakc98d9122020-05-05 10:36:01 -050016#include <filesystem>
Lei YU90532252018-05-24 11:15:24 +080017#endif
18
Gunnar Millsec1b41c2017-05-02 12:20:36 -050019namespace phosphor
20{
21namespace software
22{
23namespace updater
24{
25
Lei YU90532252018-05-24 11:15:24 +080026#ifdef WANT_SIGNATURE_VERIFY
Adriana Kobylakc98d9122020-05-05 10:36:01 -050027namespace fs = std::filesystem;
Lei YU90532252018-05-24 11:15:24 +080028#endif
29
Gunnar Millsb60add12017-08-24 16:41:42 -050030using AssociationList =
Adriana Kobylak2285fe02018-02-27 15:36:59 -060031 std::vector<std::tuple<std::string, std::string, std::string>>;
Gunnar Millsec1b41c2017-05-02 12:20:36 -050032using ActivationInherit = sdbusplus::server::object::object<
Gunnar Millsf5eaf392017-08-22 16:36:55 -050033 sdbusplus::xyz::openbmc_project::Software::server::Activation,
John Wang85c356f2019-09-11 16:20:13 +080034 sdbusplus::xyz::openbmc_project::Association::server::Definitions>;
Saqib Khanb0774702017-05-23 16:02:41 -050035using ActivationBlocksTransitionInherit = sdbusplus::server::object::object<
Adriana Kobylak2285fe02018-02-27 15:36:59 -060036 sdbusplus::xyz::openbmc_project::Software::server::
37 ActivationBlocksTransition>;
Saqib Khan4c1aec02017-07-06 11:46:13 -050038using RedundancyPriorityInherit = sdbusplus::server::object::object<
39 sdbusplus::xyz::openbmc_project::Software::server::RedundancyPriority>;
Michael Tritz0edd4ad2017-07-26 14:27:42 -050040using ActivationProgressInherit = sdbusplus::server::object::object<
41 sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>;
Saqib Khan4c1aec02017-07-06 11:46:13 -050042
Jayashankar Padatha0135602019-04-22 16:22:58 +053043constexpr auto applyTimeImmediate =
44 "xyz.openbmc_project.Software.ApplyTime.RequestedApplyTimes.Immediate";
45constexpr auto applyTimeIntf = "xyz.openbmc_project.Software.ApplyTime";
46constexpr auto dbusPropIntf = "org.freedesktop.DBus.Properties";
47constexpr auto applyTimeObjPath = "/xyz/openbmc_project/software/apply_time";
48constexpr auto applyTimeProp = "RequestedApplyTime";
49
Michael Tritzbed88af2017-07-19 16:00:06 -050050namespace sdbusRule = sdbusplus::bus::match::rules;
51
Saqib Khan4c1aec02017-07-06 11:46:13 -050052class ItemUpdater;
53class Activation;
54class RedundancyPriority;
55
56/** @class RedundancyPriority
57 * @brief OpenBMC RedundancyPriority implementation
58 * @details A concrete implementation for
59 * xyz.openbmc_project.Software.RedundancyPriority DBus API.
60 */
61class RedundancyPriority : public RedundancyPriorityInherit
62{
Adriana Kobylak2285fe02018-02-27 15:36:59 -060063 public:
64 /** @brief Constructs RedundancyPriority.
65 *
66 * @param[in] bus - The Dbus bus object
67 * @param[in] path - The Dbus object path
68 * @param[in] parent - Parent object.
69 * @param[in] value - The redundancyPriority value
70 * @param[in] freePriority - Call freePriorioty, default to true
71 */
72 RedundancyPriority(sdbusplus::bus::bus& bus, const std::string& path,
73 Activation& parent, uint8_t value,
74 bool freePriority = true) :
Lei YU29d84b02020-02-13 15:13:09 +080075 RedundancyPriorityInherit(bus, path.c_str(),
76 action::emit_interface_added),
77 parent(parent)
Adriana Kobylak2285fe02018-02-27 15:36:59 -060078 {
79 // Set Property
80 if (freePriority)
Saqib Khan4c1aec02017-07-06 11:46:13 -050081 {
Adriana Kobylak2285fe02018-02-27 15:36:59 -060082 priority(value);
83 }
84 else
85 {
86 sdbusPriority(value);
Saqib Khan140fcb12017-08-07 09:06:57 -050087 }
Adriana Kobylak2285fe02018-02-27 15:36:59 -060088 }
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;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500115};
Saqib Khanb0774702017-05-23 16:02:41 -0500116
117/** @class ActivationBlocksTransition
118 * @brief OpenBMC ActivationBlocksTransition implementation.
119 * @details A concrete implementation for
120 * xyz.openbmc_project.Software.ActivationBlocksTransition DBus API.
121 */
122class ActivationBlocksTransition : public ActivationBlocksTransitionInherit
123{
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600124 public:
125 /** @brief Constructs ActivationBlocksTransition.
126 *
127 * @param[in] bus - The Dbus bus object
128 * @param[in] path - The Dbus object path
129 */
130 ActivationBlocksTransition(sdbusplus::bus::bus& bus,
131 const std::string& path) :
Lei YU29d84b02020-02-13 15:13:09 +0800132 ActivationBlocksTransitionInherit(bus, path.c_str(),
133 action::emit_interface_added),
134 bus(bus)
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600135 {
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600136 enableRebootGuard();
137 }
Saqib Khan140fcb12017-08-07 09:06:57 -0500138
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600139 ~ActivationBlocksTransition()
140 {
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600141 disableRebootGuard();
142 }
Saqib Khan140fcb12017-08-07 09:06:57 -0500143
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600144 private:
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600145 sdbusplus::bus::bus& bus;
Saqib Khanf37cefc2017-09-12 08:44:41 -0500146
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600147 /** @brief Enables a Guard that blocks any BMC reboot commands */
148 void enableRebootGuard();
Saqib Khanf37cefc2017-09-12 08:44:41 -0500149
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600150 /** @brief Disables any guard that was blocking the BMC reboot */
151 void disableRebootGuard();
Saqib Khanb0774702017-05-23 16:02:41 -0500152};
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500153
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500154class ActivationProgress : public ActivationProgressInherit
155{
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600156 public:
157 /** @brief Constructs ActivationProgress.
158 *
159 * @param[in] bus - The Dbus bus object
160 * @param[in] path - The Dbus object path
161 */
162 ActivationProgress(sdbusplus::bus::bus& bus, const std::string& path) :
Lei YU29d84b02020-02-13 15:13:09 +0800163 ActivationProgressInherit(bus, path.c_str(),
164 action::emit_interface_added)
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600165 {
166 progress(0);
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600167 }
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500168};
169
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500170/** @class Activation
171 * @brief OpenBMC activation software management implementation.
172 * @details A concrete implementation for
173 * xyz.openbmc_project.Software.Activation DBus API.
174 */
Lei YU1be8d502018-06-20 11:48:36 +0800175class Activation : public ActivationInherit, public Flash
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500176{
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600177 public:
178 /** @brief Constructs Activation Software Manager
179 *
180 * @param[in] bus - The Dbus bus object
181 * @param[in] path - The Dbus object path
182 * @param[in] parent - Parent object.
183 * @param[in] versionId - The software version id
184 * @param[in] activationStatus - The status of Activation
185 * @param[in] assocs - Association objects
186 */
187 Activation(sdbusplus::bus::bus& bus, const std::string& path,
188 ItemUpdater& parent, std::string& versionId,
189 sdbusplus::xyz::openbmc_project::Software::server::Activation::
190 Activations activationStatus,
191 AssociationList& assocs) :
192 ActivationInherit(bus, path.c_str(), true),
193 bus(bus), path(path), parent(parent), versionId(versionId),
194 systemdSignals(
195 bus,
196 sdbusRule::type::signal() + sdbusRule::member("JobRemoved") +
197 sdbusRule::path("/org/freedesktop/systemd1") +
198 sdbusRule::interface("org.freedesktop.systemd1.Manager"),
199 std::bind(std::mem_fn(&Activation::unitStateChange), this,
200 std::placeholders::_1))
201 {
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600202 // Set Properties.
203 activation(activationStatus);
204 associations(assocs);
Gunnar Millsb60add12017-08-24 16:41:42 -0500205
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600206 // Emit deferred signal.
207 emit_object_added();
208 }
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500209
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600210 /** @brief Overloaded Activation property setter function
211 *
212 * @param[in] value - One of Activation::Activations
213 *
214 * @return Success or exception thrown
215 */
216 Activations activation(Activations value) override;
Saqib Khanb0774702017-05-23 16:02:41 -0500217
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600218 /** @brief Activation */
219 using ActivationInherit::activation;
Leonel Gonzaleze4233682017-07-07 14:38:25 -0500220
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600221 /** @brief Overloaded requestedActivation property setter function
222 *
223 * @param[in] value - One of Activation::RequestedActivations
224 *
225 * @return Success or exception thrown
226 */
227 RequestedActivations
228 requestedActivation(RequestedActivations value) override;
Saqib Khanb0774702017-05-23 16:02:41 -0500229
Adriana Kobylak9f89e2e2018-05-30 13:16:20 -0500230 /** @brief Overloaded write flash function */
231 void flashWrite() override;
232
Vijay Khemkae9f6c842020-01-14 14:32:39 -0800233#ifdef HOST_BIOS_UPGRADE
234 /* @brief write to Host flash function */
235 void flashWriteHost();
236
237 /** @brief Function that acts on Bios upgrade service file state changes */
238 void onStateChangesBios(sdbusplus::message::message&);
239#endif
240
Adriana Kobylak3ce563a2018-06-06 16:41:15 -0500241 /** @brief Overloaded function that acts on service file state changes */
242 void onStateChanges(sdbusplus::message::message&) override;
243
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600244 /** @brief Check if systemd state change is relevant to this object
245 *
246 * Instance specific interface to handle the detected systemd state
247 * change
248 *
249 * @param[in] msg - Data associated with subscribed signal
250 *
251 */
252 void unitStateChange(sdbusplus::message::message& msg);
Michael Tritzbed88af2017-07-19 16:00:06 -0500253
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600254 /**
255 * @brief subscribe to the systemd signals
256 *
257 * This object needs to capture when it's systemd targets complete
258 * so it can keep it's state updated
259 *
260 */
261 void subscribeToSystemdSignals();
Michael Tritzbed88af2017-07-19 16:00:06 -0500262
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600263 /**
264 * @brief unsubscribe from the systemd signals
265 *
266 * systemd signals are only of interest during the activation process.
267 * Once complete, we want to unsubscribe to avoid unnecessary calls of
268 * unitStateChange().
269 *
270 */
271 void unsubscribeFromSystemdSignals();
Michael Tritzf2b5e0d2017-07-25 14:39:34 -0500272
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600273 /**
274 * @brief Deletes the version from Image Manager and the
275 * untar image from image upload dir.
276 */
277 void deleteImageManagerObject();
Saqib Khanee13e832017-10-23 12:53:11 -0500278
Jayashankar Padatha0135602019-04-22 16:22:58 +0530279 /**
280 * @brief Determine the configured image apply time value
281 *
282 * @return true if the image apply time value is immediate
283 **/
284 bool checkApplyTimeImmediate();
285
286 /**
287 * @brief Reboot the BMC. Called when ApplyTime is immediate.
288 *
289 * @return none
290 **/
291 void rebootBmc();
292
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600293 /** @brief Persistent sdbusplus DBus bus connection */
294 sdbusplus::bus::bus& bus;
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500295
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600296 /** @brief Persistent DBus object path */
297 std::string path;
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500298
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600299 /** @brief Parent Object. */
300 ItemUpdater& parent;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500301
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600302 /** @brief Version id */
303 std::string versionId;
Saqib Khanb0774702017-05-23 16:02:41 -0500304
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600305 /** @brief Persistent ActivationBlocksTransition dbus object */
306 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500307
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600308 /** @brief Persistent RedundancyPriority dbus object */
309 std::unique_ptr<RedundancyPriority> redundancyPriority;
Michael Tritzbed88af2017-07-19 16:00:06 -0500310
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600311 /** @brief Persistent ActivationProgress dbus object */
312 std::unique_ptr<ActivationProgress> activationProgress;
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500313
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600314 /** @brief Used to subscribe to dbus systemd signals **/
315 sdbusplus::bus::match_t systemdSignals;
Michael Tritzbed88af2017-07-19 16:00:06 -0500316
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600317 /** @brief Tracks whether the read-write volume has been created as
318 * part of the activation process. **/
319 bool rwVolumeCreated = false;
Michael Tritzbed88af2017-07-19 16:00:06 -0500320
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600321 /** @brief Tracks whether the read-only volume has been created as
322 * part of the activation process. **/
323 bool roVolumeCreated = false;
Adriana Kobylak166bdf32018-04-09 14:24:06 -0500324
325 /** @brief Tracks if the service that updates the U-Boot environment
326 * variables has completed. **/
327 bool ubootEnvVarsUpdated = false;
Lei YU90532252018-05-24 11:15:24 +0800328
329#ifdef WANT_SIGNATURE_VERIFY
330 private:
331 /** @brief Verify signature of the images.
332 *
333 * @param[in] imageDir - The path of images to verify
334 * @param[in] confDir - The path of configs for verification
335 *
336 * @return true if verification successful and false otherwise
337 */
338 bool verifySignature(const fs::path& imageDir, const fs::path& confDir);
339
340 /** @brief Called when image verification fails. */
341 void onVerifyFailed();
342#endif
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500343};
344
345} // namespace updater
346} // namespace software
347} // namespace phosphor