| 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 | { |
| Alpana Kumari | 7709552 | 2026-01-23 05:55:17 -0600 | [diff] [blame] | 152 | Logger::getLoggerInstance()->logMessage( |
| Rekha Aparna | ffdff31 | 2025-03-25 01:10:56 -0500 | [diff] [blame] | 153 | std::string("Failed to update IM value to P11 series."), |
| Alpana Kumari | 7709552 | 2026-01-23 05:55:17 -0600 | [diff] [blame] | 154 | PlaceHolder::PEL, |
| 155 | types::PelInfoTuple{types::ErrorType::InternalFailure, |
| 156 | types::SeverityType::Informational, 0, |
| 157 | std::nullopt, std::nullopt, std::nullopt, |
| 158 | std::nullopt}); |
| Rekha Aparna | ffdff31 | 2025-03-25 01:10:56 -0500 | [diff] [blame] | 159 | } |
| 160 | } |
| 161 | |
| 162 | int SingleFab::singleFabImOverride() const noexcept |
| 163 | { |
| Rekha Aparna | 5702229 | 2025-11-25 04:20:41 -0600 | [diff] [blame] | 164 | uint16_t l_errCode = 0; |
| Rekha Aparna | ffdff31 | 2025-03-25 01:10:56 -0500 | [diff] [blame] | 165 | const std::string& l_planarImValue = getImFromPlanar(); |
| 166 | const std::string& l_eBmcImValue = getImFromPersistedLocation(); |
| Rekha Aparna | 5702229 | 2025-11-25 04:20:41 -0600 | [diff] [blame] | 167 | const bool& l_isFieldModeEnabled = |
| 168 | commonUtility::isFieldModeEnabled(l_errCode); |
| 169 | |
| 170 | if (l_errCode) |
| 171 | { |
| 172 | Logger::getLoggerInstance()->logMessage( |
| 173 | "Failed to check is field mode enabled, error : " + |
| 174 | commonUtility::getErrCodeMsg(l_errCode)); |
| 175 | } |
| 176 | |
| Rekha Aparna | ffdff31 | 2025-03-25 01:10:56 -0500 | [diff] [blame] | 177 | const bool& l_isLabModeEnabled = |
| 178 | !l_isFieldModeEnabled; // used for understanding |
| 179 | const bool& l_isPowerVsImage = vpdSpecificUtility::isPowerVsImage(); |
| 180 | const bool& l_isNormalImage = !l_isPowerVsImage; // used for understanding |
| 181 | |
| 182 | if (!isValidImSeries(l_planarImValue)) |
| 183 | { |
| 184 | // Create Errorlog for invalid IM series encountered |
| Alpana Kumari | 7709552 | 2026-01-23 05:55:17 -0600 | [diff] [blame] | 185 | Logger::getLoggerInstance()->logMessage( |
| Rekha Aparna | ffdff31 | 2025-03-25 01:10:56 -0500 | [diff] [blame] | 186 | std::string("Invalid IM found on the system planar, IM value : ") + |
| 187 | l_planarImValue, |
| Alpana Kumari | 7709552 | 2026-01-23 05:55:17 -0600 | [diff] [blame] | 188 | PlaceHolder::PEL, |
| 189 | types::PelInfoTuple{types::ErrorType::InvalidSystem, |
| 190 | types::SeverityType::Error, 0, std::nullopt, |
| 191 | std::nullopt, std::nullopt, std::nullopt}); |
| Rekha Aparna | ffdff31 | 2025-03-25 01:10:56 -0500 | [diff] [blame] | 192 | |
| 193 | return constants::SUCCESS; |
| 194 | } |
| 195 | |
| 196 | if (!l_eBmcImValue.empty()) |
| 197 | { |
| 198 | if (isP10System(l_eBmcImValue)) |
| 199 | { |
| 200 | if (isP10System(l_planarImValue)) |
| 201 | { |
| 202 | if (l_isFieldModeEnabled && l_isNormalImage) |
| 203 | { |
| Alpana Kumari | 7709552 | 2026-01-23 05:55:17 -0600 | [diff] [blame] | 204 | Logger::getLoggerInstance()->logMessage( |
| Rekha Aparna | ffdff31 | 2025-03-25 01:10:56 -0500 | [diff] [blame] | 205 | std::string("Mismatch in IM value found eBMC IM [") + |
| Alpana Kumari | 7709552 | 2026-01-23 05:55:17 -0600 | [diff] [blame] | 206 | l_eBmcImValue + "] planar IM [" + l_planarImValue + |
| 207 | "] Field mode enabled [" + |
| 208 | ((l_isFieldModeEnabled) ? "true" : "false") + "]", |
| 209 | PlaceHolder::PEL, |
| 210 | types::PelInfoTuple{ |
| 211 | types::ErrorType::SystemTypeMismatch, |
| 212 | types::SeverityType::Warning, 0, std::nullopt, |
| 213 | std::nullopt, std::nullopt, std::nullopt}); |
| Rekha Aparna | ffdff31 | 2025-03-25 01:10:56 -0500 | [diff] [blame] | 214 | |
| 215 | return constants::FAILURE; |
| 216 | } |
| 217 | } |
| 218 | else if (isP11System(l_planarImValue)) |
| 219 | { |
| 220 | if (!(l_isLabModeEnabled && l_isNormalImage)) |
| 221 | { |
| Alpana Kumari | 7709552 | 2026-01-23 05:55:17 -0600 | [diff] [blame] | 222 | Logger::getLoggerInstance()->logMessage( |
| Rekha Aparna | ffdff31 | 2025-03-25 01:10:56 -0500 | [diff] [blame] | 223 | std::string("Mismatch in IM value found eBMC IM [") + |
| Alpana Kumari | 7709552 | 2026-01-23 05:55:17 -0600 | [diff] [blame] | 224 | l_eBmcImValue + "] planar IM [" + l_planarImValue + |
| 225 | "] Field mode enabled [" + |
| 226 | ((l_isFieldModeEnabled) ? "true" : "false") + "]", |
| 227 | PlaceHolder::PEL, |
| 228 | types::PelInfoTuple{ |
| 229 | types::ErrorType::SystemTypeMismatch, |
| 230 | types::SeverityType::Warning, 0, std::nullopt, |
| 231 | std::nullopt, std::nullopt, std::nullopt}); |
| Rekha Aparna | ffdff31 | 2025-03-25 01:10:56 -0500 | [diff] [blame] | 232 | |
| 233 | return constants::FAILURE; |
| 234 | } |
| 235 | } |
| 236 | } |
| 237 | else if (isP11System(l_eBmcImValue)) |
| 238 | { |
| 239 | if (l_isPowerVsImage) |
| 240 | { |
| Alpana Kumari | 7709552 | 2026-01-23 05:55:17 -0600 | [diff] [blame] | 241 | Logger::getLoggerInstance()->logMessage( |
| Rekha Aparna | ffdff31 | 2025-03-25 01:10:56 -0500 | [diff] [blame] | 242 | std::string("Mismatch in IM value found eBMC IM [") + |
| Alpana Kumari | 7709552 | 2026-01-23 05:55:17 -0600 | [diff] [blame] | 243 | l_eBmcImValue + "] planar IM [" + l_planarImValue + |
| 244 | "] Field mode enabled [" + |
| 245 | ((l_isFieldModeEnabled) ? "true" : "false") + "]", |
| 246 | PlaceHolder::PEL, |
| 247 | types::PelInfoTuple{types::ErrorType::SystemTypeMismatch, |
| 248 | types::SeverityType::Warning, 0, |
| 249 | std::nullopt, std::nullopt, |
| 250 | std::nullopt, std::nullopt}); |
| Rekha Aparna | ffdff31 | 2025-03-25 01:10:56 -0500 | [diff] [blame] | 251 | |
| 252 | return constants::FAILURE; |
| 253 | } |
| 254 | else |
| 255 | { |
| 256 | if (isP10System(l_planarImValue)) |
| 257 | { |
| 258 | updateSystemImValueInVpdToP11Series(l_planarImValue); |
| 259 | } |
| 260 | } |
| 261 | } |
| 262 | } |
| 263 | else |
| 264 | { |
| 265 | if (isP11System(l_planarImValue) && l_isPowerVsImage) |
| 266 | { |
| Alpana Kumari | 7709552 | 2026-01-23 05:55:17 -0600 | [diff] [blame] | 267 | Logger::getLoggerInstance()->logMessage( |
| Rekha Aparna | ffdff31 | 2025-03-25 01:10:56 -0500 | [diff] [blame] | 268 | std::string("Mismatch in IM value found eBMC IM [") + |
| Alpana Kumari | 7709552 | 2026-01-23 05:55:17 -0600 | [diff] [blame] | 269 | l_eBmcImValue + "] planar IM [" + l_planarImValue + |
| 270 | "] Field mode enabled" + |
| 271 | ((l_isFieldModeEnabled) ? "true" : "false") + "]", |
| 272 | PlaceHolder::PEL, |
| 273 | types::PelInfoTuple{types::ErrorType::SystemTypeMismatch, |
| 274 | types::SeverityType::Warning, 0, |
| 275 | std::nullopt, std::nullopt, std::nullopt, |
| 276 | std::nullopt}); |
| Rekha Aparna | ffdff31 | 2025-03-25 01:10:56 -0500 | [diff] [blame] | 277 | |
| 278 | return constants::FAILURE; |
| 279 | } |
| 280 | else if (isP10System(l_planarImValue) && l_isNormalImage) |
| 281 | { |
| 282 | if (l_isLabModeEnabled) |
| 283 | { |
| Alpana Kumari | 7709552 | 2026-01-23 05:55:17 -0600 | [diff] [blame] | 284 | Logger::getLoggerInstance()->logMessage( |
| Rekha Aparna | ffdff31 | 2025-03-25 01:10:56 -0500 | [diff] [blame] | 285 | std::string("Mismatch in IM value found eBMC IM [") + |
| Alpana Kumari | 7709552 | 2026-01-23 05:55:17 -0600 | [diff] [blame] | 286 | l_eBmcImValue + "] planar IM [" + l_planarImValue + |
| 287 | "] Field mode enabled [" + |
| 288 | ((l_isFieldModeEnabled) ? "true" : "false") + "]", |
| 289 | PlaceHolder::PEL, |
| 290 | types::PelInfoTuple{types::ErrorType::UnknownSystemSettings, |
| 291 | types::SeverityType::Warning, 0, |
| 292 | std::nullopt, std::nullopt, |
| 293 | std::nullopt, std::nullopt}); |
| Rekha Aparna | ffdff31 | 2025-03-25 01:10:56 -0500 | [diff] [blame] | 294 | } |
| 295 | else |
| 296 | { |
| 297 | updateSystemImValueInVpdToP11Series(l_planarImValue); |
| 298 | } |
| 299 | } |
| 300 | } |
| 301 | return constants::SUCCESS; |
| Souvik Roy | cd828d4 | 2025-03-24 02:29:45 -0500 | [diff] [blame] | 302 | } |
| Anupama B R | 08fa59e | 2025-03-06 22:55:11 -0600 | [diff] [blame] | 303 | } // namespace vpd |