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