Skip to content

Commit

Permalink
Implement vpd-tool mfgClean stub (#561)
Browse files Browse the repository at this point in the history
This commit implements vpd-tool mfgClean stub which allows the user to
select --mfgClean option. The actual implementation of mfgClean is yet
to be implemented.

Test:

```
root@p10bmc:/tmp# ./vpd-tool --mfgClean --yes
root@p10bmc:~# echo $?
0
root@p10bmc:/tmp# ./vpd-tool --mfgClean
This option resets some of the system VPD keywords to their default
values. Do you really wish to proceed further?[yes/no]:yes
root@p10bmc:~# echo $?
0
```

Change-Id: I472c1000ad2fd769a28d11b93cb52687628a215b
Signed-off-by: Souvik Roy <souvik.roy10@ibm.com>
  • Loading branch information
Souvik Roy committed Jan 10, 2025
1 parent e9cdb93 commit f80293a
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
14 changes: 14 additions & 0 deletions vpd-tool/include/vpd_tool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,19 @@ class VpdTool
const std::string& i_keywordName,
const std::string& i_keywordValue,
const bool i_onHardware) noexcept;

/**
* @brief Reset specific keywords on System VPD to default value.
*
* This API resets specific System VPD keywords to default value. The
* keyword values are reset on:
* 1. Primary EEPROM path.
* 2. Secondary EEPROM path.
* 3. D-Bus cache.
* 4. Backup path.
*
* @return On success returns 0, otherwise returns -1.
*/
int cleanSystemVpd() const noexcept;
};
} // namespace vpd
25 changes: 25 additions & 0 deletions vpd-tool/src/vpd_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,29 @@ nlohmann::json VpdTool::getBackupRestoreCfgJsonObj() const noexcept

return l_parsedBackupRestoreJson;
}

int VpdTool::cleanSystemVpd() const noexcept
{
int l_rc{constants::FAILURE};
try
{
// TODO:
// get the keyword map from backup_restore json
// iterate through the keyword map get default value of
// l_keywordName.
// use readKeyword API to read hardware value from hardware.
// if hardware value != default value,
// use writeKeyword API to update default value on hardware,
// backup and D - Bus.

l_rc = constants::SUCCESS;
}
catch (const std::exception& l_ex)
{
// TODO: Enable logging when verbose is enabled.
std::cerr << l_ex.what() << std::endl;
}
return l_rc;
}

} // namespace vpd
37 changes: 36 additions & 1 deletion vpd-tool/src/vpd_tool_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ int main(int argc, char** argv)
" From DBus to console: "
"vpd-tool -o -O <DBus Object Path>\n"
"Fix System VPD:\n"
" vpd-tool --fixSystemVPD");
" vpd-tool --fixSystemVPD\n"
"MfgClean:\n"
" Flag to clean and reset specific keywords on system VPD to its default value.\n"
" vpd-tool --mfgClean\n");

auto l_objectOption = l_app.add_option("--object, -O", l_vpdPath,
"File path");
Expand Down Expand Up @@ -88,6 +91,13 @@ int main(int argc, char** argv)
"--fixSystemVPD",
"Use this option to interactively fix critical system VPD keywords");

auto l_mfgCleanFlag = l_app.add_flag(
"--mfgClean", "Manufacturing clean on system VPD keyword");

auto l_mfgCleanConfirmFlag = l_app.add_flag(
"--yes", "Using this flag with --mfgClean option, assumes "
"yes to proceed without confirmation.");

CLI11_PARSE(l_app, argc, argv);

if (!l_objectOption->empty() && l_vpdPath.empty())
Expand Down Expand Up @@ -187,6 +197,31 @@ int main(int argc, char** argv)
vpd::VpdTool l_vpdToolObj;
l_rc = l_vpdToolObj.fixSystemVpd();
}
else if (!l_mfgCleanFlag->empty())
{
bool l_shouldCleanSystemVpd{true};
if (l_mfgCleanConfirmFlag->empty())
{
constexpr auto MAX_CONFIRMATION_STR_LENGTH{3};
std::string l_confirmation{};
std::cout
<< "This option resets some of the system VPD keywords to their default values. Do you really wish to proceed further?[yes/no]:";
std::cin >> std::setw(MAX_CONFIRMATION_STR_LENGTH) >>
l_confirmation;

if (l_confirmation != "yes")
{
l_shouldCleanSystemVpd = false;
l_rc = vpd::constants::SUCCESS;
}
}

if (l_shouldCleanSystemVpd)
{
vpd::VpdTool l_vpdToolObj;
l_rc = l_vpdToolObj.cleanSystemVpd();
}
}
else
{
std::cout << l_app.help() << std::endl;
Expand Down

0 comments on commit f80293a

Please sign in to comment.