Matt Spinler | 711d51d | 2019-11-06 09:36:51 -0600 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2019 IBM Corporation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 16 | #include "src.hpp" |
| 17 | |
Matt Spinler | 717de42 | 2020-06-04 13:10:14 -0500 | [diff] [blame] | 18 | #include "device_callouts.hpp" |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 19 | #include "json_utils.hpp" |
| 20 | #include "paths.hpp" |
| 21 | #include "pel_values.hpp" |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 22 | #ifdef PELTOOL |
| 23 | #include <Python.h> |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 24 | |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 25 | #include <nlohmann/json.hpp> |
Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 26 | |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 27 | #include <sstream> |
| 28 | #endif |
Matt Spinler | 0bacc8e | 2023-07-07 16:25:39 -0500 | [diff] [blame] | 29 | #include <phosphor-logging/lg2.hpp> |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 30 | |
Jayanth Othayoth | 1aa90d4 | 2023-09-13 04:25:45 -0500 | [diff] [blame] | 31 | #include <format> |
| 32 | |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 33 | namespace openpower |
| 34 | { |
| 35 | namespace pels |
| 36 | { |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 37 | namespace pv = openpower::pels::pel_values; |
| 38 | namespace rg = openpower::pels::message; |
Matt Spinler | 85f61a6 | 2020-06-03 16:28:55 -0500 | [diff] [blame] | 39 | using namespace std::string_literals; |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 40 | |
Matt Spinler | 075e5ba | 2020-02-21 15:46:00 -0600 | [diff] [blame] | 41 | constexpr size_t ccinSize = 4; |
| 42 | |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 43 | #ifdef PELTOOL |
Sumit Kumar | 516935a | 2021-04-14 13:00:54 -0500 | [diff] [blame] | 44 | using orderedJSON = nlohmann::ordered_json; |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 45 | |
| 46 | void pyDecRef(PyObject* pyObj) |
| 47 | { |
| 48 | Py_XDECREF(pyObj); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * @brief Returns a JSON string to append to SRC section. |
| 53 | * |
| 54 | * The returning string will contain a JSON object, but without |
| 55 | * the outer {}. If the input JSON isn't a JSON object (dict), then |
| 56 | * one will be created with the input added to a 'SRC Details' key. |
| 57 | * |
| 58 | * @param[in] json - The JSON to convert to a string |
| 59 | * |
| 60 | * @return std::string - The JSON string |
| 61 | */ |
Sumit Kumar | 516935a | 2021-04-14 13:00:54 -0500 | [diff] [blame] | 62 | std::string prettyJSON(const orderedJSON& json) |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 63 | { |
Sumit Kumar | 516935a | 2021-04-14 13:00:54 -0500 | [diff] [blame] | 64 | orderedJSON output; |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 65 | if (!json.is_object()) |
| 66 | { |
| 67 | output["SRC Details"] = json; |
| 68 | } |
| 69 | else |
| 70 | { |
| 71 | for (const auto& [key, value] : json.items()) |
| 72 | { |
Harisuddin Mohamed Isa | 69c1827 | 2021-05-29 13:18:45 +0800 | [diff] [blame] | 73 | output["SRC Details"][key] = value; |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 74 | } |
| 75 | } |
| 76 | |
| 77 | // Let nlohmann do the pretty printing. |
| 78 | std::stringstream stream; |
| 79 | stream << std::setw(4) << output; |
| 80 | |
| 81 | auto jsonString = stream.str(); |
| 82 | |
| 83 | // Now it looks like: |
| 84 | // { |
| 85 | // "Key": "Value", |
| 86 | // ... |
| 87 | // } |
| 88 | |
| 89 | // Replace the { and the following newline, and the } and its |
| 90 | // preceeding newline. |
| 91 | jsonString.erase(0, 2); |
| 92 | |
| 93 | auto pos = jsonString.find_last_of('}'); |
| 94 | jsonString.erase(pos - 1); |
| 95 | |
| 96 | return jsonString; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * @brief Call Python modules to parse the data into a JSON string |
| 101 | * |
| 102 | * The module to call is based on the Creator Subsystem ID under the namespace |
| 103 | * "srcparsers". For example: "srcparsers.xsrc.xsrc" where "x" is the Creator |
| 104 | * Subsystem ID in ASCII lowercase. |
| 105 | * |
| 106 | * All modules must provide the following: |
| 107 | * Function: parseSRCToJson |
| 108 | * Argument list: |
| 109 | * 1. (str) ASCII string (Hex Word 1) |
| 110 | * 2. (str) Hex Word 2 |
| 111 | * 3. (str) Hex Word 3 |
| 112 | * 4. (str) Hex Word 4 |
| 113 | * 5. (str) Hex Word 5 |
| 114 | * 6. (str) Hex Word 6 |
| 115 | * 7. (str) Hex Word 7 |
| 116 | * 8. (str) Hex Word 8 |
| 117 | * 9. (str) Hex Word 9 |
| 118 | *-Return data: |
| 119 | * 1. (str) JSON string |
| 120 | * |
| 121 | * @param[in] hexwords - Vector of strings of Hexwords 1-9 |
| 122 | * @param[in] creatorID - The creatorID from the Private Header section |
| 123 | * @return std::optional<std::string> - The JSON string if it could be created, |
| 124 | * else std::nullopt |
| 125 | */ |
| 126 | std::optional<std::string> getPythonJSON(std::vector<std::string>& hexwords, |
| 127 | uint8_t creatorID) |
| 128 | { |
Matt Spinler | be952d2 | 2022-07-01 11:30:11 -0500 | [diff] [blame] | 129 | PyObject *pName, *pModule, *eType, *eValue, *eTraceback; |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 130 | std::string pErrStr; |
| 131 | std::string module = getNumberString("%c", tolower(creatorID)) + "src"; |
| 132 | pName = PyUnicode_FromString( |
| 133 | std::string("srcparsers." + module + "." + module).c_str()); |
| 134 | std::unique_ptr<PyObject, decltype(&pyDecRef)> modNamePtr(pName, &pyDecRef); |
| 135 | pModule = PyImport_Import(pName); |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 136 | if (pModule == NULL) |
| 137 | { |
| 138 | pErrStr = "No error string found"; |
| 139 | PyErr_Fetch(&eType, &eValue, &eTraceback); |
Harisuddin Mohamed Isa | 69c1827 | 2021-05-29 13:18:45 +0800 | [diff] [blame] | 140 | if (eType) |
| 141 | { |
| 142 | Py_XDECREF(eType); |
| 143 | } |
| 144 | if (eTraceback) |
| 145 | { |
| 146 | Py_XDECREF(eTraceback); |
| 147 | } |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 148 | if (eValue) |
| 149 | { |
| 150 | PyObject* pStr = PyObject_Str(eValue); |
Harisuddin Mohamed Isa | 69c1827 | 2021-05-29 13:18:45 +0800 | [diff] [blame] | 151 | Py_XDECREF(eValue); |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 152 | if (pStr) |
| 153 | { |
| 154 | pErrStr = PyUnicode_AsUTF8(pStr); |
Harisuddin Mohamed Isa | 69c1827 | 2021-05-29 13:18:45 +0800 | [diff] [blame] | 155 | Py_XDECREF(pStr); |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 156 | } |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 157 | } |
| 158 | } |
| 159 | else |
| 160 | { |
Harisuddin Mohamed Isa | 69c1827 | 2021-05-29 13:18:45 +0800 | [diff] [blame] | 161 | std::unique_ptr<PyObject, decltype(&pyDecRef)> modPtr(pModule, |
| 162 | &pyDecRef); |
| 163 | std::string funcToCall = "parseSRCToJson"; |
Matt Spinler | be952d2 | 2022-07-01 11:30:11 -0500 | [diff] [blame] | 164 | PyObject* pKey = PyUnicode_FromString(funcToCall.c_str()); |
Harisuddin Mohamed Isa | 69c1827 | 2021-05-29 13:18:45 +0800 | [diff] [blame] | 165 | std::unique_ptr<PyObject, decltype(&pyDecRef)> keyPtr(pKey, &pyDecRef); |
Matt Spinler | be952d2 | 2022-07-01 11:30:11 -0500 | [diff] [blame] | 166 | PyObject* pDict = PyModule_GetDict(pModule); |
Harisuddin Mohamed Isa | 69c1827 | 2021-05-29 13:18:45 +0800 | [diff] [blame] | 167 | Py_INCREF(pDict); |
| 168 | if (!PyDict_Contains(pDict, pKey)) |
| 169 | { |
| 170 | Py_DECREF(pDict); |
Matt Spinler | 0bacc8e | 2023-07-07 16:25:39 -0500 | [diff] [blame] | 171 | lg2::error( |
| 172 | "Python module error. Function missing: {FUNC}, SRC = {SRC}, module = {MODULE}", |
| 173 | "FUNC", funcToCall, "SRC", hexwords.front(), "MODULE", module); |
Harisuddin Mohamed Isa | 69c1827 | 2021-05-29 13:18:45 +0800 | [diff] [blame] | 174 | return std::nullopt; |
| 175 | } |
Matt Spinler | be952d2 | 2022-07-01 11:30:11 -0500 | [diff] [blame] | 176 | PyObject* pFunc = PyDict_GetItemString(pDict, funcToCall.c_str()); |
Harisuddin Mohamed Isa | 69c1827 | 2021-05-29 13:18:45 +0800 | [diff] [blame] | 177 | Py_DECREF(pDict); |
| 178 | Py_INCREF(pFunc); |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 179 | if (PyCallable_Check(pFunc)) |
| 180 | { |
Matt Spinler | be952d2 | 2022-07-01 11:30:11 -0500 | [diff] [blame] | 181 | PyObject* pArgs = PyTuple_New(9); |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 182 | std::unique_ptr<PyObject, decltype(&pyDecRef)> argPtr(pArgs, |
| 183 | &pyDecRef); |
| 184 | for (size_t i = 0; i < 9; i++) |
| 185 | { |
Matt Spinler | c198403 | 2023-01-05 10:09:59 -0600 | [diff] [blame] | 186 | std::string arg{"00000000"}; |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 187 | if (i < hexwords.size()) |
| 188 | { |
Matt Spinler | c198403 | 2023-01-05 10:09:59 -0600 | [diff] [blame] | 189 | arg = hexwords[i]; |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 190 | } |
Matt Spinler | c198403 | 2023-01-05 10:09:59 -0600 | [diff] [blame] | 191 | PyTuple_SetItem(pArgs, i, Py_BuildValue("s", arg.c_str())); |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 192 | } |
Matt Spinler | be952d2 | 2022-07-01 11:30:11 -0500 | [diff] [blame] | 193 | PyObject* pResult = PyObject_CallObject(pFunc, pArgs); |
Harisuddin Mohamed Isa | 69c1827 | 2021-05-29 13:18:45 +0800 | [diff] [blame] | 194 | Py_DECREF(pFunc); |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 195 | if (pResult) |
| 196 | { |
Harisuddin Mohamed Isa | 69c1827 | 2021-05-29 13:18:45 +0800 | [diff] [blame] | 197 | std::unique_ptr<PyObject, decltype(&pyDecRef)> resPtr( |
| 198 | pResult, &pyDecRef); |
Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 199 | PyObject* pBytes = PyUnicode_AsEncodedString(pResult, "utf-8", |
| 200 | "~E~"); |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 201 | std::unique_ptr<PyObject, decltype(&pyDecRef)> pyBytePtr( |
| 202 | pBytes, &pyDecRef); |
| 203 | const char* output = PyBytes_AS_STRING(pBytes); |
| 204 | try |
| 205 | { |
Matt Spinler | bb1c1d5 | 2021-06-03 13:18:48 -0600 | [diff] [blame] | 206 | orderedJSON json = orderedJSON::parse(output); |
Harisuddin Mohamed Isa | 69c1827 | 2021-05-29 13:18:45 +0800 | [diff] [blame] | 207 | if ((json.is_object() && !json.empty()) || |
| 208 | (json.is_array() && json.size() > 0) || |
| 209 | (json.is_string() && json != "")) |
| 210 | { |
| 211 | return prettyJSON(json); |
| 212 | } |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 213 | } |
Patrick Williams | 66491c6 | 2021-10-06 12:23:37 -0500 | [diff] [blame] | 214 | catch (const std::exception& e) |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 215 | { |
Matt Spinler | 0bacc8e | 2023-07-07 16:25:39 -0500 | [diff] [blame] | 216 | lg2::error( |
| 217 | "Bad JSON from parser. Error = {ERROR}, SRC = {SRC}, module = {MODULE}", |
| 218 | "ERROR", e, "SRC", hexwords.front(), "MODULE", module); |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 219 | return std::nullopt; |
| 220 | } |
| 221 | } |
| 222 | else |
| 223 | { |
| 224 | pErrStr = "No error string found"; |
| 225 | PyErr_Fetch(&eType, &eValue, &eTraceback); |
Harisuddin Mohamed Isa | 69c1827 | 2021-05-29 13:18:45 +0800 | [diff] [blame] | 226 | if (eType) |
| 227 | { |
| 228 | Py_XDECREF(eType); |
| 229 | } |
| 230 | if (eTraceback) |
| 231 | { |
| 232 | Py_XDECREF(eTraceback); |
| 233 | } |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 234 | if (eValue) |
| 235 | { |
| 236 | PyObject* pStr = PyObject_Str(eValue); |
Harisuddin Mohamed Isa | 69c1827 | 2021-05-29 13:18:45 +0800 | [diff] [blame] | 237 | Py_XDECREF(eValue); |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 238 | if (pStr) |
| 239 | { |
| 240 | pErrStr = PyUnicode_AsUTF8(pStr); |
Harisuddin Mohamed Isa | 69c1827 | 2021-05-29 13:18:45 +0800 | [diff] [blame] | 241 | Py_XDECREF(pStr); |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 242 | } |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 243 | } |
| 244 | } |
| 245 | } |
| 246 | } |
| 247 | if (!pErrStr.empty()) |
| 248 | { |
Matt Spinler | 0bacc8e | 2023-07-07 16:25:39 -0500 | [diff] [blame] | 249 | lg2::debug("Python exception thrown by parser. Error = {ERROR}, " |
| 250 | "SRC = {SRC}, module = {MODULE}", |
| 251 | "ERROR", pErrStr, "SRC", hexwords.front(), "MODULE", module); |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 252 | } |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 253 | return std::nullopt; |
| 254 | } |
| 255 | #endif |
| 256 | |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 257 | void SRC::unflatten(Stream& stream) |
| 258 | { |
| 259 | stream >> _header >> _version >> _flags >> _reserved1B >> _wordCount >> |
| 260 | _reserved2B >> _size; |
| 261 | |
| 262 | for (auto& word : _hexData) |
| 263 | { |
| 264 | stream >> word; |
| 265 | } |
| 266 | |
| 267 | _asciiString = std::make_unique<src::AsciiString>(stream); |
| 268 | |
| 269 | if (hasAdditionalSections()) |
| 270 | { |
| 271 | // The callouts section is currently the only extra subsection type |
| 272 | _callouts = std::make_unique<src::Callouts>(stream); |
| 273 | } |
| 274 | } |
| 275 | |
Matt Spinler | 0688545 | 2019-11-06 10:35:42 -0600 | [diff] [blame] | 276 | void SRC::flatten(Stream& stream) const |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 277 | { |
| 278 | stream << _header << _version << _flags << _reserved1B << _wordCount |
| 279 | << _reserved2B << _size; |
| 280 | |
| 281 | for (auto& word : _hexData) |
| 282 | { |
| 283 | stream << word; |
| 284 | } |
| 285 | |
| 286 | _asciiString->flatten(stream); |
| 287 | |
| 288 | if (_callouts) |
| 289 | { |
| 290 | _callouts->flatten(stream); |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | SRC::SRC(Stream& pel) |
| 295 | { |
| 296 | try |
| 297 | { |
| 298 | unflatten(pel); |
| 299 | validate(); |
| 300 | } |
| 301 | catch (const std::exception& e) |
| 302 | { |
Matt Spinler | 0bacc8e | 2023-07-07 16:25:39 -0500 | [diff] [blame] | 303 | lg2::error("Cannot unflatten SRC, error = {ERROR}", "ERROR", e); |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 304 | _valid = false; |
| 305 | } |
| 306 | } |
| 307 | |
Matt Spinler | 075e5ba | 2020-02-21 15:46:00 -0600 | [diff] [blame] | 308 | SRC::SRC(const message::Entry& regEntry, const AdditionalData& additionalData, |
Matt Spinler | 5a90a95 | 2020-08-27 09:39:03 -0500 | [diff] [blame] | 309 | const nlohmann::json& jsonCallouts, const DataInterfaceBase& dataIface) |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 310 | { |
| 311 | _header.id = static_cast<uint16_t>(SectionID::primarySRC); |
| 312 | _header.version = srcSectionVersion; |
| 313 | _header.subType = srcSectionSubtype; |
| 314 | _header.componentID = regEntry.componentID; |
| 315 | |
| 316 | _version = srcVersion; |
| 317 | |
| 318 | _flags = 0; |
Vijay Lobo | f3702bb | 2021-04-09 15:10:19 -0500 | [diff] [blame] | 319 | |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 320 | _reserved1B = 0; |
| 321 | |
| 322 | _wordCount = numSRCHexDataWords + 1; |
| 323 | |
| 324 | _reserved2B = 0; |
| 325 | |
| 326 | // There are multiple fields encoded in the hex data words. |
| 327 | std::for_each(_hexData.begin(), _hexData.end(), |
| 328 | [](auto& word) { word = 0; }); |
Matt Spinler | 7c61918 | 2020-07-27 15:15:11 -0500 | [diff] [blame] | 329 | |
| 330 | // Hex Word 2 Nibbles: |
| 331 | // MIGVEPFF |
| 332 | // M: Partition dump status = 0 |
| 333 | // I: System boot state = TODO |
| 334 | // G: Partition Boot type = 0 |
Sumit Kumar | 9d43a72 | 2021-08-24 09:46:19 -0500 | [diff] [blame] | 335 | // V: BMC dump status |
Matt Spinler | 7c61918 | 2020-07-27 15:15:11 -0500 | [diff] [blame] | 336 | // E: Platform boot mode = 0 (side = temporary, speed = fast) |
Sumit Kumar | 9d43a72 | 2021-08-24 09:46:19 -0500 | [diff] [blame] | 337 | // P: Platform dump status |
Matt Spinler | 7c61918 | 2020-07-27 15:15:11 -0500 | [diff] [blame] | 338 | // FF: SRC format, set below |
| 339 | |
Vijay Lobo | 875b6c7 | 2021-10-20 17:38:56 -0500 | [diff] [blame] | 340 | setProgressCode(dataIface); |
Sumit Kumar | 9d43a72 | 2021-08-24 09:46:19 -0500 | [diff] [blame] | 341 | setDumpStatus(dataIface); |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 342 | setBMCFormat(); |
| 343 | setBMCPosition(); |
Matt Spinler | 075e5ba | 2020-02-21 15:46:00 -0600 | [diff] [blame] | 344 | setMotherboardCCIN(dataIface); |
| 345 | |
Matt Spinler | da5b76b | 2023-06-01 15:56:57 -0500 | [diff] [blame] | 346 | if (regEntry.src.checkstopFlag) |
| 347 | { |
| 348 | setErrorStatusFlag(ErrorStatusFlags::hwCheckstop); |
| 349 | } |
| 350 | |
Matt Spinler | 3fe93e9 | 2023-04-14 14:06:59 -0500 | [diff] [blame] | 351 | if (regEntry.src.deconfigFlag) |
| 352 | { |
| 353 | setErrorStatusFlag(ErrorStatusFlags::deconfigured); |
| 354 | } |
| 355 | |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 356 | // Fill in the last 4 words from the AdditionalData property contents. |
| 357 | setUserDefinedHexWords(regEntry, additionalData); |
| 358 | |
| 359 | _asciiString = std::make_unique<src::AsciiString>(regEntry); |
| 360 | |
Sumit Kumar | 50bfa69 | 2022-01-06 06:48:26 -0600 | [diff] [blame] | 361 | // Check for additional data - PEL_SUBSYSTEM |
| 362 | auto ss = additionalData.getValue("PEL_SUBSYSTEM"); |
| 363 | if (ss) |
| 364 | { |
| 365 | auto eventSubsystem = std::stoul(*ss, NULL, 16); |
Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 366 | std::string subsystem = pv::getValue(eventSubsystem, |
| 367 | pel_values::subsystemValues); |
Sumit Kumar | 50bfa69 | 2022-01-06 06:48:26 -0600 | [diff] [blame] | 368 | if (subsystem == "invalid") |
| 369 | { |
Matt Spinler | 0bacc8e | 2023-07-07 16:25:39 -0500 | [diff] [blame] | 370 | lg2::warning("SRC: Invalid SubSystem value: {VAL}", "VAL", lg2::hex, |
| 371 | eventSubsystem); |
Sumit Kumar | 50bfa69 | 2022-01-06 06:48:26 -0600 | [diff] [blame] | 372 | } |
| 373 | else |
| 374 | { |
| 375 | _asciiString->setByte(2, eventSubsystem); |
| 376 | } |
| 377 | } |
| 378 | |
Matt Spinler | 5a90a95 | 2020-08-27 09:39:03 -0500 | [diff] [blame] | 379 | addCallouts(regEntry, additionalData, jsonCallouts, dataIface); |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 380 | |
| 381 | _size = baseSRCSize; |
| 382 | _size += _callouts ? _callouts->flattenedSize() : 0; |
| 383 | _header.size = Section::flattenedSize() + _size; |
| 384 | |
| 385 | _valid = true; |
| 386 | } |
| 387 | |
| 388 | void SRC::setUserDefinedHexWords(const message::Entry& regEntry, |
| 389 | const AdditionalData& ad) |
| 390 | { |
| 391 | if (!regEntry.src.hexwordADFields) |
| 392 | { |
| 393 | return; |
| 394 | } |
| 395 | |
Harisuddin Mohamed Isa | 1a1b0df | 2020-11-23 16:34:36 +0800 | [diff] [blame] | 396 | // Save the AdditionalData value corresponding to the first element of |
| 397 | // adName tuple into _hexData[wordNum]. |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 398 | for (const auto& [wordNum, adName] : *regEntry.src.hexwordADFields) |
| 399 | { |
| 400 | // Can only set words 6 - 9 |
| 401 | if (!isUserDefinedWord(wordNum)) |
| 402 | { |
Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 403 | std::string msg = "SRC user data word out of range: " + |
| 404 | std::to_string(wordNum); |
Matt Spinler | 85f61a6 | 2020-06-03 16:28:55 -0500 | [diff] [blame] | 405 | addDebugData(msg); |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 406 | continue; |
| 407 | } |
| 408 | |
Harisuddin Mohamed Isa | 1a1b0df | 2020-11-23 16:34:36 +0800 | [diff] [blame] | 409 | auto value = ad.getValue(std::get<0>(adName)); |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 410 | if (value) |
| 411 | { |
| 412 | _hexData[getWordIndexFromWordNum(wordNum)] = |
| 413 | std::strtoul(value.value().c_str(), nullptr, 0); |
| 414 | } |
| 415 | else |
| 416 | { |
Harisuddin Mohamed Isa | 1a1b0df | 2020-11-23 16:34:36 +0800 | [diff] [blame] | 417 | std::string msg = "Source for user data SRC word not found: " + |
| 418 | std::get<0>(adName); |
Matt Spinler | 85f61a6 | 2020-06-03 16:28:55 -0500 | [diff] [blame] | 419 | addDebugData(msg); |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 420 | } |
| 421 | } |
| 422 | } |
| 423 | |
Matt Spinler | 075e5ba | 2020-02-21 15:46:00 -0600 | [diff] [blame] | 424 | void SRC::setMotherboardCCIN(const DataInterfaceBase& dataIface) |
| 425 | { |
| 426 | uint32_t ccin = 0; |
| 427 | auto ccinString = dataIface.getMotherboardCCIN(); |
| 428 | |
| 429 | try |
| 430 | { |
| 431 | if (ccinString.size() == ccinSize) |
| 432 | { |
| 433 | ccin = std::stoi(ccinString, 0, 16); |
| 434 | } |
| 435 | } |
Patrick Williams | 66491c6 | 2021-10-06 12:23:37 -0500 | [diff] [blame] | 436 | catch (const std::exception& e) |
Matt Spinler | 075e5ba | 2020-02-21 15:46:00 -0600 | [diff] [blame] | 437 | { |
Matt Spinler | 0bacc8e | 2023-07-07 16:25:39 -0500 | [diff] [blame] | 438 | lg2::warning("Could not convert motherboard CCIN {CCIN} to a number", |
| 439 | "CCIN", ccinString); |
Matt Spinler | 075e5ba | 2020-02-21 15:46:00 -0600 | [diff] [blame] | 440 | return; |
| 441 | } |
| 442 | |
| 443 | // Set the first 2 bytes |
| 444 | _hexData[1] |= ccin << 16; |
| 445 | } |
| 446 | |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 447 | void SRC::validate() |
| 448 | { |
| 449 | bool failed = false; |
| 450 | |
| 451 | if ((header().id != static_cast<uint16_t>(SectionID::primarySRC)) && |
| 452 | (header().id != static_cast<uint16_t>(SectionID::secondarySRC))) |
| 453 | { |
Matt Spinler | 0bacc8e | 2023-07-07 16:25:39 -0500 | [diff] [blame] | 454 | lg2::error("Invalid SRC section ID: {ID}", "ID", lg2::hex, header().id); |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 455 | failed = true; |
| 456 | } |
| 457 | |
| 458 | // Check the version in the SRC, not in the header |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 459 | if (_version != srcVersion) |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 460 | { |
Matt Spinler | 0bacc8e | 2023-07-07 16:25:39 -0500 | [diff] [blame] | 461 | lg2::error("Invalid SRC version: {VERSION}", "VERSION", lg2::hex, |
| 462 | header().version); |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 463 | failed = true; |
| 464 | } |
| 465 | |
| 466 | _valid = failed ? false : true; |
| 467 | } |
| 468 | |
Matt Spinler | 075e5ba | 2020-02-21 15:46:00 -0600 | [diff] [blame] | 469 | bool SRC::isBMCSRC() const |
| 470 | { |
| 471 | auto as = asciiString(); |
| 472 | if (as.length() >= 2) |
| 473 | { |
| 474 | uint8_t errorType = strtoul(as.substr(0, 2).c_str(), nullptr, 16); |
| 475 | return (errorType == static_cast<uint8_t>(SRCType::bmcError) || |
| 476 | errorType == static_cast<uint8_t>(SRCType::powerError)); |
| 477 | } |
| 478 | return false; |
| 479 | } |
| 480 | |
Matt Spinler | 4deed97 | 2023-04-28 14:09:22 -0500 | [diff] [blame] | 481 | bool SRC::isHostbootSRC() const |
| 482 | { |
| 483 | auto as = asciiString(); |
| 484 | if (as.length() >= 2) |
| 485 | { |
| 486 | uint8_t errorType = strtoul(as.substr(0, 2).c_str(), nullptr, 16); |
| 487 | return errorType == static_cast<uint8_t>(SRCType::hostbootError); |
| 488 | } |
| 489 | return false; |
| 490 | } |
| 491 | |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 492 | std::optional<std::string> SRC::getErrorDetails(message::Registry& registry, |
| 493 | DetailLevel type, |
| 494 | bool toCache) const |
| 495 | { |
| 496 | const std::string jsonIndent(indentLevel, 0x20); |
| 497 | std::string errorOut; |
Matt Spinler | 075e5ba | 2020-02-21 15:46:00 -0600 | [diff] [blame] | 498 | if (isBMCSRC()) |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 499 | { |
| 500 | auto entry = registry.lookup("0x" + asciiString().substr(4, 4), |
| 501 | rg::LookupType::reasonCode, toCache); |
| 502 | if (entry) |
| 503 | { |
| 504 | errorOut.append(jsonIndent + "\"Error Details\": {\n"); |
| 505 | auto errorMsg = getErrorMessage(*entry); |
| 506 | if (errorMsg) |
| 507 | { |
| 508 | if (type == DetailLevel::message) |
| 509 | { |
| 510 | return errorMsg.value(); |
| 511 | } |
| 512 | else |
| 513 | { |
| 514 | jsonInsert(errorOut, "Message", errorMsg.value(), 2); |
| 515 | } |
| 516 | } |
| 517 | if (entry->src.hexwordADFields) |
| 518 | { |
Harisuddin Mohamed Isa | 1a1b0df | 2020-11-23 16:34:36 +0800 | [diff] [blame] | 519 | std::map<size_t, std::tuple<std::string, std::string>> |
| 520 | adFields = entry->src.hexwordADFields.value(); |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 521 | for (const auto& hexwordMap : adFields) |
| 522 | { |
Zane Shelley | e8db29b | 2021-11-13 10:34:07 -0600 | [diff] [blame] | 523 | auto srcValue = getNumberString( |
Harisuddin Mohamed Isa | 1a1b0df | 2020-11-23 16:34:36 +0800 | [diff] [blame] | 524 | "0x%X", |
Zane Shelley | e8db29b | 2021-11-13 10:34:07 -0600 | [diff] [blame] | 525 | _hexData[getWordIndexFromWordNum(hexwordMap.first)]); |
| 526 | |
| 527 | auto srcKey = std::get<0>(hexwordMap.second); |
| 528 | auto srcDesc = std::get<1>(hexwordMap.second); |
| 529 | |
| 530 | // Only include this hex word in the error details if the |
| 531 | // description exists. |
| 532 | if (!srcDesc.empty()) |
| 533 | { |
| 534 | std::vector<std::string> valueDescr; |
| 535 | valueDescr.push_back(srcValue); |
| 536 | valueDescr.push_back(srcDesc); |
| 537 | jsonInsertArray(errorOut, srcKey, valueDescr, 2); |
| 538 | } |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 539 | } |
| 540 | } |
| 541 | errorOut.erase(errorOut.size() - 2); |
| 542 | errorOut.append("\n"); |
| 543 | errorOut.append(jsonIndent + "},\n"); |
| 544 | return errorOut; |
| 545 | } |
| 546 | } |
| 547 | return std::nullopt; |
| 548 | } |
| 549 | |
| 550 | std::optional<std::string> |
| 551 | SRC::getErrorMessage(const message::Entry& regEntry) const |
| 552 | { |
| 553 | try |
| 554 | { |
| 555 | if (regEntry.doc.messageArgSources) |
| 556 | { |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 557 | std::vector<uint32_t> argSourceVals; |
| 558 | std::string message; |
| 559 | const auto& argValues = regEntry.doc.messageArgSources.value(); |
| 560 | for (size_t i = 0; i < argValues.size(); ++i) |
| 561 | { |
| 562 | argSourceVals.push_back(_hexData[getWordIndexFromWordNum( |
| 563 | argValues[i].back() - '0')]); |
| 564 | } |
Patrick Williams | 0230abb | 2021-04-19 14:32:50 -0500 | [diff] [blame] | 565 | |
| 566 | auto it = std::begin(regEntry.doc.message); |
| 567 | auto it_end = std::end(regEntry.doc.message); |
| 568 | |
| 569 | while (it != it_end) |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 570 | { |
Patrick Williams | 0230abb | 2021-04-19 14:32:50 -0500 | [diff] [blame] | 571 | if (*it == '%') |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 572 | { |
Patrick Williams | 0230abb | 2021-04-19 14:32:50 -0500 | [diff] [blame] | 573 | ++it; |
| 574 | |
| 575 | size_t wordIndex = *it - '0'; |
| 576 | if (isdigit(*it) && wordIndex >= 1 && |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 577 | static_cast<uint16_t>(wordIndex) <= |
| 578 | argSourceVals.size()) |
| 579 | { |
| 580 | message.append(getNumberString( |
Zane Shelley | 39936e3 | 2021-11-13 16:19:34 -0600 | [diff] [blame] | 581 | "0x%08X", argSourceVals[wordIndex - 1])); |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 582 | } |
| 583 | else |
| 584 | { |
Patrick Williams | 0230abb | 2021-04-19 14:32:50 -0500 | [diff] [blame] | 585 | message.append("%" + std::string(1, *it)); |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 586 | } |
| 587 | } |
| 588 | else |
| 589 | { |
Patrick Williams | 0230abb | 2021-04-19 14:32:50 -0500 | [diff] [blame] | 590 | message.push_back(*it); |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 591 | } |
Patrick Williams | 0230abb | 2021-04-19 14:32:50 -0500 | [diff] [blame] | 592 | ++it; |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 593 | } |
Patrick Williams | 0230abb | 2021-04-19 14:32:50 -0500 | [diff] [blame] | 594 | |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 595 | return message; |
| 596 | } |
| 597 | else |
| 598 | { |
| 599 | return regEntry.doc.message; |
| 600 | } |
| 601 | } |
| 602 | catch (const std::exception& e) |
| 603 | { |
Matt Spinler | 0bacc8e | 2023-07-07 16:25:39 -0500 | [diff] [blame] | 604 | lg2::error( |
| 605 | "Cannot get error message from registry entry, error = {ERROR}", |
| 606 | "ERROR", e); |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 607 | } |
| 608 | return std::nullopt; |
| 609 | } |
| 610 | |
| 611 | std::optional<std::string> SRC::getCallouts() const |
| 612 | { |
| 613 | if (!_callouts) |
| 614 | { |
| 615 | return std::nullopt; |
| 616 | } |
| 617 | std::string printOut; |
| 618 | const std::string jsonIndent(indentLevel, 0x20); |
| 619 | const auto& callout = _callouts->callouts(); |
| 620 | const auto& compDescrp = pv::failingComponentType; |
| 621 | printOut.append(jsonIndent + "\"Callout Section\": {\n"); |
| 622 | jsonInsert(printOut, "Callout Count", std::to_string(callout.size()), 2); |
| 623 | printOut.append(jsonIndent + jsonIndent + "\"Callouts\": ["); |
| 624 | for (auto& entry : callout) |
| 625 | { |
| 626 | printOut.append("{\n"); |
| 627 | if (entry->fruIdentity()) |
| 628 | { |
| 629 | jsonInsert( |
| 630 | printOut, "FRU Type", |
| 631 | compDescrp.at(entry->fruIdentity()->failingComponentType()), 3); |
| 632 | jsonInsert(printOut, "Priority", |
| 633 | pv::getValue(entry->priority(), |
| 634 | pel_values::calloutPriorityValues), |
| 635 | 3); |
| 636 | if (!entry->locationCode().empty()) |
| 637 | { |
| 638 | jsonInsert(printOut, "Location Code", entry->locationCode(), 3); |
| 639 | } |
| 640 | if (entry->fruIdentity()->getPN().has_value()) |
| 641 | { |
| 642 | jsonInsert(printOut, "Part Number", |
| 643 | entry->fruIdentity()->getPN().value(), 3); |
| 644 | } |
| 645 | if (entry->fruIdentity()->getMaintProc().has_value()) |
| 646 | { |
Matt Spinler | 9e8b49e | 2020-09-10 13:15:26 -0500 | [diff] [blame] | 647 | jsonInsert(printOut, "Procedure", |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 648 | entry->fruIdentity()->getMaintProc().value(), 3); |
| 649 | if (pv::procedureDesc.find( |
| 650 | entry->fruIdentity()->getMaintProc().value()) != |
| 651 | pv::procedureDesc.end()) |
| 652 | { |
| 653 | jsonInsert( |
| 654 | printOut, "Description", |
| 655 | pv::procedureDesc.at( |
| 656 | entry->fruIdentity()->getMaintProc().value()), |
| 657 | 3); |
| 658 | } |
| 659 | } |
| 660 | if (entry->fruIdentity()->getCCIN().has_value()) |
| 661 | { |
| 662 | jsonInsert(printOut, "CCIN", |
| 663 | entry->fruIdentity()->getCCIN().value(), 3); |
| 664 | } |
| 665 | if (entry->fruIdentity()->getSN().has_value()) |
| 666 | { |
| 667 | jsonInsert(printOut, "Serial Number", |
| 668 | entry->fruIdentity()->getSN().value(), 3); |
| 669 | } |
| 670 | } |
| 671 | if (entry->pceIdentity()) |
| 672 | { |
| 673 | const auto& pceIdentMtms = entry->pceIdentity()->mtms(); |
| 674 | if (!pceIdentMtms.machineTypeAndModel().empty()) |
| 675 | { |
| 676 | jsonInsert(printOut, "PCE MTMS", |
| 677 | pceIdentMtms.machineTypeAndModel() + "_" + |
| 678 | pceIdentMtms.machineSerialNumber(), |
| 679 | 3); |
| 680 | } |
| 681 | if (!entry->pceIdentity()->enclosureName().empty()) |
| 682 | { |
| 683 | jsonInsert(printOut, "PCE Name", |
| 684 | entry->pceIdentity()->enclosureName(), 3); |
| 685 | } |
| 686 | } |
| 687 | if (entry->mru()) |
| 688 | { |
| 689 | const auto& mruCallouts = entry->mru()->mrus(); |
| 690 | std::string mruId; |
| 691 | for (auto& element : mruCallouts) |
| 692 | { |
| 693 | if (!mruId.empty()) |
| 694 | { |
| 695 | mruId.append(", " + getNumberString("%08X", element.id)); |
| 696 | } |
| 697 | else |
| 698 | { |
| 699 | mruId.append(getNumberString("%08X", element.id)); |
| 700 | } |
| 701 | } |
| 702 | jsonInsert(printOut, "MRU Id", mruId, 3); |
| 703 | } |
| 704 | printOut.erase(printOut.size() - 2); |
| 705 | printOut.append("\n" + jsonIndent + jsonIndent + "}, "); |
| 706 | }; |
| 707 | printOut.erase(printOut.size() - 2); |
| 708 | printOut.append("]\n" + jsonIndent + "}"); |
| 709 | return printOut; |
| 710 | } |
| 711 | |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 712 | std::optional<std::string> SRC::getJSON(message::Registry& registry, |
Patrick Williams | d26fa3e | 2021-04-21 15:22:23 -0500 | [diff] [blame] | 713 | const std::vector<std::string>& plugins |
| 714 | [[maybe_unused]], |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 715 | uint8_t creatorID) const |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 716 | { |
| 717 | std::string ps; |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 718 | std::vector<std::string> hexwords; |
Harisuddin Mohamed Isa | bebeb94 | 2020-03-12 17:12:24 +0800 | [diff] [blame] | 719 | jsonInsert(ps, pv::sectionVer, getNumberString("%d", _header.version), 1); |
| 720 | jsonInsert(ps, pv::subSection, getNumberString("%d", _header.subType), 1); |
Matt Spinler | b832aa5 | 2023-03-21 15:32:34 -0500 | [diff] [blame] | 721 | jsonInsert(ps, pv::createdBy, |
| 722 | getComponentName(_header.componentID, creatorID), 1); |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 723 | jsonInsert(ps, "SRC Version", getNumberString("0x%02X", _version), 1); |
Harisuddin Mohamed Isa | c32e551 | 2020-02-06 18:05:21 +0800 | [diff] [blame] | 724 | jsonInsert(ps, "SRC Format", getNumberString("0x%02X", _hexData[0] & 0xFF), |
| 725 | 1); |
| 726 | jsonInsert(ps, "Virtual Progress SRC", |
| 727 | pv::boolString.at(_flags & virtualProgressSRC), 1); |
| 728 | jsonInsert(ps, "I5/OS Service Event Bit", |
| 729 | pv::boolString.at(_flags & i5OSServiceEventBit), 1); |
| 730 | jsonInsert(ps, "Hypervisor Dump Initiated", |
| 731 | pv::boolString.at(_flags & hypDumpInit), 1); |
Matt Spinler | 075e5ba | 2020-02-21 15:46:00 -0600 | [diff] [blame] | 732 | |
| 733 | if (isBMCSRC()) |
| 734 | { |
| 735 | std::string ccinString; |
| 736 | uint32_t ccin = _hexData[1] >> 16; |
| 737 | |
| 738 | if (ccin) |
| 739 | { |
| 740 | ccinString = getNumberString("%04X", ccin); |
| 741 | } |
| 742 | // The PEL spec calls it a backplane, so call it that here. |
| 743 | jsonInsert(ps, "Backplane CCIN", ccinString, 1); |
Matt Spinler | afa2c79 | 2020-08-27 11:01:39 -0500 | [diff] [blame] | 744 | |
Sumit Kumar | 3e27443 | 2021-09-14 06:37:56 -0500 | [diff] [blame] | 745 | jsonInsert(ps, "Terminate FW Error", |
| 746 | pv::boolString.at( |
| 747 | _hexData[3] & |
| 748 | static_cast<uint32_t>(ErrorStatusFlags::terminateFwErr)), |
| 749 | 1); |
Matt Spinler | 4deed97 | 2023-04-28 14:09:22 -0500 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | if (isBMCSRC() || isHostbootSRC()) |
| 753 | { |
Matt Spinler | afa2c79 | 2020-08-27 11:01:39 -0500 | [diff] [blame] | 754 | jsonInsert(ps, "Deconfigured", |
| 755 | pv::boolString.at( |
| 756 | _hexData[3] & |
| 757 | static_cast<uint32_t>(ErrorStatusFlags::deconfigured)), |
| 758 | 1); |
| 759 | |
| 760 | jsonInsert( |
| 761 | ps, "Guarded", |
| 762 | pv::boolString.at(_hexData[3] & |
| 763 | static_cast<uint32_t>(ErrorStatusFlags::guarded)), |
| 764 | 1); |
Matt Spinler | 075e5ba | 2020-02-21 15:46:00 -0600 | [diff] [blame] | 765 | } |
| 766 | |
Harisuddin Mohamed Isa | a214ed3 | 2020-02-28 15:58:23 +0800 | [diff] [blame] | 767 | auto errorDetails = getErrorDetails(registry, DetailLevel::json, true); |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 768 | if (errorDetails) |
| 769 | { |
| 770 | ps.append(errorDetails.value()); |
| 771 | } |
| 772 | jsonInsert(ps, "Valid Word Count", getNumberString("0x%02X", _wordCount), |
| 773 | 1); |
| 774 | std::string refcode = asciiString(); |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 775 | hexwords.push_back(refcode); |
Harisuddin Mohamed Isa | fecaa57 | 2020-03-11 16:04:50 +0800 | [diff] [blame] | 776 | std::string extRefcode; |
| 777 | size_t pos = refcode.find(0x20); |
| 778 | if (pos != std::string::npos) |
| 779 | { |
| 780 | size_t nextPos = refcode.find_first_not_of(0x20, pos); |
| 781 | if (nextPos != std::string::npos) |
| 782 | { |
| 783 | extRefcode = trimEnd(refcode.substr(nextPos)); |
| 784 | } |
| 785 | refcode.erase(pos); |
| 786 | } |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 787 | jsonInsert(ps, "Reference Code", refcode, 1); |
Harisuddin Mohamed Isa | fecaa57 | 2020-03-11 16:04:50 +0800 | [diff] [blame] | 788 | if (!extRefcode.empty()) |
| 789 | { |
| 790 | jsonInsert(ps, "Extended Reference Code", extRefcode, 1); |
| 791 | } |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 792 | for (size_t i = 2; i <= _wordCount; i++) |
| 793 | { |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 794 | std::string tmpWord = |
| 795 | getNumberString("%08X", _hexData[getWordIndexFromWordNum(i)]); |
| 796 | jsonInsert(ps, "Hex Word " + std::to_string(i), tmpWord, 1); |
| 797 | hexwords.push_back(tmpWord); |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 798 | } |
| 799 | auto calloutJson = getCallouts(); |
| 800 | if (calloutJson) |
| 801 | { |
| 802 | ps.append(calloutJson.value()); |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 803 | ps.append(",\n"); |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 804 | } |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 805 | std::string subsystem = getNumberString("%c", tolower(creatorID)); |
| 806 | bool srcDetailExists = false; |
| 807 | #ifdef PELTOOL |
| 808 | if (std::find(plugins.begin(), plugins.end(), subsystem + "src") != |
| 809 | plugins.end()) |
| 810 | { |
| 811 | auto pyJson = getPythonJSON(hexwords, creatorID); |
| 812 | if (pyJson) |
| 813 | { |
| 814 | ps.append(pyJson.value()); |
| 815 | srcDetailExists = true; |
| 816 | } |
| 817 | } |
| 818 | #endif |
| 819 | if (!srcDetailExists) |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 820 | { |
| 821 | ps.erase(ps.size() - 2); |
| 822 | } |
| 823 | return ps; |
| 824 | } |
| 825 | |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 826 | void SRC::addCallouts(const message::Entry& regEntry, |
| 827 | const AdditionalData& additionalData, |
Matt Spinler | 5a90a95 | 2020-08-27 09:39:03 -0500 | [diff] [blame] | 828 | const nlohmann::json& jsonCallouts, |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 829 | const DataInterfaceBase& dataIface) |
| 830 | { |
Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 831 | auto registryCallouts = getRegistryCallouts(regEntry, additionalData, |
| 832 | dataIface); |
Matt Spinler | f00f9d0 | 2020-10-23 09:14:22 -0500 | [diff] [blame] | 833 | |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 834 | auto item = additionalData.getValue("CALLOUT_INVENTORY_PATH"); |
Miguel Gomez | 53ef155 | 2020-10-14 21:16:32 +0000 | [diff] [blame] | 835 | auto priority = additionalData.getValue("CALLOUT_PRIORITY"); |
Matt Spinler | f00f9d0 | 2020-10-23 09:14:22 -0500 | [diff] [blame] | 836 | |
Miguel Gomez | 53ef155 | 2020-10-14 21:16:32 +0000 | [diff] [blame] | 837 | std::optional<CalloutPriority> calloutPriority; |
| 838 | |
| 839 | // Only H, M or L priority values. |
| 840 | if (priority && !(*priority).empty()) |
| 841 | { |
| 842 | uint8_t p = (*priority)[0]; |
| 843 | if (p == 'H' || p == 'M' || p == 'L') |
| 844 | { |
| 845 | calloutPriority = static_cast<CalloutPriority>(p); |
| 846 | } |
| 847 | } |
Matt Spinler | f00f9d0 | 2020-10-23 09:14:22 -0500 | [diff] [blame] | 848 | // If the first registry callout says to use the passed in inventory |
| 849 | // path to get the location code for a symbolic FRU callout with a |
| 850 | // trusted location code, then do not add the inventory path as a |
| 851 | // normal FRU callout. |
| 852 | bool useInvForSymbolicFRULocCode = |
| 853 | !registryCallouts.empty() && registryCallouts[0].useInventoryLocCode && |
| 854 | !registryCallouts[0].symbolicFRUTrusted.empty(); |
| 855 | |
| 856 | if (item && !useInvForSymbolicFRULocCode) |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 857 | { |
Miguel Gomez | 53ef155 | 2020-10-14 21:16:32 +0000 | [diff] [blame] | 858 | addInventoryCallout(*item, calloutPriority, std::nullopt, dataIface); |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 859 | } |
| 860 | |
Matt Spinler | 717de42 | 2020-06-04 13:10:14 -0500 | [diff] [blame] | 861 | addDevicePathCallouts(additionalData, dataIface); |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 862 | |
Matt Spinler | f00f9d0 | 2020-10-23 09:14:22 -0500 | [diff] [blame] | 863 | addRegistryCallouts(registryCallouts, dataIface, |
| 864 | (useInvForSymbolicFRULocCode) ? item : std::nullopt); |
Matt Spinler | 5a90a95 | 2020-08-27 09:39:03 -0500 | [diff] [blame] | 865 | |
| 866 | if (!jsonCallouts.empty()) |
| 867 | { |
| 868 | addJSONCallouts(jsonCallouts, dataIface); |
| 869 | } |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | void SRC::addInventoryCallout(const std::string& inventoryPath, |
Matt Spinler | af191c7 | 2020-06-04 11:35:13 -0500 | [diff] [blame] | 873 | const std::optional<CalloutPriority>& priority, |
| 874 | const std::optional<std::string>& locationCode, |
Matt Spinler | b8cb60f | 2020-08-27 10:55:55 -0500 | [diff] [blame] | 875 | const DataInterfaceBase& dataIface, |
| 876 | const std::vector<src::MRU::MRUCallout>& mrus) |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 877 | { |
| 878 | std::string locCode; |
| 879 | std::string fn; |
| 880 | std::string ccin; |
| 881 | std::string sn; |
| 882 | std::unique_ptr<src::Callout> callout; |
| 883 | |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 884 | try |
| 885 | { |
Matt Spinler | af191c7 | 2020-06-04 11:35:13 -0500 | [diff] [blame] | 886 | // Use the passed in location code if there otherwise look it up |
| 887 | if (locationCode) |
| 888 | { |
| 889 | locCode = *locationCode; |
| 890 | } |
| 891 | else |
| 892 | { |
| 893 | locCode = dataIface.getLocationCode(inventoryPath); |
| 894 | } |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 895 | |
Matt Spinler | 9b90e2a | 2020-04-14 10:59:04 -0500 | [diff] [blame] | 896 | try |
| 897 | { |
| 898 | dataIface.getHWCalloutFields(inventoryPath, fn, ccin, sn); |
| 899 | |
Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 900 | CalloutPriority p = priority ? priority.value() |
| 901 | : CalloutPriority::high; |
Matt Spinler | af191c7 | 2020-06-04 11:35:13 -0500 | [diff] [blame] | 902 | |
Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 903 | callout = std::make_unique<src::Callout>(p, locCode, fn, ccin, sn, |
| 904 | mrus); |
Matt Spinler | 9b90e2a | 2020-04-14 10:59:04 -0500 | [diff] [blame] | 905 | } |
Patrick Williams | 45e8352 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 906 | catch (const sdbusplus::exception_t& e) |
Matt Spinler | 9b90e2a | 2020-04-14 10:59:04 -0500 | [diff] [blame] | 907 | { |
Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 908 | std::string msg = "No VPD found for " + inventoryPath + ": " + |
| 909 | e.what(); |
Matt Spinler | 85f61a6 | 2020-06-03 16:28:55 -0500 | [diff] [blame] | 910 | addDebugData(msg); |
Matt Spinler | 9b90e2a | 2020-04-14 10:59:04 -0500 | [diff] [blame] | 911 | |
| 912 | // Just create the callout with empty FRU fields |
Matt Spinler | b8cb60f | 2020-08-27 10:55:55 -0500 | [diff] [blame] | 913 | callout = std::make_unique<src::Callout>( |
| 914 | CalloutPriority::high, locCode, fn, ccin, sn, mrus); |
Matt Spinler | 9b90e2a | 2020-04-14 10:59:04 -0500 | [diff] [blame] | 915 | } |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 916 | } |
Patrick Williams | 45e8352 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 917 | catch (const sdbusplus::exception_t& e) |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 918 | { |
Matt Spinler | 85f61a6 | 2020-06-03 16:28:55 -0500 | [diff] [blame] | 919 | std::string msg = "Could not get location code for " + inventoryPath + |
| 920 | ": " + e.what(); |
| 921 | addDebugData(msg); |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 922 | |
Matt Spinler | 479b692 | 2021-08-17 16:34:59 -0500 | [diff] [blame] | 923 | // Don't add a callout in this case, because: |
| 924 | // 1) With how the inventory is primed, there is no case where |
| 925 | // a location code is expected to be missing. This implies |
| 926 | // the caller is passing in something invalid. |
| 927 | // 2) The addDebugData call above will put the passed in path into |
| 928 | // a user data section that can be seen by development for debug. |
| 929 | // 3) Even if we wanted to do a 'no_vpd_for_fru' sort of maint. |
| 930 | // procedure, we don't have a good way to indicate to the user |
| 931 | // anything about the intended callout (they won't see user data). |
| 932 | // 4) Creating a new standalone event log for this problem isn't |
| 933 | // possible from inside a PEL section. |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 934 | } |
| 935 | |
Matt Spinler | 479b692 | 2021-08-17 16:34:59 -0500 | [diff] [blame] | 936 | if (callout) |
| 937 | { |
| 938 | createCalloutsObject(); |
| 939 | _callouts->addCallout(std::move(callout)); |
| 940 | } |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 941 | } |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 942 | |
Matt Spinler | f00f9d0 | 2020-10-23 09:14:22 -0500 | [diff] [blame] | 943 | std::vector<message::RegistryCallout> |
| 944 | SRC::getRegistryCallouts(const message::Entry& regEntry, |
| 945 | const AdditionalData& additionalData, |
| 946 | const DataInterfaceBase& dataIface) |
| 947 | { |
| 948 | std::vector<message::RegistryCallout> registryCallouts; |
| 949 | |
| 950 | if (regEntry.callouts) |
| 951 | { |
Matt Spinler | 9a50c8d | 2021-04-12 14:22:26 -0500 | [diff] [blame] | 952 | std::vector<std::string> systemNames; |
| 953 | |
Matt Spinler | f00f9d0 | 2020-10-23 09:14:22 -0500 | [diff] [blame] | 954 | try |
| 955 | { |
Matt Spinler | 9a50c8d | 2021-04-12 14:22:26 -0500 | [diff] [blame] | 956 | systemNames = dataIface.getSystemNames(); |
| 957 | } |
| 958 | catch (const std::exception& e) |
| 959 | { |
| 960 | // Compatible interface not available yet |
| 961 | } |
Matt Spinler | f00f9d0 | 2020-10-23 09:14:22 -0500 | [diff] [blame] | 962 | |
Matt Spinler | 9a50c8d | 2021-04-12 14:22:26 -0500 | [diff] [blame] | 963 | try |
| 964 | { |
Matt Spinler | f00f9d0 | 2020-10-23 09:14:22 -0500 | [diff] [blame] | 965 | registryCallouts = message::Registry::getCallouts( |
| 966 | regEntry.callouts.value(), systemNames, additionalData); |
| 967 | } |
| 968 | catch (const std::exception& e) |
| 969 | { |
Jayanth Othayoth | 1aa90d4 | 2023-09-13 04:25:45 -0500 | [diff] [blame] | 970 | addDebugData(std::format( |
Matt Spinler | f00f9d0 | 2020-10-23 09:14:22 -0500 | [diff] [blame] | 971 | "Error parsing PEL message registry callout JSON: {}", |
| 972 | e.what())); |
| 973 | } |
| 974 | } |
| 975 | |
| 976 | return registryCallouts; |
| 977 | } |
| 978 | |
| 979 | void SRC::addRegistryCallouts( |
| 980 | const std::vector<message::RegistryCallout>& callouts, |
| 981 | const DataInterfaceBase& dataIface, |
| 982 | std::optional<std::string> trustedSymbolicFRUInvPath) |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 983 | { |
| 984 | try |
| 985 | { |
Matt Spinler | f00f9d0 | 2020-10-23 09:14:22 -0500 | [diff] [blame] | 986 | for (const auto& callout : callouts) |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 987 | { |
Matt Spinler | f00f9d0 | 2020-10-23 09:14:22 -0500 | [diff] [blame] | 988 | addRegistryCallout(callout, dataIface, trustedSymbolicFRUInvPath); |
| 989 | |
| 990 | // Only the first callout gets the inventory path |
| 991 | if (trustedSymbolicFRUInvPath) |
| 992 | { |
| 993 | trustedSymbolicFRUInvPath = std::nullopt; |
| 994 | } |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 995 | } |
| 996 | } |
Patrick Williams | 66491c6 | 2021-10-06 12:23:37 -0500 | [diff] [blame] | 997 | catch (const std::exception& e) |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 998 | { |
Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 999 | std::string msg = "Error parsing PEL message registry callout JSON: "s + |
| 1000 | e.what(); |
Matt Spinler | 85f61a6 | 2020-06-03 16:28:55 -0500 | [diff] [blame] | 1001 | addDebugData(msg); |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 1002 | } |
| 1003 | } |
| 1004 | |
Matt Spinler | f00f9d0 | 2020-10-23 09:14:22 -0500 | [diff] [blame] | 1005 | void SRC::addRegistryCallout( |
| 1006 | const message::RegistryCallout& regCallout, |
| 1007 | const DataInterfaceBase& dataIface, |
| 1008 | const std::optional<std::string>& trustedSymbolicFRUInvPath) |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 1009 | { |
| 1010 | std::unique_ptr<src::Callout> callout; |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 1011 | auto locCode = regCallout.locCode; |
| 1012 | |
Matt Spinler | af191c7 | 2020-06-04 11:35:13 -0500 | [diff] [blame] | 1013 | if (!locCode.empty()) |
| 1014 | { |
| 1015 | try |
| 1016 | { |
| 1017 | locCode = dataIface.expandLocationCode(locCode, 0); |
| 1018 | } |
| 1019 | catch (const std::exception& e) |
| 1020 | { |
Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 1021 | auto msg = "Unable to expand location code " + locCode + ": " + |
| 1022 | e.what(); |
Matt Spinler | af191c7 | 2020-06-04 11:35:13 -0500 | [diff] [blame] | 1023 | addDebugData(msg); |
| 1024 | return; |
| 1025 | } |
| 1026 | } |
| 1027 | |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 1028 | // Via the PEL values table, get the priority enum. |
| 1029 | // The schema will have validated the priority was a valid value. |
Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 1030 | auto priorityIt = pv::findByName(regCallout.priority, |
| 1031 | pv::calloutPriorityValues); |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 1032 | assert(priorityIt != pv::calloutPriorityValues.end()); |
| 1033 | auto priority = |
| 1034 | static_cast<CalloutPriority>(std::get<pv::fieldValuePos>(*priorityIt)); |
| 1035 | |
| 1036 | if (!regCallout.procedure.empty()) |
| 1037 | { |
| 1038 | // Procedure callout |
Matt Spinler | 2edce4e | 2024-01-17 11:13:51 -0600 | [diff] [blame] | 1039 | callout = std::make_unique<src::Callout>(priority, regCallout.procedure, |
| 1040 | src::CalloutValueType::raw); |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 1041 | } |
| 1042 | else if (!regCallout.symbolicFRU.empty()) |
| 1043 | { |
| 1044 | // Symbolic FRU callout |
| 1045 | callout = std::make_unique<src::Callout>( |
| 1046 | priority, regCallout.symbolicFRU, locCode, false); |
| 1047 | } |
| 1048 | else if (!regCallout.symbolicFRUTrusted.empty()) |
| 1049 | { |
| 1050 | // Symbolic FRU with trusted location code callout |
| 1051 | |
Matt Spinler | f00f9d0 | 2020-10-23 09:14:22 -0500 | [diff] [blame] | 1052 | // Use the location code from the inventory path if there is one. |
| 1053 | if (trustedSymbolicFRUInvPath) |
| 1054 | { |
| 1055 | try |
| 1056 | { |
| 1057 | locCode = dataIface.getLocationCode(*trustedSymbolicFRUInvPath); |
| 1058 | } |
| 1059 | catch (const std::exception& e) |
| 1060 | { |
| 1061 | addDebugData( |
Jayanth Othayoth | 1aa90d4 | 2023-09-13 04:25:45 -0500 | [diff] [blame] | 1062 | std::format("Could not get location code for {}: {}", |
Matt Spinler | f00f9d0 | 2020-10-23 09:14:22 -0500 | [diff] [blame] | 1063 | *trustedSymbolicFRUInvPath, e.what())); |
| 1064 | locCode.clear(); |
| 1065 | } |
| 1066 | } |
| 1067 | |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 1068 | // The registry wants it to be trusted, but that requires a valid |
| 1069 | // location code for it to actually be. |
| 1070 | callout = std::make_unique<src::Callout>( |
| 1071 | priority, regCallout.symbolicFRUTrusted, locCode, !locCode.empty()); |
| 1072 | } |
| 1073 | else |
| 1074 | { |
Matt Spinler | af191c7 | 2020-06-04 11:35:13 -0500 | [diff] [blame] | 1075 | // A hardware callout |
Matt Spinler | bad056b | 2023-01-25 14:16:57 -0600 | [diff] [blame] | 1076 | std::vector<std::string> inventoryPaths; |
Matt Spinler | af191c7 | 2020-06-04 11:35:13 -0500 | [diff] [blame] | 1077 | |
| 1078 | try |
| 1079 | { |
| 1080 | // Get the inventory item from the unexpanded location code |
Matt Spinler | bad056b | 2023-01-25 14:16:57 -0600 | [diff] [blame] | 1081 | inventoryPaths = |
Matt Spinler | 2f9225a | 2020-08-05 12:58:49 -0500 | [diff] [blame] | 1082 | dataIface.getInventoryFromLocCode(regCallout.locCode, 0, false); |
Matt Spinler | af191c7 | 2020-06-04 11:35:13 -0500 | [diff] [blame] | 1083 | } |
| 1084 | catch (const std::exception& e) |
| 1085 | { |
| 1086 | std::string msg = |
| 1087 | "Unable to get inventory path from location code: " + locCode + |
| 1088 | ": " + e.what(); |
| 1089 | addDebugData(msg); |
| 1090 | return; |
| 1091 | } |
| 1092 | |
Matt Spinler | bad056b | 2023-01-25 14:16:57 -0600 | [diff] [blame] | 1093 | // Just use first path returned since they all point to the same FRU. |
| 1094 | addInventoryCallout(inventoryPaths[0], priority, locCode, dataIface); |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | if (callout) |
| 1098 | { |
| 1099 | createCalloutsObject(); |
| 1100 | _callouts->addCallout(std::move(callout)); |
| 1101 | } |
| 1102 | } |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 1103 | |
Matt Spinler | 717de42 | 2020-06-04 13:10:14 -0500 | [diff] [blame] | 1104 | void SRC::addDevicePathCallouts(const AdditionalData& additionalData, |
| 1105 | const DataInterfaceBase& dataIface) |
| 1106 | { |
| 1107 | std::vector<device_callouts::Callout> callouts; |
| 1108 | auto i2cBus = additionalData.getValue("CALLOUT_IIC_BUS"); |
| 1109 | auto i2cAddr = additionalData.getValue("CALLOUT_IIC_ADDR"); |
| 1110 | auto devPath = additionalData.getValue("CALLOUT_DEVICE_PATH"); |
| 1111 | |
| 1112 | // A device callout contains either: |
| 1113 | // * CALLOUT_ERRNO, CALLOUT_DEVICE_PATH |
| 1114 | // * CALLOUT_ERRNO, CALLOUT_IIC_BUS, CALLOUT_IIC_ADDR |
| 1115 | // We don't care about the errno. |
| 1116 | |
| 1117 | if (devPath) |
| 1118 | { |
| 1119 | try |
| 1120 | { |
| 1121 | callouts = device_callouts::getCallouts(*devPath, |
| 1122 | dataIface.getSystemNames()); |
| 1123 | } |
| 1124 | catch (const std::exception& e) |
| 1125 | { |
| 1126 | addDebugData(e.what()); |
| 1127 | callouts.clear(); |
| 1128 | } |
| 1129 | } |
| 1130 | else if (i2cBus && i2cAddr) |
| 1131 | { |
| 1132 | size_t bus; |
| 1133 | uint8_t address; |
| 1134 | |
| 1135 | try |
| 1136 | { |
| 1137 | // If /dev/i2c- is prepended, remove it |
| 1138 | if (i2cBus->find("/dev/i2c-") != std::string::npos) |
| 1139 | { |
| 1140 | *i2cBus = i2cBus->substr(9); |
| 1141 | } |
| 1142 | |
| 1143 | bus = stoul(*i2cBus, nullptr, 0); |
| 1144 | address = stoul(*i2cAddr, nullptr, 0); |
| 1145 | } |
| 1146 | catch (const std::exception& e) |
| 1147 | { |
| 1148 | std::string msg = "Invalid CALLOUT_IIC_BUS " + *i2cBus + |
| 1149 | " or CALLOUT_IIC_ADDR " + *i2cAddr + |
| 1150 | " in AdditionalData property"; |
| 1151 | addDebugData(msg); |
| 1152 | return; |
| 1153 | } |
| 1154 | |
| 1155 | try |
| 1156 | { |
| 1157 | callouts = device_callouts::getI2CCallouts( |
| 1158 | bus, address, dataIface.getSystemNames()); |
| 1159 | } |
| 1160 | catch (const std::exception& e) |
| 1161 | { |
| 1162 | addDebugData(e.what()); |
| 1163 | callouts.clear(); |
| 1164 | } |
| 1165 | } |
| 1166 | |
| 1167 | for (const auto& callout : callouts) |
| 1168 | { |
| 1169 | // The priority shouldn't be invalid, but check just in case. |
| 1170 | CalloutPriority priority = CalloutPriority::high; |
| 1171 | |
| 1172 | if (!callout.priority.empty()) |
| 1173 | { |
| 1174 | auto p = pel_values::findByValue( |
| 1175 | static_cast<uint32_t>(callout.priority[0]), |
| 1176 | pel_values::calloutPriorityValues); |
| 1177 | |
| 1178 | if (p != pel_values::calloutPriorityValues.end()) |
| 1179 | { |
| 1180 | priority = static_cast<CalloutPriority>(callout.priority[0]); |
| 1181 | } |
| 1182 | else |
| 1183 | { |
| 1184 | std::string msg = |
| 1185 | "Invalid priority found in dev callout JSON: " + |
| 1186 | callout.priority[0]; |
| 1187 | addDebugData(msg); |
| 1188 | } |
| 1189 | } |
| 1190 | |
Matt Spinler | 0d92b52 | 2021-06-16 13:28:17 -0600 | [diff] [blame] | 1191 | std::optional<std::string> locCode; |
| 1192 | |
| 1193 | try |
| 1194 | { |
| 1195 | locCode = dataIface.expandLocationCode(callout.locationCode, 0); |
| 1196 | } |
| 1197 | catch (const std::exception& e) |
| 1198 | { |
Jayanth Othayoth | 1aa90d4 | 2023-09-13 04:25:45 -0500 | [diff] [blame] | 1199 | auto msg = std::format("Unable to expand location code {}: {}", |
Matt Spinler | 0d92b52 | 2021-06-16 13:28:17 -0600 | [diff] [blame] | 1200 | callout.locationCode, e.what()); |
| 1201 | addDebugData(msg); |
| 1202 | } |
| 1203 | |
Matt Spinler | 717de42 | 2020-06-04 13:10:14 -0500 | [diff] [blame] | 1204 | try |
| 1205 | { |
Matt Spinler | bad056b | 2023-01-25 14:16:57 -0600 | [diff] [blame] | 1206 | auto inventoryPaths = dataIface.getInventoryFromLocCode( |
Matt Spinler | 2f9225a | 2020-08-05 12:58:49 -0500 | [diff] [blame] | 1207 | callout.locationCode, 0, false); |
Matt Spinler | 717de42 | 2020-06-04 13:10:14 -0500 | [diff] [blame] | 1208 | |
Matt Spinler | bad056b | 2023-01-25 14:16:57 -0600 | [diff] [blame] | 1209 | // Just use first path returned since they all |
| 1210 | // point to the same FRU. |
| 1211 | addInventoryCallout(inventoryPaths[0], priority, locCode, |
| 1212 | dataIface); |
Matt Spinler | 717de42 | 2020-06-04 13:10:14 -0500 | [diff] [blame] | 1213 | } |
| 1214 | catch (const std::exception& e) |
| 1215 | { |
| 1216 | std::string msg = |
| 1217 | "Unable to get inventory path from location code: " + |
| 1218 | callout.locationCode + ": " + e.what(); |
| 1219 | addDebugData(msg); |
| 1220 | } |
| 1221 | |
| 1222 | // Until the code is there to convert these MRU value strings to |
| 1223 | // the official MRU values in the callout objects, just store |
| 1224 | // the MRU name in the debug UserData section. |
| 1225 | if (!callout.mru.empty()) |
| 1226 | { |
| 1227 | std::string msg = "MRU: " + callout.mru; |
| 1228 | addDebugData(msg); |
| 1229 | } |
| 1230 | |
| 1231 | // getCallouts() may have generated some debug data it stored |
| 1232 | // in a callout object. Save it as well. |
| 1233 | if (!callout.debug.empty()) |
| 1234 | { |
| 1235 | addDebugData(callout.debug); |
| 1236 | } |
| 1237 | } |
| 1238 | } |
| 1239 | |
Matt Spinler | 5a90a95 | 2020-08-27 09:39:03 -0500 | [diff] [blame] | 1240 | void SRC::addJSONCallouts(const nlohmann::json& jsonCallouts, |
| 1241 | const DataInterfaceBase& dataIface) |
| 1242 | { |
| 1243 | if (jsonCallouts.empty()) |
| 1244 | { |
| 1245 | return; |
| 1246 | } |
| 1247 | |
| 1248 | if (!jsonCallouts.is_array()) |
| 1249 | { |
| 1250 | addDebugData("Callout JSON isn't an array"); |
| 1251 | return; |
| 1252 | } |
| 1253 | |
| 1254 | for (const auto& callout : jsonCallouts) |
| 1255 | { |
| 1256 | try |
| 1257 | { |
| 1258 | addJSONCallout(callout, dataIface); |
| 1259 | } |
| 1260 | catch (const std::exception& e) |
| 1261 | { |
Jayanth Othayoth | 1aa90d4 | 2023-09-13 04:25:45 -0500 | [diff] [blame] | 1262 | addDebugData(std::format( |
Matt Spinler | 5a90a95 | 2020-08-27 09:39:03 -0500 | [diff] [blame] | 1263 | "Failed extracting callout data from JSON: {}", e.what())); |
| 1264 | } |
| 1265 | } |
| 1266 | } |
| 1267 | |
| 1268 | void SRC::addJSONCallout(const nlohmann::json& jsonCallout, |
| 1269 | const DataInterfaceBase& dataIface) |
| 1270 | { |
Matt Spinler | 3bdd011 | 2020-08-27 10:24:34 -0500 | [diff] [blame] | 1271 | auto priority = getPriorityFromJSON(jsonCallout); |
| 1272 | std::string locCode; |
| 1273 | std::string unexpandedLocCode; |
| 1274 | std::unique_ptr<src::Callout> callout; |
| 1275 | |
| 1276 | // Expand the location code if it's there |
| 1277 | if (jsonCallout.contains("LocationCode")) |
| 1278 | { |
| 1279 | unexpandedLocCode = jsonCallout.at("LocationCode").get<std::string>(); |
| 1280 | |
| 1281 | try |
| 1282 | { |
| 1283 | locCode = dataIface.expandLocationCode(unexpandedLocCode, 0); |
| 1284 | } |
| 1285 | catch (const std::exception& e) |
| 1286 | { |
Jayanth Othayoth | 1aa90d4 | 2023-09-13 04:25:45 -0500 | [diff] [blame] | 1287 | addDebugData(std::format("Unable to expand location code {}: {}", |
Matt Spinler | 3bdd011 | 2020-08-27 10:24:34 -0500 | [diff] [blame] | 1288 | unexpandedLocCode, e.what())); |
| 1289 | // Use the value from the JSON so at least there's something |
| 1290 | locCode = unexpandedLocCode; |
| 1291 | } |
| 1292 | } |
| 1293 | |
| 1294 | // Create either a procedure, symbolic FRU, or normal FRU callout. |
| 1295 | if (jsonCallout.contains("Procedure")) |
| 1296 | { |
| 1297 | auto procedure = jsonCallout.at("Procedure").get<std::string>(); |
| 1298 | |
Matt Spinler | 3c7ec6d | 2022-05-06 08:50:20 -0500 | [diff] [blame] | 1299 | // If it's the registry name instead of the raw name, convert. |
| 1300 | if (pv::maintenanceProcedures.find(procedure) != |
| 1301 | pv::maintenanceProcedures.end()) |
| 1302 | { |
| 1303 | procedure = pv::maintenanceProcedures.at(procedure); |
| 1304 | } |
| 1305 | |
Matt Spinler | 3bdd011 | 2020-08-27 10:24:34 -0500 | [diff] [blame] | 1306 | callout = std::make_unique<src::Callout>( |
| 1307 | static_cast<CalloutPriority>(priority), procedure, |
| 1308 | src::CalloutValueType::raw); |
| 1309 | } |
| 1310 | else if (jsonCallout.contains("SymbolicFRU")) |
| 1311 | { |
| 1312 | auto fru = jsonCallout.at("SymbolicFRU").get<std::string>(); |
| 1313 | |
Matt Spinler | 3c7ec6d | 2022-05-06 08:50:20 -0500 | [diff] [blame] | 1314 | // If it's the registry name instead of the raw name, convert. |
| 1315 | if (pv::symbolicFRUs.find(fru) != pv::symbolicFRUs.end()) |
| 1316 | { |
| 1317 | fru = pv::symbolicFRUs.at(fru); |
| 1318 | } |
| 1319 | |
Matt Spinler | 3bdd011 | 2020-08-27 10:24:34 -0500 | [diff] [blame] | 1320 | bool trusted = false; |
| 1321 | if (jsonCallout.contains("TrustedLocationCode") && !locCode.empty()) |
| 1322 | { |
| 1323 | trusted = jsonCallout.at("TrustedLocationCode").get<bool>(); |
| 1324 | } |
| 1325 | |
| 1326 | callout = std::make_unique<src::Callout>( |
| 1327 | static_cast<CalloutPriority>(priority), fru, |
| 1328 | src::CalloutValueType::raw, locCode, trusted); |
| 1329 | } |
| 1330 | else |
| 1331 | { |
| 1332 | // A hardware FRU |
| 1333 | std::string inventoryPath; |
Matt Spinler | b8cb60f | 2020-08-27 10:55:55 -0500 | [diff] [blame] | 1334 | std::vector<src::MRU::MRUCallout> mrus; |
Matt Spinler | 3bdd011 | 2020-08-27 10:24:34 -0500 | [diff] [blame] | 1335 | |
| 1336 | if (jsonCallout.contains("InventoryPath")) |
| 1337 | { |
| 1338 | inventoryPath = jsonCallout.at("InventoryPath").get<std::string>(); |
| 1339 | } |
| 1340 | else |
| 1341 | { |
| 1342 | if (unexpandedLocCode.empty()) |
| 1343 | { |
| 1344 | throw std::runtime_error{"JSON callout needs either an " |
| 1345 | "inventory path or location code"}; |
| 1346 | } |
| 1347 | |
| 1348 | try |
| 1349 | { |
Matt Spinler | bad056b | 2023-01-25 14:16:57 -0600 | [diff] [blame] | 1350 | auto inventoryPaths = dataIface.getInventoryFromLocCode( |
Matt Spinler | 3bdd011 | 2020-08-27 10:24:34 -0500 | [diff] [blame] | 1351 | unexpandedLocCode, 0, false); |
Matt Spinler | bad056b | 2023-01-25 14:16:57 -0600 | [diff] [blame] | 1352 | // Just use first path returned since they all |
| 1353 | // point to the same FRU. |
| 1354 | inventoryPath = inventoryPaths[0]; |
Matt Spinler | 3bdd011 | 2020-08-27 10:24:34 -0500 | [diff] [blame] | 1355 | } |
| 1356 | catch (const std::exception& e) |
| 1357 | { |
| 1358 | throw std::runtime_error{ |
Jayanth Othayoth | 1aa90d4 | 2023-09-13 04:25:45 -0500 | [diff] [blame] | 1359 | std::format("Unable to get inventory path from " |
Matt Spinler | 3bdd011 | 2020-08-27 10:24:34 -0500 | [diff] [blame] | 1360 | "location code: {}: {}", |
| 1361 | unexpandedLocCode, e.what())}; |
| 1362 | } |
| 1363 | } |
| 1364 | |
Matt Spinler | b8cb60f | 2020-08-27 10:55:55 -0500 | [diff] [blame] | 1365 | if (jsonCallout.contains("MRUs")) |
| 1366 | { |
| 1367 | mrus = getMRUsFromJSON(jsonCallout.at("MRUs")); |
| 1368 | } |
| 1369 | |
Matt Spinler | 3bdd011 | 2020-08-27 10:24:34 -0500 | [diff] [blame] | 1370 | // If the location code was also passed in, use that here too |
| 1371 | // so addInventoryCallout doesn't have to look it up. |
| 1372 | std::optional<std::string> lc; |
| 1373 | if (!locCode.empty()) |
| 1374 | { |
| 1375 | lc = locCode; |
| 1376 | } |
| 1377 | |
Matt Spinler | b8cb60f | 2020-08-27 10:55:55 -0500 | [diff] [blame] | 1378 | addInventoryCallout(inventoryPath, priority, lc, dataIface, mrus); |
Matt Spinler | afa2c79 | 2020-08-27 11:01:39 -0500 | [diff] [blame] | 1379 | |
| 1380 | if (jsonCallout.contains("Deconfigured")) |
| 1381 | { |
| 1382 | if (jsonCallout.at("Deconfigured").get<bool>()) |
| 1383 | { |
| 1384 | setErrorStatusFlag(ErrorStatusFlags::deconfigured); |
| 1385 | } |
| 1386 | } |
| 1387 | |
| 1388 | if (jsonCallout.contains("Guarded")) |
| 1389 | { |
| 1390 | if (jsonCallout.at("Guarded").get<bool>()) |
| 1391 | { |
| 1392 | setErrorStatusFlag(ErrorStatusFlags::guarded); |
| 1393 | } |
| 1394 | } |
Matt Spinler | 3bdd011 | 2020-08-27 10:24:34 -0500 | [diff] [blame] | 1395 | } |
| 1396 | |
| 1397 | if (callout) |
| 1398 | { |
| 1399 | createCalloutsObject(); |
| 1400 | _callouts->addCallout(std::move(callout)); |
| 1401 | } |
| 1402 | } |
| 1403 | |
| 1404 | CalloutPriority SRC::getPriorityFromJSON(const nlohmann::json& json) |
| 1405 | { |
| 1406 | // Looks like: |
| 1407 | // { |
| 1408 | // "Priority": "H" |
| 1409 | // } |
| 1410 | auto p = json.at("Priority").get<std::string>(); |
| 1411 | if (p.empty()) |
| 1412 | { |
| 1413 | throw std::runtime_error{"Priority field in callout is empty"}; |
| 1414 | } |
| 1415 | |
| 1416 | auto priority = static_cast<CalloutPriority>(p.front()); |
| 1417 | |
| 1418 | // Validate it |
| 1419 | auto priorityIt = pv::findByValue(static_cast<uint32_t>(priority), |
| 1420 | pv::calloutPriorityValues); |
| 1421 | if (priorityIt == pv::calloutPriorityValues.end()) |
| 1422 | { |
| 1423 | throw std::runtime_error{ |
Jayanth Othayoth | 1aa90d4 | 2023-09-13 04:25:45 -0500 | [diff] [blame] | 1424 | std::format("Invalid priority '{}' found in JSON callout", p)}; |
Matt Spinler | 3bdd011 | 2020-08-27 10:24:34 -0500 | [diff] [blame] | 1425 | } |
| 1426 | |
| 1427 | return priority; |
Matt Spinler | 5a90a95 | 2020-08-27 09:39:03 -0500 | [diff] [blame] | 1428 | } |
| 1429 | |
Matt Spinler | b8cb60f | 2020-08-27 10:55:55 -0500 | [diff] [blame] | 1430 | std::vector<src::MRU::MRUCallout> |
| 1431 | SRC::getMRUsFromJSON(const nlohmann::json& mruJSON) |
| 1432 | { |
| 1433 | std::vector<src::MRU::MRUCallout> mrus; |
| 1434 | |
| 1435 | // Looks like: |
| 1436 | // [ |
| 1437 | // { |
| 1438 | // "ID": 100, |
| 1439 | // "Priority": "H" |
| 1440 | // } |
| 1441 | // ] |
| 1442 | if (!mruJSON.is_array()) |
| 1443 | { |
| 1444 | addDebugData("MRU callout JSON is not an array"); |
| 1445 | return mrus; |
| 1446 | } |
| 1447 | |
| 1448 | for (const auto& mruCallout : mruJSON) |
| 1449 | { |
| 1450 | try |
| 1451 | { |
| 1452 | auto priority = getPriorityFromJSON(mruCallout); |
| 1453 | auto id = mruCallout.at("ID").get<uint32_t>(); |
| 1454 | |
| 1455 | src::MRU::MRUCallout mru{static_cast<uint32_t>(priority), id}; |
| 1456 | mrus.push_back(std::move(mru)); |
| 1457 | } |
| 1458 | catch (const std::exception& e) |
| 1459 | { |
Jayanth Othayoth | 1aa90d4 | 2023-09-13 04:25:45 -0500 | [diff] [blame] | 1460 | addDebugData(std::format("Invalid MRU entry in JSON: {}: {}", |
Matt Spinler | b8cb60f | 2020-08-27 10:55:55 -0500 | [diff] [blame] | 1461 | mruCallout.dump(), e.what())); |
| 1462 | } |
| 1463 | } |
| 1464 | |
| 1465 | return mrus; |
| 1466 | } |
| 1467 | |
Sumit Kumar | 9d43a72 | 2021-08-24 09:46:19 -0500 | [diff] [blame] | 1468 | void SRC::setDumpStatus(const DataInterfaceBase& dataIface) |
| 1469 | { |
| 1470 | std::vector<bool> dumpStatus{false, false, false}; |
| 1471 | |
| 1472 | try |
| 1473 | { |
| 1474 | std::vector<std::string> dumpType = {"bmc/entry", "resource/entry", |
| 1475 | "system/entry"}; |
| 1476 | dumpStatus = dataIface.checkDumpStatus(dumpType); |
| 1477 | |
| 1478 | // For bmc - set bit 0 of nibble [4-7] bits of byte-1 SP dump |
| 1479 | // For resource - set bit 2 of nibble [4-7] bits of byte-2 Hypervisor |
| 1480 | // For system - set bit 1 of nibble [4-7] bits of byte-2 HW dump |
| 1481 | _hexData[0] |= ((dumpStatus[0] << 19) | (dumpStatus[1] << 9) | |
| 1482 | (dumpStatus[2] << 10)); |
| 1483 | } |
| 1484 | catch (const std::exception& e) |
| 1485 | { |
Matt Spinler | 0bacc8e | 2023-07-07 16:25:39 -0500 | [diff] [blame] | 1486 | lg2::error("Checking dump status failed: {ERROR}", "ERROR", e); |
Sumit Kumar | 9d43a72 | 2021-08-24 09:46:19 -0500 | [diff] [blame] | 1487 | } |
| 1488 | } |
| 1489 | |
Sumit Kumar | 3e27443 | 2021-09-14 06:37:56 -0500 | [diff] [blame] | 1490 | std::vector<uint8_t> SRC::getSrcStruct() |
| 1491 | { |
| 1492 | std::vector<uint8_t> data; |
| 1493 | Stream stream{data}; |
| 1494 | |
| 1495 | //------ Ref section 4.3 in PEL doc--- |
| 1496 | //------ SRC Structure 40 bytes------- |
| 1497 | // Byte-0 | Byte-1 | Byte-2 | Byte-3 | |
| 1498 | // ----------------------------------- |
| 1499 | // 02 | 08 | 00 | 09 | ==> Header |
| 1500 | // 00 | 00 | 00 | 48 | ==> Header |
| 1501 | // 00 | 00 | 00 | 00 | ==> Hex data word-2 |
| 1502 | // 00 | 00 | 00 | 00 | ==> Hex data word-3 |
| 1503 | // 00 | 00 | 00 | 00 | ==> Hex data word-4 |
| 1504 | // 20 | 00 | 00 | 00 | ==> Hex data word-5 |
| 1505 | // 00 | 00 | 00 | 00 | ==> Hex data word-6 |
| 1506 | // 00 | 00 | 00 | 00 | ==> Hex data word-7 |
| 1507 | // 00 | 00 | 00 | 00 | ==> Hex data word-8 |
| 1508 | // 00 | 00 | 00 | 00 | ==> Hex data word-9 |
| 1509 | // ----------------------------------- |
| 1510 | // ASCII string - 8 bytes | |
| 1511 | // ----------------------------------- |
| 1512 | // ASCII space NULL - 24 bytes | |
| 1513 | // ----------------------------------- |
| 1514 | //_size = Base SRC struct: 8 byte header + hex data section + ASCII string |
| 1515 | |
| 1516 | uint8_t flags = (_flags | postOPPanel); |
| 1517 | |
| 1518 | stream << _version << flags << _reserved1B << _wordCount << _reserved2B |
| 1519 | << _size; |
| 1520 | |
| 1521 | for (auto& word : _hexData) |
| 1522 | { |
| 1523 | stream << word; |
| 1524 | } |
| 1525 | |
| 1526 | _asciiString->flatten(stream); |
| 1527 | |
| 1528 | return data; |
| 1529 | } |
| 1530 | |
Vijay Lobo | 875b6c7 | 2021-10-20 17:38:56 -0500 | [diff] [blame] | 1531 | void SRC::setProgressCode(const DataInterfaceBase& dataIface) |
| 1532 | { |
| 1533 | std::vector<uint8_t> progressSRC; |
| 1534 | |
| 1535 | try |
| 1536 | { |
| 1537 | progressSRC = dataIface.getRawProgressSRC(); |
| 1538 | } |
| 1539 | catch (const std::exception& e) |
| 1540 | { |
Matt Spinler | 0bacc8e | 2023-07-07 16:25:39 -0500 | [diff] [blame] | 1541 | lg2::error("Error getting progress code: {ERROR}", "ERROR", e); |
Vijay Lobo | 875b6c7 | 2021-10-20 17:38:56 -0500 | [diff] [blame] | 1542 | return; |
| 1543 | } |
| 1544 | |
| 1545 | _hexData[2] = getProgressCode(progressSRC); |
| 1546 | } |
| 1547 | |
| 1548 | uint32_t SRC::getProgressCode(std::vector<uint8_t>& rawProgressSRC) |
| 1549 | { |
| 1550 | uint32_t progressCode = 0; |
| 1551 | |
| 1552 | // A valid progress SRC is at least 72 bytes |
| 1553 | if (rawProgressSRC.size() < 72) |
| 1554 | { |
| 1555 | return progressCode; |
| 1556 | } |
| 1557 | |
| 1558 | try |
| 1559 | { |
| 1560 | // The ASCII string field in progress SRCs starts at offset 40. |
| 1561 | // Take the first 8 characters to put in the uint32: |
| 1562 | // "CC009189" -> 0xCC009189 |
| 1563 | Stream stream{rawProgressSRC, 40}; |
| 1564 | src::AsciiString aString{stream}; |
| 1565 | auto progressCodeString = aString.get().substr(0, 8); |
| 1566 | |
| 1567 | if (std::all_of(progressCodeString.begin(), progressCodeString.end(), |
| 1568 | [](char c) { |
Patrick Williams | ac1ba3f | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 1569 | return std::isxdigit(static_cast<unsigned char>(c)); |
Patrick Williams | 5fb575a | 2023-10-20 11:18:21 -0500 | [diff] [blame] | 1570 | })) |
Vijay Lobo | 875b6c7 | 2021-10-20 17:38:56 -0500 | [diff] [blame] | 1571 | { |
| 1572 | progressCode = std::stoul(progressCodeString, nullptr, 16); |
| 1573 | } |
| 1574 | } |
| 1575 | catch (const std::exception& e) |
| 1576 | {} |
| 1577 | |
| 1578 | return progressCode; |
| 1579 | } |
| 1580 | |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 1581 | } // namespace pels |
| 1582 | } // namespace openpower |