SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "const.hpp" |
| 4 | #include "types.hpp" |
| 5 | |
Patrick Williams | c78d887 | 2023-05-10 07:50:56 -0500 | [diff] [blame] | 6 | #include <nlohmann/json.hpp> |
| 7 | |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 8 | #include <cstddef> |
| 9 | #include <fstream> |
| 10 | #include <tuple> |
| 11 | |
| 12 | namespace openpower |
| 13 | { |
| 14 | namespace vpd |
| 15 | { |
| 16 | namespace manager |
| 17 | { |
| 18 | namespace editor |
| 19 | { |
| 20 | |
PriyangaRamasamy | 794ad82 | 2021-03-29 02:44:16 -0500 | [diff] [blame] | 21 | /** @class EditorImpl */ |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 22 | class EditorImpl |
| 23 | { |
| 24 | public: |
| 25 | EditorImpl() = delete; |
| 26 | EditorImpl(const EditorImpl&) = delete; |
| 27 | EditorImpl& operator=(const EditorImpl&) = delete; |
| 28 | EditorImpl(EditorImpl&&) = delete; |
| 29 | EditorImpl& operator=(EditorImpl&&) = delete; |
Patrick Williams | c78d887 | 2023-05-10 07:50:56 -0500 | [diff] [blame] | 30 | ~EditorImpl() {} |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 31 | |
| 32 | /** @brief Construct EditorImpl class |
| 33 | * |
PriyangaRamasamy | 794ad82 | 2021-03-29 02:44:16 -0500 | [diff] [blame] | 34 | * @param[in] record - Record Name |
| 35 | * @param[in] kwd - Keyword |
| 36 | * @param[in] vpd - Vpd Vector |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 37 | */ |
SunnySrivastava1984 | a0d460e | 2020-06-03 07:49:26 -0500 | [diff] [blame] | 38 | EditorImpl(const std::string& record, const std::string& kwd, |
| 39 | Binary&& vpd) : |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 40 | startOffset(0), |
| 41 | thisRecord(record, kwd), vpdFile(std::move(vpd)) |
Patrick Williams | c78d887 | 2023-05-10 07:50:56 -0500 | [diff] [blame] | 42 | {} |
SunnySrivastava1984 | a0d460e | 2020-06-03 07:49:26 -0500 | [diff] [blame] | 43 | |
| 44 | /** @brief Construct EditorImpl class |
| 45 | * |
| 46 | * @param[in] path - Path to the vpd file |
PriyangaRamasamy | 794ad82 | 2021-03-29 02:44:16 -0500 | [diff] [blame] | 47 | * @param[in] json - Parsed inventory json |
| 48 | * @param[in] record - Record name |
| 49 | * @param[in] kwd - Keyword |
| 50 | * @param[in] inventoryPath - Inventory path of the vpd |
SunnySrivastava1984 | a0d460e | 2020-06-03 07:49:26 -0500 | [diff] [blame] | 51 | */ |
SunnySrivastava1984 | b421bfd | 2020-03-02 08:59:32 -0600 | [diff] [blame] | 52 | EditorImpl(const inventory::Path& path, const nlohmann::json& json, |
Alpana Kumari | 920408d | 2020-05-14 00:07:03 -0500 | [diff] [blame] | 53 | const std::string& record, const std::string& kwd, |
| 54 | const sdbusplus::message::object_path& inventoryPath) : |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 55 | vpdFilePath(path), |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 56 | objPath(inventoryPath), startOffset(0), jsonFile(json), |
| 57 | thisRecord(record, kwd) |
Patrick Williams | c78d887 | 2023-05-10 07:50:56 -0500 | [diff] [blame] | 58 | {} |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 59 | |
PriyangaRamasamy | c0a534f | 2020-08-24 21:29:18 +0530 | [diff] [blame] | 60 | /** @brief Construct EditorImpl class |
| 61 | * |
| 62 | * @param[in] path - EEPROM path |
| 63 | * @param[in] json - Parsed inventory json object |
| 64 | * @param[in] record - Record name |
| 65 | * @param[in] kwd - Keyword name |
| 66 | */ |
| 67 | EditorImpl(const inventory::Path& path, const nlohmann::json& json, |
| 68 | const std::string& record, const std::string& kwd) : |
| 69 | vpdFilePath(path), |
| 70 | jsonFile(json), thisRecord(record, kwd) |
Patrick Williams | c78d887 | 2023-05-10 07:50:56 -0500 | [diff] [blame] | 71 | {} |
PriyangaRamasamy | c0a534f | 2020-08-24 21:29:18 +0530 | [diff] [blame] | 72 | |
PriyangaRamasamy | 794ad82 | 2021-03-29 02:44:16 -0500 | [diff] [blame] | 73 | /** |
| 74 | * @brief Update data for keyword |
| 75 | * The method looks for the record name to update in VTOC and then |
| 76 | * looks for the keyword name in that record. when found it updates the data |
| 77 | * of keyword with the given data. It does not block keyword data update in |
| 78 | * case the length of new data is greater than or less than the current data |
Manojkiran Eda | af92175 | 2024-06-17 15:10:21 +0530 | [diff] [blame] | 79 | * length. If the new data length is more than the length allotted to that |
PriyangaRamasamy | 794ad82 | 2021-03-29 02:44:16 -0500 | [diff] [blame] | 80 | * keyword the new data will be truncated to update only the allotted |
| 81 | * length. Similarly if the new data length is less then only that much data |
| 82 | * will be updated for the keyword and remaining bits will be left |
| 83 | * unchanged. |
| 84 | * |
| 85 | * Following is the algorithm used to update keyword: |
| 86 | * 1) Look for the record name in the given VPD file |
| 87 | * 2) Look for the keyword name for which data needs to be updated |
| 88 | * which is the table of contents record. |
| 89 | * 3) update the data for that keyword with the new data |
| 90 | * |
| 91 | * @param[in] kwdData - data to update |
Santosh Puranik | a0b2391 | 2022-02-10 13:37:09 +0530 | [diff] [blame] | 92 | * @param[in] offset - offset at which the VPD starts |
PriyangaRamasamy | 794ad82 | 2021-03-29 02:44:16 -0500 | [diff] [blame] | 93 | * @param[in] updCache - Flag which tells whether to update Cache or not. |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 94 | */ |
Santosh Puranik | a0b2391 | 2022-02-10 13:37:09 +0530 | [diff] [blame] | 95 | void updateKeyword(const Binary& kwdData, uint32_t offset, |
| 96 | const bool& updCache); |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 97 | |
SunnySrivastava1984 | 4330654 | 2020-04-01 02:50:20 -0500 | [diff] [blame] | 98 | /** @brief Expands location code on DBUS |
| 99 | * @param[in] locationCodeType - "fcs" or "mts" |
| 100 | */ |
| 101 | void expandLocationCode(const std::string& locationCodeType); |
| 102 | |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 103 | private: |
| 104 | /** @brief read VTOC record from the vpd file |
| 105 | */ |
| 106 | void readVTOC(); |
| 107 | |
| 108 | /** @brief validate ecc data for the VTOC record |
PriyangaRamasamy | 794ad82 | 2021-03-29 02:44:16 -0500 | [diff] [blame] | 109 | * @param[in] itrToRecData -iterator to the record data |
| 110 | * @param[in] itrToECCData - iterator to the ECC data |
| 111 | * @param[in] recLength - Length of the record |
| 112 | * @param[in] eccLength - Length of the record's ECC |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 113 | */ |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 114 | void checkECC(Binary::const_iterator& itrToRecData, |
| 115 | Binary::const_iterator& itrToECCData, |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 116 | openpower::vpd::constants::RecordLength recLength, |
| 117 | openpower::vpd::constants::ECCLength eccLength); |
| 118 | |
| 119 | /** @brief reads value at the given offset |
| 120 | * @param[in] offset - offset value |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 121 | * @return value at that offset in bigendian |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 122 | */ |
| 123 | auto getValue(openpower::vpd::constants::offsets::Offsets offset); |
| 124 | |
| 125 | /** @brief Checks if required record name exist in the VPD file |
| 126 | * @param[in] iterator - pointing to start of PT kwd |
| 127 | * @param[in] ptLength - length of the PT kwd |
| 128 | */ |
| 129 | void checkPTForRecord(Binary::const_iterator& iterator, Byte ptLength); |
| 130 | |
PriyangaRamasamy | 794ad82 | 2021-03-29 02:44:16 -0500 | [diff] [blame] | 131 | /** @brief Checks for required keyword in the record */ |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 132 | void checkRecordForKwd(); |
| 133 | |
| 134 | /** @brief update data for given keyword |
| 135 | * @param[in] kwdData- data to be updated |
| 136 | */ |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 137 | void updateData(const Binary& kwdData); |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 138 | |
PriyangaRamasamy | 794ad82 | 2021-03-29 02:44:16 -0500 | [diff] [blame] | 139 | /** @brief update record ECC */ |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 140 | void updateRecordECC(); |
| 141 | |
PriyangaRamasamy | 794ad82 | 2021-03-29 02:44:16 -0500 | [diff] [blame] | 142 | /** @brief method to update cache once the data for keyword has been updated |
SunnySrivastava1984 | b421bfd | 2020-03-02 08:59:32 -0600 | [diff] [blame] | 143 | */ |
| 144 | void updateCache(); |
| 145 | |
| 146 | /** @brief method to process and update CI in case required |
| 147 | * @param[in] - objectPath - path of the object to introspect |
| 148 | */ |
| 149 | void processAndUpdateCI(const std::string& objectPath); |
| 150 | |
PriyangaRamasamy | 794ad82 | 2021-03-29 02:44:16 -0500 | [diff] [blame] | 151 | /** @brief method to process and update extra interface |
SunnySrivastava1984 | b421bfd | 2020-03-02 08:59:32 -0600 | [diff] [blame] | 152 | * @param[in] Inventory - single inventory json subpart |
PriyangaRamasamy | 794ad82 | 2021-03-29 02:44:16 -0500 | [diff] [blame] | 153 | * @param[in] objPath - path of the object to introspect |
SunnySrivastava1984 | b421bfd | 2020-03-02 08:59:32 -0600 | [diff] [blame] | 154 | */ |
| 155 | void processAndUpdateEI(const nlohmann::json& Inventory, |
| 156 | const inventory::Path& objPath); |
| 157 | |
SunnySrivastava1984 | d076da8 | 2020-03-05 05:33:35 -0600 | [diff] [blame] | 158 | /** @brief method to make busctl call |
| 159 | * |
| 160 | * @param[in] object - bus object path |
| 161 | * @param[in] interface - bus interface |
| 162 | * @param[in] property - property to update on BUS |
PriyangaRamasamy | 794ad82 | 2021-03-29 02:44:16 -0500 | [diff] [blame] | 163 | * @param[in] data - data to be updated on Bus |
SunnySrivastava1984 | d076da8 | 2020-03-05 05:33:35 -0600 | [diff] [blame] | 164 | * |
| 165 | */ |
| 166 | template <typename T> |
| 167 | void makeDbusCall(const std::string& object, const std::string& interface, |
| 168 | const std::string& property, const std::variant<T>& data); |
| 169 | |
girik | 18bb985 | 2022-11-16 05:48:13 -0600 | [diff] [blame] | 170 | /** @brief Method to check the record's Data using ECC */ |
| 171 | void checkRecordData(); |
| 172 | |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 173 | // path to the VPD file to edit |
Alpana Kumari | 920408d | 2020-05-14 00:07:03 -0500 | [diff] [blame] | 174 | inventory::Path vpdFilePath; |
| 175 | |
PriyangaRamasamy | 794ad82 | 2021-03-29 02:44:16 -0500 | [diff] [blame] | 176 | // inventory path of the vpd fru to update keyword |
Sunny Srivastava | f31a91b | 2022-06-09 08:11:29 -0500 | [diff] [blame] | 177 | inventory::Path objPath{}; |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 178 | |
| 179 | // stream to perform operation on file |
| 180 | std::fstream vpdFileStream; |
| 181 | |
girik | 18bb985 | 2022-11-16 05:48:13 -0600 | [diff] [blame] | 182 | // stream to operate on VPD data |
| 183 | std::fstream vpdDataFileStream; |
| 184 | |
Alpana Kumari | 920408d | 2020-05-14 00:07:03 -0500 | [diff] [blame] | 185 | // offset to get vpd data from EEPROM |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 186 | uint32_t startOffset; |
Alpana Kumari | 920408d | 2020-05-14 00:07:03 -0500 | [diff] [blame] | 187 | |
SunnySrivastava1984 | b421bfd | 2020-03-02 08:59:32 -0600 | [diff] [blame] | 188 | // file to store parsed json |
SunnySrivastava1984 | a0d460e | 2020-06-03 07:49:26 -0500 | [diff] [blame] | 189 | const nlohmann::json jsonFile; |
SunnySrivastava1984 | b421bfd | 2020-03-02 08:59:32 -0600 | [diff] [blame] | 190 | |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 191 | // structure to hold info about record to edit |
| 192 | struct RecInfo |
| 193 | { |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 194 | Binary kwdUpdatedData; // need access to it in case encoding is needed |
SunnySrivastava1984 | a0d460e | 2020-06-03 07:49:26 -0500 | [diff] [blame] | 195 | const std::string recName; |
| 196 | const std::string recKWd; |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 197 | openpower::vpd::constants::RecordOffset recOffset; |
| 198 | openpower::vpd::constants::ECCOffset recECCoffset; |
| 199 | std::size_t recECCLength; |
| 200 | std::size_t kwdDataLength; |
| 201 | openpower::vpd::constants::RecordSize recSize; |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 202 | openpower::vpd::constants::DataOffset kwDataOffset; |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 203 | // constructor |
| 204 | RecInfo(const std::string& rec, const std::string& kwd) : |
| 205 | recName(rec), recKWd(kwd), recOffset(0), recECCoffset(0), |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 206 | recECCLength(0), kwdDataLength(0), recSize(0), kwDataOffset(0) |
Patrick Williams | c78d887 | 2023-05-10 07:50:56 -0500 | [diff] [blame] | 207 | {} |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 208 | } thisRecord; |
| 209 | |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 210 | Binary vpdFile; |
| 211 | |
Alpana Kumari | 920408d | 2020-05-14 00:07:03 -0500 | [diff] [blame] | 212 | // If requested Interface is common Interface |
| 213 | bool isCI; |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 214 | }; // class EditorImpl |
| 215 | |
| 216 | } // namespace editor |
| 217 | } // namespace manager |
| 218 | } // namespace vpd |
Patrick Williams | c78d887 | 2023-05-10 07:50:56 -0500 | [diff] [blame] | 219 | } // namespace openpower |