Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for power vs configuration #597

Draft
wants to merge 1 commit into
base: 1110
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.')
8 changes: 8 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 Expand Up @@ -156,6 +160,10 @@ constexpr auto hostInterface = "xyz.openbmc_project.State.Host";
constexpr auto hostService = "xyz.openbmc_project.State.Host";
constexpr auto hostRunningState =
"xyz.openbmc_project.State.Host.HostState.Running";
constexpr auto functionalImageObjPath =
"/xyz/openbmc_project/software/functional";
constexpr auto associationInterface = "xyz.openbmc_project.Association";
constexpr auto powerVsImagePrefix = "MX";
static constexpr auto BD_YEAR_END = 4;
static constexpr auto BD_MONTH_END = 7;
static constexpr auto BD_DAY_END = 10;
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
37 changes: 37 additions & 0 deletions vpd-manager/include/utility/dbus_utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -564,5 +564,42 @@ inline int DisableRebootGuard() noexcept
return l_rc;
}

/**
* @brief API to return functioal image prefix.
*
* Every functional image belongs to a series which is denoted by the first two
* characters of the image name. The API extracts that and return that to the
* caller.
*
* @return Prefix of the image, empty string in case of any error.
*/
inline std::string getImagePrefix()
{
types::DbusVariantType l_retVal = readDbusProperty(
constants::objectMapperService, constants::functionalImageObjPath,
constants::associationInterface, "endpoints");

if (auto l_listOfFunctionalPath =
std::get_if<std::vector<std::string>>(&l_retVal))
{
// extract the first two character from the image name.
if (!(*l_listOfFunctionalPath).empty() &&
(*l_listOfFunctionalPath).at(0).length() > constants::VALUE_2)
{
std::string value = (*l_listOfFunctionalPath)
.at(0)
.sbstr(constants::VALUE_0,
constants::VALUE_2);

std::cout << value << std::endl;
// return first two character from image name.
return (*l_listOfFunctionalPath)
.at(0)
.sbstr(constants::VALUE_0, constants::VALUE_2);
}
}

return std::string;
}
} // namespace dbusUtility
} // namespace vpd
58 changes: 58 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,62 @@ 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) &&
(dbusUtility::getImagePrefix() ==
constants::powerVsImagePrefix))
{
return true;
}

logging::logMessage("Not a power VS configuration");
return false;
}

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