blob: abc29388e81b3c4464044868167852caff19c813 [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
19namespace intel
20{
21namespace pfr
22{
23
24static constexpr uint8_t activeImage = 0;
25static constexpr uint8_t recoveryImage = 1;
26
AppaRao Puli0e758912020-01-29 03:07:54 +053027std::shared_ptr<sdbusplus::asio::dbus_interface> associationIface;
28std::set<std::tuple<std::string, std::string, std::string>> associations;
29
AppaRao Pulie63eeda2019-07-05 16:25:38 +053030PfrVersion::PfrVersion(sdbusplus::asio::object_server &srv_,
31 std::shared_ptr<sdbusplus::asio::connection> &conn_,
AppaRao Pulie4e95652019-07-19 16:52:01 +053032 const std::string &path_, const ImageType &imgType_,
33 const std::string &purpose_) :
AppaRao Pulie63eeda2019-07-05 16:25:38 +053034 server(srv_),
AppaRao Pulie4e95652019-07-19 16:52:01 +053035 conn(conn_), path(path_), imgType(imgType_), purpose(purpose_)
AppaRao Pulie63eeda2019-07-05 16:25:38 +053036{
AppaRao Puli4b639a22019-10-01 18:12:59 +053037 version = getFirmwareVersion(imgType);
AppaRao Pulie63eeda2019-07-05 16:25:38 +053038
39 std::string objPath = "/xyz/openbmc_project/software/" + path;
AppaRao Pulie4e95652019-07-19 16:52:01 +053040 versionIface =
AppaRao Pulie63eeda2019-07-05 16:25:38 +053041 server.add_interface(objPath, "xyz.openbmc_project.Software.Version");
AppaRao Pulie4e95652019-07-19 16:52:01 +053042 versionIface->register_property("Purpose", purpose);
43 versionIface->register_property(
44 versionStr, version,
45 // Override set
46 [this](const std::string &req, std::string &propertyValue) {
47 if (internalSet)
48 {
49 if (req != propertyValue)
50 {
51 version = req;
52 propertyValue = req;
53 return 1;
54 }
55 }
56 return 0;
57 });
AppaRao Pulie63eeda2019-07-05 16:25:38 +053058
AppaRao Pulie4e95652019-07-19 16:52:01 +053059 versionIface->initialize();
AppaRao Pulid6f46c42019-07-19 22:34:04 +053060
AppaRao Puli916d6002019-12-18 01:37:02 +053061 std::string activation =
62 "xyz.openbmc_project.Software.Activation.Activations.StandbySpare";
63
64 if ((imgType == ImageType::bmcActive) ||
65 (imgType == ImageType::biosActive) ||
66 (imgType == ImageType::cpldActive))
Vikram Bodireddy0fd4dde2019-12-06 15:48:00 +053067 {
AppaRao Puli916d6002019-12-18 01:37:02 +053068 // Running images so set Activations to "Active"
Vikram Bodireddy0fd4dde2019-12-06 15:48:00 +053069 activation =
70 "xyz.openbmc_project.Software.Activation.Activations.Active";
AppaRao Puli916d6002019-12-18 01:37:02 +053071
AppaRao Puli0e758912020-01-29 03:07:54 +053072 // For all Active images, functional endpoints must be added. This is
73 // used in bmcweb & ipmi for fetching active component versions.
74
75 // TODO: We have redundant active firmware version objects for BMC
76 // and BIOS active images. BMC version is read from /etc/os-release
77 // BIOS version is read from SMBIOS. Since it provides more
78 // version information, Lets expose those as functional.
79 // Down the line, Redundant inventory objects need to be addressed.
80 if (imgType == ImageType::cpldActive)
81 {
82 associations.emplace("functional", "software_version", objPath);
83 }
Vikram Bodireddy0fd4dde2019-12-06 15:48:00 +053084 }
85
AppaRao Pulid6f46c42019-07-19 22:34:04 +053086 std::string reqActNone =
87 "xyz.openbmc_project.Software.Activation.RequestedActivations.None";
88 auto activationIface = server.add_interface(
89 objPath, "xyz.openbmc_project.Software.Activation");
90 activationIface->register_property("Activation", activation);
91 activationIface->register_property("RequestedActivation", reqActNone);
92
93 activationIface->initialize();
AppaRao Puli0e758912020-01-29 03:07:54 +053094
95 // All the components exposed under PFR.Manager are updateable.
96 // Lets add objPath endpoints to 'updatable' association
97 associations.emplace("updateable", "software_version", objPath);
98 associationIface->set_property("Associations", associations);
AppaRao Pulie63eeda2019-07-05 16:25:38 +053099}
100
AppaRao Pulie4e95652019-07-19 16:52:01 +0530101void PfrVersion::updateVersion()
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530102{
AppaRao Pulie4e95652019-07-19 16:52:01 +0530103 if (versionIface && versionIface->is_initialized())
104 {
AppaRao Puli4b639a22019-10-01 18:12:59 +0530105 std::string ver = getFirmwareVersion(imgType);
AppaRao Pulie4e95652019-07-19 16:52:01 +0530106 internalSet = true;
107 versionIface->set_property(versionStr, ver);
108 internalSet = false;
109 }
110 return;
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530111}
112
113PfrConfig::PfrConfig(sdbusplus::asio::object_server &srv_,
114 std::shared_ptr<sdbusplus::asio::connection> &conn_) :
115 server(srv_),
116 conn(conn_)
117{
AppaRao Pulicc1ed682019-10-01 12:29:40 +0530118 pfrCfgIface = server.add_interface("/xyz/openbmc_project/pfr",
119 "xyz.openbmc_project.PFR.Attributes");
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530120
AppaRao Pulie4e95652019-07-19 16:52:01 +0530121 getProvisioningStatus(ufmLocked, ufmProvisioned);
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530122
AppaRao Pulie4e95652019-07-19 16:52:01 +0530123 pfrCfgIface->register_property(ufmProvisionedStr, ufmProvisioned,
124 // Override set
125 [this](const bool req, bool propertyValue) {
126 if (internalSet)
127 {
128 if (req != propertyValue)
129 {
130 ufmProvisioned = req;
131 propertyValue = req;
132 return 1;
133 }
134 }
135 return 0;
136 });
137
138 pfrCfgIface->register_property(ufmLockedStr, ufmLocked,
139 // Override set
140 [this](const bool req, bool propertyValue) {
141 if (internalSet)
142 {
143 if (req != propertyValue)
144 {
145 ufmLocked = req;
146 propertyValue = req;
147 return 1;
148 }
149 }
150 return 0;
151 });
152
153 pfrCfgIface->initialize();
AppaRao Puli0e758912020-01-29 03:07:54 +0530154
155 associationIface =
156 server.add_interface("/xyz/openbmc_project/software",
157 "xyz.openbmc_project.Association.Definitions");
158 associationIface->register_property("Associations", associations);
159 associationIface->initialize();
AppaRao Pulie4e95652019-07-19 16:52:01 +0530160}
161
162void PfrConfig::updateProvisioningStatus()
163{
164 if (pfrCfgIface && pfrCfgIface->is_initialized())
165 {
166 bool lockVal = false;
167 bool provVal = false;
168 getProvisioningStatus(lockVal, provVal);
169 internalSet = true;
170 pfrCfgIface->set_property(ufmProvisionedStr, provVal);
171 pfrCfgIface->set_property(ufmLockedStr, lockVal);
172 internalSet = false;
173 }
174 return;
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530175}
176
177} // namespace pfr
178} // namespace intel