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