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" |
| 6 | #include "types.hpp" |
| 7 | |
| 8 | #include <utility/json_utility.hpp> |
| 9 | |
| 10 | namespace vpd |
| 11 | { |
| 12 | constexpr auto pimPersistVsbpPath = |
| 13 | "/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^] | 14 | constexpr auto IM_SIZE_IN_BYTES = 0x04; |
| 15 | constexpr auto IM_KW_VALUE_OFFSET = 0x000005fb; |
Anupama B R | 08fa59e | 2025-03-06 22:55:11 -0600 | [diff] [blame] | 16 | |
| 17 | std::string SingleFab::getImFromPersistedLocation() const noexcept |
| 18 | { |
| 19 | try |
| 20 | { |
| 21 | auto l_parsedVsbpJsonObj = |
| 22 | jsonUtility::getParsedJson(pimPersistVsbpPath); |
| 23 | if (!l_parsedVsbpJsonObj.contains("value0") || |
| 24 | !l_parsedVsbpJsonObj["value0"].contains(constants::kwdIM) || |
| 25 | !l_parsedVsbpJsonObj["value0"][constants::kwdIM].is_array()) |
| 26 | { |
| 27 | throw std::runtime_error( |
| 28 | "Json is empty or mandatory tag(s) missing from JSON"); |
| 29 | } |
| 30 | |
| 31 | const types::BinaryVector l_imValue = |
| 32 | l_parsedVsbpJsonObj["value0"][constants::kwdIM] |
| 33 | .get<types::BinaryVector>(); |
| 34 | |
| 35 | std::ostringstream l_imData; |
| 36 | for (const auto& l_byte : l_imValue) |
| 37 | { |
| 38 | l_imData << std::setw(2) << std::setfill('0') << std::hex |
| 39 | << static_cast<int>(l_byte); |
| 40 | } |
| 41 | return l_imData.str(); |
| 42 | } |
| 43 | catch (const std::exception& l_ex) |
| 44 | { |
| 45 | logging::logMessage( |
| 46 | "Error while getting IM value from PIM persisted file: " + |
| 47 | std::string(pimPersistVsbpPath) + |
| 48 | ", reason: " + std::string(l_ex.what())); |
| 49 | } |
| 50 | |
| 51 | return std::string(); |
| 52 | } |
Anupama B R | b5bfcbc | 2025-03-03 03:00:04 -0600 | [diff] [blame^] | 53 | |
| 54 | std::string SingleFab::getImFromPlanar() const noexcept |
| 55 | { |
| 56 | try |
| 57 | { |
| 58 | types::BinaryVector l_imValue(IM_SIZE_IN_BYTES); |
| 59 | std::fstream l_vpdFileStream; |
| 60 | |
| 61 | l_vpdFileStream.exceptions( |
| 62 | std::ifstream::badbit | std::ifstream::failbit); |
| 63 | |
| 64 | l_vpdFileStream.open(SYSTEM_VPD_FILE_PATH, |
| 65 | std::ios::in | std::ios::binary); |
| 66 | |
| 67 | l_vpdFileStream.seekg(IM_KW_VALUE_OFFSET, std::ios_base::beg); |
| 68 | |
| 69 | // Read keyword value |
| 70 | l_vpdFileStream.read(reinterpret_cast<char*>(&l_imValue[0]), |
| 71 | IM_SIZE_IN_BYTES); |
| 72 | |
| 73 | l_vpdFileStream.clear(std::ios_base::eofbit); |
| 74 | |
| 75 | std::ostringstream l_imData; |
| 76 | for (const auto& l_byte : l_imValue) |
| 77 | { |
| 78 | l_imData << std::setw(2) << std::setfill('0') << std::hex |
| 79 | << static_cast<int>(l_byte); |
| 80 | } |
| 81 | return l_imData.str(); |
| 82 | } |
| 83 | catch (const std::ifstream::failure& l_ex) |
| 84 | {} |
| 85 | |
| 86 | return std::string(); |
| 87 | } |
Anupama B R | 08fa59e | 2025-03-06 22:55:11 -0600 | [diff] [blame] | 88 | } // namespace vpd |