blob: 31f7023f360c98e7d55204f24e9c7e257b1df2af [file] [log] [blame]
Adriana Kobylak2d8fa222017-03-15 12:34:32 -05001#pragma once
2
Gunnar Millsf6ed5892018-09-07 17:08:02 -05003#include "config.h"
4
Jayashankar Padath4d3d9122019-07-24 16:46:22 +05305#include "utils.hpp"
Gunnar Millsf6ed5892018-09-07 17:08:02 -05006#include "xyz/openbmc_project/Software/ActivationProgress/server.hpp"
7#include "xyz/openbmc_project/Software/ExtendedVersion/server.hpp"
8#include "xyz/openbmc_project/Software/RedundancyPriority/server.hpp"
9
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -050010#include <sdbusplus/server.hpp>
John Wangd05d4722019-09-11 15:18:15 +080011#include <xyz/openbmc_project/Association/Definitions/server.hpp>
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050012#include <xyz/openbmc_project/Software/Activation/server.hpp>
Adriana Kobylakea9626f2017-04-05 15:37:40 -050013#include <xyz/openbmc_project/Software/ActivationBlocksTransition/server.hpp>
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050014
Brad Bishop8facccf2020-11-04 09:44:58 -050015#include <string>
16
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050017namespace openpower
18{
19namespace software
20{
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -050021namespace updater
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050022{
23
Gunnar Mills3edb84b2017-08-18 15:13:15 -050024using AssociationList =
Adriana Kobylak70dcb632018-02-27 15:46:52 -060025 std::vector<std::tuple<std::string, std::string, std::string>>;
Patrick Williams0dea1992022-07-22 19:26:52 -050026using ActivationInherit = sdbusplus::server::object_t<
Saqib Khan7254f0e2017-04-10 21:45:37 -050027 sdbusplus::xyz::openbmc_project::Software::server::ExtendedVersion,
Saqib Khanc350c612017-08-13 13:36:44 -050028 sdbusplus::xyz::openbmc_project::Software::server::Activation,
John Wangd05d4722019-09-11 15:18:15 +080029 sdbusplus::xyz::openbmc_project::Association::server::Definitions>;
Patrick Williams0dea1992022-07-22 19:26:52 -050030using ActivationBlocksTransitionInherit =
31 sdbusplus::server::object_t<sdbusplus::xyz::openbmc_project::Software::
32 server::ActivationBlocksTransition>;
33using RedundancyPriorityInherit = sdbusplus::server::object_t<
Saqib Khan942df8a2017-06-01 14:09:27 -050034 sdbusplus::xyz::openbmc_project::Software::server::RedundancyPriority>;
Patrick Williams0dea1992022-07-22 19:26:52 -050035using ActivationProgressInherit = sdbusplus::server::object_t<
Michael Tritz1793b642017-06-28 18:35:58 -050036 sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>;
Saqib Khan942df8a2017-06-01 14:09:27 -050037
Jayashankar Padath4d3d9122019-07-24 16:46:22 +053038constexpr auto applyTimeImmediate =
39 "xyz.openbmc_project.Software.ApplyTime.RequestedApplyTimes.Immediate";
40constexpr auto applyTimeIntf = "xyz.openbmc_project.Software.ApplyTime";
41constexpr auto dbusPropIntf = "org.freedesktop.DBus.Properties";
42constexpr auto applyTimeObjPath = "/xyz/openbmc_project/software/apply_time";
43constexpr auto applyTimeProp = "RequestedApplyTime";
44
45constexpr auto hostStateIntf = "xyz.openbmc_project.State.Host";
46constexpr auto hostStateObjPath = "/xyz/openbmc_project/state/host0";
47constexpr auto hostStateRebootProp = "RequestedHostTransition";
48constexpr auto hostStateRebootVal =
49 "xyz.openbmc_project.State.Host.Transition.Reboot";
50
Michael Tritz9d25b602017-06-14 14:41:43 -050051namespace sdbusRule = sdbusplus::bus::match::rules;
52
Saqib Khan81bac882017-06-08 12:17:01 -050053class ItemUpdater;
54class Activation;
55class RedundancyPriority;
56
Saqib Khan942df8a2017-06-01 14:09:27 -050057/** @class RedundancyPriority
58 * @brief OpenBMC RedundancyPriority implementation
59 * @details A concrete implementation for
60 * xyz.openbmc_project.Software.RedundancyPriority DBus API.
61 */
62class RedundancyPriority : public RedundancyPriorityInherit
63{
Adriana Kobylak70dcb632018-02-27 15:46:52 -060064 public:
65 /** @brief Constructs RedundancyPriority.
66 *
67 * @param[in] bus - The Dbus bus object
68 * @param[in] path - The Dbus object path
69 * @param[in] parent - Parent object.
70 * @param[in] value - The redundancyPriority value
71 */
Patrick Williams0dea1992022-07-22 19:26:52 -050072 RedundancyPriority(sdbusplus::bus_t& bus, const std::string& path,
Adriana Kobylak70dcb632018-02-27 15:46:52 -060073 Activation& parent, uint8_t value) :
Albert Zhang7f1967d2020-03-02 14:12:08 +080074 RedundancyPriorityInherit(bus, path.c_str(),
75 action::emit_interface_added),
76 parent(parent)
Adriana Kobylak70dcb632018-02-27 15:46:52 -060077 {
78 // Set Property
79 priority(value);
Adriana Kobylak70dcb632018-02-27 15:46:52 -060080 }
Saqib Khan2021b4c2017-06-07 14:37:36 -050081
Adriana Kobylak70dcb632018-02-27 15:46:52 -060082 /** @brief Overloaded Priority property set function
83 *
84 * @param[in] value - uint8_t
85 *
86 * @return Success or exception thrown
87 */
88 uint8_t priority(uint8_t value) override;
Saqib Khan81bac882017-06-08 12:17:01 -050089
Adriana Kobylak70dcb632018-02-27 15:46:52 -060090 /** @brief Priority property get function
91 *
92 * @returns uint8_t - The Priority value
93 */
94 using RedundancyPriorityInherit::priority;
Saqib Khan81bac882017-06-08 12:17:01 -050095
Adriana Kobylak70dcb632018-02-27 15:46:52 -060096 /** @brief Parent Object. */
97 Activation& parent;
Saqib Khan942df8a2017-06-01 14:09:27 -050098};
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050099
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500100/** @class ActivationBlocksTransition
101 * @brief OpenBMC ActivationBlocksTransition implementation.
102 * @details A concrete implementation for
103 * xyz.openbmc_project.Software.ActivationBlocksTransition DBus API.
104 */
105class ActivationBlocksTransition : public ActivationBlocksTransitionInherit
106{
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600107 public:
108 /** @brief Constructs ActivationBlocksTransition.
109 *
110 * @param[in] bus - The Dbus bus object
111 * @param[in] path - The Dbus object path
112 */
Patrick Williams0dea1992022-07-22 19:26:52 -0500113 ActivationBlocksTransition(sdbusplus::bus_t& bus, const std::string& path) :
Albert Zhang7f1967d2020-03-02 14:12:08 +0800114 ActivationBlocksTransitionInherit(bus, path.c_str(),
115 action::emit_interface_added)
Adriana Kobylaka8eda562017-07-17 15:24:29 -0500116
Brad Bishop8facccf2020-11-04 09:44:58 -0500117 {}
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500118};
119
Michael Tritz1793b642017-06-28 18:35:58 -0500120class ActivationProgress : public ActivationProgressInherit
121{
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600122 public:
123 /** @brief Constructs ActivationProgress.
124 *
125 * @param[in] bus - The Dbus bus object
126 * @param[in] path - The Dbus object path
127 */
Patrick Williams0dea1992022-07-22 19:26:52 -0500128 ActivationProgress(sdbusplus::bus_t& bus, const std::string& path) :
Albert Zhang7f1967d2020-03-02 14:12:08 +0800129 ActivationProgressInherit(bus, path.c_str(),
130 action::emit_interface_added)
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600131 {
132 progress(0);
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600133 }
Michael Tritz1793b642017-06-28 18:35:58 -0500134};
135
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500136/** @class Activation
137 * @brief OpenBMC activation software management implementation.
138 * @details A concrete implementation for
139 * xyz.openbmc_project.Software.Activation DBus API.
140 */
141class Activation : public ActivationInherit
142{
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600143 public:
144 /** @brief Constructs Activation Software Manager
145 *
146 * @param[in] bus - The Dbus bus object
147 * @param[in] path - The Dbus object path
148 * @param[in] parent - Parent object.
149 * @param[in] versionId - The software version id
150 * @param[in] extVersion - The extended version
151 * @param[in] activationStatus - The status of Activation
152 * @param[in] assocs - Association objects
153 */
Patrick Williams0dea1992022-07-22 19:26:52 -0500154 Activation(sdbusplus::bus_t& bus, const std::string& path,
Lei YUa9ac9272019-02-22 16:38:35 +0800155 ItemUpdater& parent, const std::string& versionId,
156 const std::string& extVersion,
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600157 sdbusplus::xyz::openbmc_project::Software::server::Activation::
158 Activations activationStatus,
159 AssociationList& assocs) :
Patrick Williams9c887d12022-04-05 21:39:40 -0500160 ActivationInherit(bus, path.c_str(),
161 ActivationInherit::action::defer_emit),
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600162 bus(bus), path(path), parent(parent), versionId(versionId),
163 systemdSignals(
164 bus,
165 sdbusRule::type::signal() + sdbusRule::member("JobRemoved") +
166 sdbusRule::path("/org/freedesktop/systemd1") +
167 sdbusRule::interface("org.freedesktop.systemd1.Manager"),
168 std::bind(std::mem_fn(&Activation::unitStateChange), this,
169 std::placeholders::_1))
170 {
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600171 // Set Properties.
172 extendedVersion(extVersion);
173 activation(activationStatus);
174 associations(assocs);
Gunnar Mills3edb84b2017-08-18 15:13:15 -0500175
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600176 // Emit deferred signal.
177 emit_object_added();
178 }
Lei YU9b21efc2019-02-21 15:52:53 +0800179 virtual ~Activation() = default;
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500180
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600181 /** @brief Overloaded requestedActivation property setter function
182 *
183 * @param[in] value - One of Activation::RequestedActivations
184 *
185 * @return Success or exception thrown
186 */
187 RequestedActivations
188 requestedActivation(RequestedActivations value) override;
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500189
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600190 /**
191 * @brief subscribe to the systemd signals
192 *
193 * This object needs to capture when it's systemd targets complete
194 * so it can keep it's state updated
195 *
196 **/
197 void subscribeToSystemdSignals();
Michael Tritz9d25b602017-06-14 14:41:43 -0500198
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600199 /**
200 * @brief unsubscribe from the systemd signals
201 *
202 * Once the activation process has completed successfully, we can
203 * safely unsubscribe from systemd signals.
204 *
205 **/
206 void unsubscribeFromSystemdSignals();
Michael Tritz1cb127f2017-07-26 15:40:38 -0500207
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600208 /** @brief Persistent sdbusplus DBus bus connection */
Patrick Williams0dea1992022-07-22 19:26:52 -0500209 sdbusplus::bus_t& bus;
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500210
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600211 /** @brief Persistent DBus object path */
212 std::string path;
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500213
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600214 /** @brief Parent Object. */
215 ItemUpdater& parent;
Saqib Khan81bac882017-06-08 12:17:01 -0500216
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600217 /** @brief Version id */
218 std::string versionId;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500219
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600220 /** @brief Persistent ActivationBlocksTransition dbus object */
221 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Saqib Khan942df8a2017-06-01 14:09:27 -0500222
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600223 /** @brief Persistent ActivationProgress dbus object */
224 std::unique_ptr<ActivationProgress> activationProgress;
Michael Tritz1793b642017-06-28 18:35:58 -0500225
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600226 /** @brief Persistent RedundancyPriority dbus object */
227 std::unique_ptr<RedundancyPriority> redundancyPriority;
Michael Tritz9d25b602017-06-14 14:41:43 -0500228
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600229 /** @brief Used to subscribe to dbus systemd signals **/
230 sdbusplus::bus::match_t systemdSignals;
Michael Tritz9d25b602017-06-14 14:41:43 -0500231
Jayashankar Padath4d3d9122019-07-24 16:46:22 +0530232 /**
233 * @brief Determine the configured image apply time value
234 *
235 * @return true if the image apply time value is immediate
236 **/
237 bool checkApplyTimeImmediate();
238
239 /**
240 * @brief Reboot the Host. Called when ApplyTime is immediate.
241 *
242 * @return none
243 **/
244 void rebootHost();
245
Lei YU9b21efc2019-02-21 15:52:53 +0800246 protected:
247 /** @brief Check if systemd state change is relevant to this object
248 *
249 * Instance specific interface to handle the detected systemd state
250 * change
251 *
252 * @param[in] msg - Data associated with subscribed signal
253 *
254 */
Patrick Williams0dea1992022-07-22 19:26:52 -0500255 virtual void unitStateChange(sdbusplus::message_t& msg) = 0;
Lei YU9b21efc2019-02-21 15:52:53 +0800256
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600257 /**
258 * @brief Deletes the version from Image Manager and the
259 * untar image from image upload dir.
260 */
261 void deleteImageManagerObject();
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500262
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600263 /** @brief Member function for clarity & brevity at activation start */
Lei YU9b21efc2019-02-21 15:52:53 +0800264 virtual void startActivation() = 0;
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500265
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600266 /** @brief Member function for clarity & brevity at activation end */
Lei YU9b21efc2019-02-21 15:52:53 +0800267 virtual void finishActivation() = 0;
Jayanth Othayoth11271fb2018-03-29 10:25:50 -0500268
269#ifdef WANT_SIGNATURE_VERIFY
270 /**
271 * @brief Wrapper function for the signature verify function.
272 * Signature class verify function used for validating
273 * signed image. Also added additional logic to continue
274 * update process in lab environment by checking the
275 * fieldModeEnabled property.
276 *
Lei YU2b2d2292019-03-18 15:22:56 +0800277 * @param[in] pnorFileName - The PNOR filename in image dir
278 *
Jayanth Othayoth11271fb2018-03-29 10:25:50 -0500279 * @return true if successful signature validation or field
280 * mode is disabled.
281 * false for unsuccessful signature validation or
282 * any internal failure during the mapper call.
283 */
Lei YU2b2d2292019-03-18 15:22:56 +0800284 bool validateSignature(const std::string& pnorFileName);
Jayanth Othayoth11271fb2018-03-29 10:25:50 -0500285
286 /**
287 * @brief Gets the fieldModeEnabled property value.
288 *
289 * @return fieldModeEnabled property value
290 * @error InternalFailure exception thrown
291 */
292 bool fieldModeEnabled();
Jayanth Othayoth11271fb2018-03-29 10:25:50 -0500293#endif
Adriana Kobylakea9626f2017-04-05 15:37:40 -0500294};
295
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500296} // namespace updater
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500297} // namespace software
298} // namespace openpower