blob: 4ec621be1ed7953784f58663a971a91cae193545 [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>
Jagpal Singh Gillbb024eb2024-04-07 23:34:00 -070014#include <xyz/openbmc_project/Software/ApplyTime/common.hpp>
Lei YU90532252018-05-24 11:15:24 +080015
16#ifdef WANT_SIGNATURE_VERIFY
Adriana Kobylakc98d9122020-05-05 10:36:01 -050017#include <filesystem>
Lei YU90532252018-05-24 11:15:24 +080018#endif
19
Gunnar Millsec1b41c2017-05-02 12:20:36 -050020namespace phosphor
21{
22namespace software
23{
24namespace updater
25{
26
Lei YU90532252018-05-24 11:15:24 +080027#ifdef WANT_SIGNATURE_VERIFY
Adriana Kobylakc98d9122020-05-05 10:36:01 -050028namespace fs = std::filesystem;
Lei YU90532252018-05-24 11:15:24 +080029#endif
30
Gunnar Millsb60add12017-08-24 16:41:42 -050031using AssociationList =
Adriana Kobylak2285fe02018-02-27 15:36:59 -060032 std::vector<std::tuple<std::string, std::string, std::string>>;
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -050033using ActivationInherit = sdbusplus::server::object_t<
Patrick Williams1e9a5f12023-08-23 16:53:06 -050034 sdbusplus::server::xyz::openbmc_project::software::Activation,
35 sdbusplus::server::xyz::openbmc_project::association::Definitions>;
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -050036using ActivationBlocksTransitionInherit =
Adriana Kobylakce82de52024-01-16 13:56:38 -060037 sdbusplus::server::object_t<sdbusplus::server::xyz::openbmc_project::
38 software::ActivationBlocksTransition>;
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -050039using RedundancyPriorityInherit = sdbusplus::server::object_t<
Patrick Williams1e9a5f12023-08-23 16:53:06 -050040 sdbusplus::server::xyz::openbmc_project::software::RedundancyPriority>;
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -050041using ActivationProgressInherit = sdbusplus::server::object_t<
Patrick Williams1e9a5f12023-08-23 16:53:06 -050042 sdbusplus::server::xyz::openbmc_project::software::ActivationProgress>;
Jagpal Singh Gillbb024eb2024-04-07 23:34:00 -070043using ApplyTimeIntf =
44 sdbusplus::common::xyz::openbmc_project::software::ApplyTime;
Saqib Khan4c1aec02017-07-06 11:46:13 -050045
Jayashankar Padatha0135602019-04-22 16:22:58 +053046constexpr auto applyTimeImmediate =
47 "xyz.openbmc_project.Software.ApplyTime.RequestedApplyTimes.Immediate";
48constexpr auto applyTimeIntf = "xyz.openbmc_project.Software.ApplyTime";
49constexpr auto dbusPropIntf = "org.freedesktop.DBus.Properties";
50constexpr auto applyTimeObjPath = "/xyz/openbmc_project/software/apply_time";
51constexpr auto applyTimeProp = "RequestedApplyTime";
52
Michael Tritzbed88af2017-07-19 16:00:06 -050053namespace sdbusRule = sdbusplus::bus::match::rules;
54
Saqib Khan4c1aec02017-07-06 11:46:13 -050055class ItemUpdater;
56class Activation;
57class RedundancyPriority;
58
59/** @class RedundancyPriority
60 * @brief OpenBMC RedundancyPriority implementation
61 * @details A concrete implementation for
62 * xyz.openbmc_project.Software.RedundancyPriority DBus API.
63 */
64class RedundancyPriority : public RedundancyPriorityInherit
65{
Adriana Kobylak2285fe02018-02-27 15:36:59 -060066 public:
67 /** @brief Constructs RedundancyPriority.
68 *
69 * @param[in] bus - The Dbus bus object
70 * @param[in] path - The Dbus object path
71 * @param[in] parent - Parent object.
72 * @param[in] value - The redundancyPriority value
73 * @param[in] freePriority - Call freePriorioty, default to true
74 */
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -050075 RedundancyPriority(sdbusplus::bus_t& bus, const std::string& path,
Adriana Kobylak2285fe02018-02-27 15:36:59 -060076 Activation& parent, uint8_t value,
77 bool freePriority = true) :
Lei YU29d84b02020-02-13 15:13:09 +080078 RedundancyPriorityInherit(bus, path.c_str(),
79 action::emit_interface_added),
80 parent(parent)
Adriana Kobylak2285fe02018-02-27 15:36:59 -060081 {
82 // Set Property
83 if (freePriority)
Saqib Khan4c1aec02017-07-06 11:46:13 -050084 {
Adriana Kobylak2285fe02018-02-27 15:36:59 -060085 priority(value);
86 }
87 else
88 {
89 sdbusPriority(value);
Saqib Khan140fcb12017-08-07 09:06:57 -050090 }
Adriana Kobylak2285fe02018-02-27 15:36:59 -060091 }
Saqib Khan4c1aec02017-07-06 11:46:13 -050092
Gunnar Millse11a2022018-03-23 12:04:48 -050093 /** @brief Overridden Priority property set function, calls freePriority
Adriana Kobylak2285fe02018-02-27 15:36:59 -060094 * to bump the duplicated priority values.
95 *
96 * @param[in] value - uint8_t
97 *
98 * @return Success or exception thrown
99 */
100 uint8_t priority(uint8_t value) override;
Adriana Kobylakb77551c2017-10-27 12:46:23 -0500101
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600102 /** @brief Non-Overriden Priority property set function
103 *
104 * @param[in] value - uint8_t
105 *
106 * @return Success or exception thrown
107 */
108 uint8_t sdbusPriority(uint8_t value);
Saqib Khan4c1aec02017-07-06 11:46:13 -0500109
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600110 /** @brief Priority property get function
111 *
112 * @returns uint8_t - The Priority value
113 */
114 using RedundancyPriorityInherit::priority;
Saqib Khan140fcb12017-08-07 09:06:57 -0500115
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600116 /** @brief Parent Object. */
117 Activation& parent;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500118};
Saqib Khanb0774702017-05-23 16:02:41 -0500119
120/** @class ActivationBlocksTransition
121 * @brief OpenBMC ActivationBlocksTransition implementation.
122 * @details A concrete implementation for
123 * xyz.openbmc_project.Software.ActivationBlocksTransition DBus API.
124 */
125class ActivationBlocksTransition : public ActivationBlocksTransitionInherit
126{
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600127 public:
128 /** @brief Constructs ActivationBlocksTransition.
129 *
130 * @param[in] bus - The Dbus bus object
131 * @param[in] path - The Dbus object path
132 */
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -0500133 ActivationBlocksTransition(sdbusplus::bus_t& bus, const std::string& path) :
Lei YU29d84b02020-02-13 15:13:09 +0800134 ActivationBlocksTransitionInherit(bus, path.c_str(),
135 action::emit_interface_added),
136 bus(bus)
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600137 {
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600138 enableRebootGuard();
139 }
Saqib Khan140fcb12017-08-07 09:06:57 -0500140
Pavithra Barithaya272bc1c2024-06-22 06:46:35 -0500141 ~ActivationBlocksTransition() override
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600142 {
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600143 disableRebootGuard();
144 }
Saqib Khan140fcb12017-08-07 09:06:57 -0500145
Pavithra Barithaya48de55f2024-06-22 05:30:44 -0500146 ActivationBlocksTransition(const ActivationBlocksTransition&) = delete;
147 ActivationBlocksTransition&
148 operator=(const ActivationBlocksTransition&) = delete;
149 ActivationBlocksTransition(ActivationBlocksTransition&&) = delete;
150 ActivationBlocksTransition&
151 operator=(ActivationBlocksTransition&&) = delete;
152
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600153 private:
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -0500154 sdbusplus::bus_t& bus;
Saqib Khanf37cefc2017-09-12 08:44:41 -0500155
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600156 /** @brief Enables a Guard that blocks any BMC reboot commands */
157 void enableRebootGuard();
Saqib Khanf37cefc2017-09-12 08:44:41 -0500158
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600159 /** @brief Disables any guard that was blocking the BMC reboot */
160 void disableRebootGuard();
Saqib Khanb0774702017-05-23 16:02:41 -0500161};
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500162
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500163class ActivationProgress : public ActivationProgressInherit
164{
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600165 public:
166 /** @brief Constructs ActivationProgress.
167 *
168 * @param[in] bus - The Dbus bus object
169 * @param[in] path - The Dbus object path
170 */
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -0500171 ActivationProgress(sdbusplus::bus_t& bus, const std::string& path) :
Lei YU29d84b02020-02-13 15:13:09 +0800172 ActivationProgressInherit(bus, path.c_str(),
173 action::emit_interface_added)
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600174 {
175 progress(0);
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600176 }
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500177};
178
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500179/** @class Activation
180 * @brief OpenBMC activation software management implementation.
181 * @details A concrete implementation for
182 * xyz.openbmc_project.Software.Activation DBus API.
183 */
Lei YU1be8d502018-06-20 11:48:36 +0800184class Activation : public ActivationInherit, public Flash
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500185{
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600186 public:
187 /** @brief Constructs Activation Software Manager
188 *
189 * @param[in] bus - The Dbus bus object
190 * @param[in] path - The Dbus object path
191 * @param[in] parent - Parent object.
192 * @param[in] versionId - The software version id
193 * @param[in] activationStatus - The status of Activation
194 * @param[in] assocs - Association objects
195 */
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -0500196 Activation(sdbusplus::bus_t& bus, const std::string& path,
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600197 ItemUpdater& parent, std::string& versionId,
Patrick Williams1e9a5f12023-08-23 16:53:06 -0500198 sdbusplus::server::xyz::openbmc_project::software::Activation::
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600199 Activations activationStatus,
200 AssociationList& assocs) :
Patrick Williams35aa9a82022-04-05 15:55:30 -0500201 ActivationInherit(bus, path.c_str(),
202 ActivationInherit::action::defer_emit),
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600203 bus(bus), path(path), parent(parent), versionId(versionId),
204 systemdSignals(
205 bus,
206 sdbusRule::type::signal() + sdbusRule::member("JobRemoved") +
207 sdbusRule::path("/org/freedesktop/systemd1") +
208 sdbusRule::interface("org.freedesktop.systemd1.Manager"),
209 std::bind(std::mem_fn(&Activation::unitStateChange), this,
210 std::placeholders::_1))
211 {
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600212 // Set Properties.
213 activation(activationStatus);
214 associations(assocs);
Gunnar Millsb60add12017-08-24 16:41:42 -0500215
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600216 // Emit deferred signal.
217 emit_object_added();
218 }
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500219
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600220 /** @brief Overloaded Activation property setter function
221 *
222 * @param[in] value - One of Activation::Activations
223 *
224 * @return Success or exception thrown
225 */
226 Activations activation(Activations value) override;
Saqib Khanb0774702017-05-23 16:02:41 -0500227
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600228 /** @brief Activation */
229 using ActivationInherit::activation;
Leonel Gonzaleze4233682017-07-07 14:38:25 -0500230
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600231 /** @brief Overloaded requestedActivation property setter function
232 *
233 * @param[in] value - One of Activation::RequestedActivations
234 *
235 * @return Success or exception thrown
236 */
237 RequestedActivations
238 requestedActivation(RequestedActivations value) override;
Saqib Khanb0774702017-05-23 16:02:41 -0500239
Adriana Kobylak9f89e2e2018-05-30 13:16:20 -0500240 /** @brief Overloaded write flash function */
241 void flashWrite() override;
242
Adriana Kobylakb824b2f2020-05-14 14:57:53 -0500243 /**
244 * @brief Handle the success of the flashWrite() function
245 *
246 * @details Perform anything that is necessary to mark the activation
247 * successful after the image has been written to flash. Sets the Activation
248 * value to Active.
249 */
250 void onFlashWriteSuccess();
251
Vijay Khemkae9f6c842020-01-14 14:32:39 -0800252#ifdef HOST_BIOS_UPGRADE
253 /* @brief write to Host flash function */
254 void flashWriteHost();
255
256 /** @brief Function that acts on Bios upgrade service file state changes */
Pavithra Barithayaf9a69252024-06-25 00:35:36 -0500257 void onStateChangesBios(sdbusplus::message_t& /*msg*/);
Vijay Khemkae9f6c842020-01-14 14:32:39 -0800258#endif
259
Adriana Kobylak3ce563a2018-06-06 16:41:15 -0500260 /** @brief Overloaded function that acts on service file state changes */
Pavithra Barithayaf9a69252024-06-25 00:35:36 -0500261 void onStateChanges(sdbusplus::message_t& /*msg*/) override;
Adriana Kobylak3ce563a2018-06-06 16:41:15 -0500262
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 */
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -0500271 void unitStateChange(sdbusplus::message_t& 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
Jayashankar Padatha0135602019-04-22 16:22:58 +0530298 /**
299 * @brief Determine the configured image apply time value
300 *
301 * @return true if the image apply time value is immediate
302 **/
303 bool checkApplyTimeImmediate();
304
305 /**
306 * @brief Reboot the BMC. Called when ApplyTime is immediate.
307 *
308 * @return none
309 **/
310 void rebootBmc();
311
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600312 /** @brief Persistent sdbusplus DBus bus connection */
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -0500313 sdbusplus::bus_t& bus;
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500314
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600315 /** @brief Persistent DBus object path */
316 std::string path;
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500317
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600318 /** @brief Parent Object. */
319 ItemUpdater& parent;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500320
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600321 /** @brief Version id */
322 std::string versionId;
Saqib Khanb0774702017-05-23 16:02:41 -0500323
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600324 /** @brief Persistent ActivationBlocksTransition dbus object */
325 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500326
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600327 /** @brief Persistent RedundancyPriority dbus object */
328 std::unique_ptr<RedundancyPriority> redundancyPriority;
Michael Tritzbed88af2017-07-19 16:00:06 -0500329
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600330 /** @brief Persistent ActivationProgress dbus object */
331 std::unique_ptr<ActivationProgress> activationProgress;
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500332
Jagpal Singh Gillbb024eb2024-04-07 23:34:00 -0700333 /** @brief Apply time */
334 ApplyTimeIntf::RequestedApplyTimes applyTime;
335
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600336 /** @brief Used to subscribe to dbus systemd signals **/
337 sdbusplus::bus::match_t systemdSignals;
Michael Tritzbed88af2017-07-19 16:00:06 -0500338
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600339 /** @brief Tracks whether the read-write volume has been created as
340 * part of the activation process. **/
341 bool rwVolumeCreated = false;
Michael Tritzbed88af2017-07-19 16:00:06 -0500342
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600343 /** @brief Tracks whether the read-only volume has been created as
344 * part of the activation process. **/
345 bool roVolumeCreated = false;
Adriana Kobylak166bdf32018-04-09 14:24:06 -0500346
347 /** @brief Tracks if the service that updates the U-Boot environment
348 * variables has completed. **/
349 bool ubootEnvVarsUpdated = false;
Lei YU90532252018-05-24 11:15:24 +0800350
351#ifdef WANT_SIGNATURE_VERIFY
352 private:
353 /** @brief Verify signature of the images.
354 *
355 * @param[in] imageDir - The path of images to verify
356 * @param[in] confDir - The path of configs for verification
357 *
358 * @return true if verification successful and false otherwise
359 */
Pavithra Barithayac5f6e7e2024-06-24 09:50:21 -0500360 static bool verifySignature(const fs::path& imageDir,
361 const fs::path& confDir);
Lei YU90532252018-05-24 11:15:24 +0800362
363 /** @brief Called when image verification fails. */
364 void onVerifyFailed();
365#endif
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500366};
367
368} // namespace updater
369} // namespace software
370} // namespace phosphor