Skip to content

Commit

Permalink
Check for power vs configuration
Browse files Browse the repository at this point in the history
Signed-off-by: Sunny Srivastava <[email protected]>
  • Loading branch information
SunnySrivastava1984 committed Jan 20, 2025
1 parent 8d35fae commit 239714c
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 3 deletions.
27 changes: 27 additions & 0 deletions configuration/ibm/5000_power_vs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"/sys/bus/spi/drivers/at25/spi12.0/eeprom": {
"VINI": {
"PN": [49, 50, 51, 52, 53, 54]
}
},
"/sys/bus/spi/drivers/at25/spi22.0/eeprom": {
"VINI" : {
"PN": [49, 50, 51, 52, 53, 54, 55]
}
},
"/sys/bus/spi/drivers/at25/spi32.0/eeprom": {
"VINI": {
"PN": [49, 50, 51, 52, 53, 54, 55, 56]
}
},
"/sys/bus/spi/drivers/at25/spi42.0/eeprom": {
"VINI": {
"PN": [49, 50, 51, 52, 53, 54, 55, 56, 57]
}
},
"/sys/bus/i2c/drivers/at24/8-0051/eeprom": {
"VINI": {
"PN": [49, 50, 51, 52, 53]
}
}
}
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ conf_data.set_quoted('JSON_ABSOLUTE_PATH_PREFIX', get_option('JSON_ABSOLUTE_PATH
conf_data.set_quoted('SYSTEM_VPD_FILE_PATH', get_option('SYSTEM_VPD_FILE_PATH'))
conf_data.set_quoted('VPD_SYMLIMK_PATH', get_option('VPD_SYMLIMK_PATH'))
conf_data.set_quoted('PIM_PATH_PREFIX', get_option('PIM_PATH_PREFIX'))
conf_data.set_quoted('POWER_VS_JSON_5000', get_option('POWER_VS_JSON_5000'))
configure_file(output: 'config.h',
configuration : conf_data)

Expand Down
3 changes: 2 additions & 1 deletion meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ option('JSON_ABSOLUTE_PATH_PREFIX', type: 'string', value: '/usr/share/vpd/', d
option('SYSTEM_VPD_FILE_PATH', type: 'string', value: '/sys/bus/i2c/drivers/at24/8-0050/eeprom', description: 'EEPROM path of system VPD.')
option('VPD_SYMLIMK_PATH', type: 'string', value: '/var/lib/vpd', description: 'Symlink folder for VPD invnetory JSONs')
option('PIM_PATH_PREFIX', type: 'string', value: '/xyz/openbmc_project/inventory', description: 'Prefix for PIM inventory paths.')
option('ibm_system', type: 'feature', value : 'enabled', description: 'Enable code specific to IBM systems.')
option('ibm_system', type: 'feature', value : 'enabled', description: 'Enable code specific to IBM systems.')
option('POWER_VS_JSON_5000', type: 'string', value : '/usr/share/vpd/5000_power_vs.json', description: 'Json file that contains part number with respect to PowerVS system.')
4 changes: 4 additions & 0 deletions vpd-manager/include/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ static constexpr auto SIZE_OF_8EQ_IN_PG = 24;
// Zero based index position of first EQ in CP00's PG keyword
static constexpr auto INDEX_OF_EQ0_IN_PG = 97;

static constexpr auto HEX_VALUE_50 = 0x50;

constexpr auto systemInvPath = "/xyz/openbmc_project/inventory/system";
constexpr auto pimPath = "/xyz/openbmc_project/inventory";
constexpr auto pimIntf = "xyz.openbmc_project.Inventory.Manager";
Expand All @@ -120,9 +122,11 @@ constexpr auto kwdVpdInf = "com.ibm.ipzvpd.VINI";
constexpr auto vsysInf = "com.ibm.ipzvpd.VSYS";
constexpr auto utilInf = "com.ibm.ipzvpd.UTIL";
constexpr auto vcenInf = "com.ibm.ipzvpd.VCEN";
constexpr auto vsbpInf = "com.ibm.ipzvpd.VSBP";
constexpr auto kwdCCIN = "CC";
constexpr auto kwdRG = "RG";
constexpr auto kwdAMM = "D0";
constexpr auto kwdIM = "IM";
constexpr auto kwdClearNVRAM_CreateLPAR = "D1";
constexpr auto kwdKeepAndClear = "D1";
constexpr auto kwdFC = "FC";
Expand Down
5 changes: 5 additions & 0 deletions vpd-manager/include/manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,11 @@ class Manager
*/
void registerHostStateChangeCallback();

/**
* @brief API to update VPD related to power vs system.
*/
void updatePowerVsVpd();

/**
* @brief API to process host state change callback.
*
Expand Down
54 changes: 54 additions & 0 deletions vpd-manager/include/utility/vpd_specific_utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <nlohmann/json.hpp>
#include <utility/common_utility.hpp>
#include <utility/dbus_utility.hpp>
#include <utility/json_utility.hpp>

#include <filesystem>
#include <fstream>
Expand Down Expand Up @@ -552,5 +553,58 @@ inline void resetDataUnderPIM(const std::string& i_objectPath,
" with error: " + std::string(l_ex.what()));
}
}

/**
* @brief API to detect of system configuration is that of PowerVS system.
*
* @param[in] i_sysConfigJson - System config JSON object.
* @return True if it is PowerVS configuration, false otherwise.
*/
inline bool isPowerVsConfiguration(const nlohmann::json& i_sysConfigJson)
{
try
{
if (i_sysConfigJson.empty())
{
throw std::runtime_error("Invalid system config JSON.");
}

const auto& l_inventoryPath = jsonUtility::getInventoryObjPathFromJson(
i_sysConfigJson, SYSTEM_VPD_FILE_PATH);

if (l_inventoryPath.empty())
{
throw std::runtime_error(
"Inventory path not found in Json for system VPD filepath.");
}

const auto& l_retValue = dbusUtility::readDbusProperty(
constants::pimServiceName, l_inventoryPath, constants::vsbpInf,
constants::kwdIM);

if (auto l_imValue = std::get_if<types::BinaryVector>(&l_retValue))
{
if (((*l_imValue).at(0) == constants::HEX_VALUE_50) /*&&
(getImagePrefix() == "MX")*/)
{
return true;
}
}

throw std::runtime_error(
"Invalid type recieved while reading system IM.");
}
catch (const std::exception& l_ex)
{
EventLogger::createSyncPel(
types::ErrorType::InvalidSystem, types::SeverityType::Informational,
__FILE__, __FUNCTION__, 0,
"Failed to process powerVS configuration with error: " +
std::string(l_ex.what()),
std::nullopt, std::nullopt, std::nullopt, std::nullopt);

return false;
}
}
} // namespace vpdSpecificUtility
} // namespace vpd
70 changes: 68 additions & 2 deletions vpd-manager/src/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include <sdbusplus/bus/match.hpp>
#include <sdbusplus/message.hpp>

#include <typeindex>

namespace vpd
{
Manager::Manager(
Expand Down Expand Up @@ -272,11 +274,18 @@ void Manager::SetTimerToDetectVpdCollectionStatus()
{
// cancel the timer
l_timer.cancel();
m_interface->set_property("CollectionStatus",
std::string("Completed"));

const nlohmann::json& l_sysCfgJsonObj =
m_worker->getSysCfgJsonObj();

if (vpdSpecificUtility::isPowerVsConfiguration(l_sysCfgJsonObj))
{
updatePowerVsVpd();
}

m_interface->set_property("CollectionStatus",
std::string("Completed"));

if (jsonUtility::isBackupAndRestoreRequired(l_sysCfgJsonObj))
{
BackupAndRestore l_backupAndRestoreObj(l_sysCfgJsonObj);
Expand Down Expand Up @@ -910,4 +919,61 @@ void Manager::performVpdRecollection()
std::string(l_ex.what()));
}
}

void Manager::updatePowerVsVpd()
{
try
{
nlohmann::json l_parsedPwrVsJson =
jsonUtility::getParsedJson(POWER_VS_JSON_5000);

for (const auto& [l_path, l_recJson] : l_parsedPwrVsJson.items())
{
std::cout << "Path = " << l_path << std::endl;

for (const auto& [l_recordName, l_kwdJson] : l_recJson.items())
{
std::cout << "record name = " << l_recordName << std::endl;

for (const auto& [l_kwdName, l_kwdValue] : l_kwdJson.items())
{
std::cout << "kwd name = " << l_kwdName << std::endl;

std::cout << "kwd value size = " << l_kwdValue.size()
<< std::endl;
if (l_kwdValue.is_array())
{
std::cout << "Is array";
types::BinaryVector l_binaryKwdValue =
l_kwdValue.get<types::BinaryVector>();

for (auto item : l_binaryKwdValue)
{
std::cout << (int)item << " ";
}
std::cout << std::endl;
}

/* if (updateKeyword(l_path,
std::make_tuple(l_recordName, l_kwdName,
l_kwdValue)) ==
constants::FAILURE)
{
// TODO should we stop all updates or log this failure
// and continue with rest of the updates.
}*/
}
}
}
}
catch (const std::exception& l_ex)
{
/* types::ErrorType l_errTYype = types::ErrorType::InvalidSystem;
if (typeid(l_ex) == std::type_index(typeid(JsonException)))
{
l_errTYype = types::ErrorType::JsonFailure;
}*/
}
}
} // namespace vpd

0 comments on commit 239714c

Please sign in to comment.