blob: 04562ea47b5e39a7805f8fe685a5e4f5671bb481 [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>>;
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -050032using ActivationInherit = sdbusplus::server::object_t<
Patrick Williams1e9a5f12023-08-23 16:53:06 -050033 sdbusplus::server::xyz::openbmc_project::software::Activation,
34 sdbusplus::server::xyz::openbmc_project::association::Definitions>;
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -050035using ActivationBlocksTransitionInherit =
36 sdbusplus::server::object_t<sdbusplus::xyz::openbmc_project::Software::
37 server::ActivationBlocksTransition>;
38using RedundancyPriorityInherit = sdbusplus::server::object_t<
Patrick Williams1e9a5f12023-08-23 16:53:06 -050039 sdbusplus::server::xyz::openbmc_project::software::RedundancyPriority>;
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -050040using ActivationProgressInherit = sdbusplus::server::object_t<
Patrick Williams1e9a5f12023-08-23 16:53:06 -050041 sdbusplus::server::xyz::openbmc_project::software::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 */
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -050072 RedundancyPriority(sdbusplus::bus_t& bus, const std::string& path,
Adriana Kobylak2285fe02018-02-27 15:36:59 -060073 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 */
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -0500130 ActivationBlocksTransition(sdbusplus::bus_t& bus, const std::string& path) :
Lei YU29d84b02020-02-13 15:13:09 +0800131 ActivationBlocksTransitionInherit(bus, path.c_str(),
132 action::emit_interface_added),
133 bus(bus)
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600134 {
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600135 enableRebootGuard();
136 }
Saqib Khan140fcb12017-08-07 09:06:57 -0500137
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600138 ~ActivationBlocksTransition()
139 {
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600140 disableRebootGuard();
141 }
Saqib Khan140fcb12017-08-07 09:06:57 -0500142
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600143 private:
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -0500144 sdbusplus::bus_t& bus;
Saqib Khanf37cefc2017-09-12 08:44:41 -0500145
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600146 /** @brief Enables a Guard that blocks any BMC reboot commands */
147 void enableRebootGuard();
Saqib Khanf37cefc2017-09-12 08:44:41 -0500148
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600149 /** @brief Disables any guard that was blocking the BMC reboot */
150 void disableRebootGuard();
Saqib Khanb0774702017-05-23 16:02:41 -0500151};
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500152
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500153class ActivationProgress : public ActivationProgressInherit
154{
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600155 public:
156 /** @brief Constructs ActivationProgress.
157 *
158 * @param[in] bus - The Dbus bus object
159 * @param[in] path - The Dbus object path
160 */
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -0500161 ActivationProgress(sdbusplus::bus_t& bus, const std::string& path) :
Lei YU29d84b02020-02-13 15:13:09 +0800162 ActivationProgressInherit(bus, path.c_str(),
163 action::emit_interface_added)
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600164 {
165 progress(0);
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600166 }
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500167};
168
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500169/** @class Activation
170 * @brief OpenBMC activation software management implementation.
171 * @details A concrete implementation for
172 * xyz.openbmc_project.Software.Activation DBus API.
173 */
Lei YU1be8d502018-06-20 11:48:36 +0800174class Activation : public ActivationInherit, public Flash
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500175{
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600176 public:
177 /** @brief Constructs Activation Software Manager
178 *
179 * @param[in] bus - The Dbus bus object
180 * @param[in] path - The Dbus object path
181 * @param[in] parent - Parent object.
182 * @param[in] versionId - The software version id
183 * @param[in] activationStatus - The status of Activation
184 * @param[in] assocs - Association objects
185 */
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -0500186 Activation(sdbusplus::bus_t& bus, const std::string& path,
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600187 ItemUpdater& parent, std::string& versionId,
Patrick Williams1e9a5f12023-08-23 16:53:06 -0500188 sdbusplus::server::xyz::openbmc_project::software::Activation::
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600189 Activations activationStatus,
190 AssociationList& assocs) :
Patrick Williams35aa9a82022-04-05 15:55:30 -0500191 ActivationInherit(bus, path.c_str(),
192 ActivationInherit::action::defer_emit),
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600193 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
Adriana Kobylakb824b2f2020-05-14 14:57:53 -0500233 /**
234 * @brief Handle the success of the flashWrite() function
235 *
236 * @details Perform anything that is necessary to mark the activation
237 * successful after the image has been written to flash. Sets the Activation
238 * value to Active.
239 */
240 void onFlashWriteSuccess();
241
Vijay Khemkae9f6c842020-01-14 14:32:39 -0800242#ifdef HOST_BIOS_UPGRADE
243 /* @brief write to Host flash function */
244 void flashWriteHost();
245
246 /** @brief Function that acts on Bios upgrade service file state changes */
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -0500247 void onStateChangesBios(sdbusplus::message_t&);
Vijay Khemkae9f6c842020-01-14 14:32:39 -0800248#endif
249
Adriana Kobylak3ce563a2018-06-06 16:41:15 -0500250 /** @brief Overloaded function that acts on service file state changes */
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -0500251 void onStateChanges(sdbusplus::message_t&) override;
Adriana Kobylak3ce563a2018-06-06 16:41:15 -0500252
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 */
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -0500261 void unitStateChange(sdbusplus::message_t& 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
Jayashankar Padatha0135602019-04-22 16:22:58 +0530288 /**
289 * @brief Determine the configured image apply time value
290 *
291 * @return true if the image apply time value is immediate
292 **/
293 bool checkApplyTimeImmediate();
294
295 /**
296 * @brief Reboot the BMC. Called when ApplyTime is immediate.
297 *
298 * @return none
299 **/
300 void rebootBmc();
301
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600302 /** @brief Persistent sdbusplus DBus bus connection */
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -0500303 sdbusplus::bus_t& bus;
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500304
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600305 /** @brief Persistent DBus object path */
306 std::string path;
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500307
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600308 /** @brief Parent Object. */
309 ItemUpdater& parent;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500310
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600311 /** @brief Version id */
312 std::string versionId;
Saqib Khanb0774702017-05-23 16:02:41 -0500313
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600314 /** @brief Persistent ActivationBlocksTransition dbus object */
315 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500316
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600317 /** @brief Persistent RedundancyPriority dbus object */
318 std::unique_ptr<RedundancyPriority> redundancyPriority;
Michael Tritzbed88af2017-07-19 16:00:06 -0500319
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600320 /** @brief Persistent ActivationProgress dbus object */
321 std::unique_ptr<ActivationProgress> activationProgress;
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500322
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600323 /** @brief Used to subscribe to dbus systemd signals **/
324 sdbusplus::bus::match_t systemdSignals;
Michael Tritzbed88af2017-07-19 16:00:06 -0500325
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600326 /** @brief Tracks whether the read-write volume has been created as
327 * part of the activation process. **/
328 bool rwVolumeCreated = false;
Michael Tritzbed88af2017-07-19 16:00:06 -0500329
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600330 /** @brief Tracks whether the read-only volume has been created as
331 * part of the activation process. **/
332 bool roVolumeCreated = false;
Adriana Kobylak166bdf32018-04-09 14:24:06 -0500333
334 /** @brief Tracks if the service that updates the U-Boot environment
335 * variables has completed. **/
336 bool ubootEnvVarsUpdated = false;
Lei YU90532252018-05-24 11:15:24 +0800337
338#ifdef WANT_SIGNATURE_VERIFY
339 private:
340 /** @brief Verify signature of the images.
341 *
342 * @param[in] imageDir - The path of images to verify
343 * @param[in] confDir - The path of configs for verification
344 *
345 * @return true if verification successful and false otherwise
346 */
347 bool verifySignature(const fs::path& imageDir, const fs::path& confDir);
348
349 /** @brief Called when image verification fails. */
350 void onVerifyFailed();
351#endif
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500352};
353
354} // namespace updater
355} // namespace software
356} // namespace phosphor