Skip to content

Commit e456b79

Browse files
Check for power vs configuration
Signed-off-by: Sunny Srivastava <[email protected]>
1 parent f41b758 commit e456b79

File tree

8 files changed

+206
-3
lines changed

8 files changed

+206
-3
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"/sys/bus/spi/drivers/at25/spi12.0/eeprom": {
3+
"VINI": {
4+
"PN": [49, 50, 51, 52, 53, 54]
5+
}
6+
},
7+
"/sys/bus/spi/drivers/at25/spi22.0/eeprom": {
8+
"VINI" : {
9+
"PN": [49, 50, 51, 52, 53, 54, 55]
10+
}
11+
},
12+
"/sys/bus/spi/drivers/at25/spi32.0/eeprom": {
13+
"VINI": {
14+
"PN": [49, 50, 51, 52, 53, 54, 55, 56]
15+
}
16+
},
17+
"/sys/bus/spi/drivers/at25/spi42.0/eeprom": {
18+
"VINI": {
19+
"PN": [49, 50, 51, 52, 53, 54, 55, 56, 57]
20+
}
21+
},
22+
"/sys/bus/i2c/drivers/at24/8-0051/eeprom": {
23+
"VINI": {
24+
"PN": [49, 50, 51, 52, 53]
25+
}
26+
}
27+
}

meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ conf_data.set_quoted('JSON_ABSOLUTE_PATH_PREFIX', get_option('JSON_ABSOLUTE_PATH
4747
conf_data.set_quoted('SYSTEM_VPD_FILE_PATH', get_option('SYSTEM_VPD_FILE_PATH'))
4848
conf_data.set_quoted('VPD_SYMLIMK_PATH', get_option('VPD_SYMLIMK_PATH'))
4949
conf_data.set_quoted('PIM_PATH_PREFIX', get_option('PIM_PATH_PREFIX'))
50+
conf_data.set_quoted('POWER_VS_JSON_5000', get_option('POWER_VS_JSON_5000'))
5051
configure_file(output: 'config.h',
5152
configuration : conf_data)
5253

meson_options.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ option('JSON_ABSOLUTE_PATH_PREFIX', type: 'string', value: '/usr/share/vpd/', d
1010
option('SYSTEM_VPD_FILE_PATH', type: 'string', value: '/sys/bus/i2c/drivers/at24/8-0050/eeprom', description: 'EEPROM path of system VPD.')
1111
option('VPD_SYMLIMK_PATH', type: 'string', value: '/var/lib/vpd', description: 'Symlink folder for VPD invnetory JSONs')
1212
option('PIM_PATH_PREFIX', type: 'string', value: '/xyz/openbmc_project/inventory', description: 'Prefix for PIM inventory paths.')
13-
option('ibm_system', type: 'feature', value : 'enabled', description: 'Enable code specific to IBM systems.')
13+
option('ibm_system', type: 'feature', value : 'enabled', description: 'Enable code specific to IBM systems.')
14+
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.')

vpd-manager/include/constants.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ static constexpr auto SIZE_OF_8EQ_IN_PG = 24;
112112
// Zero based index position of first EQ in CP00's PG keyword
113113
static constexpr auto INDEX_OF_EQ0_IN_PG = 97;
114114

115+
static constexpr auto HEX_VALUE_50 = 0x50;
116+
115117
constexpr auto systemInvPath = "/xyz/openbmc_project/inventory/system";
116118
constexpr auto pimPath = "/xyz/openbmc_project/inventory";
117119
constexpr auto pimIntf = "xyz.openbmc_project.Inventory.Manager";
@@ -120,9 +122,11 @@ constexpr auto kwdVpdInf = "com.ibm.ipzvpd.VINI";
120122
constexpr auto vsysInf = "com.ibm.ipzvpd.VSYS";
121123
constexpr auto utilInf = "com.ibm.ipzvpd.UTIL";
122124
constexpr auto vcenInf = "com.ibm.ipzvpd.VCEN";
125+
constexpr auto vsbpInf = "com.ibm.ipzvpd.VSBP";
123126
constexpr auto kwdCCIN = "CC";
124127
constexpr auto kwdRG = "RG";
125128
constexpr auto kwdAMM = "D0";
129+
constexpr auto kwdIM = "IM";
126130
constexpr auto kwdClearNVRAM_CreateLPAR = "D1";
127131
constexpr auto kwdKeepAndClear = "D1";
128132
constexpr auto kwdFC = "FC";
@@ -156,6 +160,10 @@ constexpr auto hostInterface = "xyz.openbmc_project.State.Host";
156160
constexpr auto hostService = "xyz.openbmc_project.State.Host";
157161
constexpr auto hostRunningState =
158162
"xyz.openbmc_project.State.Host.HostState.Running";
163+
constexpr auto functionalImageObjPath =
164+
"/xyz/openbmc_project/software/functional";
165+
constexpr auto associationInterface = "xyz.openbmc_project.Association";
166+
constexpr auto powerVsImagePrefix = "MX";
159167
static constexpr auto BD_YEAR_END = 4;
160168
static constexpr auto BD_MONTH_END = 7;
161169
static constexpr auto BD_DAY_END = 10;

vpd-manager/include/manager.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,11 @@ class Manager
271271
*/
272272
void registerHostStateChangeCallback();
273273

274+
/**
275+
* @brief API to update VPD related to power vs system.
276+
*/
277+
void updatePowerVsVpd();
278+
274279
/**
275280
* @brief API to process host state change callback.
276281
*

vpd-manager/include/utility/dbus_utility.hpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,5 +564,42 @@ inline int DisableRebootGuard() noexcept
564564
return l_rc;
565565
}
566566

567+
/**
568+
* @brief API to return functioal image prefix.
569+
*
570+
* Every functional image belongs to a series which is denoted by the first two
571+
* characters of the image name. The API extracts that and return that to the
572+
* caller.
573+
*
574+
* @return Prefix of the image, empty string in case of any error.
575+
*/
576+
inline std::string getImagePrefix()
577+
{
578+
types::DbusVariantType l_retVal = readDbusProperty(
579+
constants::objectMapperService, constants::functionalImageObjPath,
580+
constants::associationInterface, "endpoints");
581+
582+
if (auto l_listOfFunctionalPath =
583+
std::get_if<std::vector<std::string>>(&l_retVal))
584+
{
585+
// extract the first two character from the image name.
586+
if (!(*l_listOfFunctionalPath).empty() &&
587+
(*l_listOfFunctionalPath).at(0).length() > constants::VALUE_2)
588+
{
589+
std::string value = (*l_listOfFunctionalPath)
590+
.at(0)
591+
.sbstr(constants::VALUE_0,
592+
constants::VALUE_2);
593+
594+
std::cout << value << std::endl;
595+
// return first two character from image name.
596+
return (*l_listOfFunctionalPath)
597+
.at(0)
598+
.sbstr(constants::VALUE_0, constants::VALUE_2);
599+
}
600+
}
601+
602+
return std::string;
603+
}
567604
} // namespace dbusUtility
568605
} // namespace vpd

vpd-manager/include/utility/vpd_specific_utility.hpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <nlohmann/json.hpp>
1111
#include <utility/common_utility.hpp>
1212
#include <utility/dbus_utility.hpp>
13+
#include <utility/json_utility.hpp>
1314

1415
#include <filesystem>
1516
#include <fstream>
@@ -552,5 +553,62 @@ inline void resetDataUnderPIM(const std::string& i_objectPath,
552553
" with error: " + std::string(l_ex.what()));
553554
}
554555
}
556+
557+
/**
558+
* @brief API to detect of system configuration is that of PowerVS system.
559+
*
560+
* @param[in] i_sysConfigJson - System config JSON object.
561+
* @return True if it is PowerVS configuration, false otherwise.
562+
*/
563+
inline bool isPowerVsConfiguration(const nlohmann::json& i_sysConfigJson)
564+
{
565+
try
566+
{
567+
if (i_sysConfigJson.empty())
568+
{
569+
throw std::runtime_error("Invalid system config JSON.");
570+
}
571+
572+
const auto& l_inventoryPath = jsonUtility::getInventoryObjPathFromJson(
573+
i_sysConfigJson, SYSTEM_VPD_FILE_PATH);
574+
575+
if (l_inventoryPath.empty())
576+
{
577+
throw std::runtime_error(
578+
"Inventory path not found in Json for system VPD filepath.");
579+
}
580+
581+
const auto& l_retValue = dbusUtility::readDbusProperty(
582+
constants::pimServiceName, l_inventoryPath, constants::vsbpInf,
583+
constants::kwdIM);
584+
585+
if (auto l_imValue = std::get_if<types::BinaryVector>(&l_retValue))
586+
{
587+
if (((*l_imValue).at(0) == constants::HEX_VALUE_50) &&
588+
(dbusUtility::getImagePrefix() ==
589+
constants::powerVsImagePrefix))
590+
{
591+
return true;
592+
}
593+
594+
logging::logMessage("Not a power VS configuration");
595+
return false;
596+
}
597+
598+
throw std::runtime_error(
599+
"Invalid type recieved while reading system IM.");
600+
}
601+
catch (const std::exception& l_ex)
602+
{
603+
EventLogger::createSyncPel(
604+
types::ErrorType::InvalidSystem, types::SeverityType::Informational,
605+
__FILE__, __FUNCTION__, 0,
606+
"Failed to process powerVS configuration with error: " +
607+
std::string(l_ex.what()),
608+
std::nullopt, std::nullopt, std::nullopt, std::nullopt);
609+
610+
return false;
611+
}
612+
}
555613
} // namespace vpdSpecificUtility
556614
} // namespace vpd

