blob: cc2df97822930264744099444ebbd9c8b2f2d61e [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>>;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050026using ActivationInherit = sdbusplus::server::object::object<
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>;
Adriana Kobylakea9626f2017-04-05 15:37:40 -050030using ActivationBlocksTransitionInherit = sdbusplus::server::object::object<
Adriana Kobylak70dcb632018-02-27 15:46:52 -060031 sdbusplus::xyz::openbmc_project::Software::server::
32 ActivationBlocksTransition>;
Saqib Khan942df8a2017-06-01 14:09:27 -050033using RedundancyPriorityInherit = sdbusplus::server::object::object<
34 sdbusplus::xyz::openbmc_project::Software::server::RedundancyPriority>;
Michael Tritz1793b642017-06-28 18:35:58 -050035using ActivationProgressInherit = sdbusplus::server::object::object<
36 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 */
72 RedundancyPriority(sdbusplus::bus::bus& bus, const std::string& path,
73 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 */
113 ActivationBlocksTransition(sdbusplus::bus::bus& bus,
114 const std::string& path) :
Albert Zhang7f1967d2020-03-02 14:12:08 +0800115 ActivationBlocksTransitionInherit(bus, path.c_str(),
116 action::emit_interface_added)
Adriana Kobylaka8eda562017-07-17 15:24:29 -0500117
Brad Bishop8facccf2020-11-04 09:44:58 -0500118 {}
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500119};
120
Michael Tritz1793b642017-06-28 18:35:58 -0500121class ActivationProgress : public ActivationProgressInherit
122{
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600123 public:
124 /** @brief Constructs ActivationProgress.
125 *
126 * @param[in] bus - The Dbus bus object
127 * @param[in] path - The Dbus object path
128 */
129 ActivationProgress(sdbusplus::bus::bus& bus, const std::string& path) :
Albert Zhang7f1967d2020-03-02 14:12:08 +0800130 ActivationProgressInherit(bus, path.c_str(),
131 action::emit_interface_added)
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600132 {
133 progress(0);
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600134 }
Michael Tritz1793b642017-06-28 18:35:58 -0500135};
136
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500137/** @class Activation
138 * @brief OpenBMC activation software management implementation.
139 * @details A concrete implementation for
140 * xyz.openbmc_project.Software.Activation DBus API.
141 */
142class Activation : public ActivationInherit
143{
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600144 public:
145 /** @brief Constructs Activation Software Manager
146 *
147 * @param[in] bus - The Dbus bus object
148 * @param[in] path - The Dbus object path
149 * @param[in] parent - Parent object.
150 * @param[in] versionId - The software version id
151 * @param[in] extVersion - The extended version
152 * @param[in] activationStatus - The status of Activation
153 * @param[in] assocs - Association objects
154 */
155 Activation(sdbusplus::bus::bus& bus, const std::string& path,
Lei YUa9ac9272019-02-22 16:38:35 +0800156 ItemUpdater& parent, const std::string& versionId,
157 const std::string& extVersion,
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600158 sdbusplus::xyz::openbmc_project::Software::server::Activation::
159 Activations activationStatus,
160 AssociationList& assocs) :
Patrick Williams9c887d12022-04-05 21:39:40 -0500161 ActivationInherit(bus, path.c_str(),
162 ActivationInherit::action::defer_emit),
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600163 bus(bus), path(path), parent(parent), versionId(versionId),
164 systemdSignals(
165 bus,
166 sdbusRule::type::signal() + sdbusRule::member("JobRemoved") +
167 sdbusRule::path("/org/freedesktop/systemd1") +
168 sdbusRule::interface("org.freedesktop.systemd1.Manager"),
169 std::bind(std::mem_fn(&Activation::unitStateChange), this,
170 std::placeholders::_1))
171 {
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600172 // Set Properties.
173 extendedVersion(extVersion);
174 activation(activationStatus);
175 associations(assocs);
Gunnar Mills3edb84b2017-08-18 15:13:15 -0500176
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600177 // Emit deferred signal.
178 emit_object_added();
179 }
Lei YU9b21efc2019-02-21 15:52:53 +0800180 virtual ~Activation() = default;
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500181
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600182 /** @brief Overloaded requestedActivation property setter function
183 *
184 * @param[in] value - One of Activation::RequestedActivations
185 *
186 * @return Success or exception thrown
187 */
188 RequestedActivations
189 requestedActivation(RequestedActivations value) override;
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500190
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600191 /**
192 * @brief subscribe to the systemd signals
193 *
194 * This object needs to capture when it's systemd targets complete
195 * so it can keep it's state updated
196 *
197 **/
198 void subscribeToSystemdSignals();
Michael Tritz9d25b602017-06-14 14:41:43 -0500199
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600200 /**
201 * @brief unsubscribe from the systemd signals
202 *
203 * Once the activation process has completed successfully, we can
204 * safely unsubscribe from systemd signals.
205 *
206 **/
207 void unsubscribeFromSystemdSignals();
Michael Tritz1cb127f2017-07-26 15:40:38 -0500208
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600209 /** @brief Persistent sdbusplus DBus bus connection */
210 sdbusplus::bus::bus& bus;
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500211
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600212 /** @brief Persistent DBus object path */
213 std::string path;
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500214
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600215 /** @brief Parent Object. */
216 ItemUpdater& parent;
Saqib Khan81bac882017-06-08 12:17:01 -0500217
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600218 /** @brief Version id */
219 std::string versionId;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500220
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600221 /** @brief Persistent ActivationBlocksTransition dbus object */
222 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Saqib Khan942df8a2017-06-01 14:09:27 -0500223
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600224 /** @brief Persistent ActivationProgress dbus object */
225 std::unique_ptr<ActivationProgress> activationProgress;
Michael Tritz1793b642017-06-28 18:35:58 -0500226
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600227 /** @brief Persistent RedundancyPriority dbus object */
228 std::unique_ptr<RedundancyPriority> redundancyPriority;
Michael Tritz9d25b602017-06-14 14:41:43 -0500229
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600230 /** @brief Used to subscribe to dbus systemd signals **/
231 sdbusplus::bus::match_t systemdSignals;
Michael Tritz9d25b602017-06-14 14:41:43 -0500232
Jayashankar Padath4d3d9122019-07-24 16:46:22 +0530233 /**
234 * @brief Determine the configured image apply time value
235 *
236 * @return true if the image apply time value is immediate
237 **/
238 bool checkApplyTimeImmediate();
239
240 /**
241 * @brief Reboot the Host. Called when ApplyTime is immediate.
242 *
243 * @return none
244 **/
245 void rebootHost();
246
Lei YU9b21efc2019-02-21 15:52:53 +0800247 protected:
248 /** @brief Check if systemd state change is relevant to this object
249 *
250 * Instance specific interface to handle the detected systemd state
251 * change
252 *
253 * @param[in] msg - Data associated with subscribed signal
254 *
255 */
256 virtual void unitStateChange(sdbusplus::message::message& msg) = 0;
257
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600258 /**
259 * @brief Deletes the version from Image Manager and the
260 * untar image from image upload dir.
261 */
262 void deleteImageManagerObject();
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500263
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600264 /** @brief Member function for clarity & brevity at activation start */
Lei YU9b21efc2019-02-21 15:52:53 +0800265 virtual void startActivation() = 0;
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500266
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600267 /** @brief Member function for clarity & brevity at activation end */
Lei YU9b21efc2019-02-21 15:52:53 +0800268 virtual void finishActivation() = 0;
Jayanth Othayoth11271fb2018-03-29 10:25:50 -0500269
270#ifdef WANT_SIGNATURE_VERIFY
271 /**
272 * @brief Wrapper function for the signature verify function.
273 * Signature class verify function used for validating
274 * signed image. Also added additional logic to continue
275 * update process in lab environment by checking the
276 * fieldModeEnabled property.
277 *
Lei YU2b2d2292019-03-18 15:22:56 +0800278 * @param[in] pnorFileName - The PNOR filename in image dir
279 *
Jayanth Othayoth11271fb2018-03-29 10:25:50 -0500280 * @return true if successful signature validation or field
281 * mode is disabled.
282 * false for unsuccessful signature validation or
283 * any internal failure during the mapper call.
284 */
Lei YU2b2d2292019-03-18 15:22:56 +0800285 bool validateSignature(const std::string& pnorFileName);
Jayanth Othayoth11271fb2018-03-29 10:25:50 -0500286
287 /**
288 * @brief Gets the fieldModeEnabled property value.
289 *
290 * @return fieldModeEnabled property value
291 * @error InternalFailure exception thrown
292 */
293 bool fieldModeEnabled();
Jayanth Othayoth11271fb2018-03-29 10:25:50 -0500294#endif
Adriana Kobylakea9626f2017-04-05 15:37:40 -0500295};
296
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500297} // namespace updater
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500298} // namespace software
299} // namespace openpower