| 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 | #pragma once | 
|  | 18 |  | 
| AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 19 | #include "pfr.hpp" | 
|  | 20 |  | 
| AppaRao Puli | 67d184c | 2020-05-29 00:48:33 +0530 | [diff] [blame] | 21 | #include <boost/asio.hpp> | 
| Jason M. Bills | 7010844 | 2022-09-21 12:32:16 -0700 | [diff] [blame^] | 22 | #include <boost/container/flat_map.hpp> | 
| Alex Schendel | 5cf320c | 2021-12-09 12:11:04 -0800 | [diff] [blame] | 23 | #include <phosphor-logging/lg2.hpp> | 
| AppaRao Puli | 67d184c | 2020-05-29 00:48:33 +0530 | [diff] [blame] | 24 | #include <phosphor-logging/log.hpp> | 
|  | 25 | #include <sdbusplus/asio/object_server.hpp> | 
|  | 26 |  | 
|  | 27 | #include <string> | 
|  | 28 |  | 
| AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 29 | namespace pfr | 
|  | 30 | { | 
|  | 31 |  | 
| AppaRao Puli | 67d184c | 2020-05-29 00:48:33 +0530 | [diff] [blame] | 32 | static constexpr const char* versionPurposeBMC = | 
| AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 33 | "xyz.openbmc_project.Software.Version.VersionPurpose.BMC"; | 
| AppaRao Puli | 67d184c | 2020-05-29 00:48:33 +0530 | [diff] [blame] | 34 | static constexpr const char* versionPurposeHost = | 
| AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 35 | "xyz.openbmc_project.Software.Version.VersionPurpose.Host"; | 
| AppaRao Puli | 67d184c | 2020-05-29 00:48:33 +0530 | [diff] [blame] | 36 | static constexpr const char* versionPurposeOther = | 
| AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 37 | "xyz.openbmc_project.Software.Version.VersionPurpose.Other"; | 
|  | 38 |  | 
| AppaRao Puli | 67d184c | 2020-05-29 00:48:33 +0530 | [diff] [blame] | 39 | static constexpr const char* versionStr = "Version"; | 
|  | 40 | static constexpr const char* ufmProvisionedStr = "UfmProvisioned"; | 
|  | 41 | static constexpr const char* ufmLockedStr = "UfmLocked"; | 
| Chalapathi Venkataramashetty | f881970 | 2021-02-03 09:43:46 +0000 | [diff] [blame] | 42 | static constexpr const char* ufmSupportStr = "UfmSupport"; | 
| AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 43 |  | 
| AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 44 | class PfrVersion | 
|  | 45 | { | 
|  | 46 | public: | 
| AppaRao Puli | 67d184c | 2020-05-29 00:48:33 +0530 | [diff] [blame] | 47 | PfrVersion(sdbusplus::asio::object_server& srv_, | 
|  | 48 | std::shared_ptr<sdbusplus::asio::connection>& conn_, | 
|  | 49 | const std::string& path_, const ImageType& imgType_, | 
|  | 50 | const std::string& purpose_); | 
| AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 51 | ~PfrVersion() = default; | 
|  | 52 |  | 
|  | 53 | std::shared_ptr<sdbusplus::asio::connection> conn; | 
|  | 54 |  | 
| AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 55 | void updateVersion(); | 
|  | 56 |  | 
| AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 57 | private: | 
| AppaRao Puli | 67d184c | 2020-05-29 00:48:33 +0530 | [diff] [blame] | 58 | sdbusplus::asio::object_server& server; | 
| AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 59 | std::shared_ptr<sdbusplus::asio::dbus_interface> versionIface; | 
|  | 60 | bool internalSet = false; | 
| AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 61 |  | 
|  | 62 | std::string path; | 
|  | 63 | std::string version; | 
|  | 64 | std::string purpose; | 
| AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 65 | ImageType imgType; | 
| AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 66 | }; | 
|  | 67 |  | 
|  | 68 | class PfrConfig | 
|  | 69 | { | 
|  | 70 | public: | 
| AppaRao Puli | 67d184c | 2020-05-29 00:48:33 +0530 | [diff] [blame] | 71 | PfrConfig(sdbusplus::asio::object_server& srv_, | 
|  | 72 | std::shared_ptr<sdbusplus::asio::connection>& conn_); | 
| AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 73 | ~PfrConfig() = default; | 
|  | 74 |  | 
|  | 75 | std::shared_ptr<sdbusplus::asio::connection> conn; | 
|  | 76 |  | 
| AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 77 | void updateProvisioningStatus(); | 
|  | 78 |  | 
| Zhikui Ren | c96f37d | 2021-12-08 15:40:51 -0800 | [diff] [blame] | 79 | bool getPfrProvisioned() const | 
|  | 80 | { | 
|  | 81 | return ufmProvisioned; | 
|  | 82 | } | 
|  | 83 |  | 
| AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 84 | private: | 
| AppaRao Puli | 67d184c | 2020-05-29 00:48:33 +0530 | [diff] [blame] | 85 | sdbusplus::asio::object_server& server; | 
| AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 86 | std::shared_ptr<sdbusplus::asio::dbus_interface> pfrCfgIface; | 
|  | 87 | bool internalSet = false; | 
| AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 88 |  | 
| AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 89 | bool ufmProvisioned; | 
|  | 90 | bool ufmLocked; | 
| Chalapathi Venkataramashetty | f881970 | 2021-02-03 09:43:46 +0000 | [diff] [blame] | 91 | bool ufmSupport; | 
| AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 92 | }; | 
|  | 93 |  | 
| Chalapathi Venkataramashetty | bcc7ce1 | 2021-05-17 04:27:21 +0000 | [diff] [blame] | 94 | // Firmware resiliency major map. | 
|  | 95 | // {<CPLD association>, {<Redfish MessageID>, <Error reason> }) | 
|  | 96 | static const boost::container::flat_map<uint8_t, | 
|  | 97 | std::pair<std::string, std::string>> | 
|  | 98 | majorErrorCodeMapRev2 = { | 
|  | 99 | {0x03, {"FirmwareResiliencyError", "Firmware update failed"}}}; | 
|  | 100 |  | 
| Zhikui Ren | c96f37d | 2021-12-08 15:40:51 -0800 | [diff] [blame] | 101 | // postcode (platform state) map. | 
|  | 102 | static const boost::container::flat_map<uint8_t, std::string> postcodeMap = { | 
|  | 103 | {0x00, "Postcode unavailable"}, | 
|  | 104 | {0x01, "CPLD Nios II processor waiting to start"}, | 
|  | 105 | {0x02, "CPLD Nios II processor started"}, | 
|  | 106 | {0x03, "Enter T-1"}, | 
|  | 107 | {0x04, "T-1 reserved 4"}, | 
|  | 108 | {0x05, "T-1 Reserved 5"}, | 
|  | 109 | {0x06, "BMC flash authentication"}, | 
|  | 110 | {0x07, "PCH/CPU flash authentication"}, | 
|  | 111 | {0x08, "Lockdown due to authentication failures"}, | 
|  | 112 | {0x09, "Enter T0"}, | 
|  | 113 | {0x0A, "T0 BMC booted"}, | 
|  | 114 | {0x0B, "T0 ME booted"}, | 
|  | 115 | {0x0C, "T0 Modular booted"}, | 
|  | 116 | {0x0C, "T0 BIOS booted"}, | 
|  | 117 | {0x0E, "T0 boot complete"}, | 
|  | 118 | {0x0F, "T0 Reserved 0xF"}, | 
|  | 119 | {0x10, "PCH/CPU firmware update"}, | 
|  | 120 | {0x11, "BMC firmware update"}, | 
|  | 121 | {0x12, "CPLD update (in CPLD Active Image)"}, | 
|  | 122 | {0x13, "CPLD update (in CPLD ROM)"}, | 
|  | 123 | {0x14, "PCH/CPU firmware volume update"}, | 
|  | 124 | {0x15, "CPLD Nios II processor waiting to start"}, | 
|  | 125 | {0x16, "Reserved 0x16"}, | 
|  | 126 | {0x40, "T-1 firmware recovery due to authentication failure"}, | 
|  | 127 | {0x41, "T-1 forced active firmware recovery"}, | 
|  | 128 | {0x42, "WDT timeout recovery"}, | 
|  | 129 | {0x43, "CPLD recovery (in CPLD ROM)"}, | 
|  | 130 | {0x44, "Lockdown due to PIT L1"}, | 
|  | 131 | {0x45, "PIT L2 firmware sealed"}, | 
|  | 132 | {0x46, "Lockdown due to PIT L2 PCH/CPU firmware hash mismatch"}, | 
|  | 133 | {0x47, "Lockdown due to PIT L2 BMC firmware hash mismatch"}, | 
|  | 134 | {0x48, "Reserved 0x48"}}; | 
|  | 135 |  | 
|  | 136 | class PfrPostcode | 
|  | 137 | { | 
|  | 138 | public: | 
|  | 139 | PfrPostcode(sdbusplus::asio::object_server& srv_, | 
|  | 140 | std::shared_ptr<sdbusplus::asio::connection>& conn_); | 
|  | 141 | ~PfrPostcode() = default; | 
|  | 142 |  | 
|  | 143 | std::shared_ptr<sdbusplus::asio::connection> conn; | 
|  | 144 |  | 
|  | 145 | void updatePostcode(); | 
|  | 146 |  | 
|  | 147 | private: | 
|  | 148 | sdbusplus::asio::object_server& server; | 
|  | 149 | std::shared_ptr<sdbusplus::asio::dbus_interface> pfrPostcodeIface; | 
|  | 150 | bool internalSet = false; | 
|  | 151 | uint8_t postcode; | 
|  | 152 | }; | 
|  | 153 |  | 
| AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 154 | } // namespace pfr |