-
Notifications
You must be signed in to change notification settings - Fork 28
/
vpd_tool_impl.hpp
322 lines (285 loc) · 9.97 KB
/
vpd_tool_impl.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#include "config.h"
#include "editor_impl.hpp"
#include "ibm_vpd_utils.hpp"
#include "types.hpp"
#include <nlohmann/json.hpp>
#include <string>
using json = nlohmann::json;
// <S.no, Record, Keyword, D-Bus value, HW value, Data mismatch>
using SystemCriticalData =
std::vector<std::tuple<uint8_t, std::string, std::string, std::string,
std::string, std::string>>;
class VpdTool
{
private:
const std::string fruPath;
const std::string recordName;
const std::string keyword;
const std::string value;
bool objFound = true;
SystemCriticalData recKwData;
// Store Type of FRU
std::string fruType;
/**
* @brief Debugger
* Displays the output in JSON.
*
* @param[in] output - json output to be displayed
*/
void debugger(json output);
/**
* @brief make Dbus Call
*
* @param[in] objectName - dbus Object
* @param[in] interface - dbus Interface
* @param[in] kw - keyword under the interface
*
* @return dbus call response
*/
auto makeDBusCall(const std::string& objectName,
const std::string& interface, const std::string& kw);
/**
* @brief Get VINI properties
* Making a dbus call for properties [SN, PN, CC, FN, DR]
* under VINI interface.
*
* @param[in] invPath - Value of inventory Path
*
* @return json output which gives the properties under invPath's VINI
* interface
*/
json getVINIProperties(std::string invPath);
/**
* @brief Get ExtraInterface Properties
* Making a dbus call for those properties under extraInterfaces.
*
* @param[in] invPath - Value of inventory path
* @param[in] extraInterface - One of the invPath's extraInterfaces whose
* value is not null
* @param[in] prop - All properties of the extraInterface.
* @param[out] output - output json which has the properties under invPath's
* extra interface.
*/
void getExtraInterfaceProperties(const std::string& invPath,
const std::string& extraInterface,
const json& prop, json& output);
/**
* @brief Interface Decider
* Decides whether to make the dbus call for
* getting properties from extraInterface or from
* VINI interface, depending on the value of
* extraInterfaces object in the inventory json.
*
* @param[in] itemEEPROM - holds the reference of one of the EEPROM objects.
*
* @return json output for one of the EEPROM objects.
*/
json interfaceDecider(json& itemEEPROM);
/**
* @brief Parse Inventory JSON
* Parses the complete inventory json and depending upon
* the user option makes the dbuscall for the frus
* via interfaceDecider function.
*
* @param[in] jsObject - Inventory json object
* @param[in] flag - flag which tells about the user option(either
* dumpInventory or dumpObject)
* @param[in] fruPath - fruPath is empty for dumpInventory option and holds
* valid fruPath for dumpObject option.
*
* @return output json
*/
json parseInvJson(const json& jsObject, char flag, std::string fruPath);
/**
* @brief eraseInventoryPath
* Remove the INVENTORY_PATH - "/xyz/openbmc_project/inventory"
* for code convenience.
*
* @param[out] fru - Reference to the fru path whose INVENTORY_PATH is
* stripped off.
*/
void eraseInventoryPath(std::string& fru);
/**
* @brief printReturnCode
* Prints the return code of the program in console output, whenever
* the program fails to exit successfully.
*
* @param[in] returnCode - return code of the program.
*/
void printReturnCode(int returnCode);
/**
* @brief Convert hex/ascii values to Binary
* @param[in] - value in hex/ascii.
* @param[out] - value in binary.
*/
openpower::vpd::Binary toBinary(const std::string& value);
/**
* @brief Get the json which has Present property value of the given fru.
* @param[in] invPath - inventory path of the fru.
* @return output json which has the Present property value.
*/
json getPresentPropJson(const std::string& invPath);
/**
* @brief Parse through the options to fix system VPD
*
* @param[in] json - Inventory JSON
* @param[in] backupEEPROMPath - Backup VPD path
*/
void parseSVPDOptions(const nlohmann::json& json,
const std::string& backupEEPROMPath);
/**
* @brief List of user options that can be used to fix system VPD keywords.
*/
enum UserOption
{
EXIT = 0,
BACKUP_DATA_FOR_ALL = 1,
SYSTEM_BACKPLANE_DATA_FOR_ALL = 2,
MORE_OPTIONS = 3,
BACKUP_DATA_FOR_CURRENT = 4,
SYSTEM_BACKPLANE_DATA_FOR_CURRENT = 5,
NEW_VALUE_ON_BOTH = 6,
SKIP_CURRENT = 7
};
/**
* @brief Print options to fix system VPD.
* @param[in] option - Option to use.
*/
void printFixSystemVPDOption(UserOption option);
/**
* @brief Get System VPD data stored in cache
*
* @param[in] svpdBusData - Map of system VPD record data.
*/
void getSystemDataFromCache(
openpower::vpd::inventory::IntfPropMap& svpdBusData);
/**
* @brief Get data from file and store in binary format
*
* @param[out] data - The resulting binary data
*
* @return If operation is success return true, else on failure return
* false.
*/
bool fileToVector(openpower::vpd::Binary& data);
/**
* @brief Copy string data to file.
*
* @param[in] input - input string
*
* @return If operation is success return true, else on failure return
* false.
*/
bool copyStringToFile(const std::string& input);
public:
/**
* @brief Dump the complete inventory in JSON format
*
* @param[in] jsObject - Inventory JSON specified in configure file.
*/
void dumpInventory(const nlohmann::basic_json<>& jsObject);
/**
* @brief Dump the given inventory object in JSON format
*
* @param[in] jsObject - Inventory JSON specified in configure file.
*/
void dumpObject(const nlohmann::basic_json<>& jsObject);
/**
* @brief Read keyword
* Read the given object path, record name and keyword
* from the inventory and display the value of the keyword
* in JSON format. The read value will be piped to file if --file is given
* by the user. Else the value read will be displayed on console.
*/
void readKeyword();
/**
* @brief Update Keyword
* Update the given keyword with the given value.
*
* @return return code (Success(0)/Failure(-1))
*/
int updateKeyword();
/**
* @brief Force Reset
* Clearing the inventory cache data and restarting the
* phosphor inventory manager and also retriggering all the
* udev events.
*
* @param[in] jsObject - Inventory JSON specified in configure file.
*/
void forceReset(const nlohmann::basic_json<>& jsObject);
/**
* @brief Update Hardware
* The given data is updated only on the given hardware path and not on dbus
* for the given record-keyword pair. The user can now update record-keyword
* value for any hardware path irrespective of whether its present or not in
* VPD JSON, by providing a valid offset. By default offset takes 0.
*
* @param[in] offset - VPD offset.
* @return returncode (success/failure).
*/
int updateHardware(const uint32_t offset);
/**
* @brief Read Keyword from Hardware
* This api is to read a keyword directly from the hardware. The hardware
* path, record name and keyword name are received at the time of
* initialising the constructor.
* The user can now read keyword from any hardware path irrespective of
* whether its present or not in VPD JSON, by providing a valid offset. By
* default offset takes 0. The read value can be either saved in a
* file/displayed on console.
*
* @param[in] startOffset - VPD offset.
*/
void readKwFromHw(const uint32_t& startOffset);
/**
* @brief Fix System VPD keyword.
* This API provides an interactive way to fix system VPD keywords that are
* part of restorable record-keyword pairs. The user can use this option to
* restore the restorable keywords in cache or in hardware or in both cache
* and hardware.
* @return returncode (success/failure).
*/
int fixSystemVPD();
/**
* @brief Clean specific keywords in system backplane VPD
*
* @return return code (success/failure)
*/
int cleanSystemVPD();
/**
* @brief Fix system VPD and its backup VPD
* API is triggered if the backup of system VPD has to be taken in a
* hardware VPD. User can use the --fixSystemVPD option to restore the
* keywords in backup VPD and/or system VPD.
*
* @param[in] backupEepromPath - Backup VPD path
* @param[in] backupInvPath - Backup inventory path
* @return returncode
*/
int fixSystemBackupVPD(const std::string& backupEepromPath,
const std::string& backupInvPath);
/**
* @brief Constructor
* Constructor is called during the
* object instantiation for dumpInventory option and
* forceReset option.
*/
VpdTool() {}
/**
* @brief Constructor
* Constructor is called during the
* object instantiation for dumpObject option.
*/
VpdTool(const std::string&& fru) : fruPath(std::move(fru)) {}
/**
* @brief Constructor
* Constructor is called during the
* object instantiation for updateKeyword option.
*/
VpdTool(const std::string&& fru, const std::string&& recName,
const std::string&& kw, const std::string&& val) :
fruPath(std::move(fru)), recordName(std::move(recName)),
keyword(std::move(kw)), value(std::move(val))
{}
};