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