vpd-manager/src/manager.cpp

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include <sdbusplus/bus/match.hpp>
1919
#include <sdbusplus/message.hpp>
2020

21+
#include <typeindex>
22+
2123
namespace vpd
2224
{
2325
Manager::Manager(
@@ -272,11 +274,18 @@ void Manager::SetTimerToDetectVpdCollectionStatus()
272274
{
273275
// cancel the timer
274276
l_timer.cancel();
275-
m_interface->set_property("CollectionStatus",
276-
std::string("Completed"));
277277

278278
const nlohmann::json& l_sysCfgJsonObj =
279279
m_worker->getSysCfgJsonObj();
280+
281+
if (vpdSpecificUtility::isPowerVsConfiguration(l_sysCfgJsonObj))
282+
{
283+
updatePowerVsVpd();
284+
}
285+
286+
m_interface->set_property("CollectionStatus",
287+
std::string("Completed"));
288+
280289
if (jsonUtility::isBackupAndRestoreRequired(l_sysCfgJsonObj))
281290
{
282291
BackupAndRestore l_backupAndRestoreObj(l_sysCfgJsonObj);
@@ -910,4 +919,61 @@ void Manager::performVpdRecollection()
910919
std::string(l_ex.what()));
911920
}
912921
}
922+
923+
void Manager::updatePowerVsVpd()
924+
{
925+
try
926+
{
927+
nlohmann::json l_parsedPwrVsJson =
928+
jsonUtility::getParsedJson(POWER_VS_JSON_5000);
929+
930+
for (const auto& [l_path, l_recJson] : l_parsedPwrVsJson.items())
931+
{
932+
std::cout << "Path = " << l_path << std::endl;
933+
934+
for (const auto& [l_recordName, l_kwdJson] : l_recJson.items())
935+
{
936+
std::cout << "record name = " << l_recordName << std::endl;
937+
938+
for (const auto& [l_kwdName, l_kwdValue] : l_kwdJson.items())
939+
{
940+
std::cout << "kwd name = " << l_kwdName << std::endl;
941+
942+
std::cout << "kwd value size = " << l_kwdValue.size()
943+
<< std::endl;
944+
if (l_kwdValue.is_array())
945+
{
946+
std::cout << "Is array";
947+
types::BinaryVector l_binaryKwdValue =
948+
l_kwdValue.get<types::BinaryVector>();
949+
950+
for (auto item : l_binaryKwdValue)
951+
{
952+
std::cout << (int)item << " ";
953+
}
954+
std::cout << std::endl;
955+
}
956+
957+
/* if (updateKeyword(l_path,
958+
std::make_tuple(l_recordName, l_kwdName,
959+
l_kwdValue)) ==
960+
constants::FAILURE)
961+
{
962+
// TODO should we stop all updates or log this failure
963+
// and continue with rest of the updates.
964+
}*/
965+
}
966+
}
967+
}
968+
}
969+
catch (const std::exception& l_ex)
970+
{
971+
/* types::ErrorType l_errTYype = types::ErrorType::InvalidSystem;
972+
973+
if (typeid(l_ex) == std::type_index(typeid(JsonException)))
974+
{
975+
l_errTYype = types::ErrorType::JsonFailure;
976+
}*/
977+
}
978+
}
913979
} // namespace vpd

0 commit comments

Comments
 (0)