Vpd-tool: Hardware option fix
The -H hardware flag is given when the user wants to update hardware.
When -H flag is given, the user must provide the eeprom path and not
the object path in -O/object option.
Test:
1. When dbus object path is given with -H Hardware flag - tool throws error.
root@rainier:/tmp# ./vpd-tool -u -H -O /system/chassis/motherboard/vdd_vrm1 -R VINI -K CC -V 0x7172
Invalid EEPROM path : /system/chassis/motherboard/vdd_vrm1. The given EEPROM path doesn't exist. Provide valid EEPROM path when -H flag is used. Refer help option. root@rainier:/tmp#
2. To update directly on hardware -
( - this updates the keyword on ONLY hardware for those keywords which are not mentioned in /usr/share/vpd/dbus_properties.json)
( - if the given keyword is present in dbus_properties.json => then both HARDWARE AND DBUS are updated.)
./vpd-tool -u -H -O /sys/devices/platform/ahb/ahb:apb/ahb:apb:bus@1e78a000/1e78a580.i2c-bus/i2c-10/10-0050/10-00500/nvmem -R VINI -K CC -V 0x7172
Tested that both hardware and dbus is updated as the record-keyword VINI-CC is a part of dbus_properties.json.
3. To update on dbus and hardware ( no matter whether or not the record-keyword is present in dbus_properties.json.)
./vpd-tool -u -O /system/chassis/motherboard/vdd_vrm1 -R VINI -K DR -V 0x7172
4. Help option
root@rainier:/tmp# ./vpd-tool --help
VPD Command line tool to dump the inventory and to read and update the keywords
Usage: ./vpd-tool [OPTIONS]
Options:
-h,--help Print this help message and exit
-O,--object TEXT Enter the Object Path
-R,--record TEXT Enter the Record Name
-K,--keyword TEXT Enter the Keyword
-V,--value TEXT Enter the value. The value to be updated should be either in ascii or in hex. ascii eg: 01234; hex eg: 0x30313233
-o,--dumpObject Needs: --object
Dump the given object from the inventory. { vpd-tool-exe --dumpObject/-o --object/-O object-name }
-i,--dumpInventory Dump all the inventory objects. { vpd-tool-exe --dumpInventory/-i }
-r,--readKeyword Needs: --object --record --keyword
Read the data of the given keyword. { vpd-tool-exe --readKeyword/-r --object/-O "object-name" --record/-R "record-name" --keyword/-K "keyword-name" }
-w,-u,--writeKeyword,--updateKeyword Needs: --object --record --keyword --value
Update the value. { vpd-tool-exe --writeKeyword/-w/--updateKeyword/-u --object/-O object-name --record/-R record-name --keyword/-K keyword-name --value/-V value-to-be-updated }
-f,-F,--forceReset Force Collect for Hardware. { vpd-tool-exe --forceReset/-f/-F }
-H,--Hardware This is a supplementary flag to write directly to hardware. When the -H flag is given, User should provide valid hardware/eeprom path (and not dbus object path) in the -O/--object path.
Signed-off-by: PriyangaRamasamy <priyanga24@in.ibm.com>
Change-Id: Id6b808422651043c8e7115b5aeb19cb3102bbe85
diff --git a/vpd_tool.cpp b/vpd_tool.cpp
index a4891f6..a6087a0 100644
--- a/vpd_tool.cpp
+++ b/vpd_tool.cpp
@@ -21,7 +21,6 @@
string recordName{};
string keyword{};
string val{};
- string path{};
auto object =
app.add_option("--object, -O", objectPath, "Enter the Object Path");
@@ -32,11 +31,6 @@
"--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",
"Dump the given object from the inventory. { "
@@ -64,7 +58,7 @@
"--writeKeyword/-w/--updateKeyword/-u "
"--object/-O object-name --record/-R record-name --keyword/-K "
"keyword-name --value/-V value-to-be-updated }")
- ->needs(pathOption)
+ ->needs(object)
->needs(record)
->needs(kw)
->needs(valOption);
@@ -74,10 +68,9 @@
"--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.");
+ "This is a supplementary flag to write directly to hardware. When the "
+ "-H flag is given, User should provide valid hardware/eeprom path (and "
+ "not dbus object path) in the -O/--object path.");
CLI11_PARSE(app, argc, argv);
@@ -88,24 +81,15 @@
{
if (*Hardware)
{
- if (!fs::exists(path)) // dbus object path
+ if (!fs::exists(objectPath)) // if dbus object path is given or
+ // invalid eeprom path is given
{
- 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;
- }
+ string errorMsg = "Invalid EEPROM path : ";
+ errorMsg += objectPath;
+ errorMsg +=
+ ". The given EEPROM path doesn't exist. Provide valid "
+ "EEPROM path when -H flag is used. Refer help option. ";
+ throw runtime_error(errorMsg);
}
}
if (*dumpObjFlag)
@@ -129,8 +113,8 @@
else if (*writeFlag && !*Hardware)
{
- VpdTool vpdToolObj(move(path), move(recordName), move(keyword),
- move(val));
+ VpdTool vpdToolObj(move(objectPath), move(recordName),
+ move(keyword), move(val));
rc = vpdToolObj.updateKeyword();
}
@@ -142,8 +126,8 @@
else if (*writeFlag && *Hardware)
{
- VpdTool vpdToolObj(move(path), move(recordName), move(keyword),
- move(val));
+ VpdTool vpdToolObj(move(objectPath), move(recordName),
+ move(keyword), move(val));
rc = vpdToolObj.updateHardware();
}