blob: fc69fea5bb6a1000856ab5c9ae8544363e8f4045 [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
AppaRao Pulie63eeda2019-07-05 16:25:38 +053019namespace pfr
20{
21
Alex Schendel5cf320c2021-12-09 12:11:04 -080022inline void printVersion(const std::string& path, const std::string& version)
23{
24 lg2::info("VERSION INFO - {TYPE} - {VER}", "TYPE", path, "VER", version);
25}
AppaRao Pulie63eeda2019-07-05 16:25:38 +053026static constexpr uint8_t activeImage = 0;
27static constexpr uint8_t recoveryImage = 1;
28
AppaRao Puli0e758912020-01-29 03:07:54 +053029std::shared_ptr<sdbusplus::asio::dbus_interface> associationIface;
30std::set<std::tuple<std::string, std::string, std::string>> associations;
31
AppaRao Puli67d184c2020-05-29 00:48:33 +053032PfrVersion::PfrVersion(sdbusplus::asio::object_server& srv_,
33 std::shared_ptr<sdbusplus::asio::connection>& conn_,
34 const std::string& path_, const ImageType& imgType_,
35 const std::string& purpose_) :
AppaRao Pulie63eeda2019-07-05 16:25:38 +053036 server(srv_),
AppaRao Pulie4e95652019-07-19 16:52:01 +053037 conn(conn_), path(path_), imgType(imgType_), purpose(purpose_)
AppaRao Pulie63eeda2019-07-05 16:25:38 +053038{
AppaRao Puli4b639a22019-10-01 18:12:59 +053039 version = getFirmwareVersion(imgType);
AppaRao Pulie63eeda2019-07-05 16:25:38 +053040
Alex Schendel5cf320c2021-12-09 12:11:04 -080041 if (!(version == "0.0" || version.empty()))
42 {
43 printVersion(path, version);
44 }
45
AppaRao Pulie63eeda2019-07-05 16:25:38 +053046 std::string objPath = "/xyz/openbmc_project/software/" + path;
AppaRao Pulie4e95652019-07-19 16:52:01 +053047 versionIface =
AppaRao Pulie63eeda2019-07-05 16:25:38 +053048 server.add_interface(objPath, "xyz.openbmc_project.Software.Version");
AppaRao Pulie63eeda2019-07-05 16:25:38 +053049
Vikram Bodireddy1c06ae42021-07-08 15:26:51 +053050 if (versionIface != nullptr)
51 {
52
53 versionIface->register_property("Purpose", purpose);
54 versionIface->register_property(
55 versionStr, version,
56 // Override set
57 [this](const std::string& req, std::string& propertyValue) {
58 if (internalSet)
59 {
60 if (req != propertyValue)
61 {
62 version = req;
63 propertyValue = req;
64 return 1;
65 }
66 }
67 return 0;
68 });
69
70 versionIface->initialize();
71 }
AppaRao Pulid6f46c42019-07-19 22:34:04 +053072
AppaRao Puli916d6002019-12-18 01:37:02 +053073 std::string activation =
74 "xyz.openbmc_project.Software.Activation.Activations.StandbySpare";
75
76 if ((imgType == ImageType::bmcActive) ||
77 (imgType == ImageType::biosActive) ||
Vikram Bodireddy8292dc62021-05-26 13:31:47 +053078 (imgType == ImageType::cpldActive) || (imgType == ImageType::afmActive))
Vikram Bodireddy0fd4dde2019-12-06 15:48:00 +053079 {
AppaRao Puli916d6002019-12-18 01:37:02 +053080 // Running images so set Activations to "Active"
Vikram Bodireddy0fd4dde2019-12-06 15:48:00 +053081 activation =
82 "xyz.openbmc_project.Software.Activation.Activations.Active";
AppaRao Puli916d6002019-12-18 01:37:02 +053083
AppaRao Puli0e758912020-01-29 03:07:54 +053084 // For all Active images, functional endpoints must be added. This is
85 // used in bmcweb & ipmi for fetching active component versions.
86
87 // TODO: We have redundant active firmware version objects for BMC
88 // and BIOS active images. BMC version is read from /etc/os-release
89 // BIOS version is read from SMBIOS. Since it provides more
90 // version information, Lets expose those as functional.
91 // Down the line, Redundant inventory objects need to be addressed.
Vikram Bodireddy8292dc62021-05-26 13:31:47 +053092 if ((imgType == ImageType::cpldActive) ||
93 (imgType == ImageType::afmActive))
AppaRao Puli0e758912020-01-29 03:07:54 +053094 {
95 associations.emplace("functional", "software_version", objPath);
96 }
Vikram Bodireddy0fd4dde2019-12-06 15:48:00 +053097 }
98
AppaRao Pulid6f46c42019-07-19 22:34:04 +053099 std::string reqActNone =
100 "xyz.openbmc_project.Software.Activation.RequestedActivations.None";
101 auto activationIface = server.add_interface(
102 objPath, "xyz.openbmc_project.Software.Activation");
AppaRao Pulid6f46c42019-07-19 22:34:04 +0530103
Vikram Bodireddy1c06ae42021-07-08 15:26:51 +0530104 if (activationIface != nullptr)
105 {
106
107 activationIface->register_property("Activation", activation);
108 activationIface->register_property("RequestedActivation", reqActNone);
109
110 activationIface->initialize();
111 }
AppaRao Puli0e758912020-01-29 03:07:54 +0530112
113 // All the components exposed under PFR.Manager are updateable.
114 // Lets add objPath endpoints to 'updatable' association
115 associations.emplace("updateable", "software_version", objPath);
116 associationIface->set_property("Associations", associations);
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530117}
118
AppaRao Pulie4e95652019-07-19 16:52:01 +0530119void PfrVersion::updateVersion()
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530120{
AppaRao Pulie4e95652019-07-19 16:52:01 +0530121 if (versionIface && versionIface->is_initialized())
122 {
AppaRao Puli4b639a22019-10-01 18:12:59 +0530123 std::string ver = getFirmwareVersion(imgType);
Alex Schendel5cf320c2021-12-09 12:11:04 -0800124 printVersion(path, ver);
AppaRao Pulie4e95652019-07-19 16:52:01 +0530125 internalSet = true;
126 versionIface->set_property(versionStr, ver);
127 internalSet = false;
128 }
129 return;
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530130}
131
AppaRao Puli67d184c2020-05-29 00:48:33 +0530132PfrConfig::PfrConfig(sdbusplus::asio::object_server& srv_,
133 std::shared_ptr<sdbusplus::asio::connection>& conn_) :
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530134 server(srv_),
135 conn(conn_)
136{
AppaRao Pulicc1ed682019-10-01 12:29:40 +0530137 pfrCfgIface = server.add_interface("/xyz/openbmc_project/pfr",
138 "xyz.openbmc_project.PFR.Attributes");
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530139
Chalapathi Venkataramashettyf8819702021-02-03 09:43:46 +0000140 ufmLocked = false;
141 ufmProvisioned = false;
142 ufmSupport = false;
143 getProvisioningStatus(ufmLocked, ufmProvisioned, ufmSupport);
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530144
AppaRao Pulie4e95652019-07-19 16:52:01 +0530145 pfrCfgIface->register_property(ufmProvisionedStr, ufmProvisioned,
146 // Override set
147 [this](const bool req, bool propertyValue) {
148 if (internalSet)
149 {
150 if (req != propertyValue)
151 {
152 ufmProvisioned = req;
153 propertyValue = req;
154 return 1;
155 }
156 }
157 return 0;
158 });
159
160 pfrCfgIface->register_property(ufmLockedStr, ufmLocked,
161 // Override set
162 [this](const bool req, bool propertyValue) {
163 if (internalSet)
164 {
165 if (req != propertyValue)
166 {
167 ufmLocked = req;
168 propertyValue = req;
169 return 1;
170 }
171 }
172 return 0;
173 });
174
Chalapathi Venkataramashettyf8819702021-02-03 09:43:46 +0000175 pfrCfgIface->register_property(ufmSupportStr, ufmSupport,
176 // Override set
177 [this](const bool req, bool propertyValue) {
178 if (internalSet)
179 {
180 if (req != propertyValue)
181 {
182 ufmSupport = req;
183 propertyValue = req;
184 return 1;
185 }
186 }
187 return 0;
188 });
189
AppaRao Pulie4e95652019-07-19 16:52:01 +0530190 pfrCfgIface->initialize();
AppaRao Puli0e758912020-01-29 03:07:54 +0530191
192 associationIface =
193 server.add_interface("/xyz/openbmc_project/software",
194 "xyz.openbmc_project.Association.Definitions");
195 associationIface->register_property("Associations", associations);
196 associationIface->initialize();
AppaRao Pulie4e95652019-07-19 16:52:01 +0530197}
198
199void PfrConfig::updateProvisioningStatus()
200{
201 if (pfrCfgIface && pfrCfgIface->is_initialized())
202 {
203 bool lockVal = false;
204 bool provVal = false;
Chalapathi Venkataramashettyf8819702021-02-03 09:43:46 +0000205 bool supportVal = false;
206 getProvisioningStatus(lockVal, provVal, supportVal);
AppaRao Pulie4e95652019-07-19 16:52:01 +0530207 internalSet = true;
208 pfrCfgIface->set_property(ufmProvisionedStr, provVal);
209 pfrCfgIface->set_property(ufmLockedStr, lockVal);
Chalapathi Venkataramashettyf8819702021-02-03 09:43:46 +0000210 pfrCfgIface->set_property(ufmSupportStr, supportVal);
AppaRao Pulie4e95652019-07-19 16:52:01 +0530211 internalSet = false;
212 }
213 return;
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530214}
215
Zhikui Renc96f37d2021-12-08 15:40:51 -0800216static constexpr const char* postcodeStrProp = "PlatformState";
217static constexpr const char* postcodeStrDefault = "Unknown";
218static constexpr const char* postcodeDataProp = "Data";
219static constexpr const char* postcodeIface =
220 "xyz.openbmc_project.State.Boot.Platform";
221
222PfrPostcode::PfrPostcode(sdbusplus::asio::object_server& srv_,
223 std::shared_ptr<sdbusplus::asio::connection>& conn_) :
224 server(srv_),
225 conn(conn_)
226{
227 if (getPlatformState(postcode) < 0)
228 {
229 postcode = 0;
230 }
231
232 pfrPostcodeIface =
233 server.add_interface("/xyz/openbmc_project/pfr", postcodeIface);
234
235 if (pfrPostcodeIface != nullptr)
236 {
237 pfrPostcodeIface->register_property(
238 postcodeDataProp, postcode,
239 // Override set
240 [this](const uint8_t req, uint8_t& propertyValue) {
241 if (internalSet)
242 {
243 if (req != propertyValue)
244 {
245 postcode = req;
246 propertyValue = req;
247 return 1;
248 }
249 }
250 return 0;
251 },
252 [this](uint8_t& propertyValue) {
253 updatePostcode();
254 propertyValue = postcode;
255 return propertyValue;
256 });
257
258 pfrPostcodeIface->register_property(postcodeStrProp,
259 std::string(postcodeStrDefault));
260
261 pfrPostcodeIface->initialize();
262 auto it = postcodeMap.find(postcode);
263 if (it != postcodeMap.end())
264 {
265 pfrPostcodeIface->set_property(postcodeStrProp, it->second);
266 }
267 }
268}
269
270void PfrPostcode::updatePostcode()
271{
272 if (pfrPostcodeIface && pfrPostcodeIface->is_initialized())
273 {
274 if (getPlatformState(postcode) < 0)
275 {
276 postcode = 0;
277 }
278
279 internalSet = true;
280 pfrPostcodeIface->set_property(postcodeDataProp, postcode);
281 auto it = postcodeMap.find(postcode);
282 if (it == postcodeMap.end())
283 {
284 pfrPostcodeIface->set_property(postcodeStrProp, postcodeStrDefault);
285 }
286 else
287 {
288 pfrPostcodeIface->set_property(postcodeStrProp, it->second);
289 }
290 internalSet = false;
291 }
292 return;
293}
294
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530295} // namespace pfr