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