blob: d31c14f092a93f5214e4195a6485d6adcc75100a [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_) :
Patrick Williams1695ee32024-08-16 15:21:41 -040042 server(srv_), conn(conn_), path(path_), imgType(imgType_), purpose(purpose_)
AppaRao Pulie63eeda2019-07-05 16:25:38 +053043{
AppaRao Puli4b639a22019-10-01 18:12:59 +053044 version = getFirmwareVersion(imgType);
AppaRao Pulie63eeda2019-07-05 16:25:38 +053045
Alex Schendel5cf320c2021-12-09 12:11:04 -080046 if (!(version == "0.0" || version.empty()))
47 {
48 printVersion(path, version);
49 }
50
AppaRao Pulie63eeda2019-07-05 16:25:38 +053051 std::string objPath = "/xyz/openbmc_project/software/" + path;
Patrick Williams1695ee32024-08-16 15:21:41 -040052 versionIface =
53 server.add_interface(objPath, "xyz.openbmc_project.Software.Version");
AppaRao Pulie63eeda2019-07-05 16:25:38 +053054
Vikram Bodireddy1c06ae42021-07-08 15:26:51 +053055 if (versionIface != nullptr)
56 {
Vikram Bodireddy1c06ae42021-07-08 15:26:51 +053057 versionIface->register_property("Purpose", purpose);
58 versionIface->register_property(
59 versionStr, version,
60 // Override set
61 [this](const std::string& req, std::string& propertyValue) {
Patrick Williams1695ee32024-08-16 15:21:41 -040062 if (internalSet)
Vikram Bodireddy1c06ae42021-07-08 15:26:51 +053063 {
Patrick Williams1695ee32024-08-16 15:21:41 -040064 if (req != propertyValue)
65 {
66 version = req;
67 propertyValue = req;
68 return 1;
69 }
Vikram Bodireddy1c06ae42021-07-08 15:26:51 +053070 }
Patrick Williams1695ee32024-08-16 15:21:41 -040071 return 0;
72 });
Vikram Bodireddy1c06ae42021-07-08 15:26:51 +053073
74 versionIface->initialize();
75 }
AppaRao Pulid6f46c42019-07-19 22:34:04 +053076
AppaRao Puli916d6002019-12-18 01:37:02 +053077 std::string activation =
78 "xyz.openbmc_project.Software.Activation.Activations.StandbySpare";
79
80 if ((imgType == ImageType::bmcActive) ||
81 (imgType == ImageType::biosActive) ||
Vikram Bodireddy8292dc62021-05-26 13:31:47 +053082 (imgType == ImageType::cpldActive) || (imgType == ImageType::afmActive))
Vikram Bodireddy0fd4dde2019-12-06 15:48:00 +053083 {
AppaRao Puli916d6002019-12-18 01:37:02 +053084 // Running images so set Activations to "Active"
Vikram Bodireddy0fd4dde2019-12-06 15:48:00 +053085 activation =
86 "xyz.openbmc_project.Software.Activation.Activations.Active";
AppaRao Puli916d6002019-12-18 01:37:02 +053087
AppaRao Puli0e758912020-01-29 03:07:54 +053088 // For all Active images, functional endpoints must be added. This is
89 // used in bmcweb & ipmi for fetching active component versions.
90
91 // TODO: We have redundant active firmware version objects for BMC
92 // and BIOS active images. BMC version is read from /etc/os-release
93 // BIOS version is read from SMBIOS. Since it provides more
94 // version information, Lets expose those as functional.
95 // Down the line, Redundant inventory objects need to be addressed.
Vikram Bodireddy8292dc62021-05-26 13:31:47 +053096 if ((imgType == ImageType::cpldActive) ||
97 (imgType == ImageType::afmActive))
AppaRao Puli0e758912020-01-29 03:07:54 +053098 {
99 associations.emplace("functional", "software_version", objPath);
100 }
Vikram Bodireddy0fd4dde2019-12-06 15:48:00 +0530101 }
102
AppaRao Pulid6f46c42019-07-19 22:34:04 +0530103 std::string reqActNone =
104 "xyz.openbmc_project.Software.Activation.RequestedActivations.None";
105 auto activationIface = server.add_interface(
106 objPath, "xyz.openbmc_project.Software.Activation");
AppaRao Pulid6f46c42019-07-19 22:34:04 +0530107
Vikram Bodireddy1c06ae42021-07-08 15:26:51 +0530108 if (activationIface != nullptr)
109 {
Vikram Bodireddy1c06ae42021-07-08 15:26:51 +0530110 activationIface->register_property("Activation", activation);
111 activationIface->register_property("RequestedActivation", reqActNone);
112
113 activationIface->initialize();
114 }
AppaRao Puli0e758912020-01-29 03:07:54 +0530115
116 // All the components exposed under PFR.Manager are updateable.
117 // Lets add objPath endpoints to 'updatable' association
118 associations.emplace("updateable", "software_version", objPath);
119 associationIface->set_property("Associations", associations);
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530120}
121
AppaRao Pulie4e95652019-07-19 16:52:01 +0530122void PfrVersion::updateVersion()
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530123{
AppaRao Pulie4e95652019-07-19 16:52:01 +0530124 if (versionIface && versionIface->is_initialized())
125 {
AppaRao Puli4b639a22019-10-01 18:12:59 +0530126 std::string ver = getFirmwareVersion(imgType);
Alex Schendel5cf320c2021-12-09 12:11:04 -0800127 printVersion(path, ver);
AppaRao Pulie4e95652019-07-19 16:52:01 +0530128 internalSet = true;
129 versionIface->set_property(versionStr, ver);
130 internalSet = false;
131 }
132 return;
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530133}
134
AppaRao Puli67d184c2020-05-29 00:48:33 +0530135PfrConfig::PfrConfig(sdbusplus::asio::object_server& srv_,
136 std::shared_ptr<sdbusplus::asio::connection>& conn_) :
Patrick Williams1695ee32024-08-16 15:21:41 -0400137 server(srv_), conn(conn_)
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530138{
AppaRao Pulicc1ed682019-10-01 12:29:40 +0530139 pfrCfgIface = server.add_interface("/xyz/openbmc_project/pfr",
140 "xyz.openbmc_project.PFR.Attributes");
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530141
Chalapathi Venkataramashettyf8819702021-02-03 09:43:46 +0000142 ufmLocked = false;
143 ufmProvisioned = false;
144 ufmSupport = false;
145 getProvisioningStatus(ufmLocked, ufmProvisioned, ufmSupport);
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530146
AppaRao Pulie4e95652019-07-19 16:52:01 +0530147 pfrCfgIface->register_property(ufmProvisionedStr, ufmProvisioned,
148 // Override set
149 [this](const bool req, bool propertyValue) {
Patrick Williams1695ee32024-08-16 15:21:41 -0400150 if (internalSet)
151 {
152 if (req != propertyValue)
153 {
154 ufmProvisioned = req;
155 propertyValue = req;
156 return 1;
157 }
158 }
159 return 0;
160 });
AppaRao Pulie4e95652019-07-19 16:52:01 +0530161
162 pfrCfgIface->register_property(ufmLockedStr, ufmLocked,
163 // Override set
164 [this](const bool req, bool propertyValue) {
Patrick Williams1695ee32024-08-16 15:21:41 -0400165 if (internalSet)
166 {
167 if (req != propertyValue)
168 {
169 ufmLocked = req;
170 propertyValue = req;
171 return 1;
172 }
173 }
174 return 0;
175 });
AppaRao Pulie4e95652019-07-19 16:52:01 +0530176
Chalapathi Venkataramashettyf8819702021-02-03 09:43:46 +0000177 pfrCfgIface->register_property(ufmSupportStr, ufmSupport,
178 // Override set
179 [this](const bool req, bool propertyValue) {
Patrick Williams1695ee32024-08-16 15:21:41 -0400180 if (internalSet)
181 {
182 if (req != propertyValue)
183 {
184 ufmSupport = req;
185 propertyValue = req;
186 return 1;
187 }
188 }
189 return 0;
190 });
Chalapathi Venkataramashettyf8819702021-02-03 09:43:46 +0000191
AppaRao Pulie4e95652019-07-19 16:52:01 +0530192 pfrCfgIface->initialize();
AppaRao Puli0e758912020-01-29 03:07:54 +0530193
deepak kumar agrawalb29a15c2022-03-25 07:45:57 +0000194 /*BMCBusy period MailBox handling */
195 pfrMBIface = server.add_interface("/xyz/openbmc_project/pfr",
196 "xyz.openbmc_project.PFR.Mailbox");
197
198 pfrMBIface->register_method("InitiateBMCBusyPeriod", [](bool setReset) {
199 if (setBMCBusy(setReset) < 0)
200 {
201 return false;
202 }
203 return true;
204 });
205
206 pfrMBIface->register_method("ReadMBRegister", [](uint32_t regAddr) {
207 uint8_t mailBoxReply = 0;
208 try
209 {
210 getMBRegister(regAddr, mailBoxReply);
211 }
212 catch (const std::exception& e)
213 {
214 throw;
215 }
216 return mailBoxReply;
217 });
218 pfrMBIface->initialize();
219
AppaRao Puli0e758912020-01-29 03:07:54 +0530220 associationIface =
221 server.add_interface("/xyz/openbmc_project/software",
222 "xyz.openbmc_project.Association.Definitions");
223 associationIface->register_property("Associations", associations);
224 associationIface->initialize();
AppaRao Pulie4e95652019-07-19 16:52:01 +0530225}
226
227void PfrConfig::updateProvisioningStatus()
228{
229 if (pfrCfgIface && pfrCfgIface->is_initialized())
230 {
231 bool lockVal = false;
232 bool provVal = false;
Chalapathi Venkataramashettyf8819702021-02-03 09:43:46 +0000233 bool supportVal = false;
234 getProvisioningStatus(lockVal, provVal, supportVal);
AppaRao Pulie4e95652019-07-19 16:52:01 +0530235 internalSet = true;
236 pfrCfgIface->set_property(ufmProvisionedStr, provVal);
237 pfrCfgIface->set_property(ufmLockedStr, lockVal);
Chalapathi Venkataramashettyf8819702021-02-03 09:43:46 +0000238 pfrCfgIface->set_property(ufmSupportStr, supportVal);
AppaRao Pulie4e95652019-07-19 16:52:01 +0530239 internalSet = false;
240 }
241 return;
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530242}
243
Zhikui Renc96f37d2021-12-08 15:40:51 -0800244static constexpr const char* postcodeStrProp = "PlatformState";
245static constexpr const char* postcodeStrDefault = "Unknown";
246static constexpr const char* postcodeDataProp = "Data";
247static constexpr const char* postcodeIface =
248 "xyz.openbmc_project.State.Boot.Platform";
249
250PfrPostcode::PfrPostcode(sdbusplus::asio::object_server& srv_,
251 std::shared_ptr<sdbusplus::asio::connection>& conn_) :
Patrick Williams1695ee32024-08-16 15:21:41 -0400252 server(srv_), conn(conn_)
Zhikui Renc96f37d2021-12-08 15:40:51 -0800253{
254 if (getPlatformState(postcode) < 0)
255 {
256 postcode = 0;
257 }
258
Patrick Williams1695ee32024-08-16 15:21:41 -0400259 pfrPostcodeIface =
260 server.add_interface("/xyz/openbmc_project/pfr", postcodeIface);
Zhikui Renc96f37d2021-12-08 15:40:51 -0800261
262 if (pfrPostcodeIface != nullptr)
263 {
264 pfrPostcodeIface->register_property(
265 postcodeDataProp, postcode,
266 // Override set
267 [this](const uint8_t req, uint8_t& propertyValue) {
Patrick Williams1695ee32024-08-16 15:21:41 -0400268 if (internalSet)
Zhikui Renc96f37d2021-12-08 15:40:51 -0800269 {
Patrick Williams1695ee32024-08-16 15:21:41 -0400270 if (req != propertyValue)
271 {
272 postcode = req;
273 propertyValue = req;
274 return 1;
275 }
Zhikui Renc96f37d2021-12-08 15:40:51 -0800276 }
Patrick Williams1695ee32024-08-16 15:21:41 -0400277 return 0;
278 },
Zhikui Renc96f37d2021-12-08 15:40:51 -0800279 [this](uint8_t& propertyValue) {
Patrick Williams1695ee32024-08-16 15:21:41 -0400280 updatePostcode();
281 propertyValue = postcode;
282 return propertyValue;
283 });
Zhikui Renc96f37d2021-12-08 15:40:51 -0800284
285 pfrPostcodeIface->register_property(postcodeStrProp,
286 std::string(postcodeStrDefault));
287
288 pfrPostcodeIface->initialize();
289 auto it = postcodeMap.find(postcode);
290 if (it != postcodeMap.end())
291 {
292 pfrPostcodeIface->set_property(postcodeStrProp, it->second);
293 }
294 }
295}
296
297void PfrPostcode::updatePostcode()
298{
299 if (pfrPostcodeIface && pfrPostcodeIface->is_initialized())
300 {
301 if (getPlatformState(postcode) < 0)
302 {
303 postcode = 0;
304 }
305
306 internalSet = true;
307 pfrPostcodeIface->set_property(postcodeDataProp, postcode);
308 auto it = postcodeMap.find(postcode);
309 if (it == postcodeMap.end())
310 {
311 pfrPostcodeIface->set_property(postcodeStrProp, postcodeStrDefault);
312 }
313 else
314 {
315 pfrPostcodeIface->set_property(postcodeStrProp, it->second);
316 }
317 internalSet = false;
318 }
319 return;
320}
321
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530322} // namespace pfr