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