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