blob: b64f1bee5c13bed4a4473f2787198dde4ec28abe [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
Jayanth Othayoth0e0c1272018-02-21 05:46:36 -06007#ifdef WANT_SIGNATURE_VERIFY
8#include <phosphor-logging/elog.hpp>
9#include <phosphor-logging/elog-errors.hpp>
10#include <xyz/openbmc_project/Common/error.hpp>
11#include "image_verify.hpp"
Jayanth Othayoth0e0c1272018-02-21 05:46:36 -060012#endif
13
Saqib Khanb0774702017-05-23 16:02:41 -050014namespace phosphor
15{
16namespace software
17{
18namespace updater
19{
20
21namespace softwareServer = sdbusplus::xyz::openbmc_project::Software::server;
22
Saqib Khanb9da6632017-09-13 09:48:37 -050023using namespace phosphor::logging;
24
Jayanth Othayoth0e0c1272018-02-21 05:46:36 -060025#ifdef WANT_SIGNATURE_VERIFY
26using InternalFailure =
27 sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
Jayanth Othayoth9a9d7c22018-03-28 10:05:26 -050028namespace control = sdbusplus::xyz::openbmc_project::Control::server;
Jayanth Othayoth0e0c1272018-02-21 05:46:36 -060029#endif
30
Michael Tritzbed88af2017-07-19 16:00:06 -050031void Activation::subscribeToSystemdSignals()
32{
Adriana Kobylak2285fe02018-02-27 15:36:59 -060033 auto method = this->bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
34 SYSTEMD_INTERFACE, "Subscribe");
Michael Tritzbed88af2017-07-19 16:00:06 -050035 this->bus.call_noreply(method);
36
37 return;
38}
39
Michael Tritzf2b5e0d2017-07-25 14:39:34 -050040void Activation::unsubscribeFromSystemdSignals()
41{
Adriana Kobylak2285fe02018-02-27 15:36:59 -060042 auto method = this->bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
43 SYSTEMD_INTERFACE, "Unsubscribe");
Michael Tritzf2b5e0d2017-07-25 14:39:34 -050044 this->bus.call_noreply(method);
45
46 return;
47}
48
Adriana Kobylak2285fe02018-02-27 15:36:59 -060049auto Activation::activation(Activations value) -> Activations
Saqib Khanb0774702017-05-23 16:02:41 -050050{
Saqib Khan4c1aec02017-07-06 11:46:13 -050051
Adriana Kobylak8bd84c82018-01-24 14:19:24 -060052 if ((value != softwareServer::Activation::Activations::Active) &&
53 (value != softwareServer::Activation::Activations::Activating))
Saqib Khan4c1aec02017-07-06 11:46:13 -050054 {
55 redundancyPriority.reset(nullptr);
56 }
57
Saqib Khanb0774702017-05-23 16:02:41 -050058 if (value == softwareServer::Activation::Activations::Activating)
59 {
Michael Tritzbed88af2017-07-19 16:00:06 -050060 if (rwVolumeCreated == false && roVolumeCreated == false)
Saqib Khanb0774702017-05-23 16:02:41 -050061 {
Adriana Kobylak204e1e72018-01-24 16:00:05 -060062 parent.freeSpace();
63
Michael Tritz0edd4ad2017-07-26 14:27:42 -050064 if (!activationProgress)
65 {
Adriana Kobylak2285fe02018-02-27 15:36:59 -060066 activationProgress =
67 std::make_unique<ActivationProgress>(bus, path);
Michael Tritz0edd4ad2017-07-26 14:27:42 -050068 }
69
Michael Tritzbed88af2017-07-19 16:00:06 -050070 if (!activationBlocksTransition)
71 {
72 activationBlocksTransition =
Adriana Kobylak2285fe02018-02-27 15:36:59 -060073 std::make_unique<ActivationBlocksTransition>(bus, path);
Michael Tritzbed88af2017-07-19 16:00:06 -050074 }
Saqib Khan4c1aec02017-07-06 11:46:13 -050075
Jayanth Othayoth0e0c1272018-02-21 05:46:36 -060076#ifdef WANT_SIGNATURE_VERIFY
77 using Signature = phosphor::software::image::Signature;
78
79 fs::path uploadDir(IMG_UPLOAD_DIR);
80
81 Signature signature(uploadDir / versionId, SIGNED_IMAGE_CONF_PATH);
82
83 // Validate the signed image.
84 if (!signature.verify())
85 {
86 log<level::ERR>("Error occurred during image validation");
87 report<InternalFailure>();
88
Jayanth Othayoth9a9d7c22018-03-28 10:05:26 -050089 // Stop the activation process, if fieldMode is enabled.
90 if (parent.control::FieldMode::fieldModeEnabled())
91 {
92 // Cleanup
93 activationBlocksTransition.reset(nullptr);
94 activationProgress.reset(nullptr);
95
96 return softwareServer::Activation::activation(
97 softwareServer::Activation::Activations::Failed);
98 }
Jayanth Othayoth0e0c1272018-02-21 05:46:36 -060099 }
100#endif
101
Adriana Kobylak9f89e2e2018-05-30 13:16:20 -0500102 flashWrite();
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500103
104 activationProgress->progress(10);
Michael Tritzbed88af2017-07-19 16:00:06 -0500105 }
106 else if (rwVolumeCreated == true && roVolumeCreated == true)
Saqib Khan4c1aec02017-07-06 11:46:13 -0500107 {
Adriana Kobylak166bdf32018-04-09 14:24:06 -0500108 if (ubootEnvVarsUpdated == false)
Michael Tritzbed88af2017-07-19 16:00:06 -0500109 {
Adriana Kobylak166bdf32018-04-09 14:24:06 -0500110 activationProgress->progress(90);
111
112 if (!redundancyPriority)
113 {
114 redundancyPriority = std::make_unique<RedundancyPriority>(
115 bus, path, *this, 0);
116 }
Michael Tritzbed88af2017-07-19 16:00:06 -0500117 }
Adriana Kobylak166bdf32018-04-09 14:24:06 -0500118 else
119 {
120 activationProgress->progress(100);
Saqib Khan4c1aec02017-07-06 11:46:13 -0500121
Adriana Kobylak166bdf32018-04-09 14:24:06 -0500122 activationBlocksTransition.reset(nullptr);
123 activationProgress.reset(nullptr);
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500124
Adriana Kobylak166bdf32018-04-09 14:24:06 -0500125 rwVolumeCreated = false;
126 roVolumeCreated = false;
127 ubootEnvVarsUpdated = false;
128 Activation::unsubscribeFromSystemdSignals();
Michael Tritzf2b5e0d2017-07-25 14:39:34 -0500129
Adriana Kobylak166bdf32018-04-09 14:24:06 -0500130 // Remove version object from image manager
131 Activation::deleteImageManagerObject();
Michael Tritzf2b5e0d2017-07-25 14:39:34 -0500132
Adriana Kobylak166bdf32018-04-09 14:24:06 -0500133 // Create active association
134 parent.createActiveAssociation(path);
Saqib Khanee13e832017-10-23 12:53:11 -0500135
Adriana Kobylak166bdf32018-04-09 14:24:06 -0500136 return softwareServer::Activation::activation(
137 softwareServer::Activation::Activations::Active);
138 }
Michael Tritzbed88af2017-07-19 16:00:06 -0500139 }
Saqib Khanb0774702017-05-23 16:02:41 -0500140 }
141 else
142 {
143 activationBlocksTransition.reset(nullptr);
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500144 activationProgress.reset(nullptr);
Saqib Khanb0774702017-05-23 16:02:41 -0500145 }
146 return softwareServer::Activation::activation(value);
147}
148
Saqib Khanee13e832017-10-23 12:53:11 -0500149void Activation::deleteImageManagerObject()
150{
Saqib Khanee13e832017-10-23 12:53:11 -0500151 // Call the Delete object for <versionID> inside image_manager
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600152 auto method = this->bus.new_method_call(VERSION_BUSNAME, path.c_str(),
153 "xyz.openbmc_project.Object.Delete",
154 "Delete");
Adriana Kobylak00bd9022018-01-24 13:55:58 -0600155 auto mapperResponseMsg = bus.call(method);
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600156 // Check that the bus call didn't result in an error
Saqib Khanee13e832017-10-23 12:53:11 -0500157 if (mapperResponseMsg.is_method_error())
158 {
159 log<level::ERR>("Error in Deleting image from image manager",
Adriana Kobylak596466b2018-02-13 14:48:53 -0600160 entry("VERSIONPATH=%s", path.c_str()));
Saqib Khanee13e832017-10-23 12:53:11 -0500161 return;
162 }
163}
164
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600165auto Activation::requestedActivation(RequestedActivations value)
166 -> RequestedActivations
Saqib Khanb0774702017-05-23 16:02:41 -0500167{
Michael Tritzbed88af2017-07-19 16:00:06 -0500168 rwVolumeCreated = false;
169 roVolumeCreated = false;
Adriana Kobylak166bdf32018-04-09 14:24:06 -0500170 ubootEnvVarsUpdated = false;
Michael Tritzbed88af2017-07-19 16:00:06 -0500171
Saqib Khanb0774702017-05-23 16:02:41 -0500172 if ((value == softwareServer::Activation::RequestedActivations::Active) &&
173 (softwareServer::Activation::requestedActivation() !=
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600174 softwareServer::Activation::RequestedActivations::Active))
Saqib Khanb0774702017-05-23 16:02:41 -0500175 {
176 if ((softwareServer::Activation::activation() ==
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600177 softwareServer::Activation::Activations::Ready) ||
Saqib Khanb0774702017-05-23 16:02:41 -0500178 (softwareServer::Activation::activation() ==
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600179 softwareServer::Activation::Activations::Failed))
Saqib Khanb0774702017-05-23 16:02:41 -0500180 {
181 Activation::activation(
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600182 softwareServer::Activation::Activations::Activating);
Saqib Khanb0774702017-05-23 16:02:41 -0500183 }
184 }
185 return softwareServer::Activation::requestedActivation(value);
186}
187
Saqib Khan4c1aec02017-07-06 11:46:13 -0500188uint8_t RedundancyPriority::priority(uint8_t value)
189{
Adriana Kobylakb77551c2017-10-27 12:46:23 -0500190 // Set the priority value so that the freePriority() function can order
191 // the versions by priority.
192 auto newPriority = softwareServer::RedundancyPriority::priority(value);
Saqib Khan5d532672017-08-09 10:44:50 -0500193 storeToFile(parent.versionId, value);
Adriana Kobylakb77551c2017-10-27 12:46:23 -0500194 parent.parent.freePriority(value, parent.versionId);
195 return newPriority;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500196}
197
Adriana Kobylakb77551c2017-10-27 12:46:23 -0500198uint8_t RedundancyPriority::sdbusPriority(uint8_t value)
Saqib Khanf0382c32017-10-24 13:36:22 -0500199{
Adriana Kobylakb77551c2017-10-27 12:46:23 -0500200 storeToFile(parent.versionId, value);
201 return softwareServer::RedundancyPriority::priority(value);
Saqib Khanf0382c32017-10-24 13:36:22 -0500202}
203
Michael Tritzbed88af2017-07-19 16:00:06 -0500204void Activation::unitStateChange(sdbusplus::message::message& msg)
205{
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500206 if (softwareServer::Activation::activation() !=
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600207 softwareServer::Activation::Activations::Activating)
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500208 {
209 return;
210 }
211
Adriana Kobylak3ce563a2018-06-06 16:41:15 -0500212 onStateChanges(msg);
Michael Tritzbed88af2017-07-19 16:00:06 -0500213
214 return;
215}
216
Saqib Khanf37cefc2017-09-12 08:44:41 -0500217void ActivationBlocksTransition::enableRebootGuard()
218{
219 log<level::INFO>("BMC image activating - BMC reboots are disabled.");
220
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600221 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
222 SYSTEMD_INTERFACE, "StartUnit");
Saqib Khanf37cefc2017-09-12 08:44:41 -0500223 method.append("reboot-guard-enable.service", "replace");
224 bus.call_noreply(method);
225}
226
227void ActivationBlocksTransition::disableRebootGuard()
228{
229 log<level::INFO>("BMC activation has ended - BMC reboots are re-enabled.");
230
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600231 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
232 SYSTEMD_INTERFACE, "StartUnit");
Saqib Khanf37cefc2017-09-12 08:44:41 -0500233 method.append("reboot-guard-disable.service", "replace");
234 bus.call_noreply(method);
235}
Michael Tritzbed88af2017-07-19 16:00:06 -0500236
Saqib Khanb0774702017-05-23 16:02:41 -0500237} // namespace updater
238} // namespace software
239} // namespace phosphor