Skip to content

Commit

Permalink
Implement vpd-tool mfgClean (ibm-openbmc#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
Manufacturing clean is successful

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
Manufacturing clean is successful

```

Change-Id: I55862fc4122a188e3e522dd64ed6bd1fa94335e8
Signed-off-by: Souvik Roy <souvik.roy10@ibm.com>
  • Loading branch information
Souvik Roy committed Jan 13, 2025
1 parent 70a1a3f commit f62f345
Showing 1 changed file with 93 additions and 12 deletions.
105 changes: 93 additions & 12 deletions vpd-tool/src/vpd_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,21 +322,101 @@ 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.
// get the keyword map from backup_restore json
// iterate through the keyword map get default value of
// l_keywordName.
// use writeKeyword API to update default value on hardware,
// backup and D - Bus.
const nlohmann::json l_parsedBackupRestoreJson =
getBackupRestoreCfgJsonObj();

// 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"];

l_rc = constants::SUCCESS;
}
// 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>();

// update the Keyword with default value, use D-Bus
// method UpdateKeyword exposed by vpd-manager.
// Note: writing to all paths (Primary EEPROM path,
// Secondary EEPROM path, D-Bus cache and Backup path)
// is the responsibility of vpd-manager's UpdateKeyword
// API
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
{
std::cerr
<< "Invalid keyword entry in Backup Restore JSON backup map"
<< std::endl;
l_anyFailure = true;
}
} // mfgClean required check
} // keyword list loop
}
else // backupRestoreJson is not valid
{
std::cerr << "Backup Restore JSON is not valid" << std::endl;
l_anyFailure = true;
}

// success/failure message
std::cout << "Manufacturing clean "
<< std::string(l_anyFailure ? " has failed"
: " is successful.")
<< std::endl;

} // try block end
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 Expand Up @@ -389,7 +469,8 @@ bool VpdTool::isFruPresent(const std::string& i_objectPath) const noexcept
{
// TODO: Enable logging when verbose is enabled.
// std::cerr << "Failed to check \"Present\" property for FRU "
// << i_objectPath << " Error: " << l_ex.what() << std::endl;
// << i_objectPath << " Error: " << l_ex.what() <<
// std::endl;
}
return l_returnValue;
}
Expand Down

0 comments on commit f62f345

Please sign in to comment.