blob: e2fdbfd60580242961d36c3c6311c7014d178d88 [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
22static constexpr uint8_t activeImage = 0;
23static constexpr uint8_t recoveryImage = 1;
24
AppaRao Puli0e758912020-01-29 03:07:54 +053025std::shared_ptr<sdbusplus::asio::dbus_interface> associationIface;
26std::set<std::tuple<std::string, std::string, std::string>> associations;
27
AppaRao Puli67d184c2020-05-29 00:48:33 +053028PfrVersion::PfrVersion(sdbusplus::asio::object_server& srv_,
29 std::shared_ptr<sdbusplus::asio::connection>& conn_,
30 const std::string& path_, const ImageType& imgType_,
31 const std::string& purpose_) :
AppaRao Pulie63eeda2019-07-05 16:25:38 +053032 server(srv_),
AppaRao Pulie4e95652019-07-19 16:52:01 +053033 conn(conn_), path(path_), imgType(imgType_), purpose(purpose_)
AppaRao Pulie63eeda2019-07-05 16:25:38 +053034{
AppaRao Puli4b639a22019-10-01 18:12:59 +053035 version = getFirmwareVersion(imgType);
AppaRao Pulie63eeda2019-07-05 16:25:38 +053036
37 std::string objPath = "/xyz/openbmc_project/software/" + path;
AppaRao Pulie4e95652019-07-19 16:52:01 +053038 versionIface =
AppaRao Pulie63eeda2019-07-05 16:25:38 +053039 server.add_interface(objPath, "xyz.openbmc_project.Software.Version");
AppaRao Pulie63eeda2019-07-05 16:25:38 +053040
Vikram Bodireddy1c06ae42021-07-08 15:26:51 +053041 if (versionIface != nullptr)
42 {
43
44 versionIface->register_property("Purpose", purpose);
45 versionIface->register_property(
46 versionStr, version,
47 // Override set
48 [this](const std::string& req, std::string& propertyValue) {
49 if (internalSet)
50 {
51 if (req != propertyValue)
52 {
53 version = req;
54 propertyValue = req;
55 return 1;
56 }
57 }
58 return 0;
59 });
60
61 versionIface->initialize();
62 }
AppaRao Pulid6f46c42019-07-19 22:34:04 +053063
AppaRao Puli916d6002019-12-18 01:37:02 +053064 std::string activation =
65 "xyz.openbmc_project.Software.Activation.Activations.StandbySpare";
66
67 if ((imgType == ImageType::bmcActive) ||
68 (imgType == ImageType::biosActive) ||
Vikram Bodireddy8292dc62021-05-26 13:31:47 +053069 (imgType == ImageType::cpldActive) || (imgType == ImageType::afmActive))
Vikram Bodireddy0fd4dde2019-12-06 15:48:00 +053070 {
AppaRao Puli916d6002019-12-18 01:37:02 +053071 // Running images so set Activations to "Active"
Vikram Bodireddy0fd4dde2019-12-06 15:48:00 +053072 activation =
73 "xyz.openbmc_project.Software.Activation.Activations.Active";
AppaRao Puli916d6002019-12-18 01:37:02 +053074
AppaRao Puli0e758912020-01-29 03:07:54 +053075 // For all Active images, functional endpoints must be added. This is
76 // used in bmcweb & ipmi for fetching active component versions.
77
78 // TODO: We have redundant active firmware version objects for BMC
79 // and BIOS active images. BMC version is read from /etc/os-release
80 // BIOS version is read from SMBIOS. Since it provides more
81 // version information, Lets expose those as functional.
82 // Down the line, Redundant inventory objects need to be addressed.
Vikram Bodireddy8292dc62021-05-26 13:31:47 +053083 if ((imgType == ImageType::cpldActive) ||
84 (imgType == ImageType::afmActive))
AppaRao Puli0e758912020-01-29 03:07:54 +053085 {
86 associations.emplace("functional", "software_version", objPath);
87 }
Vikram Bodireddy0fd4dde2019-12-06 15:48:00 +053088 }
89
AppaRao Pulid6f46c42019-07-19 22:34:04 +053090 std::string reqActNone =
91 "xyz.openbmc_project.Software.Activation.RequestedActivations.None";
92 auto activationIface = server.add_interface(
93 objPath, "xyz.openbmc_project.Software.Activation");
AppaRao Pulid6f46c42019-07-19 22:34:04 +053094
Vikram Bodireddy1c06ae42021-07-08 15:26:51 +053095 if (activationIface != nullptr)
96 {
97
98 activationIface->register_property("Activation", activation);
99 activationIface->register_property("RequestedActivation", reqActNone);
100
101 activationIface->initialize();
102 }
AppaRao Puli0e758912020-01-29 03:07:54 +0530103
104 // All the components exposed under PFR.Manager are updateable.
105 // Lets add objPath endpoints to 'updatable' association
106 associations.emplace("updateable", "software_version", objPath);
107 associationIface->set_property("Associations", associations);
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530108}
109
AppaRao Pulie4e95652019-07-19 16:52:01 +0530110void PfrVersion::updateVersion()
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530111{
AppaRao Pulie4e95652019-07-19 16:52:01 +0530112 if (versionIface && versionIface->is_initialized())
113 {
AppaRao Puli4b639a22019-10-01 18:12:59 +0530114 std::string ver = getFirmwareVersion(imgType);
AppaRao Pulie4e95652019-07-19 16:52:01 +0530115 internalSet = true;
116 versionIface->set_property(versionStr, ver);
117 internalSet = false;
118 }
119 return;
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530120}
121
AppaRao Puli67d184c2020-05-29 00:48:33 +0530122PfrConfig::PfrConfig(sdbusplus::asio::object_server& srv_,
123 std::shared_ptr<sdbusplus::asio::connection>& conn_) :
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530124 server(srv_),
125 conn(conn_)
126{
AppaRao Pulicc1ed682019-10-01 12:29:40 +0530127 pfrCfgIface = server.add_interface("/xyz/openbmc_project/pfr",
128 "xyz.openbmc_project.PFR.Attributes");
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530129
Chalapathi Venkataramashettyf8819702021-02-03 09:43:46 +0000130 ufmLocked = false;
131 ufmProvisioned = false;
132 ufmSupport = false;
133 getProvisioningStatus(ufmLocked, ufmProvisioned, ufmSupport);
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530134
AppaRao Pulie4e95652019-07-19 16:52:01 +0530135 pfrCfgIface->register_property(ufmProvisionedStr, ufmProvisioned,
136 // Override set
137 [this](const bool req, bool propertyValue) {
138 if (internalSet)
139 {
140 if (req != propertyValue)
141 {
142 ufmProvisioned = req;
143 propertyValue = req;
144 return 1;
145 }
146 }
147 return 0;
148 });
149
150 pfrCfgIface->register_property(ufmLockedStr, ufmLocked,
151 // Override set
152 [this](const bool req, bool propertyValue) {
153 if (internalSet)
154 {
155 if (req != propertyValue)
156 {
157 ufmLocked = req;
158 propertyValue = req;
159 return 1;
160 }
161 }
162 return 0;
163 });
164
Chalapathi Venkataramashettyf8819702021-02-03 09:43:46 +0000165 pfrCfgIface->register_property(ufmSupportStr, ufmSupport,
166 // Override set
167 [this](const bool req, bool propertyValue) {
168 if (internalSet)
169 {
170 if (req != propertyValue)
171 {
172 ufmSupport = req;
173 propertyValue = req;
174 return 1;
175 }
176 }
177 return 0;
178 });
179
AppaRao Pulie4e95652019-07-19 16:52:01 +0530180 pfrCfgIface->initialize();
AppaRao Puli0e758912020-01-29 03:07:54 +0530181
182 associationIface =
183 server.add_interface("/xyz/openbmc_project/software",
184 "xyz.openbmc_project.Association.Definitions");
185 associationIface->register_property("Associations", associations);
186 associationIface->initialize();
AppaRao Pulie4e95652019-07-19 16:52:01 +0530187}
188
189void PfrConfig::updateProvisioningStatus()
190{
191 if (pfrCfgIface && pfrCfgIface->is_initialized())
192 {
193 bool lockVal = false;
194 bool provVal = false;
Chalapathi Venkataramashettyf8819702021-02-03 09:43:46 +0000195 bool supportVal = false;
196 getProvisioningStatus(lockVal, provVal, supportVal);
AppaRao Pulie4e95652019-07-19 16:52:01 +0530197 internalSet = true;
198 pfrCfgIface->set_property(ufmProvisionedStr, provVal);
199 pfrCfgIface->set_property(ufmLockedStr, lockVal);
Chalapathi Venkataramashettyf8819702021-02-03 09:43:46 +0000200 pfrCfgIface->set_property(ufmSupportStr, supportVal);
AppaRao Pulie4e95652019-07-19 16:52:01 +0530201 internalSet = false;
202 }
203 return;
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530204}
205
206} // namespace pfr