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 | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 35 | Manager::Manager(std::shared_ptr<boost::asio::io_context>& ioCon, |
| 36 | std::shared_ptr<sdbusplus::asio::dbus_interface>& iFace, |
| 37 | std::shared_ptr<sdbusplus::asio::connection>& conn) : |
| 38 | ioContext(ioCon), |
| 39 | interface(iFace), conn(conn) |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 40 | { |
Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 41 | interface->register_method( |
| 42 | "WriteKeyword", |
| 43 | [this](const sdbusplus::message::object_path& path, |
| 44 | const std::string& recordName, const std::string& keyword, |
| 45 | const Binary& value) { |
Patrick Williams | c78d887 | 2023-05-10 07:50:56 -0500 | [diff] [blame] | 46 | this->writeKeyword(path, recordName, keyword, value); |
Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 47 | }); |
| 48 | |
| 49 | interface->register_method( |
| 50 | "GetFRUsByUnexpandedLocationCode", |
| 51 | [this](const std::string& locationCode, |
| 52 | const uint16_t nodeNumber) -> inventory::ListOfPaths { |
| 53 | return this->getFRUsByUnexpandedLocationCode(locationCode, |
| 54 | nodeNumber); |
| 55 | }); |
| 56 | |
| 57 | interface->register_method( |
| 58 | "GetFRUsByExpandedLocationCode", |
| 59 | [this](const std::string& locationCode) -> inventory::ListOfPaths { |
| 60 | return this->getFRUsByExpandedLocationCode(locationCode); |
| 61 | }); |
| 62 | |
| 63 | interface->register_method( |
| 64 | "GetExpandedLocationCode", |
| 65 | [this](const std::string& locationCode, |
| 66 | const uint16_t nodeNumber) -> std::string { |
| 67 | return this->getExpandedLocationCode(locationCode, nodeNumber); |
| 68 | }); |
| 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) { |
| 75 | this->deleteFRUVPD(path); |
| 76 | }); |
| 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) { |
| 80 | this->collectFRUVPD(path); |
| 81 | }); |
| 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 | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 390 | void Manager::writeKeyword(const sdbusplus::message::object_path& path, |
| 391 | const std::string& recordName, |
| 392 | const std::string& keyword, const Binary& value) |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 393 | { |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 394 | try |
| 395 | { |
Santosh Puranik | 8c79681 | 2021-12-01 19:17:56 +0530 | [diff] [blame] | 396 | std::string objPath{path}; |
| 397 | // Strip any inventory prefix in path |
| 398 | if (objPath.find(INVENTORY_PATH) == 0) |
| 399 | { |
| 400 | objPath = objPath.substr(sizeof(INVENTORY_PATH) - 1); |
| 401 | } |
| 402 | |
| 403 | if (frus.find(objPath) == frus.end()) |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 404 | { |
| 405 | throw std::runtime_error("Inventory path not found"); |
| 406 | } |
| 407 | |
Santosh Puranik | a0b2391 | 2022-02-10 13:37:09 +0530 | [diff] [blame] | 408 | inventory::Path vpdFilePath = std::get<0>(frus.find(objPath)->second); |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 409 | |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 410 | // instantiate editor class to update the data |
Santosh Puranik | 8c79681 | 2021-12-01 19:17:56 +0530 | [diff] [blame] | 411 | EditorImpl edit(vpdFilePath, jsonFile, recordName, keyword, objPath); |
Santosh Puranik | a0b2391 | 2022-02-10 13:37:09 +0530 | [diff] [blame] | 412 | |
| 413 | uint32_t offset = 0; |
| 414 | // Setup offset, if any |
| 415 | for (const auto& item : jsonFile["frus"][vpdFilePath]) |
| 416 | { |
| 417 | if (item.find("offset") != item.end()) |
| 418 | { |
| 419 | offset = item["offset"]; |
| 420 | break; |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | edit.updateKeyword(value, offset, true); |
| 425 | |
| 426 | // If we have a redundant EEPROM to update, then update just the EEPROM, |
| 427 | // not the cache since that is already done when we updated the primary |
| 428 | if (!std::get<1>(frus.find(objPath)->second).empty()) |
| 429 | { |
| 430 | EditorImpl edit(std::get<1>(frus.find(objPath)->second), jsonFile, |
Sunny Srivastava | f31a91b | 2022-06-09 08:11:29 -0500 | [diff] [blame] | 431 | recordName, keyword, objPath); |
Santosh Puranik | a0b2391 | 2022-02-10 13:37:09 +0530 | [diff] [blame] | 432 | edit.updateKeyword(value, offset, false); |
| 433 | } |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 434 | |
SunnySrivastava1984 | 4330654 | 2020-04-01 02:50:20 -0500 | [diff] [blame] | 435 | // if it is a motehrboard FRU need to check for location expansion |
Santosh Puranik | a0b2391 | 2022-02-10 13:37:09 +0530 | [diff] [blame] | 436 | if (std::get<2>(frus.find(objPath)->second)) |
SunnySrivastava1984 | 4330654 | 2020-04-01 02:50:20 -0500 | [diff] [blame] | 437 | { |
| 438 | if (recordName == "VCEN" && (keyword == "FC" || keyword == "SE")) |
| 439 | { |
| 440 | edit.expandLocationCode("fcs"); |
| 441 | } |
| 442 | else if (recordName == "VSYS" && |
| 443 | (keyword == "TM" || keyword == "SE")) |
| 444 | { |
| 445 | edit.expandLocationCode("mts"); |
| 446 | } |
| 447 | } |
| 448 | |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 449 | return; |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 450 | } |
| 451 | catch (const std::exception& e) |
| 452 | { |
| 453 | std::cerr << e.what() << std::endl; |
| 454 | } |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 455 | } |
| 456 | |
SunnySrivastava1984 | 1356d7e | 2020-04-24 04:29:35 -0500 | [diff] [blame] | 457 | ListOfPaths |
Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 458 | Manager::getFRUsByUnexpandedLocationCode(const LocationCode& locationCode, |
SunnySrivastava1984 | fb5815a | 2020-04-24 08:03:52 -0500 | [diff] [blame] | 459 | const NodeNumber nodeNumber) |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 460 | { |
SunnySrivastava1984 | 1356d7e | 2020-04-24 04:29:35 -0500 | [diff] [blame] | 461 | ReaderImpl read; |
| 462 | return read.getFrusAtLocation(locationCode, nodeNumber, fruLocationCode); |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 463 | } |
| 464 | |
SunnySrivastava1984 | 1356d7e | 2020-04-24 04:29:35 -0500 | [diff] [blame] | 465 | ListOfPaths |
Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 466 | Manager::getFRUsByExpandedLocationCode(const LocationCode& locationCode) |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 467 | { |
SunnySrivastava1984 | fb5815a | 2020-04-24 08:03:52 -0500 | [diff] [blame] | 468 | ReaderImpl read; |
| 469 | return read.getFRUsByExpandedLocationCode(locationCode, fruLocationCode); |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 470 | } |
| 471 | |
Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 472 | LocationCode Manager::getExpandedLocationCode(const LocationCode& locationCode, |
SunnySrivastava1984 | fb5815a | 2020-04-24 08:03:52 -0500 | [diff] [blame] | 473 | const NodeNumber nodeNumber) |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 474 | { |
SunnySrivastava1984 | bca5aaa | 2020-04-21 05:31:04 -0500 | [diff] [blame] | 475 | ReaderImpl read; |
| 476 | return read.getExpandedLocationCode(locationCode, nodeNumber, |
| 477 | fruLocationCode); |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 478 | } |
SunnySrivastava1984 | de3c60d | 2020-02-03 10:34:33 -0600 | [diff] [blame] | 479 | |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 480 | void Manager::performVPDRecollection() |
| 481 | { |
| 482 | // get list of FRUs replaceable at standby |
| 483 | for (const auto& item : replaceableFrus) |
| 484 | { |
| 485 | const vector<nlohmann::json>& groupEEPROM = jsonFile["frus"][item]; |
| 486 | const nlohmann::json& singleFru = groupEEPROM[0]; |
| 487 | |
| 488 | const string& inventoryPath = |
| 489 | singleFru["inventoryPath"] |
| 490 | .get_ref<const nlohmann::json::string_t&>(); |
| 491 | |
Santosh Puranik | d40e42d | 2022-03-23 13:58:06 +0530 | [diff] [blame] | 492 | bool prePostActionRequired = false; |
| 493 | |
| 494 | if ((jsonFile["frus"][item].at(0)).find("preAction") != |
| 495 | jsonFile["frus"][item].at(0).end()) |
| 496 | { |
Sunny Srivastava | a2ddc96 | 2022-06-29 08:53:16 -0500 | [diff] [blame] | 497 | try |
Santosh Puranik | d40e42d | 2022-03-23 13:58:06 +0530 | [diff] [blame] | 498 | { |
Sunny Srivastava | a2ddc96 | 2022-06-29 08:53:16 -0500 | [diff] [blame] | 499 | if (!executePreAction(jsonFile, item)) |
| 500 | { |
| 501 | // if the FRU has preAction defined then its execution |
| 502 | // should pass to ensure bind/unbind of data. |
| 503 | // preAction execution failed. should not call |
| 504 | // bind/unbind. |
| 505 | log<level::ERR>( |
| 506 | "Pre-Action execution failed for the FRU", |
| 507 | entry("ERROR=%s", |
| 508 | ("Inventory path: " + inventoryPath).c_str())); |
| 509 | continue; |
| 510 | } |
| 511 | } |
| 512 | catch (const GpioException& e) |
| 513 | { |
| 514 | log<level::ERR>(e.what()); |
| 515 | PelAdditionalData additionalData{}; |
| 516 | additionalData.emplace("DESCRIPTION", e.what()); |
| 517 | createPEL(additionalData, PelSeverity::WARNING, |
| 518 | errIntfForGpioError, sdBus); |
Santosh Puranik | d40e42d | 2022-03-23 13:58:06 +0530 | [diff] [blame] | 519 | continue; |
| 520 | } |
| 521 | prePostActionRequired = true; |
| 522 | } |
| 523 | |
Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 524 | // unbind, bind the driver to trigger parser. |
| 525 | triggerVpdCollection(singleFru, inventoryPath); |
Santosh Puranik | d40e42d | 2022-03-23 13:58:06 +0530 | [diff] [blame] | 526 | |
| 527 | // this check is added to avoid file system expensive call in case not |
| 528 | // required. |
| 529 | if (prePostActionRequired) |
| 530 | { |
| 531 | // Check if device showed up (test for file) |
| 532 | if (!filesystem::exists(item)) |
| 533 | { |
Sunny Srivastava | a2ddc96 | 2022-06-29 08:53:16 -0500 | [diff] [blame] | 534 | try |
| 535 | { |
| 536 | // If not, then take failure postAction |
| 537 | executePostFailAction(jsonFile, item); |
| 538 | } |
| 539 | catch (const GpioException& e) |
| 540 | { |
| 541 | PelAdditionalData additionalData{}; |
| 542 | additionalData.emplace("DESCRIPTION", e.what()); |
| 543 | createPEL(additionalData, PelSeverity::WARNING, |
| 544 | errIntfForGpioError, sdBus); |
| 545 | } |
Santosh Puranik | d40e42d | 2022-03-23 13:58:06 +0530 | [diff] [blame] | 546 | } |
Alpana Kumari | 41d498c | 2021-09-16 00:29:12 -0500 | [diff] [blame] | 547 | else |
| 548 | { |
| 549 | // bind the LED driver |
| 550 | string chipAddr = singleFru.value("pcaChipAddress", ""); |
| 551 | cout << "performVPDRecollection: Executing driver binding for " |
| 552 | "chip " |
| 553 | "address - " |
| 554 | << chipAddr << endl; |
| 555 | |
| 556 | executeCmd(createBindUnbindDriverCmnd(chipAddr, "i2c", |
| 557 | "leds-pca955x", "/bind")); |
| 558 | } |
Santosh Puranik | d40e42d | 2022-03-23 13:58:06 +0530 | [diff] [blame] | 559 | } |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 560 | } |
| 561 | } |
| 562 | |
Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 563 | void Manager::collectFRUVPD(const sdbusplus::message::object_path& path) |
| 564 | { |
Sunny Srivastava | 5ef6ccc | 2022-05-30 01:35:13 -0500 | [diff] [blame] | 565 | std::cout << "Manager called to collect vpd for fru: " << std::string{path} |
| 566 | << std::endl; |
| 567 | |
Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 568 | using InvalidArgument = |
| 569 | sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument; |
| 570 | using Argument = xyz::openbmc_project::Common::InvalidArgument; |
| 571 | |
Santosh Puranik | bc59947 | 2022-12-19 20:17:10 +0530 | [diff] [blame] | 572 | std::string objPath{path}; |
| 573 | |
| 574 | // Strip any inventory prefix in path |
| 575 | if (objPath.find(INVENTORY_PATH) == 0) |
Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 576 | { |
Santosh Puranik | bc59947 | 2022-12-19 20:17:10 +0530 | [diff] [blame] | 577 | objPath = objPath.substr(sizeof(INVENTORY_PATH) - 1); |
Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 578 | } |
| 579 | |
Santosh Puranik | bc59947 | 2022-12-19 20:17:10 +0530 | [diff] [blame] | 580 | // if path not found in Json. |
| 581 | if (frus.find(objPath) == frus.end()) |
| 582 | { |
| 583 | elog<InvalidArgument>(Argument::ARGUMENT_NAME("Object Path"), |
| 584 | Argument::ARGUMENT_VALUE(objPath.c_str())); |
| 585 | } |
| 586 | |
| 587 | inventory::Path vpdFilePath = std::get<0>(frus.find(objPath)->second); |
Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 588 | |
| 589 | const std::vector<nlohmann::json>& groupEEPROM = |
| 590 | jsonFile["frus"][vpdFilePath].get_ref<const nlohmann::json::array_t&>(); |
| 591 | |
Sunny Srivastava | ab2304d | 2023-01-10 23:30:05 -0600 | [diff] [blame] | 592 | nlohmann::json singleFru{}; |
| 593 | for (const auto& item : groupEEPROM) |
| 594 | { |
| 595 | if (item["inventoryPath"] == objPath) |
| 596 | { |
| 597 | // this is the inventory we are looking for |
| 598 | singleFru = item; |
| 599 | break; |
| 600 | } |
| 601 | } |
Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 602 | |
| 603 | // check if the device qualifies for CM. |
| 604 | if (singleFru.value("concurrentlyMaintainable", false)) |
| 605 | { |
| 606 | bool prePostActionRequired = false; |
| 607 | |
| 608 | if ((jsonFile["frus"][vpdFilePath].at(0)).find("preAction") != |
| 609 | jsonFile["frus"][vpdFilePath].at(0).end()) |
| 610 | { |
| 611 | if (!executePreAction(jsonFile, vpdFilePath)) |
| 612 | { |
| 613 | // if the FRU has preAction defined then its execution should |
| 614 | // pass to ensure bind/unbind of data. |
| 615 | // preAction execution failed. should not call bind/unbind. |
| 616 | log<level::ERR>("Pre-Action execution failed for the FRU"); |
| 617 | return; |
| 618 | } |
| 619 | |
| 620 | prePostActionRequired = true; |
| 621 | } |
| 622 | |
| 623 | // unbind, bind the driver to trigger parser. |
Santosh Puranik | bc59947 | 2022-12-19 20:17:10 +0530 | [diff] [blame] | 624 | triggerVpdCollection(singleFru, objPath); |
Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 625 | |
| 626 | // this check is added to avoid file system expensive call in case not |
| 627 | // required. |
| 628 | if (prePostActionRequired) |
| 629 | { |
| 630 | // Check if device showed up (test for file) |
| 631 | if (!filesystem::exists(vpdFilePath)) |
| 632 | { |
Santosh Puranik | bc59947 | 2022-12-19 20:17:10 +0530 | [diff] [blame] | 633 | try |
| 634 | { |
| 635 | // If not, then take failure postAction |
| 636 | executePostFailAction(jsonFile, vpdFilePath); |
| 637 | } |
| 638 | catch (const GpioException& e) |
| 639 | { |
| 640 | PelAdditionalData additionalData{}; |
| 641 | additionalData.emplace("DESCRIPTION", e.what()); |
| 642 | createPEL(additionalData, PelSeverity::WARNING, |
| 643 | errIntfForGpioError, sdBus); |
| 644 | } |
Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 645 | } |
Alpana Kumari | 41d498c | 2021-09-16 00:29:12 -0500 | [diff] [blame] | 646 | else |
| 647 | { |
| 648 | // bind the LED driver |
| 649 | string chipAddr = jsonFile["frus"][vpdFilePath].at(0).value( |
| 650 | "pcaChipAddress", ""); |
| 651 | cout << "Executing driver binding for chip address - " |
| 652 | << chipAddr << endl; |
| 653 | |
| 654 | executeCmd(createBindUnbindDriverCmnd(chipAddr, "i2c", |
| 655 | "leds-pca955x", "/bind")); |
| 656 | } |
Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 657 | } |
| 658 | return; |
| 659 | } |
| 660 | else |
| 661 | { |
Santosh Puranik | bc59947 | 2022-12-19 20:17:10 +0530 | [diff] [blame] | 662 | elog<InvalidArgument>(Argument::ARGUMENT_NAME("Object Path"), |
| 663 | Argument::ARGUMENT_VALUE(objPath.c_str())); |
Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 664 | } |
| 665 | } |
| 666 | |
| 667 | void Manager::triggerVpdCollection(const nlohmann::json& singleFru, |
| 668 | const std::string& path) |
| 669 | { |
| 670 | if ((singleFru.find("devAddress") == singleFru.end()) || |
| 671 | (singleFru.find("driverType") == singleFru.end()) || |
| 672 | (singleFru.find("busType") == singleFru.end())) |
| 673 | { |
| 674 | // The FRUs is marked for collection but missing mandatory |
| 675 | // fields for collection. Log error and return. |
| 676 | log<level::ERR>( |
| 677 | "Collection Failed as mandatory field missing in Json", |
| 678 | entry("ERROR=%s", ("Recollection failed for " + (path)).c_str())); |
| 679 | |
| 680 | return; |
| 681 | } |
| 682 | |
| 683 | string deviceAddress = singleFru["devAddress"]; |
| 684 | const string& driverType = singleFru["driverType"]; |
| 685 | const string& busType = singleFru["busType"]; |
| 686 | |
| 687 | // devTreeStatus flag is present in json as false to mention |
| 688 | // that the EEPROM is not mentioned in device tree. If this flag |
| 689 | // is absent consider the value to be true, i.e EEPROM is |
| 690 | // mentioned in device tree |
| 691 | if (!singleFru.value("devTreeStatus", true)) |
| 692 | { |
| 693 | auto pos = deviceAddress.find('-'); |
| 694 | if (pos != string::npos) |
| 695 | { |
| 696 | string busNum = deviceAddress.substr(0, pos); |
| 697 | deviceAddress = "0x" + deviceAddress.substr(pos + 1, string::npos); |
| 698 | |
| 699 | string deleteDevice = "echo" + deviceAddress + " > /sys/bus/" + |
| 700 | busType + "/devices/" + busType + "-" + |
| 701 | busNum + "/delete_device"; |
| 702 | executeCmd(deleteDevice); |
| 703 | |
| 704 | string addDevice = "echo" + driverType + " " + deviceAddress + |
| 705 | " > /sys/bus/" + busType + "/devices/" + |
| 706 | busType + "-" + busNum + "/new_device"; |
| 707 | executeCmd(addDevice); |
| 708 | } |
| 709 | else |
| 710 | { |
| 711 | const string& inventoryPath = |
| 712 | singleFru["inventoryPath"] |
| 713 | .get_ref<const nlohmann::json::string_t&>(); |
| 714 | |
| 715 | log<level::ERR>( |
| 716 | "Wrong format of device address in Json", |
| 717 | entry("ERROR=%s", |
| 718 | ("Recollection failed for " + inventoryPath).c_str())); |
| 719 | } |
| 720 | } |
| 721 | else |
| 722 | { |
| 723 | executeCmd(createBindUnbindDriverCmnd(deviceAddress, busType, |
| 724 | driverType, "/unbind")); |
| 725 | executeCmd(createBindUnbindDriverCmnd(deviceAddress, busType, |
| 726 | driverType, "/bind")); |
| 727 | } |
| 728 | } |
| 729 | |
Sunny Srivastava | 28abd6e | 2021-07-28 02:58:28 -0500 | [diff] [blame] | 730 | void Manager::deleteFRUVPD(const sdbusplus::message::object_path& path) |
| 731 | { |
Sunny Srivastava | 5ef6ccc | 2022-05-30 01:35:13 -0500 | [diff] [blame] | 732 | std::cout << "Manager called to delete vpd for fru: " << std::string{path} |
| 733 | << std::endl; |
| 734 | |
Sunny Srivastava | 28abd6e | 2021-07-28 02:58:28 -0500 | [diff] [blame] | 735 | using InvalidArgument = |
| 736 | sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument; |
| 737 | using Argument = xyz::openbmc_project::Common::InvalidArgument; |
| 738 | |
Santosh Puranik | bc59947 | 2022-12-19 20:17:10 +0530 | [diff] [blame] | 739 | std::string objPath{path}; |
| 740 | |
| 741 | // Strip any inventory prefix in path |
| 742 | if (objPath.find(INVENTORY_PATH) == 0) |
Sunny Srivastava | 28abd6e | 2021-07-28 02:58:28 -0500 | [diff] [blame] | 743 | { |
Santosh Puranik | bc59947 | 2022-12-19 20:17:10 +0530 | [diff] [blame] | 744 | objPath = objPath.substr(sizeof(INVENTORY_PATH) - 1); |
Sunny Srivastava | 28abd6e | 2021-07-28 02:58:28 -0500 | [diff] [blame] | 745 | } |
| 746 | |
Santosh Puranik | bc59947 | 2022-12-19 20:17:10 +0530 | [diff] [blame] | 747 | // if path not found in Json. |
| 748 | if (frus.find(objPath) == frus.end()) |
| 749 | { |
| 750 | elog<InvalidArgument>(Argument::ARGUMENT_NAME("Object Path"), |
| 751 | Argument::ARGUMENT_VALUE(objPath.c_str())); |
| 752 | } |
| 753 | |
| 754 | inventory::Path& vpdFilePath = std::get<0>(frus.find(objPath)->second); |
Alpana Kumari | 41d498c | 2021-09-16 00:29:12 -0500 | [diff] [blame] | 755 | |
| 756 | string chipAddress = |
| 757 | jsonFile["frus"][vpdFilePath].at(0).value("pcaChipAddress", ""); |
| 758 | |
| 759 | // Unbind the LED driver for this FRU |
| 760 | cout << "Unbinding device- " << chipAddress << endl; |
| 761 | executeCmd(createBindUnbindDriverCmnd(chipAddress, "i2c", "leds-pca955x", |
| 762 | "/unbind")); |
| 763 | |
Sunny Srivastava | 28abd6e | 2021-07-28 02:58:28 -0500 | [diff] [blame] | 764 | // if the FRU is not present then log error |
Santosh Puranik | bc59947 | 2022-12-19 20:17:10 +0530 | [diff] [blame] | 765 | if (readBusProperty(objPath, "xyz.openbmc_project.Inventory.Item", |
Sunny Srivastava | 28abd6e | 2021-07-28 02:58:28 -0500 | [diff] [blame] | 766 | "Present") == "false") |
| 767 | { |
Santosh Puranik | bc59947 | 2022-12-19 20:17:10 +0530 | [diff] [blame] | 768 | elog<InvalidArgument>(Argument::ARGUMENT_NAME("FRU not preset"), |
| 769 | Argument::ARGUMENT_VALUE(objPath.c_str())); |
Sunny Srivastava | 28abd6e | 2021-07-28 02:58:28 -0500 | [diff] [blame] | 770 | } |
| 771 | else |
| 772 | { |
Santosh Puranik | bc59947 | 2022-12-19 20:17:10 +0530 | [diff] [blame] | 773 | // Set present property of FRU as false as it has been removed. |
| 774 | // CC data for FRU is also removed as |
| 775 | // a) FRU is not there so CC does not make sense. |
| 776 | // b) Sensors dependent on Panel uses CC data. |
| 777 | inventory::InterfaceMap interfaces{ |
| 778 | {"xyz.openbmc_project.Inventory.Item", {{"Present", false}}}, |
| 779 | {"com.ibm.ipzvpd.VINI", {{"CC", Binary{}}}}}; |
| 780 | |
| 781 | inventory::ObjectMap objectMap; |
| 782 | objectMap.emplace(objPath, move(interfaces)); |
Sunny Srivastava | 28abd6e | 2021-07-28 02:58:28 -0500 | [diff] [blame] | 783 | |
| 784 | common::utility::callPIM(move(objectMap)); |
| 785 | } |
| 786 | } |
| 787 | |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 788 | } // namespace manager |
| 789 | } // namespace vpd |
Patrick Williams | c78d887 | 2023-05-10 07:50:56 -0500 | [diff] [blame] | 790 | } // namespace openpower |