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