blob: 2386bd2b5fd28eebae921c2fb01f6c739e008e49 [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
Jagpal Singh Gill6397c092025-07-16 21:18:00 -070010#include <sdbusplus/async.hpp>
Saqib Khanb0774702017-05-23 16:02:41 -050011#include <sdbusplus/server.hpp>
John Wang85c356f2019-09-11 16:20:13 +080012#include <xyz/openbmc_project/Association/Definitions/server.hpp>
Gunnar Millsec1b41c2017-05-02 12:20:36 -050013#include <xyz/openbmc_project/Software/Activation/server.hpp>
Saqib Khanb0774702017-05-23 16:02:41 -050014#include <xyz/openbmc_project/Software/ActivationBlocksTransition/server.hpp>
Jagpal Singh Gillbb024eb2024-04-07 23:34:00 -070015#include <xyz/openbmc_project/Software/ApplyTime/common.hpp>
Lei YU90532252018-05-24 11:15:24 +080016
17#ifdef WANT_SIGNATURE_VERIFY
Adriana Kobylakc98d9122020-05-05 10:36:01 -050018#include <filesystem>
Lei YU90532252018-05-24 11:15:24 +080019#endif
20
Gunnar Millsec1b41c2017-05-02 12:20:36 -050021namespace phosphor
22{
23namespace software
24{
25namespace updater
26{
27
Lei YU90532252018-05-24 11:15:24 +080028#ifdef WANT_SIGNATURE_VERIFY
Adriana Kobylakc98d9122020-05-05 10:36:01 -050029namespace fs = std::filesystem;
Lei YU90532252018-05-24 11:15:24 +080030#endif
31
Gunnar Millsb60add12017-08-24 16:41:42 -050032using AssociationList =
Adriana Kobylak2285fe02018-02-27 15:36:59 -060033 std::vector<std::tuple<std::string, std::string, std::string>>;
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -050034using ActivationInherit = sdbusplus::server::object_t<
Patrick Williams1e9a5f12023-08-23 16:53:06 -050035 sdbusplus::server::xyz::openbmc_project::software::Activation,
36 sdbusplus::server::xyz::openbmc_project::association::Definitions>;
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -050037using ActivationBlocksTransitionInherit =
Adriana Kobylakce82de52024-01-16 13:56:38 -060038 sdbusplus::server::object_t<sdbusplus::server::xyz::openbmc_project::
39 software::ActivationBlocksTransition>;
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -050040using RedundancyPriorityInherit = sdbusplus::server::object_t<
Patrick Williams1e9a5f12023-08-23 16:53:06 -050041 sdbusplus::server::xyz::openbmc_project::software::RedundancyPriority>;
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -050042using ActivationProgressInherit = sdbusplus::server::object_t<
Patrick Williams1e9a5f12023-08-23 16:53:06 -050043 sdbusplus::server::xyz::openbmc_project::software::ActivationProgress>;
Jagpal Singh Gillbb024eb2024-04-07 23:34:00 -070044using ApplyTimeIntf =
45 sdbusplus::common::xyz::openbmc_project::software::ApplyTime;
Saqib Khan4c1aec02017-07-06 11:46:13 -050046
Jayashankar Padatha0135602019-04-22 16:22:58 +053047constexpr auto applyTimeImmediate =
48 "xyz.openbmc_project.Software.ApplyTime.RequestedApplyTimes.Immediate";
49constexpr auto applyTimeIntf = "xyz.openbmc_project.Software.ApplyTime";
50constexpr auto dbusPropIntf = "org.freedesktop.DBus.Properties";
51constexpr auto applyTimeObjPath = "/xyz/openbmc_project/software/apply_time";
52constexpr auto applyTimeProp = "RequestedApplyTime";
53
Michael Tritzbed88af2017-07-19 16:00:06 -050054namespace sdbusRule = sdbusplus::bus::match::rules;
55
Saqib Khan4c1aec02017-07-06 11:46:13 -050056class ItemUpdater;
57class Activation;
58class RedundancyPriority;
59
60/** @class RedundancyPriority
61 * @brief OpenBMC RedundancyPriority implementation
62 * @details A concrete implementation for
63 * xyz.openbmc_project.Software.RedundancyPriority DBus API.
64 */
65class RedundancyPriority : public RedundancyPriorityInherit
66{
Adriana Kobylak2285fe02018-02-27 15:36:59 -060067 public:
68 /** @brief Constructs RedundancyPriority.
69 *
70 * @param[in] bus - The Dbus bus object
71 * @param[in] path - The Dbus object path
72 * @param[in] parent - Parent object.
73 * @param[in] value - The redundancyPriority value
74 * @param[in] freePriority - Call freePriorioty, default to true
75 */
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -050076 RedundancyPriority(sdbusplus::bus_t& bus, const std::string& path,
Adriana Kobylak2285fe02018-02-27 15:36:59 -060077 Activation& parent, uint8_t value,
78 bool freePriority = true) :
Lei YU29d84b02020-02-13 15:13:09 +080079 RedundancyPriorityInherit(bus, path.c_str(),
80 action::emit_interface_added),
81 parent(parent)
Adriana Kobylak2285fe02018-02-27 15:36:59 -060082 {
83 // Set Property
84 if (freePriority)
Saqib Khan4c1aec02017-07-06 11:46:13 -050085 {
Adriana Kobylak2285fe02018-02-27 15:36:59 -060086 priority(value);
87 }
88 else
89 {
90 sdbusPriority(value);
Saqib Khan140fcb12017-08-07 09:06:57 -050091 }
Adriana Kobylak2285fe02018-02-27 15:36:59 -060092 }
Saqib Khan4c1aec02017-07-06 11:46:13 -050093
Gunnar Millse11a2022018-03-23 12:04:48 -050094 /** @brief Overridden Priority property set function, calls freePriority
Adriana Kobylak2285fe02018-02-27 15:36:59 -060095 * to bump the duplicated priority values.
96 *
97 * @param[in] value - uint8_t
98 *
99 * @return Success or exception thrown
100 */
101 uint8_t priority(uint8_t value) override;
Adriana Kobylakb77551c2017-10-27 12:46:23 -0500102
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600103 /** @brief Non-Overriden Priority property set function
104 *
105 * @param[in] value - uint8_t
106 *
107 * @return Success or exception thrown
108 */
109 uint8_t sdbusPriority(uint8_t value);
Saqib Khan4c1aec02017-07-06 11:46:13 -0500110
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600111 /** @brief Priority property get function
112 *
113 * @returns uint8_t - The Priority value
114 */
115 using RedundancyPriorityInherit::priority;
Saqib Khan140fcb12017-08-07 09:06:57 -0500116
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600117 /** @brief Parent Object. */
118 Activation& parent;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500119};
Saqib Khanb0774702017-05-23 16:02:41 -0500120
121/** @class ActivationBlocksTransition
122 * @brief OpenBMC ActivationBlocksTransition implementation.
123 * @details A concrete implementation for
124 * xyz.openbmc_project.Software.ActivationBlocksTransition DBus API.
125 */
126class ActivationBlocksTransition : public ActivationBlocksTransitionInherit
127{
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600128 public:
129 /** @brief Constructs ActivationBlocksTransition.
130 *
131 * @param[in] bus - The Dbus bus object
132 * @param[in] path - The Dbus object path
133 */
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -0500134 ActivationBlocksTransition(sdbusplus::bus_t& bus, const std::string& path) :
Lei YU29d84b02020-02-13 15:13:09 +0800135 ActivationBlocksTransitionInherit(bus, path.c_str(),
136 action::emit_interface_added),
137 bus(bus)
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600138 {
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600139 enableRebootGuard();
140 }
Saqib Khan140fcb12017-08-07 09:06:57 -0500141
Pavithra Barithaya272bc1c2024-06-22 06:46:35 -0500142 ~ActivationBlocksTransition() override
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600143 {
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600144 disableRebootGuard();
145 }
Saqib Khan140fcb12017-08-07 09:06:57 -0500146
Pavithra Barithaya48de55f2024-06-22 05:30:44 -0500147 ActivationBlocksTransition(const ActivationBlocksTransition&) = delete;
Patrick Williamseae5ec92025-02-01 08:21:45 -0500148 ActivationBlocksTransition& operator=(const ActivationBlocksTransition&) =
149 delete;
Pavithra Barithaya48de55f2024-06-22 05:30:44 -0500150 ActivationBlocksTransition(ActivationBlocksTransition&&) = delete;
Patrick Williamseae5ec92025-02-01 08:21:45 -0500151 ActivationBlocksTransition& operator=(ActivationBlocksTransition&&) =
152 delete;
Pavithra Barithaya48de55f2024-06-22 05:30:44 -0500153
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600154 private:
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -0500155 sdbusplus::bus_t& bus;
Saqib Khanf37cefc2017-09-12 08:44:41 -0500156
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600157 /** @brief Enables a Guard that blocks any BMC reboot commands */
158 void enableRebootGuard();
Saqib Khanf37cefc2017-09-12 08:44:41 -0500159
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600160 /** @brief Disables any guard that was blocking the BMC reboot */
161 void disableRebootGuard();
Saqib Khanb0774702017-05-23 16:02:41 -0500162};
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500163
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500164class ActivationProgress : public ActivationProgressInherit
165{
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600166 public:
167 /** @brief Constructs ActivationProgress.
168 *
169 * @param[in] bus - The Dbus bus object
170 * @param[in] path - The Dbus object path
171 */
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -0500172 ActivationProgress(sdbusplus::bus_t& bus, const std::string& path) :
Lei YU29d84b02020-02-13 15:13:09 +0800173 ActivationProgressInherit(bus, path.c_str(),
174 action::emit_interface_added)
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600175 {
176 progress(0);
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600177 }
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500178};
179
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500180/** @class Activation
181 * @brief OpenBMC activation software management implementation.
182 * @details A concrete implementation for
183 * xyz.openbmc_project.Software.Activation DBus API.
184 */
Lei YU1be8d502018-06-20 11:48:36 +0800185class Activation : public ActivationInherit, public Flash
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500186{
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600187 public:
188 /** @brief Constructs Activation Software Manager
189 *
190 * @param[in] bus - The Dbus bus object
191 * @param[in] path - The Dbus object path
192 * @param[in] parent - Parent object.
193 * @param[in] versionId - The software version id
194 * @param[in] activationStatus - The status of Activation
195 * @param[in] assocs - Association objects
196 */
Jagpal Singh Gill6397c092025-07-16 21:18:00 -0700197 Activation(sdbusplus::async::context& ctx, const std::string& path,
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600198 ItemUpdater& parent, std::string& versionId,
Patrick Williams1e9a5f12023-08-23 16:53:06 -0500199 sdbusplus::server::xyz::openbmc_project::software::Activation::
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600200 Activations activationStatus,
201 AssociationList& assocs) :
Jagpal Singh Gill6397c092025-07-16 21:18:00 -0700202 ActivationInherit(ctx.get_bus(), path.c_str(),
Patrick Williams35aa9a82022-04-05 15:55:30 -0500203 ActivationInherit::action::defer_emit),
Jagpal Singh Gill6397c092025-07-16 21:18:00 -0700204 ctx(ctx), bus(ctx.get_bus()), path(path), parent(parent),
205 versionId(versionId),
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600206 systemdSignals(
207 bus,
208 sdbusRule::type::signal() + sdbusRule::member("JobRemoved") +
209 sdbusRule::path("/org/freedesktop/systemd1") +
210 sdbusRule::interface("org.freedesktop.systemd1.Manager"),
211 std::bind(std::mem_fn(&Activation::unitStateChange), this,
212 std::placeholders::_1))
213 {
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600214 // Set Properties.
215 activation(activationStatus);
216 associations(assocs);
Gunnar Millsb60add12017-08-24 16:41:42 -0500217
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600218 // Emit deferred signal.
219 emit_object_added();
220 }
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500221
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600222 /** @brief Overloaded Activation property setter function
223 *
224 * @param[in] value - One of Activation::Activations
225 *
226 * @return Success or exception thrown
227 */
228 Activations activation(Activations value) override;
Saqib Khanb0774702017-05-23 16:02:41 -0500229
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600230 /** @brief Activation */
231 using ActivationInherit::activation;
Leonel Gonzaleze4233682017-07-07 14:38:25 -0500232
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600233 /** @brief Overloaded requestedActivation property setter function
234 *
235 * @param[in] value - One of Activation::RequestedActivations
236 *
237 * @return Success or exception thrown
238 */
Patrick Williamseae5ec92025-02-01 08:21:45 -0500239 RequestedActivations requestedActivation(
240 RequestedActivations value) override;
Saqib Khanb0774702017-05-23 16:02:41 -0500241
Adriana Kobylak9f89e2e2018-05-30 13:16:20 -0500242 /** @brief Overloaded write flash function */
243 void flashWrite() override;
244
Adriana Kobylakb824b2f2020-05-14 14:57:53 -0500245 /**
246 * @brief Handle the success of the flashWrite() function
247 *
248 * @details Perform anything that is necessary to mark the activation
249 * successful after the image has been written to flash. Sets the Activation
250 * value to Active.
251 */
252 void onFlashWriteSuccess();
253
Vijay Khemkae9f6c842020-01-14 14:32:39 -0800254#ifdef HOST_BIOS_UPGRADE
255 /* @brief write to Host flash function */
256 void flashWriteHost();
257
258 /** @brief Function that acts on Bios upgrade service file state changes */
Pavithra Barithayaf9a69252024-06-25 00:35:36 -0500259 void onStateChangesBios(sdbusplus::message_t& /*msg*/);
Vijay Khemkae9f6c842020-01-14 14:32:39 -0800260#endif
261
Adriana Kobylak3ce563a2018-06-06 16:41:15 -0500262 /** @brief Overloaded function that acts on service file state changes */
Pavithra Barithayaf9a69252024-06-25 00:35:36 -0500263 void onStateChanges(sdbusplus::message_t& /*msg*/) override;
Adriana Kobylak3ce563a2018-06-06 16:41:15 -0500264
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600265 /** @brief Check if systemd state change is relevant to this object
266 *
267 * Instance specific interface to handle the detected systemd state
268 * change
269 *
270 * @param[in] msg - Data associated with subscribed signal
271 *
272 */
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -0500273 void unitStateChange(sdbusplus::message_t& msg);
Michael Tritzbed88af2017-07-19 16:00:06 -0500274
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600275 /**
276 * @brief subscribe to the systemd signals
277 *
278 * This object needs to capture when it's systemd targets complete
279 * so it can keep it's state updated
280 *
281 */
282 void subscribeToSystemdSignals();
Michael Tritzbed88af2017-07-19 16:00:06 -0500283
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600284 /**
285 * @brief unsubscribe from the systemd signals
286 *
287 * systemd signals are only of interest during the activation process.
288 * Once complete, we want to unsubscribe to avoid unnecessary calls of
289 * unitStateChange().
290 *
291 */
292 void unsubscribeFromSystemdSignals();
Michael Tritzf2b5e0d2017-07-25 14:39:34 -0500293
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600294 /**
295 * @brief Deletes the version from Image Manager and the
296 * untar image from image upload dir.
297 */
298 void deleteImageManagerObject();
Saqib Khanee13e832017-10-23 12:53:11 -0500299
Jayashankar Padatha0135602019-04-22 16:22:58 +0530300 /**
301 * @brief Determine the configured image apply time value
302 *
303 * @return true if the image apply time value is immediate
304 **/
305 bool checkApplyTimeImmediate();
306
307 /**
308 * @brief Reboot the BMC. Called when ApplyTime is immediate.
309 *
310 * @return none
311 **/
312 void rebootBmc();
313
Jagpal Singh Gill6397c092025-07-16 21:18:00 -0700314 /** @brief D-Bus context */
315 sdbusplus::async::context& ctx;
316
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600317 /** @brief Persistent sdbusplus DBus bus connection */
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -0500318 sdbusplus::bus_t& bus;
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500319
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600320 /** @brief Persistent DBus object path */
321 std::string path;
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500322
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600323 /** @brief Parent Object. */
324 ItemUpdater& parent;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500325
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600326 /** @brief Version id */
327 std::string versionId;
Saqib Khanb0774702017-05-23 16:02:41 -0500328
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600329 /** @brief Persistent ActivationBlocksTransition dbus object */
330 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500331
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600332 /** @brief Persistent RedundancyPriority dbus object */
333 std::unique_ptr<RedundancyPriority> redundancyPriority;
Michael Tritzbed88af2017-07-19 16:00:06 -0500334
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600335 /** @brief Persistent ActivationProgress dbus object */
336 std::unique_ptr<ActivationProgress> activationProgress;
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500337
Jagpal Singh Gillbb024eb2024-04-07 23:34:00 -0700338 /** @brief Apply time */
339 ApplyTimeIntf::RequestedApplyTimes applyTime;
340
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600341 /** @brief Used to subscribe to dbus systemd signals **/
342 sdbusplus::bus::match_t systemdSignals;
Michael Tritzbed88af2017-07-19 16:00:06 -0500343
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600344 /** @brief Tracks whether the read-write volume has been created as
345 * part of the activation process. **/
346 bool rwVolumeCreated = false;
Michael Tritzbed88af2017-07-19 16:00:06 -0500347
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600348 /** @brief Tracks whether the read-only volume has been created as
349 * part of the activation process. **/
350 bool roVolumeCreated = false;
Adriana Kobylak166bdf32018-04-09 14:24:06 -0500351
352 /** @brief Tracks if the service that updates the U-Boot environment
353 * variables has completed. **/
354 bool ubootEnvVarsUpdated = false;
Lei YU90532252018-05-24 11:15:24 +0800355
356#ifdef WANT_SIGNATURE_VERIFY
357 private:
358 /** @brief Verify signature of the images.
359 *
360 * @param[in] imageDir - The path of images to verify
361 * @param[in] confDir - The path of configs for verification
362 *
363 * @return true if verification successful and false otherwise
364 */
Pavithra Barithayac5f6e7e2024-06-24 09:50:21 -0500365 static bool verifySignature(const fs::path& imageDir,
366 const fs::path& confDir);
Lei YU90532252018-05-24 11:15:24 +0800367
368 /** @brief Called when image verification fails. */
369 void onVerifyFailed();
370#endif
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500371};
372
373} // namespace updater
374} // namespace software
375} // namespace phosphor