blob: 57e121b49429dc88d7ba3f59419b2e0b6bcb3e37 [file] [log] [blame]
AppaRao Pulie63eeda2019-07-05 16:25:38 +05301/*
2// Copyright (c) 2019 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16
17#include "pfr_mgr.hpp"
AppaRao Pulie63eeda2019-07-05 16:25:38 +053018
deepak kumar agrawalb29a15c2022-03-25 07:45:57 +000019#include "file.hpp"
20
AppaRao Pulie63eeda2019-07-05 16:25:38 +053021namespace pfr
22{
23
Alex Schendel5cf320c2021-12-09 12:11:04 -080024inline void printVersion(const std::string& path, const std::string& version)
25{
26 lg2::info("VERSION INFO - {TYPE} - {VER}", "TYPE", path, "VER", version);
27}
AppaRao Pulie63eeda2019-07-05 16:25:38 +053028static constexpr uint8_t activeImage = 0;
29static constexpr uint8_t recoveryImage = 1;
30
AppaRao Puli0e758912020-01-29 03:07:54 +053031std::shared_ptr<sdbusplus::asio::dbus_interface> associationIface;
32std::set<std::tuple<std::string, std::string, std::string>> associations;
33
deepak kumar agrawalb29a15c2022-03-25 07:45:57 +000034using GetSubTreeType = std::vector<
35 std::pair<std::string,
36 std::vector<std::pair<std::string, std::vector<std::string>>>>>;
37
AppaRao Puli67d184c2020-05-29 00:48:33 +053038PfrVersion::PfrVersion(sdbusplus::asio::object_server& srv_,
39 std::shared_ptr<sdbusplus::asio::connection>& conn_,
40 const std::string& path_, const ImageType& imgType_,
41 const std::string& purpose_) :
AppaRao Pulie63eeda2019-07-05 16:25:38 +053042 server(srv_),
AppaRao Pulie4e95652019-07-19 16:52:01 +053043 conn(conn_), path(path_), imgType(imgType_), purpose(purpose_)
AppaRao Pulie63eeda2019-07-05 16:25:38 +053044{
AppaRao Puli4b639a22019-10-01 18:12:59 +053045 version = getFirmwareVersion(imgType);
AppaRao Pulie63eeda2019-07-05 16:25:38 +053046
Alex Schendel5cf320c2021-12-09 12:11:04 -080047 if (!(version == "0.0" || version.empty()))
48 {
49 printVersion(path, version);
50 }
51
AppaRao Pulie63eeda2019-07-05 16:25:38 +053052 std::string objPath = "/xyz/openbmc_project/software/" + path;
Patrick Williams304e82e2023-05-10 07:51:13 -050053 versionIface = server.add_interface(objPath,
54 "xyz.openbmc_project.Software.Version");
AppaRao Pulie63eeda2019-07-05 16:25:38 +053055
Vikram Bodireddy1c06ae42021-07-08 15:26:51 +053056 if (versionIface != nullptr)
57 {
Vikram Bodireddy1c06ae42021-07-08 15:26:51 +053058 versionIface->register_property("Purpose", purpose);
59 versionIface->register_property(
60 versionStr, version,
61 // Override set
62 [this](const std::string& req, std::string& propertyValue) {
Patrick Williams304e82e2023-05-10 07:51:13 -050063 if (internalSet)
64 {
65 if (req != propertyValue)
Vikram Bodireddy1c06ae42021-07-08 15:26:51 +053066 {
Patrick Williams304e82e2023-05-10 07:51:13 -050067 version = req;
68 propertyValue = req;
69 return 1;
Vikram Bodireddy1c06ae42021-07-08 15:26:51 +053070 }
Patrick Williams304e82e2023-05-10 07:51:13 -050071 }
72 return 0;
Patrick Williams1388f6c2023-10-20 11:19:41 -050073 });
Vikram Bodireddy1c06ae42021-07-08 15:26:51 +053074
75 versionIface->initialize();
76 }
AppaRao Pulid6f46c42019-07-19 22:34:04 +053077
AppaRao Puli916d6002019-12-18 01:37:02 +053078 std::string activation =
79 "xyz.openbmc_project.Software.Activation.Activations.StandbySpare";
80
81 if ((imgType == ImageType::bmcActive) ||
82 (imgType == ImageType::biosActive) ||
Vikram Bodireddy8292dc62021-05-26 13:31:47 +053083 (imgType == ImageType::cpldActive) || (imgType == ImageType::afmActive))
Vikram Bodireddy0fd4dde2019-12-06 15:48:00 +053084 {
AppaRao Puli916d6002019-12-18 01:37:02 +053085 // Running images so set Activations to "Active"
Vikram Bodireddy0fd4dde2019-12-06 15:48:00 +053086 activation =
87 "xyz.openbmc_project.Software.Activation.Activations.Active";
AppaRao Puli916d6002019-12-18 01:37:02 +053088
AppaRao Puli0e758912020-01-29 03:07:54 +053089 // For all Active images, functional endpoints must be added. This is
90 // used in bmcweb & ipmi for fetching active component versions.
91
92 // TODO: We have redundant active firmware version objects for BMC
93 // and BIOS active images. BMC version is read from /etc/os-release
94 // BIOS version is read from SMBIOS. Since it provides more
95 // version information, Lets expose those as functional.
96 // Down the line, Redundant inventory objects need to be addressed.
Vikram Bodireddy8292dc62021-05-26 13:31:47 +053097 if ((imgType == ImageType::cpldActive) ||
98 (imgType == ImageType::afmActive))
AppaRao Puli0e758912020-01-29 03:07:54 +053099 {
100 associations.emplace("functional", "software_version", objPath);
101 }
Vikram Bodireddy0fd4dde2019-12-06 15:48:00 +0530102 }
103
AppaRao Pulid6f46c42019-07-19 22:34:04 +0530104 std::string reqActNone =
105 "xyz.openbmc_project.Software.Activation.RequestedActivations.None";
106 auto activationIface = server.add_interface(
107 objPath, "xyz.openbmc_project.Software.Activation");
AppaRao Pulid6f46c42019-07-19 22:34:04 +0530108
Vikram Bodireddy1c06ae42021-07-08 15:26:51 +0530109 if (activationIface != nullptr)
110 {
Vikram Bodireddy1c06ae42021-07-08 15:26:51 +0530111 activationIface->register_property("Activation", activation);
112 activationIface->register_property("RequestedActivation", reqActNone);
113
114 activationIface->initialize();
115 }
AppaRao Puli0e758912020-01-29 03:07:54 +0530116
117 // All the components exposed under PFR.Manager are updateable.
118 // Lets add objPath endpoints to 'updatable' association
119 associations.emplace("updateable", "software_version", objPath);
120 associationIface->set_property("Associations", associations);
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530121}
122
AppaRao Pulie4e95652019-07-19 16:52:01 +0530123void PfrVersion::updateVersion()
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530124{
AppaRao Pulie4e95652019-07-19 16:52:01 +0530125 if (versionIface && versionIface->is_initialized())
126 {
AppaRao Puli4b639a22019-10-01 18:12:59 +0530127 std::string ver = getFirmwareVersion(imgType);
Alex Schendel5cf320c2021-12-09 12:11:04 -0800128 printVersion(path, ver);
AppaRao Pulie4e95652019-07-19 16:52:01 +0530129 internalSet = true;
130 versionIface->set_property(versionStr, ver);
131 internalSet = false;
132 }
133 return;
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530134}
135
AppaRao Puli67d184c2020-05-29 00:48:33 +0530136PfrConfig::PfrConfig(sdbusplus::asio::object_server& srv_,
137 std::shared_ptr<sdbusplus::asio::connection>& conn_) :
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530138 server(srv_),
139 conn(conn_)
140{
AppaRao Pulicc1ed682019-10-01 12:29:40 +0530141 pfrCfgIface = server.add_interface("/xyz/openbmc_project/pfr",
142 "xyz.openbmc_project.PFR.Attributes");
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530143
Chalapathi Venkataramashettyf8819702021-02-03 09:43:46 +0000144 ufmLocked = false;
145 ufmProvisioned = false;
146 ufmSupport = false;
147 getProvisioningStatus(ufmLocked, ufmProvisioned, ufmSupport);
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530148
AppaRao Pulie4e95652019-07-19 16:52:01 +0530149 pfrCfgIface->register_property(ufmProvisionedStr, ufmProvisioned,
150 // Override set
151 [this](const bool req, bool propertyValue) {
Patrick Williams304e82e2023-05-10 07:51:13 -0500152 if (internalSet)
153 {
154 if (req != propertyValue)
155 {
156 ufmProvisioned = req;
157 propertyValue = req;
158 return 1;
159 }
160 }
161 return 0;
162 });
AppaRao Pulie4e95652019-07-19 16:52:01 +0530163
164 pfrCfgIface->register_property(ufmLockedStr, ufmLocked,
165 // Override set
166 [this](const bool req, bool propertyValue) {
Patrick Williams304e82e2023-05-10 07:51:13 -0500167 if (internalSet)
168 {
169 if (req != propertyValue)
170 {
171 ufmLocked = req;
172 propertyValue = req;
173 return 1;
174 }
175 }
176 return 0;
177 });
AppaRao Pulie4e95652019-07-19 16:52:01 +0530178
Chalapathi Venkataramashettyf8819702021-02-03 09:43:46 +0000179 pfrCfgIface->register_property(ufmSupportStr, ufmSupport,
180 // Override set
181 [this](const bool req, bool propertyValue) {
Patrick Williams304e82e2023-05-10 07:51:13 -0500182 if (internalSet)
183 {
184 if (req != propertyValue)
185 {
186 ufmSupport = req;
187 propertyValue = req;
188 return 1;
189 }
190 }
191 return 0;
192 });
Chalapathi Venkataramashettyf8819702021-02-03 09:43:46 +0000193
AppaRao Pulie4e95652019-07-19 16:52:01 +0530194 pfrCfgIface->initialize();
AppaRao Puli0e758912020-01-29 03:07:54 +0530195
deepak kumar agrawalb29a15c2022-03-25 07:45:57 +0000196 /*BMCBusy period MailBox handling */
197 pfrMBIface = server.add_interface("/xyz/openbmc_project/pfr",
198 "xyz.openbmc_project.PFR.Mailbox");
199
200 pfrMBIface->register_method("InitiateBMCBusyPeriod", [](bool setReset) {
201 if (setBMCBusy(setReset) < 0)
202 {
203 return false;
204 }
205 return true;
206 });
207
208 pfrMBIface->register_method("ReadMBRegister", [](uint32_t regAddr) {
209 uint8_t mailBoxReply = 0;
210 try
211 {
212 getMBRegister(regAddr, mailBoxReply);
213 }
214 catch (const std::exception& e)
215 {
216 throw;
217 }
218 return mailBoxReply;
219 });
220 pfrMBIface->initialize();
221
AppaRao Puli0e758912020-01-29 03:07:54 +0530222 associationIface =
223 server.add_interface("/xyz/openbmc_project/software",
224 "xyz.openbmc_project.Association.Definitions");
225 associationIface->register_property("Associations", associations);
226 associationIface->initialize();
AppaRao Pulie4e95652019-07-19 16:52:01 +0530227}
228
229void PfrConfig::updateProvisioningStatus()
230{
231 if (pfrCfgIface && pfrCfgIface->is_initialized())
232 {
233 bool lockVal = false;
234 bool provVal = false;
Chalapathi Venkataramashettyf8819702021-02-03 09:43:46 +0000235 bool supportVal = false;
236 getProvisioningStatus(lockVal, provVal, supportVal);
AppaRao Pulie4e95652019-07-19 16:52:01 +0530237 internalSet = true;
238 pfrCfgIface->set_property(ufmProvisionedStr, provVal);
239 pfrCfgIface->set_property(ufmLockedStr, lockVal);
Chalapathi Venkataramashettyf8819702021-02-03 09:43:46 +0000240 pfrCfgIface->set_property(ufmSupportStr, supportVal);
AppaRao Pulie4e95652019-07-19 16:52:01 +0530241 internalSet = false;
242 }
243 return;
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530244}
245
Zhikui Renc96f37d2021-12-08 15:40:51 -0800246static constexpr const char* postcodeStrProp = "PlatformState";
247static constexpr const char* postcodeStrDefault = "Unknown";
248static constexpr const char* postcodeDataProp = "Data";
249static constexpr const char* postcodeIface =
250 "xyz.openbmc_project.State.Boot.Platform";
251
252PfrPostcode::PfrPostcode(sdbusplus::asio::object_server& srv_,
253 std::shared_ptr<sdbusplus::asio::connection>& conn_) :
254 server(srv_),
255 conn(conn_)
256{
257 if (getPlatformState(postcode) < 0)
258 {
259 postcode = 0;
260 }
261
Patrick Williams304e82e2023-05-10 07:51:13 -0500262 pfrPostcodeIface = server.add_interface("/xyz/openbmc_project/pfr",
263 postcodeIface);
Zhikui Renc96f37d2021-12-08 15:40:51 -0800264
265 if (pfrPostcodeIface != nullptr)
266 {
267 pfrPostcodeIface->register_property(
268 postcodeDataProp, postcode,
269 // Override set
270 [this](const uint8_t req, uint8_t& propertyValue) {
Patrick Williams304e82e2023-05-10 07:51:13 -0500271 if (internalSet)
272 {
273 if (req != propertyValue)
Zhikui Renc96f37d2021-12-08 15:40:51 -0800274 {
Patrick Williams304e82e2023-05-10 07:51:13 -0500275 postcode = req;
276 propertyValue = req;
277 return 1;
Zhikui Renc96f37d2021-12-08 15:40:51 -0800278 }
Patrick Williams304e82e2023-05-10 07:51:13 -0500279 }
280 return 0;
Patrick Williams1388f6c2023-10-20 11:19:41 -0500281 },
Zhikui Renc96f37d2021-12-08 15:40:51 -0800282 [this](uint8_t& propertyValue) {
Patrick Williams304e82e2023-05-10 07:51:13 -0500283 updatePostcode();
284 propertyValue = postcode;
285 return propertyValue;
286 });
Zhikui Renc96f37d2021-12-08 15:40:51 -0800287
288 pfrPostcodeIface->register_property(postcodeStrProp,
289 std::string(postcodeStrDefault));
290
291 pfrPostcodeIface->initialize();
292 auto it = postcodeMap.find(postcode);
293 if (it != postcodeMap.end())
294 {
295 pfrPostcodeIface->set_property(postcodeStrProp, it->second);
296 }
297 }
298}
299
300void PfrPostcode::updatePostcode()
301{
302 if (pfrPostcodeIface && pfrPostcodeIface->is_initialized())
303 {
304 if (getPlatformState(postcode) < 0)
305 {
306 postcode = 0;
307 }
308
309 internalSet = true;
310 pfrPostcodeIface->set_property(postcodeDataProp, postcode);
311 auto it = postcodeMap.find(postcode);
312 if (it == postcodeMap.end())
313 {
314 pfrPostcodeIface->set_property(postcodeStrProp, postcodeStrDefault);
315 }
316 else
317 {
318 pfrPostcodeIface->set_property(postcodeStrProp, it->second);
319 }
320 internalSet = false;
321 }
322 return;
323}
324
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530325} // namespace pfr