From 0503e13f68350e4ebbbe12c896da823163239d77 Mon Sep 17 00:00:00 2001 From: Souvik Roy Date: Wed, 8 Jan 2025 06:26:45 -0600 Subject: [PATCH] Implement vpd-tool mfgClean 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 --- vpd-tool/meson.build | 2 +- vpd-tool/src/vpd_tool.cpp | 45 +++++++++++++++++++++++++++++++++++---- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/vpd-tool/meson.build b/vpd-tool/meson.build index 403c9cb8..83ed3c87 100644 --- a/vpd-tool/meson.build +++ b/vpd-tool/meson.build @@ -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 ) \ No newline at end of file diff --git a/vpd-tool/src/vpd_tool.cpp b/vpd-tool/src/vpd_tool.cpp index 04c4d6a4..2da5875c 100644 --- a/vpd-tool/src/vpd_tool.cpp +++ b/vpd-tool/src/vpd_tool.cpp @@ -1,3 +1,5 @@ +#include "config.h" + #include "vpd_tool.hpp" #include "tool_constants.hpp" @@ -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(&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;