SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
| 3 | #include "manager.hpp" |
| 4 | |
Santosh Puranik | bf78ed8 | 2022-04-20 13:17:04 +0530 | [diff] [blame] | 5 | #include "common_utility.hpp" |
SunnySrivastava1984 | d076da8 | 2020-03-05 05:33:35 -0600 | [diff] [blame] | 6 | #include "editor_impl.hpp" |
Sunny Srivastava | 6c71c9d | 2021-04-15 04:43:54 -0500 | [diff] [blame] | 7 | #include "ibm_vpd_utils.hpp" |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 8 | #include "ipz_parser.hpp" |
Santosh Puranik | 6b2b537 | 2022-06-02 20:49:02 +0530 | [diff] [blame] | 9 | #include "parser_factory.hpp" |
SunnySrivastava1984 | bca5aaa | 2020-04-21 05:31:04 -0500 | [diff] [blame] | 10 | #include "reader_impl.hpp" |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 11 | #include "vpd_exceptions.hpp" |
| 12 | |
| 13 | #include <phosphor-logging/elog-errors.hpp> |
Sunny Srivastava | 28abd6e | 2021-07-28 02:58:28 -0500 | [diff] [blame] | 14 | #include <xyz/openbmc_project/Common/error.hpp> |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 15 | |
Patrick Williams | c78d887 | 2023-05-10 07:50:56 -0500 | [diff] [blame] | 16 | #include <filesystem> |
| 17 | |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 18 | using namespace openpower::vpd::constants; |
SunnySrivastava1984 | 1356d7e | 2020-04-24 04:29:35 -0500 | [diff] [blame] | 19 | using namespace openpower::vpd::inventory; |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 20 | using namespace openpower::vpd::manager::editor; |
SunnySrivastava1984 | bca5aaa | 2020-04-21 05:31:04 -0500 | [diff] [blame] | 21 | using namespace openpower::vpd::manager::reader; |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 22 | using namespace std; |
| 23 | using namespace openpower::vpd::parser; |
Santosh Puranik | 6b2b537 | 2022-06-02 20:49:02 +0530 | [diff] [blame] | 24 | using namespace openpower::vpd::parser::factory; |
| 25 | using namespace openpower::vpd::ipz::parser; |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 26 | using namespace openpower::vpd::exceptions; |
| 27 | using namespace phosphor::logging; |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 28 | |
| 29 | namespace openpower |
| 30 | { |
| 31 | namespace vpd |
| 32 | { |
| 33 | namespace manager |
| 34 | { |
Sunny Srivastava | c6e7ea9 | 2023-11-03 21:10:43 +0530 | [diff] [blame] | 35 | |
Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 36 | Manager::Manager(std::shared_ptr<boost::asio::io_context>& ioCon, |
| 37 | std::shared_ptr<sdbusplus::asio::dbus_interface>& iFace, |
| 38 | std::shared_ptr<sdbusplus::asio::connection>& conn) : |
| 39 | ioContext(ioCon), |
| 40 | interface(iFace), conn(conn) |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 41 | { |
Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 42 | interface->register_method( |
| 43 | "WriteKeyword", |
| 44 | [this](const sdbusplus::message::object_path& path, |
| 45 | const std::string& recordName, const std::string& keyword, |
| 46 | const Binary& value) { |
Patrick Williams | c78d887 | 2023-05-10 07:50:56 -0500 | [diff] [blame] | 47 | this->writeKeyword(path, recordName, keyword, value); |
Patrick Williams | b7b352a | 2023-10-20 11:19:19 -0500 | [diff] [blame] | 48 | }); |
Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 49 | |
| 50 | interface->register_method( |
| 51 | "GetFRUsByUnexpandedLocationCode", |
| 52 | [this](const std::string& locationCode, |
| 53 | const uint16_t nodeNumber) -> inventory::ListOfPaths { |
Patrick Williams | b7b352a | 2023-10-20 11:19:19 -0500 | [diff] [blame] | 54 | return this->getFRUsByUnexpandedLocationCode(locationCode, nodeNumber); |
| 55 | }); |
Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 56 | |
| 57 | interface->register_method( |
| 58 | "GetFRUsByExpandedLocationCode", |
| 59 | [this](const std::string& locationCode) -> inventory::ListOfPaths { |
Patrick Williams | b7b352a | 2023-10-20 11:19:19 -0500 | [diff] [blame] | 60 | return this->getFRUsByExpandedLocationCode(locationCode); |
| 61 | }); |
Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 62 | |
| 63 | interface->register_method( |
| 64 | "GetExpandedLocationCode", |
| 65 | [this](const std::string& locationCode, |
| 66 | const uint16_t nodeNumber) -> std::string { |
Patrick Williams | b7b352a | 2023-10-20 11:19:19 -0500 | [diff] [blame] | 67 | return this->getExpandedLocationCode(locationCode, nodeNumber); |
| 68 | }); |
Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 69 | |
| 70 | interface->register_method("PerformVPDRecollection", |
| 71 | [this]() { this->performVPDRecollection(); }); |
| 72 | |
Sunny Srivastava | 28abd6e | 2021-07-28 02:58:28 -0500 | [diff] [blame] | 73 | interface->register_method( |
| 74 | "deleteFRUVPD", [this](const sdbusplus::message::object_path& path) { |
Patrick Williams | b7b352a | 2023-10-20 11:19:19 -0500 | [diff] [blame] | 75 | this->deleteFRUVPD(path); |
| 76 | }); |
Sunny Srivastava | 28abd6e | 2021-07-28 02:58:28 -0500 | [diff] [blame] | 77 | |
Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 78 | interface->register_method( |
| 79 | "CollectFRUVPD", [this](const sdbusplus::message::object_path& path) { |
Patrick Williams | b7b352a | 2023-10-20 11:19:19 -0500 | [diff] [blame] | 80 | this->collectFRUVPD(path); |
| 81 | }); |
Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 82 | |
Sunny Srivastava | fdf9ff2 | 2022-06-15 11:15:54 -0500 | [diff] [blame] | 83 | sd_bus_default(&sdBus); |
Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 84 | initManager(); |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 85 | } |
| 86 | |
Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 87 | void Manager::initManager() |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 88 | { |
SunnySrivastava1984 | de3c60d | 2020-02-03 10:34:33 -0600 | [diff] [blame] | 89 | try |
| 90 | { |
| 91 | processJSON(); |
Santosh Puranik | 6b2b537 | 2022-06-02 20:49:02 +0530 | [diff] [blame] | 92 | restoreSystemVpd(); |
Sunny Srivastava | ecb5c7d | 2021-09-02 07:20:24 -0500 | [diff] [blame] | 93 | listenHostState(); |
Santosh Puranik | b62f605 | 2022-04-06 18:37:54 +0530 | [diff] [blame] | 94 | listenAssetTag(); |
Alpana Kumari | b17dd3b | 2020-10-01 00:18:10 -0500 | [diff] [blame] | 95 | |
Santosh Puranik | f2d3b53 | 2022-04-19 06:44:07 -0500 | [diff] [blame] | 96 | // Create an instance of the BIOS handler |
Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 97 | biosHandler = std::make_shared<BiosHandler>(conn, *this); |
Santosh Puranik | f2d3b53 | 2022-04-19 06:44:07 -0500 | [diff] [blame] | 98 | |
Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 99 | // instantiate gpioMonitor class |
| 100 | gpioMon = std::make_shared<GpioMonitor>(jsonFile, ioContext); |
SunnySrivastava1984 | de3c60d | 2020-02-03 10:34:33 -0600 | [diff] [blame] | 101 | } |
| 102 | catch (const std::exception& e) |
| 103 | { |
| 104 | std::cerr << e.what() << "\n"; |
| 105 | } |
SunnySrivastava1984 | de3c60d | 2020-02-03 10:34:33 -0600 | [diff] [blame] | 106 | } |
| 107 | |
Santosh Puranik | 6b2b537 | 2022-06-02 20:49:02 +0530 | [diff] [blame] | 108 | /** |
| 109 | * @brief An api to get list of blank system VPD properties. |
| 110 | * @param[in] vpdMap - IPZ vpd map. |
| 111 | * @param[in] objectPath - Object path for the FRU. |
| 112 | * @param[out] blankPropertyList - Properties which are blank in System VPD and |
| 113 | * needs to be updated as standby. |
| 114 | */ |
| 115 | static void |
| 116 | getListOfBlankSystemVpd(Parsed& vpdMap, const string& objectPath, |
| 117 | std::vector<RestoredEeproms>& blankPropertyList) |
| 118 | { |
| 119 | for (const auto& systemRecKwdPair : svpdKwdMap) |
| 120 | { |
| 121 | auto it = vpdMap.find(systemRecKwdPair.first); |
| 122 | |
| 123 | // check if record is found in map we got by parser |
| 124 | if (it != vpdMap.end()) |
| 125 | { |
| 126 | const auto& kwdListForRecord = systemRecKwdPair.second; |
Priyanga Ramasamy | 952d6c5 | 2022-11-07 07:20:24 -0600 | [diff] [blame] | 127 | for (const auto& keywordInfo : kwdListForRecord) |
Santosh Puranik | 6b2b537 | 2022-06-02 20:49:02 +0530 | [diff] [blame] | 128 | { |
Priyanga Ramasamy | 952d6c5 | 2022-11-07 07:20:24 -0600 | [diff] [blame] | 129 | const auto& keyword = get<0>(keywordInfo); |
| 130 | |
Santosh Puranik | 6b2b537 | 2022-06-02 20:49:02 +0530 | [diff] [blame] | 131 | DbusPropertyMap& kwdValMap = it->second; |
| 132 | auto iterator = kwdValMap.find(keyword); |
| 133 | |
| 134 | if (iterator != kwdValMap.end()) |
| 135 | { |
| 136 | string& kwdValue = iterator->second; |
| 137 | |
| 138 | // check bus data |
| 139 | const string& recordName = systemRecKwdPair.first; |
| 140 | const string& busValue = readBusProperty( |
| 141 | objectPath, ipzVpdInf + recordName, keyword); |
| 142 | |
Priyanga Ramasamy | 834c078 | 2023-02-14 12:22:39 -0600 | [diff] [blame] | 143 | const auto& defaultValue = get<1>(keywordInfo); |
| 144 | |
| 145 | if (Binary(busValue.begin(), busValue.end()) != |
| 146 | defaultValue) |
Santosh Puranik | 6b2b537 | 2022-06-02 20:49:02 +0530 | [diff] [blame] | 147 | { |
Priyanga Ramasamy | 834c078 | 2023-02-14 12:22:39 -0600 | [diff] [blame] | 148 | if (Binary(kwdValue.begin(), kwdValue.end()) == |
| 149 | defaultValue) |
Santosh Puranik | 6b2b537 | 2022-06-02 20:49:02 +0530 | [diff] [blame] | 150 | { |
| 151 | // implies data is blank on EEPROM but not on cache. |
| 152 | // So EEPROM vpd update is required. |
| 153 | Binary busData(busValue.begin(), busValue.end()); |
| 154 | |
| 155 | blankPropertyList.push_back(std::make_tuple( |
| 156 | objectPath, recordName, keyword, busData)); |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | void Manager::restoreSystemVpd() |
| 166 | { |
| 167 | std::cout << "Attempting system VPD restore" << std::endl; |
| 168 | ParserInterface* parser = nullptr; |
| 169 | try |
| 170 | { |
| 171 | auto vpdVector = getVpdDataInVector(jsonFile, systemVpdFilePath); |
girik | 18bb985 | 2022-11-16 05:48:13 -0600 | [diff] [blame] | 172 | uint32_t vpdStartOffset = 0; |
Sunny Srivastava | f31a91b | 2022-06-09 08:11:29 -0500 | [diff] [blame] | 173 | const auto& inventoryPath = |
| 174 | jsonFile["frus"][systemVpdFilePath][0]["inventoryPath"] |
| 175 | .get_ref<const nlohmann::json::string_t&>(); |
| 176 | |
girik | 18bb985 | 2022-11-16 05:48:13 -0600 | [diff] [blame] | 177 | parser = ParserFactory::getParser(vpdVector, (pimPath + inventoryPath), |
| 178 | systemVpdFilePath, vpdStartOffset); |
Santosh Puranik | 6b2b537 | 2022-06-02 20:49:02 +0530 | [diff] [blame] | 179 | auto parseResult = parser->parse(); |
| 180 | |
| 181 | if (auto pVal = std::get_if<Store>(&parseResult)) |
| 182 | { |
| 183 | // map to hold all the keywords whose value is blank and |
| 184 | // needs to be updated at standby. |
| 185 | std::vector<RestoredEeproms> blankSystemVpdProperties{}; |
| 186 | getListOfBlankSystemVpd(pVal->getVpdMap(), SYSTEM_OBJECT, |
| 187 | blankSystemVpdProperties); |
| 188 | |
| 189 | // if system VPD restore is required, update the |
| 190 | // EEPROM |
| 191 | for (const auto& item : blankSystemVpdProperties) |
| 192 | { |
| 193 | std::cout << "Restoring keyword: " << std::get<2>(item) |
| 194 | << std::endl; |
| 195 | writeKeyword(std::get<0>(item), std::get<1>(item), |
| 196 | std::get<2>(item), std::get<3>(item)); |
| 197 | } |
| 198 | } |
| 199 | else |
| 200 | { |
| 201 | std::cerr << "Not a valid format to restore system VPD" |
| 202 | << std::endl; |
| 203 | } |
| 204 | } |
| 205 | catch (const std::exception& e) |
| 206 | { |
| 207 | std::cerr << "Failed to restore system VPD due to exception: " |
| 208 | << e.what() << std::endl; |
| 209 | } |
| 210 | // release the parser object |
| 211 | ParserFactory::freeParser(parser); |
| 212 | } |
| 213 | |
Sunny Srivastava | ecb5c7d | 2021-09-02 07:20:24 -0500 | [diff] [blame] | 214 | void Manager::listenHostState() |
| 215 | { |
Patrick Williams | 2eb0176 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 216 | static std::shared_ptr<sdbusplus::bus::match_t> hostState = |
| 217 | std::make_shared<sdbusplus::bus::match_t>( |
Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 218 | *conn, |
Sunny Srivastava | ecb5c7d | 2021-09-02 07:20:24 -0500 | [diff] [blame] | 219 | sdbusplus::bus::match::rules::propertiesChanged( |
| 220 | "/xyz/openbmc_project/state/host0", |
| 221 | "xyz.openbmc_project.State.Host"), |
Patrick Williams | 2eb0176 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 222 | [this](sdbusplus::message_t& msg) { hostStateCallBack(msg); }); |
Sunny Srivastava | ecb5c7d | 2021-09-02 07:20:24 -0500 | [diff] [blame] | 223 | } |
| 224 | |
Sunny Srivastava | fdf9ff2 | 2022-06-15 11:15:54 -0500 | [diff] [blame] | 225 | void Manager::checkEssentialFrus() |
| 226 | { |
| 227 | for (const auto& invPath : essentialFrus) |
| 228 | { |
| 229 | const auto res = readBusProperty(invPath, invItemIntf, "Present"); |
| 230 | |
| 231 | // implies the essential FRU is missing. Log PEL. |
| 232 | if (res == "false") |
| 233 | { |
| 234 | auto rc = sd_bus_call_method_async( |
| 235 | sdBus, NULL, loggerService, loggerObjectPath, |
| 236 | loggerCreateInterface, "Create", NULL, NULL, "ssa{ss}", |
| 237 | errIntfForEssentialFru, |
| 238 | "xyz.openbmc_project.Logging.Entry.Level.Warning", 2, |
| 239 | "DESCRIPTION", "Essential fru missing from the system.", |
| 240 | "CALLOUT_INVENTORY_PATH", (pimPath + invPath).c_str()); |
| 241 | |
| 242 | if (rc < 0) |
| 243 | { |
| 244 | log<level::ERR>("Error calling sd_bus_call_method_async", |
| 245 | entry("RC=%d", rc), |
| 246 | entry("MSG=%s", strerror(-rc))); |
| 247 | } |
| 248 | } |
| 249 | } |
| 250 | } |
| 251 | |
Patrick Williams | 7a975f0 | 2022-12-07 03:19:53 -0600 | [diff] [blame] | 252 | void Manager::hostStateCallBack(sdbusplus::message_t& msg) |
Sunny Srivastava | ecb5c7d | 2021-09-02 07:20:24 -0500 | [diff] [blame] | 253 | { |
| 254 | if (msg.is_method_error()) |
| 255 | { |
| 256 | std::cerr << "Error in reading signal " << std::endl; |
| 257 | } |
| 258 | |
| 259 | Path object; |
| 260 | PropertyMap propMap; |
| 261 | msg.read(object, propMap); |
| 262 | const auto itr = propMap.find("CurrentHostState"); |
| 263 | if (itr != propMap.end()) |
| 264 | { |
| 265 | if (auto hostState = std::get_if<std::string>(&(itr->second))) |
| 266 | { |
| 267 | // implies system is moving from standby to power on state |
| 268 | if (*hostState == "xyz.openbmc_project.State.Host.HostState." |
| 269 | "TransitioningToRunning") |
| 270 | { |
Sunny Srivastava | fdf9ff2 | 2022-06-15 11:15:54 -0500 | [diff] [blame] | 271 | // detect if essential frus are present in the system. |
| 272 | checkEssentialFrus(); |
| 273 | |
Sunny Srivastava | ecb5c7d | 2021-09-02 07:20:24 -0500 | [diff] [blame] | 274 | // check and perfrom recollection for FRUs replaceable at |
| 275 | // standby. |
| 276 | performVPDRecollection(); |
| 277 | return; |
| 278 | } |
| 279 | } |
Sunny Srivastava | ecb5c7d | 2021-09-02 07:20:24 -0500 | [diff] [blame] | 280 | } |
| 281 | } |
| 282 | |
Santosh Puranik | b62f605 | 2022-04-06 18:37:54 +0530 | [diff] [blame] | 283 | void Manager::listenAssetTag() |
| 284 | { |
Patrick Williams | 2eb0176 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 285 | static std::shared_ptr<sdbusplus::bus::match_t> assetMatcher = |
| 286 | std::make_shared<sdbusplus::bus::match_t>( |
Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 287 | *conn, |
Santosh Puranik | b62f605 | 2022-04-06 18:37:54 +0530 | [diff] [blame] | 288 | sdbusplus::bus::match::rules::propertiesChanged( |
| 289 | "/xyz/openbmc_project/inventory/system", |
| 290 | "xyz.openbmc_project.Inventory.Decorator.AssetTag"), |
Patrick Williams | 2eb0176 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 291 | [this](sdbusplus::message_t& msg) { assetTagCallback(msg); }); |
Santosh Puranik | b62f605 | 2022-04-06 18:37:54 +0530 | [diff] [blame] | 292 | } |
| 293 | |
Patrick Williams | 2eb0176 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 294 | void Manager::assetTagCallback(sdbusplus::message_t& msg) |
Santosh Puranik | b62f605 | 2022-04-06 18:37:54 +0530 | [diff] [blame] | 295 | { |
| 296 | if (msg.is_method_error()) |
| 297 | { |
| 298 | std::cerr << "Error in reading signal " << std::endl; |
| 299 | } |
| 300 | |
| 301 | Path object; |
| 302 | PropertyMap propMap; |
| 303 | msg.read(object, propMap); |
| 304 | const auto itr = propMap.find("AssetTag"); |
| 305 | if (itr != propMap.end()) |
| 306 | { |
| 307 | if (auto assetTag = std::get_if<std::string>(&(itr->second))) |
| 308 | { |
| 309 | // Call Notify to persist the AssetTag |
| 310 | inventory::ObjectMap objectMap = { |
| 311 | {std::string{"/system"}, |
| 312 | {{"xyz.openbmc_project.Inventory.Decorator.AssetTag", |
| 313 | {{"AssetTag", *assetTag}}}}}}; |
| 314 | |
| 315 | common::utility::callPIM(std::move(objectMap)); |
| 316 | } |
| 317 | else |
| 318 | { |
| 319 | std::cerr << "Failed to read asset tag" << std::endl; |
| 320 | } |
| 321 | } |
| 322 | } |
| 323 | |
SunnySrivastava1984 | de3c60d | 2020-02-03 10:34:33 -0600 | [diff] [blame] | 324 | void Manager::processJSON() |
| 325 | { |
Santosh Puranik | 0246a4d | 2020-11-04 16:57:39 +0530 | [diff] [blame] | 326 | std::ifstream json(INVENTORY_JSON_SYM_LINK, std::ios::binary); |
SunnySrivastava1984 | de3c60d | 2020-02-03 10:34:33 -0600 | [diff] [blame] | 327 | |
| 328 | if (!json) |
| 329 | { |
| 330 | throw std::runtime_error("json file not found"); |
| 331 | } |
| 332 | |
| 333 | jsonFile = nlohmann::json::parse(json); |
| 334 | if (jsonFile.find("frus") == jsonFile.end()) |
| 335 | { |
| 336 | throw std::runtime_error("frus group not found in json"); |
| 337 | } |
| 338 | |
| 339 | const nlohmann::json& groupFRUS = |
| 340 | jsonFile["frus"].get_ref<const nlohmann::json::object_t&>(); |
| 341 | for (const auto& itemFRUS : groupFRUS.items()) |
| 342 | { |
| 343 | const std::vector<nlohmann::json>& groupEEPROM = |
| 344 | itemFRUS.value().get_ref<const nlohmann::json::array_t&>(); |
| 345 | for (const auto& itemEEPROM : groupEEPROM) |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 346 | { |
SunnySrivastava1984 | 4330654 | 2020-04-01 02:50:20 -0500 | [diff] [blame] | 347 | bool isMotherboard = false; |
Santosh Puranik | a0b2391 | 2022-02-10 13:37:09 +0530 | [diff] [blame] | 348 | std::string redundantPath; |
| 349 | |
SunnySrivastava1984 | 4330654 | 2020-04-01 02:50:20 -0500 | [diff] [blame] | 350 | if (itemEEPROM["extraInterfaces"].find( |
| 351 | "xyz.openbmc_project.Inventory.Item.Board.Motherboard") != |
| 352 | itemEEPROM["extraInterfaces"].end()) |
| 353 | { |
| 354 | isMotherboard = true; |
| 355 | } |
Santosh Puranik | a0b2391 | 2022-02-10 13:37:09 +0530 | [diff] [blame] | 356 | if (itemEEPROM.find("redundantEeprom") != itemEEPROM.end()) |
| 357 | { |
| 358 | redundantPath = itemEEPROM["redundantEeprom"] |
| 359 | .get_ref<const nlohmann::json::string_t&>(); |
| 360 | } |
| 361 | frus.emplace( |
| 362 | itemEEPROM["inventoryPath"] |
| 363 | .get_ref<const nlohmann::json::string_t&>(), |
| 364 | std::make_tuple(itemFRUS.key(), redundantPath, isMotherboard)); |
SunnySrivastava1984 | bca5aaa | 2020-04-21 05:31:04 -0500 | [diff] [blame] | 365 | |
Alpana Kumari | 414d5ae | 2021-03-04 21:06:35 +0000 | [diff] [blame] | 366 | if (itemEEPROM["extraInterfaces"].find(IBM_LOCATION_CODE_INF) != |
Alpana Kumari | 920408d | 2020-05-14 00:07:03 -0500 | [diff] [blame] | 367 | itemEEPROM["extraInterfaces"].end()) |
| 368 | { |
| 369 | fruLocationCode.emplace( |
Alpana Kumari | 414d5ae | 2021-03-04 21:06:35 +0000 | [diff] [blame] | 370 | itemEEPROM["extraInterfaces"][IBM_LOCATION_CODE_INF] |
Alpana Kumari | 920408d | 2020-05-14 00:07:03 -0500 | [diff] [blame] | 371 | ["LocationCode"] |
| 372 | .get_ref<const nlohmann::json::string_t&>(), |
| 373 | itemEEPROM["inventoryPath"] |
| 374 | .get_ref<const nlohmann::json::string_t&>()); |
| 375 | } |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 376 | |
Sunny Srivastava | ecb5c7d | 2021-09-02 07:20:24 -0500 | [diff] [blame] | 377 | if (itemEEPROM.value("replaceableAtStandby", false)) |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 378 | { |
| 379 | replaceableFrus.emplace_back(itemFRUS.key()); |
| 380 | } |
Sunny Srivastava | fdf9ff2 | 2022-06-15 11:15:54 -0500 | [diff] [blame] | 381 | |
| 382 | if (itemEEPROM.value("essentialFru", false)) |
| 383 | { |
| 384 | essentialFrus.emplace_back(itemEEPROM["inventoryPath"]); |
| 385 | } |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 386 | } |
| 387 | } |
| 388 | } |
| 389 | |
Sunny Srivastava | 8377086 | 2023-10-31 12:57:20 -0500 | [diff] [blame] | 390 | void Manager::updateSystemVPDBackUpFRU(const std::string& recordName, |
| 391 | const std::string& keyword, |
| 392 | const Binary& value) |
| 393 | { |
| 394 | const std::string& systemVpdBackupPath = |
| 395 | jsonFile["frus"][systemVpdFilePath].at(0).value("systemVpdBackupPath", |
| 396 | ""); |
| 397 | |
| 398 | if (!systemVpdBackupPath.empty() && |
| 399 | jsonFile["frus"][systemVpdBackupPath].at(0).contains("inventoryPath")) |
| 400 | { |
| 401 | std::string systemVpdBackupInvPath = |
| 402 | jsonFile["frus"][systemVpdBackupPath][0]["inventoryPath"] |
| 403 | .get_ref<const nlohmann::json::string_t&>(); |
| 404 | |
| 405 | const auto& itr = svpdKwdMap.find(recordName); |
| 406 | if (itr != svpdKwdMap.end()) |
| 407 | { |
| 408 | auto systemKwdInfoList = itr->second; |
| 409 | const auto& itrToKwd = find_if(systemKwdInfoList.begin(), |
| 410 | systemKwdInfoList.end(), |
| 411 | [&keyword](const auto& kwdInfo) { |
| 412 | return (keyword == std::get<0>(kwdInfo)); |
| 413 | }); |
| 414 | |
| 415 | if (itrToKwd != systemKwdInfoList.end()) |
| 416 | { |
| 417 | EditorImpl edit(systemVpdBackupPath, jsonFile, |
| 418 | std::get<4>(*itrToKwd), std::get<5>(*itrToKwd), |
| 419 | systemVpdBackupInvPath); |
| 420 | |
| 421 | // Setup offset, if any |
| 422 | uint32_t offset = 0; |
| 423 | if (jsonFile["frus"][systemVpdBackupPath].at(0).contains( |
| 424 | "offset")) |
| 425 | { |
| 426 | offset = |
| 427 | jsonFile["frus"][systemVpdBackupPath].at(0).contains( |
| 428 | "offset"); |
| 429 | } |
| 430 | |
| 431 | edit.updateKeyword(value, offset, true); |
| 432 | } |
| 433 | } |
| 434 | } |
| 435 | else |
| 436 | { |
| 437 | if (systemVpdBackupPath.empty()) |
| 438 | { |
| 439 | throw std::runtime_error( |
| 440 | "Invalid entry for systemVpdBackupPath in JSON"); |
| 441 | } |
| 442 | else |
| 443 | { |
| 444 | throw std::runtime_error( |
| 445 | "Inventory path missing for systemVpdBackupPath"); |
| 446 | } |
| 447 | } |
| 448 | } |
| 449 | |
Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 450 | void Manager::writeKeyword(const sdbusplus::message::object_path& path, |
| 451 | const std::string& recordName, |
| 452 | const std::string& keyword, const Binary& value) |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 453 | { |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 454 | try |
| 455 | { |
Santosh Puranik | 8c79681 | 2021-12-01 19:17:56 +0530 | [diff] [blame] | 456 | std::string objPath{path}; |
| 457 | // Strip any inventory prefix in path |
| 458 | if (objPath.find(INVENTORY_PATH) == 0) |
| 459 | { |
| 460 | objPath = objPath.substr(sizeof(INVENTORY_PATH) - 1); |
| 461 | } |
| 462 | |
| 463 | if (frus.find(objPath) == frus.end()) |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 464 | { |
| 465 | throw std::runtime_error("Inventory path not found"); |
| 466 | } |
| 467 | |
Santosh Puranik | a0b2391 | 2022-02-10 13:37:09 +0530 | [diff] [blame] | 468 | inventory::Path vpdFilePath = std::get<0>(frus.find(objPath)->second); |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 469 | |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 470 | // instantiate editor class to update the data |
Santosh Puranik | 8c79681 | 2021-12-01 19:17:56 +0530 | [diff] [blame] | 471 | EditorImpl edit(vpdFilePath, jsonFile, recordName, keyword, objPath); |
Santosh Puranik | a0b2391 | 2022-02-10 13:37:09 +0530 | [diff] [blame] | 472 | |
| 473 | uint32_t offset = 0; |
| 474 | // Setup offset, if any |
| 475 | for (const auto& item : jsonFile["frus"][vpdFilePath]) |
| 476 | { |
| 477 | if (item.find("offset") != item.end()) |
| 478 | { |
| 479 | offset = item["offset"]; |
| 480 | break; |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | edit.updateKeyword(value, offset, true); |
| 485 | |
Sunny Srivastava | 8377086 | 2023-10-31 12:57:20 -0500 | [diff] [blame] | 486 | // If system VPD is being updated and system VPD is marked for back up |
| 487 | // on another FRU, update data on back up as well. |
| 488 | if (objPath == sdbusplus::message::object_path{SYSTEM_OBJECT} && |
| 489 | jsonFile["frus"][systemVpdFilePath].at(0).contains( |
| 490 | "systemVpdBackupPath")) |
| 491 | { |
| 492 | updateSystemVPDBackUpFRU(recordName, keyword, value); |
| 493 | } |
| 494 | |
Santosh Puranik | a0b2391 | 2022-02-10 13:37:09 +0530 | [diff] [blame] | 495 | // If we have a redundant EEPROM to update, then update just the EEPROM, |
| 496 | // not the cache since that is already done when we updated the primary |
| 497 | if (!std::get<1>(frus.find(objPath)->second).empty()) |
| 498 | { |
| 499 | EditorImpl edit(std::get<1>(frus.find(objPath)->second), jsonFile, |
Sunny Srivastava | f31a91b | 2022-06-09 08:11:29 -0500 | [diff] [blame] | 500 | recordName, keyword, objPath); |
Santosh Puranik | a0b2391 | 2022-02-10 13:37:09 +0530 | [diff] [blame] | 501 | edit.updateKeyword(value, offset, false); |
| 502 | } |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 503 | |
SunnySrivastava1984 | 4330654 | 2020-04-01 02:50:20 -0500 | [diff] [blame] | 504 | // if it is a motehrboard FRU need to check for location expansion |
Santosh Puranik | a0b2391 | 2022-02-10 13:37:09 +0530 | [diff] [blame] | 505 | if (std::get<2>(frus.find(objPath)->second)) |
SunnySrivastava1984 | 4330654 | 2020-04-01 02:50:20 -0500 | [diff] [blame] | 506 | { |
| 507 | if (recordName == "VCEN" && (keyword == "FC" || keyword == "SE")) |
| 508 | { |
| 509 | edit.expandLocationCode("fcs"); |
| 510 | } |
| 511 | else if (recordName == "VSYS" && |
| 512 | (keyword == "TM" || keyword == "SE")) |
| 513 | { |
| 514 | edit.expandLocationCode("mts"); |
| 515 | } |
| 516 | } |
| 517 | |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 518 | return; |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 519 | } |
| 520 | catch (const std::exception& e) |
| 521 | { |
| 522 | std::cerr << e.what() << std::endl; |
| 523 | } |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 524 | } |
| 525 | |
SunnySrivastava1984 | 1356d7e | 2020-04-24 04:29:35 -0500 | [diff] [blame] | 526 | ListOfPaths |
Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 527 | Manager::getFRUsByUnexpandedLocationCode(const LocationCode& locationCode, |
SunnySrivastava1984 | fb5815a | 2020-04-24 08:03:52 -0500 | [diff] [blame] | 528 | const NodeNumber nodeNumber) |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 529 | { |
SunnySrivastava1984 | 1356d7e | 2020-04-24 04:29:35 -0500 | [diff] [blame] | 530 | ReaderImpl read; |
| 531 | return read.getFrusAtLocation(locationCode, nodeNumber, fruLocationCode); |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 532 | } |
| 533 | |
SunnySrivastava1984 | 1356d7e | 2020-04-24 04:29:35 -0500 | [diff] [blame] | 534 | ListOfPaths |
Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 535 | Manager::getFRUsByExpandedLocationCode(const LocationCode& locationCode) |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 536 | { |
SunnySrivastava1984 | fb5815a | 2020-04-24 08:03:52 -0500 | [diff] [blame] | 537 | ReaderImpl read; |
| 538 | return read.getFRUsByExpandedLocationCode(locationCode, fruLocationCode); |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 539 | } |
| 540 | |
Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 541 | LocationCode Manager::getExpandedLocationCode(const LocationCode& locationCode, |
SunnySrivastava1984 | fb5815a | 2020-04-24 08:03:52 -0500 | [diff] [blame] | 542 | const NodeNumber nodeNumber) |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 543 | { |
SunnySrivastava1984 | bca5aaa | 2020-04-21 05:31:04 -0500 | [diff] [blame] | 544 | ReaderImpl read; |
| 545 | return read.getExpandedLocationCode(locationCode, nodeNumber, |
| 546 | fruLocationCode); |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 547 | } |
SunnySrivastava1984 | de3c60d | 2020-02-03 10:34:33 -0600 | [diff] [blame] | 548 | |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 549 | void Manager::performVPDRecollection() |
| 550 | { |
| 551 | // get list of FRUs replaceable at standby |
| 552 | for (const auto& item : replaceableFrus) |
| 553 | { |
| 554 | const vector<nlohmann::json>& groupEEPROM = jsonFile["frus"][item]; |
| 555 | const nlohmann::json& singleFru = groupEEPROM[0]; |
| 556 | |
| 557 | const string& inventoryPath = |
| 558 | singleFru["inventoryPath"] |
| 559 | .get_ref<const nlohmann::json::string_t&>(); |
| 560 | |
Santosh Puranik | d40e42d | 2022-03-23 13:58:06 +0530 | [diff] [blame] | 561 | bool prePostActionRequired = false; |
| 562 | |
| 563 | if ((jsonFile["frus"][item].at(0)).find("preAction") != |
| 564 | jsonFile["frus"][item].at(0).end()) |
| 565 | { |
Sunny Srivastava | a2ddc96 | 2022-06-29 08:53:16 -0500 | [diff] [blame] | 566 | try |
Santosh Puranik | d40e42d | 2022-03-23 13:58:06 +0530 | [diff] [blame] | 567 | { |
Sunny Srivastava | a2ddc96 | 2022-06-29 08:53:16 -0500 | [diff] [blame] | 568 | if (!executePreAction(jsonFile, item)) |
| 569 | { |
| 570 | // if the FRU has preAction defined then its execution |
| 571 | // should pass to ensure bind/unbind of data. |
| 572 | // preAction execution failed. should not call |
| 573 | // bind/unbind. |
| 574 | log<level::ERR>( |
| 575 | "Pre-Action execution failed for the FRU", |
| 576 | entry("ERROR=%s", |
| 577 | ("Inventory path: " + inventoryPath).c_str())); |
| 578 | continue; |
| 579 | } |
| 580 | } |
| 581 | catch (const GpioException& e) |
| 582 | { |
| 583 | log<level::ERR>(e.what()); |
| 584 | PelAdditionalData additionalData{}; |
| 585 | additionalData.emplace("DESCRIPTION", e.what()); |
| 586 | createPEL(additionalData, PelSeverity::WARNING, |
| 587 | errIntfForGpioError, sdBus); |
Santosh Puranik | d40e42d | 2022-03-23 13:58:06 +0530 | [diff] [blame] | 588 | continue; |
| 589 | } |
| 590 | prePostActionRequired = true; |
| 591 | } |
| 592 | |
Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 593 | // unbind, bind the driver to trigger parser. |
| 594 | triggerVpdCollection(singleFru, inventoryPath); |
Santosh Puranik | d40e42d | 2022-03-23 13:58:06 +0530 | [diff] [blame] | 595 | |
| 596 | // this check is added to avoid file system expensive call in case not |
| 597 | // required. |
| 598 | if (prePostActionRequired) |
| 599 | { |
| 600 | // Check if device showed up (test for file) |
| 601 | if (!filesystem::exists(item)) |
| 602 | { |
Sunny Srivastava | a2ddc96 | 2022-06-29 08:53:16 -0500 | [diff] [blame] | 603 | try |
| 604 | { |
| 605 | // If not, then take failure postAction |
| 606 | executePostFailAction(jsonFile, item); |
| 607 | } |
| 608 | catch (const GpioException& e) |
| 609 | { |
| 610 | PelAdditionalData additionalData{}; |
| 611 | additionalData.emplace("DESCRIPTION", e.what()); |
| 612 | createPEL(additionalData, PelSeverity::WARNING, |
| 613 | errIntfForGpioError, sdBus); |
| 614 | } |
Santosh Puranik | d40e42d | 2022-03-23 13:58:06 +0530 | [diff] [blame] | 615 | } |
Alpana Kumari | 41d498c | 2021-09-16 00:29:12 -0500 | [diff] [blame] | 616 | else |
| 617 | { |
| 618 | // bind the LED driver |
| 619 | string chipAddr = singleFru.value("pcaChipAddress", ""); |
| 620 | cout << "performVPDRecollection: Executing driver binding for " |
| 621 | "chip " |
| 622 | "address - " |
| 623 | << chipAddr << endl; |
| 624 | |
| 625 | executeCmd(createBindUnbindDriverCmnd(chipAddr, "i2c", |
| 626 | "leds-pca955x", "/bind")); |
| 627 | } |
Santosh Puranik | d40e42d | 2022-03-23 13:58:06 +0530 | [diff] [blame] | 628 | } |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 629 | } |
| 630 | } |
| 631 | |
Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 632 | void Manager::collectFRUVPD(const sdbusplus::message::object_path& path) |
| 633 | { |
Sunny Srivastava | 5ef6ccc | 2022-05-30 01:35:13 -0500 | [diff] [blame] | 634 | std::cout << "Manager called to collect vpd for fru: " << std::string{path} |
| 635 | << std::endl; |
| 636 | |
Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 637 | using InvalidArgument = |
| 638 | sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument; |
| 639 | using Argument = xyz::openbmc_project::Common::InvalidArgument; |
| 640 | |
Santosh Puranik | bc59947 | 2022-12-19 20:17:10 +0530 | [diff] [blame] | 641 | std::string objPath{path}; |
| 642 | |
| 643 | // Strip any inventory prefix in path |
| 644 | if (objPath.find(INVENTORY_PATH) == 0) |
Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 645 | { |
Santosh Puranik | bc59947 | 2022-12-19 20:17:10 +0530 | [diff] [blame] | 646 | objPath = objPath.substr(sizeof(INVENTORY_PATH) - 1); |
Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 647 | } |
| 648 | |
Santosh Puranik | bc59947 | 2022-12-19 20:17:10 +0530 | [diff] [blame] | 649 | // if path not found in Json. |
| 650 | if (frus.find(objPath) == frus.end()) |
| 651 | { |
| 652 | elog<InvalidArgument>(Argument::ARGUMENT_NAME("Object Path"), |
| 653 | Argument::ARGUMENT_VALUE(objPath.c_str())); |
| 654 | } |
| 655 | |
| 656 | inventory::Path vpdFilePath = std::get<0>(frus.find(objPath)->second); |
Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 657 | |
| 658 | const std::vector<nlohmann::json>& groupEEPROM = |
| 659 | jsonFile["frus"][vpdFilePath].get_ref<const nlohmann::json::array_t&>(); |
| 660 | |
Sunny Srivastava | ab2304d | 2023-01-10 23:30:05 -0600 | [diff] [blame] | 661 | nlohmann::json singleFru{}; |
| 662 | for (const auto& item : groupEEPROM) |
| 663 | { |
| 664 | if (item["inventoryPath"] == objPath) |
| 665 | { |
| 666 | // this is the inventory we are looking for |
| 667 | singleFru = item; |
| 668 | break; |
| 669 | } |
| 670 | } |
Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 671 | |
| 672 | // check if the device qualifies for CM. |
| 673 | if (singleFru.value("concurrentlyMaintainable", false)) |
| 674 | { |
| 675 | bool prePostActionRequired = false; |
| 676 | |
| 677 | if ((jsonFile["frus"][vpdFilePath].at(0)).find("preAction") != |
| 678 | jsonFile["frus"][vpdFilePath].at(0).end()) |
| 679 | { |
| 680 | if (!executePreAction(jsonFile, vpdFilePath)) |
| 681 | { |
| 682 | // if the FRU has preAction defined then its execution should |
| 683 | // pass to ensure bind/unbind of data. |
| 684 | // preAction execution failed. should not call bind/unbind. |
| 685 | log<level::ERR>("Pre-Action execution failed for the FRU"); |
| 686 | return; |
| 687 | } |
| 688 | |
| 689 | prePostActionRequired = true; |
| 690 | } |
| 691 | |
| 692 | // unbind, bind the driver to trigger parser. |
Santosh Puranik | bc59947 | 2022-12-19 20:17:10 +0530 | [diff] [blame] | 693 | triggerVpdCollection(singleFru, objPath); |
Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 694 | |
| 695 | // this check is added to avoid file system expensive call in case not |
| 696 | // required. |
| 697 | if (prePostActionRequired) |
| 698 | { |
| 699 | // Check if device showed up (test for file) |
| 700 | if (!filesystem::exists(vpdFilePath)) |
| 701 | { |
Santosh Puranik | bc59947 | 2022-12-19 20:17:10 +0530 | [diff] [blame] | 702 | try |
| 703 | { |
| 704 | // If not, then take failure postAction |
| 705 | executePostFailAction(jsonFile, vpdFilePath); |
| 706 | } |
| 707 | catch (const GpioException& e) |
| 708 | { |
| 709 | PelAdditionalData additionalData{}; |
| 710 | additionalData.emplace("DESCRIPTION", e.what()); |
| 711 | createPEL(additionalData, PelSeverity::WARNING, |
| 712 | errIntfForGpioError, sdBus); |
| 713 | } |
Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 714 | } |
Alpana Kumari | 41d498c | 2021-09-16 00:29:12 -0500 | [diff] [blame] | 715 | else |
| 716 | { |
| 717 | // bind the LED driver |
| 718 | string chipAddr = jsonFile["frus"][vpdFilePath].at(0).value( |
| 719 | "pcaChipAddress", ""); |
| 720 | cout << "Executing driver binding for chip address - " |
| 721 | << chipAddr << endl; |
| 722 | |
| 723 | executeCmd(createBindUnbindDriverCmnd(chipAddr, "i2c", |
| 724 | "leds-pca955x", "/bind")); |
| 725 | } |
Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 726 | } |
| 727 | return; |
| 728 | } |
| 729 | else |
| 730 | { |
Santosh Puranik | bc59947 | 2022-12-19 20:17:10 +0530 | [diff] [blame] | 731 | elog<InvalidArgument>(Argument::ARGUMENT_NAME("Object Path"), |
| 732 | Argument::ARGUMENT_VALUE(objPath.c_str())); |
Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 733 | } |
| 734 | } |
| 735 | |
| 736 | void Manager::triggerVpdCollection(const nlohmann::json& singleFru, |
| 737 | const std::string& path) |
| 738 | { |
| 739 | if ((singleFru.find("devAddress") == singleFru.end()) || |
| 740 | (singleFru.find("driverType") == singleFru.end()) || |
| 741 | (singleFru.find("busType") == singleFru.end())) |
| 742 | { |
| 743 | // The FRUs is marked for collection but missing mandatory |
| 744 | // fields for collection. Log error and return. |
| 745 | log<level::ERR>( |
| 746 | "Collection Failed as mandatory field missing in Json", |
| 747 | entry("ERROR=%s", ("Recollection failed for " + (path)).c_str())); |
| 748 | |
| 749 | return; |
| 750 | } |
| 751 | |
| 752 | string deviceAddress = singleFru["devAddress"]; |
| 753 | const string& driverType = singleFru["driverType"]; |
| 754 | const string& busType = singleFru["busType"]; |
| 755 | |
| 756 | // devTreeStatus flag is present in json as false to mention |
| 757 | // that the EEPROM is not mentioned in device tree. If this flag |
| 758 | // is absent consider the value to be true, i.e EEPROM is |
| 759 | // mentioned in device tree |
| 760 | if (!singleFru.value("devTreeStatus", true)) |
| 761 | { |
| 762 | auto pos = deviceAddress.find('-'); |
| 763 | if (pos != string::npos) |
| 764 | { |
| 765 | string busNum = deviceAddress.substr(0, pos); |
| 766 | deviceAddress = "0x" + deviceAddress.substr(pos + 1, string::npos); |
| 767 | |
| 768 | string deleteDevice = "echo" + deviceAddress + " > /sys/bus/" + |
| 769 | busType + "/devices/" + busType + "-" + |
| 770 | busNum + "/delete_device"; |
| 771 | executeCmd(deleteDevice); |
| 772 | |
| 773 | string addDevice = "echo" + driverType + " " + deviceAddress + |
| 774 | " > /sys/bus/" + busType + "/devices/" + |
| 775 | busType + "-" + busNum + "/new_device"; |
| 776 | executeCmd(addDevice); |
| 777 | } |
| 778 | else |
| 779 | { |
| 780 | const string& inventoryPath = |
| 781 | singleFru["inventoryPath"] |
| 782 | .get_ref<const nlohmann::json::string_t&>(); |
| 783 | |
| 784 | log<level::ERR>( |
| 785 | "Wrong format of device address in Json", |
| 786 | entry("ERROR=%s", |
| 787 | ("Recollection failed for " + inventoryPath).c_str())); |
| 788 | } |
| 789 | } |
| 790 | else |
| 791 | { |
| 792 | executeCmd(createBindUnbindDriverCmnd(deviceAddress, busType, |
| 793 | driverType, "/unbind")); |
| 794 | executeCmd(createBindUnbindDriverCmnd(deviceAddress, busType, |
| 795 | driverType, "/bind")); |
| 796 | } |
| 797 | } |
| 798 | |
Sunny Srivastava | 28abd6e | 2021-07-28 02:58:28 -0500 | [diff] [blame] | 799 | void Manager::deleteFRUVPD(const sdbusplus::message::object_path& path) |
| 800 | { |
Sunny Srivastava | 5ef6ccc | 2022-05-30 01:35:13 -0500 | [diff] [blame] | 801 | std::cout << "Manager called to delete vpd for fru: " << std::string{path} |
| 802 | << std::endl; |
| 803 | |
Sunny Srivastava | 28abd6e | 2021-07-28 02:58:28 -0500 | [diff] [blame] | 804 | using InvalidArgument = |
| 805 | sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument; |
| 806 | using Argument = xyz::openbmc_project::Common::InvalidArgument; |
| 807 | |
Santosh Puranik | bc59947 | 2022-12-19 20:17:10 +0530 | [diff] [blame] | 808 | std::string objPath{path}; |
| 809 | |
| 810 | // Strip any inventory prefix in path |
| 811 | if (objPath.find(INVENTORY_PATH) == 0) |
Sunny Srivastava | 28abd6e | 2021-07-28 02:58:28 -0500 | [diff] [blame] | 812 | { |
Santosh Puranik | bc59947 | 2022-12-19 20:17:10 +0530 | [diff] [blame] | 813 | objPath = objPath.substr(sizeof(INVENTORY_PATH) - 1); |
Sunny Srivastava | 28abd6e | 2021-07-28 02:58:28 -0500 | [diff] [blame] | 814 | } |
| 815 | |
Santosh Puranik | bc59947 | 2022-12-19 20:17:10 +0530 | [diff] [blame] | 816 | // if path not found in Json. |
| 817 | if (frus.find(objPath) == frus.end()) |
| 818 | { |
| 819 | elog<InvalidArgument>(Argument::ARGUMENT_NAME("Object Path"), |
| 820 | Argument::ARGUMENT_VALUE(objPath.c_str())); |
| 821 | } |
| 822 | |
| 823 | inventory::Path& vpdFilePath = std::get<0>(frus.find(objPath)->second); |
Alpana Kumari | 41d498c | 2021-09-16 00:29:12 -0500 | [diff] [blame] | 824 | |
| 825 | string chipAddress = |
| 826 | jsonFile["frus"][vpdFilePath].at(0).value("pcaChipAddress", ""); |
| 827 | |
| 828 | // Unbind the LED driver for this FRU |
| 829 | cout << "Unbinding device- " << chipAddress << endl; |
| 830 | executeCmd(createBindUnbindDriverCmnd(chipAddress, "i2c", "leds-pca955x", |
| 831 | "/unbind")); |
| 832 | |
Sunny Srivastava | 28abd6e | 2021-07-28 02:58:28 -0500 | [diff] [blame] | 833 | // if the FRU is not present then log error |
Santosh Puranik | bc59947 | 2022-12-19 20:17:10 +0530 | [diff] [blame] | 834 | if (readBusProperty(objPath, "xyz.openbmc_project.Inventory.Item", |
Sunny Srivastava | 28abd6e | 2021-07-28 02:58:28 -0500 | [diff] [blame] | 835 | "Present") == "false") |
| 836 | { |
Santosh Puranik | bc59947 | 2022-12-19 20:17:10 +0530 | [diff] [blame] | 837 | elog<InvalidArgument>(Argument::ARGUMENT_NAME("FRU not preset"), |
| 838 | Argument::ARGUMENT_VALUE(objPath.c_str())); |
Sunny Srivastava | 28abd6e | 2021-07-28 02:58:28 -0500 | [diff] [blame] | 839 | } |
| 840 | else |
| 841 | { |
Sunny Srivastava | c6e7ea9 | 2023-11-03 21:10:43 +0530 | [diff] [blame] | 842 | inventory::InterfaceMap interfacesPropMap; |
| 843 | clearVpdOnRemoval(INVENTORY_PATH + objPath, interfacesPropMap); |
Santosh Puranik | bc59947 | 2022-12-19 20:17:10 +0530 | [diff] [blame] | 844 | |
| 845 | inventory::ObjectMap objectMap; |
Sunny Srivastava | c6e7ea9 | 2023-11-03 21:10:43 +0530 | [diff] [blame] | 846 | objectMap.emplace(objPath, move(interfacesPropMap)); |
Sunny Srivastava | 28abd6e | 2021-07-28 02:58:28 -0500 | [diff] [blame] | 847 | |
| 848 | common::utility::callPIM(move(objectMap)); |
| 849 | } |
| 850 | } |
| 851 | |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 852 | } // namespace manager |
| 853 | } // namespace vpd |
Patrick Williams | c78d887 | 2023-05-10 07:50:56 -0500 | [diff] [blame] | 854 | } // namespace openpower |