blob: d60fd3cc71862aa745ed1b71611ba00798b90813 [file] [log] [blame]
Anupama B Rb5bfcbc2025-03-03 03:00:04 -06001#include "config.h"
2
Anupama B R08fa59e2025-03-06 22:55:11 -06003#include "single_fab.hpp"
4
5#include "constants.hpp"
Rekha Aparna57022292025-11-25 04:20:41 -06006#include "logger.hpp"
RekhaAparna01d3e693e2025-03-04 05:08:30 -06007#include "parser.hpp"
Anupama B R08fa59e2025-03-06 22:55:11 -06008#include "types.hpp"
9
RekhaAparna01d3e693e2025-03-04 05:08:30 -060010#include <nlohmann/json.hpp>
RekhaAparna01f05f3542025-03-02 22:25:23 -060011#include <utility/common_utility.hpp>
Rekha Aparnaa39aafa2025-11-04 00:06:12 -060012#include <utility/event_logger_utility.hpp>
Anupama B R08fa59e2025-03-06 22:55:11 -060013#include <utility/json_utility.hpp>
Rekha Aparnaffdff312025-03-25 01:10:56 -050014#include <utility/vpd_specific_utility.hpp>
Anupama B R08fa59e2025-03-06 22:55:11 -060015
16namespace vpd
17{
18constexpr auto pimPersistVsbpPath =
19 "/var/lib/phosphor-inventory-manager/xyz/openbmc_project/inventory/system/chassis/motherboard/com.ibm.ipzvpd.VSBP";
Anupama B Rb5bfcbc2025-03-03 03:00:04 -060020constexpr auto IM_SIZE_IN_BYTES = 0x04;
21constexpr auto IM_KW_VALUE_OFFSET = 0x000005fb;
Anupama B R08fa59e2025-03-06 22:55:11 -060022
23std::string SingleFab::getImFromPersistedLocation() const noexcept
24{
25 try
26 {
Rekha Aparnaca9a0862025-08-29 04:08:33 -050027 uint16_t l_errCode = 0;
Anupama B R08fa59e2025-03-06 22:55:11 -060028 auto l_parsedVsbpJsonObj =
Rekha Aparnaca9a0862025-08-29 04:08:33 -050029 jsonUtility::getParsedJson(pimPersistVsbpPath, l_errCode);
30
31 if (l_errCode)
32 {
33 throw JsonException(
34 "Failed to parse JSON file [ " +
Rekha Aparnac6159a22025-10-09 12:20:20 +053035 std::string(pimPersistVsbpPath) +
36 " ], error : " + commonUtility::getErrCodeMsg(l_errCode),
Rekha Aparnaca9a0862025-08-29 04:08:33 -050037 pimPersistVsbpPath);
38 }
39
Anupama B R08fa59e2025-03-06 22:55:11 -060040 if (!l_parsedVsbpJsonObj.contains("value0") ||
41 !l_parsedVsbpJsonObj["value0"].contains(constants::kwdIM) ||
42 !l_parsedVsbpJsonObj["value0"][constants::kwdIM].is_array())
43 {
Rekha Aparnaca9a0862025-08-29 04:08:33 -050044 throw std::runtime_error("Mandatory tag(s) missing from JSON");
Anupama B R08fa59e2025-03-06 22:55:11 -060045 }
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)
RekhaAparna01d3e693e2025-03-04 05:08:30 -060060 {}
Anupama B R08fa59e2025-03-06 22:55:11 -060061
62 return std::string();
63}
Anupama B Rb5bfcbc2025-03-03 03:00:04 -060064
65std::string SingleFab::getImFromPlanar() const noexcept
66{
67 try
68 {
Anupama B Re2f09be2025-04-08 04:41:28 -050069 const std::string l_systemPlanarPath(SYSTEM_VPD_FILE_PATH);
70 Parser l_parserObj(l_systemPlanarPath, nlohmann::json{});
Anupama B Rb5bfcbc2025-03-03 03:00:04 -060071
Anupama B Re2f09be2025-04-08 04:41:28 -050072 std::shared_ptr<ParserInterface> l_vpdParserInstance =
73 l_parserObj.getVpdParserInstance();
Anupama B Rb5bfcbc2025-03-03 03:00:04 -060074
Anupama B Re2f09be2025-04-08 04:41:28 -050075 auto l_readValue = l_vpdParserInstance->readKeywordFromHardware(
76 std::make_tuple(constants::recVSBP, constants::kwdIM));
Anupama B Rb5bfcbc2025-03-03 03:00:04 -060077
Anupama B Re2f09be2025-04-08 04:41:28 -050078 if (auto l_keywordValue =
79 std::get_if<types::BinaryVector>(&l_readValue);
80 l_keywordValue && !l_keywordValue->empty())
Anupama B Rb5bfcbc2025-03-03 03:00:04 -060081 {
Anupama B Re2f09be2025-04-08 04:41:28 -050082 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 Rb5bfcbc2025-03-03 03:00:04 -060090 }
Anupama B Rb5bfcbc2025-03-03 03:00:04 -060091 }
92 catch (const std::ifstream::failure& l_ex)
93 {}
94
95 return std::string();
96}
RekhaAparna01d3e693e2025-03-04 05:08:30 -060097
98bool 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}
RekhaAparna01f05f3542025-03-02 22:25:23 -0600126
Rekha Aparnaffdff312025-03-25 01:10:56 -0500127void SingleFab::updateSystemImValueInVpdToP11Series(
Souvik Roycd828d42025-03-24 02:29:45 -0500128 std::string i_currentImValuePlanar) const noexcept
129{
130 bool l_retVal{false};
131 if (!i_currentImValuePlanar.empty())
132 {
Anupama B R879d4652025-04-21 04:19:02 -0500133 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 Roycd828d42025-03-24 02:29:45 -0500143 // 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 Aparnaffdff312025-03-25 01:10:56 -0500149
150 if (!l_retVal)
151 {
Alpana Kumari77095522026-01-23 05:55:17 -0600152 Logger::getLoggerInstance()->logMessage(
Rekha Aparnaffdff312025-03-25 01:10:56 -0500153 std::string("Failed to update IM value to P11 series."),
Alpana Kumari77095522026-01-23 05:55:17 -0600154 PlaceHolder::PEL,
155 types::PelInfoTuple{types::ErrorType::InternalFailure,
156 types::SeverityType::Informational, 0,
157 std::nullopt, std::nullopt, std::nullopt,
158 std::nullopt});
Rekha Aparnaffdff312025-03-25 01:10:56 -0500159 }
160}
161
162int SingleFab::singleFabImOverride() const noexcept
163{
Rekha Aparna57022292025-11-25 04:20:41 -0600164 uint16_t l_errCode = 0;
Rekha Aparnaffdff312025-03-25 01:10:56 -0500165 const std::string& l_planarImValue = getImFromPlanar();
166 const std::string& l_eBmcImValue = getImFromPersistedLocation();
Rekha Aparna57022292025-11-25 04:20:41 -0600167 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 Aparnaffdff312025-03-25 01:10:56 -0500177 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 Kumari77095522026-01-23 05:55:17 -0600185 Logger::getLoggerInstance()->logMessage(
Rekha Aparnaffdff312025-03-25 01:10:56 -0500186 std::string("Invalid IM found on the system planar, IM value : ") +
187 l_planarImValue,
Alpana Kumari77095522026-01-23 05:55:17 -0600188 PlaceHolder::PEL,
189 types::PelInfoTuple{types::ErrorType::InvalidSystem,
190 types::SeverityType::Error, 0, std::nullopt,
191 std::nullopt, std::nullopt, std::nullopt});
Rekha Aparnaffdff312025-03-25 01:10:56 -0500192
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 Kumari77095522026-01-23 05:55:17 -0600204 Logger::getLoggerInstance()->logMessage(
Rekha Aparnaffdff312025-03-25 01:10:56 -0500205 std::string("Mismatch in IM value found eBMC IM [") +
Alpana Kumari77095522026-01-23 05:55:17 -0600206 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 Aparnaffdff312025-03-25 01:10:56 -0500214
215 return constants::FAILURE;
216 }
217 }
218 else if (isP11System(l_planarImValue))
219 {
220 if (!(l_isLabModeEnabled && l_isNormalImage))
221 {
Alpana Kumari77095522026-01-23 05:55:17 -0600222 Logger::getLoggerInstance()->logMessage(
Rekha Aparnaffdff312025-03-25 01:10:56 -0500223 std::string("Mismatch in IM value found eBMC IM [") +
Alpana Kumari77095522026-01-23 05:55:17 -0600224 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 Aparnaffdff312025-03-25 01:10:56 -0500232
233 return constants::FAILURE;
234 }
235 }
236 }
237 else if (isP11System(l_eBmcImValue))
238 {
239 if (l_isPowerVsImage)
240 {
Alpana Kumari77095522026-01-23 05:55:17 -0600241 Logger::getLoggerInstance()->logMessage(
Rekha Aparnaffdff312025-03-25 01:10:56 -0500242 std::string("Mismatch in IM value found eBMC IM [") +
Alpana Kumari77095522026-01-23 05:55:17 -0600243 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 Aparnaffdff312025-03-25 01:10:56 -0500251
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 Kumari77095522026-01-23 05:55:17 -0600267 Logger::getLoggerInstance()->logMessage(
Rekha Aparnaffdff312025-03-25 01:10:56 -0500268 std::string("Mismatch in IM value found eBMC IM [") +
Alpana Kumari77095522026-01-23 05:55:17 -0600269 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 Aparnaffdff312025-03-25 01:10:56 -0500277
278 return constants::FAILURE;
279 }
280 else if (isP10System(l_planarImValue) && l_isNormalImage)
281 {
282 if (l_isLabModeEnabled)
283 {
Alpana Kumari77095522026-01-23 05:55:17 -0600284 Logger::getLoggerInstance()->logMessage(
Rekha Aparnaffdff312025-03-25 01:10:56 -0500285 std::string("Mismatch in IM value found eBMC IM [") +
Alpana Kumari77095522026-01-23 05:55:17 -0600286 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 Aparnaffdff312025-03-25 01:10:56 -0500294 }
295 else
296 {
297 updateSystemImValueInVpdToP11Series(l_planarImValue);
298 }
299 }
300 }
301 return constants::SUCCESS;
Souvik Roycd828d42025-03-24 02:29:45 -0500302}
Anupama B R08fa59e2025-03-06 22:55:11 -0600303} // namespace vpd