Skip to content

Commit

Permalink
Implement vpd-tool mfgClean
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 specified keyword values are reset on:
  - Primary EEPROM path.
  - Redundant EEPROM path(if any)
  - D-Bus cache.
  - Backup path.

The specific System VPD keywords are maintained as a static read only
map in the code.

Change-Id: I18fffc04a5fbf7a972074621dd817049b89b5860
Signed-off-by: Souvik Roy <souvik.roy10@ibm.com>
  • Loading branch information
Souvik Roy committed Jan 9, 2025
1 parent ec2f582 commit 0503e13
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
2 changes: 1 addition & 1 deletion vpd-tool/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ sources = ['src/vpd_tool_main.cpp',

vpd_tool_exe = executable('vpd-tool',
sources,
include_directories : ['include/'],
include_directories : ['include/','../'],
dependencies: dependency_list,
install: true
)
45 changes: 41 additions & 4 deletions vpd-tool/src/vpd_tool.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "config.h"

#include "vpd_tool.hpp"

#include "tool_constants.hpp"
Expand Down Expand Up @@ -215,16 +217,51 @@ int VpdTool::cleanSystemVpd() const noexcept
// if hardware value != default value,
// use writeKeyword API to update default value on hardware,
// backup and D - Bus.
(void)g_systemVpdKeywordMap;
for (const auto& l_entry : g_systemVpdKeywordMap)
{
const auto& l_recordName = l_entry.first;
const auto& l_keyWordMap = l_entry.second;
for (const auto& l_keywordTuple : l_keyWordMap)
{
// check if MFG reset is required for this keyword
if (!std::get<2>(l_keywordTuple))
{
continue;
}

const auto& l_keywordName = std::get<0>(l_keywordTuple);
const auto& l_keywordValueDefault = std::get<1>(l_keywordTuple);

// read keyword value on hardware
const types::DbusVariantType l_keywordValue =
utils::readKeywordFromHardware(
SYSTEM_VPD_FILE_PATH,
std::make_tuple(l_recordName, l_keywordName));

if (const auto l_keywordValueHW =
std::get_if<types::BinaryVector>(&l_keywordValue);
l_keywordValueHW && !l_keywordValueHW->empty())
{
if (*l_keywordValueHW != l_keywordValueDefault)
{
// do writeKeyword and update with default value.
l_rc = utils::writeKeyword(
SYSTEM_VPD_FILE_PATH,
std::make_tuple(l_recordName, l_keywordName,
l_keywordValueDefault));
}
}
}
}

l_rc = constants::SUCCESS;
}
catch (const std::exception& l_ex)
{
// TODO: Enable logging when verbose is enabled.
// std::cerr << "Manufacturing clean failed for " << i_recordName << ":"
// << i_keywordName << ". Error : " << l_ex.what() <<
// std::endl;
// std::cerr << "Manufacturing clean failed. Error : " << l_ex.what()
// << std::endl;
l_rc = constants::FAILURE;
}

return l_rc;
Expand Down

0 comments on commit 0503e13

Please sign in to comment.