| Anupama B R | b5bfcbc | 2025-03-03 03:00:04 -0600 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
| Anupama B R | 08fa59e | 2025-03-06 22:55:11 -0600 | [diff] [blame] | 3 | #include "single_fab.hpp" |
| 4 | |
| 5 | #include "constants.hpp" |
| Rekha Aparna | 5702229 | 2025-11-25 04:20:41 -0600 | [diff] [blame] | 6 | #include "logger.hpp" |
| RekhaAparna01 | d3e693e | 2025-03-04 05:08:30 -0600 | [diff] [blame] | 7 | #include "parser.hpp" |
| Anupama B R | 08fa59e | 2025-03-06 22:55:11 -0600 | [diff] [blame] | 8 | #include "types.hpp" |
| 9 | |
| RekhaAparna01 | d3e693e | 2025-03-04 05:08:30 -0600 | [diff] [blame] | 10 | #include <nlohmann/json.hpp> |
| RekhaAparna01 | f05f354 | 2025-03-02 22:25:23 -0600 | [diff] [blame] | 11 | #include <utility/common_utility.hpp> |
| Rekha Aparna | a39aafa | 2025-11-04 00:06:12 -0600 | [diff] [blame] | 12 | #include <utility/event_logger_utility.hpp> |
| Anupama B R | 08fa59e | 2025-03-06 22:55:11 -0600 | [diff] [blame] | 13 | #include <utility/json_utility.hpp> |
| Rekha Aparna | ffdff31 | 2025-03-25 01:10:56 -0500 | [diff] [blame] | 14 | #include <utility/vpd_specific_utility.hpp> |
| Anupama B R | 08fa59e | 2025-03-06 22:55:11 -0600 | [diff] [blame] | 15 | |
| 16 | namespace vpd |
| 17 | { |
| 18 | constexpr auto pimPersistVsbpPath = |
| 19 | "/var/lib/phosphor-inventory-manager/xyz/openbmc_project/inventory/system/chassis/motherboard/com.ibm.ipzvpd.VSBP"; |
| Anupama B R | b5bfcbc | 2025-03-03 03:00:04 -0600 | [diff] [blame] | 20 | constexpr auto IM_SIZE_IN_BYTES = 0x04; |
| 21 | constexpr auto IM_KW_VALUE_OFFSET = 0x000005fb; |
| Anupama B R | 08fa59e | 2025-03-06 22:55:11 -0600 | [diff] [blame] | 22 | |
| 23 | std::string SingleFab::getImFromPersistedLocation() const noexcept |
| 24 | { |
| 25 | try |
| 26 | { |
| Rekha Aparna | ca9a086 | 2025-08-29 04:08:33 -0500 | [diff] [blame] | 27 | uint16_t l_errCode = 0; |
| Anupama B R | 08fa59e | 2025-03-06 22:55:11 -0600 | [diff] [blame] | 28 | auto l_parsedVsbpJsonObj = |
| Rekha Aparna | ca9a086 | 2025-08-29 04:08:33 -0500 | [diff] [blame] | 29 | jsonUtility::getParsedJson(pimPersistVsbpPath, l_errCode); |
| 30 | |
| 31 | if (l_errCode) |
| 32 | { |
| 33 | throw JsonException( |
| 34 | "Failed to parse JSON file [ " + |
| Rekha Aparna | c6159a2 | 2025-10-09 12:20:20 +0530 | [diff] [blame] | 35 | std::string(pimPersistVsbpPath) + |
| 36 | " ], error : " + commonUtility::getErrCodeMsg(l_errCode), |
| Rekha Aparna | ca9a086 | 2025-08-29 04:08:33 -0500 | [diff] [blame] | 37 | pimPersistVsbpPath); |
| 38 | } |
| 39 | |
| Anupama B R | 08fa59e | 2025-03-06 22:55:11 -0600 | [diff] [blame] | 40 | if (!l_parsedVsbpJsonObj.contains("value0") || |
| 41 | !l_parsedVsbpJsonObj["value0"].contains(constants::kwdIM) || |
| 42 | !l_parsedVsbpJsonObj["value0"][constants::kwdIM].is_array()) |
| 43 | { |
| Rekha Aparna | ca9a086 | 2025-08-29 04:08:33 -0500 | [diff] [blame] | 44 | throw std::runtime_error("Mandatory tag(s) missing from JSON"); |
| Anupama B R | 08fa59e | 2025-03-06 22:55:11 -0600 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | const types::BinaryVector l_imValue = |
| 48 | l_parsedVsbpJsonObj["value0"][constants::kwdIM] |
| 49 | .get<types::BinaryVector>(); |
| 50 | |
| 51 | std::ostringstream l_imData; |
| 52 | for (const auto& l_byte : l_imValue) |
| 53 | { |
| 54 | l_imData << std::setw(2) << std::setfill('0') << std::hex |
| 55 | << static_cast<int>(l_byte); |
| 56 | } |
| 57 | return l_imData.str(); |
| 58 | } |
| 59 | catch (const std::exception& l_ex) |
| RekhaAparna01 | d3e693e | 2025-03-04 05:08:30 -0600 | [diff] [blame] | 60 | {} |
| Anupama B R | 08fa59e | 2025-03-06 22:55:11 -0600 | [diff] [blame] | 61 | |
| 62 | return std::string(); |
| 63 | } |
| Anupama B R | b5bfcbc | 2025-03-03 03:00:04 -0600 | [diff] [blame] | 64 | |
| 65 | std::string SingleFab::getImFromPlanar() const noexcept |
| 66 | { |
| 67 | try |
| 68 | { |
| Anupama B R | e2f09be | 2025-04-08 04:41:28 -0500 | [diff] [blame] | 69 | const std::string l_systemPlanarPath(SYSTEM_VPD_FILE_PATH); |
| 70 | Parser l_parserObj(l_systemPlanarPath, nlohmann::json{}); |
| Anupama B R | b5bfcbc | 2025-03-03 03:00:04 -0600 | [diff] [blame] | 71 | |
| Anupama B R | e2f09be | 2025-04-08 04:41:28 -0500 | [diff] [blame] | 72 | std::shared_ptr<ParserInterface> l_vpdParserInstance = |
| 73 | l_parserObj.getVpdParserInstance(); |
| Anupama B R | b5bfcbc | 2025-03-03 03:00:04 -0600 | [diff] [blame] | 74 | |
| Anupama B R | e2f09be | 2025-04-08 04:41:28 -0500 | [diff] [blame] | 75 | auto l_readValue = l_vpdParserInstance->readKeywordFromHardware( |
| 76 | std::make_tuple(constants::recVSBP, constants::kwdIM)); |
| Anupama B R | b5bfcbc | 2025-03-03 03:00:04 -0600 | [diff] [blame] | 77 | |
| Anupama B R | e2f09be | 2025-04-08 04:41:28 -0500 | [diff] [blame] | 78 | if (auto l_keywordValue = |
| 79 | std::get_if<types::BinaryVector>(&l_readValue); |
| 80 | l_keywordValue && !l_keywordValue->empty()) |
| Anupama B R | b5bfcbc | 2025-03-03 03:00:04 -0600 | [diff] [blame] | 81 | { |
| Anupama B R | e2f09be | 2025-04-08 04:41:28 -0500 | [diff] [blame] | 82 | std::ostringstream l_imData; |
| 83 | for (const auto& l_byte : *l_keywordValue) |
| 84 | { |
| 85 | l_imData << std::setw(2) << std::setfill('0') << std::hex |
| 86 | << static_cast<int>(l_byte); |
| 87 | } |
| 88 | |
| 89 | return l_imData.str(); |
| Anupama B R | b5bfcbc | 2025-03-03 03:00:04 -0600 | [diff] [blame] | 90 | } |
| Anupama B R | b5bfcbc | 2025-03-03 03:00:04 -0600 | [diff] [blame] | 91 | } |
| 92 | catch (const std::ifstream::failure& l_ex) |
| 93 | {} |
| 94 | |
| 95 | return std::string(); |
| 96 | } |
| RekhaAparna01 | d3e693e | 2025-03-04 05:08:30 -0600 | [diff] [blame] | 97 | |
| 98 | bool SingleFab::setImOnPlanar(const std::string& i_imValue) const noexcept |
| 99 | { |
| 100 | try |
| 101 | { |
| 102 | types::BinaryVector l_imValue; |
| 103 | const std::string l_systemPlanarEepromPath = SYSTEM_VPD_FILE_PATH; |
| 104 | |
| 105 | // Convert string to vector of bytes |
| 106 | for (auto l_value : i_imValue | std::views::chunk(2)) |
| 107 | { |
| 108 | std::string l_byteString(l_value.begin(), l_value.end()); |
| 109 | l_imValue.push_back( |
| 110 | static_cast<uint8_t>(std::stoi(l_byteString, nullptr, 16))); |
| 111 | } |
| 112 | |
| 113 | std::shared_ptr<Parser> l_parserObj = std::make_shared<Parser>( |
| 114 | l_systemPlanarEepromPath, nlohmann::json{}); |
| 115 | |
| 116 | int l_bytes_updated = l_parserObj->updateVpdKeywordOnHardware( |
| 117 | std::make_tuple(constants::recVSBP, constants::kwdIM, l_imValue)); |
| 118 | |
| 119 | return l_bytes_updated > 0 ? true : false; |
| 120 | } |
| 121 | catch (const std::exception& l_ex) |
| 122 | { |
| 123 | return false; |
| 124 | } |
| 125 | } |
| RekhaAparna01 | f05f354 | 2025-03-02 22:25:23 -0600 | [diff] [blame] | 126 | |
| Rekha Aparna | ffdff31 | 2025-03-25 01:10:56 -0500 | [diff] [blame] | 127 | void SingleFab::updateSystemImValueInVpdToP11Series( |
| Souvik Roy | cd828d4 | 2025-03-24 02:29:45 -0500 | [diff] [blame] | 128 | std::string i_currentImValuePlanar) const noexcept |
| 129 | { |
| 130 | bool l_retVal{false}; |
| 131 | if (!i_currentImValuePlanar.empty()) |
| 132 | { |
| Anupama B R | 879d465 | 2025-04-21 04:19:02 -0500 | [diff] [blame] | 133 | if (i_currentImValuePlanar.compare( |
| 134 | constants::VALUE_4, constants::VALUE_1, |
| 135 | std::to_string(constants::VALUE_3)) == |
| 136 | constants::STR_CMP_SUCCESS) |
| 137 | { |
| 138 | i_currentImValuePlanar.replace(constants::VALUE_4, |
| 139 | constants::VALUE_1, |
| 140 | std::to_string(constants::VALUE_2)); |
| 141 | } |
| 142 | |
| Souvik Roy | cd828d4 | 2025-03-24 02:29:45 -0500 | [diff] [blame] | 143 | // update the IM value to P11 series(6000x). Replace the first character |
| 144 | // of IM value string with '6' |
| 145 | l_retVal = setImOnPlanar(i_currentImValuePlanar.replace( |
| 146 | constants::VALUE_0, constants::VALUE_1, |
| 147 | std::to_string(constants::VALUE_6))); |
| 148 | } |
| Rekha Aparna | ffdff31 | 2025-03-25 01:10:56 -0500 | [diff] [blame] | 149 | |
| 150 | if (!l_retVal) |
| 151 | { |
| 152 | EventLogger::createSyncPel( |
| 153 | types::ErrorType::InternalFailure, |
| 154 | types::SeverityType::Informational, __FILE__, __FUNCTION__, 0, |
| 155 | std::string("Failed to update IM value to P11 series."), |
| 156 | std::nullopt, std::nullopt, std::nullopt, std::nullopt); |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | int SingleFab::singleFabImOverride() const noexcept |
| 161 | { |
| Rekha Aparna | 5702229 | 2025-11-25 04:20:41 -0600 | [diff] [blame] | 162 | uint16_t l_errCode = 0; |
| Rekha Aparna | ffdff31 | 2025-03-25 01:10:56 -0500 | [diff] [blame] | 163 | const std::string& l_planarImValue = getImFromPlanar(); |
| 164 | const std::string& l_eBmcImValue = getImFromPersistedLocation(); |
| Rekha Aparna | 5702229 | 2025-11-25 04:20:41 -0600 | [diff] [blame] | 165 | const bool& l_isFieldModeEnabled = |
| 166 | commonUtility::isFieldModeEnabled(l_errCode); |
| 167 | |
| 168 | if (l_errCode) |
| 169 | { |
| 170 | Logger::getLoggerInstance()->logMessage( |
| 171 | "Failed to check is field mode enabled, error : " + |
| 172 | commonUtility::getErrCodeMsg(l_errCode)); |
| 173 | } |
| 174 | |
| Rekha Aparna | ffdff31 | 2025-03-25 01:10:56 -0500 | [diff] [blame] | 175 | const bool& l_isLabModeEnabled = |
| 176 | !l_isFieldModeEnabled; // used for understanding |
| 177 | const bool& l_isPowerVsImage = vpdSpecificUtility::isPowerVsImage(); |
| 178 | const bool& l_isNormalImage = !l_isPowerVsImage; // used for understanding |
| 179 | |
| 180 | if (!isValidImSeries(l_planarImValue)) |
| 181 | { |
| 182 | // Create Errorlog for invalid IM series encountered |
| 183 | EventLogger::createSyncPel( |
| 184 | types::ErrorType::InvalidSystem, types::SeverityType::Error, |
| 185 | __FILE__, __FUNCTION__, 0, |
| 186 | std::string("Invalid IM found on the system planar, IM value : ") + |
| 187 | l_planarImValue, |
| 188 | std::nullopt, std::nullopt, std::nullopt, std::nullopt); |
| 189 | |
| 190 | return constants::SUCCESS; |
| 191 | } |
| 192 | |
| 193 | if (!l_eBmcImValue.empty()) |
| 194 | { |
| 195 | if (isP10System(l_eBmcImValue)) |
| 196 | { |
| 197 | if (isP10System(l_planarImValue)) |
| 198 | { |
| 199 | if (l_isFieldModeEnabled && l_isNormalImage) |
| 200 | { |
| 201 | EventLogger::createSyncPel( |
| 202 | types::ErrorType::SystemTypeMismatch, |
| 203 | types::SeverityType::Warning, __FILE__, __FUNCTION__, 0, |
| 204 | std::string("Mismatch in IM value found eBMC IM [") + |
| 205 | l_eBmcImValue + std::string("] planar IM [") + |
| 206 | l_planarImValue + |
| 207 | std::string("] Field mode enabled [") + |
| 208 | ((l_isFieldModeEnabled) ? "true" : "false") + |
| 209 | std::string("]"), |
| 210 | std::nullopt, std::nullopt, std::nullopt, std::nullopt); |
| 211 | |
| 212 | return constants::FAILURE; |
| 213 | } |
| 214 | } |
| 215 | else if (isP11System(l_planarImValue)) |
| 216 | { |
| 217 | if (!(l_isLabModeEnabled && l_isNormalImage)) |
| 218 | { |
| 219 | EventLogger::createSyncPel( |
| 220 | types::ErrorType::SystemTypeMismatch, |
| 221 | types::SeverityType::Warning, __FILE__, __FUNCTION__, 0, |
| 222 | std::string("Mismatch in IM value found eBMC IM [") + |
| 223 | l_eBmcImValue + std::string("] planar IM [") + |
| 224 | l_planarImValue + |
| 225 | std::string("] Field mode enabled [") + |
| 226 | ((l_isFieldModeEnabled) ? "true" : "false") + |
| 227 | std::string("]"), |
| 228 | std::nullopt, std::nullopt, std::nullopt, std::nullopt); |
| 229 | |
| 230 | return constants::FAILURE; |
| 231 | } |
| 232 | } |
| 233 | } |
| 234 | else if (isP11System(l_eBmcImValue)) |
| 235 | { |
| 236 | if (l_isPowerVsImage) |
| 237 | { |
| 238 | EventLogger::createSyncPel( |
| 239 | types::ErrorType::SystemTypeMismatch, |
| 240 | types::SeverityType::Warning, __FILE__, __FUNCTION__, 0, |
| 241 | std::string("Mismatch in IM value found eBMC IM [") + |
| 242 | l_eBmcImValue + std::string("] planar IM [") + |
| 243 | l_planarImValue + |
| 244 | std::string("] Field mode enabled [") + |
| 245 | ((l_isFieldModeEnabled) ? "true" : "false") + |
| 246 | std::string("]"), |
| 247 | std::nullopt, std::nullopt, std::nullopt, std::nullopt); |
| 248 | |
| 249 | return constants::FAILURE; |
| 250 | } |
| 251 | else |
| 252 | { |
| 253 | if (isP10System(l_planarImValue)) |
| 254 | { |
| 255 | updateSystemImValueInVpdToP11Series(l_planarImValue); |
| 256 | } |
| 257 | } |
| 258 | } |
| 259 | } |
| 260 | else |
| 261 | { |
| 262 | if (isP11System(l_planarImValue) && l_isPowerVsImage) |
| 263 | { |
| 264 | EventLogger::createSyncPel( |
| 265 | types::ErrorType::SystemTypeMismatch, |
| 266 | types::SeverityType::Warning, __FILE__, __FUNCTION__, 0, |
| 267 | std::string("Mismatch in IM value found eBMC IM [") + |
| 268 | l_eBmcImValue + std::string("] planar IM [") + |
| 269 | l_planarImValue + std::string("] Field mode enabled [") + |
| 270 | ((l_isFieldModeEnabled) ? "true" : "false") + |
| 271 | std::string("]"), |
| 272 | std::nullopt, std::nullopt, std::nullopt, std::nullopt); |
| 273 | |
| 274 | return constants::FAILURE; |
| 275 | } |
| 276 | else if (isP10System(l_planarImValue) && l_isNormalImage) |
| 277 | { |
| 278 | if (l_isLabModeEnabled) |
| 279 | { |
| 280 | EventLogger::createSyncPel( |
| 281 | types::ErrorType::UnknownSystemSettings, |
| 282 | types::SeverityType::Warning, __FILE__, __FUNCTION__, 0, |
| 283 | std::string("Mismatch in IM value found eBMC IM [") + |
| 284 | l_eBmcImValue + std::string("] planar IM [") + |
| 285 | l_planarImValue + |
| 286 | std::string("] Field mode enabled [") + |
| 287 | ((l_isFieldModeEnabled) ? "true" : "false") + |
| 288 | std::string("]"), |
| 289 | std::nullopt, std::nullopt, std::nullopt, std::nullopt); |
| 290 | } |
| 291 | else |
| 292 | { |
| 293 | updateSystemImValueInVpdToP11Series(l_planarImValue); |
| 294 | } |
| 295 | } |
| 296 | } |
| 297 | return constants::SUCCESS; |
| Souvik Roy | cd828d4 | 2025-03-24 02:29:45 -0500 | [diff] [blame] | 298 | } |
| Anupama B R | 08fa59e | 2025-03-06 22:55:11 -0600 | [diff] [blame] | 299 | } // namespace vpd |