blob: de7d9822db6585f80146f13e3d27f31b3c17c0e5 [file] [log] [blame]
Saqib Khanb0774702017-05-23 16:02:41 -05001#include "activation.hpp"
Saqib Khan4c1aec02017-07-06 11:46:13 -05002#include "item_updater.hpp"
Michael Tritzf2b5e0d2017-07-25 14:39:34 -05003#include "config.h"
Saqib Khan5d532672017-08-09 10:44:50 -05004#include "serialize.hpp"
Saqib Khanb9da6632017-09-13 09:48:37 -05005#include <phosphor-logging/log.hpp>
6
Saqib Khanb0774702017-05-23 16:02:41 -05007namespace phosphor
8{
9namespace software
10{
11namespace updater
12{
13
14namespace softwareServer = sdbusplus::xyz::openbmc_project::Software::server;
15
Saqib Khanb9da6632017-09-13 09:48:37 -050016using namespace phosphor::logging;
17
Michael Tritzbed88af2017-07-19 16:00:06 -050018void Activation::subscribeToSystemdSignals()
19{
Michael Tritzf2b5e0d2017-07-25 14:39:34 -050020 auto method = this->bus.new_method_call(SYSTEMD_BUSNAME,
Michael Tritzbed88af2017-07-19 16:00:06 -050021 SYSTEMD_PATH,
Michael Tritzf2b5e0d2017-07-25 14:39:34 -050022 SYSTEMD_INTERFACE,
Michael Tritzbed88af2017-07-19 16:00:06 -050023 "Subscribe");
24 this->bus.call_noreply(method);
25
26 return;
27}
28
Michael Tritzf2b5e0d2017-07-25 14:39:34 -050029void Activation::unsubscribeFromSystemdSignals()
30{
31 auto method = this->bus.new_method_call(SYSTEMD_BUSNAME,
32 SYSTEMD_PATH,
33 SYSTEMD_INTERFACE,
34 "Unsubscribe");
35 this->bus.call_noreply(method);
36
37 return;
38}
39
Saqib Khanb0774702017-05-23 16:02:41 -050040auto Activation::activation(Activations value) ->
41 Activations
42{
Saqib Khan4c1aec02017-07-06 11:46:13 -050043
Adriana Kobylak8bd84c82018-01-24 14:19:24 -060044 if ((value != softwareServer::Activation::Activations::Active) &&
45 (value != softwareServer::Activation::Activations::Activating))
Saqib Khan4c1aec02017-07-06 11:46:13 -050046 {
47 redundancyPriority.reset(nullptr);
48 }
49
Saqib Khanb0774702017-05-23 16:02:41 -050050 if (value == softwareServer::Activation::Activations::Activating)
51 {
Michael Tritzbed88af2017-07-19 16:00:06 -050052 if (rwVolumeCreated == false && roVolumeCreated == false)
Saqib Khanb0774702017-05-23 16:02:41 -050053 {
Michael Tritz0edd4ad2017-07-26 14:27:42 -050054 if (!activationProgress)
55 {
56 activationProgress = std::make_unique<ActivationProgress>(bus,
Gunnar Mills3fa38202017-10-08 17:07:43 -050057 path);
Michael Tritz0edd4ad2017-07-26 14:27:42 -050058 }
59
Michael Tritzbed88af2017-07-19 16:00:06 -050060 if (!activationBlocksTransition)
61 {
62 activationBlocksTransition =
63 std::make_unique<ActivationBlocksTransition>(
64 bus,
65 path);
66 }
Saqib Khan4c1aec02017-07-06 11:46:13 -050067
Michael Tritzbed88af2017-07-19 16:00:06 -050068 auto method = bus.new_method_call(
Michael Tritzf2b5e0d2017-07-25 14:39:34 -050069 SYSTEMD_BUSNAME,
Michael Tritzbed88af2017-07-19 16:00:06 -050070 SYSTEMD_PATH,
Michael Tritzf2b5e0d2017-07-25 14:39:34 -050071 SYSTEMD_INTERFACE,
Michael Tritzbed88af2017-07-19 16:00:06 -050072 "StartUnit");
73 method.append("obmc-flash-bmc-ubirw.service", "replace");
74 bus.call_noreply(method);
75
76 auto roServiceFile = "obmc-flash-bmc-ubiro@" + versionId +
77 ".service";
78 method = bus.new_method_call(
Michael Tritzf2b5e0d2017-07-25 14:39:34 -050079 SYSTEMD_BUSNAME,
Michael Tritzbed88af2017-07-19 16:00:06 -050080 SYSTEMD_PATH,
Michael Tritzf2b5e0d2017-07-25 14:39:34 -050081 SYSTEMD_INTERFACE,
Michael Tritzbed88af2017-07-19 16:00:06 -050082 "StartUnit");
83 method.append(roServiceFile, "replace");
84 bus.call_noreply(method);
Michael Tritz0edd4ad2017-07-26 14:27:42 -050085
86 activationProgress->progress(10);
Michael Tritzbed88af2017-07-19 16:00:06 -050087 }
88 else if (rwVolumeCreated == true && roVolumeCreated == true)
Saqib Khan4c1aec02017-07-06 11:46:13 -050089 {
Adriana Kobylak4c3edc92018-01-24 14:50:15 -060090 if (ubootEnvVarsUpdated == false)
Michael Tritzbed88af2017-07-19 16:00:06 -050091 {
Adriana Kobylak4c3edc92018-01-24 14:50:15 -060092 activationProgress->progress(90);
93
94 if (!redundancyPriority)
95 {
96 redundancyPriority =
97 std::make_unique<RedundancyPriority>(
98 bus,
99 path,
100 *this,
101 0);
102 }
Michael Tritzbed88af2017-07-19 16:00:06 -0500103 }
Adriana Kobylak4c3edc92018-01-24 14:50:15 -0600104 else
105 {
106 activationProgress->progress(100);
Saqib Khan4c1aec02017-07-06 11:46:13 -0500107
Adriana Kobylak4c3edc92018-01-24 14:50:15 -0600108 activationBlocksTransition.reset(nullptr);
109 activationProgress.reset(nullptr);
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500110
Adriana Kobylak4c3edc92018-01-24 14:50:15 -0600111 rwVolumeCreated = false;
112 roVolumeCreated = false;
113 ubootEnvVarsUpdated = false;
114 Activation::unsubscribeFromSystemdSignals();
Michael Tritzf2b5e0d2017-07-25 14:39:34 -0500115
Adriana Kobylak4c3edc92018-01-24 14:50:15 -0600116 // Remove version object from image manager
117 Activation::deleteImageManagerObject();
Michael Tritzf2b5e0d2017-07-25 14:39:34 -0500118
Adriana Kobylak4c3edc92018-01-24 14:50:15 -0600119 // Create active association
120 parent.createActiveAssociation(path);
Saqib Khanee13e832017-10-23 12:53:11 -0500121
Adriana Kobylak4c3edc92018-01-24 14:50:15 -0600122 return softwareServer::Activation::activation(
123 softwareServer::Activation::Activations::Active);
124 }
Michael Tritzbed88af2017-07-19 16:00:06 -0500125 }
Saqib Khanb0774702017-05-23 16:02:41 -0500126 }
127 else
128 {
129 activationBlocksTransition.reset(nullptr);
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500130 activationProgress.reset(nullptr);
Saqib Khanb0774702017-05-23 16:02:41 -0500131 }
132 return softwareServer::Activation::activation(value);
133}
134
Saqib Khanee13e832017-10-23 12:53:11 -0500135void Activation::deleteImageManagerObject()
136{
Saqib Khanee13e832017-10-23 12:53:11 -0500137 // Call the Delete object for <versionID> inside image_manager
Adriana Kobylak00bd9022018-01-24 13:55:58 -0600138 auto method = this->bus.new_method_call(VERSION_BUSNAME,
Saqib Khanee13e832017-10-23 12:53:11 -0500139 path.c_str(),
140 "xyz.openbmc_project.Object.Delete",
141 "Delete");
Adriana Kobylak00bd9022018-01-24 13:55:58 -0600142 auto mapperResponseMsg = bus.call(method);
Saqib Khanee13e832017-10-23 12:53:11 -0500143 //Check that the bus call didn't result in an error
144 if (mapperResponseMsg.is_method_error())
145 {
146 log<level::ERR>("Error in Deleting image from image manager",
Adriana Kobylak596466b2018-02-13 14:48:53 -0600147 entry("VERSIONPATH=%s", path.c_str()));
Saqib Khanee13e832017-10-23 12:53:11 -0500148 return;
149 }
150}
151
Saqib Khanb0774702017-05-23 16:02:41 -0500152auto Activation::requestedActivation(RequestedActivations value) ->
153 RequestedActivations
154{
Michael Tritzbed88af2017-07-19 16:00:06 -0500155 rwVolumeCreated = false;
156 roVolumeCreated = false;
Adriana Kobylak4c3edc92018-01-24 14:50:15 -0600157 ubootEnvVarsUpdated = false;
Michael Tritzbed88af2017-07-19 16:00:06 -0500158
Saqib Khanb0774702017-05-23 16:02:41 -0500159 if ((value == softwareServer::Activation::RequestedActivations::Active) &&
160 (softwareServer::Activation::requestedActivation() !=
161 softwareServer::Activation::RequestedActivations::Active))
162 {
163 if ((softwareServer::Activation::activation() ==
164 softwareServer::Activation::Activations::Ready) ||
165 (softwareServer::Activation::activation() ==
166 softwareServer::Activation::Activations::Failed))
167 {
168 Activation::activation(
169 softwareServer::Activation::Activations::Activating);
170
171 }
172 }
173 return softwareServer::Activation::requestedActivation(value);
174}
175
Saqib Khan4c1aec02017-07-06 11:46:13 -0500176uint8_t RedundancyPriority::priority(uint8_t value)
177{
Adriana Kobylakb77551c2017-10-27 12:46:23 -0500178 // Set the priority value so that the freePriority() function can order
179 // the versions by priority.
180 auto newPriority = softwareServer::RedundancyPriority::priority(value);
Saqib Khan5d532672017-08-09 10:44:50 -0500181 storeToFile(parent.versionId, value);
Adriana Kobylakb77551c2017-10-27 12:46:23 -0500182 parent.parent.freePriority(value, parent.versionId);
183 return newPriority;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500184}
185
Adriana Kobylakb77551c2017-10-27 12:46:23 -0500186uint8_t RedundancyPriority::sdbusPriority(uint8_t value)
Saqib Khanf0382c32017-10-24 13:36:22 -0500187{
Adriana Kobylakb77551c2017-10-27 12:46:23 -0500188 storeToFile(parent.versionId, value);
189 return softwareServer::RedundancyPriority::priority(value);
Saqib Khanf0382c32017-10-24 13:36:22 -0500190}
191
Michael Tritzbed88af2017-07-19 16:00:06 -0500192void Activation::unitStateChange(sdbusplus::message::message& msg)
193{
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500194 if (softwareServer::Activation::activation() !=
195 softwareServer::Activation::Activations::Activating)
196 {
197 return;
198 }
199
Michael Tritzbed88af2017-07-19 16:00:06 -0500200 uint32_t newStateID {};
201 sdbusplus::message::object_path newStateObjPath;
202 std::string newStateUnit{};
203 std::string newStateResult{};
204
205 //Read the msg and populate each variable
206 msg.read(newStateID, newStateObjPath, newStateUnit, newStateResult);
207
208 auto rwServiceFile = "obmc-flash-bmc-ubirw.service";
209 auto roServiceFile = "obmc-flash-bmc-ubiro@" + versionId + ".service";
Adriana Kobylak4c3edc92018-01-24 14:50:15 -0600210 auto ubootVarsServiceFile = "obmc-flash-bmc-updateubootvars@" + versionId +
211 ".service";
Michael Tritzbed88af2017-07-19 16:00:06 -0500212
Gunnar Mills3fa38202017-10-08 17:07:43 -0500213 if (newStateUnit == rwServiceFile && newStateResult == "done")
Michael Tritzbed88af2017-07-19 16:00:06 -0500214 {
215 rwVolumeCreated = true;
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500216 activationProgress->progress(activationProgress->progress() + 20);
Michael Tritzbed88af2017-07-19 16:00:06 -0500217 }
218
Gunnar Mills3fa38202017-10-08 17:07:43 -0500219 if (newStateUnit == roServiceFile && newStateResult == "done")
Michael Tritzbed88af2017-07-19 16:00:06 -0500220 {
221 roVolumeCreated = true;
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500222 activationProgress->progress(activationProgress->progress() + 50);
Michael Tritzbed88af2017-07-19 16:00:06 -0500223 }
224
Adriana Kobylak4c3edc92018-01-24 14:50:15 -0600225 if (newStateUnit == ubootVarsServiceFile && newStateResult == "done")
226 {
227 ubootEnvVarsUpdated = true;
228 }
229
230 if (newStateUnit == rwServiceFile ||
231 newStateUnit == roServiceFile ||
232 newStateUnit == ubootVarsServiceFile)
Michael Tritzbed88af2017-07-19 16:00:06 -0500233 {
Adriana Kobylak8bd84c82018-01-24 14:19:24 -0600234 if (newStateResult == "failed" || newStateResult == "dependency")
235 {
236 Activation::activation(
237 softwareServer::Activation::Activations::Failed);
238 }
Adriana Kobylak4c3edc92018-01-24 14:50:15 -0600239 else if ((rwVolumeCreated && roVolumeCreated) || // Volumes were created
240 (ubootEnvVarsUpdated)) // Enviroment variables were updated
Adriana Kobylak8bd84c82018-01-24 14:19:24 -0600241 {
242 Activation::activation(
243 softwareServer::Activation::Activations::Activating);
244 }
Michael Tritzbed88af2017-07-19 16:00:06 -0500245 }
246
247 return;
248}
249
250
Saqib Khanb0774702017-05-23 16:02:41 -0500251} // namespace updater
252} // namespace software
253} // namespace phosphor