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 | { |
jinuthomas | f457a3e | 2023-04-13 12:22:48 -0500 | [diff] [blame^] | 206 | std::cerr << "Failed to expand location code with exception: " |
| 207 | << e.what() << "\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 | { |
jinuthomas | f457a3e | 2023-04-13 12:22:48 -0500 | [diff] [blame^] | 265 | std::cerr << "Unknown Keyword[" << kw << "] found "; |
jinuthomas | d640f69 | 2023-03-28 04:13:23 -0500 | [diff] [blame] | 266 | } |
| 267 | } |
| 268 | else |
| 269 | { |
jinuthomas | f457a3e | 2023-04-13 12:22:48 -0500 | [diff] [blame^] | 270 | std::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 | f457a3e | 2023-04-13 12:22:48 -0500 | [diff] [blame^] | 511 | std::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 | f457a3e | 2023-04-13 12:22:48 -0500 | [diff] [blame^] | 514 | std::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 | { |
jinuthomas | f457a3e | 2023-04-13 12:22:48 -0500 | [diff] [blame^] | 520 | std::cerr << "EEPROM " << file |
| 521 | << " does not exist. Take failure action" |
| 522 | << std::endl; |
Sunny Srivastava | a2ddc96 | 2022-06-29 08:53:16 -0500 | [diff] [blame] | 523 | // If not, then take failure postAction |
| 524 | executePostFailAction(json, file); |
| 525 | } |
| 526 | } |
| 527 | else |
| 528 | { |
| 529 | // missing required informations |
jinuthomas | f457a3e | 2023-04-13 12:22:48 -0500 | [diff] [blame^] | 530 | std::cerr << "VPD inventory JSON missing basic informations of " |
| 531 | "preAction " |
| 532 | "for this FRU : [" |
| 533 | << file << "]. Executing executePostFailAction." |
| 534 | << std::endl; |
Sunny Srivastava | a2ddc96 | 2022-06-29 08:53:16 -0500 | [diff] [blame] | 535 | |
| 536 | // Take failure postAction |
Alpana Kumari | 40d1c19 | 2022-03-09 21:16:02 -0600 | [diff] [blame] | 537 | executePostFailAction(json, file); |
Sunny Srivastava | a2ddc96 | 2022-06-29 08:53:16 -0500 | [diff] [blame] | 538 | return; |
Alpana Kumari | 40d1c19 | 2022-03-09 21:16:02 -0600 | [diff] [blame] | 539 | } |
| 540 | } |
Santosh Puranik | dedb5a6 | 2022-12-19 23:58:32 +0530 | [diff] [blame] | 541 | else |
| 542 | { |
| 543 | // If the FRU is not there, clear the VINI/CCIN data. |
| 544 | // Enity manager probes for this keyword to look for this |
| 545 | // FRU, now if the data is persistent on BMC and FRU is |
| 546 | // removed this can lead to ambiguity. Hence clearing this |
| 547 | // Keyword if FRU is absent. |
| 548 | const auto& invPath = |
| 549 | json["frus"][file].at(0).value("inventoryPath", ""); |
| 550 | |
| 551 | if (!invPath.empty()) |
| 552 | { |
| 553 | inventory::ObjectMap pimObjMap{ |
| 554 | {invPath, {{"com.ibm.ipzvpd.VINI", {{"CC", Binary{}}}}}}}; |
| 555 | |
| 556 | common::utility::callPIM(move(pimObjMap)); |
| 557 | } |
| 558 | else |
| 559 | { |
| 560 | throw std::runtime_error("Path empty in Json"); |
| 561 | } |
| 562 | } |
Sunny Srivastava | a2ddc96 | 2022-06-29 08:53:16 -0500 | [diff] [blame] | 563 | } |
| 564 | catch (const GpioException& e) |
| 565 | { |
| 566 | PelAdditionalData additionalData{}; |
| 567 | additionalData.emplace("DESCRIPTION", e.what()); |
| 568 | createPEL(additionalData, PelSeverity::WARNING, errIntfForGpioError, |
| 569 | nullptr); |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 570 | } |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 571 | } |
| 572 | |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 573 | /** |
Santosh Puranik | f3e6968 | 2022-03-31 17:52:38 +0530 | [diff] [blame] | 574 | * @brief Fills the Decorator.AssetTag property into the interfaces map |
| 575 | * |
| 576 | * This function should only be called in cases where we did not find a JSON |
| 577 | * symlink. A missing symlink in /var/lib will be considered as a factory reset |
| 578 | * and this function will be used to default the AssetTag property. |
| 579 | * |
| 580 | * @param interfaces A possibly pre-populated map of inetrfaces to properties. |
| 581 | * @param vpdMap A VPD map of the system VPD data. |
| 582 | */ |
| 583 | static void fillAssetTag(inventory::InterfaceMap& interfaces, |
| 584 | const Parsed& vpdMap) |
| 585 | { |
| 586 | // Read the system serial number and MTM |
| 587 | // Default asset tag is Server-MTM-System Serial |
| 588 | inventory::Interface assetIntf{ |
| 589 | "xyz.openbmc_project.Inventory.Decorator.AssetTag"}; |
| 590 | inventory::PropertyMap assetTagProps; |
| 591 | std::string defaultAssetTag = |
| 592 | std::string{"Server-"} + getKwVal(vpdMap, "VSYS", "TM") + |
| 593 | std::string{"-"} + getKwVal(vpdMap, "VSYS", "SE"); |
| 594 | assetTagProps.emplace("AssetTag", defaultAssetTag); |
| 595 | insertOrMerge(interfaces, assetIntf, std::move(assetTagProps)); |
| 596 | } |
| 597 | |
| 598 | /** |
Santosh Puranik | d3a379a | 2021-08-23 19:12:59 +0530 | [diff] [blame] | 599 | * @brief Set certain one time properties in the inventory |
| 600 | * Use this function to insert the Functional and Enabled properties into the |
| 601 | * inventory map. This function first checks if the object in question already |
| 602 | * has these properties hosted on D-Bus, if the property is already there, it is |
| 603 | * not modified, hence the name "one time". If the property is not already |
| 604 | * 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] | 605 | * Functional and Enabled) |
Santosh Puranik | d3a379a | 2021-08-23 19:12:59 +0530 | [diff] [blame] | 606 | * |
| 607 | * @param[in] object - The inventory D-Bus obejct without the inventory prefix. |
| 608 | * @param[inout] interfaces - Reference to a map of inventory interfaces to |
| 609 | * which the properties will be attached. |
| 610 | */ |
| 611 | static void setOneTimeProperties(const std::string& object, |
| 612 | inventory::InterfaceMap& interfaces) |
| 613 | { |
| 614 | auto bus = sdbusplus::bus::new_default(); |
| 615 | auto objectPath = INVENTORY_PATH + object; |
| 616 | auto prop = bus.new_method_call("xyz.openbmc_project.Inventory.Manager", |
| 617 | objectPath.c_str(), |
| 618 | "org.freedesktop.DBus.Properties", "Get"); |
| 619 | prop.append("xyz.openbmc_project.State.Decorator.OperationalStatus"); |
| 620 | prop.append("Functional"); |
| 621 | try |
| 622 | { |
| 623 | auto result = bus.call(prop); |
| 624 | } |
| 625 | catch (const sdbusplus::exception::SdBusError& e) |
| 626 | { |
| 627 | // Treat as property unavailable |
| 628 | inventory::PropertyMap prop; |
| 629 | prop.emplace("Functional", true); |
| 630 | interfaces.emplace( |
| 631 | "xyz.openbmc_project.State.Decorator.OperationalStatus", |
| 632 | move(prop)); |
| 633 | } |
| 634 | prop = bus.new_method_call("xyz.openbmc_project.Inventory.Manager", |
| 635 | objectPath.c_str(), |
| 636 | "org.freedesktop.DBus.Properties", "Get"); |
| 637 | prop.append("xyz.openbmc_project.Object.Enable"); |
| 638 | prop.append("Enabled"); |
| 639 | try |
| 640 | { |
| 641 | auto result = bus.call(prop); |
| 642 | } |
| 643 | catch (const sdbusplus::exception::SdBusError& e) |
| 644 | { |
| 645 | // Treat as property unavailable |
| 646 | inventory::PropertyMap prop; |
Santosh Puranik | dedb5a6 | 2022-12-19 23:58:32 +0530 | [diff] [blame] | 647 | prop.emplace("Enabled", true); |
Santosh Puranik | d3a379a | 2021-08-23 19:12:59 +0530 | [diff] [blame] | 648 | interfaces.emplace("xyz.openbmc_project.Object.Enable", move(prop)); |
| 649 | } |
| 650 | } |
| 651 | |
| 652 | /** |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 653 | * @brief Prime the Inventory |
| 654 | * Prime the inventory by populating only the location code, |
| 655 | * type interface and the inventory object for the frus |
| 656 | * which are not system vpd fru. |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 657 | * |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 658 | * @param[in] jsObject - Reference to vpd inventory json object |
| 659 | * @param[in] vpdMap - Reference to the parsed vpd map |
| 660 | * |
| 661 | * @returns Map of items in extraInterface. |
| 662 | */ |
| 663 | template <typename T> |
| 664 | inventory::ObjectMap primeInventory(const nlohmann::json& jsObject, |
| 665 | const T& vpdMap) |
| 666 | { |
| 667 | inventory::ObjectMap objects; |
| 668 | |
| 669 | for (auto& itemFRUS : jsObject["frus"].items()) |
| 670 | { |
| 671 | for (auto& itemEEPROM : itemFRUS.value()) |
| 672 | { |
Alpana Kumari | 2e6c6f7 | 2020-12-03 00:10:03 -0600 | [diff] [blame] | 673 | // Take pre actions if needed |
| 674 | if (itemEEPROM.find("preAction") != itemEEPROM.end()) |
| 675 | { |
| 676 | preAction(jsObject, itemFRUS.key()); |
| 677 | } |
| 678 | |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 679 | inventory::InterfaceMap interfaces; |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 680 | inventory::Object object(itemEEPROM.at("inventoryPath")); |
| 681 | |
Santosh Puranik | 50f60bf | 2021-05-26 17:55:06 +0530 | [diff] [blame] | 682 | if ((itemFRUS.key() != systemVpdFilePath) && |
| 683 | !itemEEPROM.value("noprime", false)) |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 684 | { |
Alpana Kumari | cfd7a75 | 2021-02-07 23:23:01 -0600 | [diff] [blame] | 685 | inventory::PropertyMap presProp; |
Priyanga Ramasamy | e358acb | 2022-03-21 14:21:50 -0500 | [diff] [blame] | 686 | |
| 687 | // Do not populate Present property for frus whose |
Priyanga Ramasamy | aca6137 | 2023-01-24 08:02:28 -0600 | [diff] [blame] | 688 | // synthesized=true. synthesized=true says the fru VPD is |
| 689 | // synthesized and owned by a separate component. |
| 690 | // In some cases, the FRU has its own VPD, but still a separate |
| 691 | // application handles the FRU's presence. So VPD parser skips |
| 692 | // populating Present property by checking the JSON flag, |
| 693 | // "handlePresence". |
Priyanga Ramasamy | e358acb | 2022-03-21 14:21:50 -0500 | [diff] [blame] | 694 | if (!itemEEPROM.value("synthesized", false)) |
| 695 | { |
Priyanga Ramasamy | aca6137 | 2023-01-24 08:02:28 -0600 | [diff] [blame] | 696 | if (itemEEPROM.value("handlePresence", true)) |
| 697 | { |
| 698 | presProp.emplace("Present", false); |
| 699 | interfaces.emplace("xyz.openbmc_project.Inventory.Item", |
| 700 | presProp); |
| 701 | } |
Priyanga Ramasamy | e358acb | 2022-03-21 14:21:50 -0500 | [diff] [blame] | 702 | } |
Priyanga Ramasamy | aca6137 | 2023-01-24 08:02:28 -0600 | [diff] [blame] | 703 | |
Santosh Puranik | d3a379a | 2021-08-23 19:12:59 +0530 | [diff] [blame] | 704 | setOneTimeProperties(object, interfaces); |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 705 | if (itemEEPROM.find("extraInterfaces") != itemEEPROM.end()) |
| 706 | { |
| 707 | for (const auto& eI : itemEEPROM["extraInterfaces"].items()) |
| 708 | { |
| 709 | inventory::PropertyMap props; |
Alpana Kumari | 414d5ae | 2021-03-04 21:06:35 +0000 | [diff] [blame] | 710 | if (eI.key() == IBM_LOCATION_CODE_INF) |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 711 | { |
| 712 | if constexpr (std::is_same<T, Parsed>::value) |
| 713 | { |
| 714 | for (auto& lC : eI.value().items()) |
| 715 | { |
| 716 | auto propVal = expandLocationCode( |
| 717 | lC.value().get<string>(), vpdMap, true); |
| 718 | |
| 719 | props.emplace(move(lC.key()), |
| 720 | move(propVal)); |
Santosh Puranik | b0f3749 | 2021-06-21 09:42:47 +0530 | [diff] [blame] | 721 | interfaces.emplace(XYZ_LOCATION_CODE_INF, |
| 722 | props); |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 723 | interfaces.emplace(move(eI.key()), |
| 724 | move(props)); |
| 725 | } |
| 726 | } |
| 727 | } |
| 728 | else if (eI.key().find("Inventory.Item.") != |
| 729 | string::npos) |
| 730 | { |
| 731 | interfaces.emplace(move(eI.key()), move(props)); |
| 732 | } |
Santosh Puranik | d3a379a | 2021-08-23 19:12:59 +0530 | [diff] [blame] | 733 | else if (eI.key() == |
| 734 | "xyz.openbmc_project.Inventory.Item") |
| 735 | { |
| 736 | for (auto& val : eI.value().items()) |
| 737 | { |
| 738 | if (val.key() == "PrettyName") |
| 739 | { |
| 740 | presProp.emplace(val.key(), |
| 741 | val.value().get<string>()); |
| 742 | } |
| 743 | } |
| 744 | // Use insert_or_assign here as we may already have |
| 745 | // inserted the present property only earlier in |
| 746 | // this function under this same interface. |
| 747 | interfaces.insert_or_assign(eI.key(), |
| 748 | move(presProp)); |
| 749 | } |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 750 | } |
| 751 | } |
| 752 | objects.emplace(move(object), move(interfaces)); |
| 753 | } |
| 754 | } |
| 755 | } |
| 756 | return objects; |
| 757 | } |
| 758 | |
Alpana Kumari | 65b8360 | 2020-09-01 00:24:56 -0500 | [diff] [blame] | 759 | /** |
| 760 | * @brief This API executes command to set environment variable |
| 761 | * And then reboot the system |
| 762 | * @param[in] key -env key to set new value |
| 763 | * @param[in] value -value to set. |
| 764 | */ |
| 765 | void setEnvAndReboot(const string& key, const string& value) |
| 766 | { |
| 767 | // set env and reboot and break. |
| 768 | executeCmd("/sbin/fw_setenv", key, value); |
Andrew Geissler | 280197e | 2020-12-08 20:51:49 -0600 | [diff] [blame] | 769 | log<level::INFO>("Rebooting BMC to pick up new device tree"); |
Alpana Kumari | 65b8360 | 2020-09-01 00:24:56 -0500 | [diff] [blame] | 770 | // make dbus call to reboot |
| 771 | auto bus = sdbusplus::bus::new_default_system(); |
| 772 | auto method = bus.new_method_call( |
| 773 | "org.freedesktop.systemd1", "/org/freedesktop/systemd1", |
| 774 | "org.freedesktop.systemd1.Manager", "Reboot"); |
| 775 | bus.call_noreply(method); |
| 776 | } |
| 777 | |
| 778 | /* |
| 779 | * @brief This API checks for env var fitconfig. |
| 780 | * If not initialised OR updated as per the current system type, |
| 781 | * update this env var and reboot the system. |
| 782 | * |
| 783 | * @param[in] systemType IM kwd in vpd tells about which system type it is. |
| 784 | * */ |
| 785 | void setDevTreeEnv(const string& systemType) |
| 786 | { |
Alpana Kumari | 37e7270 | 2021-11-18 11:18:04 -0600 | [diff] [blame] | 787 | // Init with default dtb |
| 788 | string newDeviceTree = "conf-aspeed-bmc-ibm-rainier-p1.dtb"; |
Santosh Puranik | e5f177a | 2022-01-24 20:14:46 +0530 | [diff] [blame] | 789 | static const deviceTreeMap deviceTreeSystemTypeMap = { |
| 790 | {RAINIER_2U, "conf-aspeed-bmc-ibm-rainier-p1.dtb"}, |
| 791 | {RAINIER_2U_V2, "conf-aspeed-bmc-ibm-rainier.dtb"}, |
| 792 | {RAINIER_4U, "conf-aspeed-bmc-ibm-rainier-4u-p1.dtb"}, |
| 793 | {RAINIER_4U_V2, "conf-aspeed-bmc-ibm-rainier-4u.dtb"}, |
| 794 | {RAINIER_1S4U, "conf-aspeed-bmc-ibm-rainier-1s4u.dtb"}, |
Alpana Kumari | 1b02611 | 2022-03-02 23:41:38 -0600 | [diff] [blame] | 795 | {EVEREST, "conf-aspeed-bmc-ibm-everest.dtb"}, |
Santosh Puranik | dedb5a6 | 2022-12-19 23:58:32 +0530 | [diff] [blame] | 796 | {EVEREST_V2, "conf-aspeed-bmc-ibm-everest.dtb"}, |
| 797 | {BONNELL, "conf-aspeed-bmc-ibm-bonnell.dtb"}}; |
Alpana Kumari | 65b8360 | 2020-09-01 00:24:56 -0500 | [diff] [blame] | 798 | |
| 799 | if (deviceTreeSystemTypeMap.find(systemType) != |
| 800 | deviceTreeSystemTypeMap.end()) |
| 801 | { |
| 802 | newDeviceTree = deviceTreeSystemTypeMap.at(systemType); |
| 803 | } |
Alpana Kumari | 37e7270 | 2021-11-18 11:18:04 -0600 | [diff] [blame] | 804 | else |
| 805 | { |
| 806 | // System type not supported |
Alpana Kumari | ab1e22c | 2021-11-24 11:03:38 -0600 | [diff] [blame] | 807 | string err = "This System type not found/supported in dtb table " + |
| 808 | systemType + |
| 809 | ".Please check the HW and IM keywords in the system " |
| 810 | "VPD.Breaking..."; |
| 811 | |
| 812 | // map to hold additional data in case of logging pel |
| 813 | PelAdditionalData additionalData{}; |
| 814 | additionalData.emplace("DESCRIPTION", err); |
| 815 | createPEL(additionalData, PelSeverity::WARNING, |
Sunny Srivastava | a2ddc96 | 2022-06-29 08:53:16 -0500 | [diff] [blame] | 816 | errIntfForInvalidSystemType, nullptr); |
Alpana Kumari | ab1e22c | 2021-11-24 11:03:38 -0600 | [diff] [blame] | 817 | exit(-1); |
Alpana Kumari | 37e7270 | 2021-11-18 11:18:04 -0600 | [diff] [blame] | 818 | } |
Alpana Kumari | 65b8360 | 2020-09-01 00:24:56 -0500 | [diff] [blame] | 819 | |
| 820 | string readVarValue; |
| 821 | bool envVarFound = false; |
| 822 | |
| 823 | vector<string> output = executeCmd("/sbin/fw_printenv"); |
| 824 | for (const auto& entry : output) |
| 825 | { |
| 826 | size_t pos = entry.find("="); |
| 827 | string key = entry.substr(0, pos); |
| 828 | if (key != "fitconfig") |
| 829 | { |
| 830 | continue; |
| 831 | } |
| 832 | |
| 833 | envVarFound = true; |
| 834 | if (pos + 1 < entry.size()) |
| 835 | { |
| 836 | readVarValue = entry.substr(pos + 1); |
| 837 | if (readVarValue.find(newDeviceTree) != string::npos) |
| 838 | { |
| 839 | // fitconfig is Updated. No action needed |
| 840 | break; |
| 841 | } |
| 842 | } |
| 843 | // set env and reboot and break. |
| 844 | setEnvAndReboot(key, newDeviceTree); |
| 845 | exit(0); |
| 846 | } |
| 847 | |
| 848 | // check If env var Not found |
| 849 | if (!envVarFound) |
| 850 | { |
| 851 | setEnvAndReboot("fitconfig", newDeviceTree); |
| 852 | } |
| 853 | } |
| 854 | |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 855 | /** |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 856 | * @brief API to check if we need to restore system VPD |
| 857 | * This functionality is only applicable for IPZ VPD data. |
| 858 | * @param[in] vpdMap - IPZ vpd map |
| 859 | * @param[in] objectPath - Object path for the FRU |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 860 | */ |
Sunny Srivastava | 3c24414 | 2022-01-11 08:47:04 -0600 | [diff] [blame] | 861 | void restoreSystemVPD(Parsed& vpdMap, const string& objectPath) |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 862 | { |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 863 | for (const auto& systemRecKwdPair : svpdKwdMap) |
| 864 | { |
| 865 | auto it = vpdMap.find(systemRecKwdPair.first); |
| 866 | |
| 867 | // check if record is found in map we got by parser |
| 868 | if (it != vpdMap.end()) |
| 869 | { |
| 870 | const auto& kwdListForRecord = systemRecKwdPair.second; |
Priyanga Ramasamy | 952d6c5 | 2022-11-07 07:20:24 -0600 | [diff] [blame] | 871 | for (const auto& keywordInfo : kwdListForRecord) |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 872 | { |
Priyanga Ramasamy | 952d6c5 | 2022-11-07 07:20:24 -0600 | [diff] [blame] | 873 | const auto keyword = get<0>(keywordInfo); |
| 874 | |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 875 | DbusPropertyMap& kwdValMap = it->second; |
| 876 | auto iterator = kwdValMap.find(keyword); |
| 877 | |
| 878 | if (iterator != kwdValMap.end()) |
| 879 | { |
| 880 | string& kwdValue = iterator->second; |
| 881 | |
| 882 | // check bus data |
| 883 | const string& recordName = systemRecKwdPair.first; |
| 884 | const string& busValue = readBusProperty( |
| 885 | objectPath, ipzVpdInf + recordName, keyword); |
| 886 | |
Priyanga Ramasamy | 952d6c5 | 2022-11-07 07:20:24 -0600 | [diff] [blame] | 887 | const auto& defaultValue = get<1>(keywordInfo); |
| 888 | Binary busDataInBinary(busValue.begin(), busValue.end()); |
| 889 | Binary kwdDataInBinary(kwdValue.begin(), kwdValue.end()); |
Sunny Srivastava | a559c2d | 2022-05-02 11:56:45 -0500 | [diff] [blame] | 890 | |
Priyanga Ramasamy | 952d6c5 | 2022-11-07 07:20:24 -0600 | [diff] [blame] | 891 | if (busDataInBinary != defaultValue) |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 892 | { |
Priyanga Ramasamy | 952d6c5 | 2022-11-07 07:20:24 -0600 | [diff] [blame] | 893 | if (kwdDataInBinary != defaultValue) |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 894 | { |
| 895 | // both the data are present, check for mismatch |
| 896 | if (busValue != kwdValue) |
| 897 | { |
Priyanga Ramasamy | 2494223 | 2023-01-05 04:54:59 -0600 | [diff] [blame] | 898 | string errMsg = "Mismatch found between backup " |
| 899 | "and primary VPD for record: "; |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 900 | errMsg += (*it).first; |
| 901 | errMsg += " and keyword: "; |
| 902 | errMsg += keyword; |
| 903 | |
Santosh Puranik | dedb5a6 | 2022-12-19 23:58:32 +0530 | [diff] [blame] | 904 | std::ostringstream busStream; |
| 905 | for (uint16_t byte : busValue) |
| 906 | { |
| 907 | busStream << std::setfill('0') |
| 908 | << std::setw(2) << std::hex |
| 909 | << "0x" << byte << " "; |
| 910 | } |
| 911 | |
| 912 | std::ostringstream vpdStream; |
| 913 | for (uint16_t byte : kwdValue) |
| 914 | { |
| 915 | vpdStream << std::setfill('0') |
| 916 | << std::setw(2) << std::hex |
| 917 | << "0x" << byte << " "; |
| 918 | } |
| 919 | |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 920 | // data mismatch |
| 921 | PelAdditionalData additionalData; |
| 922 | additionalData.emplace("CALLOUT_INVENTORY_PATH", |
Priyanga Ramasamy | f612368 | 2022-12-02 07:29:07 -0600 | [diff] [blame] | 923 | INVENTORY_PATH + |
| 924 | objectPath); |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 925 | |
| 926 | additionalData.emplace("DESCRIPTION", errMsg); |
Santosh Puranik | dedb5a6 | 2022-12-19 23:58:32 +0530 | [diff] [blame] | 927 | additionalData.emplace( |
Priyanga Ramasamy | 2494223 | 2023-01-05 04:54:59 -0600 | [diff] [blame] | 928 | "Value read from Backup: ", |
| 929 | busStream.str()); |
| 930 | additionalData.emplace( |
| 931 | "Value read from Primary: ", |
Santosh Puranik | dedb5a6 | 2022-12-19 23:58:32 +0530 | [diff] [blame] | 932 | vpdStream.str()); |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 933 | |
Sunny Srivastava | 0746eee | 2021-03-22 13:36:54 -0500 | [diff] [blame] | 934 | createPEL(additionalData, PelSeverity::WARNING, |
Priyanga Ramasamy | 2494223 | 2023-01-05 04:54:59 -0600 | [diff] [blame] | 935 | errIntfForVPDMismatch, nullptr); |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 936 | } |
| 937 | } |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 938 | |
Priyanga Ramasamy | 2494223 | 2023-01-05 04:54:59 -0600 | [diff] [blame] | 939 | // If backup data is not default, then irrespective of |
| 940 | // primary data(default or other than backup), copy the |
| 941 | // backup data to vpd map as we don't need to change the |
| 942 | // backup data in either case in the process of |
Santosh Puranik | dedb5a6 | 2022-12-19 23:58:32 +0530 | [diff] [blame] | 943 | // restoring system vpd. |
Santosh Puranik | dedb5a6 | 2022-12-19 23:58:32 +0530 | [diff] [blame] | 944 | kwdValue = busValue; |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 945 | } |
Priyanga Ramasamy | 952d6c5 | 2022-11-07 07:20:24 -0600 | [diff] [blame] | 946 | else if (kwdDataInBinary == defaultValue && |
| 947 | get<2>(keywordInfo)) // Check isPELRequired is true |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 948 | { |
Priyanga Ramasamy | 2494223 | 2023-01-05 04:54:59 -0600 | [diff] [blame] | 949 | string errMsg = "Found default value on both backup " |
| 950 | "and primary VPD for record: "; |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 951 | errMsg += (*it).first; |
| 952 | errMsg += " and keyword: "; |
| 953 | errMsg += keyword; |
Priyanga Ramasamy | 2494223 | 2023-01-05 04:54:59 -0600 | [diff] [blame] | 954 | errMsg += ". SSR need to update primary VPD."; |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 955 | |
Priyanga Ramasamy | 2494223 | 2023-01-05 04:54:59 -0600 | [diff] [blame] | 956 | // mfg default on both backup and primary, log PEL |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 957 | PelAdditionalData additionalData; |
| 958 | additionalData.emplace("CALLOUT_INVENTORY_PATH", |
Priyanga Ramasamy | f612368 | 2022-12-02 07:29:07 -0600 | [diff] [blame] | 959 | INVENTORY_PATH + objectPath); |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 960 | |
| 961 | additionalData.emplace("DESCRIPTION", errMsg); |
| 962 | |
| 963 | // log PEL TODO: Block IPL |
Sunny Srivastava | 0746eee | 2021-03-22 13:36:54 -0500 | [diff] [blame] | 964 | createPEL(additionalData, PelSeverity::ERROR, |
Priyanga Ramasamy | 2494223 | 2023-01-05 04:54:59 -0600 | [diff] [blame] | 965 | errIntfForVPDDefault, nullptr); |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 966 | continue; |
| 967 | } |
| 968 | } |
| 969 | } |
| 970 | } |
| 971 | } |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | /** |
alpana07 | 7ce6872 | 2021-07-25 13:23:59 -0500 | [diff] [blame] | 975 | * @brief This checks for is this FRU a processor |
| 976 | * And if yes, then checks for is this primary |
| 977 | * |
| 978 | * @param[in] js- vpd json to get the information about this FRU |
| 979 | * @param[in] filePath- FRU vpd |
| 980 | * |
| 981 | * @return true/false |
| 982 | */ |
| 983 | bool isThisPrimaryProcessor(nlohmann::json& js, const string& filePath) |
| 984 | { |
| 985 | bool isProcessor = false; |
| 986 | bool isPrimary = false; |
| 987 | |
| 988 | for (const auto& item : js["frus"][filePath]) |
| 989 | { |
| 990 | if (item.find("extraInterfaces") != item.end()) |
| 991 | { |
| 992 | for (const auto& eI : item["extraInterfaces"].items()) |
| 993 | { |
| 994 | if (eI.key().find("Inventory.Item.Cpu") != string::npos) |
| 995 | { |
| 996 | isProcessor = true; |
| 997 | } |
| 998 | } |
| 999 | } |
| 1000 | |
| 1001 | if (isProcessor) |
| 1002 | { |
| 1003 | string cpuType = item.value("cpuType", ""); |
| 1004 | if (cpuType == "primary") |
| 1005 | { |
| 1006 | isPrimary = true; |
| 1007 | } |
| 1008 | } |
| 1009 | } |
| 1010 | |
| 1011 | return (isProcessor && isPrimary); |
| 1012 | } |
| 1013 | |
| 1014 | /** |
| 1015 | * @brief This finds DIMM vpd in vpd json and enables them by binding the device |
| 1016 | * driver |
| 1017 | * @param[in] js- vpd json to iterate through and take action if it is DIMM |
| 1018 | */ |
| 1019 | void doEnableAllDimms(nlohmann::json& js) |
| 1020 | { |
| 1021 | // iterate over each fru |
| 1022 | for (const auto& eachFru : js["frus"].items()) |
| 1023 | { |
| 1024 | // skip the driver binding if eeprom already exists |
| 1025 | if (fs::exists(eachFru.key())) |
| 1026 | { |
| 1027 | continue; |
| 1028 | } |
| 1029 | |
| 1030 | for (const auto& eachInventory : eachFru.value()) |
| 1031 | { |
| 1032 | if (eachInventory.find("extraInterfaces") != eachInventory.end()) |
| 1033 | { |
| 1034 | for (const auto& eI : eachInventory["extraInterfaces"].items()) |
| 1035 | { |
| 1036 | if (eI.key().find("Inventory.Item.Dimm") != string::npos) |
| 1037 | { |
| 1038 | string dimmVpd = eachFru.key(); |
| 1039 | // fetch it from |
| 1040 | // "/sys/bus/i2c/drivers/at24/414-0050/eeprom" |
| 1041 | |
| 1042 | regex matchPatern("([0-9]+-[0-9]{4})"); |
| 1043 | smatch matchFound; |
| 1044 | if (regex_search(dimmVpd, matchFound, matchPatern)) |
| 1045 | { |
| 1046 | vector<string> i2cReg; |
| 1047 | boost::split(i2cReg, matchFound.str(0), |
| 1048 | boost::is_any_of("-")); |
| 1049 | |
| 1050 | // remove 0s from begining |
| 1051 | const regex pattern("^0+(?!$)"); |
| 1052 | for (auto& i : i2cReg) |
| 1053 | { |
| 1054 | i = regex_replace(i, pattern, ""); |
| 1055 | } |
| 1056 | |
| 1057 | if (i2cReg.size() == 2) |
| 1058 | { |
| 1059 | // echo 24c32 0x50 > |
| 1060 | // /sys/bus/i2c/devices/i2c-16/new_device |
| 1061 | string cmnd = "echo 24c32 0x" + i2cReg[1] + |
| 1062 | " > /sys/bus/i2c/devices/i2c-" + |
| 1063 | i2cReg[0] + "/new_device"; |
| 1064 | |
| 1065 | executeCmd(cmnd); |
| 1066 | } |
| 1067 | } |
| 1068 | } |
| 1069 | } |
| 1070 | } |
| 1071 | } |
| 1072 | } |
| 1073 | } |
| 1074 | |
| 1075 | /** |
Priyanga Ramasamy | 6abdeb6 | 2022-01-09 23:15:11 -0600 | [diff] [blame] | 1076 | * @brief Check if the given CPU is an IO only chip. |
| 1077 | * The CPU is termed as IO, whose all of the cores are bad and can never be |
| 1078 | * used. Those CPU chips can be used for IO purpose like connecting PCIe devices |
| 1079 | * etc., The CPU whose every cores are bad, can be identified from the CP00 |
| 1080 | * record's PG keyword, only if all of the 8 EQs' value equals 0xE7F9FF. (1EQ |
| 1081 | * has 4 cores grouped together by sharing its cache memory.) |
| 1082 | * @param [in] pgKeyword - PG Keyword of CPU. |
| 1083 | * @return true if the given cpu is an IO, false otherwise. |
| 1084 | */ |
| 1085 | static bool isCPUIOGoodOnly(const string& pgKeyword) |
| 1086 | { |
| 1087 | const unsigned char io[] = {0xE7, 0xF9, 0xFF, 0xE7, 0xF9, 0xFF, 0xE7, 0xF9, |
| 1088 | 0xFF, 0xE7, 0xF9, 0xFF, 0xE7, 0xF9, 0xFF, 0xE7, |
| 1089 | 0xF9, 0xFF, 0xE7, 0xF9, 0xFF, 0xE7, 0xF9, 0xFF}; |
| 1090 | // EQ0 index (in PG keyword) starts at 97 (with offset starting from 0). |
| 1091 | // Each EQ carries 3 bytes of data. Totally there are 8 EQs. If all EQs' |
| 1092 | // value equals 0xE7F9FF, then the cpu has no good cores and its treated as |
| 1093 | // IO. |
| 1094 | if (memcmp(io, pgKeyword.data() + 97, 24) == 0) |
| 1095 | { |
| 1096 | return true; |
| 1097 | } |
| 1098 | |
| 1099 | // The CPU is not an IO |
| 1100 | return false; |
| 1101 | } |
| 1102 | |
| 1103 | /** |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 1104 | * @brief Populate Dbus. |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1105 | * This method invokes all the populateInterface functions |
| 1106 | * and notifies PIM about dbus object. |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 1107 | * @param[in] vpdMap - Either IPZ vpd map or Keyword vpd map based on the |
| 1108 | * input. |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1109 | * @param[in] js - Inventory json object |
| 1110 | * @param[in] filePath - Path of the vpd file |
| 1111 | * @param[in] preIntrStr - Interface string |
| 1112 | */ |
| 1113 | template <typename T> |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 1114 | static void populateDbus(T& vpdMap, nlohmann::json& js, const string& filePath) |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1115 | { |
| 1116 | inventory::InterfaceMap interfaces; |
| 1117 | inventory::ObjectMap objects; |
| 1118 | inventory::PropertyMap prop; |
Shantappa Teekappanavar | 6aa5450 | 2021-12-09 12:59:56 -0600 | [diff] [blame] | 1119 | string ccinFromVpd; |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1120 | |
Santosh Puranik | 50f60bf | 2021-05-26 17:55:06 +0530 | [diff] [blame] | 1121 | bool isSystemVpd = (filePath == systemVpdFilePath); |
| 1122 | if constexpr (is_same<T, Parsed>::value) |
| 1123 | { |
Shantappa Teekappanavar | 6aa5450 | 2021-12-09 12:59:56 -0600 | [diff] [blame] | 1124 | ccinFromVpd = getKwVal(vpdMap, "VINI", "CC"); |
| 1125 | transform(ccinFromVpd.begin(), ccinFromVpd.end(), ccinFromVpd.begin(), |
| 1126 | ::toupper); |
| 1127 | |
Santosh Puranik | 50f60bf | 2021-05-26 17:55:06 +0530 | [diff] [blame] | 1128 | if (isSystemVpd) |
| 1129 | { |
| 1130 | std::vector<std::string> interfaces = {motherBoardInterface}; |
| 1131 | // call mapper to check for object path creation |
| 1132 | MapperResponse subTree = |
| 1133 | getObjectSubtreeForInterfaces(pimPath, 0, interfaces); |
| 1134 | string mboardPath = |
| 1135 | js["frus"][filePath].at(0).value("inventoryPath", ""); |
| 1136 | |
| 1137 | // Attempt system VPD restore if we have a motherboard |
| 1138 | // object in the inventory. |
| 1139 | if ((subTree.size() != 0) && |
| 1140 | (subTree.find(pimPath + mboardPath) != subTree.end())) |
| 1141 | { |
Sunny Srivastava | 3c24414 | 2022-01-11 08:47:04 -0600 | [diff] [blame] | 1142 | restoreSystemVPD(vpdMap, mboardPath); |
Santosh Puranik | 50f60bf | 2021-05-26 17:55:06 +0530 | [diff] [blame] | 1143 | } |
| 1144 | else |
| 1145 | { |
| 1146 | log<level::ERR>("No object path found"); |
| 1147 | } |
| 1148 | } |
alpana07 | 7ce6872 | 2021-07-25 13:23:59 -0500 | [diff] [blame] | 1149 | else |
| 1150 | { |
| 1151 | // check if it is processor vpd. |
| 1152 | auto isPrimaryCpu = isThisPrimaryProcessor(js, filePath); |
| 1153 | |
| 1154 | if (isPrimaryCpu) |
| 1155 | { |
| 1156 | auto ddVersion = getKwVal(vpdMap, "CRP0", "DD"); |
| 1157 | |
| 1158 | auto chipVersion = atoi(ddVersion.substr(1, 2).c_str()); |
| 1159 | |
| 1160 | if (chipVersion >= 2) |
| 1161 | { |
| 1162 | doEnableAllDimms(js); |
Santosh Puranik | 253fbe9 | 2022-10-06 22:38:09 +0530 | [diff] [blame] | 1163 | // Sleep for a few seconds to let the DIMM parses start |
| 1164 | using namespace std::chrono_literals; |
| 1165 | std::this_thread::sleep_for(5s); |
alpana07 | 7ce6872 | 2021-07-25 13:23:59 -0500 | [diff] [blame] | 1166 | } |
| 1167 | } |
| 1168 | } |
Santosh Puranik | 50f60bf | 2021-05-26 17:55:06 +0530 | [diff] [blame] | 1169 | } |
| 1170 | |
Santosh Puranik | f3e6968 | 2022-03-31 17:52:38 +0530 | [diff] [blame] | 1171 | auto processFactoryReset = false; |
| 1172 | |
Priyanga Ramasamy | 32c687f | 2022-01-04 23:14:03 -0600 | [diff] [blame] | 1173 | if (isSystemVpd) |
| 1174 | { |
| 1175 | string systemJsonName{}; |
| 1176 | if constexpr (is_same<T, Parsed>::value) |
| 1177 | { |
| 1178 | // pick the right system json |
| 1179 | systemJsonName = getSystemsJson(vpdMap); |
| 1180 | } |
| 1181 | |
| 1182 | fs::path target = systemJsonName; |
| 1183 | fs::path link = INVENTORY_JSON_SYM_LINK; |
| 1184 | |
Santosh Puranik | f3e6968 | 2022-03-31 17:52:38 +0530 | [diff] [blame] | 1185 | // If the symlink does not exist, we treat that as a factory reset |
| 1186 | processFactoryReset = !fs::exists(INVENTORY_JSON_SYM_LINK); |
| 1187 | |
Priyanga Ramasamy | 32c687f | 2022-01-04 23:14:03 -0600 | [diff] [blame] | 1188 | // Create the directory for hosting the symlink |
| 1189 | fs::create_directories(VPD_FILES_PATH); |
| 1190 | // unlink the symlink previously created (if any) |
| 1191 | remove(INVENTORY_JSON_SYM_LINK); |
| 1192 | // create a new symlink based on the system |
| 1193 | fs::create_symlink(target, link); |
| 1194 | |
| 1195 | // Reloading the json |
| 1196 | ifstream inventoryJson(link); |
| 1197 | js = json::parse(inventoryJson); |
| 1198 | inventoryJson.close(); |
| 1199 | } |
| 1200 | |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1201 | for (const auto& item : js["frus"][filePath]) |
| 1202 | { |
| 1203 | const auto& objectPath = item["inventoryPath"]; |
| 1204 | sdbusplus::message::object_path object(objectPath); |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 1205 | |
Shantappa Teekappanavar | 6aa5450 | 2021-12-09 12:59:56 -0600 | [diff] [blame] | 1206 | vector<string> ccinList; |
| 1207 | if (item.find("ccin") != item.end()) |
| 1208 | { |
| 1209 | for (const auto& cc : item["ccin"]) |
| 1210 | { |
| 1211 | string ccin = cc; |
| 1212 | transform(ccin.begin(), ccin.end(), ccin.begin(), ::toupper); |
| 1213 | ccinList.push_back(ccin); |
| 1214 | } |
| 1215 | } |
| 1216 | |
| 1217 | if (!ccinFromVpd.empty() && !ccinList.empty() && |
| 1218 | (find(ccinList.begin(), ccinList.end(), ccinFromVpd) == |
| 1219 | ccinList.end())) |
| 1220 | { |
| 1221 | continue; |
| 1222 | } |
| 1223 | |
Priyanga Ramasamy | e3fed70 | 2022-01-11 01:05:32 -0600 | [diff] [blame] | 1224 | if ((isSystemVpd) || (item.value("noprime", false))) |
Santosh Puranik | d3a379a | 2021-08-23 19:12:59 +0530 | [diff] [blame] | 1225 | { |
Priyanga Ramasamy | e3fed70 | 2022-01-11 01:05:32 -0600 | [diff] [blame] | 1226 | |
| 1227 | // Populate one time properties for the system VPD and its sub-frus |
| 1228 | // and for other non-primeable frus. |
Santosh Puranik | d3a379a | 2021-08-23 19:12:59 +0530 | [diff] [blame] | 1229 | // For the remaining FRUs, this will get handled as a part of |
| 1230 | // priming the inventory. |
| 1231 | setOneTimeProperties(objectPath, interfaces); |
| 1232 | } |
| 1233 | |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1234 | // Populate the VPD keywords and the common interfaces only if we |
| 1235 | // are asked to inherit that data from the VPD, else only add the |
| 1236 | // extraInterfaces. |
| 1237 | if (item.value("inherit", true)) |
| 1238 | { |
Alpana Kumari | 58e2214 | 2020-05-05 00:22:12 -0500 | [diff] [blame] | 1239 | if constexpr (is_same<T, Parsed>::value) |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1240 | { |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 1241 | // Each record in the VPD becomes an interface and all |
| 1242 | // keyword within the record are properties under that |
| 1243 | // interface. |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1244 | for (const auto& record : vpdMap) |
| 1245 | { |
| 1246 | populateFruSpecificInterfaces( |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 1247 | record.second, ipzVpdInf + record.first, interfaces); |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1248 | } |
| 1249 | } |
Alpana Kumari | 58e2214 | 2020-05-05 00:22:12 -0500 | [diff] [blame] | 1250 | else if constexpr (is_same<T, KeywordVpdMap>::value) |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1251 | { |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 1252 | populateFruSpecificInterfaces(vpdMap, kwdVpdInf, interfaces); |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1253 | } |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 1254 | if (js.find("commonInterfaces") != js.end()) |
| 1255 | { |
| 1256 | populateInterfaces(js["commonInterfaces"], interfaces, vpdMap, |
| 1257 | isSystemVpd); |
| 1258 | } |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1259 | } |
Santosh Puranik | 0859eb6 | 2020-03-16 02:56:29 -0500 | [diff] [blame] | 1260 | else |
| 1261 | { |
| 1262 | // Check if we have been asked to inherit specific record(s) |
Alpana Kumari | 58e2214 | 2020-05-05 00:22:12 -0500 | [diff] [blame] | 1263 | if constexpr (is_same<T, Parsed>::value) |
Santosh Puranik | 0859eb6 | 2020-03-16 02:56:29 -0500 | [diff] [blame] | 1264 | { |
| 1265 | if (item.find("copyRecords") != item.end()) |
| 1266 | { |
| 1267 | for (const auto& record : item["copyRecords"]) |
| 1268 | { |
| 1269 | const string& recordName = record; |
| 1270 | if (vpdMap.find(recordName) != vpdMap.end()) |
| 1271 | { |
| 1272 | populateFruSpecificInterfaces( |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 1273 | vpdMap.at(recordName), ipzVpdInf + recordName, |
Santosh Puranik | 0859eb6 | 2020-03-16 02:56:29 -0500 | [diff] [blame] | 1274 | interfaces); |
| 1275 | } |
| 1276 | } |
| 1277 | } |
| 1278 | } |
| 1279 | } |
Santosh Puranik | 32c4650 | 2022-02-10 08:55:07 +0530 | [diff] [blame] | 1280 | // Populate interfaces and properties that are common to every FRU |
| 1281 | // and additional interface that might be defined on a per-FRU |
| 1282 | // basis. |
| 1283 | if (item.find("extraInterfaces") != item.end()) |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1284 | { |
Santosh Puranik | 32c4650 | 2022-02-10 08:55:07 +0530 | [diff] [blame] | 1285 | populateInterfaces(item["extraInterfaces"], interfaces, vpdMap, |
| 1286 | isSystemVpd); |
Priyanga Ramasamy | 6abdeb6 | 2022-01-09 23:15:11 -0600 | [diff] [blame] | 1287 | if constexpr (is_same<T, Parsed>::value) |
| 1288 | { |
| 1289 | if (item["extraInterfaces"].find( |
| 1290 | "xyz.openbmc_project.Inventory.Item.Cpu") != |
| 1291 | item["extraInterfaces"].end()) |
| 1292 | { |
| 1293 | if (isCPUIOGoodOnly(getKwVal(vpdMap, "CP00", "PG"))) |
| 1294 | { |
Priyanga Ramasamy | 2c607a9 | 2022-04-08 00:30:17 -0500 | [diff] [blame] | 1295 | interfaces[invItemIntf]["PrettyName"] = "IO Module"; |
Priyanga Ramasamy | 6abdeb6 | 2022-01-09 23:15:11 -0600 | [diff] [blame] | 1296 | } |
| 1297 | } |
| 1298 | } |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1299 | } |
Priyanga Ramasamy | e358acb | 2022-03-21 14:21:50 -0500 | [diff] [blame] | 1300 | |
| 1301 | // embedded property(true or false) says whether the subfru is embedded |
| 1302 | // into the parent fru (or) not. VPD sets Present property only for |
| 1303 | // embedded frus. If the subfru is not an embedded FRU, the subfru may |
| 1304 | // or may not be physically present. Those non embedded frus will always |
| 1305 | // have Present=false irrespective of its physical presence or absence. |
| 1306 | // Eg: nvme drive in nvme slot is not an embedded FRU. So don't set |
| 1307 | // Present to true for such sub frus. |
| 1308 | // Eg: ethernet port is embedded into bmc card. So set Present to true |
| 1309 | // for such sub frus. Also donot populate present property for embedded |
| 1310 | // subfru which is synthesized. Currently there is no subfru which are |
| 1311 | // both embedded and synthesized. But still the case is handled here. |
| 1312 | if ((item.value("embedded", true)) && |
| 1313 | (!item.value("synthesized", false))) |
| 1314 | { |
Priyanga Ramasamy | aca6137 | 2023-01-24 08:02:28 -0600 | [diff] [blame] | 1315 | // Check if its required to handle presence for this FRU. |
| 1316 | if (item.value("handlePresence", true)) |
| 1317 | { |
| 1318 | inventory::PropertyMap presProp; |
| 1319 | presProp.emplace("Present", true); |
| 1320 | insertOrMerge(interfaces, invItemIntf, move(presProp)); |
| 1321 | } |
Priyanga Ramasamy | e358acb | 2022-03-21 14:21:50 -0500 | [diff] [blame] | 1322 | } |
Priyanga Ramasamy | aa8a893 | 2022-01-27 09:12:41 -0600 | [diff] [blame] | 1323 | |
Santosh Puranik | f3e6968 | 2022-03-31 17:52:38 +0530 | [diff] [blame] | 1324 | if constexpr (is_same<T, Parsed>::value) |
| 1325 | { |
| 1326 | // Restore asset tag, if needed |
| 1327 | if (processFactoryReset && objectPath == "/system") |
| 1328 | { |
| 1329 | fillAssetTag(interfaces, vpdMap); |
| 1330 | } |
| 1331 | } |
| 1332 | |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1333 | objects.emplace(move(object), move(interfaces)); |
| 1334 | } |
| 1335 | |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 1336 | if (isSystemVpd) |
| 1337 | { |
| 1338 | inventory::ObjectMap primeObject = primeInventory(js, vpdMap); |
| 1339 | objects.insert(primeObject.begin(), primeObject.end()); |
Alpana Kumari | 65b8360 | 2020-09-01 00:24:56 -0500 | [diff] [blame] | 1340 | |
Alpana Kumari | f05effd | 2021-04-07 07:32:53 -0500 | [diff] [blame] | 1341 | // set the U-boot environment variable for device-tree |
| 1342 | if constexpr (is_same<T, Parsed>::value) |
| 1343 | { |
Santosh Puranik | e5f177a | 2022-01-24 20:14:46 +0530 | [diff] [blame] | 1344 | setDevTreeEnv(fs::path(getSystemsJson(vpdMap)).filename()); |
Alpana Kumari | f05effd | 2021-04-07 07:32:53 -0500 | [diff] [blame] | 1345 | } |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 1346 | } |
| 1347 | |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1348 | // Notify PIM |
Sunny Srivastava | 6c71c9d | 2021-04-15 04:43:54 -0500 | [diff] [blame] | 1349 | common::utility::callPIM(move(objects)); |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1350 | } |
| 1351 | |
| 1352 | int main(int argc, char** argv) |
| 1353 | { |
| 1354 | int rc = 0; |
SunnySrivastava1984 | a20be8e | 2020-08-26 02:00:50 -0500 | [diff] [blame] | 1355 | json js{}; |
PriyangaRamasamy | c2fe40f | 2021-03-02 06:27:33 -0600 | [diff] [blame] | 1356 | Binary vpdVector{}; |
| 1357 | string file{}; |
jinuthomas | f457a3e | 2023-04-13 12:22:48 -0500 | [diff] [blame^] | 1358 | string driver{}; |
SunnySrivastava1984 | a20be8e | 2020-08-26 02:00:50 -0500 | [diff] [blame] | 1359 | // map to hold additional data in case of logging pel |
| 1360 | PelAdditionalData additionalData{}; |
| 1361 | |
| 1362 | // this is needed to hold base fru inventory path in case there is ECC or |
| 1363 | // vpd exception while parsing the file |
| 1364 | std::string baseFruInventoryPath = {}; |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1365 | |
Sunny Srivastava | 0746eee | 2021-03-22 13:36:54 -0500 | [diff] [blame] | 1366 | // severity for PEL |
| 1367 | PelSeverity pelSeverity = PelSeverity::WARNING; |
| 1368 | |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1369 | try |
| 1370 | { |
jinuthomas | f457a3e | 2023-04-13 12:22:48 -0500 | [diff] [blame^] | 1371 | App app{"ibm-read-vpd - App to read IPZ/Jedec format VPD, parse it and " |
| 1372 | "store it in DBUS"}; |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1373 | |
| 1374 | app.add_option("-f, --file", file, "File containing VPD (IPZ/KEYWORD)") |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 1375 | ->required(); |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1376 | |
jinuthomas | f457a3e | 2023-04-13 12:22:48 -0500 | [diff] [blame^] | 1377 | app.add_option("--driver", driver, |
| 1378 | "Driver used by kernel (at24,at25,ee1004)") |
| 1379 | ->required(); |
| 1380 | |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1381 | CLI11_PARSE(app, argc, argv); |
| 1382 | |
Sunny Srivastava | 0746eee | 2021-03-22 13:36:54 -0500 | [diff] [blame] | 1383 | // PEL severity should be ERROR in case of any system VPD failure |
| 1384 | if (file == systemVpdFilePath) |
| 1385 | { |
| 1386 | pelSeverity = PelSeverity::ERROR; |
| 1387 | } |
| 1388 | |
jinuthomas | f457a3e | 2023-04-13 12:22:48 -0500 | [diff] [blame^] | 1389 | // Check if input file is not empty. |
| 1390 | if ((file.empty()) || (driver.empty())) |
| 1391 | { |
| 1392 | std::cerr << "Encountered empty input parameter file [" << file |
| 1393 | << "] driver [" << driver << "]" << std::endl; |
| 1394 | return 0; |
| 1395 | } |
| 1396 | |
| 1397 | // Check if currently supported driver or not |
| 1398 | if ((driver != at24driver) && (driver != at25driver) && |
| 1399 | (driver != ee1004driver)) |
| 1400 | { |
| 1401 | std::cerr << "The driver [" << driver << "] is not supported." |
| 1402 | << std::endl; |
| 1403 | return 0; |
| 1404 | } |
| 1405 | |
Santosh Puranik | 0246a4d | 2020-11-04 16:57:39 +0530 | [diff] [blame] | 1406 | auto jsonToParse = INVENTORY_JSON_DEFAULT; |
| 1407 | |
| 1408 | // If the symlink exists, it means it has been setup for us, switch the |
| 1409 | // path |
| 1410 | if (fs::exists(INVENTORY_JSON_SYM_LINK)) |
| 1411 | { |
| 1412 | jsonToParse = INVENTORY_JSON_SYM_LINK; |
| 1413 | } |
| 1414 | |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1415 | // 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] | 1416 | ifstream inventoryJson(jsonToParse); |
SunnySrivastava1984 | a20be8e | 2020-08-26 02:00:50 -0500 | [diff] [blame] | 1417 | if (!inventoryJson) |
| 1418 | { |
Sunny Srivastava | 0746eee | 2021-03-22 13:36:54 -0500 | [diff] [blame] | 1419 | throw(VpdJsonException("Failed to access Json path", jsonToParse)); |
SunnySrivastava1984 | a20be8e | 2020-08-26 02:00:50 -0500 | [diff] [blame] | 1420 | } |
| 1421 | |
| 1422 | try |
| 1423 | { |
| 1424 | js = json::parse(inventoryJson); |
| 1425 | } |
Patrick Williams | 8e15b93 | 2021-10-06 13:04:22 -0500 | [diff] [blame] | 1426 | catch (const json::parse_error& ex) |
SunnySrivastava1984 | a20be8e | 2020-08-26 02:00:50 -0500 | [diff] [blame] | 1427 | { |
Sunny Srivastava | 0746eee | 2021-03-22 13:36:54 -0500 | [diff] [blame] | 1428 | throw(VpdJsonException("Json parsing failed", jsonToParse)); |
SunnySrivastava1984 | a20be8e | 2020-08-26 02:00:50 -0500 | [diff] [blame] | 1429 | } |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1430 | |
Santosh Puranik | 12e24ff | 2021-05-11 19:33:50 +0530 | [diff] [blame] | 1431 | // Do we have the mandatory "frus" section? |
| 1432 | if (js.find("frus") == js.end()) |
| 1433 | { |
| 1434 | throw(VpdJsonException("FRUs section not found in JSON", |
| 1435 | jsonToParse)); |
| 1436 | } |
| 1437 | |
PriyangaRamasamy | 647868e | 2020-09-08 17:03:19 +0530 | [diff] [blame] | 1438 | // Check if it's a udev path - patterned as(/ahb/ahb:apb/ahb:apb:bus@) |
| 1439 | if (file.find("/ahb:apb") != string::npos) |
| 1440 | { |
| 1441 | // Translate udev path to a generic /sys/bus/.. file path. |
jinuthomas | f457a3e | 2023-04-13 12:22:48 -0500 | [diff] [blame^] | 1442 | udevToGenericPath(file, driver); |
Santosh Puranik | 12e24ff | 2021-05-11 19:33:50 +0530 | [diff] [blame] | 1443 | |
| 1444 | if ((js["frus"].find(file) != js["frus"].end()) && |
Santosh Puranik | 50f60bf | 2021-05-26 17:55:06 +0530 | [diff] [blame] | 1445 | (file == systemVpdFilePath)) |
PriyangaRamasamy | 647868e | 2020-09-08 17:03:19 +0530 | [diff] [blame] | 1446 | { |
jinuthomas | f457a3e | 2023-04-13 12:22:48 -0500 | [diff] [blame^] | 1447 | std::cout << "We have already collected system VPD, skiping." |
| 1448 | << std::endl; |
PriyangaRamasamy | 647868e | 2020-09-08 17:03:19 +0530 | [diff] [blame] | 1449 | return 0; |
| 1450 | } |
| 1451 | } |
| 1452 | |
| 1453 | if (file.empty()) |
| 1454 | { |
jinuthomas | f457a3e | 2023-04-13 12:22:48 -0500 | [diff] [blame^] | 1455 | std::cerr << "The EEPROM path <" << file << "> is not valid."; |
PriyangaRamasamy | 647868e | 2020-09-08 17:03:19 +0530 | [diff] [blame] | 1456 | return 0; |
| 1457 | } |
Santosh Puranik | 12e24ff | 2021-05-11 19:33:50 +0530 | [diff] [blame] | 1458 | if (js["frus"].find(file) == js["frus"].end()) |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1459 | { |
jinuthomas | f457a3e | 2023-04-13 12:22:48 -0500 | [diff] [blame^] | 1460 | std::cerr << "The EEPROM path [" << file |
| 1461 | << "] is not found in the json." << std::endl; |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 1462 | return 0; |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1463 | } |
| 1464 | |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 1465 | if (!fs::exists(file)) |
| 1466 | { |
jinuthomas | f457a3e | 2023-04-13 12:22:48 -0500 | [diff] [blame^] | 1467 | std::cout << "Device path: " << file |
| 1468 | << " does not exist. Spurious udev event? Exiting." |
| 1469 | << std::endl; |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 1470 | return 0; |
| 1471 | } |
| 1472 | |
Santosh Puranik | dedb5a6 | 2022-12-19 23:58:32 +0530 | [diff] [blame] | 1473 | // In case of system VPD it will already be filled, Don't have to |
| 1474 | // overwrite that. |
| 1475 | if (baseFruInventoryPath.empty()) |
| 1476 | { |
| 1477 | baseFruInventoryPath = js["frus"][file][0]["inventoryPath"]; |
| 1478 | } |
| 1479 | |
Santosh Puranik | 8589375 | 2020-11-10 21:31:43 +0530 | [diff] [blame] | 1480 | // 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] | 1481 | // We skip reading VPD when the power is ON in two scenarios: |
Santosh Puranik | 31d50fa | 2022-04-04 12:04:37 +0530 | [diff] [blame] | 1482 | // 1) The eeprom we are trying to read is that of the system VPD and the |
| 1483 | // JSON symlink is already setup (the symlink's existence tells us we |
| 1484 | // are not coming out of a factory reset) |
| 1485 | // 2) The JSON tells us that the FRU EEPROM cannot be |
| 1486 | // read when we are powered ON. |
Santosh Puranik | 27a5e95 | 2021-10-07 22:08:01 -0500 | [diff] [blame] | 1487 | if (js["frus"][file].at(0).value("powerOffOnly", false) || |
Santosh Puranik | 31d50fa | 2022-04-04 12:04:37 +0530 | [diff] [blame] | 1488 | (file == systemVpdFilePath && fs::exists(INVENTORY_JSON_SYM_LINK))) |
Santosh Puranik | 8589375 | 2020-11-10 21:31:43 +0530 | [diff] [blame] | 1489 | { |
| 1490 | if ("xyz.openbmc_project.State.Chassis.PowerState.On" == |
| 1491 | getPowerState()) |
| 1492 | { |
jinuthomas | f457a3e | 2023-04-13 12:22:48 -0500 | [diff] [blame^] | 1493 | std::cout << "This VPD cannot be read when power is ON" |
| 1494 | << std::endl; |
Santosh Puranik | 8589375 | 2020-11-10 21:31:43 +0530 | [diff] [blame] | 1495 | return 0; |
| 1496 | } |
| 1497 | } |
SunnySrivastava1984 | a20be8e | 2020-08-26 02:00:50 -0500 | [diff] [blame] | 1498 | |
Santosh Puranik | e9c5753 | 2022-03-15 16:51:51 +0530 | [diff] [blame] | 1499 | // Check if this VPD should be recollected at all |
| 1500 | if (!needsRecollection(js, file)) |
| 1501 | { |
jinuthomas | f457a3e | 2023-04-13 12:22:48 -0500 | [diff] [blame^] | 1502 | std::cout << "Skip VPD recollection for: " << file << std::endl; |
Santosh Puranik | e9c5753 | 2022-03-15 16:51:51 +0530 | [diff] [blame] | 1503 | return 0; |
| 1504 | } |
| 1505 | |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 1506 | try |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1507 | { |
girik | 18bb985 | 2022-11-16 05:48:13 -0600 | [diff] [blame] | 1508 | uint32_t vpdStartOffset = 0; |
| 1509 | for (const auto& item : js["frus"][file]) |
| 1510 | { |
| 1511 | if (item.find("offset") != item.end()) |
| 1512 | { |
| 1513 | vpdStartOffset = item["offset"]; |
| 1514 | } |
| 1515 | } |
PriyangaRamasamy | c2fe40f | 2021-03-02 06:27:33 -0600 | [diff] [blame] | 1516 | vpdVector = getVpdDataInVector(js, file); |
Sunny Srivastava | f31a91b | 2022-06-09 08:11:29 -0500 | [diff] [blame] | 1517 | ParserInterface* parser = ParserFactory::getParser( |
girik | 18bb985 | 2022-11-16 05:48:13 -0600 | [diff] [blame] | 1518 | vpdVector, (pimPath + baseFruInventoryPath), file, |
| 1519 | vpdStartOffset); |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 1520 | variant<KeywordVpdMap, Store> parseResult; |
| 1521 | parseResult = parser->parse(); |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 1522 | |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 1523 | if (auto pVal = get_if<Store>(&parseResult)) |
| 1524 | { |
| 1525 | populateDbus(pVal->getVpdMap(), js, file); |
| 1526 | } |
| 1527 | else if (auto pVal = get_if<KeywordVpdMap>(&parseResult)) |
| 1528 | { |
| 1529 | populateDbus(*pVal, js, file); |
| 1530 | } |
| 1531 | |
| 1532 | // release the parser object |
| 1533 | ParserFactory::freeParser(parser); |
| 1534 | } |
Patrick Williams | 8e15b93 | 2021-10-06 13:04:22 -0500 | [diff] [blame] | 1535 | catch (const exception& e) |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 1536 | { |
Alpana Kumari | 735dee9 | 2022-03-25 01:24:40 -0500 | [diff] [blame] | 1537 | executePostFailAction(js, file); |
PriyangaRamasamy | a504c3e | 2020-12-06 12:14:52 -0600 | [diff] [blame] | 1538 | throw; |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 1539 | } |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1540 | } |
SunnySrivastava1984 | a20be8e | 2020-08-26 02:00:50 -0500 | [diff] [blame] | 1541 | catch (const VpdJsonException& ex) |
| 1542 | { |
| 1543 | additionalData.emplace("JSON_PATH", ex.getJsonPath()); |
| 1544 | additionalData.emplace("DESCRIPTION", ex.what()); |
Sunny Srivastava | a2ddc96 | 2022-06-29 08:53:16 -0500 | [diff] [blame] | 1545 | createPEL(additionalData, pelSeverity, errIntfForJsonFailure, nullptr); |
SunnySrivastava1984 | a20be8e | 2020-08-26 02:00:50 -0500 | [diff] [blame] | 1546 | |
jinuthomas | f457a3e | 2023-04-13 12:22:48 -0500 | [diff] [blame^] | 1547 | std::cerr << ex.what() << "\n"; |
SunnySrivastava1984 | a20be8e | 2020-08-26 02:00:50 -0500 | [diff] [blame] | 1548 | rc = -1; |
| 1549 | } |
| 1550 | catch (const VpdEccException& ex) |
| 1551 | { |
| 1552 | additionalData.emplace("DESCRIPTION", "ECC check failed"); |
| 1553 | additionalData.emplace("CALLOUT_INVENTORY_PATH", |
| 1554 | INVENTORY_PATH + baseFruInventoryPath); |
Sunny Srivastava | a2ddc96 | 2022-06-29 08:53:16 -0500 | [diff] [blame] | 1555 | createPEL(additionalData, pelSeverity, errIntfForEccCheckFail, nullptr); |
PriyangaRamasamy | c2fe40f | 2021-03-02 06:27:33 -0600 | [diff] [blame] | 1556 | dumpBadVpd(file, vpdVector); |
jinuthomas | f457a3e | 2023-04-13 12:22:48 -0500 | [diff] [blame^] | 1557 | std::cerr << ex.what() << "\n"; |
SunnySrivastava1984 | a20be8e | 2020-08-26 02:00:50 -0500 | [diff] [blame] | 1558 | rc = -1; |
| 1559 | } |
| 1560 | catch (const VpdDataException& ex) |
| 1561 | { |
alpana07 | 5cb3b1f | 2021-12-16 11:19:36 -0600 | [diff] [blame] | 1562 | if (isThisPcieOnPass1planar(js, file)) |
| 1563 | { |
jinuthomas | f457a3e | 2023-04-13 12:22:48 -0500 | [diff] [blame^] | 1564 | std::cout << "Pcie_device [" << file |
| 1565 | << "]'s VPD is not valid on PASS1 planar.Ignoring.\n"; |
alpana07 | 5cb3b1f | 2021-12-16 11:19:36 -0600 | [diff] [blame] | 1566 | rc = 0; |
| 1567 | } |
Santosh Puranik | 53b38ed | 2022-04-10 23:15:22 +0530 | [diff] [blame] | 1568 | else if (!(isPresent(js, file).value_or(true))) |
| 1569 | { |
jinuthomas | f457a3e | 2023-04-13 12:22:48 -0500 | [diff] [blame^] | 1570 | std::cout << "FRU at: " << file |
| 1571 | << " is not detected present. Ignore parser error.\n"; |
Santosh Puranik | 53b38ed | 2022-04-10 23:15:22 +0530 | [diff] [blame] | 1572 | rc = 0; |
| 1573 | } |
alpana07 | 5cb3b1f | 2021-12-16 11:19:36 -0600 | [diff] [blame] | 1574 | else |
| 1575 | { |
| 1576 | string errorMsg = |
| 1577 | "VPD file is either empty or invalid. Parser failed for ["; |
| 1578 | errorMsg += file; |
| 1579 | errorMsg += "], with error = " + std::string(ex.what()); |
| 1580 | |
| 1581 | additionalData.emplace("DESCRIPTION", errorMsg); |
| 1582 | additionalData.emplace("CALLOUT_INVENTORY_PATH", |
| 1583 | INVENTORY_PATH + baseFruInventoryPath); |
Sunny Srivastava | a2ddc96 | 2022-06-29 08:53:16 -0500 | [diff] [blame] | 1584 | createPEL(additionalData, pelSeverity, errIntfForInvalidVPD, |
| 1585 | nullptr); |
alpana07 | 5cb3b1f | 2021-12-16 11:19:36 -0600 | [diff] [blame] | 1586 | |
| 1587 | rc = -1; |
| 1588 | } |
SunnySrivastava1984 | a20be8e | 2020-08-26 02:00:50 -0500 | [diff] [blame] | 1589 | } |
Patrick Williams | 8e15b93 | 2021-10-06 13:04:22 -0500 | [diff] [blame] | 1590 | catch (const exception& e) |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1591 | { |
PriyangaRamasamy | c2fe40f | 2021-03-02 06:27:33 -0600 | [diff] [blame] | 1592 | dumpBadVpd(file, vpdVector); |
jinuthomas | f457a3e | 2023-04-13 12:22:48 -0500 | [diff] [blame^] | 1593 | std::cerr << e.what() << "\n"; |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1594 | rc = -1; |
| 1595 | } |
| 1596 | |
| 1597 | return rc; |
Alpana Kumari | 735dee9 | 2022-03-25 01:24:40 -0500 | [diff] [blame] | 1598 | } |