PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
Sunny Srivastava | 6c71c9d | 2021-04-15 04:43:54 -0500 | [diff] [blame] | 3 | #include "common_utility.hpp" |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 4 | #include "defines.hpp" |
Sunny Srivastava | 6c71c9d | 2021-04-15 04:43:54 -0500 | [diff] [blame] | 5 | #include "ibm_vpd_utils.hpp" |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 6 | #include "ipz_parser.hpp" |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 7 | #include "keyword_vpd_parser.hpp" |
Alpana Kumari | a00936f | 2020-04-14 07:15:46 -0500 | [diff] [blame] | 8 | #include "memory_vpd_parser.hpp" |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 9 | #include "parser_factory.hpp" |
SunnySrivastava1984 | a20be8e | 2020-08-26 02:00:50 -0500 | [diff] [blame] | 10 | #include "vpd_exceptions.hpp" |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 11 | |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 12 | #include <assert.h> |
Alpana Kumari | 8ea3f6d | 2020-04-02 00:26:07 -0500 | [diff] [blame] | 13 | #include <ctype.h> |
| 14 | |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 15 | #include <CLI/CLI.hpp> |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 16 | #include <algorithm> |
alpana07 | 7ce6872 | 2021-07-25 13:23:59 -0500 | [diff] [blame] | 17 | #include <boost/algorithm/string.hpp> |
Alpana Kumari | 65b8360 | 2020-09-01 00:24:56 -0500 | [diff] [blame] | 18 | #include <cstdarg> |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 19 | #include <exception> |
PriyangaRamasamy | 83a1d5d | 2020-04-30 19:15:43 +0530 | [diff] [blame] | 20 | #include <filesystem> |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 21 | #include <fstream> |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 22 | #include <gpiod.hpp> |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 23 | #include <iostream> |
| 24 | #include <iterator> |
Andrew Geissler | 280197e | 2020-12-08 20:51:49 -0600 | [diff] [blame] | 25 | #include <phosphor-logging/log.hpp> |
alpana07 | 7ce6872 | 2021-07-25 13:23:59 -0500 | [diff] [blame] | 26 | #include <regex> |
Santosh Puranik | 253fbe9 | 2022-10-06 22:38:09 +0530 | [diff] [blame] | 27 | #include <thread> |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 28 | |
| 29 | using namespace std; |
| 30 | using namespace openpower::vpd; |
| 31 | using namespace CLI; |
| 32 | using namespace vpd::keyword::parser; |
PriyangaRamasamy | 83a1d5d | 2020-04-30 19:15:43 +0530 | [diff] [blame] | 33 | using namespace openpower::vpd::constants; |
| 34 | namespace fs = filesystem; |
| 35 | using json = nlohmann::json; |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 36 | using namespace openpower::vpd::parser::factory; |
SunnySrivastava1984 | 945a02d | 2020-05-06 01:55:41 -0500 | [diff] [blame] | 37 | using namespace openpower::vpd::inventory; |
Alpana Kumari | a00936f | 2020-04-14 07:15:46 -0500 | [diff] [blame] | 38 | using namespace openpower::vpd::memory::parser; |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 39 | using namespace openpower::vpd::parser::interface; |
SunnySrivastava1984 | a20be8e | 2020-08-26 02:00:50 -0500 | [diff] [blame] | 40 | using namespace openpower::vpd::exceptions; |
Andrew Geissler | 280197e | 2020-12-08 20:51:49 -0600 | [diff] [blame] | 41 | using namespace phosphor::logging; |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 42 | |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 43 | /** |
Santosh Puranik | e9c5753 | 2022-03-15 16:51:51 +0530 | [diff] [blame] | 44 | * @brief Returns the BMC state |
| 45 | */ |
| 46 | static auto getBMCState() |
| 47 | { |
| 48 | std::string bmcState; |
| 49 | try |
| 50 | { |
| 51 | auto bus = sdbusplus::bus::new_default(); |
| 52 | auto properties = bus.new_method_call( |
| 53 | "xyz.openbmc_project.State.BMC", "/xyz/openbmc_project/state/bmc0", |
| 54 | "org.freedesktop.DBus.Properties", "Get"); |
| 55 | properties.append("xyz.openbmc_project.State.BMC"); |
| 56 | properties.append("CurrentBMCState"); |
| 57 | auto result = bus.call(properties); |
| 58 | std::variant<std::string> val; |
| 59 | result.read(val); |
| 60 | if (auto pVal = std::get_if<std::string>(&val)) |
| 61 | { |
| 62 | bmcState = *pVal; |
| 63 | } |
| 64 | } |
| 65 | catch (const sdbusplus::exception::SdBusError& e) |
| 66 | { |
| 67 | // Ignore any error |
| 68 | std::cerr << "Failed to get BMC state: " << e.what() << "\n"; |
| 69 | } |
| 70 | return bmcState; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * @brief Check if the FRU is in the cache |
| 75 | * |
| 76 | * Checks if the FRU associated with the supplied D-Bus object path is already |
| 77 | * on D-Bus. This can be used to test if a VPD collection is required for this |
| 78 | * FRU. It uses the "xyz.openbmc_project.Inventory.Item, Present" property to |
| 79 | * determine the presence of a FRU in the cache. |
| 80 | * |
| 81 | * @param objectPath - The D-Bus object path without the PIM prefix. |
| 82 | * @return true if the object exists on D-Bus, false otherwise. |
| 83 | */ |
| 84 | static auto isFruInVpdCache(const std::string& objectPath) |
| 85 | { |
| 86 | try |
| 87 | { |
| 88 | auto bus = sdbusplus::bus::new_default(); |
| 89 | auto invPath = std::string{pimPath} + objectPath; |
| 90 | auto props = bus.new_method_call( |
| 91 | "xyz.openbmc_project.Inventory.Manager", invPath.c_str(), |
| 92 | "org.freedesktop.DBus.Properties", "Get"); |
| 93 | props.append("xyz.openbmc_project.Inventory.Item"); |
| 94 | props.append("Present"); |
| 95 | auto result = bus.call(props); |
| 96 | std::variant<bool> present; |
| 97 | result.read(present); |
| 98 | if (auto pVal = std::get_if<bool>(&present)) |
| 99 | { |
| 100 | return *pVal; |
| 101 | } |
| 102 | return false; |
| 103 | } |
| 104 | catch (const sdbusplus::exception::SdBusError& e) |
| 105 | { |
| 106 | std::cout << "FRU: " << objectPath << " not in D-Bus\n"; |
| 107 | // Assume not present in case of an error |
| 108 | return false; |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * @brief Check if VPD recollection is needed for the given EEPROM |
| 114 | * |
| 115 | * Not all FRUs can be swapped at BMC ready state. This function does the |
| 116 | * following: |
| 117 | * -- Check if the FRU is marked as "pluggableAtStandby" OR |
| 118 | * "concurrentlyMaintainable". If so, return true. |
| 119 | * -- Check if we are at BMC NotReady state. If we are, then return true. |
| 120 | * -- Else check if the FRU is not present in the VPD cache (to cover for VPD |
| 121 | * force collection). If not found in the cache, return true. |
| 122 | * -- Else return false. |
| 123 | * |
| 124 | * @param js - JSON Object. |
| 125 | * @param filePath - The EEPROM file. |
| 126 | * @return true if collection should be attempted, false otherwise. |
| 127 | */ |
| 128 | static auto needsRecollection(const nlohmann::json& js, const string& filePath) |
| 129 | { |
| 130 | if (js["frus"][filePath].at(0).value("pluggableAtStandby", false) || |
| 131 | js["frus"][filePath].at(0).value("concurrentlyMaintainable", false)) |
| 132 | { |
| 133 | return true; |
| 134 | } |
| 135 | if (getBMCState() == "xyz.openbmc_project.State.BMC.BMCState.NotReady") |
| 136 | { |
| 137 | return true; |
| 138 | } |
| 139 | if (!isFruInVpdCache(js["frus"][filePath].at(0).value("inventoryPath", ""))) |
| 140 | { |
| 141 | return true; |
| 142 | } |
| 143 | return false; |
| 144 | } |
| 145 | |
| 146 | /** |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 147 | * @brief Expands location codes |
| 148 | */ |
| 149 | static auto expandLocationCode(const string& unexpanded, const Parsed& vpdMap, |
| 150 | bool isSystemVpd) |
| 151 | { |
| 152 | auto expanded{unexpanded}; |
| 153 | static constexpr auto SYSTEM_OBJECT = "/system/chassis/motherboard"; |
| 154 | static constexpr auto VCEN_IF = "com.ibm.ipzvpd.VCEN"; |
| 155 | static constexpr auto VSYS_IF = "com.ibm.ipzvpd.VSYS"; |
| 156 | size_t idx = expanded.find("fcs"); |
| 157 | try |
| 158 | { |
| 159 | if (idx != string::npos) |
| 160 | { |
| 161 | string fc{}; |
| 162 | string se{}; |
| 163 | if (isSystemVpd) |
| 164 | { |
| 165 | const auto& fcData = vpdMap.at("VCEN").at("FC"); |
| 166 | const auto& seData = vpdMap.at("VCEN").at("SE"); |
| 167 | fc = string(fcData.data(), fcData.size()); |
| 168 | se = string(seData.data(), seData.size()); |
| 169 | } |
| 170 | else |
| 171 | { |
| 172 | fc = readBusProperty(SYSTEM_OBJECT, VCEN_IF, "FC"); |
| 173 | se = readBusProperty(SYSTEM_OBJECT, VCEN_IF, "SE"); |
| 174 | } |
| 175 | |
Alpana Kumari | 81671f6 | 2021-02-10 02:21:59 -0600 | [diff] [blame] | 176 | // TODO: See if ND0 can be placed in the JSON |
| 177 | expanded.replace(idx, 3, fc.substr(0, 4) + ".ND0." + se); |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 178 | } |
| 179 | else |
| 180 | { |
| 181 | idx = expanded.find("mts"); |
| 182 | if (idx != string::npos) |
| 183 | { |
| 184 | string mt{}; |
| 185 | string se{}; |
| 186 | if (isSystemVpd) |
| 187 | { |
| 188 | const auto& mtData = vpdMap.at("VSYS").at("TM"); |
| 189 | const auto& seData = vpdMap.at("VSYS").at("SE"); |
| 190 | mt = string(mtData.data(), mtData.size()); |
| 191 | se = string(seData.data(), seData.size()); |
| 192 | } |
| 193 | else |
| 194 | { |
| 195 | mt = readBusProperty(SYSTEM_OBJECT, VSYS_IF, "TM"); |
| 196 | se = readBusProperty(SYSTEM_OBJECT, VSYS_IF, "SE"); |
| 197 | } |
| 198 | |
| 199 | replace(mt.begin(), mt.end(), '-', '.'); |
| 200 | expanded.replace(idx, 3, mt + "." + se); |
| 201 | } |
| 202 | } |
| 203 | } |
Patrick Williams | 8e15b93 | 2021-10-06 13:04:22 -0500 | [diff] [blame] | 204 | catch (const exception& e) |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 205 | { |
Alpana Kumari | 58e2214 | 2020-05-05 00:22:12 -0500 | [diff] [blame] | 206 | cerr << "Failed to expand location code with exception: " << e.what() |
| 207 | << "\n"; |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 208 | } |
| 209 | return expanded; |
| 210 | } |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 211 | |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 212 | /** |
| 213 | * @brief Populate FRU specific interfaces. |
| 214 | * |
| 215 | * This is a common method which handles both |
| 216 | * ipz and keyword specific interfaces thus, |
| 217 | * reducing the code redundancy. |
| 218 | * @param[in] map - Reference to the innermost keyword-value map. |
| 219 | * @param[in] preIntrStr - Reference to the interface string. |
| 220 | * @param[out] interfaces - Reference to interface map. |
| 221 | */ |
| 222 | template <typename T> |
| 223 | static void populateFruSpecificInterfaces(const T& map, |
| 224 | const string& preIntrStr, |
| 225 | inventory::InterfaceMap& interfaces) |
| 226 | { |
| 227 | inventory::PropertyMap prop; |
| 228 | |
| 229 | for (const auto& kwVal : map) |
| 230 | { |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 231 | auto kw = kwVal.first; |
| 232 | |
| 233 | if (kw[0] == '#') |
| 234 | { |
Alpana Kumari | 58e2214 | 2020-05-05 00:22:12 -0500 | [diff] [blame] | 235 | kw = string("PD_") + kw[1]; |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 236 | } |
Alpana Kumari | 8ea3f6d | 2020-04-02 00:26:07 -0500 | [diff] [blame] | 237 | else if (isdigit(kw[0])) |
| 238 | { |
Alpana Kumari | 58e2214 | 2020-05-05 00:22:12 -0500 | [diff] [blame] | 239 | kw = string("N_") + kw; |
Alpana Kumari | 8ea3f6d | 2020-04-02 00:26:07 -0500 | [diff] [blame] | 240 | } |
Alpana Kumari | 3ab26a7 | 2021-04-05 19:09:19 +0000 | [diff] [blame] | 241 | if constexpr (is_same<T, KeywordVpdMap>::value) |
| 242 | { |
jinuthomas | d640f69 | 2023-03-28 04:13:23 -0500 | [diff] [blame] | 243 | if (auto keywordValue = get_if<Binary>(&kwVal.second)) |
Alpana Kumari | 3ab26a7 | 2021-04-05 19:09:19 +0000 | [diff] [blame] | 244 | { |
jinuthomas | d640f69 | 2023-03-28 04:13:23 -0500 | [diff] [blame] | 245 | Binary vec((*keywordValue).begin(), (*keywordValue).end()); |
Alpana Kumari | 3ab26a7 | 2021-04-05 19:09:19 +0000 | [diff] [blame] | 246 | prop.emplace(move(kw), move(vec)); |
| 247 | } |
jinuthomas | d640f69 | 2023-03-28 04:13:23 -0500 | [diff] [blame] | 248 | else if (auto keywordValue = get_if<std::string>(&kwVal.second)) |
| 249 | { |
| 250 | Binary vec((*keywordValue).begin(), (*keywordValue).end()); |
| 251 | prop.emplace(move(kw), move(vec)); |
| 252 | } |
| 253 | else if (auto keywordValue = get_if<size_t>(&kwVal.second)) |
Alpana Kumari | 3ab26a7 | 2021-04-05 19:09:19 +0000 | [diff] [blame] | 254 | { |
| 255 | if (kw == "MemorySizeInKB") |
| 256 | { |
| 257 | inventory::PropertyMap memProp; |
jinuthomas | d640f69 | 2023-03-28 04:13:23 -0500 | [diff] [blame] | 258 | memProp.emplace(move(kw), ((*keywordValue))); |
| 259 | interfaces.emplace( |
| 260 | "xyz.openbmc_project.Inventory.Item.Dimm", |
| 261 | move(memProp)); |
Alpana Kumari | 3ab26a7 | 2021-04-05 19:09:19 +0000 | [diff] [blame] | 262 | } |
jinuthomas | d640f69 | 2023-03-28 04:13:23 -0500 | [diff] [blame] | 263 | else |
| 264 | { |
| 265 | cerr << "Unknown Keyword[" << kw << "] found "; |
| 266 | } |
| 267 | } |
| 268 | else |
| 269 | { |
| 270 | cerr << "Unknown Variant found "; |
Alpana Kumari | 3ab26a7 | 2021-04-05 19:09:19 +0000 | [diff] [blame] | 271 | } |
| 272 | } |
| 273 | else |
| 274 | { |
| 275 | Binary vec(kwVal.second.begin(), kwVal.second.end()); |
| 276 | prop.emplace(move(kw), move(vec)); |
| 277 | } |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | interfaces.emplace(preIntrStr, move(prop)); |
| 281 | } |
| 282 | |
| 283 | /** |
| 284 | * @brief Populate Interfaces. |
| 285 | * |
| 286 | * This method populates common and extra interfaces to dbus. |
| 287 | * @param[in] js - json object |
| 288 | * @param[out] interfaces - Reference to interface map |
| 289 | * @param[in] vpdMap - Reference to the parsed vpd map. |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 290 | * @param[in] isSystemVpd - Denotes whether we are collecting the system VPD. |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 291 | */ |
| 292 | template <typename T> |
| 293 | static void populateInterfaces(const nlohmann::json& js, |
| 294 | inventory::InterfaceMap& interfaces, |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 295 | const T& vpdMap, bool isSystemVpd) |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 296 | { |
| 297 | for (const auto& ifs : js.items()) |
| 298 | { |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 299 | string inf = ifs.key(); |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 300 | inventory::PropertyMap props; |
| 301 | |
| 302 | for (const auto& itr : ifs.value().items()) |
| 303 | { |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 304 | const string& busProp = itr.key(); |
| 305 | |
Alpana Kumari | 31970de | 2020-02-17 06:49:57 -0600 | [diff] [blame] | 306 | if (itr.value().is_boolean()) |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 307 | { |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 308 | props.emplace(busProp, itr.value().get<bool>()); |
| 309 | } |
| 310 | else if (itr.value().is_string()) |
| 311 | { |
Priyanga Ramasamy | 0d61c58 | 2022-01-21 04:38:22 -0600 | [diff] [blame] | 312 | if (busProp == "LocationCode" && inf == IBM_LOCATION_CODE_INF) |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 313 | { |
Priyanga Ramasamy | 0d61c58 | 2022-01-21 04:38:22 -0600 | [diff] [blame] | 314 | std::string prop; |
| 315 | if constexpr (is_same<T, Parsed>::value) |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 316 | { |
Alpana Kumari | 414d5ae | 2021-03-04 21:06:35 +0000 | [diff] [blame] | 317 | // TODO deprecate the com.ibm interface later |
Priyanga Ramasamy | 0d61c58 | 2022-01-21 04:38:22 -0600 | [diff] [blame] | 318 | prop = expandLocationCode(itr.value().get<string>(), |
| 319 | vpdMap, isSystemVpd); |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 320 | } |
Priyanga Ramasamy | 0d61c58 | 2022-01-21 04:38:22 -0600 | [diff] [blame] | 321 | else if constexpr (is_same<T, KeywordVpdMap>::value) |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 322 | { |
Priyanga Ramasamy | 0d61c58 | 2022-01-21 04:38:22 -0600 | [diff] [blame] | 323 | // Send empty Parsed object to expandLocationCode api. |
| 324 | prop = expandLocationCode(itr.value().get<string>(), |
| 325 | Parsed{}, false); |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 326 | } |
Priyanga Ramasamy | 0d61c58 | 2022-01-21 04:38:22 -0600 | [diff] [blame] | 327 | props.emplace(busProp, prop); |
| 328 | interfaces.emplace(XYZ_LOCATION_CODE_INF, props); |
| 329 | interfaces.emplace(IBM_LOCATION_CODE_INF, props); |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 330 | } |
| 331 | else |
| 332 | { |
| 333 | props.emplace(busProp, itr.value().get<string>()); |
| 334 | } |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 335 | } |
Santosh Puranik | ed609af | 2021-06-21 11:30:07 +0530 | [diff] [blame] | 336 | else if (itr.value().is_array()) |
| 337 | { |
| 338 | try |
| 339 | { |
| 340 | props.emplace(busProp, itr.value().get<Binary>()); |
| 341 | } |
Patrick Williams | 8e15b93 | 2021-10-06 13:04:22 -0500 | [diff] [blame] | 342 | catch (const nlohmann::detail::type_error& e) |
Santosh Puranik | ed609af | 2021-06-21 11:30:07 +0530 | [diff] [blame] | 343 | { |
| 344 | std::cerr << "Type exception: " << e.what() << "\n"; |
| 345 | // Ignore any type errors |
| 346 | } |
| 347 | } |
Alpana Kumari | 31970de | 2020-02-17 06:49:57 -0600 | [diff] [blame] | 348 | else if (itr.value().is_object()) |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 349 | { |
Alpana Kumari | 31970de | 2020-02-17 06:49:57 -0600 | [diff] [blame] | 350 | const string& rec = itr.value().value("recordName", ""); |
| 351 | const string& kw = itr.value().value("keywordName", ""); |
| 352 | const string& encoding = itr.value().value("encoding", ""); |
| 353 | |
Alpana Kumari | 58e2214 | 2020-05-05 00:22:12 -0500 | [diff] [blame] | 354 | if constexpr (is_same<T, Parsed>::value) |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 355 | { |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 356 | if (!rec.empty() && !kw.empty() && vpdMap.count(rec) && |
| 357 | vpdMap.at(rec).count(kw)) |
Alpana Kumari | 31970de | 2020-02-17 06:49:57 -0600 | [diff] [blame] | 358 | { |
| 359 | auto encoded = |
| 360 | encodeKeyword(vpdMap.at(rec).at(kw), encoding); |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 361 | props.emplace(busProp, encoded); |
Alpana Kumari | 31970de | 2020-02-17 06:49:57 -0600 | [diff] [blame] | 362 | } |
| 363 | } |
Alpana Kumari | 58e2214 | 2020-05-05 00:22:12 -0500 | [diff] [blame] | 364 | else if constexpr (is_same<T, KeywordVpdMap>::value) |
Alpana Kumari | 31970de | 2020-02-17 06:49:57 -0600 | [diff] [blame] | 365 | { |
| 366 | if (!kw.empty() && vpdMap.count(kw)) |
| 367 | { |
jinuthomas | d640f69 | 2023-03-28 04:13:23 -0500 | [diff] [blame] | 368 | if (auto kwValue = get_if<Binary>(&vpdMap.at(kw))) |
Alpana Kumari | 3ab26a7 | 2021-04-05 19:09:19 +0000 | [diff] [blame] | 369 | { |
| 370 | auto prop = |
| 371 | string((*kwValue).begin(), (*kwValue).end()); |
| 372 | |
| 373 | auto encoded = encodeKeyword(prop, encoding); |
| 374 | |
| 375 | props.emplace(busProp, encoded); |
| 376 | } |
jinuthomas | d640f69 | 2023-03-28 04:13:23 -0500 | [diff] [blame] | 377 | else if (auto kwValue = |
| 378 | get_if<std::string>(&vpdMap.at(kw))) |
| 379 | { |
| 380 | auto prop = |
| 381 | string((*kwValue).begin(), (*kwValue).end()); |
| 382 | |
| 383 | auto encoded = encodeKeyword(prop, encoding); |
| 384 | |
| 385 | props.emplace(busProp, encoded); |
| 386 | } |
| 387 | else if (auto uintValue = |
| 388 | get_if<size_t>(&vpdMap.at(kw))) |
Alpana Kumari | 3ab26a7 | 2021-04-05 19:09:19 +0000 | [diff] [blame] | 389 | { |
| 390 | props.emplace(busProp, *uintValue); |
| 391 | } |
jinuthomas | d640f69 | 2023-03-28 04:13:23 -0500 | [diff] [blame] | 392 | else |
| 393 | { |
| 394 | std::cerr << " Unknown Keyword [" << kw |
| 395 | << "] Encountered"; |
| 396 | } |
Alpana Kumari | 31970de | 2020-02-17 06:49:57 -0600 | [diff] [blame] | 397 | } |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 398 | } |
| 399 | } |
Matt Spinler | b1e64bb | 2021-09-08 09:57:48 -0500 | [diff] [blame] | 400 | else if (itr.value().is_number()) |
| 401 | { |
| 402 | // For now assume the value is a size_t. In the future it would |
| 403 | // be nice to come up with a way to get the type from the JSON. |
| 404 | props.emplace(busProp, itr.value().get<size_t>()); |
| 405 | } |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 406 | } |
Priyanga Ramasamy | aa8a893 | 2022-01-27 09:12:41 -0600 | [diff] [blame] | 407 | insertOrMerge(interfaces, inf, move(props)); |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 408 | } |
| 409 | } |
| 410 | |
alpana07 | 5cb3b1f | 2021-12-16 11:19:36 -0600 | [diff] [blame] | 411 | /** |
| 412 | * @brief This API checks if this FRU is pcie_devices. If yes then it further |
| 413 | * checks whether it is PASS1 planar. |
| 414 | */ |
| 415 | static bool isThisPcieOnPass1planar(const nlohmann::json& js, |
| 416 | const string& file) |
| 417 | { |
| 418 | auto isThisPCIeDev = false; |
| 419 | auto isPASS1 = false; |
| 420 | |
| 421 | // Check if it is a PCIE device |
| 422 | if (js["frus"].find(file) != js["frus"].end()) |
| 423 | { |
Santosh Puranik | c03f390 | 2022-04-14 10:58:26 +0530 | [diff] [blame] | 424 | if ((js["frus"][file].at(0).find("extraInterfaces") != |
| 425 | js["frus"][file].at(0).end())) |
alpana07 | 5cb3b1f | 2021-12-16 11:19:36 -0600 | [diff] [blame] | 426 | { |
Santosh Puranik | c03f390 | 2022-04-14 10:58:26 +0530 | [diff] [blame] | 427 | if (js["frus"][file].at(0)["extraInterfaces"].find( |
alpana07 | 5cb3b1f | 2021-12-16 11:19:36 -0600 | [diff] [blame] | 428 | "xyz.openbmc_project.Inventory.Item.PCIeDevice") != |
Santosh Puranik | c03f390 | 2022-04-14 10:58:26 +0530 | [diff] [blame] | 429 | js["frus"][file].at(0)["extraInterfaces"].end()) |
alpana07 | 5cb3b1f | 2021-12-16 11:19:36 -0600 | [diff] [blame] | 430 | { |
| 431 | isThisPCIeDev = true; |
| 432 | } |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | if (isThisPCIeDev) |
| 437 | { |
Alpana Kumari | a6181e2 | 2022-05-12 05:01:53 -0500 | [diff] [blame] | 438 | // Collect HW version and SystemType to know if it is PASS1 planar. |
alpana07 | 5cb3b1f | 2021-12-16 11:19:36 -0600 | [diff] [blame] | 439 | auto bus = sdbusplus::bus::new_default(); |
Alpana Kumari | a6181e2 | 2022-05-12 05:01:53 -0500 | [diff] [blame] | 440 | auto property1 = bus.new_method_call( |
alpana07 | 5cb3b1f | 2021-12-16 11:19:36 -0600 | [diff] [blame] | 441 | INVENTORY_MANAGER_SERVICE, |
| 442 | "/xyz/openbmc_project/inventory/system/chassis/motherboard", |
| 443 | "org.freedesktop.DBus.Properties", "Get"); |
Alpana Kumari | a6181e2 | 2022-05-12 05:01:53 -0500 | [diff] [blame] | 444 | property1.append("com.ibm.ipzvpd.VINI"); |
| 445 | property1.append("HW"); |
| 446 | auto result1 = bus.call(property1); |
| 447 | inventory::Value hwVal; |
| 448 | result1.read(hwVal); |
alpana07 | 5cb3b1f | 2021-12-16 11:19:36 -0600 | [diff] [blame] | 449 | |
Alpana Kumari | a6181e2 | 2022-05-12 05:01:53 -0500 | [diff] [blame] | 450 | // SystemType |
| 451 | auto property2 = bus.new_method_call( |
| 452 | INVENTORY_MANAGER_SERVICE, |
| 453 | "/xyz/openbmc_project/inventory/system/chassis/motherboard", |
| 454 | "org.freedesktop.DBus.Properties", "Get"); |
| 455 | property2.append("com.ibm.ipzvpd.VSBP"); |
| 456 | property2.append("IM"); |
| 457 | auto result2 = bus.call(property2); |
| 458 | inventory::Value imVal; |
| 459 | result2.read(imVal); |
| 460 | |
| 461 | auto pVal1 = get_if<Binary>(&hwVal); |
| 462 | auto pVal2 = get_if<Binary>(&imVal); |
| 463 | |
| 464 | if (pVal1 && pVal2) |
alpana07 | 5cb3b1f | 2021-12-16 11:19:36 -0600 | [diff] [blame] | 465 | { |
Alpana Kumari | a6181e2 | 2022-05-12 05:01:53 -0500 | [diff] [blame] | 466 | auto hwVersion = *pVal1; |
| 467 | auto systemType = *pVal2; |
| 468 | |
| 469 | // IM kw for Everest |
| 470 | Binary everestSystem{80, 00, 48, 00}; |
| 471 | |
| 472 | if (systemType == everestSystem) |
| 473 | { |
| 474 | if (hwVersion[1] < 21) |
| 475 | { |
| 476 | isPASS1 = true; |
| 477 | } |
| 478 | } |
| 479 | else if (hwVersion[1] < 2) |
| 480 | { |
alpana07 | 5cb3b1f | 2021-12-16 11:19:36 -0600 | [diff] [blame] | 481 | isPASS1 = true; |
Alpana Kumari | a6181e2 | 2022-05-12 05:01:53 -0500 | [diff] [blame] | 482 | } |
alpana07 | 5cb3b1f | 2021-12-16 11:19:36 -0600 | [diff] [blame] | 483 | } |
| 484 | } |
| 485 | |
| 486 | return (isThisPCIeDev && isPASS1); |
| 487 | } |
| 488 | |
Alpana Kumari | 735dee9 | 2022-03-25 01:24:40 -0500 | [diff] [blame] | 489 | /** Performs any pre-action needed to get the FRU setup for collection. |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 490 | * |
| 491 | * @param[in] json - json object |
| 492 | * @param[in] file - eeprom file path |
| 493 | */ |
| 494 | static void preAction(const nlohmann::json& json, const string& file) |
| 495 | { |
Alpana Kumari | 735dee9 | 2022-03-25 01:24:40 -0500 | [diff] [blame] | 496 | if ((json["frus"][file].at(0)).find("preAction") == |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 497 | json["frus"][file].at(0).end()) |
| 498 | { |
Alpana Kumari | 735dee9 | 2022-03-25 01:24:40 -0500 | [diff] [blame] | 499 | return; |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 500 | } |
| 501 | |
Sunny Srivastava | a2ddc96 | 2022-06-29 08:53:16 -0500 | [diff] [blame] | 502 | try |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 503 | { |
Sunny Srivastava | a2ddc96 | 2022-06-29 08:53:16 -0500 | [diff] [blame] | 504 | if (executePreAction(json, file)) |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 505 | { |
Sunny Srivastava | a2ddc96 | 2022-06-29 08:53:16 -0500 | [diff] [blame] | 506 | if (json["frus"][file].at(0).find("devAddress") != |
| 507 | json["frus"][file].at(0).end()) |
Alpana Kumari | 40d1c19 | 2022-03-09 21:16:02 -0600 | [diff] [blame] | 508 | { |
Sunny Srivastava | a2ddc96 | 2022-06-29 08:53:16 -0500 | [diff] [blame] | 509 | // Now bind the device |
| 510 | string bind = json["frus"][file].at(0).value("devAddress", ""); |
jinuthomas | d640f69 | 2023-03-28 04:13:23 -0500 | [diff] [blame] | 511 | cout << "Binding device " << bind << std::endl; |
Sunny Srivastava | a2ddc96 | 2022-06-29 08:53:16 -0500 | [diff] [blame] | 512 | string bindCmd = string("echo \"") + bind + |
| 513 | string("\" > /sys/bus/i2c/drivers/at24/bind"); |
jinuthomas | d640f69 | 2023-03-28 04:13:23 -0500 | [diff] [blame] | 514 | cout << bindCmd << std::endl; |
Sunny Srivastava | a2ddc96 | 2022-06-29 08:53:16 -0500 | [diff] [blame] | 515 | executeCmd(bindCmd); |
| 516 | |
| 517 | // Check if device showed up (test for file) |
| 518 | if (!fs::exists(file)) |
| 519 | { |
| 520 | cerr << "EEPROM " << file |
jinuthomas | d640f69 | 2023-03-28 04:13:23 -0500 | [diff] [blame] | 521 | << " does not exist. Take failure action" << std::endl; |
Sunny Srivastava | a2ddc96 | 2022-06-29 08:53:16 -0500 | [diff] [blame] | 522 | // If not, then take failure postAction |
| 523 | executePostFailAction(json, file); |
| 524 | } |
| 525 | } |
| 526 | else |
| 527 | { |
| 528 | // missing required informations |
| 529 | cerr << "VPD inventory JSON missing basic informations of " |
| 530 | "preAction " |
| 531 | "for this FRU : [" |
jinuthomas | d640f69 | 2023-03-28 04:13:23 -0500 | [diff] [blame] | 532 | << file << "]. Executing executePostFailAction." |
| 533 | << std::endl; |
Sunny Srivastava | a2ddc96 | 2022-06-29 08:53:16 -0500 | [diff] [blame] | 534 | |
| 535 | // Take failure postAction |
Alpana Kumari | 40d1c19 | 2022-03-09 21:16:02 -0600 | [diff] [blame] | 536 | executePostFailAction(json, file); |
Sunny Srivastava | a2ddc96 | 2022-06-29 08:53:16 -0500 | [diff] [blame] | 537 | return; |
Alpana Kumari | 40d1c19 | 2022-03-09 21:16:02 -0600 | [diff] [blame] | 538 | } |
| 539 | } |
Santosh Puranik | dedb5a6 | 2022-12-19 23:58:32 +0530 | [diff] [blame] | 540 | else |
| 541 | { |
| 542 | // If the FRU is not there, clear the VINI/CCIN data. |
| 543 | // Enity manager probes for this keyword to look for this |
| 544 | // FRU, now if the data is persistent on BMC and FRU is |
| 545 | // removed this can lead to ambiguity. Hence clearing this |
| 546 | // Keyword if FRU is absent. |
| 547 | const auto& invPath = |
| 548 | json["frus"][file].at(0).value("inventoryPath", ""); |
| 549 | |
| 550 | if (!invPath.empty()) |
| 551 | { |
| 552 | inventory::ObjectMap pimObjMap{ |
| 553 | {invPath, {{"com.ibm.ipzvpd.VINI", {{"CC", Binary{}}}}}}}; |
| 554 | |
| 555 | common::utility::callPIM(move(pimObjMap)); |
| 556 | } |
| 557 | else |
| 558 | { |
| 559 | throw std::runtime_error("Path empty in Json"); |
| 560 | } |
| 561 | } |
Sunny Srivastava | a2ddc96 | 2022-06-29 08:53:16 -0500 | [diff] [blame] | 562 | } |
| 563 | catch (const GpioException& e) |
| 564 | { |
| 565 | PelAdditionalData additionalData{}; |
| 566 | additionalData.emplace("DESCRIPTION", e.what()); |
| 567 | createPEL(additionalData, PelSeverity::WARNING, errIntfForGpioError, |
| 568 | nullptr); |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 569 | } |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 570 | } |
| 571 | |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 572 | /** |
Santosh Puranik | f3e6968 | 2022-03-31 17:52:38 +0530 | [diff] [blame] | 573 | * @brief Fills the Decorator.AssetTag property into the interfaces map |
| 574 | * |
| 575 | * This function should only be called in cases where we did not find a JSON |
| 576 | * symlink. A missing symlink in /var/lib will be considered as a factory reset |
| 577 | * and this function will be used to default the AssetTag property. |
| 578 | * |
| 579 | * @param interfaces A possibly pre-populated map of inetrfaces to properties. |
| 580 | * @param vpdMap A VPD map of the system VPD data. |
| 581 | */ |
| 582 | static void fillAssetTag(inventory::InterfaceMap& interfaces, |
| 583 | const Parsed& vpdMap) |
| 584 | { |
| 585 | // Read the system serial number and MTM |
| 586 | // Default asset tag is Server-MTM-System Serial |
| 587 | inventory::Interface assetIntf{ |
| 588 | "xyz.openbmc_project.Inventory.Decorator.AssetTag"}; |
| 589 | inventory::PropertyMap assetTagProps; |
| 590 | std::string defaultAssetTag = |
| 591 | std::string{"Server-"} + getKwVal(vpdMap, "VSYS", "TM") + |
| 592 | std::string{"-"} + getKwVal(vpdMap, "VSYS", "SE"); |
| 593 | assetTagProps.emplace("AssetTag", defaultAssetTag); |
| 594 | insertOrMerge(interfaces, assetIntf, std::move(assetTagProps)); |
| 595 | } |
| 596 | |
| 597 | /** |
Santosh Puranik | d3a379a | 2021-08-23 19:12:59 +0530 | [diff] [blame] | 598 | * @brief Set certain one time properties in the inventory |
| 599 | * Use this function to insert the Functional and Enabled properties into the |
| 600 | * inventory map. This function first checks if the object in question already |
| 601 | * has these properties hosted on D-Bus, if the property is already there, it is |
| 602 | * not modified, hence the name "one time". If the property is not already |
| 603 | * present, it will be added to the map with a suitable default value (true for |
Santosh Puranik | dedb5a6 | 2022-12-19 23:58:32 +0530 | [diff] [blame] | 604 | * Functional and Enabled) |
Santosh Puranik | d3a379a | 2021-08-23 19:12:59 +0530 | [diff] [blame] | 605 | * |
| 606 | * @param[in] object - The inventory D-Bus obejct without the inventory prefix. |
| 607 | * @param[inout] interfaces - Reference to a map of inventory interfaces to |
| 608 | * which the properties will be attached. |
| 609 | */ |
| 610 | static void setOneTimeProperties(const std::string& object, |
| 611 | inventory::InterfaceMap& interfaces) |
| 612 | { |
| 613 | auto bus = sdbusplus::bus::new_default(); |
| 614 | auto objectPath = INVENTORY_PATH + object; |
| 615 | auto prop = bus.new_method_call("xyz.openbmc_project.Inventory.Manager", |
| 616 | objectPath.c_str(), |
| 617 | "org.freedesktop.DBus.Properties", "Get"); |
| 618 | prop.append("xyz.openbmc_project.State.Decorator.OperationalStatus"); |
| 619 | prop.append("Functional"); |
| 620 | try |
| 621 | { |
| 622 | auto result = bus.call(prop); |
| 623 | } |
| 624 | catch (const sdbusplus::exception::SdBusError& e) |
| 625 | { |
| 626 | // Treat as property unavailable |
| 627 | inventory::PropertyMap prop; |
| 628 | prop.emplace("Functional", true); |
| 629 | interfaces.emplace( |
| 630 | "xyz.openbmc_project.State.Decorator.OperationalStatus", |
| 631 | move(prop)); |
| 632 | } |
| 633 | prop = bus.new_method_call("xyz.openbmc_project.Inventory.Manager", |
| 634 | objectPath.c_str(), |
| 635 | "org.freedesktop.DBus.Properties", "Get"); |
| 636 | prop.append("xyz.openbmc_project.Object.Enable"); |
| 637 | prop.append("Enabled"); |
| 638 | try |
| 639 | { |
| 640 | auto result = bus.call(prop); |
| 641 | } |
| 642 | catch (const sdbusplus::exception::SdBusError& e) |
| 643 | { |
| 644 | // Treat as property unavailable |
| 645 | inventory::PropertyMap prop; |
Santosh Puranik | dedb5a6 | 2022-12-19 23:58:32 +0530 | [diff] [blame] | 646 | prop.emplace("Enabled", true); |
Santosh Puranik | d3a379a | 2021-08-23 19:12:59 +0530 | [diff] [blame] | 647 | interfaces.emplace("xyz.openbmc_project.Object.Enable", move(prop)); |
| 648 | } |
| 649 | } |
| 650 | |
| 651 | /** |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 652 | * @brief Prime the Inventory |
| 653 | * Prime the inventory by populating only the location code, |
| 654 | * type interface and the inventory object for the frus |
| 655 | * which are not system vpd fru. |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 656 | * |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 657 | * @param[in] jsObject - Reference to vpd inventory json object |
| 658 | * @param[in] vpdMap - Reference to the parsed vpd map |
| 659 | * |
| 660 | * @returns Map of items in extraInterface. |
| 661 | */ |
| 662 | template <typename T> |
| 663 | inventory::ObjectMap primeInventory(const nlohmann::json& jsObject, |
| 664 | const T& vpdMap) |
| 665 | { |
| 666 | inventory::ObjectMap objects; |
| 667 | |
| 668 | for (auto& itemFRUS : jsObject["frus"].items()) |
| 669 | { |
| 670 | for (auto& itemEEPROM : itemFRUS.value()) |
| 671 | { |
Alpana Kumari | 2e6c6f7 | 2020-12-03 00:10:03 -0600 | [diff] [blame] | 672 | // Take pre actions if needed |
| 673 | if (itemEEPROM.find("preAction") != itemEEPROM.end()) |
| 674 | { |
| 675 | preAction(jsObject, itemFRUS.key()); |
| 676 | } |
| 677 | |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 678 | inventory::InterfaceMap interfaces; |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 679 | inventory::Object object(itemEEPROM.at("inventoryPath")); |
| 680 | |
Santosh Puranik | 50f60bf | 2021-05-26 17:55:06 +0530 | [diff] [blame] | 681 | if ((itemFRUS.key() != systemVpdFilePath) && |
| 682 | !itemEEPROM.value("noprime", false)) |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 683 | { |
Alpana Kumari | cfd7a75 | 2021-02-07 23:23:01 -0600 | [diff] [blame] | 684 | inventory::PropertyMap presProp; |
Priyanga Ramasamy | e358acb | 2022-03-21 14:21:50 -0500 | [diff] [blame] | 685 | |
| 686 | // Do not populate Present property for frus whose |
Priyanga Ramasamy | aca6137 | 2023-01-24 08:02:28 -0600 | [diff] [blame] | 687 | // synthesized=true. synthesized=true says the fru VPD is |
| 688 | // synthesized and owned by a separate component. |
| 689 | // In some cases, the FRU has its own VPD, but still a separate |
| 690 | // application handles the FRU's presence. So VPD parser skips |
| 691 | // populating Present property by checking the JSON flag, |
| 692 | // "handlePresence". |
Priyanga Ramasamy | e358acb | 2022-03-21 14:21:50 -0500 | [diff] [blame] | 693 | if (!itemEEPROM.value("synthesized", false)) |
| 694 | { |
Priyanga Ramasamy | aca6137 | 2023-01-24 08:02:28 -0600 | [diff] [blame] | 695 | if (itemEEPROM.value("handlePresence", true)) |
| 696 | { |
| 697 | presProp.emplace("Present", false); |
| 698 | interfaces.emplace("xyz.openbmc_project.Inventory.Item", |
| 699 | presProp); |
| 700 | } |
Priyanga Ramasamy | e358acb | 2022-03-21 14:21:50 -0500 | [diff] [blame] | 701 | } |
Priyanga Ramasamy | aca6137 | 2023-01-24 08:02:28 -0600 | [diff] [blame] | 702 | |
Santosh Puranik | d3a379a | 2021-08-23 19:12:59 +0530 | [diff] [blame] | 703 | setOneTimeProperties(object, interfaces); |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 704 | if (itemEEPROM.find("extraInterfaces") != itemEEPROM.end()) |
| 705 | { |
| 706 | for (const auto& eI : itemEEPROM["extraInterfaces"].items()) |
| 707 | { |
| 708 | inventory::PropertyMap props; |
Alpana Kumari | 414d5ae | 2021-03-04 21:06:35 +0000 | [diff] [blame] | 709 | if (eI.key() == IBM_LOCATION_CODE_INF) |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 710 | { |
| 711 | if constexpr (std::is_same<T, Parsed>::value) |
| 712 | { |
| 713 | for (auto& lC : eI.value().items()) |
| 714 | { |
| 715 | auto propVal = expandLocationCode( |
| 716 | lC.value().get<string>(), vpdMap, true); |
| 717 | |
| 718 | props.emplace(move(lC.key()), |
| 719 | move(propVal)); |
Santosh Puranik | b0f3749 | 2021-06-21 09:42:47 +0530 | [diff] [blame] | 720 | interfaces.emplace(XYZ_LOCATION_CODE_INF, |
| 721 | props); |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 722 | interfaces.emplace(move(eI.key()), |
| 723 | move(props)); |
| 724 | } |
| 725 | } |
| 726 | } |
| 727 | else if (eI.key().find("Inventory.Item.") != |
| 728 | string::npos) |
| 729 | { |
| 730 | interfaces.emplace(move(eI.key()), move(props)); |
| 731 | } |
Santosh Puranik | d3a379a | 2021-08-23 19:12:59 +0530 | [diff] [blame] | 732 | else if (eI.key() == |
| 733 | "xyz.openbmc_project.Inventory.Item") |
| 734 | { |
| 735 | for (auto& val : eI.value().items()) |
| 736 | { |
| 737 | if (val.key() == "PrettyName") |
| 738 | { |
| 739 | presProp.emplace(val.key(), |
| 740 | val.value().get<string>()); |
| 741 | } |
| 742 | } |
| 743 | // Use insert_or_assign here as we may already have |
| 744 | // inserted the present property only earlier in |
| 745 | // this function under this same interface. |
| 746 | interfaces.insert_or_assign(eI.key(), |
| 747 | move(presProp)); |
| 748 | } |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 749 | } |
| 750 | } |
| 751 | objects.emplace(move(object), move(interfaces)); |
| 752 | } |
| 753 | } |
| 754 | } |
| 755 | return objects; |
| 756 | } |
| 757 | |
Alpana Kumari | 65b8360 | 2020-09-01 00:24:56 -0500 | [diff] [blame] | 758 | /** |
| 759 | * @brief This API executes command to set environment variable |
| 760 | * And then reboot the system |
| 761 | * @param[in] key -env key to set new value |
| 762 | * @param[in] value -value to set. |
| 763 | */ |
| 764 | void setEnvAndReboot(const string& key, const string& value) |
| 765 | { |
| 766 | // set env and reboot and break. |
| 767 | executeCmd("/sbin/fw_setenv", key, value); |
Andrew Geissler | 280197e | 2020-12-08 20:51:49 -0600 | [diff] [blame] | 768 | log<level::INFO>("Rebooting BMC to pick up new device tree"); |
Alpana Kumari | 65b8360 | 2020-09-01 00:24:56 -0500 | [diff] [blame] | 769 | // make dbus call to reboot |
| 770 | auto bus = sdbusplus::bus::new_default_system(); |
| 771 | auto method = bus.new_method_call( |
| 772 | "org.freedesktop.systemd1", "/org/freedesktop/systemd1", |
| 773 | "org.freedesktop.systemd1.Manager", "Reboot"); |
| 774 | bus.call_noreply(method); |
| 775 | } |
| 776 | |
| 777 | /* |
| 778 | * @brief This API checks for env var fitconfig. |
| 779 | * If not initialised OR updated as per the current system type, |
| 780 | * update this env var and reboot the system. |
| 781 | * |
| 782 | * @param[in] systemType IM kwd in vpd tells about which system type it is. |
| 783 | * */ |
| 784 | void setDevTreeEnv(const string& systemType) |
| 785 | { |
Alpana Kumari | 37e7270 | 2021-11-18 11:18:04 -0600 | [diff] [blame] | 786 | // Init with default dtb |
| 787 | string newDeviceTree = "conf-aspeed-bmc-ibm-rainier-p1.dtb"; |
Santosh Puranik | e5f177a | 2022-01-24 20:14:46 +0530 | [diff] [blame] | 788 | static const deviceTreeMap deviceTreeSystemTypeMap = { |
| 789 | {RAINIER_2U, "conf-aspeed-bmc-ibm-rainier-p1.dtb"}, |
| 790 | {RAINIER_2U_V2, "conf-aspeed-bmc-ibm-rainier.dtb"}, |
| 791 | {RAINIER_4U, "conf-aspeed-bmc-ibm-rainier-4u-p1.dtb"}, |
| 792 | {RAINIER_4U_V2, "conf-aspeed-bmc-ibm-rainier-4u.dtb"}, |
| 793 | {RAINIER_1S4U, "conf-aspeed-bmc-ibm-rainier-1s4u.dtb"}, |
Alpana Kumari | 1b02611 | 2022-03-02 23:41:38 -0600 | [diff] [blame] | 794 | {EVEREST, "conf-aspeed-bmc-ibm-everest.dtb"}, |
Santosh Puranik | dedb5a6 | 2022-12-19 23:58:32 +0530 | [diff] [blame] | 795 | {EVEREST_V2, "conf-aspeed-bmc-ibm-everest.dtb"}, |
| 796 | {BONNELL, "conf-aspeed-bmc-ibm-bonnell.dtb"}}; |
Alpana Kumari | 65b8360 | 2020-09-01 00:24:56 -0500 | [diff] [blame] | 797 | |
| 798 | if (deviceTreeSystemTypeMap.find(systemType) != |
| 799 | deviceTreeSystemTypeMap.end()) |
| 800 | { |
| 801 | newDeviceTree = deviceTreeSystemTypeMap.at(systemType); |
| 802 | } |
Alpana Kumari | 37e7270 | 2021-11-18 11:18:04 -0600 | [diff] [blame] | 803 | else |
| 804 | { |
| 805 | // System type not supported |
Alpana Kumari | ab1e22c | 2021-11-24 11:03:38 -0600 | [diff] [blame] | 806 | string err = "This System type not found/supported in dtb table " + |
| 807 | systemType + |
| 808 | ".Please check the HW and IM keywords in the system " |
| 809 | "VPD.Breaking..."; |
| 810 | |
| 811 | // map to hold additional data in case of logging pel |
| 812 | PelAdditionalData additionalData{}; |
| 813 | additionalData.emplace("DESCRIPTION", err); |
| 814 | createPEL(additionalData, PelSeverity::WARNING, |
Sunny Srivastava | a2ddc96 | 2022-06-29 08:53:16 -0500 | [diff] [blame] | 815 | errIntfForInvalidSystemType, nullptr); |
Alpana Kumari | ab1e22c | 2021-11-24 11:03:38 -0600 | [diff] [blame] | 816 | exit(-1); |
Alpana Kumari | 37e7270 | 2021-11-18 11:18:04 -0600 | [diff] [blame] | 817 | } |
Alpana Kumari | 65b8360 | 2020-09-01 00:24:56 -0500 | [diff] [blame] | 818 | |
| 819 | string readVarValue; |
| 820 | bool envVarFound = false; |
| 821 | |
| 822 | vector<string> output = executeCmd("/sbin/fw_printenv"); |
| 823 | for (const auto& entry : output) |
| 824 | { |
| 825 | size_t pos = entry.find("="); |
| 826 | string key = entry.substr(0, pos); |
| 827 | if (key != "fitconfig") |
| 828 | { |
| 829 | continue; |
| 830 | } |
| 831 | |
| 832 | envVarFound = true; |
| 833 | if (pos + 1 < entry.size()) |
| 834 | { |
| 835 | readVarValue = entry.substr(pos + 1); |
| 836 | if (readVarValue.find(newDeviceTree) != string::npos) |
| 837 | { |
| 838 | // fitconfig is Updated. No action needed |
| 839 | break; |
| 840 | } |
| 841 | } |
| 842 | // set env and reboot and break. |
| 843 | setEnvAndReboot(key, newDeviceTree); |
| 844 | exit(0); |
| 845 | } |
| 846 | |
| 847 | // check If env var Not found |
| 848 | if (!envVarFound) |
| 849 | { |
| 850 | setEnvAndReboot("fitconfig", newDeviceTree); |
| 851 | } |
| 852 | } |
| 853 | |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 854 | /** |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 855 | * @brief API to check if we need to restore system VPD |
| 856 | * This functionality is only applicable for IPZ VPD data. |
| 857 | * @param[in] vpdMap - IPZ vpd map |
| 858 | * @param[in] objectPath - Object path for the FRU |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 859 | */ |
Sunny Srivastava | 3c24414 | 2022-01-11 08:47:04 -0600 | [diff] [blame] | 860 | void restoreSystemVPD(Parsed& vpdMap, const string& objectPath) |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 861 | { |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 862 | for (const auto& systemRecKwdPair : svpdKwdMap) |
| 863 | { |
| 864 | auto it = vpdMap.find(systemRecKwdPair.first); |
| 865 | |
| 866 | // check if record is found in map we got by parser |
| 867 | if (it != vpdMap.end()) |
| 868 | { |
| 869 | const auto& kwdListForRecord = systemRecKwdPair.second; |
Priyanga Ramasamy | 952d6c5 | 2022-11-07 07:20:24 -0600 | [diff] [blame] | 870 | for (const auto& keywordInfo : kwdListForRecord) |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 871 | { |
Priyanga Ramasamy | 952d6c5 | 2022-11-07 07:20:24 -0600 | [diff] [blame] | 872 | const auto keyword = get<0>(keywordInfo); |
| 873 | |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 874 | DbusPropertyMap& kwdValMap = it->second; |
| 875 | auto iterator = kwdValMap.find(keyword); |
| 876 | |
| 877 | if (iterator != kwdValMap.end()) |
| 878 | { |
| 879 | string& kwdValue = iterator->second; |
| 880 | |
| 881 | // check bus data |
| 882 | const string& recordName = systemRecKwdPair.first; |
| 883 | const string& busValue = readBusProperty( |
| 884 | objectPath, ipzVpdInf + recordName, keyword); |
| 885 | |
Priyanga Ramasamy | 952d6c5 | 2022-11-07 07:20:24 -0600 | [diff] [blame] | 886 | const auto& defaultValue = get<1>(keywordInfo); |
| 887 | Binary busDataInBinary(busValue.begin(), busValue.end()); |
| 888 | Binary kwdDataInBinary(kwdValue.begin(), kwdValue.end()); |
Sunny Srivastava | a559c2d | 2022-05-02 11:56:45 -0500 | [diff] [blame] | 889 | |
Priyanga Ramasamy | 952d6c5 | 2022-11-07 07:20:24 -0600 | [diff] [blame] | 890 | if (busDataInBinary != defaultValue) |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 891 | { |
Priyanga Ramasamy | 952d6c5 | 2022-11-07 07:20:24 -0600 | [diff] [blame] | 892 | if (kwdDataInBinary != defaultValue) |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 893 | { |
| 894 | // both the data are present, check for mismatch |
| 895 | if (busValue != kwdValue) |
| 896 | { |
Priyanga Ramasamy | 2494223 | 2023-01-05 04:54:59 -0600 | [diff] [blame] | 897 | string errMsg = "Mismatch found between backup " |
| 898 | "and primary VPD for record: "; |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 899 | errMsg += (*it).first; |
| 900 | errMsg += " and keyword: "; |
| 901 | errMsg += keyword; |
| 902 | |
Santosh Puranik | dedb5a6 | 2022-12-19 23:58:32 +0530 | [diff] [blame] | 903 | std::ostringstream busStream; |
| 904 | for (uint16_t byte : busValue) |
| 905 | { |
| 906 | busStream << std::setfill('0') |
| 907 | << std::setw(2) << std::hex |
| 908 | << "0x" << byte << " "; |
| 909 | } |
| 910 | |
| 911 | std::ostringstream vpdStream; |
| 912 | for (uint16_t byte : kwdValue) |
| 913 | { |
| 914 | vpdStream << std::setfill('0') |
| 915 | << std::setw(2) << std::hex |
| 916 | << "0x" << byte << " "; |
| 917 | } |
| 918 | |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 919 | // data mismatch |
| 920 | PelAdditionalData additionalData; |
| 921 | additionalData.emplace("CALLOUT_INVENTORY_PATH", |
Priyanga Ramasamy | f612368 | 2022-12-02 07:29:07 -0600 | [diff] [blame] | 922 | INVENTORY_PATH + |
| 923 | objectPath); |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 924 | |
| 925 | additionalData.emplace("DESCRIPTION", errMsg); |
Santosh Puranik | dedb5a6 | 2022-12-19 23:58:32 +0530 | [diff] [blame] | 926 | additionalData.emplace( |
Priyanga Ramasamy | 2494223 | 2023-01-05 04:54:59 -0600 | [diff] [blame] | 927 | "Value read from Backup: ", |
| 928 | busStream.str()); |
| 929 | additionalData.emplace( |
| 930 | "Value read from Primary: ", |
Santosh Puranik | dedb5a6 | 2022-12-19 23:58:32 +0530 | [diff] [blame] | 931 | vpdStream.str()); |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 932 | |
Sunny Srivastava | 0746eee | 2021-03-22 13:36:54 -0500 | [diff] [blame] | 933 | createPEL(additionalData, PelSeverity::WARNING, |
Priyanga Ramasamy | 2494223 | 2023-01-05 04:54:59 -0600 | [diff] [blame] | 934 | errIntfForVPDMismatch, nullptr); |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 935 | } |
| 936 | } |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 937 | |
Priyanga Ramasamy | 2494223 | 2023-01-05 04:54:59 -0600 | [diff] [blame] | 938 | // If backup data is not default, then irrespective of |
| 939 | // primary data(default or other than backup), copy the |
| 940 | // backup data to vpd map as we don't need to change the |
| 941 | // backup data in either case in the process of |
Santosh Puranik | dedb5a6 | 2022-12-19 23:58:32 +0530 | [diff] [blame] | 942 | // restoring system vpd. |
Santosh Puranik | dedb5a6 | 2022-12-19 23:58:32 +0530 | [diff] [blame] | 943 | kwdValue = busValue; |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 944 | } |
Priyanga Ramasamy | 952d6c5 | 2022-11-07 07:20:24 -0600 | [diff] [blame] | 945 | else if (kwdDataInBinary == defaultValue && |
| 946 | get<2>(keywordInfo)) // Check isPELRequired is true |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 947 | { |
Priyanga Ramasamy | 2494223 | 2023-01-05 04:54:59 -0600 | [diff] [blame] | 948 | string errMsg = "Found default value on both backup " |
| 949 | "and primary VPD for record: "; |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 950 | errMsg += (*it).first; |
| 951 | errMsg += " and keyword: "; |
| 952 | errMsg += keyword; |
Priyanga Ramasamy | 2494223 | 2023-01-05 04:54:59 -0600 | [diff] [blame] | 953 | errMsg += ". SSR need to update primary VPD."; |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 954 | |
Priyanga Ramasamy | 2494223 | 2023-01-05 04:54:59 -0600 | [diff] [blame] | 955 | // mfg default on both backup and primary, log PEL |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 956 | PelAdditionalData additionalData; |
| 957 | additionalData.emplace("CALLOUT_INVENTORY_PATH", |
Priyanga Ramasamy | f612368 | 2022-12-02 07:29:07 -0600 | [diff] [blame] | 958 | INVENTORY_PATH + objectPath); |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 959 | |
| 960 | additionalData.emplace("DESCRIPTION", errMsg); |
| 961 | |
| 962 | // log PEL TODO: Block IPL |
Sunny Srivastava | 0746eee | 2021-03-22 13:36:54 -0500 | [diff] [blame] | 963 | createPEL(additionalData, PelSeverity::ERROR, |
Priyanga Ramasamy | 2494223 | 2023-01-05 04:54:59 -0600 | [diff] [blame] | 964 | errIntfForVPDDefault, nullptr); |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 965 | continue; |
| 966 | } |
| 967 | } |
| 968 | } |
| 969 | } |
| 970 | } |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 971 | } |
| 972 | |
| 973 | /** |
alpana07 | 7ce6872 | 2021-07-25 13:23:59 -0500 | [diff] [blame] | 974 | * @brief This checks for is this FRU a processor |
| 975 | * And if yes, then checks for is this primary |
| 976 | * |
| 977 | * @param[in] js- vpd json to get the information about this FRU |
| 978 | * @param[in] filePath- FRU vpd |
| 979 | * |
| 980 | * @return true/false |
| 981 | */ |
| 982 | bool isThisPrimaryProcessor(nlohmann::json& js, const string& filePath) |
| 983 | { |
| 984 | bool isProcessor = false; |
| 985 | bool isPrimary = false; |
| 986 | |
| 987 | for (const auto& item : js["frus"][filePath]) |
| 988 | { |
| 989 | if (item.find("extraInterfaces") != item.end()) |
| 990 | { |
| 991 | for (const auto& eI : item["extraInterfaces"].items()) |
| 992 | { |
| 993 | if (eI.key().find("Inventory.Item.Cpu") != string::npos) |
| 994 | { |
| 995 | isProcessor = true; |
| 996 | } |
| 997 | } |
| 998 | } |
| 999 | |
| 1000 | if (isProcessor) |
| 1001 | { |
| 1002 | string cpuType = item.value("cpuType", ""); |
| 1003 | if (cpuType == "primary") |
| 1004 | { |
| 1005 | isPrimary = true; |
| 1006 | } |
| 1007 | } |
| 1008 | } |
| 1009 | |
| 1010 | return (isProcessor && isPrimary); |
| 1011 | } |
| 1012 | |
| 1013 | /** |
| 1014 | * @brief This finds DIMM vpd in vpd json and enables them by binding the device |
| 1015 | * driver |
| 1016 | * @param[in] js- vpd json to iterate through and take action if it is DIMM |
| 1017 | */ |
| 1018 | void doEnableAllDimms(nlohmann::json& js) |
| 1019 | { |
| 1020 | // iterate over each fru |
| 1021 | for (const auto& eachFru : js["frus"].items()) |
| 1022 | { |
| 1023 | // skip the driver binding if eeprom already exists |
| 1024 | if (fs::exists(eachFru.key())) |
| 1025 | { |
| 1026 | continue; |
| 1027 | } |
| 1028 | |
| 1029 | for (const auto& eachInventory : eachFru.value()) |
| 1030 | { |
| 1031 | if (eachInventory.find("extraInterfaces") != eachInventory.end()) |
| 1032 | { |
| 1033 | for (const auto& eI : eachInventory["extraInterfaces"].items()) |
| 1034 | { |
| 1035 | if (eI.key().find("Inventory.Item.Dimm") != string::npos) |
| 1036 | { |
| 1037 | string dimmVpd = eachFru.key(); |
| 1038 | // fetch it from |
| 1039 | // "/sys/bus/i2c/drivers/at24/414-0050/eeprom" |
| 1040 | |
| 1041 | regex matchPatern("([0-9]+-[0-9]{4})"); |
| 1042 | smatch matchFound; |
| 1043 | if (regex_search(dimmVpd, matchFound, matchPatern)) |
| 1044 | { |
| 1045 | vector<string> i2cReg; |
| 1046 | boost::split(i2cReg, matchFound.str(0), |
| 1047 | boost::is_any_of("-")); |
| 1048 | |
| 1049 | // remove 0s from begining |
| 1050 | const regex pattern("^0+(?!$)"); |
| 1051 | for (auto& i : i2cReg) |
| 1052 | { |
| 1053 | i = regex_replace(i, pattern, ""); |
| 1054 | } |
| 1055 | |
| 1056 | if (i2cReg.size() == 2) |
| 1057 | { |
| 1058 | // echo 24c32 0x50 > |
| 1059 | // /sys/bus/i2c/devices/i2c-16/new_device |
| 1060 | string cmnd = "echo 24c32 0x" + i2cReg[1] + |
| 1061 | " > /sys/bus/i2c/devices/i2c-" + |
| 1062 | i2cReg[0] + "/new_device"; |
| 1063 | |
| 1064 | executeCmd(cmnd); |
| 1065 | } |
| 1066 | } |
| 1067 | } |
| 1068 | } |
| 1069 | } |
| 1070 | } |
| 1071 | } |
| 1072 | } |
| 1073 | |
| 1074 | /** |
Priyanga Ramasamy | 6abdeb6 | 2022-01-09 23:15:11 -0600 | [diff] [blame] | 1075 | * @brief Check if the given CPU is an IO only chip. |
| 1076 | * The CPU is termed as IO, whose all of the cores are bad and can never be |
| 1077 | * used. Those CPU chips can be used for IO purpose like connecting PCIe devices |
| 1078 | * etc., The CPU whose every cores are bad, can be identified from the CP00 |
| 1079 | * record's PG keyword, only if all of the 8 EQs' value equals 0xE7F9FF. (1EQ |
| 1080 | * has 4 cores grouped together by sharing its cache memory.) |
| 1081 | * @param [in] pgKeyword - PG Keyword of CPU. |
| 1082 | * @return true if the given cpu is an IO, false otherwise. |
| 1083 | */ |
| 1084 | static bool isCPUIOGoodOnly(const string& pgKeyword) |
| 1085 | { |
| 1086 | const unsigned char io[] = {0xE7, 0xF9, 0xFF, 0xE7, 0xF9, 0xFF, 0xE7, 0xF9, |
| 1087 | 0xFF, 0xE7, 0xF9, 0xFF, 0xE7, 0xF9, 0xFF, 0xE7, |
| 1088 | 0xF9, 0xFF, 0xE7, 0xF9, 0xFF, 0xE7, 0xF9, 0xFF}; |
| 1089 | // EQ0 index (in PG keyword) starts at 97 (with offset starting from 0). |
| 1090 | // Each EQ carries 3 bytes of data. Totally there are 8 EQs. If all EQs' |
| 1091 | // value equals 0xE7F9FF, then the cpu has no good cores and its treated as |
| 1092 | // IO. |
| 1093 | if (memcmp(io, pgKeyword.data() + 97, 24) == 0) |
| 1094 | { |
| 1095 | return true; |
| 1096 | } |
| 1097 | |
| 1098 | // The CPU is not an IO |
| 1099 | return false; |
| 1100 | } |
| 1101 | |
| 1102 | /** |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 1103 | * @brief Populate Dbus. |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1104 | * This method invokes all the populateInterface functions |
| 1105 | * and notifies PIM about dbus object. |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 1106 | * @param[in] vpdMap - Either IPZ vpd map or Keyword vpd map based on the |
| 1107 | * input. |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1108 | * @param[in] js - Inventory json object |
| 1109 | * @param[in] filePath - Path of the vpd file |
| 1110 | * @param[in] preIntrStr - Interface string |
| 1111 | */ |
| 1112 | template <typename T> |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 1113 | static void populateDbus(T& vpdMap, nlohmann::json& js, const string& filePath) |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1114 | { |
| 1115 | inventory::InterfaceMap interfaces; |
| 1116 | inventory::ObjectMap objects; |
| 1117 | inventory::PropertyMap prop; |
Shantappa Teekappanavar | 6aa5450 | 2021-12-09 12:59:56 -0600 | [diff] [blame] | 1118 | string ccinFromVpd; |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1119 | |
Santosh Puranik | 50f60bf | 2021-05-26 17:55:06 +0530 | [diff] [blame] | 1120 | bool isSystemVpd = (filePath == systemVpdFilePath); |
| 1121 | if constexpr (is_same<T, Parsed>::value) |
| 1122 | { |
Shantappa Teekappanavar | 6aa5450 | 2021-12-09 12:59:56 -0600 | [diff] [blame] | 1123 | ccinFromVpd = getKwVal(vpdMap, "VINI", "CC"); |
| 1124 | transform(ccinFromVpd.begin(), ccinFromVpd.end(), ccinFromVpd.begin(), |
| 1125 | ::toupper); |
| 1126 | |
Santosh Puranik | 50f60bf | 2021-05-26 17:55:06 +0530 | [diff] [blame] | 1127 | if (isSystemVpd) |
| 1128 | { |
| 1129 | std::vector<std::string> interfaces = {motherBoardInterface}; |
| 1130 | // call mapper to check for object path creation |
| 1131 | MapperResponse subTree = |
| 1132 | getObjectSubtreeForInterfaces(pimPath, 0, interfaces); |
| 1133 | string mboardPath = |
| 1134 | js["frus"][filePath].at(0).value("inventoryPath", ""); |
| 1135 | |
| 1136 | // Attempt system VPD restore if we have a motherboard |
| 1137 | // object in the inventory. |
| 1138 | if ((subTree.size() != 0) && |
| 1139 | (subTree.find(pimPath + mboardPath) != subTree.end())) |
| 1140 | { |
Sunny Srivastava | 3c24414 | 2022-01-11 08:47:04 -0600 | [diff] [blame] | 1141 | restoreSystemVPD(vpdMap, mboardPath); |
Santosh Puranik | 50f60bf | 2021-05-26 17:55:06 +0530 | [diff] [blame] | 1142 | } |
| 1143 | else |
| 1144 | { |
| 1145 | log<level::ERR>("No object path found"); |
| 1146 | } |
| 1147 | } |
alpana07 | 7ce6872 | 2021-07-25 13:23:59 -0500 | [diff] [blame] | 1148 | else |
| 1149 | { |
| 1150 | // check if it is processor vpd. |
| 1151 | auto isPrimaryCpu = isThisPrimaryProcessor(js, filePath); |
| 1152 | |
| 1153 | if (isPrimaryCpu) |
| 1154 | { |
| 1155 | auto ddVersion = getKwVal(vpdMap, "CRP0", "DD"); |
| 1156 | |
| 1157 | auto chipVersion = atoi(ddVersion.substr(1, 2).c_str()); |
| 1158 | |
| 1159 | if (chipVersion >= 2) |
| 1160 | { |
| 1161 | doEnableAllDimms(js); |
Santosh Puranik | 253fbe9 | 2022-10-06 22:38:09 +0530 | [diff] [blame] | 1162 | // Sleep for a few seconds to let the DIMM parses start |
| 1163 | using namespace std::chrono_literals; |
| 1164 | std::this_thread::sleep_for(5s); |
alpana07 | 7ce6872 | 2021-07-25 13:23:59 -0500 | [diff] [blame] | 1165 | } |
| 1166 | } |
| 1167 | } |
Santosh Puranik | 50f60bf | 2021-05-26 17:55:06 +0530 | [diff] [blame] | 1168 | } |
| 1169 | |
Santosh Puranik | f3e6968 | 2022-03-31 17:52:38 +0530 | [diff] [blame] | 1170 | auto processFactoryReset = false; |
| 1171 | |
Priyanga Ramasamy | 32c687f | 2022-01-04 23:14:03 -0600 | [diff] [blame] | 1172 | if (isSystemVpd) |
| 1173 | { |
| 1174 | string systemJsonName{}; |
| 1175 | if constexpr (is_same<T, Parsed>::value) |
| 1176 | { |
| 1177 | // pick the right system json |
| 1178 | systemJsonName = getSystemsJson(vpdMap); |
| 1179 | } |
| 1180 | |
| 1181 | fs::path target = systemJsonName; |
| 1182 | fs::path link = INVENTORY_JSON_SYM_LINK; |
| 1183 | |
Santosh Puranik | f3e6968 | 2022-03-31 17:52:38 +0530 | [diff] [blame] | 1184 | // If the symlink does not exist, we treat that as a factory reset |
| 1185 | processFactoryReset = !fs::exists(INVENTORY_JSON_SYM_LINK); |
| 1186 | |
Priyanga Ramasamy | 32c687f | 2022-01-04 23:14:03 -0600 | [diff] [blame] | 1187 | // Create the directory for hosting the symlink |
| 1188 | fs::create_directories(VPD_FILES_PATH); |
| 1189 | // unlink the symlink previously created (if any) |
| 1190 | remove(INVENTORY_JSON_SYM_LINK); |
| 1191 | // create a new symlink based on the system |
| 1192 | fs::create_symlink(target, link); |
| 1193 | |
| 1194 | // Reloading the json |
| 1195 | ifstream inventoryJson(link); |
| 1196 | js = json::parse(inventoryJson); |
| 1197 | inventoryJson.close(); |
| 1198 | } |
| 1199 | |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1200 | for (const auto& item : js["frus"][filePath]) |
| 1201 | { |
| 1202 | const auto& objectPath = item["inventoryPath"]; |
| 1203 | sdbusplus::message::object_path object(objectPath); |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 1204 | |
Shantappa Teekappanavar | 6aa5450 | 2021-12-09 12:59:56 -0600 | [diff] [blame] | 1205 | vector<string> ccinList; |
| 1206 | if (item.find("ccin") != item.end()) |
| 1207 | { |
| 1208 | for (const auto& cc : item["ccin"]) |
| 1209 | { |
| 1210 | string ccin = cc; |
| 1211 | transform(ccin.begin(), ccin.end(), ccin.begin(), ::toupper); |
| 1212 | ccinList.push_back(ccin); |
| 1213 | } |
| 1214 | } |
| 1215 | |
| 1216 | if (!ccinFromVpd.empty() && !ccinList.empty() && |
| 1217 | (find(ccinList.begin(), ccinList.end(), ccinFromVpd) == |
| 1218 | ccinList.end())) |
| 1219 | { |
| 1220 | continue; |
| 1221 | } |
| 1222 | |
Priyanga Ramasamy | e3fed70 | 2022-01-11 01:05:32 -0600 | [diff] [blame] | 1223 | if ((isSystemVpd) || (item.value("noprime", false))) |
Santosh Puranik | d3a379a | 2021-08-23 19:12:59 +0530 | [diff] [blame] | 1224 | { |
Priyanga Ramasamy | e3fed70 | 2022-01-11 01:05:32 -0600 | [diff] [blame] | 1225 | |
| 1226 | // Populate one time properties for the system VPD and its sub-frus |
| 1227 | // and for other non-primeable frus. |
Santosh Puranik | d3a379a | 2021-08-23 19:12:59 +0530 | [diff] [blame] | 1228 | // For the remaining FRUs, this will get handled as a part of |
| 1229 | // priming the inventory. |
| 1230 | setOneTimeProperties(objectPath, interfaces); |
| 1231 | } |
| 1232 | |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1233 | // Populate the VPD keywords and the common interfaces only if we |
| 1234 | // are asked to inherit that data from the VPD, else only add the |
| 1235 | // extraInterfaces. |
| 1236 | if (item.value("inherit", true)) |
| 1237 | { |
Alpana Kumari | 58e2214 | 2020-05-05 00:22:12 -0500 | [diff] [blame] | 1238 | if constexpr (is_same<T, Parsed>::value) |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1239 | { |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 1240 | // Each record in the VPD becomes an interface and all |
| 1241 | // keyword within the record are properties under that |
| 1242 | // interface. |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1243 | for (const auto& record : vpdMap) |
| 1244 | { |
| 1245 | populateFruSpecificInterfaces( |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 1246 | record.second, ipzVpdInf + record.first, interfaces); |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1247 | } |
| 1248 | } |
Alpana Kumari | 58e2214 | 2020-05-05 00:22:12 -0500 | [diff] [blame] | 1249 | else if constexpr (is_same<T, KeywordVpdMap>::value) |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1250 | { |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 1251 | populateFruSpecificInterfaces(vpdMap, kwdVpdInf, interfaces); |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1252 | } |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 1253 | if (js.find("commonInterfaces") != js.end()) |
| 1254 | { |
| 1255 | populateInterfaces(js["commonInterfaces"], interfaces, vpdMap, |
| 1256 | isSystemVpd); |
| 1257 | } |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1258 | } |
Santosh Puranik | 0859eb6 | 2020-03-16 02:56:29 -0500 | [diff] [blame] | 1259 | else |
| 1260 | { |
| 1261 | // Check if we have been asked to inherit specific record(s) |
Alpana Kumari | 58e2214 | 2020-05-05 00:22:12 -0500 | [diff] [blame] | 1262 | if constexpr (is_same<T, Parsed>::value) |
Santosh Puranik | 0859eb6 | 2020-03-16 02:56:29 -0500 | [diff] [blame] | 1263 | { |
| 1264 | if (item.find("copyRecords") != item.end()) |
| 1265 | { |
| 1266 | for (const auto& record : item["copyRecords"]) |
| 1267 | { |
| 1268 | const string& recordName = record; |
| 1269 | if (vpdMap.find(recordName) != vpdMap.end()) |
| 1270 | { |
| 1271 | populateFruSpecificInterfaces( |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 1272 | vpdMap.at(recordName), ipzVpdInf + recordName, |
Santosh Puranik | 0859eb6 | 2020-03-16 02:56:29 -0500 | [diff] [blame] | 1273 | interfaces); |
| 1274 | } |
| 1275 | } |
| 1276 | } |
| 1277 | } |
| 1278 | } |
Santosh Puranik | 32c4650 | 2022-02-10 08:55:07 +0530 | [diff] [blame] | 1279 | // Populate interfaces and properties that are common to every FRU |
| 1280 | // and additional interface that might be defined on a per-FRU |
| 1281 | // basis. |
| 1282 | if (item.find("extraInterfaces") != item.end()) |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1283 | { |
Santosh Puranik | 32c4650 | 2022-02-10 08:55:07 +0530 | [diff] [blame] | 1284 | populateInterfaces(item["extraInterfaces"], interfaces, vpdMap, |
| 1285 | isSystemVpd); |
Priyanga Ramasamy | 6abdeb6 | 2022-01-09 23:15:11 -0600 | [diff] [blame] | 1286 | if constexpr (is_same<T, Parsed>::value) |
| 1287 | { |
| 1288 | if (item["extraInterfaces"].find( |
| 1289 | "xyz.openbmc_project.Inventory.Item.Cpu") != |
| 1290 | item["extraInterfaces"].end()) |
| 1291 | { |
| 1292 | if (isCPUIOGoodOnly(getKwVal(vpdMap, "CP00", "PG"))) |
| 1293 | { |
Priyanga Ramasamy | 2c607a9 | 2022-04-08 00:30:17 -0500 | [diff] [blame] | 1294 | interfaces[invItemIntf]["PrettyName"] = "IO Module"; |
Priyanga Ramasamy | 6abdeb6 | 2022-01-09 23:15:11 -0600 | [diff] [blame] | 1295 | } |
| 1296 | } |
| 1297 | } |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1298 | } |
Priyanga Ramasamy | e358acb | 2022-03-21 14:21:50 -0500 | [diff] [blame] | 1299 | |
| 1300 | // embedded property(true or false) says whether the subfru is embedded |
| 1301 | // into the parent fru (or) not. VPD sets Present property only for |
| 1302 | // embedded frus. If the subfru is not an embedded FRU, the subfru may |
| 1303 | // or may not be physically present. Those non embedded frus will always |
| 1304 | // have Present=false irrespective of its physical presence or absence. |
| 1305 | // Eg: nvme drive in nvme slot is not an embedded FRU. So don't set |
| 1306 | // Present to true for such sub frus. |
| 1307 | // Eg: ethernet port is embedded into bmc card. So set Present to true |
| 1308 | // for such sub frus. Also donot populate present property for embedded |
| 1309 | // subfru which is synthesized. Currently there is no subfru which are |
| 1310 | // both embedded and synthesized. But still the case is handled here. |
| 1311 | if ((item.value("embedded", true)) && |
| 1312 | (!item.value("synthesized", false))) |
| 1313 | { |
Priyanga Ramasamy | aca6137 | 2023-01-24 08:02:28 -0600 | [diff] [blame] | 1314 | // Check if its required to handle presence for this FRU. |
| 1315 | if (item.value("handlePresence", true)) |
| 1316 | { |
| 1317 | inventory::PropertyMap presProp; |
| 1318 | presProp.emplace("Present", true); |
| 1319 | insertOrMerge(interfaces, invItemIntf, move(presProp)); |
| 1320 | } |
Priyanga Ramasamy | e358acb | 2022-03-21 14:21:50 -0500 | [diff] [blame] | 1321 | } |
Priyanga Ramasamy | aa8a893 | 2022-01-27 09:12:41 -0600 | [diff] [blame] | 1322 | |
Santosh Puranik | f3e6968 | 2022-03-31 17:52:38 +0530 | [diff] [blame] | 1323 | if constexpr (is_same<T, Parsed>::value) |
| 1324 | { |
| 1325 | // Restore asset tag, if needed |
| 1326 | if (processFactoryReset && objectPath == "/system") |
| 1327 | { |
| 1328 | fillAssetTag(interfaces, vpdMap); |
| 1329 | } |
| 1330 | } |
| 1331 | |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1332 | objects.emplace(move(object), move(interfaces)); |
| 1333 | } |
| 1334 | |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 1335 | if (isSystemVpd) |
| 1336 | { |
| 1337 | inventory::ObjectMap primeObject = primeInventory(js, vpdMap); |
| 1338 | objects.insert(primeObject.begin(), primeObject.end()); |
Alpana Kumari | 65b8360 | 2020-09-01 00:24:56 -0500 | [diff] [blame] | 1339 | |
Alpana Kumari | f05effd | 2021-04-07 07:32:53 -0500 | [diff] [blame] | 1340 | // set the U-boot environment variable for device-tree |
| 1341 | if constexpr (is_same<T, Parsed>::value) |
| 1342 | { |
Santosh Puranik | e5f177a | 2022-01-24 20:14:46 +0530 | [diff] [blame] | 1343 | setDevTreeEnv(fs::path(getSystemsJson(vpdMap)).filename()); |
Alpana Kumari | f05effd | 2021-04-07 07:32:53 -0500 | [diff] [blame] | 1344 | } |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 1345 | } |
| 1346 | |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1347 | // Notify PIM |
Sunny Srivastava | 6c71c9d | 2021-04-15 04:43:54 -0500 | [diff] [blame] | 1348 | common::utility::callPIM(move(objects)); |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1349 | } |
| 1350 | |
| 1351 | int main(int argc, char** argv) |
| 1352 | { |
| 1353 | int rc = 0; |
SunnySrivastava1984 | a20be8e | 2020-08-26 02:00:50 -0500 | [diff] [blame] | 1354 | json js{}; |
PriyangaRamasamy | c2fe40f | 2021-03-02 06:27:33 -0600 | [diff] [blame] | 1355 | Binary vpdVector{}; |
| 1356 | string file{}; |
SunnySrivastava1984 | a20be8e | 2020-08-26 02:00:50 -0500 | [diff] [blame] | 1357 | // map to hold additional data in case of logging pel |
| 1358 | PelAdditionalData additionalData{}; |
| 1359 | |
| 1360 | // this is needed to hold base fru inventory path in case there is ECC or |
| 1361 | // vpd exception while parsing the file |
| 1362 | std::string baseFruInventoryPath = {}; |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1363 | |
Sunny Srivastava | 0746eee | 2021-03-22 13:36:54 -0500 | [diff] [blame] | 1364 | // severity for PEL |
| 1365 | PelSeverity pelSeverity = PelSeverity::WARNING; |
| 1366 | |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1367 | try |
| 1368 | { |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1369 | App app{"ibm-read-vpd - App to read IPZ format VPD, parse it and store " |
| 1370 | "in DBUS"}; |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1371 | |
| 1372 | app.add_option("-f, --file", file, "File containing VPD (IPZ/KEYWORD)") |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 1373 | ->required(); |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1374 | |
| 1375 | CLI11_PARSE(app, argc, argv); |
| 1376 | |
Sunny Srivastava | 0746eee | 2021-03-22 13:36:54 -0500 | [diff] [blame] | 1377 | // PEL severity should be ERROR in case of any system VPD failure |
| 1378 | if (file == systemVpdFilePath) |
| 1379 | { |
| 1380 | pelSeverity = PelSeverity::ERROR; |
| 1381 | } |
| 1382 | |
Santosh Puranik | 0246a4d | 2020-11-04 16:57:39 +0530 | [diff] [blame] | 1383 | auto jsonToParse = INVENTORY_JSON_DEFAULT; |
| 1384 | |
| 1385 | // If the symlink exists, it means it has been setup for us, switch the |
| 1386 | // path |
| 1387 | if (fs::exists(INVENTORY_JSON_SYM_LINK)) |
| 1388 | { |
| 1389 | jsonToParse = INVENTORY_JSON_SYM_LINK; |
| 1390 | } |
| 1391 | |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1392 | // Make sure that the file path we get is for a supported EEPROM |
Santosh Puranik | 0246a4d | 2020-11-04 16:57:39 +0530 | [diff] [blame] | 1393 | ifstream inventoryJson(jsonToParse); |
SunnySrivastava1984 | a20be8e | 2020-08-26 02:00:50 -0500 | [diff] [blame] | 1394 | if (!inventoryJson) |
| 1395 | { |
Sunny Srivastava | 0746eee | 2021-03-22 13:36:54 -0500 | [diff] [blame] | 1396 | throw(VpdJsonException("Failed to access Json path", jsonToParse)); |
SunnySrivastava1984 | a20be8e | 2020-08-26 02:00:50 -0500 | [diff] [blame] | 1397 | } |
| 1398 | |
| 1399 | try |
| 1400 | { |
| 1401 | js = json::parse(inventoryJson); |
| 1402 | } |
Patrick Williams | 8e15b93 | 2021-10-06 13:04:22 -0500 | [diff] [blame] | 1403 | catch (const json::parse_error& ex) |
SunnySrivastava1984 | a20be8e | 2020-08-26 02:00:50 -0500 | [diff] [blame] | 1404 | { |
Sunny Srivastava | 0746eee | 2021-03-22 13:36:54 -0500 | [diff] [blame] | 1405 | throw(VpdJsonException("Json parsing failed", jsonToParse)); |
SunnySrivastava1984 | a20be8e | 2020-08-26 02:00:50 -0500 | [diff] [blame] | 1406 | } |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1407 | |
Santosh Puranik | 12e24ff | 2021-05-11 19:33:50 +0530 | [diff] [blame] | 1408 | // Do we have the mandatory "frus" section? |
| 1409 | if (js.find("frus") == js.end()) |
| 1410 | { |
| 1411 | throw(VpdJsonException("FRUs section not found in JSON", |
| 1412 | jsonToParse)); |
| 1413 | } |
| 1414 | |
PriyangaRamasamy | 647868e | 2020-09-08 17:03:19 +0530 | [diff] [blame] | 1415 | // Check if it's a udev path - patterned as(/ahb/ahb:apb/ahb:apb:bus@) |
| 1416 | if (file.find("/ahb:apb") != string::npos) |
| 1417 | { |
| 1418 | // Translate udev path to a generic /sys/bus/.. file path. |
| 1419 | udevToGenericPath(file); |
Santosh Puranik | 12e24ff | 2021-05-11 19:33:50 +0530 | [diff] [blame] | 1420 | |
| 1421 | if ((js["frus"].find(file) != js["frus"].end()) && |
Santosh Puranik | 50f60bf | 2021-05-26 17:55:06 +0530 | [diff] [blame] | 1422 | (file == systemVpdFilePath)) |
PriyangaRamasamy | 647868e | 2020-09-08 17:03:19 +0530 | [diff] [blame] | 1423 | { |
Santosh Puranik | 6b2b537 | 2022-06-02 20:49:02 +0530 | [diff] [blame] | 1424 | // We have already collected system VPD, skip. |
PriyangaRamasamy | 647868e | 2020-09-08 17:03:19 +0530 | [diff] [blame] | 1425 | return 0; |
| 1426 | } |
| 1427 | } |
| 1428 | |
| 1429 | if (file.empty()) |
| 1430 | { |
| 1431 | cerr << "The EEPROM path <" << file << "> is not valid."; |
| 1432 | return 0; |
| 1433 | } |
Santosh Puranik | 12e24ff | 2021-05-11 19:33:50 +0530 | [diff] [blame] | 1434 | if (js["frus"].find(file) == js["frus"].end()) |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1435 | { |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 1436 | return 0; |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1437 | } |
| 1438 | |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 1439 | if (!fs::exists(file)) |
| 1440 | { |
| 1441 | cout << "Device path: " << file |
jinuthomas | d640f69 | 2023-03-28 04:13:23 -0500 | [diff] [blame] | 1442 | << " does not exist. Spurious udev event? Exiting." |
| 1443 | << std::endl; |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 1444 | return 0; |
| 1445 | } |
| 1446 | |
Santosh Puranik | dedb5a6 | 2022-12-19 23:58:32 +0530 | [diff] [blame] | 1447 | // In case of system VPD it will already be filled, Don't have to |
| 1448 | // overwrite that. |
| 1449 | if (baseFruInventoryPath.empty()) |
| 1450 | { |
| 1451 | baseFruInventoryPath = js["frus"][file][0]["inventoryPath"]; |
| 1452 | } |
| 1453 | |
Santosh Puranik | 8589375 | 2020-11-10 21:31:43 +0530 | [diff] [blame] | 1454 | // Check if we can read the VPD file based on the power state |
Santosh Puranik | 27a5e95 | 2021-10-07 22:08:01 -0500 | [diff] [blame] | 1455 | // We skip reading VPD when the power is ON in two scenarios: |
Santosh Puranik | 31d50fa | 2022-04-04 12:04:37 +0530 | [diff] [blame] | 1456 | // 1) The eeprom we are trying to read is that of the system VPD and the |
| 1457 | // JSON symlink is already setup (the symlink's existence tells us we |
| 1458 | // are not coming out of a factory reset) |
| 1459 | // 2) The JSON tells us that the FRU EEPROM cannot be |
| 1460 | // read when we are powered ON. |
Santosh Puranik | 27a5e95 | 2021-10-07 22:08:01 -0500 | [diff] [blame] | 1461 | if (js["frus"][file].at(0).value("powerOffOnly", false) || |
Santosh Puranik | 31d50fa | 2022-04-04 12:04:37 +0530 | [diff] [blame] | 1462 | (file == systemVpdFilePath && fs::exists(INVENTORY_JSON_SYM_LINK))) |
Santosh Puranik | 8589375 | 2020-11-10 21:31:43 +0530 | [diff] [blame] | 1463 | { |
| 1464 | if ("xyz.openbmc_project.State.Chassis.PowerState.On" == |
| 1465 | getPowerState()) |
| 1466 | { |
jinuthomas | d640f69 | 2023-03-28 04:13:23 -0500 | [diff] [blame] | 1467 | cout << "This VPD cannot be read when power is ON" << std::endl; |
Santosh Puranik | 8589375 | 2020-11-10 21:31:43 +0530 | [diff] [blame] | 1468 | return 0; |
| 1469 | } |
| 1470 | } |
SunnySrivastava1984 | a20be8e | 2020-08-26 02:00:50 -0500 | [diff] [blame] | 1471 | |
Santosh Puranik | e9c5753 | 2022-03-15 16:51:51 +0530 | [diff] [blame] | 1472 | // Check if this VPD should be recollected at all |
| 1473 | if (!needsRecollection(js, file)) |
| 1474 | { |
jinuthomas | d640f69 | 2023-03-28 04:13:23 -0500 | [diff] [blame] | 1475 | cout << "Skip VPD recollection for: " << file << std::endl; |
Santosh Puranik | e9c5753 | 2022-03-15 16:51:51 +0530 | [diff] [blame] | 1476 | return 0; |
| 1477 | } |
| 1478 | |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 1479 | try |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1480 | { |
girik | 18bb985 | 2022-11-16 05:48:13 -0600 | [diff] [blame] | 1481 | uint32_t vpdStartOffset = 0; |
| 1482 | for (const auto& item : js["frus"][file]) |
| 1483 | { |
| 1484 | if (item.find("offset") != item.end()) |
| 1485 | { |
| 1486 | vpdStartOffset = item["offset"]; |
| 1487 | } |
| 1488 | } |
PriyangaRamasamy | c2fe40f | 2021-03-02 06:27:33 -0600 | [diff] [blame] | 1489 | vpdVector = getVpdDataInVector(js, file); |
Sunny Srivastava | f31a91b | 2022-06-09 08:11:29 -0500 | [diff] [blame] | 1490 | ParserInterface* parser = ParserFactory::getParser( |
girik | 18bb985 | 2022-11-16 05:48:13 -0600 | [diff] [blame] | 1491 | vpdVector, (pimPath + baseFruInventoryPath), file, |
| 1492 | vpdStartOffset); |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 1493 | variant<KeywordVpdMap, Store> parseResult; |
| 1494 | parseResult = parser->parse(); |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 1495 | |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 1496 | if (auto pVal = get_if<Store>(&parseResult)) |
| 1497 | { |
| 1498 | populateDbus(pVal->getVpdMap(), js, file); |
| 1499 | } |
| 1500 | else if (auto pVal = get_if<KeywordVpdMap>(&parseResult)) |
| 1501 | { |
| 1502 | populateDbus(*pVal, js, file); |
| 1503 | } |
| 1504 | |
| 1505 | // release the parser object |
| 1506 | ParserFactory::freeParser(parser); |
| 1507 | } |
Patrick Williams | 8e15b93 | 2021-10-06 13:04:22 -0500 | [diff] [blame] | 1508 | catch (const exception& e) |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 1509 | { |
Alpana Kumari | 735dee9 | 2022-03-25 01:24:40 -0500 | [diff] [blame] | 1510 | executePostFailAction(js, file); |
PriyangaRamasamy | a504c3e | 2020-12-06 12:14:52 -0600 | [diff] [blame] | 1511 | throw; |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 1512 | } |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1513 | } |
SunnySrivastava1984 | a20be8e | 2020-08-26 02:00:50 -0500 | [diff] [blame] | 1514 | catch (const VpdJsonException& ex) |
| 1515 | { |
| 1516 | additionalData.emplace("JSON_PATH", ex.getJsonPath()); |
| 1517 | additionalData.emplace("DESCRIPTION", ex.what()); |
Sunny Srivastava | a2ddc96 | 2022-06-29 08:53:16 -0500 | [diff] [blame] | 1518 | createPEL(additionalData, pelSeverity, errIntfForJsonFailure, nullptr); |
SunnySrivastava1984 | a20be8e | 2020-08-26 02:00:50 -0500 | [diff] [blame] | 1519 | |
| 1520 | cerr << ex.what() << "\n"; |
| 1521 | rc = -1; |
| 1522 | } |
| 1523 | catch (const VpdEccException& ex) |
| 1524 | { |
| 1525 | additionalData.emplace("DESCRIPTION", "ECC check failed"); |
| 1526 | additionalData.emplace("CALLOUT_INVENTORY_PATH", |
| 1527 | INVENTORY_PATH + baseFruInventoryPath); |
Sunny Srivastava | a2ddc96 | 2022-06-29 08:53:16 -0500 | [diff] [blame] | 1528 | createPEL(additionalData, pelSeverity, errIntfForEccCheckFail, nullptr); |
PriyangaRamasamy | c2fe40f | 2021-03-02 06:27:33 -0600 | [diff] [blame] | 1529 | dumpBadVpd(file, vpdVector); |
SunnySrivastava1984 | a20be8e | 2020-08-26 02:00:50 -0500 | [diff] [blame] | 1530 | cerr << ex.what() << "\n"; |
| 1531 | rc = -1; |
| 1532 | } |
| 1533 | catch (const VpdDataException& ex) |
| 1534 | { |
alpana07 | 5cb3b1f | 2021-12-16 11:19:36 -0600 | [diff] [blame] | 1535 | if (isThisPcieOnPass1planar(js, file)) |
| 1536 | { |
| 1537 | cout << "Pcie_device [" << file |
| 1538 | << "]'s VPD is not valid on PASS1 planar.Ignoring.\n"; |
| 1539 | rc = 0; |
| 1540 | } |
Santosh Puranik | 53b38ed | 2022-04-10 23:15:22 +0530 | [diff] [blame] | 1541 | else if (!(isPresent(js, file).value_or(true))) |
| 1542 | { |
| 1543 | cout << "FRU at: " << file |
| 1544 | << " is not detected present. Ignore parser error.\n"; |
| 1545 | rc = 0; |
| 1546 | } |
alpana07 | 5cb3b1f | 2021-12-16 11:19:36 -0600 | [diff] [blame] | 1547 | else |
| 1548 | { |
| 1549 | string errorMsg = |
| 1550 | "VPD file is either empty or invalid. Parser failed for ["; |
| 1551 | errorMsg += file; |
| 1552 | errorMsg += "], with error = " + std::string(ex.what()); |
| 1553 | |
| 1554 | additionalData.emplace("DESCRIPTION", errorMsg); |
| 1555 | additionalData.emplace("CALLOUT_INVENTORY_PATH", |
| 1556 | INVENTORY_PATH + baseFruInventoryPath); |
Sunny Srivastava | a2ddc96 | 2022-06-29 08:53:16 -0500 | [diff] [blame] | 1557 | createPEL(additionalData, pelSeverity, errIntfForInvalidVPD, |
| 1558 | nullptr); |
alpana07 | 5cb3b1f | 2021-12-16 11:19:36 -0600 | [diff] [blame] | 1559 | |
| 1560 | rc = -1; |
| 1561 | } |
SunnySrivastava1984 | a20be8e | 2020-08-26 02:00:50 -0500 | [diff] [blame] | 1562 | } |
Patrick Williams | 8e15b93 | 2021-10-06 13:04:22 -0500 | [diff] [blame] | 1563 | catch (const exception& e) |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1564 | { |
PriyangaRamasamy | c2fe40f | 2021-03-02 06:27:33 -0600 | [diff] [blame] | 1565 | dumpBadVpd(file, vpdVector); |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1566 | cerr << e.what() << "\n"; |
| 1567 | rc = -1; |
| 1568 | } |
| 1569 | |
| 1570 | return rc; |
Alpana Kumari | 735dee9 | 2022-03-25 01:24:40 -0500 | [diff] [blame] | 1571 | } |