Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1 | #include "ipmi_fru_info_area.hpp" |
| 2 | |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 3 | #include <algorithm> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 4 | #include <ctime> |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 5 | #include <map> |
| 6 | #include <numeric> |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 7 | #include <phosphor-logging/elog.hpp> |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 8 | |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 9 | namespace ipmi |
| 10 | { |
| 11 | namespace fru |
| 12 | { |
| 13 | using namespace phosphor::logging; |
| 14 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 15 | // Property variables |
| 16 | static constexpr auto partNumber = "PartNumber"; |
| 17 | static constexpr auto serialNumber = "SerialNumber"; |
| 18 | static constexpr auto manufacturer = "Manufacturer"; |
| 19 | static constexpr auto buildDate = "BuildDate"; |
| 20 | static constexpr auto model = "Model"; |
| 21 | static constexpr auto prettyName = "PrettyName"; |
| 22 | static constexpr auto version = "Version"; |
Oskar Senft | 40f59e2 | 2018-12-04 22:43:19 -0500 | [diff] [blame] | 23 | static constexpr auto type = "Type"; |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 24 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 25 | // Board info areas |
| 26 | static constexpr auto board = "Board"; |
| 27 | static constexpr auto chassis = "Chassis"; |
| 28 | static constexpr auto product = "Product"; |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 29 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 30 | static constexpr auto specVersion = 0x1; |
| 31 | static constexpr auto recordUnitOfMeasurement = 0x8; // size in bytes |
| 32 | static constexpr auto checksumSize = 0x1; // size in bytes |
| 33 | static constexpr auto recordNotPresent = 0x0; |
| 34 | static constexpr auto englishLanguageCode = 0x0; |
| 35 | static constexpr auto typeLengthByteNull = 0x0; |
| 36 | static constexpr auto endOfCustomFields = 0xC1; |
| 37 | static constexpr auto commonHeaderFormatSize = 0x8; // size in bytes |
| 38 | static constexpr auto manufacturingDateSize = 0x3; |
| 39 | static constexpr auto areaSizeOffset = 0x1; |
| 40 | static constexpr uint8_t typeASCII = 0xC0; |
| 41 | static constexpr auto maxRecordAttributeValue = 0x1F; |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 42 | |
Andres Oportus | 7ebd246 | 2018-04-09 10:35:21 -0700 | [diff] [blame] | 43 | static constexpr auto secs_from_1970_1996 = 820454400; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 44 | static constexpr auto maxMfgDateValue = 0xFFFFFF; // 3 Byte length |
Andres Oportus | 7ebd246 | 2018-04-09 10:35:21 -0700 | [diff] [blame] | 45 | static constexpr auto secs_per_min = 60; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 46 | static constexpr auto secsToMaxMfgdate = |
| 47 | secs_from_1970_1996 + secs_per_min * maxMfgDateValue; |
Andres Oportus | 7ebd246 | 2018-04-09 10:35:21 -0700 | [diff] [blame] | 48 | |
Oskar Senft | 8b18941 | 2018-12-07 16:13:38 -0500 | [diff] [blame] | 49 | // Minimum size of resulting FRU blob. |
| 50 | // This is also the theoretical maximum size according to the spec: |
| 51 | // 8 bytes header + 5 areas at 0xff*8 bytes max each |
| 52 | // 8 + 5*0xff*8 = 0x27e0 |
| 53 | static constexpr auto fruMinSize = 0x27E0; |
| 54 | |
| 55 | // Value to use for padding. |
| 56 | // Using 0xff to match the default (blank) value in a physical EEPROM. |
| 57 | static constexpr auto fruPadValue = 0xff; |
| 58 | |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 59 | /** |
| 60 | * @brief Format Beginning of Individual IPMI FRU Data Section |
| 61 | * |
| 62 | * @param[in] langCode Language code |
| 63 | * @param[in/out] data FRU area data |
| 64 | */ |
| 65 | void preFormatProcessing(bool langCode, FruAreaData& data) |
| 66 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 67 | // Add id for version of FRU Info Storage Spec used |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 68 | data.emplace_back(specVersion); |
| 69 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 70 | // Add Data Size - 0 as a placeholder, can edit after the data is finalized |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 71 | data.emplace_back(typeLengthByteNull); |
| 72 | |
| 73 | if (langCode) |
| 74 | { |
| 75 | data.emplace_back(englishLanguageCode); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * @brief Append checksum of the FRU area data |
| 81 | * |
| 82 | * @param[in/out] data FRU area data |
| 83 | */ |
| 84 | void appendDataChecksum(FruAreaData& data) |
| 85 | { |
| 86 | uint8_t checksumVal = std::accumulate(data.begin(), data.end(), 0); |
| 87 | // Push the Zero checksum as the last byte of this data |
| 88 | // This appears to be a simple summation of all the bytes |
| 89 | data.emplace_back(-checksumVal); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * @brief Append padding bytes for the FRU area data |
| 94 | * |
| 95 | * @param[in/out] data FRU area data |
| 96 | */ |
| 97 | void padData(FruAreaData& data) |
| 98 | { |
Ratan Gupta | 3e6a769 | 2018-02-07 16:10:16 +0530 | [diff] [blame] | 99 | uint8_t pad = (data.size() + checksumSize) % recordUnitOfMeasurement; |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 100 | if (pad) |
| 101 | { |
Ratan Gupta | 3e6a769 | 2018-02-07 16:10:16 +0530 | [diff] [blame] | 102 | data.resize((data.size() + recordUnitOfMeasurement - pad)); |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * @brief Format End of Individual IPMI FRU Data Section |
| 108 | * |
| 109 | * @param[in/out] fruAreaData FRU area info data |
| 110 | */ |
| 111 | void postFormatProcessing(FruAreaData& data) |
| 112 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 113 | // This area needs to be padded to a multiple of 8 bytes (after checksum) |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 114 | padData(data); |
| 115 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 116 | // Set size of data info area |
| 117 | data.at(areaSizeOffset) = |
| 118 | (data.size() + checksumSize) / (recordUnitOfMeasurement); |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 119 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 120 | // Finally add area checksum |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 121 | appendDataChecksum(data); |
| 122 | } |
| 123 | |
| 124 | /** |
Oskar Senft | 40f59e2 | 2018-12-04 22:43:19 -0500 | [diff] [blame] | 125 | * @brief Read chassis type property value from inventory and append to the FRU |
| 126 | * area data. |
| 127 | * |
| 128 | * @param[in] propMap map of property values |
| 129 | * @param[in,out] data FRU area data to be appended |
| 130 | */ |
| 131 | void appendChassisType(const PropertyMap& propMap, FruAreaData& data) |
| 132 | { |
| 133 | uint8_t chassisType = 0; // Not specified |
| 134 | auto iter = propMap.find(type); |
| 135 | if (iter != propMap.end()) |
| 136 | { |
| 137 | auto value = iter->second; |
| 138 | chassisType = std::stoi(value); |
| 139 | } |
| 140 | data.emplace_back(chassisType); |
| 141 | } |
| 142 | |
| 143 | /** |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 144 | * @brief Read property value from inventory and append to the FRU area data |
| 145 | * |
| 146 | * @param[in] key key to search for in the property inventory data |
| 147 | * @param[in] propMap map of property values |
| 148 | * @param[in,out] data FRU area data to be appended |
| 149 | */ |
| 150 | void appendData(const Property& key, const PropertyMap& propMap, |
| 151 | FruAreaData& data) |
| 152 | { |
| 153 | auto iter = propMap.find(key); |
| 154 | if (iter != propMap.end()) |
| 155 | { |
| 156 | auto value = iter->second; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 157 | // If starts with 0x or 0X remove them |
| 158 | // ex: 0x123a just take 123a |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 159 | if ((value.compare(0, 2, "0x")) == 0 || |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 160 | (value.compare(0, 2, "0X") == 0)) |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 161 | { |
| 162 | value.erase(0, 2); |
| 163 | } |
Ratan Gupta | 6edfc5c | 2018-01-31 21:41:45 +0530 | [diff] [blame] | 164 | |
| 165 | // 5 bits for length |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 166 | // if length is greater then 31(2^5) bytes then trim the data to 31 |
| 167 | // bytess. |
| 168 | auto valueLength = (value.length() > maxRecordAttributeValue) |
| 169 | ? maxRecordAttributeValue |
| 170 | : value.length(); |
Ratan Gupta | 6edfc5c | 2018-01-31 21:41:45 +0530 | [diff] [blame] | 171 | // 2 bits for type |
| 172 | // Set the type to ascii |
| 173 | uint8_t typeLength = valueLength | ipmi::fru::typeASCII; |
| 174 | |
| 175 | data.emplace_back(typeLength); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 176 | std::copy(value.begin(), value.begin() + valueLength, |
Ratan Gupta | 6edfc5c | 2018-01-31 21:41:45 +0530 | [diff] [blame] | 177 | std::back_inserter(data)); |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 178 | } |
| 179 | else |
| 180 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 181 | // set 0 size |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 182 | data.emplace_back(typeLengthByteNull); |
| 183 | } |
| 184 | } |
| 185 | |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 186 | /** |
| 187 | * @brief Appends Build Date |
| 188 | * |
| 189 | * @param[in] propMap map of property values |
| 190 | * @param[in/out] data FRU area to add the manfufacture date |
| 191 | */ |
| 192 | void appendMfgDate(const PropertyMap& propMap, FruAreaData& data) |
| 193 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 194 | // MFG Date/Time |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 195 | auto iter = propMap.find(buildDate); |
Nagaraju Goruganti | b898cde | 2018-07-10 00:47:43 -0500 | [diff] [blame] | 196 | if ((iter != propMap.end()) && (iter->second.size() > 0)) |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 197 | { |
Andres Oportus | 7ebd246 | 2018-04-09 10:35:21 -0700 | [diff] [blame] | 198 | tm time = {}; |
| 199 | strptime(iter->second.c_str(), "%F - %H:%M:%S", &time); |
| 200 | time_t raw = mktime(&time); |
| 201 | |
| 202 | // From FRU Spec: |
| 203 | // "Mfg. Date / Time |
| 204 | // Number of minutes from 0:00 hrs 1/1/96. |
| 205 | // LSbyte first (little endian) |
| 206 | // 00_00_00h = unspecified." |
Nagaraju Goruganti | b898cde | 2018-07-10 00:47:43 -0500 | [diff] [blame] | 207 | if ((raw >= secs_from_1970_1996) && (raw <= secsToMaxMfgdate)) |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 208 | { |
Andres Oportus | 7ebd246 | 2018-04-09 10:35:21 -0700 | [diff] [blame] | 209 | raw -= secs_from_1970_1996; |
| 210 | raw /= secs_per_min; |
| 211 | uint8_t fru_raw[3]; |
| 212 | fru_raw[0] = raw & 0xFF; |
| 213 | fru_raw[1] = (raw >> 8) & 0xFF; |
| 214 | fru_raw[2] = (raw >> 16) & 0xFF; |
| 215 | std::copy(fru_raw, fru_raw + 3, std::back_inserter(data)); |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 216 | return; |
| 217 | } |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 218 | std::fprintf(stderr, "MgfDate invalid date: %u secs since UNIX epoch\n", |
| 219 | static_cast<unsigned int>(raw)); |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 220 | } |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 221 | // Blank date |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 222 | data.emplace_back(0); |
| 223 | data.emplace_back(0); |
| 224 | data.emplace_back(0); |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * @brief Builds a section of the common header |
| 229 | * |
| 230 | * @param[in] infoAreaSize size of the FRU area to write |
| 231 | * @param[in] offset Current offset for data in overall record |
| 232 | * @param[in/out] data Common Header section data container |
| 233 | */ |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 234 | void buildCommonHeaderSection(const uint32_t& infoAreaSize, uint16_t& offset, |
| 235 | FruAreaData& data) |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 236 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 237 | // Check if data for internal use section populated |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 238 | if (infoAreaSize == 0) |
| 239 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 240 | // Indicate record not present |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 241 | data.emplace_back(recordNotPresent); |
| 242 | } |
| 243 | else |
| 244 | { |
Ratan Gupta | 2f66f00 | 2018-01-31 21:26:25 +0530 | [diff] [blame] | 245 | // offset should be multiple of 8. |
Ratan Gupta | 3e6a769 | 2018-02-07 16:10:16 +0530 | [diff] [blame] | 246 | auto remainder = offset % recordUnitOfMeasurement; |
Ratan Gupta | 2f66f00 | 2018-01-31 21:26:25 +0530 | [diff] [blame] | 247 | // add the padding bytes in the offset so that offset |
| 248 | // will be multiple of 8 byte. |
Ratan Gupta | 3e6a769 | 2018-02-07 16:10:16 +0530 | [diff] [blame] | 249 | offset += (remainder > 0) ? recordUnitOfMeasurement - remainder : 0; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 250 | // Place data to define offset to area data section |
Ratan Gupta | 3e6a769 | 2018-02-07 16:10:16 +0530 | [diff] [blame] | 251 | data.emplace_back(offset / recordUnitOfMeasurement); |
Ratan Gupta | 2f66f00 | 2018-01-31 21:26:25 +0530 | [diff] [blame] | 252 | |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 253 | offset += infoAreaSize; |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | * @brief Builds the Chassis info area data section |
| 259 | * |
| 260 | * @param[in] propMap map of properties for chassis info area |
| 261 | * @return FruAreaData container with chassis info area |
| 262 | */ |
| 263 | FruAreaData buildChassisInfoArea(const PropertyMap& propMap) |
| 264 | { |
| 265 | FruAreaData fruAreaData; |
| 266 | if (!propMap.empty()) |
| 267 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 268 | // Set formatting data that goes at the beginning of the record |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 269 | preFormatProcessing(false, fruAreaData); |
| 270 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 271 | // chassis type |
Oskar Senft | 40f59e2 | 2018-12-04 22:43:19 -0500 | [diff] [blame] | 272 | appendChassisType(propMap, fruAreaData); |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 273 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 274 | // Chasiss part number, in config.yaml it is configured as model |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 275 | appendData(model, propMap, fruAreaData); |
| 276 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 277 | // Board serial number |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 278 | appendData(serialNumber, propMap, fruAreaData); |
| 279 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 280 | // Indicate End of Custom Fields |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 281 | fruAreaData.emplace_back(endOfCustomFields); |
| 282 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 283 | // Complete record data formatting |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 284 | postFormatProcessing(fruAreaData); |
| 285 | } |
| 286 | return fruAreaData; |
| 287 | } |
| 288 | |
| 289 | /** |
| 290 | * @brief Builds the Board info area data section |
| 291 | * |
| 292 | * @param[in] propMap map of properties for board info area |
| 293 | * @return FruAreaData container with board info area |
| 294 | */ |
| 295 | FruAreaData buildBoardInfoArea(const PropertyMap& propMap) |
| 296 | { |
| 297 | FruAreaData fruAreaData; |
| 298 | if (!propMap.empty()) |
| 299 | { |
| 300 | preFormatProcessing(true, fruAreaData); |
| 301 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 302 | // Manufacturing date |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 303 | appendMfgDate(propMap, fruAreaData); |
| 304 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 305 | // manufacturer |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 306 | appendData(manufacturer, propMap, fruAreaData); |
| 307 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 308 | // Product name/Pretty name |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 309 | appendData(prettyName, propMap, fruAreaData); |
| 310 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 311 | // Board serial number |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 312 | appendData(serialNumber, propMap, fruAreaData); |
| 313 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 314 | // Board part number |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 315 | appendData(partNumber, propMap, fruAreaData); |
| 316 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 317 | // FRU File ID - Empty |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 318 | fruAreaData.emplace_back(typeLengthByteNull); |
| 319 | |
| 320 | // Empty FRU File ID bytes |
| 321 | fruAreaData.emplace_back(recordNotPresent); |
| 322 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 323 | // End of custom fields |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 324 | fruAreaData.emplace_back(endOfCustomFields); |
| 325 | |
| 326 | postFormatProcessing(fruAreaData); |
| 327 | } |
| 328 | return fruAreaData; |
| 329 | } |
| 330 | |
| 331 | /** |
| 332 | * @brief Builds the Product info area data section |
| 333 | * |
| 334 | * @param[in] propMap map of FRU properties for Board info area |
| 335 | * @return FruAreaData container with product info area data |
| 336 | */ |
| 337 | FruAreaData buildProductInfoArea(const PropertyMap& propMap) |
| 338 | { |
| 339 | FruAreaData fruAreaData; |
| 340 | if (!propMap.empty()) |
| 341 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 342 | // Set formatting data that goes at the beginning of the record |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 343 | preFormatProcessing(true, fruAreaData); |
| 344 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 345 | // manufacturer |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 346 | appendData(manufacturer, propMap, fruAreaData); |
| 347 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 348 | // Product name/Pretty name |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 349 | appendData(prettyName, propMap, fruAreaData); |
| 350 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 351 | // Product part/model number |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 352 | appendData(model, propMap, fruAreaData); |
| 353 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 354 | // Product version |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 355 | appendData(version, propMap, fruAreaData); |
| 356 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 357 | // Serial Number |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 358 | appendData(serialNumber, propMap, fruAreaData); |
| 359 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 360 | // Add Asset Tag |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 361 | fruAreaData.emplace_back(recordNotPresent); |
| 362 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 363 | // FRU File ID - Empty |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 364 | fruAreaData.emplace_back(typeLengthByteNull); |
| 365 | |
| 366 | // Empty FRU File ID bytes |
| 367 | fruAreaData.emplace_back(recordNotPresent); |
| 368 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 369 | // End of custom fields |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 370 | fruAreaData.emplace_back(endOfCustomFields); |
| 371 | |
| 372 | postFormatProcessing(fruAreaData); |
| 373 | } |
| 374 | return fruAreaData; |
| 375 | } |
| 376 | |
| 377 | FruAreaData buildFruAreaData(const FruInventoryData& inventory) |
| 378 | { |
Ratan Gupta | 2f66f00 | 2018-01-31 21:26:25 +0530 | [diff] [blame] | 379 | FruAreaData combFruArea{}; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 380 | // Now build common header with data for this FRU Inv Record |
| 381 | // Use this variable to increment size of header as we go along to determine |
| 382 | // offset for the subsequent area offsets |
Ratan Gupta | 2f66f00 | 2018-01-31 21:26:25 +0530 | [diff] [blame] | 383 | uint16_t curDataOffset = commonHeaderFormatSize; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 384 | // First byte is id for version of FRU Info Storage Spec used |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 385 | combFruArea.emplace_back(specVersion); |
| 386 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 387 | // 2nd byte is offset to internal use data |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 388 | combFruArea.emplace_back(recordNotPresent); |
| 389 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 390 | // 3rd byte is offset to chassis data |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 391 | FruAreaData chassisArea; |
| 392 | auto chassisIt = inventory.find(chassis); |
| 393 | if (chassisIt != inventory.end()) |
| 394 | { |
| 395 | chassisArea = std::move(buildChassisInfoArea(chassisIt->second)); |
| 396 | } |
Ratan Gupta | 2f66f00 | 2018-01-31 21:26:25 +0530 | [diff] [blame] | 397 | // update the offset to chassis data. |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 398 | buildCommonHeaderSection(chassisArea.size(), curDataOffset, combFruArea); |
| 399 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 400 | // 4th byte is offset to board data |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 401 | FruAreaData boardArea; |
| 402 | auto boardIt = inventory.find(board); |
| 403 | if (boardIt != inventory.end()) |
| 404 | { |
| 405 | boardArea = std::move(buildBoardInfoArea(boardIt->second)); |
| 406 | } |
Ratan Gupta | 2f66f00 | 2018-01-31 21:26:25 +0530 | [diff] [blame] | 407 | // update the offset to the board data. |
| 408 | buildCommonHeaderSection(boardArea.size(), curDataOffset, combFruArea); |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 409 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 410 | // 5th byte is offset to product data |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 411 | FruAreaData prodArea; |
| 412 | auto prodIt = inventory.find(product); |
| 413 | if (prodIt != inventory.end()) |
| 414 | { |
| 415 | prodArea = std::move(buildProductInfoArea(prodIt->second)); |
| 416 | } |
Ratan Gupta | 2f66f00 | 2018-01-31 21:26:25 +0530 | [diff] [blame] | 417 | // update the offset to the product data. |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 418 | buildCommonHeaderSection(prodArea.size(), curDataOffset, combFruArea); |
| 419 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 420 | // 6th byte is offset to multirecord data |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 421 | combFruArea.emplace_back(recordNotPresent); |
| 422 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 423 | // 7th byte is PAD |
Ratan Gupta | 2f66f00 | 2018-01-31 21:26:25 +0530 | [diff] [blame] | 424 | combFruArea.emplace_back(recordNotPresent); |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 425 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 426 | // 8th (Final byte of Header Format) is the checksum |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 427 | appendDataChecksum(combFruArea); |
| 428 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 429 | // Combine everything into one full IPMI FRU specification Record |
| 430 | // add chassis use area data |
| 431 | combFruArea.insert(combFruArea.end(), chassisArea.begin(), |
| 432 | chassisArea.end()); |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 433 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 434 | // add board area data |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 435 | combFruArea.insert(combFruArea.end(), boardArea.begin(), boardArea.end()); |
| 436 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 437 | // add product use area data |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 438 | combFruArea.insert(combFruArea.end(), prodArea.begin(), prodArea.end()); |
| 439 | |
Oskar Senft | 8b18941 | 2018-12-07 16:13:38 -0500 | [diff] [blame] | 440 | // If area is smaller than the minimum size, pad it. This enables ipmitool |
| 441 | // to update the FRU blob with values longer than the original payload. |
| 442 | if (combFruArea.size() < fruMinSize) |
| 443 | { |
| 444 | combFruArea.resize(fruMinSize, fruPadValue); |
| 445 | } |
| 446 | |
Marri Devender Rao | 7d9157e | 2017-07-01 16:11:40 -0500 | [diff] [blame] | 447 | return combFruArea; |
| 448 | } |
| 449 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 450 | } // namespace fru |
| 451 | } // namespace ipmi |