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