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