Skip to content

Commit

Permalink
Implement vpd-tool mfgClean (#573)
Browse files Browse the repository at this point in the history
This commit implements vpd-tool --mfgClean option.
This API resets specific System VPD keywords to default value.
The System VPD keywords are fetched from backup_restore.json.

The specified keyword values are reset on:
  - Primary EEPROM path.
  - Redundant EEPROM path(if any)
  - D-Bus cache.
  - Backup path.

Test:
```
root@p10bmc:~# ./vpd-tool --mfgClean --yes
Cleaning System VPD...
Hardware path: "/sys/bus/i2c/drivers/at24/8-0050/eeprom"
Data updated successfully
Data updated successfully
Data updated successfully

 The critical keywords from system backplane VPD has been reset
 successfully.

root@p10bmc:~# ./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
Cleaning System VPD...
Hardware path: "/sys/bus/i2c/drivers/at24/8-0050/eeprom"

 The critical keywords from system backplane VPD has been reset successfully.
```

Change-Id: I55862fc4122a188e3e522dd64ed6bd1fa94335e8
Signed-off-by: Souvik Roy <souvik.roy10@ibm.com>
  • Loading branch information
Souvik Roy committed Jan 10, 2025
1 parent 64f8e0b commit 933e808
Showing 1 changed file with 110 additions and 3 deletions.
113 changes: 110 additions & 3 deletions vpd-tool/src/vpd_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,21 +197,128 @@ 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.
const nlohmann::json l_parsedBackupRestoreJson =
getBackupRestoreCfgJsonObj();

l_rc = constants::SUCCESS;
// flag to track any failure
bool l_anyFailure{false};

// check for mandatory tags
if (l_parsedBackupRestoreJson.contains("source") &&
l_parsedBackupRestoreJson.contains("backupMap") &&
l_parsedBackupRestoreJson["source"].contains("hardwarePath") &&
l_parsedBackupRestoreJson["backupMap"].is_array())
{
// get the source hardware path
const auto& l_hardwarePath =
l_parsedBackupRestoreJson["source"]["hardwarePath"];

// iterate through the backup map
for (const auto& l_aRecordKwInfo :
l_parsedBackupRestoreJson["backupMap"])
{
// check if Manufacturing Reset is required for this entry
const bool l_isMfgCleanRequired =
l_aRecordKwInfo.value("isManufactureResetRequired", false);

if (l_isMfgCleanRequired)
{
// get the Record name and Keyword name
const std::string& l_srcRecordName =
l_aRecordKwInfo.value("sourceRecord", "");
const std::string& l_srcKeywordName =
l_aRecordKwInfo.value("sourceKeyword", "");

// validate the Record name, Keyword name and the
// defaultValue
if (!l_srcRecordName.empty() && !l_srcKeywordName.empty() &&
l_aRecordKwInfo.contains("defaultValue") &&
l_aRecordKwInfo["defaultValue"].is_array())
{
const types::BinaryVector l_defaultBinaryValue =
l_aRecordKwInfo["defaultValue"]
.get<types::BinaryVector>();

// get the value on hardware
const auto& l_keywordValue =
utils::readKeywordFromHardware(
l_hardwarePath,
std::make_tuple(l_srcRecordName,
l_srcKeywordName));

if (const auto l_keywordValueHW =
std::get_if<types::BinaryVector>(
&l_keywordValue);
l_keywordValueHW && !l_keywordValueHW->empty())
{
// check if value on hardware is default, if
// not write default value to hardware
if (*l_keywordValueHW != l_defaultBinaryValue)
{
if (constants::FAILURE ==
utils::writeKeyword(
l_hardwarePath,
std::make_tuple(l_srcRecordName,
l_srcKeywordName,
l_defaultBinaryValue)))
{
// TODO: Enable logging when verbose
// is enabled.
std::cerr << "Failed to update "
<< l_srcRecordName << ":"
<< l_srcKeywordName << std::endl;
l_anyFailure = true;
}
}
}
else
{
l_anyFailure = true;
// TODO: Enable logging when verbose is enabled.
std::cerr
<< "Couldn't read default value for record name: " +
l_srcRecordName +
", keyword name: " + l_srcKeywordName +
" from backup and restore config JSON file."
<< std::endl;
}
}
else
{
std::cerr << "Backup Restore JSON is not valid"
<< std::endl;
l_anyFailure = true;
}
}
} // keyword loop
}
else
{
std::cerr << "Backup Restore JSON is not valid" << std::endl;
l_anyFailure = true;
}

if (!l_anyFailure)
{
l_rc = constants::SUCCESS;
std::cout
<< "\n The critical keywords from system backplane VPD has "
"been reset successfully."
<< std::endl;
}
}
catch (const std::exception& l_ex)
{
// TODO: Enable logging when verbose is enabled.
std::cerr << l_ex.what() << std::endl;
std::cerr << "Manufacturing clean failed.Error : " << l_ex.what()
<< std::endl;
}
return l_rc;
}
Expand Down

0 comments on commit 933e808

Please sign in to comment.