Patrick Venture | 02ba884 | 2018-10-20 13:37:54 -0700 | [diff] [blame] | 1 | #include "writefrudata.hpp" |
| 2 | |
Patrick Venture | 5c2bd5e | 2018-10-20 19:45:48 -0700 | [diff] [blame] | 3 | #include "fru_area.hpp" |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 4 | #include "frup.hpp" |
| 5 | #include "types.hpp" |
| 6 | |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 7 | #include <host-ipmid/ipmid-api.h> |
Chris Austen | b45c4cb | 2015-11-01 06:34:56 -0600 | [diff] [blame] | 8 | #include <unistd.h> |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 9 | |
| 10 | #include <algorithm> |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 11 | #include <cstdio> |
| 12 | #include <cstring> |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 13 | #include <exception> |
| 14 | #include <fstream> |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 15 | #include <iostream> |
Patrick Venture | b390c0e | 2018-10-20 13:36:48 -0700 | [diff] [blame] | 16 | #include <map> |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 17 | #include <memory> |
Patrick Venture | 5739ac3 | 2018-10-16 19:17:41 -0700 | [diff] [blame] | 18 | #include <phosphor-logging/log.hpp> |
Patrick Venture | 7191849 | 2018-10-20 19:40:13 -0700 | [diff] [blame] | 19 | #include <sdbusplus/bus.hpp> |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 20 | #include <sstream> |
| 21 | #include <vector> |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 22 | |
Deepak Kodihalli | 788bd1f | 2017-02-20 01:21:59 -0600 | [diff] [blame] | 23 | using namespace ipmi::vpd; |
Patrick Venture | 5739ac3 | 2018-10-16 19:17:41 -0700 | [diff] [blame] | 24 | using namespace phosphor::logging; |
Deepak Kodihalli | 788bd1f | 2017-02-20 01:21:59 -0600 | [diff] [blame] | 25 | |
Ratan Gupta | cb0d4e5 | 2016-12-22 19:05:57 +0530 | [diff] [blame] | 26 | extern const FruMap frus; |
Deepak Kodihalli | 788bd1f | 2017-02-20 01:21:59 -0600 | [diff] [blame] | 27 | extern const std::map<Path, InterfaceMap> extras; |
Ratan Gupta | cb0d4e5 | 2016-12-22 19:05:57 +0530 | [diff] [blame] | 28 | |
Patrick Venture | 19bea9a | 2018-10-20 19:54:27 -0700 | [diff] [blame] | 29 | using FruAreaVector = std::vector<std::unique_ptr<IPMIFruArea>>; |
| 30 | |
Patrick Venture | 234b735 | 2018-10-20 09:37:09 -0700 | [diff] [blame] | 31 | namespace |
| 32 | { |
| 33 | |
| 34 | //------------------------------------------------------------ |
| 35 | // Cleanup routine |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 36 | // Must always be called as last reference to fruFilePointer. |
Patrick Venture | 234b735 | 2018-10-20 09:37:09 -0700 | [diff] [blame] | 37 | //------------------------------------------------------------ |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 38 | int cleanupError(FILE* fruFilePointer, FruAreaVector& fruAreaVec) |
Patrick Venture | 234b735 | 2018-10-20 09:37:09 -0700 | [diff] [blame] | 39 | { |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 40 | if (fruFilePointer != NULL) |
Patrick Venture | 234b735 | 2018-10-20 09:37:09 -0700 | [diff] [blame] | 41 | { |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 42 | std::fclose(fruFilePointer); |
Patrick Venture | 234b735 | 2018-10-20 09:37:09 -0700 | [diff] [blame] | 43 | } |
| 44 | |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 45 | if (!(fruAreaVec.empty())) |
Patrick Venture | 234b735 | 2018-10-20 09:37:09 -0700 | [diff] [blame] | 46 | { |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 47 | fruAreaVec.clear(); |
Patrick Venture | 234b735 | 2018-10-20 09:37:09 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | return -1; |
| 51 | } |
| 52 | |
Patrick Venture | de8ea56 | 2018-10-20 09:44:19 -0700 | [diff] [blame] | 53 | //------------------------------------------------------------------------ |
| 54 | // Gets the value of the key from the fru dictionary of the given section. |
| 55 | // FRU dictionary is parsed fru data for all the sections. |
| 56 | //------------------------------------------------------------------------ |
| 57 | std::string getFRUValue(const std::string& section, const std::string& key, |
| 58 | const std::string& delimiter, IPMIFruInfo& fruData) |
| 59 | { |
| 60 | |
| 61 | auto minIndexValue = 0; |
| 62 | auto maxIndexValue = 0; |
| 63 | std::string fruValue = ""; |
| 64 | |
| 65 | if (section == "Board") |
| 66 | { |
| 67 | minIndexValue = OPENBMC_VPD_KEY_BOARD_MFG_DATE; |
| 68 | maxIndexValue = OPENBMC_VPD_KEY_BOARD_MAX; |
| 69 | } |
| 70 | else if (section == "Product") |
| 71 | { |
| 72 | minIndexValue = OPENBMC_VPD_KEY_PRODUCT_MFR; |
| 73 | maxIndexValue = OPENBMC_VPD_KEY_PRODUCT_MAX; |
| 74 | } |
| 75 | else if (section == "Chassis") |
| 76 | { |
| 77 | minIndexValue = OPENBMC_VPD_KEY_CHASSIS_TYPE; |
| 78 | maxIndexValue = OPENBMC_VPD_KEY_CHASSIS_MAX; |
| 79 | } |
| 80 | |
| 81 | auto first = fruData.cbegin() + minIndexValue; |
| 82 | auto last = first + (maxIndexValue - minIndexValue) + 1; |
| 83 | |
Patrick Venture | c7eecc1 | 2018-10-21 08:55:44 -0700 | [diff] [blame] | 84 | auto itr = std::find_if(first, last, |
| 85 | [&key](const auto& e) { return key == e.first; }); |
Patrick Venture | de8ea56 | 2018-10-20 09:44:19 -0700 | [diff] [blame] | 86 | |
| 87 | if (itr != last) |
| 88 | { |
| 89 | fruValue = itr->second; |
| 90 | } |
| 91 | |
| 92 | // if the key is custom property then the value could be in two formats. |
| 93 | // 1) custom field 2 = "value". |
| 94 | // 2) custom field 2 = "key:value". |
| 95 | // if delimiter length = 0 i.e custom field 2 = "value" |
| 96 | |
| 97 | constexpr auto customProp = "Custom Field"; |
| 98 | if (key.find(customProp) != std::string::npos) |
| 99 | { |
| 100 | if (delimiter.length() > 0) |
| 101 | { |
| 102 | size_t delimiterpos = fruValue.find(delimiter); |
| 103 | if (delimiterpos != std::string::npos) |
Patrick Venture | 740d8c0 | 2018-10-21 12:53:05 -0700 | [diff] [blame] | 104 | { |
Patrick Venture | de8ea56 | 2018-10-20 09:44:19 -0700 | [diff] [blame] | 105 | fruValue = fruValue.substr(delimiterpos + 1); |
Patrick Venture | 740d8c0 | 2018-10-21 12:53:05 -0700 | [diff] [blame] | 106 | } |
Patrick Venture | de8ea56 | 2018-10-20 09:44:19 -0700 | [diff] [blame] | 107 | } |
| 108 | } |
| 109 | return fruValue; |
| 110 | } |
| 111 | |
Patrick Venture | 17baa27 | 2018-10-20 09:48:08 -0700 | [diff] [blame] | 112 | // Get the inventory service from the mapper. |
| 113 | auto getService(sdbusplus::bus::bus& bus, const std::string& intf, |
| 114 | const std::string& path) |
| 115 | { |
| 116 | auto mapperCall = |
| 117 | bus.new_method_call("xyz.openbmc_project.ObjectMapper", |
| 118 | "/xyz/openbmc_project/object_mapper", |
| 119 | "xyz.openbmc_project.ObjectMapper", "GetObject"); |
| 120 | |
| 121 | mapperCall.append(path); |
| 122 | mapperCall.append(std::vector<std::string>({intf})); |
| 123 | std::map<std::string, std::vector<std::string>> mapperResponse; |
| 124 | |
| 125 | try |
| 126 | { |
| 127 | auto mapperResponseMsg = bus.call(mapperCall); |
| 128 | mapperResponseMsg.read(mapperResponse); |
| 129 | } |
| 130 | catch (const sdbusplus::exception::SdBusError& ex) |
| 131 | { |
| 132 | log<level::ERR>("Exception from sdbus call", |
| 133 | entry("WHAT=%s", ex.what())); |
| 134 | throw; |
| 135 | } |
| 136 | |
| 137 | if (mapperResponse.begin() == mapperResponse.end()) |
| 138 | { |
| 139 | throw std::runtime_error("ERROR in reading the mapper response"); |
| 140 | } |
| 141 | |
| 142 | return mapperResponse.begin()->first; |
| 143 | } |
| 144 | |
Patrick Venture | 44a957d | 2018-10-20 09:41:29 -0700 | [diff] [blame] | 145 | // Takes FRU data, invokes Parser for each fru record area and updates |
| 146 | // Inventory |
| 147 | //------------------------------------------------------------------------ |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 148 | int updateInventory(FruAreaVector& areaVector, sdbusplus::bus::bus& bus) |
Patrick Venture | 44a957d | 2018-10-20 09:41:29 -0700 | [diff] [blame] | 149 | { |
| 150 | // Generic error reporter |
| 151 | int rc = 0; |
| 152 | uint8_t fruid = 0; |
| 153 | IPMIFruInfo fruData; |
| 154 | |
| 155 | // For each FRU area, extract the needed data , get it parsed and update |
| 156 | // the Inventory. |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 157 | for (const auto& fruArea : areaVector) |
Patrick Venture | 44a957d | 2018-10-20 09:41:29 -0700 | [diff] [blame] | 158 | { |
Patrick Venture | f22b36a | 2018-10-20 20:59:07 -0700 | [diff] [blame] | 159 | fruid = fruArea->getFruID(); |
Patrick Venture | 44a957d | 2018-10-20 09:41:29 -0700 | [diff] [blame] | 160 | // Fill the container with information |
Patrick Venture | 355c561 | 2018-10-22 08:49:36 -0700 | [diff] [blame^] | 161 | rc = parse_fru_area(fruArea->getType(), |
| 162 | static_cast<const void*>(fruArea->getData()), |
| 163 | fruArea->getLength(), fruData); |
Patrick Venture | 44a957d | 2018-10-20 09:41:29 -0700 | [diff] [blame] | 164 | if (rc < 0) |
| 165 | { |
| 166 | log<level::ERR>("Error parsing FRU records"); |
| 167 | return rc; |
| 168 | } |
| 169 | } // END walking the vector of areas and updating |
| 170 | |
| 171 | // For each Fru we have the list of instances which needs to be updated. |
| 172 | // Each instance object implements certain interfaces. |
| 173 | // Each Interface is having Dbus properties. |
| 174 | // Each Dbus Property would be having metaData(eg section,VpdPropertyName). |
| 175 | |
| 176 | // Here we are just printing the object,interface and the properties. |
| 177 | // which needs to be called with the new inventory manager implementation. |
Patrick Venture | 44a957d | 2018-10-20 09:41:29 -0700 | [diff] [blame] | 178 | using namespace std::string_literals; |
| 179 | static const auto intf = "xyz.openbmc_project.Inventory.Manager"s; |
| 180 | static const auto path = "/xyz/openbmc_project/inventory"s; |
| 181 | std::string service; |
| 182 | try |
| 183 | { |
| 184 | service = getService(bus, intf, path); |
| 185 | } |
| 186 | catch (const std::exception& e) |
| 187 | { |
| 188 | std::cerr << e.what() << "\n"; |
| 189 | return -1; |
| 190 | } |
| 191 | |
| 192 | auto iter = frus.find(fruid); |
| 193 | if (iter == frus.end()) |
| 194 | { |
| 195 | log<level::ERR>("Unable to get the fru info", |
| 196 | entry("FRU=%d", static_cast<int>(fruid))); |
| 197 | return -1; |
| 198 | } |
| 199 | |
| 200 | auto& instanceList = iter->second; |
| 201 | if (instanceList.size() <= 0) |
| 202 | { |
| 203 | log<level::DEBUG>("Object list empty for this FRU", |
| 204 | entry("FRU=%d", static_cast<int>(fruid))); |
| 205 | } |
| 206 | |
| 207 | ObjectMap objects; |
Patrick Venture | c7eecc1 | 2018-10-21 08:55:44 -0700 | [diff] [blame] | 208 | for (const auto& instance : instanceList) |
Patrick Venture | 44a957d | 2018-10-20 09:41:29 -0700 | [diff] [blame] | 209 | { |
| 210 | InterfaceMap interfaces; |
| 211 | const auto& extrasIter = extras.find(instance.path); |
| 212 | |
Patrick Venture | c7eecc1 | 2018-10-21 08:55:44 -0700 | [diff] [blame] | 213 | for (const auto& interfaceList : instance.interfaces) |
Patrick Venture | 44a957d | 2018-10-20 09:41:29 -0700 | [diff] [blame] | 214 | { |
| 215 | PropertyMap props; // store all the properties |
Patrick Venture | c7eecc1 | 2018-10-21 08:55:44 -0700 | [diff] [blame] | 216 | for (const auto& properties : interfaceList.second) |
Patrick Venture | 44a957d | 2018-10-20 09:41:29 -0700 | [diff] [blame] | 217 | { |
| 218 | std::string value; |
| 219 | decltype(auto) pdata = properties.second; |
| 220 | |
| 221 | if (!pdata.section.empty() && !pdata.property.empty()) |
| 222 | { |
| 223 | value = getFRUValue(pdata.section, pdata.property, |
| 224 | pdata.delimiter, fruData); |
| 225 | } |
| 226 | props.emplace(std::move(properties.first), std::move(value)); |
| 227 | } |
| 228 | // Check and update extra properties |
| 229 | if (extras.end() != extrasIter) |
| 230 | { |
| 231 | const auto& propsIter = |
| 232 | (extrasIter->second).find(interfaceList.first); |
| 233 | if ((extrasIter->second).end() != propsIter) |
| 234 | { |
| 235 | for (const auto& map : propsIter->second) |
| 236 | { |
| 237 | props.emplace(map.first, map.second); |
| 238 | } |
| 239 | } |
| 240 | } |
| 241 | interfaces.emplace(std::move(interfaceList.first), |
| 242 | std::move(props)); |
| 243 | } |
| 244 | |
| 245 | // Call the inventory manager |
Patrick Venture | 9a528f2 | 2018-10-20 13:31:28 -0700 | [diff] [blame] | 246 | sdbusplus::message::object_path objectPath = instance.path; |
Patrick Venture | 44a957d | 2018-10-20 09:41:29 -0700 | [diff] [blame] | 247 | // Check and update extra properties |
| 248 | if (extras.end() != extrasIter) |
| 249 | { |
| 250 | for (const auto& entry : extrasIter->second) |
| 251 | { |
| 252 | if (interfaces.end() == interfaces.find(entry.first)) |
| 253 | { |
| 254 | interfaces.emplace(entry.first, entry.second); |
| 255 | } |
| 256 | } |
| 257 | } |
Patrick Venture | 9a528f2 | 2018-10-20 13:31:28 -0700 | [diff] [blame] | 258 | objects.emplace(objectPath, interfaces); |
Patrick Venture | 44a957d | 2018-10-20 09:41:29 -0700 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | auto pimMsg = bus.new_method_call(service.c_str(), path.c_str(), |
| 262 | intf.c_str(), "Notify"); |
| 263 | pimMsg.append(std::move(objects)); |
| 264 | |
| 265 | try |
| 266 | { |
| 267 | auto inventoryMgrResponseMsg = bus.call(pimMsg); |
| 268 | } |
| 269 | catch (const sdbusplus::exception::SdBusError& ex) |
| 270 | { |
| 271 | log<level::ERR>("Error in notify call", entry("WHAT=%s", ex.what())); |
| 272 | return -1; |
| 273 | } |
| 274 | |
| 275 | return rc; |
| 276 | } |
| 277 | |
Patrick Venture | 234b735 | 2018-10-20 09:37:09 -0700 | [diff] [blame] | 278 | } // namespace |
| 279 | |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 280 | //------------------------------------------------ |
vishwa | f3ca352 | 2015-12-02 10:35:13 -0600 | [diff] [blame] | 281 | // Takes the pointer to stream of bytes and length |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 282 | // and returns the 8 bit checksum |
| 283 | // This algo is per IPMI V2.0 spec |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 284 | //------------------------------------------------- |
Patrick Venture | 062e145 | 2018-10-21 09:16:47 -0700 | [diff] [blame] | 285 | unsigned char calculateCRC(const unsigned char* data, size_t len) |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 286 | { |
| 287 | char crc = 0; |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 288 | size_t byte = 0; |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 289 | |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 290 | for (byte = 0; byte < len; byte++) |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 291 | { |
| 292 | crc += *data++; |
| 293 | } |
vishwa | f3ca352 | 2015-12-02 10:35:13 -0600 | [diff] [blame] | 294 | |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 295 | return (-crc); |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | //--------------------------------------------------------------------- |
| 299 | // Accepts a fru area offset in commom hdr and tells which area it is. |
| 300 | //--------------------------------------------------------------------- |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 301 | ipmi_fru_area_type getFruAreaType(uint8_t areaOffset) |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 302 | { |
| 303 | ipmi_fru_area_type type = IPMI_FRU_AREA_TYPE_MAX; |
| 304 | |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 305 | switch (areaOffset) |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 306 | { |
| 307 | case IPMI_FRU_INTERNAL_OFFSET: |
| 308 | type = IPMI_FRU_AREA_INTERNAL_USE; |
| 309 | break; |
| 310 | |
| 311 | case IPMI_FRU_CHASSIS_OFFSET: |
| 312 | type = IPMI_FRU_AREA_CHASSIS_INFO; |
| 313 | break; |
| 314 | |
| 315 | case IPMI_FRU_BOARD_OFFSET: |
| 316 | type = IPMI_FRU_AREA_BOARD_INFO; |
| 317 | break; |
| 318 | |
| 319 | case IPMI_FRU_PRODUCT_OFFSET: |
| 320 | type = IPMI_FRU_AREA_PRODUCT_INFO; |
| 321 | break; |
| 322 | |
| 323 | case IPMI_FRU_MULTI_OFFSET: |
| 324 | type = IPMI_FRU_AREA_MULTI_RECORD; |
| 325 | break; |
| 326 | |
| 327 | default: |
| 328 | type = IPMI_FRU_AREA_TYPE_MAX; |
| 329 | } |
| 330 | |
| 331 | return type; |
| 332 | } |
| 333 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 334 | ///----------------------------------------------- |
| 335 | // Validates the data for crc and mandatory fields |
| 336 | ///----------------------------------------------- |
Patrick Venture | 062e145 | 2018-10-21 09:16:47 -0700 | [diff] [blame] | 337 | int verifyFruData(const uint8_t* data, const size_t len) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 338 | { |
| 339 | uint8_t checksum = 0; |
| 340 | int rc = -1; |
| 341 | |
| 342 | // Validate for first byte to always have a value of [1] |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 343 | if (data[0] != IPMI_FRU_HDR_BYTE_ZERO) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 344 | { |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 345 | log<level::ERR>("Invalid entry in byte-0", |
| 346 | entry("ENTRY=0x%X", static_cast<uint32_t>(data[0]))); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 347 | return rc; |
| 348 | } |
| 349 | #ifdef __IPMI_DEBUG__ |
| 350 | else |
| 351 | { |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 352 | log<level::DEBUG>("Validated in entry_1 of fruData", |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 353 | entry("ENTRY=0x%X", static_cast<uint32_t>(data[0]))); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 354 | } |
| 355 | #endif |
| 356 | |
| 357 | // See if the calculated CRC matches with the embedded one. |
| 358 | // CRC to be calculated on all except the last one that is CRC itself. |
Patrick Venture | 062e145 | 2018-10-21 09:16:47 -0700 | [diff] [blame] | 359 | checksum = calculateCRC(data, len - 1); |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 360 | if (checksum != data[len - 1]) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 361 | { |
| 362 | #ifdef __IPMI_DEBUG__ |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 363 | log<level::ERR>( |
| 364 | "Checksum mismatch", |
| 365 | entry("Calculated=0x%X", static_cast<uint32_t>(checksum)), |
| 366 | entry("Embedded=0x%X", static_cast<uint32_t>(data[len]))); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 367 | #endif |
| 368 | return rc; |
| 369 | } |
| 370 | #ifdef __IPMI_DEBUG__ |
| 371 | else |
| 372 | { |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 373 | log<level::DEBUG>("Checksum matches"); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 374 | } |
| 375 | #endif |
| 376 | |
| 377 | return EXIT_SUCCESS; |
| 378 | } |
| 379 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 380 | ///---------------------------------------------------- |
| 381 | // Checks if a particular fru area is populated or not |
| 382 | ///---------------------------------------------------- |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 383 | bool removeInvalidArea(const std::unique_ptr<IPMIFruArea>& fruArea) |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 384 | { |
Deepak Kodihalli | 89ededd | 2017-02-11 01:59:32 -0600 | [diff] [blame] | 385 | // Filter the ones that are empty |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 386 | if (!(fruArea->getLength())) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 387 | { |
| 388 | return true; |
| 389 | } |
| 390 | return false; |
| 391 | } |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 392 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 393 | ///---------------------------------------------------------------------------------- |
| 394 | // Populates various FRU areas |
| 395 | // @prereq : This must be called only after validating common header. |
| 396 | ///---------------------------------------------------------------------------------- |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 397 | int ipmiPopulateFruAreas(uint8_t* fruData, const size_t dataLen, |
| 398 | FruAreaVector& fruAreaVec) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 399 | { |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 400 | int rc = -1; |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 401 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 402 | // Now walk the common header and see if the file size has atleast the last |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 403 | // offset mentioned by the struct common_header. If the file size is less |
| 404 | // than the offset of any if the fru areas mentioned in the common header, |
| 405 | // then we do not have a complete file. |
| 406 | for (uint8_t fruEntry = IPMI_FRU_INTERNAL_OFFSET; |
| 407 | fruEntry < (sizeof(struct common_header) - 2); fruEntry++) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 408 | { |
Yi Li | 75c2d46 | 2016-04-11 16:57:46 +0800 | [diff] [blame] | 409 | rc = -1; |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 410 | // Actual offset in the payload is the offset mentioned in common header |
Gunnar Mills | c19b813 | 2018-06-14 08:56:17 -0500 | [diff] [blame] | 411 | // multiplied by 8. Common header is always the first 8 bytes. |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 412 | size_t areaOffset = fruData[fruEntry] * IPMI_EIGHT_BYTES; |
| 413 | if (areaOffset && (dataLen < (areaOffset + 2))) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 414 | { |
| 415 | // Our file size is less than what it needs to be. +2 because we are |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 416 | // using area len that is at 2 byte off areaOffset |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 417 | log<level::ERR>("fru file is incomplete", |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 418 | entry("SIZE=%d", dataLen)); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 419 | return rc; |
| 420 | } |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 421 | else if (areaOffset) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 422 | { |
| 423 | // Read 2 bytes to know the actual size of area. |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 424 | uint8_t areaHeader[2] = {0}; |
| 425 | std::memcpy(areaHeader, &((uint8_t*)fruData)[areaOffset], |
| 426 | sizeof(areaHeader)); |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 427 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 428 | // Size of this area will be the 2nd byte in the fru area header. |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 429 | size_t areaLen = areaHeader[1] * IPMI_EIGHT_BYTES; |
| 430 | uint8_t areaData[areaLen] = {0}; |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 431 | |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 432 | log<level::DEBUG>("Fru Data", entry("SIZE=%d", dataLen), |
| 433 | entry("AREA OFFSET=%d", areaOffset), |
| 434 | entry("AREA_SIZE=%d", areaLen)); |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 435 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 436 | // See if we really have that much buffer. We have area offset amd |
| 437 | // from there, the actual len. |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 438 | if (dataLen < (areaLen + areaOffset)) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 439 | { |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 440 | log<level::ERR>("Incomplete Fru file", |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 441 | entry("SIZE=%d", dataLen)); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 442 | return rc; |
| 443 | } |
| 444 | |
| 445 | // Save off the data. |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 446 | std::memcpy(areaData, &((uint8_t*)fruData)[areaOffset], areaLen); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 447 | |
| 448 | // Validate the crc |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 449 | rc = verifyFruData(areaData, areaLen); |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 450 | if (rc < 0) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 451 | { |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 452 | log<level::ERR>("Err validating fru area", |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 453 | entry("OFFSET=%d", areaOffset)); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 454 | return rc; |
| 455 | } |
| 456 | else |
| 457 | { |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 458 | log<level::DEBUG>("Successfully verified area checksum.", |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 459 | entry("OFFSET=%d", areaOffset)); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | // We already have a vector that is passed to us containing all |
| 463 | // of the fields populated. Update the data portion now. |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 464 | for (auto& iter : fruAreaVec) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 465 | { |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 466 | if (iter->getType() == getFruAreaType(fruEntry)) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 467 | { |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 468 | iter->setData(areaData, areaLen); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 469 | } |
| 470 | } |
| 471 | } // If we have fru data present |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 472 | } // Walk struct common_header |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 473 | |
| 474 | // Not all the fields will be populated in a fru data. Mostly all cases will |
| 475 | // not have more than 2 or 3. |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 476 | fruAreaVec.erase( |
| 477 | std::remove_if(fruAreaVec.begin(), fruAreaVec.end(), removeInvalidArea), |
| 478 | fruAreaVec.end()); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 479 | |
| 480 | return EXIT_SUCCESS; |
| 481 | } |
| 482 | |
| 483 | ///--------------------------------------------------------- |
| 484 | // Validates the fru data per ipmi common header constructs. |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 485 | // Returns with updated struct common_header and also file_size |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 486 | //---------------------------------------------------------- |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 487 | int ipmiValidateCommonHeader(const uint8_t* fruData, const size_t dataLen) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 488 | { |
| 489 | int rc = -1; |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 490 | |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 491 | uint8_t commonHdr[sizeof(struct common_header)] = {0}; |
| 492 | if (dataLen >= sizeof(commonHdr)) |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 493 | { |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 494 | std::memcpy(commonHdr, fruData, sizeof(commonHdr)); |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 495 | } |
| 496 | else |
| 497 | { |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 498 | log<level::ERR>("Incomplete fru data file", entry("SIZE=%d", dataLen)); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 499 | return rc; |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 500 | } |
| 501 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 502 | // Verify the crc and size |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 503 | rc = verifyFruData(commonHdr, sizeof(commonHdr)); |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 504 | if (rc < 0) |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 505 | { |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 506 | log<level::ERR>("Failed to validate common header"); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 507 | return rc; |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 508 | } |
| 509 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 510 | return EXIT_SUCCESS; |
| 511 | } |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 512 | |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 513 | ///----------------------------------------------------- |
| 514 | // Accepts the filename and validates per IPMI FRU spec |
| 515 | //---------------------------------------------------- |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 516 | int validateFRUArea(const uint8_t fruid, const char* fruFilename, |
| 517 | sdbusplus::bus::bus& bus, const bool bmcOnlyFru) |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 518 | { |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 519 | size_t dataLen = 0; |
| 520 | size_t bytesRead = 0; |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 521 | int rc = -1; |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 522 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 523 | // Vector that holds individual IPMI FRU AREAs. Although MULTI and INTERNAL |
| 524 | // are not used, keeping it here for completeness. |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 525 | FruAreaVector fruAreaVec; |
Yi Li | 75c2d46 | 2016-04-11 16:57:46 +0800 | [diff] [blame] | 526 | |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 527 | for (uint8_t fruEntry = IPMI_FRU_INTERNAL_OFFSET; |
| 528 | fruEntry < (sizeof(struct common_header) - 2); fruEntry++) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 529 | { |
| 530 | // Create an object and push onto a vector. |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 531 | std::unique_ptr<IPMIFruArea> fruArea = std::make_unique<IPMIFruArea>( |
| 532 | fruid, getFruAreaType(fruEntry), bmcOnlyFru); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 533 | |
| 534 | // Physically being present |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 535 | bool present = access(fruFilename, F_OK) == 0; |
| 536 | fruArea->setPresent(present); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 537 | |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 538 | fruAreaVec.emplace_back(std::move(fruArea)); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 539 | } |
| 540 | |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 541 | FILE* fruFilePointer = std::fopen(fruFilename, "rb"); |
| 542 | if (fruFilePointer == NULL) |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 543 | { |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 544 | log<level::ERR>("Unable to open fru file", |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 545 | entry("FILE=%s", fruFilename), |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 546 | entry("ERRNO=%s", std::strerror(errno))); |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 547 | return cleanupError(fruFilePointer, fruAreaVec); |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 548 | } |
| 549 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 550 | // Get the size of the file to see if it meets minimum requirement |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 551 | if (std::fseek(fruFilePointer, 0, SEEK_END)) |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 552 | { |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 553 | log<level::ERR>("Unable to seek fru file", |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 554 | entry("FILE=%s", fruFilename), |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 555 | entry("ERRNO=%s", std::strerror(errno))); |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 556 | return cleanupError(fruFilePointer, fruAreaVec); |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 557 | } |
| 558 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 559 | // Allocate a buffer to hold entire file content |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 560 | dataLen = std::ftell(fruFilePointer); |
| 561 | uint8_t fruData[dataLen] = {0}; |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 562 | |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 563 | std::rewind(fruFilePointer); |
| 564 | bytesRead = std::fread(fruData, dataLen, 1, fruFilePointer); |
| 565 | if (bytesRead != 1) |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 566 | { |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 567 | log<level::ERR>("Failed reading fru data.", |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 568 | entry("BYTESREAD=%d", bytesRead), |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 569 | entry("ERRNO=%s", std::strerror(errno))); |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 570 | return cleanupError(fruFilePointer, fruAreaVec); |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 571 | } |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 572 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 573 | // We are done reading. |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 574 | std::fclose(fruFilePointer); |
| 575 | fruFilePointer = NULL; |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 576 | |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 577 | rc = ipmiValidateCommonHeader(fruData, dataLen); |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 578 | if (rc < 0) |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 579 | { |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 580 | return cleanupError(fruFilePointer, fruAreaVec); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 581 | } |
| 582 | |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 583 | // Now that we validated the common header, populate various fru sections if |
| 584 | // we have them here. |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 585 | rc = ipmiPopulateFruAreas(fruData, dataLen, fruAreaVec); |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 586 | if (rc < 0) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 587 | { |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 588 | log<level::ERR>("Populating FRU areas failed", entry("FRU=%d", fruid)); |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 589 | return cleanupError(fruFilePointer, fruAreaVec); |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 590 | } |
| 591 | else |
| 592 | { |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 593 | log<level::DEBUG>("Populated FRU areas", entry("FILE=%s", fruFilename)); |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 594 | } |
| 595 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 596 | #ifdef __IPMI_DEBUG__ |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 597 | for (const auto& iter : fruAreaVec) |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 598 | { |
Patrick Venture | 0e3a1c4 | 2018-10-20 21:15:41 -0700 | [diff] [blame] | 599 | std::printf("FRU ID : [%d]\n", iter->getFruID()); |
| 600 | std::printf("AREA NAME : [%s]\n", iter->getName()); |
| 601 | std::printf("TYPE : [%d]\n", iter->getType()); |
| 602 | std::printf("LEN : [%d]\n", iter->getLength()); |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 603 | } |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 604 | #endif |
| 605 | |
| 606 | // If the vector is populated with everything, then go ahead and update the |
| 607 | // inventory. |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 608 | if (!(fruAreaVec.empty())) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 609 | { |
| 610 | |
| 611 | #ifdef __IPMI_DEBUG__ |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 612 | std::printf("\n SIZE of vector is : [%d] \n", fruAreaVec.size()); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 613 | #endif |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 614 | rc = updateInventory(fruAreaVec, bus); |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 615 | if (rc < 0) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 616 | { |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 617 | log<level::ERR>("Error updating inventory."); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 618 | } |
| 619 | } |
| 620 | |
| 621 | // we are done with all that we wanted to do. This will do the job of |
| 622 | // calling any destructors too. |
Patrick Venture | ef83b99 | 2018-10-21 09:32:44 -0700 | [diff] [blame] | 623 | fruAreaVec.clear(); |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 624 | |
| 625 | return rc; |
| 626 | } |