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" |
| 18 | #include "pfr.hpp" |
| 19 | |
| 20 | namespace intel |
| 21 | { |
| 22 | namespace pfr |
| 23 | { |
| 24 | |
| 25 | static constexpr uint8_t activeImage = 0; |
| 26 | static constexpr uint8_t recoveryImage = 1; |
| 27 | |
| 28 | PfrVersion::PfrVersion(sdbusplus::asio::object_server &srv_, |
| 29 | std::shared_ptr<sdbusplus::asio::connection> &conn_, |
| 30 | const std::string &path_) : |
| 31 | server(srv_), |
| 32 | conn(conn_), path(path_) |
| 33 | { |
| 34 | if (path == "bmc_active") |
| 35 | { |
| 36 | purpose = "xyz.openbmc_project.Software.Version.VersionPurpose.BMC"; |
| 37 | ImageType imgType = ImageType::bmcActive; |
| 38 | version = getVersionInfoCPLD(imgType); |
| 39 | } |
| 40 | else if (path == "bmc_recovery") |
| 41 | { |
| 42 | purpose = "xyz.openbmc_project.Software.Version.VersionPurpose.BMC"; |
| 43 | ImageType imgType = ImageType::bmcRecovery; |
| 44 | version = getVersionInfoCPLD(imgType); |
| 45 | } |
| 46 | else if (path == "bios_active") |
| 47 | { |
| 48 | purpose = "xyz.openbmc_project.Software.Version.VersionPurpose.Host"; |
| 49 | ImageType imgType = ImageType::biosActive; |
| 50 | version = getVersionInfoCPLD(imgType); |
| 51 | } |
| 52 | else if (path == "bios_recovery") |
| 53 | { |
| 54 | purpose = "xyz.openbmc_project.Software.Version.VersionPurpose.Host"; |
| 55 | ImageType imgType = ImageType::biosRecovery; |
| 56 | version = getVersionInfoCPLD(imgType); |
| 57 | } |
| 58 | else if (path == "cpld") |
| 59 | { |
| 60 | purpose = "xyz.openbmc_project.Software.Version.VersionPurpose.Other"; |
| 61 | ImageType imgType = ImageType::cpld; |
| 62 | version = getVersionInfoCPLD(imgType); |
| 63 | } |
| 64 | else |
| 65 | { |
| 66 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 67 | "Invalid path specified for PfrVersion"); |
| 68 | return; |
| 69 | } |
| 70 | |
| 71 | std::string objPath = "/xyz/openbmc_project/software/" + path; |
| 72 | auto iface = |
| 73 | server.add_interface(objPath, "xyz.openbmc_project.Software.Version"); |
| 74 | iface->register_property("Purpose", purpose); |
| 75 | iface->register_property("Version", version); |
| 76 | |
| 77 | iface->initialize(); |
AppaRao Puli | d6f46c4 | 2019-07-19 22:34:04 +0530 | [diff] [blame^] | 78 | |
| 79 | /* Activation interface represents activation state for an associated |
| 80 | * xyz.openbmc_project.Software.Version. since these versions are already |
| 81 | * active, so we should set "activation" to Active and |
| 82 | * "RequestedActivation" to None. */ |
| 83 | std::string activation = |
| 84 | "xyz.openbmc_project.Software.Activation.Activations.Active"; |
| 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 | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | bool PfrConfig::getPFRProvisionedState() |
| 96 | { |
| 97 | bool ufmProvisioned = false; |
| 98 | bool ufmLocked = false; |
| 99 | getProvisioningStatus(ufmLocked, ufmProvisioned); |
| 100 | |
| 101 | return ufmProvisioned; |
| 102 | } |
| 103 | |
| 104 | PfrConfig::PfrConfig(sdbusplus::asio::object_server &srv_, |
| 105 | std::shared_ptr<sdbusplus::asio::connection> &conn_) : |
| 106 | server(srv_), |
| 107 | conn(conn_) |
| 108 | { |
| 109 | auto pfrIntf = |
| 110 | server.add_interface("/xyz/openbmc_project/intel_pfr", |
| 111 | "xyz.openbmc_project.Intel_PFR.Attributes"); |
| 112 | |
| 113 | pfrIntf->register_property("provisioned_state", getPFRProvisionedState()); |
| 114 | |
| 115 | pfrIntf->initialize(); |
| 116 | } |
| 117 | |
| 118 | } // namespace pfr |
| 119 | } // namespace intel |