blob: b7739167beeb1c27e12f11aa51609e9beeff0edc [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
58 /* Activation interface represents activation state for an associated
59 * xyz.openbmc_project.Software.Version. since these versions are already
60 * active, so we should set "activation" to Active and
61 * "RequestedActivation" to None. */
Vikram Bodireddy0fd4dde2019-12-06 15:48:00 +053062 std::string activation;
63 if (imgType == ImageType::bmcRecovery ||
64 imgType == ImageType::biosRecovery ||
65 imgType == ImageType::cpldRecovery)
66 {
67 activation =
68 "xyz.openbmc_project.Software.Activation.Activations.StandbySpare";
69 }
70 else
71 {
72 activation =
73 "xyz.openbmc_project.Software.Activation.Activations.Active";
74 }
75
AppaRao Pulid6f46c42019-07-19 22:34:04 +053076 std::string reqActNone =
77 "xyz.openbmc_project.Software.Activation.RequestedActivations.None";
78 auto activationIface = server.add_interface(
79 objPath, "xyz.openbmc_project.Software.Activation");
80 activationIface->register_property("Activation", activation);
81 activationIface->register_property("RequestedActivation", reqActNone);
82
83 activationIface->initialize();
AppaRao Pulie63eeda2019-07-05 16:25:38 +053084}
85
AppaRao Pulie4e95652019-07-19 16:52:01 +053086void PfrVersion::updateVersion()
AppaRao Pulie63eeda2019-07-05 16:25:38 +053087{
AppaRao Pulie4e95652019-07-19 16:52:01 +053088 if (versionIface && versionIface->is_initialized())
89 {
AppaRao Puli4b639a22019-10-01 18:12:59 +053090 std::string ver = getFirmwareVersion(imgType);
AppaRao Pulie4e95652019-07-19 16:52:01 +053091 internalSet = true;
92 versionIface->set_property(versionStr, ver);
93 internalSet = false;
94 }
95 return;
AppaRao Pulie63eeda2019-07-05 16:25:38 +053096}
97
98PfrConfig::PfrConfig(sdbusplus::asio::object_server &srv_,
99 std::shared_ptr<sdbusplus::asio::connection> &conn_) :
100 server(srv_),
101 conn(conn_)
102{
AppaRao Pulicc1ed682019-10-01 12:29:40 +0530103 pfrCfgIface = server.add_interface("/xyz/openbmc_project/pfr",
104 "xyz.openbmc_project.PFR.Attributes");
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530105
AppaRao Pulie4e95652019-07-19 16:52:01 +0530106 getProvisioningStatus(ufmLocked, ufmProvisioned);
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530107
AppaRao Pulie4e95652019-07-19 16:52:01 +0530108 pfrCfgIface->register_property(ufmProvisionedStr, ufmProvisioned,
109 // Override set
110 [this](const bool req, bool propertyValue) {
111 if (internalSet)
112 {
113 if (req != propertyValue)
114 {
115 ufmProvisioned = req;
116 propertyValue = req;
117 return 1;
118 }
119 }
120 return 0;
121 });
122
123 pfrCfgIface->register_property(ufmLockedStr, ufmLocked,
124 // Override set
125 [this](const bool req, bool propertyValue) {
126 if (internalSet)
127 {
128 if (req != propertyValue)
129 {
130 ufmLocked = req;
131 propertyValue = req;
132 return 1;
133 }
134 }
135 return 0;
136 });
137
138 pfrCfgIface->initialize();
139}
140
141void PfrConfig::updateProvisioningStatus()
142{
143 if (pfrCfgIface && pfrCfgIface->is_initialized())
144 {
145 bool lockVal = false;
146 bool provVal = false;
147 getProvisioningStatus(lockVal, provVal);
148 internalSet = true;
149 pfrCfgIface->set_property(ufmProvisionedStr, provVal);
150 pfrCfgIface->set_property(ufmLockedStr, lockVal);
151 internalSet = false;
152 }
153 return;
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530154}
155
156} // namespace pfr
157} // namespace intel