blob: 479cf5f31b65843d021029c747f092572f21a650 [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 Pulie4e95652019-07-19 16:52:01 +053040 versionIface->register_property("Purpose", purpose);
41 versionIface->register_property(
42 versionStr, version,
43 // Override set
AppaRao Puli67d184c2020-05-29 00:48:33 +053044 [this](const std::string& req, std::string& propertyValue) {
AppaRao Pulie4e95652019-07-19 16:52:01 +053045 if (internalSet)
46 {
47 if (req != propertyValue)
48 {
49 version = req;
50 propertyValue = req;
51 return 1;
52 }
53 }
54 return 0;
55 });
AppaRao Pulie63eeda2019-07-05 16:25:38 +053056
AppaRao Pulie4e95652019-07-19 16:52:01 +053057 versionIface->initialize();
AppaRao Pulid6f46c42019-07-19 22:34:04 +053058
AppaRao Puli916d6002019-12-18 01:37:02 +053059 std::string activation =
60 "xyz.openbmc_project.Software.Activation.Activations.StandbySpare";
61
62 if ((imgType == ImageType::bmcActive) ||
63 (imgType == ImageType::biosActive) ||
64 (imgType == ImageType::cpldActive))
Vikram Bodireddy0fd4dde2019-12-06 15:48:00 +053065 {
AppaRao Puli916d6002019-12-18 01:37:02 +053066 // Running images so set Activations to "Active"
Vikram Bodireddy0fd4dde2019-12-06 15:48:00 +053067 activation =
68 "xyz.openbmc_project.Software.Activation.Activations.Active";
AppaRao Puli916d6002019-12-18 01:37:02 +053069
AppaRao Puli0e758912020-01-29 03:07:54 +053070 // For all Active images, functional endpoints must be added. This is
71 // used in bmcweb & ipmi for fetching active component versions.
72
73 // TODO: We have redundant active firmware version objects for BMC
74 // and BIOS active images. BMC version is read from /etc/os-release
75 // BIOS version is read from SMBIOS. Since it provides more
76 // version information, Lets expose those as functional.
77 // Down the line, Redundant inventory objects need to be addressed.
78 if (imgType == ImageType::cpldActive)
79 {
80 associations.emplace("functional", "software_version", objPath);
81 }
Vikram Bodireddy0fd4dde2019-12-06 15:48:00 +053082 }
83
AppaRao Pulid6f46c42019-07-19 22:34:04 +053084 std::string reqActNone =
85 "xyz.openbmc_project.Software.Activation.RequestedActivations.None";
86 auto activationIface = server.add_interface(
87 objPath, "xyz.openbmc_project.Software.Activation");
88 activationIface->register_property("Activation", activation);
89 activationIface->register_property("RequestedActivation", reqActNone);
90
91 activationIface->initialize();
AppaRao Puli0e758912020-01-29 03:07:54 +053092
93 // All the components exposed under PFR.Manager are updateable.
94 // Lets add objPath endpoints to 'updatable' association
95 associations.emplace("updateable", "software_version", objPath);
96 associationIface->set_property("Associations", associations);
AppaRao Pulie63eeda2019-07-05 16:25:38 +053097}
98
AppaRao Pulie4e95652019-07-19 16:52:01 +053099void PfrVersion::updateVersion()
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530100{
AppaRao Pulie4e95652019-07-19 16:52:01 +0530101 if (versionIface && versionIface->is_initialized())
102 {
AppaRao Puli4b639a22019-10-01 18:12:59 +0530103 std::string ver = getFirmwareVersion(imgType);
AppaRao Pulie4e95652019-07-19 16:52:01 +0530104 internalSet = true;
105 versionIface->set_property(versionStr, ver);
106 internalSet = false;
107 }
108 return;
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530109}
110
AppaRao Puli67d184c2020-05-29 00:48:33 +0530111PfrConfig::PfrConfig(sdbusplus::asio::object_server& srv_,
112 std::shared_ptr<sdbusplus::asio::connection>& conn_) :
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530113 server(srv_),
114 conn(conn_)
115{
AppaRao Pulicc1ed682019-10-01 12:29:40 +0530116 pfrCfgIface = server.add_interface("/xyz/openbmc_project/pfr",
117 "xyz.openbmc_project.PFR.Attributes");
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530118
Chalapathi Venkataramashettyf8819702021-02-03 09:43:46 +0000119 ufmLocked = false;
120 ufmProvisioned = false;
121 ufmSupport = false;
122 getProvisioningStatus(ufmLocked, ufmProvisioned, ufmSupport);
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530123
AppaRao Pulie4e95652019-07-19 16:52:01 +0530124 pfrCfgIface->register_property(ufmProvisionedStr, ufmProvisioned,
125 // Override set
126 [this](const bool req, bool propertyValue) {
127 if (internalSet)
128 {
129 if (req != propertyValue)
130 {
131 ufmProvisioned = req;
132 propertyValue = req;
133 return 1;
134 }
135 }
136 return 0;
137 });
138
139 pfrCfgIface->register_property(ufmLockedStr, ufmLocked,
140 // Override set
141 [this](const bool req, bool propertyValue) {
142 if (internalSet)
143 {
144 if (req != propertyValue)
145 {
146 ufmLocked = req;
147 propertyValue = req;
148 return 1;
149 }
150 }
151 return 0;
152 });
153
Chalapathi Venkataramashettyf8819702021-02-03 09:43:46 +0000154 pfrCfgIface->register_property(ufmSupportStr, ufmSupport,
155 // Override set
156 [this](const bool req, bool propertyValue) {
157 if (internalSet)
158 {
159 if (req != propertyValue)
160 {
161 ufmSupport = req;
162 propertyValue = req;
163 return 1;
164 }
165 }
166 return 0;
167 });
168
AppaRao Pulie4e95652019-07-19 16:52:01 +0530169 pfrCfgIface->initialize();
AppaRao Puli0e758912020-01-29 03:07:54 +0530170
171 associationIface =
172 server.add_interface("/xyz/openbmc_project/software",
173 "xyz.openbmc_project.Association.Definitions");
174 associationIface->register_property("Associations", associations);
175 associationIface->initialize();
AppaRao Pulie4e95652019-07-19 16:52:01 +0530176}
177
178void PfrConfig::updateProvisioningStatus()
179{
180 if (pfrCfgIface && pfrCfgIface->is_initialized())
181 {
182 bool lockVal = false;
183 bool provVal = false;
Chalapathi Venkataramashettyf8819702021-02-03 09:43:46 +0000184 bool supportVal = false;
185 getProvisioningStatus(lockVal, provVal, supportVal);
AppaRao Pulie4e95652019-07-19 16:52:01 +0530186 internalSet = true;
187 pfrCfgIface->set_property(ufmProvisionedStr, provVal);
188 pfrCfgIface->set_property(ufmLockedStr, lockVal);
Chalapathi Venkataramashettyf8819702021-02-03 09:43:46 +0000189 pfrCfgIface->set_property(ufmSupportStr, supportVal);
AppaRao Pulie4e95652019-07-19 16:52:01 +0530190 internalSet = false;
191 }
192 return;
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530193}
194
195} // namespace pfr