blob: ff4832627b82417ba0219084fe7f7b146b1f9738 [file] [log] [blame]
Adriana Kobylak692b5552017-04-17 14:02:58 -05001#include "config.h"
Gunnar Millsf6ed5892018-09-07 17:08:02 -05002
3#include "activation.hpp"
4
Saqib Khan81bac882017-06-08 12:17:01 -05005#include "item_updater.hpp"
Gunnar Millsf6ed5892018-09-07 17:08:02 -05006
7#include <experimental/filesystem>
Saqib Khan7f80e0b2017-10-22 11:29:07 -05008#include <phosphor-logging/log.hpp>
Gunnar Mills74b657e2018-07-13 09:27:31 -05009#include <sdbusplus/exception.hpp>
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -050010
Jayanth Othayoth4016e522018-03-20 09:39:06 -050011#ifdef WANT_SIGNATURE_VERIFY
Jayanth Othayoth4016e522018-03-20 09:39:06 -050012#include "image_verify.hpp"
Gunnar Millsf6ed5892018-09-07 17:08:02 -050013
14#include <phosphor-logging/elog-errors.hpp>
15#include <phosphor-logging/elog.hpp>
16#include <sdbusplus/server.hpp>
17#include <xyz/openbmc_project/Common/error.hpp>
Jayanth Othayoth4016e522018-03-20 09:39:06 -050018#endif
19
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -050020namespace openpower
21{
22namespace software
23{
24namespace updater
25{
26
Adriana Kobylak55f9e832017-05-14 16:13:00 -050027namespace fs = std::experimental::filesystem;
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -050028namespace softwareServer = sdbusplus::xyz::openbmc_project::Software::server;
29
Saqib Khan7f80e0b2017-10-22 11:29:07 -050030using namespace phosphor::logging;
Gunnar Mills74b657e2018-07-13 09:27:31 -050031using sdbusplus::exception::SdBusError;
Saqib Khan7f80e0b2017-10-22 11:29:07 -050032
Jayanth Othayoth4016e522018-03-20 09:39:06 -050033#ifdef WANT_SIGNATURE_VERIFY
34using InternalFailure =
35 sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
Jayanth Othayoth11271fb2018-03-29 10:25:50 -050036
37// Field mode path and interface.
38constexpr auto FIELDMODE_PATH("/xyz/openbmc_project/software");
39constexpr auto FIELDMODE_INTERFACE("xyz.openbmc_project.Control.FieldMode");
Jayanth Othayoth4016e522018-03-20 09:39:06 -050040#endif
41
Adriana Kobylak70dcb632018-02-27 15:46:52 -060042constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1";
43constexpr auto SYSTEMD_OBJ_PATH = "/org/freedesktop/systemd1";
Michael Tritz9d25b602017-06-14 14:41:43 -050044
45void Activation::subscribeToSystemdSignals()
46{
Adriana Kobylak70dcb632018-02-27 15:46:52 -060047 auto method = this->bus.new_method_call(SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH,
48 SYSTEMD_INTERFACE, "Subscribe");
Gunnar Mills74b657e2018-07-13 09:27:31 -050049 try
50 {
51 this->bus.call_noreply(method);
52 }
53 catch (const SdBusError& e)
54 {
55 if (e.name() != nullptr &&
56 strcmp("org.freedesktop.systemd1.AlreadySubscribed", e.name()) == 0)
57 {
58 // If an Activation attempt fails, the Unsubscribe method is not
59 // called. This may lead to an AlreadySubscribed error if the
60 // Activation is re-attempted.
61 }
62 else
63 {
64 log<level::ERR>("Error subscribing to systemd",
65 entry("ERROR=%s", e.what()));
66 }
67 }
Michael Tritz9d25b602017-06-14 14:41:43 -050068 return;
69}
70
Michael Tritz1cb127f2017-07-26 15:40:38 -050071void Activation::unsubscribeFromSystemdSignals()
72{
Adriana Kobylak70dcb632018-02-27 15:46:52 -060073 auto method = this->bus.new_method_call(SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH,
74 SYSTEMD_INTERFACE, "Unsubscribe");
Michael Tritz1cb127f2017-07-26 15:40:38 -050075 this->bus.call_noreply(method);
76
77 return;
78}
79
Adriana Kobylak70dcb632018-02-27 15:46:52 -060080auto Activation::requestedActivation(RequestedActivations value)
81 -> RequestedActivations
Adriana Kobylak2fdb9312017-05-14 19:08:26 -050082{
83 if ((value == softwareServer::Activation::RequestedActivations::Active) &&
84 (softwareServer::Activation::requestedActivation() !=
Adriana Kobylak70dcb632018-02-27 15:46:52 -060085 softwareServer::Activation::RequestedActivations::Active))
Adriana Kobylak2fdb9312017-05-14 19:08:26 -050086 {
87 if ((softwareServer::Activation::activation() ==
Adriana Kobylak70dcb632018-02-27 15:46:52 -060088 softwareServer::Activation::Activations::Ready) ||
Adriana Kobylak2fdb9312017-05-14 19:08:26 -050089 (softwareServer::Activation::activation() ==
Adriana Kobylak70dcb632018-02-27 15:46:52 -060090 softwareServer::Activation::Activations::Failed))
Adriana Kobylak2fdb9312017-05-14 19:08:26 -050091 {
Lei YUa2e67162019-02-22 17:35:24 +080092 activation(softwareServer::Activation::Activations::Activating);
Adriana Kobylak2fdb9312017-05-14 19:08:26 -050093 }
94 }
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -050095 return softwareServer::Activation::requestedActivation(value);
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -050096}
97
Saqib Khan7f80e0b2017-10-22 11:29:07 -050098void Activation::deleteImageManagerObject()
99{
100 // Get the Delete object for <versionID> inside image_manager
Lei YUc9caf862019-01-24 15:40:25 +0800101 constexpr auto versionServiceStr = "xyz.openbmc_project.Software.Version";
102 constexpr auto deleteInterface = "xyz.openbmc_project.Object.Delete";
103 std::string versionService;
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600104 auto method = this->bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH,
105 MAPPER_INTERFACE, "GetObject");
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500106
107 method.append(path);
Lei YUc9caf862019-01-24 15:40:25 +0800108 method.append(std::vector<std::string>({deleteInterface}));
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500109 auto mapperResponseMsg = bus.call(method);
110 if (mapperResponseMsg.is_method_error())
111 {
112 log<level::ERR>("Error in Get Delete Object",
Joseph Reynoldsafd0a452018-05-30 11:16:03 -0500113 entry("VERSIONPATH=%s", path.c_str()));
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500114 return;
115 }
116 std::map<std::string, std::vector<std::string>> mapperResponse;
117 mapperResponseMsg.read(mapperResponse);
118 if (mapperResponse.begin() == mapperResponse.end())
119 {
120 log<level::ERR>("ERROR in reading the mapper response",
Joseph Reynoldsafd0a452018-05-30 11:16:03 -0500121 entry("VERSIONPATH=%s", path.c_str()));
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500122 return;
123 }
124
Lei YUc9caf862019-01-24 15:40:25 +0800125 // We need to find the phosphor-software-manager's version service
126 // to invoke the delete interface
127 for (auto resp : mapperResponse)
128 {
129 if (resp.first.find(versionServiceStr) != std::string::npos)
130 {
131 versionService = resp.first;
132 }
133 }
134
135 if (versionService.empty())
136 {
137 log<level::ERR>("Error finding version service");
138 return;
139 }
140
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500141 // Call the Delete object for <versionID> inside image_manager
Lei YUc9caf862019-01-24 15:40:25 +0800142 method = this->bus.new_method_call(versionService.c_str(), path.c_str(),
143 deleteInterface, "Delete");
Adriana Kobylakab435df2018-07-16 11:37:19 -0500144 try
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500145 {
Adriana Kobylakab435df2018-07-16 11:37:19 -0500146 auto mapperResponseMsg = bus.call(method);
147
148 // Check that the bus call didn't result in an error
149 if (mapperResponseMsg.is_method_error())
150 {
151 log<level::ERR>("Error in Deleting image from image manager",
152 entry("VERSIONPATH=%s", path.c_str()));
153 return;
154 }
155 }
156 catch (const SdBusError& e)
157 {
158 if (e.name() != nullptr && strcmp("System.Error.ELOOP", e.name()) == 0)
159 {
160 // TODO: Error being tracked with openbmc/openbmc#3311
161 }
162 else
163 {
164 log<level::ERR>("Error performing call to Delete object path",
165 entry("ERROR=%s", e.what()),
166 entry("PATH=%s", path.c_str()));
167 }
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500168 return;
169 }
170}
171
Saqib Khan2021b4c2017-06-07 14:37:36 -0500172uint8_t RedundancyPriority::priority(uint8_t value)
173{
Saqib Khanb8e7f312017-08-12 10:24:10 -0500174 parent.parent.freePriority(value, parent.versionId);
Saqib Khan2021b4c2017-06-07 14:37:36 -0500175 return softwareServer::RedundancyPriority::priority(value);
176}
177
Jayanth Othayoth11271fb2018-03-29 10:25:50 -0500178#ifdef WANT_SIGNATURE_VERIFY
Lei YU9b21efc2019-02-21 15:52:53 +0800179bool Activation::validateSignature()
Jayanth Othayoth11271fb2018-03-29 10:25:50 -0500180{
181 using Signature = openpower::software::image::Signature;
182 fs::path imageDir(IMG_DIR);
183
184 Signature signature(imageDir / versionId, PNOR_SIGNED_IMAGE_CONF_PATH);
185
186 // Validate the signed image.
187 if (signature.verify())
188 {
189 return true;
190 }
191 // Log error and continue activation process, if field mode disabled.
192 log<level::ERR>("Error occurred during image validation");
193 report<InternalFailure>();
194
195 try
196 {
197 if (!fieldModeEnabled())
198 {
199 return true;
200 }
201 }
202 catch (const InternalFailure& e)
203 {
204 report<InternalFailure>();
205 }
206 return false;
207}
208
209bool Activation::fieldModeEnabled()
210{
211 auto fieldModeSvc = getService(bus, FIELDMODE_PATH, FIELDMODE_INTERFACE);
212
213 auto method = bus.new_method_call(fieldModeSvc.c_str(), FIELDMODE_PATH,
214 "org.freedesktop.DBus.Properties", "Get");
215
216 method.append(FIELDMODE_INTERFACE, "FieldModeEnabled");
217 auto reply = bus.call(method);
218 if (reply.is_method_error())
219 {
220 log<level::ERR>("Error in fieldModeEnabled getValue");
221 elog<InternalFailure>();
222 }
223 sdbusplus::message::variant<bool> fieldMode;
224 reply.read(fieldMode);
225
William A. Kennington III17f55a82018-11-27 15:22:05 -0800226 return sdbusplus::message::variant_ns::get<bool>(fieldMode);
Jayanth Othayoth11271fb2018-03-29 10:25:50 -0500227}
228
229std::string Activation::getService(sdbusplus::bus::bus& bus,
230 const std::string& path,
231 const std::string& intf)
232{
233 auto mapperCall = bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH,
234 MAPPER_INTERFACE, "GetObject");
235
236 mapperCall.append(path);
237 mapperCall.append(std::vector<std::string>({intf}));
238
239 auto mapperResponseMsg = bus.call(mapperCall);
240
241 if (mapperResponseMsg.is_method_error())
242 {
243 log<level::ERR>("ERROR in getting service",
244 entry("PATH=%s", path.c_str()),
245 entry("INTERFACE=%s", intf.c_str()));
246
247 elog<InternalFailure>();
248 }
249
250 std::map<std::string, std::vector<std::string>> mapperResponse;
251 mapperResponseMsg.read(mapperResponse);
252
253 if (mapperResponse.begin() == mapperResponse.end())
254 {
255 log<level::ERR>("ERROR reading mapper response",
256 entry("PATH=%s", path.c_str()),
257 entry("INTERFACE=%s", intf.c_str()));
258
259 elog<InternalFailure>();
260 }
261 return mapperResponse.begin()->first;
262}
263#endif
264
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500265} // namespace updater
266} // namespace software
267} // namespace openpower