vpd-tool --mfgClean implementation
vpd-tool supports a new option --mfgClean, which cleans specific
keywords in system backplane VPD and restore it with their default
value.
This option will be used to ensure that the VPD is properly defaulted
in the FRU stock.
The FAB test will make use this option to reset system
backplane VPD keywords to its defaults.
vpd-tool --mfgClean --yes
====================
Test:
./vpd-tool --mfgClean
This option resets some of the critical keywords in System Backplane VPD
to its default value. Do you really wish to proceed further?[yes/no]: yes
The critical keywords from system backplane VPD has been reset successfully.
./vpd-tool --mfgClean --yes
The critical keywords from system backplane VPD has been reset successfully.
Verified that the critical keywords have been reset to defaults.
Signed-off-by: Priyanga Ramasamy <priyanga24@in.ibm.com>
Change-Id: Ia53498d222f2828d07a7d170291e641b7f69f9ac
diff --git a/types.hpp b/types.hpp
index cb7a121..7619aef 100644
--- a/types.hpp
+++ b/types.hpp
@@ -77,6 +77,8 @@
using GetAllResultType = std::vector<std::pair<Keyword, Value>>;
using IntfPropMap = std::map<RecordName, GetAllResultType>;
+using RecKwValMap =
+ std::unordered_map<RecordName, std::unordered_map<Keyword, Binary>>;
} // namespace inventory
} // namespace vpd
diff --git a/vpd_tool.cpp b/vpd_tool.cpp
index a0699bb..61518bd 100644
--- a/vpd_tool.cpp
+++ b/vpd_tool.cpp
@@ -84,6 +84,14 @@
"--fixSystemVPD", "Use this option to interactively fix critical "
"system VPD keywords {vpd-tool-exe --fixSystemVPD}");
+ auto mfgClean =
+ app.add_flag("--mfgClean", "Flag to clean and reset specific keywords "
+ "on system VPD to its default value.");
+
+ auto confirm =
+ app.add_flag("--yes", "Using this flag with --mfgClean option, assumes "
+ "yes to proceed without confirmation.");
+
CLI11_PARSE(app, argc, argv);
ifstream inventoryJson(INVENTORY_JSON_SYM_LINK);
@@ -164,6 +172,24 @@
VpdTool vpdToolObj;
rc = vpdToolObj.fixSystemVPD();
}
+ else if (*mfgClean)
+ {
+ if (!*confirm)
+ {
+ std::string confirmation{};
+ std::cout << "\nThis option resets some of the system VPD "
+ "keywords to their default values. Do you really "
+ "wish to proceed further?[yes/no]: ";
+ std::cin >> confirmation;
+
+ if (confirmation != "yes")
+ {
+ return 0;
+ }
+ }
+ VpdTool vpdToolObj;
+ rc = vpdToolObj.cleanSystemVPD();
+ }
else
{
throw runtime_error("One of the valid options is required. Refer "
diff --git a/vpd_tool_impl.cpp b/vpd_tool_impl.cpp
index 6c32ec1..6244018 100644
--- a/vpd_tool_impl.cpp
+++ b/vpd_tool_impl.cpp
@@ -968,4 +968,70 @@
}
} while (true);
+}
+
+int VpdTool::cleanSystemVPD()
+{
+ try
+ {
+ // Get system VPD hardware data in map
+ unordered_map<string, DbusPropertyMap> vpdMap;
+ json js;
+ getVPDInMap(constants::systemVpdFilePath, vpdMap, js,
+ constants::pimPath +
+ static_cast<std::string>(constants::SYSTEM_OBJECT));
+
+ RecKwValMap kwdsToBeUpdated;
+
+ for (auto recordMap : svpdKwdMap)
+ {
+ const auto& record = recordMap.first;
+ std::unordered_map<std::string, Binary> kwDefault;
+ for (auto keywordMap : recordMap.second)
+ {
+ // Skip those keywords which cannot be reset at manufacturing
+ if (!std::get<3>(keywordMap))
+ {
+ continue;
+ }
+ const auto& keyword = std::get<0>(keywordMap);
+
+ // Get hardware value for this keyword from vpdMap
+ Binary hardwareValue;
+
+ auto recItr = vpdMap.find(record);
+
+ if (recItr != vpdMap.end())
+ {
+ DbusPropertyMap& kwValMap = recItr->second;
+ auto kwItr = kwValMap.find(keyword);
+ if (kwItr != kwValMap.end())
+ {
+ hardwareValue = toBinary(kwItr->second);
+ }
+ }
+
+ // compare hardware value with the keyword's default value
+ auto defaultValue = std::get<1>(keywordMap);
+ if (hardwareValue != defaultValue)
+ {
+ EditorImpl edit(constants::systemVpdFilePath, js, record,
+ keyword);
+ edit.updateKeyword(defaultValue, 0, true);
+ }
+ }
+ }
+
+ std::cout
+ << "\n The critical keywords from system backplane VPD has been "
+ "reset successfully."
+ << std::endl;
+ }
+ catch (const std::exception& e)
+ {
+ std::cerr << e.what();
+ std::cerr
+ << "\nManufacturing reset on system vpd keywords is unsuccessful";
+ }
+ return 0;
}
\ No newline at end of file
diff --git a/vpd_tool_impl.hpp b/vpd_tool_impl.hpp
index fc9b225..4a75a71 100644
--- a/vpd_tool_impl.hpp
+++ b/vpd_tool_impl.hpp
@@ -251,6 +251,13 @@
int fixSystemVPD();
/**
+ * @brief Clean specific keywords in system backplane VPD
+ *
+ * @return return code (success/failure)
+ */
+ int cleanSystemVPD();
+
+ /**
* @brief Constructor
* Constructor is called during the
* object instantiation for dumpInventory option and