AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 1 | /* |
| 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 Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 18 | |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 19 | namespace pfr |
| 20 | { |
| 21 | |
| 22 | static constexpr uint8_t activeImage = 0; |
| 23 | static constexpr uint8_t recoveryImage = 1; |
| 24 | |
AppaRao Puli | 0e75891 | 2020-01-29 03:07:54 +0530 | [diff] [blame] | 25 | std::shared_ptr<sdbusplus::asio::dbus_interface> associationIface; |
| 26 | std::set<std::tuple<std::string, std::string, std::string>> associations; |
| 27 | |
AppaRao Puli | 67d184c | 2020-05-29 00:48:33 +0530 | [diff] [blame] | 28 | PfrVersion::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 Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 32 | server(srv_), |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 33 | conn(conn_), path(path_), imgType(imgType_), purpose(purpose_) |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 34 | { |
AppaRao Puli | 4b639a2 | 2019-10-01 18:12:59 +0530 | [diff] [blame] | 35 | version = getFirmwareVersion(imgType); |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 36 | |
| 37 | std::string objPath = "/xyz/openbmc_project/software/" + path; |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 38 | versionIface = |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 39 | server.add_interface(objPath, "xyz.openbmc_project.Software.Version"); |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 40 | versionIface->register_property("Purpose", purpose); |
| 41 | versionIface->register_property( |
| 42 | versionStr, version, |
| 43 | // Override set |
AppaRao Puli | 67d184c | 2020-05-29 00:48:33 +0530 | [diff] [blame] | 44 | [this](const std::string& req, std::string& propertyValue) { |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 45 | if (internalSet) |
| 46 | { |
| 47 | if (req != propertyValue) |
| 48 | { |
| 49 | version = req; |
| 50 | propertyValue = req; |
| 51 | return 1; |
| 52 | } |
| 53 | } |
| 54 | return 0; |
| 55 | }); |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 56 | |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 57 | versionIface->initialize(); |
AppaRao Puli | d6f46c4 | 2019-07-19 22:34:04 +0530 | [diff] [blame] | 58 | |
AppaRao Puli | 916d600 | 2019-12-18 01:37:02 +0530 | [diff] [blame] | 59 | std::string activation = |
| 60 | "xyz.openbmc_project.Software.Activation.Activations.StandbySpare"; |
| 61 | |
| 62 | if ((imgType == ImageType::bmcActive) || |
| 63 | (imgType == ImageType::biosActive) || |
Vikram Bodireddy | 8292dc6 | 2021-05-26 13:31:47 +0530 | [diff] [blame] | 64 | (imgType == ImageType::cpldActive) || (imgType == ImageType::afmActive)) |
Vikram Bodireddy | 0fd4dde | 2019-12-06 15:48:00 +0530 | [diff] [blame] | 65 | { |
AppaRao Puli | 916d600 | 2019-12-18 01:37:02 +0530 | [diff] [blame] | 66 | // Running images so set Activations to "Active" |
Vikram Bodireddy | 0fd4dde | 2019-12-06 15:48:00 +0530 | [diff] [blame] | 67 | activation = |
| 68 | "xyz.openbmc_project.Software.Activation.Activations.Active"; |
AppaRao Puli | 916d600 | 2019-12-18 01:37:02 +0530 | [diff] [blame] | 69 | |
AppaRao Puli | 0e75891 | 2020-01-29 03:07:54 +0530 | [diff] [blame] | 70 | // 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. |
Vikram Bodireddy | 8292dc6 | 2021-05-26 13:31:47 +0530 | [diff] [blame] | 78 | if ((imgType == ImageType::cpldActive) || |
| 79 | (imgType == ImageType::afmActive)) |
AppaRao Puli | 0e75891 | 2020-01-29 03:07:54 +0530 | [diff] [blame] | 80 | { |
| 81 | associations.emplace("functional", "software_version", objPath); |
| 82 | } |
Vikram Bodireddy | 0fd4dde | 2019-12-06 15:48:00 +0530 | [diff] [blame] | 83 | } |
| 84 | |
AppaRao Puli | d6f46c4 | 2019-07-19 22:34:04 +0530 | [diff] [blame] | 85 | std::string reqActNone = |
| 86 | "xyz.openbmc_project.Software.Activation.RequestedActivations.None"; |
| 87 | auto activationIface = server.add_interface( |
| 88 | objPath, "xyz.openbmc_project.Software.Activation"); |
| 89 | activationIface->register_property("Activation", activation); |
| 90 | activationIface->register_property("RequestedActivation", reqActNone); |
| 91 | |
| 92 | activationIface->initialize(); |
AppaRao Puli | 0e75891 | 2020-01-29 03:07:54 +0530 | [diff] [blame] | 93 | |
| 94 | // All the components exposed under PFR.Manager are updateable. |
| 95 | // Lets add objPath endpoints to 'updatable' association |
| 96 | associations.emplace("updateable", "software_version", objPath); |
| 97 | associationIface->set_property("Associations", associations); |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 98 | } |
| 99 | |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 100 | void PfrVersion::updateVersion() |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 101 | { |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 102 | if (versionIface && versionIface->is_initialized()) |
| 103 | { |
AppaRao Puli | 4b639a2 | 2019-10-01 18:12:59 +0530 | [diff] [blame] | 104 | std::string ver = getFirmwareVersion(imgType); |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 105 | internalSet = true; |
| 106 | versionIface->set_property(versionStr, ver); |
| 107 | internalSet = false; |
| 108 | } |
| 109 | return; |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 110 | } |
| 111 | |
AppaRao Puli | 67d184c | 2020-05-29 00:48:33 +0530 | [diff] [blame] | 112 | PfrConfig::PfrConfig(sdbusplus::asio::object_server& srv_, |
| 113 | std::shared_ptr<sdbusplus::asio::connection>& conn_) : |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 114 | server(srv_), |
| 115 | conn(conn_) |
| 116 | { |
AppaRao Puli | cc1ed68 | 2019-10-01 12:29:40 +0530 | [diff] [blame] | 117 | pfrCfgIface = server.add_interface("/xyz/openbmc_project/pfr", |
| 118 | "xyz.openbmc_project.PFR.Attributes"); |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 119 | |
Chalapathi Venkataramashetty | f881970 | 2021-02-03 09:43:46 +0000 | [diff] [blame] | 120 | ufmLocked = false; |
| 121 | ufmProvisioned = false; |
| 122 | ufmSupport = false; |
| 123 | getProvisioningStatus(ufmLocked, ufmProvisioned, ufmSupport); |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 124 | |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 125 | pfrCfgIface->register_property(ufmProvisionedStr, ufmProvisioned, |
| 126 | // Override set |
| 127 | [this](const bool req, bool propertyValue) { |
| 128 | if (internalSet) |
| 129 | { |
| 130 | if (req != propertyValue) |
| 131 | { |
| 132 | ufmProvisioned = req; |
| 133 | propertyValue = req; |
| 134 | return 1; |
| 135 | } |
| 136 | } |
| 137 | return 0; |
| 138 | }); |
| 139 | |
| 140 | pfrCfgIface->register_property(ufmLockedStr, ufmLocked, |
| 141 | // Override set |
| 142 | [this](const bool req, bool propertyValue) { |
| 143 | if (internalSet) |
| 144 | { |
| 145 | if (req != propertyValue) |
| 146 | { |
| 147 | ufmLocked = req; |
| 148 | propertyValue = req; |
| 149 | return 1; |
| 150 | } |
| 151 | } |
| 152 | return 0; |
| 153 | }); |
| 154 | |
Chalapathi Venkataramashetty | f881970 | 2021-02-03 09:43:46 +0000 | [diff] [blame] | 155 | pfrCfgIface->register_property(ufmSupportStr, ufmSupport, |
| 156 | // Override set |
| 157 | [this](const bool req, bool propertyValue) { |
| 158 | if (internalSet) |
| 159 | { |
| 160 | if (req != propertyValue) |
| 161 | { |
| 162 | ufmSupport = req; |
| 163 | propertyValue = req; |
| 164 | return 1; |
| 165 | } |
| 166 | } |
| 167 | return 0; |
| 168 | }); |
| 169 | |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 170 | pfrCfgIface->initialize(); |
AppaRao Puli | 0e75891 | 2020-01-29 03:07:54 +0530 | [diff] [blame] | 171 | |
| 172 | associationIface = |
| 173 | server.add_interface("/xyz/openbmc_project/software", |
| 174 | "xyz.openbmc_project.Association.Definitions"); |
| 175 | associationIface->register_property("Associations", associations); |
| 176 | associationIface->initialize(); |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | void PfrConfig::updateProvisioningStatus() |
| 180 | { |
| 181 | if (pfrCfgIface && pfrCfgIface->is_initialized()) |
| 182 | { |
| 183 | bool lockVal = false; |
| 184 | bool provVal = false; |
Chalapathi Venkataramashetty | f881970 | 2021-02-03 09:43:46 +0000 | [diff] [blame] | 185 | bool supportVal = false; |
| 186 | getProvisioningStatus(lockVal, provVal, supportVal); |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 187 | internalSet = true; |
| 188 | pfrCfgIface->set_property(ufmProvisionedStr, provVal); |
| 189 | pfrCfgIface->set_property(ufmLockedStr, lockVal); |
Chalapathi Venkataramashetty | f881970 | 2021-02-03 09:43:46 +0000 | [diff] [blame] | 190 | pfrCfgIface->set_property(ufmSupportStr, supportVal); |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 191 | internalSet = false; |
| 192 | } |
| 193 | return; |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | } // namespace pfr |