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