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 | |
Alpana Kumari | 65b8360 | 2020-09-01 00:24:56 -0500 | [diff] [blame] | 43 | static const deviceTreeMap deviceTreeSystemTypeMap = { |
Joel Stanley | 6fb0ef9 | 2021-05-26 13:14:32 +0930 | [diff] [blame] | 44 | {RAINIER_2U, "conf-aspeed-bmc-ibm-rainier-p1.dtb"}, |
| 45 | {RAINIER_2U_V2, "conf-aspeed-bmc-ibm-rainier.dtb"}, |
| 46 | {RAINIER_4U, "conf-aspeed-bmc-ibm-rainier-4u-p1.dtb"}, |
| 47 | {RAINIER_4U_V2, "conf-aspeed-bmc-ibm-rainier-4u.dtb"}, |
Andrew Geissler | 2fe709f | 2021-03-25 10:59:07 -0500 | [diff] [blame] | 48 | {RAINIER_1S4U, "conf-aspeed-bmc-ibm-rainier-1s4u.dtb"}, |
| 49 | {EVEREST, "conf-aspeed-bmc-ibm-everest.dtb"}}; |
Alpana Kumari | 65b8360 | 2020-09-01 00:24:56 -0500 | [diff] [blame] | 50 | |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 51 | /** |
Santosh Puranik | 8589375 | 2020-11-10 21:31:43 +0530 | [diff] [blame] | 52 | * @brief Returns the power state for chassis0 |
| 53 | */ |
| 54 | static auto getPowerState() |
| 55 | { |
| 56 | // TODO: How do we handle multiple chassis? |
| 57 | string powerState{}; |
| 58 | auto bus = sdbusplus::bus::new_default(); |
| 59 | auto properties = |
| 60 | bus.new_method_call("xyz.openbmc_project.State.Chassis", |
| 61 | "/xyz/openbmc_project/state/chassis0", |
| 62 | "org.freedesktop.DBus.Properties", "Get"); |
| 63 | properties.append("xyz.openbmc_project.State.Chassis"); |
| 64 | properties.append("CurrentPowerState"); |
| 65 | auto result = bus.call(properties); |
| 66 | if (!result.is_method_error()) |
| 67 | { |
| 68 | variant<string> val; |
| 69 | result.read(val); |
| 70 | if (auto pVal = get_if<string>(&val)) |
| 71 | { |
| 72 | powerState = *pVal; |
| 73 | } |
| 74 | } |
| 75 | cout << "Power state is: " << powerState << endl; |
| 76 | return powerState; |
| 77 | } |
| 78 | |
| 79 | /** |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 80 | * @brief Expands location codes |
| 81 | */ |
| 82 | static auto expandLocationCode(const string& unexpanded, const Parsed& vpdMap, |
| 83 | bool isSystemVpd) |
| 84 | { |
| 85 | auto expanded{unexpanded}; |
| 86 | static constexpr auto SYSTEM_OBJECT = "/system/chassis/motherboard"; |
| 87 | static constexpr auto VCEN_IF = "com.ibm.ipzvpd.VCEN"; |
| 88 | static constexpr auto VSYS_IF = "com.ibm.ipzvpd.VSYS"; |
| 89 | size_t idx = expanded.find("fcs"); |
| 90 | try |
| 91 | { |
| 92 | if (idx != string::npos) |
| 93 | { |
| 94 | string fc{}; |
| 95 | string se{}; |
| 96 | if (isSystemVpd) |
| 97 | { |
| 98 | const auto& fcData = vpdMap.at("VCEN").at("FC"); |
| 99 | const auto& seData = vpdMap.at("VCEN").at("SE"); |
| 100 | fc = string(fcData.data(), fcData.size()); |
| 101 | se = string(seData.data(), seData.size()); |
| 102 | } |
| 103 | else |
| 104 | { |
| 105 | fc = readBusProperty(SYSTEM_OBJECT, VCEN_IF, "FC"); |
| 106 | se = readBusProperty(SYSTEM_OBJECT, VCEN_IF, "SE"); |
| 107 | } |
| 108 | |
Alpana Kumari | 81671f6 | 2021-02-10 02:21:59 -0600 | [diff] [blame] | 109 | // TODO: See if ND0 can be placed in the JSON |
| 110 | expanded.replace(idx, 3, fc.substr(0, 4) + ".ND0." + se); |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 111 | } |
| 112 | else |
| 113 | { |
| 114 | idx = expanded.find("mts"); |
| 115 | if (idx != string::npos) |
| 116 | { |
| 117 | string mt{}; |
| 118 | string se{}; |
| 119 | if (isSystemVpd) |
| 120 | { |
| 121 | const auto& mtData = vpdMap.at("VSYS").at("TM"); |
| 122 | const auto& seData = vpdMap.at("VSYS").at("SE"); |
| 123 | mt = string(mtData.data(), mtData.size()); |
| 124 | se = string(seData.data(), seData.size()); |
| 125 | } |
| 126 | else |
| 127 | { |
| 128 | mt = readBusProperty(SYSTEM_OBJECT, VSYS_IF, "TM"); |
| 129 | se = readBusProperty(SYSTEM_OBJECT, VSYS_IF, "SE"); |
| 130 | } |
| 131 | |
| 132 | replace(mt.begin(), mt.end(), '-', '.'); |
| 133 | expanded.replace(idx, 3, mt + "." + se); |
| 134 | } |
| 135 | } |
| 136 | } |
Patrick Williams | 8e15b93 | 2021-10-06 13:04:22 -0500 | [diff] [blame] | 137 | catch (const exception& e) |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 138 | { |
Alpana Kumari | 58e2214 | 2020-05-05 00:22:12 -0500 | [diff] [blame] | 139 | cerr << "Failed to expand location code with exception: " << e.what() |
| 140 | << "\n"; |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 141 | } |
| 142 | return expanded; |
| 143 | } |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 144 | |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 145 | /** |
| 146 | * @brief Populate FRU specific interfaces. |
| 147 | * |
| 148 | * This is a common method which handles both |
| 149 | * ipz and keyword specific interfaces thus, |
| 150 | * reducing the code redundancy. |
| 151 | * @param[in] map - Reference to the innermost keyword-value map. |
| 152 | * @param[in] preIntrStr - Reference to the interface string. |
| 153 | * @param[out] interfaces - Reference to interface map. |
| 154 | */ |
| 155 | template <typename T> |
| 156 | static void populateFruSpecificInterfaces(const T& map, |
| 157 | const string& preIntrStr, |
| 158 | inventory::InterfaceMap& interfaces) |
| 159 | { |
| 160 | inventory::PropertyMap prop; |
| 161 | |
| 162 | for (const auto& kwVal : map) |
| 163 | { |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 164 | auto kw = kwVal.first; |
| 165 | |
| 166 | if (kw[0] == '#') |
| 167 | { |
Alpana Kumari | 58e2214 | 2020-05-05 00:22:12 -0500 | [diff] [blame] | 168 | kw = string("PD_") + kw[1]; |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 169 | } |
Alpana Kumari | 8ea3f6d | 2020-04-02 00:26:07 -0500 | [diff] [blame] | 170 | else if (isdigit(kw[0])) |
| 171 | { |
Alpana Kumari | 58e2214 | 2020-05-05 00:22:12 -0500 | [diff] [blame] | 172 | kw = string("N_") + kw; |
Alpana Kumari | 8ea3f6d | 2020-04-02 00:26:07 -0500 | [diff] [blame] | 173 | } |
Alpana Kumari | 3ab26a7 | 2021-04-05 19:09:19 +0000 | [diff] [blame] | 174 | if constexpr (is_same<T, KeywordVpdMap>::value) |
| 175 | { |
| 176 | if (get_if<Binary>(&kwVal.second)) |
| 177 | { |
| 178 | Binary vec(get_if<Binary>(&kwVal.second)->begin(), |
| 179 | get_if<Binary>(&kwVal.second)->end()); |
Alpana Kumari | 3ab26a7 | 2021-04-05 19:09:19 +0000 | [diff] [blame] | 180 | prop.emplace(move(kw), move(vec)); |
| 181 | } |
| 182 | else |
| 183 | { |
| 184 | if (kw == "MemorySizeInKB") |
| 185 | { |
| 186 | inventory::PropertyMap memProp; |
| 187 | auto memVal = get_if<size_t>(&kwVal.second); |
| 188 | if (memVal) |
| 189 | { |
| 190 | memProp.emplace(move(kw), |
| 191 | ((*memVal) * CONVERT_MB_TO_KB)); |
| 192 | interfaces.emplace( |
| 193 | "xyz.openbmc_project.Inventory.Item.Dimm", |
| 194 | move(memProp)); |
| 195 | } |
| 196 | else |
| 197 | { |
| 198 | cerr << "MemorySizeInKB value not found in vpd map\n"; |
| 199 | } |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | else |
| 204 | { |
| 205 | Binary vec(kwVal.second.begin(), kwVal.second.end()); |
| 206 | prop.emplace(move(kw), move(vec)); |
| 207 | } |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | interfaces.emplace(preIntrStr, move(prop)); |
| 211 | } |
| 212 | |
| 213 | /** |
| 214 | * @brief Populate Interfaces. |
| 215 | * |
| 216 | * This method populates common and extra interfaces to dbus. |
| 217 | * @param[in] js - json object |
| 218 | * @param[out] interfaces - Reference to interface map |
| 219 | * @param[in] vpdMap - Reference to the parsed vpd map. |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 220 | * @param[in] isSystemVpd - Denotes whether we are collecting the system VPD. |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 221 | */ |
| 222 | template <typename T> |
| 223 | static void populateInterfaces(const nlohmann::json& js, |
| 224 | inventory::InterfaceMap& interfaces, |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 225 | const T& vpdMap, bool isSystemVpd) |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 226 | { |
| 227 | for (const auto& ifs : js.items()) |
| 228 | { |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 229 | string inf = ifs.key(); |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 230 | inventory::PropertyMap props; |
| 231 | |
| 232 | for (const auto& itr : ifs.value().items()) |
| 233 | { |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 234 | const string& busProp = itr.key(); |
| 235 | |
Alpana Kumari | 31970de | 2020-02-17 06:49:57 -0600 | [diff] [blame] | 236 | if (itr.value().is_boolean()) |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 237 | { |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 238 | props.emplace(busProp, itr.value().get<bool>()); |
| 239 | } |
| 240 | else if (itr.value().is_string()) |
| 241 | { |
Alpana Kumari | 58e2214 | 2020-05-05 00:22:12 -0500 | [diff] [blame] | 242 | if constexpr (is_same<T, Parsed>::value) |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 243 | { |
| 244 | if (busProp == "LocationCode" && |
Alpana Kumari | 414d5ae | 2021-03-04 21:06:35 +0000 | [diff] [blame] | 245 | inf == IBM_LOCATION_CODE_INF) |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 246 | { |
Alpana Kumari | 414d5ae | 2021-03-04 21:06:35 +0000 | [diff] [blame] | 247 | // TODO deprecate the com.ibm interface later |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 248 | auto prop = expandLocationCode( |
| 249 | itr.value().get<string>(), vpdMap, isSystemVpd); |
| 250 | props.emplace(busProp, prop); |
Alpana Kumari | 414d5ae | 2021-03-04 21:06:35 +0000 | [diff] [blame] | 251 | interfaces.emplace(XYZ_LOCATION_CODE_INF, props); |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 252 | } |
| 253 | else |
| 254 | { |
| 255 | props.emplace(busProp, itr.value().get<string>()); |
| 256 | } |
| 257 | } |
| 258 | else |
| 259 | { |
| 260 | props.emplace(busProp, itr.value().get<string>()); |
| 261 | } |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 262 | } |
Santosh Puranik | ed609af | 2021-06-21 11:30:07 +0530 | [diff] [blame] | 263 | else if (itr.value().is_array()) |
| 264 | { |
| 265 | try |
| 266 | { |
| 267 | props.emplace(busProp, itr.value().get<Binary>()); |
| 268 | } |
Patrick Williams | 8e15b93 | 2021-10-06 13:04:22 -0500 | [diff] [blame] | 269 | catch (const nlohmann::detail::type_error& e) |
Santosh Puranik | ed609af | 2021-06-21 11:30:07 +0530 | [diff] [blame] | 270 | { |
| 271 | std::cerr << "Type exception: " << e.what() << "\n"; |
| 272 | // Ignore any type errors |
| 273 | } |
| 274 | } |
Alpana Kumari | 31970de | 2020-02-17 06:49:57 -0600 | [diff] [blame] | 275 | else if (itr.value().is_object()) |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 276 | { |
Alpana Kumari | 31970de | 2020-02-17 06:49:57 -0600 | [diff] [blame] | 277 | const string& rec = itr.value().value("recordName", ""); |
| 278 | const string& kw = itr.value().value("keywordName", ""); |
| 279 | const string& encoding = itr.value().value("encoding", ""); |
| 280 | |
Alpana Kumari | 58e2214 | 2020-05-05 00:22:12 -0500 | [diff] [blame] | 281 | if constexpr (is_same<T, Parsed>::value) |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 282 | { |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 283 | if (!rec.empty() && !kw.empty() && vpdMap.count(rec) && |
| 284 | vpdMap.at(rec).count(kw)) |
Alpana Kumari | 31970de | 2020-02-17 06:49:57 -0600 | [diff] [blame] | 285 | { |
| 286 | auto encoded = |
| 287 | encodeKeyword(vpdMap.at(rec).at(kw), encoding); |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 288 | props.emplace(busProp, encoded); |
Alpana Kumari | 31970de | 2020-02-17 06:49:57 -0600 | [diff] [blame] | 289 | } |
| 290 | } |
Alpana Kumari | 58e2214 | 2020-05-05 00:22:12 -0500 | [diff] [blame] | 291 | else if constexpr (is_same<T, KeywordVpdMap>::value) |
Alpana Kumari | 31970de | 2020-02-17 06:49:57 -0600 | [diff] [blame] | 292 | { |
| 293 | if (!kw.empty() && vpdMap.count(kw)) |
| 294 | { |
Alpana Kumari | 3ab26a7 | 2021-04-05 19:09:19 +0000 | [diff] [blame] | 295 | auto kwValue = get_if<Binary>(&vpdMap.at(kw)); |
| 296 | auto uintValue = get_if<size_t>(&vpdMap.at(kw)); |
| 297 | |
| 298 | if (kwValue) |
| 299 | { |
| 300 | auto prop = |
| 301 | string((*kwValue).begin(), (*kwValue).end()); |
| 302 | |
| 303 | auto encoded = encodeKeyword(prop, encoding); |
| 304 | |
| 305 | props.emplace(busProp, encoded); |
| 306 | } |
| 307 | else if (uintValue) |
| 308 | { |
| 309 | props.emplace(busProp, *uintValue); |
| 310 | } |
Alpana Kumari | 31970de | 2020-02-17 06:49:57 -0600 | [diff] [blame] | 311 | } |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 312 | } |
| 313 | } |
Matt Spinler | b1e64bb | 2021-09-08 09:57:48 -0500 | [diff] [blame] | 314 | else if (itr.value().is_number()) |
| 315 | { |
| 316 | // For now assume the value is a size_t. In the future it would |
| 317 | // be nice to come up with a way to get the type from the JSON. |
| 318 | props.emplace(busProp, itr.value().get<size_t>()); |
| 319 | } |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 320 | } |
| 321 | interfaces.emplace(inf, move(props)); |
| 322 | } |
| 323 | } |
| 324 | |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 325 | static Binary getVpdDataInVector(const nlohmann::json& js, const string& file) |
Alpana Kumari | 58e2214 | 2020-05-05 00:22:12 -0500 | [diff] [blame] | 326 | { |
| 327 | uint32_t offset = 0; |
| 328 | // check if offset present? |
| 329 | for (const auto& item : js["frus"][file]) |
| 330 | { |
| 331 | if (item.find("offset") != item.end()) |
| 332 | { |
| 333 | offset = item["offset"]; |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | // TODO: Figure out a better way to get max possible VPD size. |
| 338 | Binary vpdVector; |
| 339 | vpdVector.resize(65504); |
| 340 | ifstream vpdFile; |
| 341 | vpdFile.open(file, ios::binary); |
| 342 | |
| 343 | vpdFile.seekg(offset, ios_base::cur); |
| 344 | vpdFile.read(reinterpret_cast<char*>(&vpdVector[0]), 65504); |
| 345 | vpdVector.resize(vpdFile.gcount()); |
| 346 | |
| 347 | return vpdVector; |
| 348 | } |
| 349 | |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 350 | /** This API will be called at the end of VPD collection to perform any post |
| 351 | * actions. |
| 352 | * |
| 353 | * @param[in] json - json object |
| 354 | * @param[in] file - eeprom file path |
| 355 | */ |
| 356 | static void postFailAction(const nlohmann::json& json, const string& file) |
| 357 | { |
| 358 | if ((json["frus"][file].at(0)).find("postActionFail") == |
| 359 | json["frus"][file].at(0).end()) |
| 360 | { |
| 361 | return; |
| 362 | } |
| 363 | |
| 364 | uint8_t pinValue = 0; |
| 365 | string pinName; |
| 366 | |
| 367 | for (const auto& postAction : |
| 368 | (json["frus"][file].at(0))["postActionFail"].items()) |
| 369 | { |
| 370 | if (postAction.key() == "pin") |
| 371 | { |
| 372 | pinName = postAction.value(); |
| 373 | } |
| 374 | else if (postAction.key() == "value") |
| 375 | { |
| 376 | // Get the value to set |
| 377 | pinValue = postAction.value(); |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | cout << "Setting GPIO: " << pinName << " to " << (int)pinValue << endl; |
| 382 | |
| 383 | try |
| 384 | { |
| 385 | gpiod::line outputLine = gpiod::find_line(pinName); |
| 386 | |
| 387 | if (!outputLine) |
| 388 | { |
| 389 | cout << "Couldn't find output line:" << pinName |
| 390 | << " on GPIO. Skipping...\n"; |
| 391 | |
| 392 | return; |
| 393 | } |
| 394 | outputLine.request( |
| 395 | {"Disable line", ::gpiod::line_request::DIRECTION_OUTPUT, 0}, |
| 396 | pinValue); |
| 397 | } |
Patrick Williams | 8e15b93 | 2021-10-06 13:04:22 -0500 | [diff] [blame] | 398 | catch (const system_error&) |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 399 | { |
| 400 | cerr << "Failed to set post-action GPIO" << endl; |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | /** Performs any pre-action needed to get the FRU setup for collection. |
| 405 | * |
| 406 | * @param[in] json - json object |
| 407 | * @param[in] file - eeprom file path |
| 408 | */ |
| 409 | static void preAction(const nlohmann::json& json, const string& file) |
| 410 | { |
| 411 | if ((json["frus"][file].at(0)).find("preAction") == |
| 412 | json["frus"][file].at(0).end()) |
| 413 | { |
| 414 | return; |
| 415 | } |
| 416 | |
| 417 | uint8_t pinValue = 0; |
| 418 | string pinName; |
| 419 | |
| 420 | for (const auto& postAction : |
| 421 | (json["frus"][file].at(0))["preAction"].items()) |
| 422 | { |
| 423 | if (postAction.key() == "pin") |
| 424 | { |
| 425 | pinName = postAction.value(); |
| 426 | } |
| 427 | else if (postAction.key() == "value") |
| 428 | { |
| 429 | // Get the value to set |
| 430 | pinValue = postAction.value(); |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | cout << "Setting GPIO: " << pinName << " to " << (int)pinValue << endl; |
| 435 | try |
| 436 | { |
| 437 | gpiod::line outputLine = gpiod::find_line(pinName); |
| 438 | |
| 439 | if (!outputLine) |
| 440 | { |
| 441 | cout << "Couldn't find output line:" << pinName |
| 442 | << " on GPIO. Skipping...\n"; |
| 443 | |
| 444 | return; |
| 445 | } |
| 446 | outputLine.request( |
| 447 | {"FRU pre-action", ::gpiod::line_request::DIRECTION_OUTPUT, 0}, |
| 448 | pinValue); |
| 449 | } |
Patrick Williams | 8e15b93 | 2021-10-06 13:04:22 -0500 | [diff] [blame] | 450 | catch (const system_error&) |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 451 | { |
| 452 | cerr << "Failed to set pre-action GPIO" << endl; |
| 453 | return; |
| 454 | } |
| 455 | |
| 456 | // Now bind the device |
Alpana Kumari | 4c3bf5b | 2021-09-16 07:24:58 -0500 | [diff] [blame] | 457 | string bind = json["frus"][file].at(0).value("devAddress", ""); |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 458 | cout << "Binding device " << bind << endl; |
| 459 | string bindCmd = string("echo \"") + bind + |
| 460 | string("\" > /sys/bus/i2c/drivers/at24/bind"); |
| 461 | cout << bindCmd << endl; |
| 462 | executeCmd(bindCmd); |
| 463 | |
| 464 | // Check if device showed up (test for file) |
| 465 | if (!fs::exists(file)) |
| 466 | { |
| 467 | cout << "EEPROM " << file << " does not exist. Take failure action" |
| 468 | << endl; |
| 469 | // If not, then take failure postAction |
| 470 | postFailAction(json, file); |
| 471 | } |
| 472 | } |
| 473 | |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 474 | /** |
Santosh Puranik | d3a379a | 2021-08-23 19:12:59 +0530 | [diff] [blame] | 475 | * @brief Set certain one time properties in the inventory |
| 476 | * Use this function to insert the Functional and Enabled properties into the |
| 477 | * inventory map. This function first checks if the object in question already |
| 478 | * has these properties hosted on D-Bus, if the property is already there, it is |
| 479 | * not modified, hence the name "one time". If the property is not already |
| 480 | * present, it will be added to the map with a suitable default value (true for |
| 481 | * Functional and false for Enabled) |
| 482 | * |
| 483 | * @param[in] object - The inventory D-Bus obejct without the inventory prefix. |
| 484 | * @param[inout] interfaces - Reference to a map of inventory interfaces to |
| 485 | * which the properties will be attached. |
| 486 | */ |
| 487 | static void setOneTimeProperties(const std::string& object, |
| 488 | inventory::InterfaceMap& interfaces) |
| 489 | { |
| 490 | auto bus = sdbusplus::bus::new_default(); |
| 491 | auto objectPath = INVENTORY_PATH + object; |
| 492 | auto prop = bus.new_method_call("xyz.openbmc_project.Inventory.Manager", |
| 493 | objectPath.c_str(), |
| 494 | "org.freedesktop.DBus.Properties", "Get"); |
| 495 | prop.append("xyz.openbmc_project.State.Decorator.OperationalStatus"); |
| 496 | prop.append("Functional"); |
| 497 | try |
| 498 | { |
| 499 | auto result = bus.call(prop); |
| 500 | } |
| 501 | catch (const sdbusplus::exception::SdBusError& e) |
| 502 | { |
| 503 | // Treat as property unavailable |
| 504 | inventory::PropertyMap prop; |
| 505 | prop.emplace("Functional", true); |
| 506 | interfaces.emplace( |
| 507 | "xyz.openbmc_project.State.Decorator.OperationalStatus", |
| 508 | move(prop)); |
| 509 | } |
| 510 | prop = bus.new_method_call("xyz.openbmc_project.Inventory.Manager", |
| 511 | objectPath.c_str(), |
| 512 | "org.freedesktop.DBus.Properties", "Get"); |
| 513 | prop.append("xyz.openbmc_project.Object.Enable"); |
| 514 | prop.append("Enabled"); |
| 515 | try |
| 516 | { |
| 517 | auto result = bus.call(prop); |
| 518 | } |
| 519 | catch (const sdbusplus::exception::SdBusError& e) |
| 520 | { |
| 521 | // Treat as property unavailable |
| 522 | inventory::PropertyMap prop; |
| 523 | prop.emplace("Enabled", false); |
| 524 | interfaces.emplace("xyz.openbmc_project.Object.Enable", move(prop)); |
| 525 | } |
| 526 | } |
| 527 | |
| 528 | /** |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 529 | * @brief Prime the Inventory |
| 530 | * Prime the inventory by populating only the location code, |
| 531 | * type interface and the inventory object for the frus |
| 532 | * which are not system vpd fru. |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 533 | * |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 534 | * @param[in] jsObject - Reference to vpd inventory json object |
| 535 | * @param[in] vpdMap - Reference to the parsed vpd map |
| 536 | * |
| 537 | * @returns Map of items in extraInterface. |
| 538 | */ |
| 539 | template <typename T> |
| 540 | inventory::ObjectMap primeInventory(const nlohmann::json& jsObject, |
| 541 | const T& vpdMap) |
| 542 | { |
| 543 | inventory::ObjectMap objects; |
| 544 | |
| 545 | for (auto& itemFRUS : jsObject["frus"].items()) |
| 546 | { |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 547 | // Take pre actions |
| 548 | preAction(jsObject, itemFRUS.key()); |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 549 | for (auto& itemEEPROM : itemFRUS.value()) |
| 550 | { |
| 551 | inventory::InterfaceMap interfaces; |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 552 | inventory::Object object(itemEEPROM.at("inventoryPath")); |
| 553 | |
Santosh Puranik | 50f60bf | 2021-05-26 17:55:06 +0530 | [diff] [blame] | 554 | if ((itemFRUS.key() != systemVpdFilePath) && |
| 555 | !itemEEPROM.value("noprime", false)) |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 556 | { |
Alpana Kumari | cfd7a75 | 2021-02-07 23:23:01 -0600 | [diff] [blame] | 557 | inventory::PropertyMap presProp; |
| 558 | presProp.emplace("Present", false); |
| 559 | interfaces.emplace("xyz.openbmc_project.Inventory.Item", |
Santosh Puranik | d3a379a | 2021-08-23 19:12:59 +0530 | [diff] [blame] | 560 | presProp); |
| 561 | setOneTimeProperties(object, interfaces); |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 562 | if (itemEEPROM.find("extraInterfaces") != itemEEPROM.end()) |
| 563 | { |
| 564 | for (const auto& eI : itemEEPROM["extraInterfaces"].items()) |
| 565 | { |
| 566 | inventory::PropertyMap props; |
Alpana Kumari | 414d5ae | 2021-03-04 21:06:35 +0000 | [diff] [blame] | 567 | if (eI.key() == IBM_LOCATION_CODE_INF) |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 568 | { |
| 569 | if constexpr (std::is_same<T, Parsed>::value) |
| 570 | { |
| 571 | for (auto& lC : eI.value().items()) |
| 572 | { |
| 573 | auto propVal = expandLocationCode( |
| 574 | lC.value().get<string>(), vpdMap, true); |
| 575 | |
| 576 | props.emplace(move(lC.key()), |
| 577 | move(propVal)); |
Santosh Puranik | b0f3749 | 2021-06-21 09:42:47 +0530 | [diff] [blame] | 578 | interfaces.emplace(XYZ_LOCATION_CODE_INF, |
| 579 | props); |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 580 | interfaces.emplace(move(eI.key()), |
| 581 | move(props)); |
| 582 | } |
| 583 | } |
| 584 | } |
| 585 | else if (eI.key().find("Inventory.Item.") != |
| 586 | string::npos) |
| 587 | { |
| 588 | interfaces.emplace(move(eI.key()), move(props)); |
| 589 | } |
Santosh Puranik | d3a379a | 2021-08-23 19:12:59 +0530 | [diff] [blame] | 590 | else if (eI.key() == |
| 591 | "xyz.openbmc_project.Inventory.Item") |
| 592 | { |
| 593 | for (auto& val : eI.value().items()) |
| 594 | { |
| 595 | if (val.key() == "PrettyName") |
| 596 | { |
| 597 | presProp.emplace(val.key(), |
| 598 | val.value().get<string>()); |
| 599 | } |
| 600 | } |
| 601 | // Use insert_or_assign here as we may already have |
| 602 | // inserted the present property only earlier in |
| 603 | // this function under this same interface. |
| 604 | interfaces.insert_or_assign(eI.key(), |
| 605 | move(presProp)); |
| 606 | } |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 607 | } |
| 608 | } |
| 609 | objects.emplace(move(object), move(interfaces)); |
| 610 | } |
| 611 | } |
| 612 | } |
| 613 | return objects; |
| 614 | } |
| 615 | |
Alpana Kumari | 65b8360 | 2020-09-01 00:24:56 -0500 | [diff] [blame] | 616 | /** |
| 617 | * @brief This API executes command to set environment variable |
| 618 | * And then reboot the system |
| 619 | * @param[in] key -env key to set new value |
| 620 | * @param[in] value -value to set. |
| 621 | */ |
| 622 | void setEnvAndReboot(const string& key, const string& value) |
| 623 | { |
| 624 | // set env and reboot and break. |
| 625 | executeCmd("/sbin/fw_setenv", key, value); |
Andrew Geissler | 280197e | 2020-12-08 20:51:49 -0600 | [diff] [blame] | 626 | log<level::INFO>("Rebooting BMC to pick up new device tree"); |
Alpana Kumari | 65b8360 | 2020-09-01 00:24:56 -0500 | [diff] [blame] | 627 | // make dbus call to reboot |
| 628 | auto bus = sdbusplus::bus::new_default_system(); |
| 629 | auto method = bus.new_method_call( |
| 630 | "org.freedesktop.systemd1", "/org/freedesktop/systemd1", |
| 631 | "org.freedesktop.systemd1.Manager", "Reboot"); |
| 632 | bus.call_noreply(method); |
| 633 | } |
| 634 | |
| 635 | /* |
| 636 | * @brief This API checks for env var fitconfig. |
| 637 | * If not initialised OR updated as per the current system type, |
| 638 | * update this env var and reboot the system. |
| 639 | * |
| 640 | * @param[in] systemType IM kwd in vpd tells about which system type it is. |
| 641 | * */ |
| 642 | void setDevTreeEnv(const string& systemType) |
| 643 | { |
| 644 | string newDeviceTree; |
| 645 | |
| 646 | if (deviceTreeSystemTypeMap.find(systemType) != |
| 647 | deviceTreeSystemTypeMap.end()) |
| 648 | { |
| 649 | newDeviceTree = deviceTreeSystemTypeMap.at(systemType); |
| 650 | } |
| 651 | |
| 652 | string readVarValue; |
| 653 | bool envVarFound = false; |
| 654 | |
| 655 | vector<string> output = executeCmd("/sbin/fw_printenv"); |
| 656 | for (const auto& entry : output) |
| 657 | { |
| 658 | size_t pos = entry.find("="); |
| 659 | string key = entry.substr(0, pos); |
| 660 | if (key != "fitconfig") |
| 661 | { |
| 662 | continue; |
| 663 | } |
| 664 | |
| 665 | envVarFound = true; |
| 666 | if (pos + 1 < entry.size()) |
| 667 | { |
| 668 | readVarValue = entry.substr(pos + 1); |
| 669 | if (readVarValue.find(newDeviceTree) != string::npos) |
| 670 | { |
| 671 | // fitconfig is Updated. No action needed |
| 672 | break; |
| 673 | } |
| 674 | } |
| 675 | // set env and reboot and break. |
| 676 | setEnvAndReboot(key, newDeviceTree); |
| 677 | exit(0); |
| 678 | } |
| 679 | |
| 680 | // check If env var Not found |
| 681 | if (!envVarFound) |
| 682 | { |
| 683 | setEnvAndReboot("fitconfig", newDeviceTree); |
| 684 | } |
| 685 | } |
| 686 | |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 687 | /** |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 688 | * @brief API to call VPD manager to write VPD to EEPROM. |
| 689 | * @param[in] Object path. |
| 690 | * @param[in] record to be updated. |
| 691 | * @param[in] keyword to be updated. |
| 692 | * @param[in] keyword data to be updated |
| 693 | */ |
| 694 | void updateHardware(const string& objectName, const string& recName, |
| 695 | const string& kwdName, const Binary& data) |
| 696 | { |
| 697 | try |
| 698 | { |
| 699 | auto bus = sdbusplus::bus::new_default(); |
| 700 | auto properties = |
| 701 | bus.new_method_call(BUSNAME, OBJPATH, IFACE, "WriteKeyword"); |
| 702 | properties.append( |
| 703 | static_cast<sdbusplus::message::object_path>(objectName)); |
| 704 | properties.append(recName); |
| 705 | properties.append(kwdName); |
| 706 | properties.append(data); |
| 707 | bus.call(properties); |
| 708 | } |
Patrick Williams | 8be4334 | 2021-09-02 09:33:36 -0500 | [diff] [blame] | 709 | catch (const sdbusplus::exception::exception& e) |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 710 | { |
| 711 | std::string what = |
| 712 | "VPDManager WriteKeyword api failed for inventory path " + |
| 713 | objectName; |
| 714 | what += " record " + recName; |
| 715 | what += " keyword " + kwdName; |
| 716 | what += " with bus error = " + std::string(e.what()); |
| 717 | |
| 718 | // map to hold additional data in case of logging pel |
| 719 | PelAdditionalData additionalData{}; |
| 720 | additionalData.emplace("CALLOUT_INVENTORY_PATH", objectName); |
| 721 | additionalData.emplace("DESCRIPTION", what); |
Sunny Srivastava | 0746eee | 2021-03-22 13:36:54 -0500 | [diff] [blame] | 722 | createPEL(additionalData, PelSeverity::WARNING, errIntfForBusFailure); |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 723 | } |
| 724 | } |
| 725 | |
| 726 | /** |
| 727 | * @brief API to check if we need to restore system VPD |
| 728 | * This functionality is only applicable for IPZ VPD data. |
| 729 | * @param[in] vpdMap - IPZ vpd map |
| 730 | * @param[in] objectPath - Object path for the FRU |
| 731 | * @return EEPROMs with records and keywords updated at standby |
| 732 | */ |
| 733 | std::vector<RestoredEeproms> restoreSystemVPD(Parsed& vpdMap, |
| 734 | const string& objectPath) |
| 735 | { |
| 736 | // the list of keywords for VSYS record is as per the S0 system. Should be |
| 737 | // updated for another type of systems |
| 738 | static std::unordered_map<std::string, std::vector<std::string>> svpdKwdMap{ |
| 739 | {"VSYS", {"BR", "TM", "SE", "SU", "RB"}}, |
| 740 | {"VCEN", {"FC", "SE"}}, |
| 741 | {"LXR0", {"LX"}}}; |
| 742 | |
| 743 | // vector to hold all the EEPROMs updated at standby |
| 744 | std::vector<RestoredEeproms> updatedEeproms = {}; |
| 745 | |
| 746 | for (const auto& systemRecKwdPair : svpdKwdMap) |
| 747 | { |
| 748 | auto it = vpdMap.find(systemRecKwdPair.first); |
| 749 | |
| 750 | // check if record is found in map we got by parser |
| 751 | if (it != vpdMap.end()) |
| 752 | { |
| 753 | const auto& kwdListForRecord = systemRecKwdPair.second; |
| 754 | for (const auto& keyword : kwdListForRecord) |
| 755 | { |
| 756 | DbusPropertyMap& kwdValMap = it->second; |
| 757 | auto iterator = kwdValMap.find(keyword); |
| 758 | |
| 759 | if (iterator != kwdValMap.end()) |
| 760 | { |
| 761 | string& kwdValue = iterator->second; |
| 762 | |
| 763 | // check bus data |
| 764 | const string& recordName = systemRecKwdPair.first; |
| 765 | const string& busValue = readBusProperty( |
| 766 | objectPath, ipzVpdInf + recordName, keyword); |
| 767 | |
| 768 | if (busValue.find_first_not_of(' ') != string::npos) |
| 769 | { |
| 770 | if (kwdValue.find_first_not_of(' ') != string::npos) |
| 771 | { |
| 772 | // both the data are present, check for mismatch |
| 773 | if (busValue != kwdValue) |
| 774 | { |
| 775 | string errMsg = "VPD data mismatch on cache " |
| 776 | "and hardware for record: "; |
| 777 | errMsg += (*it).first; |
| 778 | errMsg += " and keyword: "; |
| 779 | errMsg += keyword; |
| 780 | |
| 781 | // data mismatch |
| 782 | PelAdditionalData additionalData; |
| 783 | additionalData.emplace("CALLOUT_INVENTORY_PATH", |
| 784 | objectPath); |
| 785 | |
| 786 | additionalData.emplace("DESCRIPTION", errMsg); |
| 787 | |
Sunny Srivastava | 0746eee | 2021-03-22 13:36:54 -0500 | [diff] [blame] | 788 | createPEL(additionalData, PelSeverity::WARNING, |
| 789 | errIntfForInvalidVPD); |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 790 | } |
| 791 | } |
| 792 | else |
| 793 | { |
| 794 | // implies hardware data is blank |
| 795 | // update the map |
| 796 | Binary busData(busValue.begin(), busValue.end()); |
| 797 | |
| 798 | updatedEeproms.push_back(std::make_tuple( |
| 799 | objectPath, recordName, keyword, busData)); |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 800 | |
Sunny Srivastava | 90a63b9 | 2021-05-26 06:30:24 -0500 | [diff] [blame] | 801 | // update the map as well, so that cache data is not |
| 802 | // updated as blank while populating VPD map on Dbus |
| 803 | // in populateDBus Api |
| 804 | kwdValue = busValue; |
| 805 | } |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 806 | } |
| 807 | else if (kwdValue.find_first_not_of(' ') == string::npos) |
| 808 | { |
| 809 | string errMsg = "VPD is blank on both cache and " |
| 810 | "hardware for record: "; |
| 811 | errMsg += (*it).first; |
| 812 | errMsg += " and keyword: "; |
| 813 | errMsg += keyword; |
| 814 | errMsg += ". SSR need to update hardware VPD."; |
| 815 | |
| 816 | // both the data are blanks, log PEL |
| 817 | PelAdditionalData additionalData; |
| 818 | additionalData.emplace("CALLOUT_INVENTORY_PATH", |
| 819 | objectPath); |
| 820 | |
| 821 | additionalData.emplace("DESCRIPTION", errMsg); |
| 822 | |
| 823 | // log PEL TODO: Block IPL |
Sunny Srivastava | 0746eee | 2021-03-22 13:36:54 -0500 | [diff] [blame] | 824 | createPEL(additionalData, PelSeverity::ERROR, |
| 825 | errIntfForBlankSystemVPD); |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 826 | continue; |
| 827 | } |
| 828 | } |
| 829 | } |
| 830 | } |
| 831 | } |
| 832 | |
| 833 | return updatedEeproms; |
| 834 | } |
| 835 | |
| 836 | /** |
alpana07 | 7ce6872 | 2021-07-25 13:23:59 -0500 | [diff] [blame] | 837 | * @brief This checks for is this FRU a processor |
| 838 | * And if yes, then checks for is this primary |
| 839 | * |
| 840 | * @param[in] js- vpd json to get the information about this FRU |
| 841 | * @param[in] filePath- FRU vpd |
| 842 | * |
| 843 | * @return true/false |
| 844 | */ |
| 845 | bool isThisPrimaryProcessor(nlohmann::json& js, const string& filePath) |
| 846 | { |
| 847 | bool isProcessor = false; |
| 848 | bool isPrimary = false; |
| 849 | |
| 850 | for (const auto& item : js["frus"][filePath]) |
| 851 | { |
| 852 | if (item.find("extraInterfaces") != item.end()) |
| 853 | { |
| 854 | for (const auto& eI : item["extraInterfaces"].items()) |
| 855 | { |
| 856 | if (eI.key().find("Inventory.Item.Cpu") != string::npos) |
| 857 | { |
| 858 | isProcessor = true; |
| 859 | } |
| 860 | } |
| 861 | } |
| 862 | |
| 863 | if (isProcessor) |
| 864 | { |
| 865 | string cpuType = item.value("cpuType", ""); |
| 866 | if (cpuType == "primary") |
| 867 | { |
| 868 | isPrimary = true; |
| 869 | } |
| 870 | } |
| 871 | } |
| 872 | |
| 873 | return (isProcessor && isPrimary); |
| 874 | } |
| 875 | |
| 876 | /** |
| 877 | * @brief This finds DIMM vpd in vpd json and enables them by binding the device |
| 878 | * driver |
| 879 | * @param[in] js- vpd json to iterate through and take action if it is DIMM |
| 880 | */ |
| 881 | void doEnableAllDimms(nlohmann::json& js) |
| 882 | { |
| 883 | // iterate over each fru |
| 884 | for (const auto& eachFru : js["frus"].items()) |
| 885 | { |
| 886 | // skip the driver binding if eeprom already exists |
| 887 | if (fs::exists(eachFru.key())) |
| 888 | { |
| 889 | continue; |
| 890 | } |
| 891 | |
| 892 | for (const auto& eachInventory : eachFru.value()) |
| 893 | { |
| 894 | if (eachInventory.find("extraInterfaces") != eachInventory.end()) |
| 895 | { |
| 896 | for (const auto& eI : eachInventory["extraInterfaces"].items()) |
| 897 | { |
| 898 | if (eI.key().find("Inventory.Item.Dimm") != string::npos) |
| 899 | { |
| 900 | string dimmVpd = eachFru.key(); |
| 901 | // fetch it from |
| 902 | // "/sys/bus/i2c/drivers/at24/414-0050/eeprom" |
| 903 | |
| 904 | regex matchPatern("([0-9]+-[0-9]{4})"); |
| 905 | smatch matchFound; |
| 906 | if (regex_search(dimmVpd, matchFound, matchPatern)) |
| 907 | { |
| 908 | vector<string> i2cReg; |
| 909 | boost::split(i2cReg, matchFound.str(0), |
| 910 | boost::is_any_of("-")); |
| 911 | |
| 912 | // remove 0s from begining |
| 913 | const regex pattern("^0+(?!$)"); |
| 914 | for (auto& i : i2cReg) |
| 915 | { |
| 916 | i = regex_replace(i, pattern, ""); |
| 917 | } |
| 918 | |
| 919 | if (i2cReg.size() == 2) |
| 920 | { |
| 921 | // echo 24c32 0x50 > |
| 922 | // /sys/bus/i2c/devices/i2c-16/new_device |
| 923 | string cmnd = "echo 24c32 0x" + i2cReg[1] + |
| 924 | " > /sys/bus/i2c/devices/i2c-" + |
| 925 | i2cReg[0] + "/new_device"; |
| 926 | |
| 927 | executeCmd(cmnd); |
| 928 | } |
| 929 | } |
| 930 | } |
| 931 | } |
| 932 | } |
| 933 | } |
| 934 | } |
| 935 | } |
| 936 | |
| 937 | /** |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 938 | * @brief Populate Dbus. |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 939 | * This method invokes all the populateInterface functions |
| 940 | * and notifies PIM about dbus object. |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 941 | * @param[in] vpdMap - Either IPZ vpd map or Keyword vpd map based on the |
| 942 | * input. |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 943 | * @param[in] js - Inventory json object |
| 944 | * @param[in] filePath - Path of the vpd file |
| 945 | * @param[in] preIntrStr - Interface string |
| 946 | */ |
| 947 | template <typename T> |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 948 | static void populateDbus(T& vpdMap, nlohmann::json& js, const string& filePath) |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 949 | { |
| 950 | inventory::InterfaceMap interfaces; |
| 951 | inventory::ObjectMap objects; |
| 952 | inventory::PropertyMap prop; |
| 953 | |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 954 | // map to hold all the keywords whose value has been changed at standby |
| 955 | vector<RestoredEeproms> updatedEeproms = {}; |
| 956 | |
Santosh Puranik | 50f60bf | 2021-05-26 17:55:06 +0530 | [diff] [blame] | 957 | bool isSystemVpd = (filePath == systemVpdFilePath); |
| 958 | if constexpr (is_same<T, Parsed>::value) |
| 959 | { |
| 960 | if (isSystemVpd) |
| 961 | { |
| 962 | std::vector<std::string> interfaces = {motherBoardInterface}; |
| 963 | // call mapper to check for object path creation |
| 964 | MapperResponse subTree = |
| 965 | getObjectSubtreeForInterfaces(pimPath, 0, interfaces); |
| 966 | string mboardPath = |
| 967 | js["frus"][filePath].at(0).value("inventoryPath", ""); |
| 968 | |
| 969 | // Attempt system VPD restore if we have a motherboard |
| 970 | // object in the inventory. |
| 971 | if ((subTree.size() != 0) && |
| 972 | (subTree.find(pimPath + mboardPath) != subTree.end())) |
| 973 | { |
| 974 | updatedEeproms = restoreSystemVPD(vpdMap, mboardPath); |
| 975 | } |
| 976 | else |
| 977 | { |
| 978 | log<level::ERR>("No object path found"); |
| 979 | } |
| 980 | } |
alpana07 | 7ce6872 | 2021-07-25 13:23:59 -0500 | [diff] [blame] | 981 | else |
| 982 | { |
| 983 | // check if it is processor vpd. |
| 984 | auto isPrimaryCpu = isThisPrimaryProcessor(js, filePath); |
| 985 | |
| 986 | if (isPrimaryCpu) |
| 987 | { |
| 988 | auto ddVersion = getKwVal(vpdMap, "CRP0", "DD"); |
| 989 | |
| 990 | auto chipVersion = atoi(ddVersion.substr(1, 2).c_str()); |
| 991 | |
| 992 | if (chipVersion >= 2) |
| 993 | { |
| 994 | doEnableAllDimms(js); |
| 995 | } |
| 996 | } |
| 997 | } |
Santosh Puranik | 50f60bf | 2021-05-26 17:55:06 +0530 | [diff] [blame] | 998 | } |
| 999 | |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1000 | for (const auto& item : js["frus"][filePath]) |
| 1001 | { |
| 1002 | const auto& objectPath = item["inventoryPath"]; |
| 1003 | sdbusplus::message::object_path object(objectPath); |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 1004 | |
Santosh Puranik | d3a379a | 2021-08-23 19:12:59 +0530 | [diff] [blame] | 1005 | if (isSystemVpd) |
| 1006 | { |
| 1007 | // Populate one time properties for the system VPD and its sub-frus. |
| 1008 | // For the remaining FRUs, this will get handled as a part of |
| 1009 | // priming the inventory. |
| 1010 | setOneTimeProperties(objectPath, interfaces); |
| 1011 | } |
| 1012 | |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1013 | // Populate the VPD keywords and the common interfaces only if we |
| 1014 | // are asked to inherit that data from the VPD, else only add the |
| 1015 | // extraInterfaces. |
| 1016 | if (item.value("inherit", true)) |
| 1017 | { |
Alpana Kumari | 58e2214 | 2020-05-05 00:22:12 -0500 | [diff] [blame] | 1018 | if constexpr (is_same<T, Parsed>::value) |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1019 | { |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 1020 | // Each record in the VPD becomes an interface and all |
| 1021 | // keyword within the record are properties under that |
| 1022 | // interface. |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1023 | for (const auto& record : vpdMap) |
| 1024 | { |
| 1025 | populateFruSpecificInterfaces( |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 1026 | record.second, ipzVpdInf + record.first, interfaces); |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1027 | } |
| 1028 | } |
Alpana Kumari | 58e2214 | 2020-05-05 00:22:12 -0500 | [diff] [blame] | 1029 | else if constexpr (is_same<T, KeywordVpdMap>::value) |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1030 | { |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 1031 | populateFruSpecificInterfaces(vpdMap, kwdVpdInf, interfaces); |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1032 | } |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 1033 | if (js.find("commonInterfaces") != js.end()) |
| 1034 | { |
| 1035 | populateInterfaces(js["commonInterfaces"], interfaces, vpdMap, |
| 1036 | isSystemVpd); |
| 1037 | } |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1038 | } |
Santosh Puranik | 0859eb6 | 2020-03-16 02:56:29 -0500 | [diff] [blame] | 1039 | else |
| 1040 | { |
| 1041 | // Check if we have been asked to inherit specific record(s) |
Alpana Kumari | 58e2214 | 2020-05-05 00:22:12 -0500 | [diff] [blame] | 1042 | if constexpr (is_same<T, Parsed>::value) |
Santosh Puranik | 0859eb6 | 2020-03-16 02:56:29 -0500 | [diff] [blame] | 1043 | { |
| 1044 | if (item.find("copyRecords") != item.end()) |
| 1045 | { |
| 1046 | for (const auto& record : item["copyRecords"]) |
| 1047 | { |
| 1048 | const string& recordName = record; |
| 1049 | if (vpdMap.find(recordName) != vpdMap.end()) |
| 1050 | { |
| 1051 | populateFruSpecificInterfaces( |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 1052 | vpdMap.at(recordName), ipzVpdInf + recordName, |
Santosh Puranik | 0859eb6 | 2020-03-16 02:56:29 -0500 | [diff] [blame] | 1053 | interfaces); |
| 1054 | } |
| 1055 | } |
| 1056 | } |
| 1057 | } |
| 1058 | } |
Alpana Kumari | 58e2214 | 2020-05-05 00:22:12 -0500 | [diff] [blame] | 1059 | if (item.value("inheritEI", true)) |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1060 | { |
Alpana Kumari | 58e2214 | 2020-05-05 00:22:12 -0500 | [diff] [blame] | 1061 | // Populate interfaces and properties that are common to every FRU |
| 1062 | // and additional interface that might be defined on a per-FRU |
| 1063 | // basis. |
| 1064 | if (item.find("extraInterfaces") != item.end()) |
| 1065 | { |
| 1066 | populateInterfaces(item["extraInterfaces"], interfaces, vpdMap, |
| 1067 | isSystemVpd); |
| 1068 | } |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1069 | } |
| 1070 | objects.emplace(move(object), move(interfaces)); |
| 1071 | } |
| 1072 | |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 1073 | if (isSystemVpd) |
| 1074 | { |
Santosh Puranik | d278df1 | 2021-05-10 15:51:42 +0530 | [diff] [blame] | 1075 | string systemJsonName{}; |
PriyangaRamasamy | 83a1d5d | 2020-04-30 19:15:43 +0530 | [diff] [blame] | 1076 | if constexpr (is_same<T, Parsed>::value) |
| 1077 | { |
Alpana Kumari | f05effd | 2021-04-07 07:32:53 -0500 | [diff] [blame] | 1078 | // pick the right system json |
Santosh Puranik | d278df1 | 2021-05-10 15:51:42 +0530 | [diff] [blame] | 1079 | systemJsonName = getSystemsJson(vpdMap); |
PriyangaRamasamy | 83a1d5d | 2020-04-30 19:15:43 +0530 | [diff] [blame] | 1080 | } |
| 1081 | |
Santosh Puranik | d278df1 | 2021-05-10 15:51:42 +0530 | [diff] [blame] | 1082 | fs::path target = systemJsonName; |
PriyangaRamasamy | 83a1d5d | 2020-04-30 19:15:43 +0530 | [diff] [blame] | 1083 | fs::path link = INVENTORY_JSON_SYM_LINK; |
| 1084 | |
Santosh Puranik | 0246a4d | 2020-11-04 16:57:39 +0530 | [diff] [blame] | 1085 | // Create the directory for hosting the symlink |
| 1086 | fs::create_directories(VPD_FILES_PATH); |
| 1087 | // unlink the symlink previously created (if any) |
PriyangaRamasamy | 83a1d5d | 2020-04-30 19:15:43 +0530 | [diff] [blame] | 1088 | remove(INVENTORY_JSON_SYM_LINK); |
| 1089 | // create a new symlink based on the system |
| 1090 | fs::create_symlink(target, link); |
| 1091 | |
| 1092 | // Reloading the json |
| 1093 | ifstream inventoryJson(link); |
| 1094 | auto js = json::parse(inventoryJson); |
| 1095 | inventoryJson.close(); |
| 1096 | |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 1097 | inventory::ObjectMap primeObject = primeInventory(js, vpdMap); |
| 1098 | objects.insert(primeObject.begin(), primeObject.end()); |
Alpana Kumari | 65b8360 | 2020-09-01 00:24:56 -0500 | [diff] [blame] | 1099 | |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 1100 | // if system VPD has been restored at standby, update the EEPROM |
| 1101 | for (const auto& item : updatedEeproms) |
| 1102 | { |
| 1103 | updateHardware(get<0>(item), get<1>(item), get<2>(item), |
| 1104 | get<3>(item)); |
| 1105 | } |
Alpana Kumari | f05effd | 2021-04-07 07:32:53 -0500 | [diff] [blame] | 1106 | |
| 1107 | // set the U-boot environment variable for device-tree |
| 1108 | if constexpr (is_same<T, Parsed>::value) |
| 1109 | { |
| 1110 | const string imKeyword = getIM(vpdMap); |
| 1111 | const string hwKeyword = getHW(vpdMap); |
| 1112 | string systemType = imKeyword; |
| 1113 | |
| 1114 | // check If system has constraint then append HW version to it. |
| 1115 | ifstream sysJson(SYSTEM_JSON); |
| 1116 | if (!sysJson) |
| 1117 | { |
| 1118 | throw((VpdJsonException("Failed to access Json path", |
| 1119 | SYSTEM_JSON))); |
| 1120 | } |
| 1121 | |
| 1122 | try |
| 1123 | { |
| 1124 | auto systemJson = json::parse(sysJson); |
Santosh Puranik | d278df1 | 2021-05-10 15:51:42 +0530 | [diff] [blame] | 1125 | if (systemJson["system"].find(imKeyword) != |
| 1126 | systemJson["system"].end()) |
| 1127 | { |
| 1128 | if (systemJson["system"][imKeyword].find("constraint") != |
| 1129 | systemJson["system"][imKeyword].end()) |
| 1130 | { |
| 1131 | systemType += "_" + hwKeyword; |
| 1132 | } |
| 1133 | } |
Alpana Kumari | f05effd | 2021-04-07 07:32:53 -0500 | [diff] [blame] | 1134 | } |
Patrick Williams | 8e15b93 | 2021-10-06 13:04:22 -0500 | [diff] [blame] | 1135 | catch (const json::parse_error& ex) |
Alpana Kumari | f05effd | 2021-04-07 07:32:53 -0500 | [diff] [blame] | 1136 | { |
| 1137 | throw((VpdJsonException("System Json parsing failed", |
| 1138 | SYSTEM_JSON))); |
| 1139 | } |
| 1140 | |
Alpana Kumari | f05effd | 2021-04-07 07:32:53 -0500 | [diff] [blame] | 1141 | setDevTreeEnv(systemType); |
| 1142 | } |
PriyangaRamasamy | 8e140a1 | 2020-04-13 19:24:03 +0530 | [diff] [blame] | 1143 | } |
| 1144 | |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1145 | // Notify PIM |
Sunny Srivastava | 6c71c9d | 2021-04-15 04:43:54 -0500 | [diff] [blame] | 1146 | common::utility::callPIM(move(objects)); |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1147 | } |
| 1148 | |
| 1149 | int main(int argc, char** argv) |
| 1150 | { |
| 1151 | int rc = 0; |
SunnySrivastava1984 | a20be8e | 2020-08-26 02:00:50 -0500 | [diff] [blame] | 1152 | json js{}; |
PriyangaRamasamy | c2fe40f | 2021-03-02 06:27:33 -0600 | [diff] [blame] | 1153 | Binary vpdVector{}; |
| 1154 | string file{}; |
SunnySrivastava1984 | a20be8e | 2020-08-26 02:00:50 -0500 | [diff] [blame] | 1155 | // map to hold additional data in case of logging pel |
| 1156 | PelAdditionalData additionalData{}; |
| 1157 | |
| 1158 | // this is needed to hold base fru inventory path in case there is ECC or |
| 1159 | // vpd exception while parsing the file |
| 1160 | std::string baseFruInventoryPath = {}; |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1161 | |
Sunny Srivastava | 0746eee | 2021-03-22 13:36:54 -0500 | [diff] [blame] | 1162 | // severity for PEL |
| 1163 | PelSeverity pelSeverity = PelSeverity::WARNING; |
| 1164 | |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1165 | try |
| 1166 | { |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1167 | App app{"ibm-read-vpd - App to read IPZ format VPD, parse it and store " |
| 1168 | "in DBUS"}; |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1169 | |
| 1170 | app.add_option("-f, --file", file, "File containing VPD (IPZ/KEYWORD)") |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 1171 | ->required(); |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1172 | |
| 1173 | CLI11_PARSE(app, argc, argv); |
| 1174 | |
Sunny Srivastava | 0746eee | 2021-03-22 13:36:54 -0500 | [diff] [blame] | 1175 | // PEL severity should be ERROR in case of any system VPD failure |
| 1176 | if (file == systemVpdFilePath) |
| 1177 | { |
| 1178 | pelSeverity = PelSeverity::ERROR; |
| 1179 | } |
| 1180 | |
Santosh Puranik | 0246a4d | 2020-11-04 16:57:39 +0530 | [diff] [blame] | 1181 | auto jsonToParse = INVENTORY_JSON_DEFAULT; |
| 1182 | |
| 1183 | // If the symlink exists, it means it has been setup for us, switch the |
| 1184 | // path |
| 1185 | if (fs::exists(INVENTORY_JSON_SYM_LINK)) |
| 1186 | { |
| 1187 | jsonToParse = INVENTORY_JSON_SYM_LINK; |
| 1188 | } |
| 1189 | |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1190 | // 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] | 1191 | ifstream inventoryJson(jsonToParse); |
SunnySrivastava1984 | a20be8e | 2020-08-26 02:00:50 -0500 | [diff] [blame] | 1192 | if (!inventoryJson) |
| 1193 | { |
Sunny Srivastava | 0746eee | 2021-03-22 13:36:54 -0500 | [diff] [blame] | 1194 | throw(VpdJsonException("Failed to access Json path", jsonToParse)); |
SunnySrivastava1984 | a20be8e | 2020-08-26 02:00:50 -0500 | [diff] [blame] | 1195 | } |
| 1196 | |
| 1197 | try |
| 1198 | { |
| 1199 | js = json::parse(inventoryJson); |
| 1200 | } |
Patrick Williams | 8e15b93 | 2021-10-06 13:04:22 -0500 | [diff] [blame] | 1201 | catch (const json::parse_error& ex) |
SunnySrivastava1984 | a20be8e | 2020-08-26 02:00:50 -0500 | [diff] [blame] | 1202 | { |
Sunny Srivastava | 0746eee | 2021-03-22 13:36:54 -0500 | [diff] [blame] | 1203 | throw(VpdJsonException("Json parsing failed", jsonToParse)); |
SunnySrivastava1984 | a20be8e | 2020-08-26 02:00:50 -0500 | [diff] [blame] | 1204 | } |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1205 | |
Santosh Puranik | 12e24ff | 2021-05-11 19:33:50 +0530 | [diff] [blame] | 1206 | // Do we have the mandatory "frus" section? |
| 1207 | if (js.find("frus") == js.end()) |
| 1208 | { |
| 1209 | throw(VpdJsonException("FRUs section not found in JSON", |
| 1210 | jsonToParse)); |
| 1211 | } |
| 1212 | |
PriyangaRamasamy | 647868e | 2020-09-08 17:03:19 +0530 | [diff] [blame] | 1213 | // Check if it's a udev path - patterned as(/ahb/ahb:apb/ahb:apb:bus@) |
| 1214 | if (file.find("/ahb:apb") != string::npos) |
| 1215 | { |
| 1216 | // Translate udev path to a generic /sys/bus/.. file path. |
| 1217 | udevToGenericPath(file); |
Santosh Puranik | 12e24ff | 2021-05-11 19:33:50 +0530 | [diff] [blame] | 1218 | |
| 1219 | if ((js["frus"].find(file) != js["frus"].end()) && |
Santosh Puranik | 50f60bf | 2021-05-26 17:55:06 +0530 | [diff] [blame] | 1220 | (file == systemVpdFilePath)) |
PriyangaRamasamy | 647868e | 2020-09-08 17:03:19 +0530 | [diff] [blame] | 1221 | { |
| 1222 | return 0; |
| 1223 | } |
| 1224 | } |
| 1225 | |
| 1226 | if (file.empty()) |
| 1227 | { |
| 1228 | cerr << "The EEPROM path <" << file << "> is not valid."; |
| 1229 | return 0; |
| 1230 | } |
Santosh Puranik | 12e24ff | 2021-05-11 19:33:50 +0530 | [diff] [blame] | 1231 | if (js["frus"].find(file) == js["frus"].end()) |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1232 | { |
Santosh Puranik | 88edeb6 | 2020-03-02 12:00:09 +0530 | [diff] [blame] | 1233 | return 0; |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1234 | } |
| 1235 | |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 1236 | if (!fs::exists(file)) |
| 1237 | { |
| 1238 | cout << "Device path: " << file |
| 1239 | << " does not exist. Spurious udev event? Exiting." << endl; |
| 1240 | return 0; |
| 1241 | } |
| 1242 | |
SunnySrivastava1984 | a20be8e | 2020-08-26 02:00:50 -0500 | [diff] [blame] | 1243 | baseFruInventoryPath = js["frus"][file][0]["inventoryPath"]; |
Santosh Puranik | 8589375 | 2020-11-10 21:31:43 +0530 | [diff] [blame] | 1244 | // 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] | 1245 | // We skip reading VPD when the power is ON in two scenarios: |
| 1246 | // 1) The eeprom we are trying to read is that of the system VPD |
| 1247 | // 2) The JSON tells us that the FRU EEPROM cannot be read when |
| 1248 | // we are powered ON. |
| 1249 | if (js["frus"][file].at(0).value("powerOffOnly", false) || |
| 1250 | (file == systemVpdFilePath)) |
Santosh Puranik | 8589375 | 2020-11-10 21:31:43 +0530 | [diff] [blame] | 1251 | { |
| 1252 | if ("xyz.openbmc_project.State.Chassis.PowerState.On" == |
| 1253 | getPowerState()) |
| 1254 | { |
| 1255 | cout << "This VPD cannot be read when power is ON" << endl; |
| 1256 | return 0; |
| 1257 | } |
| 1258 | } |
SunnySrivastava1984 | a20be8e | 2020-08-26 02:00:50 -0500 | [diff] [blame] | 1259 | |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 1260 | try |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1261 | { |
PriyangaRamasamy | c2fe40f | 2021-03-02 06:27:33 -0600 | [diff] [blame] | 1262 | vpdVector = getVpdDataInVector(js, file); |
PriyangaRamasamy | 33c61c2 | 2021-04-06 11:15:57 -0500 | [diff] [blame] | 1263 | ParserInterface* parser = ParserFactory::getParser(vpdVector); |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 1264 | variant<KeywordVpdMap, Store> parseResult; |
| 1265 | parseResult = parser->parse(); |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 1266 | |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 1267 | if (auto pVal = get_if<Store>(&parseResult)) |
| 1268 | { |
| 1269 | populateDbus(pVal->getVpdMap(), js, file); |
| 1270 | } |
| 1271 | else if (auto pVal = get_if<KeywordVpdMap>(&parseResult)) |
| 1272 | { |
| 1273 | populateDbus(*pVal, js, file); |
| 1274 | } |
| 1275 | |
| 1276 | // release the parser object |
| 1277 | ParserFactory::freeParser(parser); |
| 1278 | } |
Patrick Williams | 8e15b93 | 2021-10-06 13:04:22 -0500 | [diff] [blame] | 1279 | catch (const exception& e) |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 1280 | { |
| 1281 | postFailAction(js, file); |
PriyangaRamasamy | a504c3e | 2020-12-06 12:14:52 -0600 | [diff] [blame] | 1282 | throw; |
Alpana Kumari | 2f79304 | 2020-08-18 05:51:03 -0500 | [diff] [blame] | 1283 | } |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1284 | } |
SunnySrivastava1984 | a20be8e | 2020-08-26 02:00:50 -0500 | [diff] [blame] | 1285 | catch (const VpdJsonException& ex) |
| 1286 | { |
| 1287 | additionalData.emplace("JSON_PATH", ex.getJsonPath()); |
| 1288 | additionalData.emplace("DESCRIPTION", ex.what()); |
Sunny Srivastava | 0746eee | 2021-03-22 13:36:54 -0500 | [diff] [blame] | 1289 | createPEL(additionalData, pelSeverity, errIntfForJsonFailure); |
SunnySrivastava1984 | a20be8e | 2020-08-26 02:00:50 -0500 | [diff] [blame] | 1290 | |
| 1291 | cerr << ex.what() << "\n"; |
| 1292 | rc = -1; |
| 1293 | } |
| 1294 | catch (const VpdEccException& ex) |
| 1295 | { |
| 1296 | additionalData.emplace("DESCRIPTION", "ECC check failed"); |
| 1297 | additionalData.emplace("CALLOUT_INVENTORY_PATH", |
| 1298 | INVENTORY_PATH + baseFruInventoryPath); |
Sunny Srivastava | 0746eee | 2021-03-22 13:36:54 -0500 | [diff] [blame] | 1299 | createPEL(additionalData, pelSeverity, errIntfForEccCheckFail); |
PriyangaRamasamy | c2fe40f | 2021-03-02 06:27:33 -0600 | [diff] [blame] | 1300 | dumpBadVpd(file, vpdVector); |
SunnySrivastava1984 | a20be8e | 2020-08-26 02:00:50 -0500 | [diff] [blame] | 1301 | cerr << ex.what() << "\n"; |
| 1302 | rc = -1; |
| 1303 | } |
| 1304 | catch (const VpdDataException& ex) |
| 1305 | { |
| 1306 | additionalData.emplace("DESCRIPTION", "Invalid VPD data"); |
| 1307 | additionalData.emplace("CALLOUT_INVENTORY_PATH", |
| 1308 | INVENTORY_PATH + baseFruInventoryPath); |
Sunny Srivastava | 0746eee | 2021-03-22 13:36:54 -0500 | [diff] [blame] | 1309 | createPEL(additionalData, pelSeverity, errIntfForInvalidVPD); |
PriyangaRamasamy | c2fe40f | 2021-03-02 06:27:33 -0600 | [diff] [blame] | 1310 | dumpBadVpd(file, vpdVector); |
SunnySrivastava1984 | a20be8e | 2020-08-26 02:00:50 -0500 | [diff] [blame] | 1311 | cerr << ex.what() << "\n"; |
| 1312 | rc = -1; |
| 1313 | } |
Patrick Williams | 8e15b93 | 2021-10-06 13:04:22 -0500 | [diff] [blame] | 1314 | catch (const exception& e) |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1315 | { |
PriyangaRamasamy | c2fe40f | 2021-03-02 06:27:33 -0600 | [diff] [blame] | 1316 | dumpBadVpd(file, vpdVector); |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1317 | cerr << e.what() << "\n"; |
| 1318 | rc = -1; |
| 1319 | } |
| 1320 | |
| 1321 | return rc; |
Andrew Geissler | add68dc | 2021-10-08 16:07:52 -0500 | [diff] [blame] | 1322 | } |