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