VPD Tool: Update Hardware
Vpd tool has --Hardware/-H flag which should be given along
with writeKeyword flags, if the user wants to write directly to "Hardware".
In general the user should give only the object path in
--path/-P value.
Only if --Hardware/-H flag is given, the user has an
option to give either eeprom path or the object path in
--path/-P value.
Test:
Tested on simics.
./vpd-tool --writeKeyword -H --path < hardware path/object path > -R < record name > -K < keyword > -V < value in hex/ascii >
CASE 1: <updating eeprom path> < update directly on hardware using -H.>
./vpd-tool -u -H -P /sys/devices/platform/ahb/ahb:apb/ahb:apb:bus@1e78a000/1e78a480.i2c-bus/i2c-8/8-0051/8-00510/nvmem -R VINI -K PN -V 0x717273
updation successful on both dbus and hardware.
CASE 2:
./vpd-tool -u -H -P /sys/devices/platform/ahb/ahb:apb/ahb:apb:bus@1e78a000/1e78a480.i2c-bus/i2c-8/8-0051/8-00510/nvmem -R DINF -K FL -V 0x717273
updation successful on hardware. <this wont get updated in dbus as the given record-keyword pair is not required to update in dbus(only those record keywords
present in dbus_properties.json are required to be updated in dbus).
CASE 3: <failure case - invalid eeprom path>
root@rainier:/tmp# ./vpd-tool -u -H -P /sys/devices/platform/ahb/ahb:apb/ahb:apb:bus@1e78a000/1e78a490.i2c-bus/i2c-8/8-0051/8-00510/nvmem -R VINI -K PN -V 0x717273
Invalid object path : /sys/devices/platform/ahb/ahb:apb/ahb:apb:bus@1e78a000/1e78a490.i2c-bus/i2c-8/8-0051/8-00510/nvmem. Unable to find the corresponding EEPROM path for the given object path : /sys/devices/platform/ahb/ahb:apb/ahb:apb:bus@1e78a000/1e7$
Signed-off-by: PriyangaRamasamy <priyanga24@in.ibm.com>
Change-Id: I6b893e699fe343c90c3a3fd2b07fd8b9a4711687
diff --git a/vpd_tool.cpp b/vpd_tool.cpp
index e0e010a..9e76331 100644
--- a/vpd_tool.cpp
+++ b/vpd_tool.cpp
@@ -1,11 +1,16 @@
+#include "utils.hpp"
#include "vpd_tool_impl.hpp"
#include <CLI/CLI.hpp>
+#include <filesystem>
#include <fstream>
#include <iostream>
using namespace CLI;
using namespace std;
+namespace fs = std::filesystem;
+using namespace openpower::vpd;
+using json = nlohmann::json;
int main(int argc, char** argv)
{
@@ -17,6 +22,7 @@
string recordName{};
string keyword{};
string val{};
+ string path{};
auto object =
app.add_option("--object, -O", objectPath, "Enter the Object Path");
@@ -27,6 +33,10 @@
"--value, -V", val,
"Enter the value. The value to be updated should be either in ascii or "
"in hex. ascii eg: 01234; hex eg: 0x30313233");
+ auto pathOption =
+ app.add_option("--path, -P", path,
+ "Path - if hardware option is used, give either EEPROM "
+ "path/Object path; if not give the object path");
auto dumpObjFlag =
app.add_flag("--dumpObject, -o",
@@ -55,7 +65,7 @@
"--writeKeyword/-w/--updateKeyword/-u "
"--object/-O object-name --record/-R record-name --keyword/-K "
"keyword-name --value/-V value-to-be-updated }")
- ->needs(object)
+ ->needs(pathOption)
->needs(record)
->needs(kw)
->needs(valOption);
@@ -63,6 +73,12 @@
auto forceResetFlag = app.add_flag(
"--forceReset, -f, -F", "Force Collect for Hardware. { vpd-tool-exe "
"--forceReset/-f/-F }");
+ auto Hardware = app.add_flag(
+ "--Hardware, -H",
+ "This is a supplementary flag to read/write directly from/to hardware. "
+ "Enter the hardware path while using the object option in "
+ "corresponding read/write flags. This --Hardware flag is to be given "
+ "along with readKeyword/writeKeyword.");
CLI11_PARSE(app, argc, argv);
@@ -71,6 +87,28 @@
try
{
+ if (*Hardware)
+ {
+ if (!fs::exists(path)) // dbus object path
+ {
+ string p = getVpdFilePath(INVENTORY_JSON_SYM_LINK, path);
+ if (p.empty()) // object path not present in inventory json
+ {
+ string errorMsg = "Invalid object path : ";
+ errorMsg += path;
+ errorMsg += ". Unable to find the corresponding EEPROM "
+ "path for the given object path : ";
+ errorMsg += path;
+ errorMsg += " in the vpd inventory json : ";
+ errorMsg += INVENTORY_JSON_SYM_LINK;
+ throw runtime_error(errorMsg);
+ }
+ else
+ {
+ path = p;
+ }
+ }
+ }
if (*dumpObjFlag)
{
VpdTool vpdToolObj(move(objectPath));
@@ -90,10 +128,10 @@
vpdToolObj.readKeyword();
}
- else if (*writeFlag)
+ else if (*writeFlag && !*Hardware)
{
- VpdTool vpdToolObj(move(objectPath), move(recordName),
- move(keyword), move(val));
+ VpdTool vpdToolObj(move(path), move(recordName), move(keyword),
+ move(val));
rc = vpdToolObj.updateKeyword();
}
@@ -103,6 +141,13 @@
vpdToolObj.forceReset(jsObject);
}
+ else if (*writeFlag && *Hardware)
+ {
+ VpdTool vpdToolObj(move(path), move(recordName), move(keyword),
+ move(val));
+ rc = vpdToolObj.updateHardware();
+ }
+
else
{
throw runtime_error("One of the valid options is required. Refer "