blob: c954f9605559275b03dc84a0bce7579022395d18 [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
27PfrVersion::PfrVersion(sdbusplus::asio::object_server &srv_,
28 std::shared_ptr<sdbusplus::asio::connection> &conn_,
AppaRao Pulie4e95652019-07-19 16:52:01 +053029 const std::string &path_, const ImageType &imgType_,
30 const std::string &purpose_) :
AppaRao Pulie63eeda2019-07-05 16:25:38 +053031 server(srv_),
AppaRao Pulie4e95652019-07-19 16:52:01 +053032 conn(conn_), path(path_), imgType(imgType_), purpose(purpose_)
AppaRao Pulie63eeda2019-07-05 16:25:38 +053033{
AppaRao Puli4b639a22019-10-01 18:12:59 +053034 version = getFirmwareVersion(imgType);
AppaRao Pulie63eeda2019-07-05 16:25:38 +053035
36 std::string objPath = "/xyz/openbmc_project/software/" + path;
AppaRao Pulie4e95652019-07-19 16:52:01 +053037 versionIface =
AppaRao Pulie63eeda2019-07-05 16:25:38 +053038 server.add_interface(objPath, "xyz.openbmc_project.Software.Version");
AppaRao Pulie4e95652019-07-19 16:52:01 +053039 versionIface->register_property("Purpose", purpose);
40 versionIface->register_property(
41 versionStr, version,
42 // Override set
43 [this](const std::string &req, std::string &propertyValue) {
44 if (internalSet)
45 {
46 if (req != propertyValue)
47 {
48 version = req;
49 propertyValue = req;
50 return 1;
51 }
52 }
53 return 0;
54 });
AppaRao Pulie63eeda2019-07-05 16:25:38 +053055
AppaRao Pulie4e95652019-07-19 16:52:01 +053056 versionIface->initialize();
AppaRao Pulid6f46c42019-07-19 22:34:04 +053057
AppaRao Puli916d6002019-12-18 01:37:02 +053058 std::string activation =
59 "xyz.openbmc_project.Software.Activation.Activations.StandbySpare";
60
61 if ((imgType == ImageType::bmcActive) ||
62 (imgType == ImageType::biosActive) ||
63 (imgType == ImageType::cpldActive))
Vikram Bodireddy0fd4dde2019-12-06 15:48:00 +053064 {
AppaRao Puli916d6002019-12-18 01:37:02 +053065 // Running images so set Activations to "Active"
Vikram Bodireddy0fd4dde2019-12-06 15:48:00 +053066 activation =
67 "xyz.openbmc_project.Software.Activation.Activations.Active";
AppaRao Puli916d6002019-12-18 01:37:02 +053068
69 /* For all Active images, functional endpoints must be added. This *
70 * will be used in bmcweb for showing active component versions. */
71 using Association = std::tuple<std::string, std::string, std::string>;
72 std::vector<Association> associations;
73 associations.push_back(
74 Association("functional", "software_version", objPath));
75 auto associationsIface =
76 server.add_interface("/xyz/openbmc_project/software",
77 "xyz.openbmc_project.Association.Definitions");
78 associationsIface->register_property("Associations", associations);
79 associationsIface->initialize();
Vikram Bodireddy0fd4dde2019-12-06 15:48:00 +053080 }
81
AppaRao Pulid6f46c42019-07-19 22:34:04 +053082 std::string reqActNone =
83 "xyz.openbmc_project.Software.Activation.RequestedActivations.None";
84 auto activationIface = server.add_interface(
85 objPath, "xyz.openbmc_project.Software.Activation");
86 activationIface->register_property("Activation", activation);
87 activationIface->register_property("RequestedActivation", reqActNone);
88
89 activationIface->initialize();
AppaRao Pulie63eeda2019-07-05 16:25:38 +053090}
91
AppaRao Pulie4e95652019-07-19 16:52:01 +053092void PfrVersion::updateVersion()
AppaRao Pulie63eeda2019-07-05 16:25:38 +053093{
AppaRao Pulie4e95652019-07-19 16:52:01 +053094 if (versionIface && versionIface->is_initialized())
95 {
AppaRao Puli4b639a22019-10-01 18:12:59 +053096 std::string ver = getFirmwareVersion(imgType);
AppaRao Pulie4e95652019-07-19 16:52:01 +053097 internalSet = true;
98 versionIface->set_property(versionStr, ver);
99 internalSet = false;
100 }
101 return;
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530102}
103
104PfrConfig::PfrConfig(sdbusplus::asio::object_server &srv_,
105 std::shared_ptr<sdbusplus::asio::connection> &conn_) :
106 server(srv_),
107 conn(conn_)
108{
AppaRao Pulicc1ed682019-10-01 12:29:40 +0530109 pfrCfgIface = server.add_interface("/xyz/openbmc_project/pfr",
110 "xyz.openbmc_project.PFR.Attributes");
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530111
AppaRao Pulie4e95652019-07-19 16:52:01 +0530112 getProvisioningStatus(ufmLocked, ufmProvisioned);
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530113
AppaRao Pulie4e95652019-07-19 16:52:01 +0530114 pfrCfgIface->register_property(ufmProvisionedStr, ufmProvisioned,
115 // Override set
116 [this](const bool req, bool propertyValue) {
117 if (internalSet)
118 {
119 if (req != propertyValue)
120 {
121 ufmProvisioned = req;
122 propertyValue = req;
123 return 1;
124 }
125 }
126 return 0;
127 });
128
129 pfrCfgIface->register_property(ufmLockedStr, ufmLocked,
130 // Override set
131 [this](const bool req, bool propertyValue) {
132 if (internalSet)
133 {
134 if (req != propertyValue)
135 {
136 ufmLocked = req;
137 propertyValue = req;
138 return 1;
139 }
140 }
141 return 0;
142 });
143
144 pfrCfgIface->initialize();
145}
146
147void PfrConfig::updateProvisioningStatus()
148{
149 if (pfrCfgIface && pfrCfgIface->is_initialized())
150 {
151 bool lockVal = false;
152 bool provVal = false;
153 getProvisioningStatus(lockVal, provVal);
154 internalSet = true;
155 pfrCfgIface->set_property(ufmProvisionedStr, provVal);
156 pfrCfgIface->set_property(ufmLockedStr, lockVal);
157 internalSet = false;
158 }
159 return;
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530160}
161
162} // namespace pfr
163} // namespace intel