Skip to content

Commit 9bde15b

Browse files
Marc Olberdingedtanous
authored andcommitted
fru-device: move Adding and updating a property into a helper
Adds updating and adding properties to a helper function that's divorced from dbus logic. This allows other code to modify a fru buffer. Tested: Called updateproperty on nvl32-obmc. Result was correct Change-Id: I432f89003cf5608900c018f72edef877534bfe40 Signed-off-by: Marc Olberding <[email protected]>
1 parent 71fbff7 commit 9bde15b

File tree

3 files changed

+91
-71
lines changed

3 files changed

+91
-71
lines changed

src/fru_device/fru_device.cpp

Lines changed: 4 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,16 +1212,6 @@ bool updateFruProperty(
12121212
"updateFruProperty called: FieldName = {NAME}, FieldValue = {VALUE}",
12131213
"NAME", propertyName, "VALUE", propertyValue);
12141214

1215-
// Validate field length: must be 2–63 characters
1216-
const size_t len = propertyValue.length();
1217-
if (len == 1 || len > 63)
1218-
{
1219-
lg2::error(
1220-
"FRU field data must be 0 or between 2 and 63 characters. Invalid Length: {LEN}",
1221-
"LEN", len);
1222-
return false;
1223-
}
1224-
12251215
std::vector<uint8_t> fruData;
12261216
if (!getFruData(fruData, bus, address))
12271217
{
@@ -1230,69 +1220,12 @@ bool updateFruProperty(
12301220
return false;
12311221
}
12321222

1233-
if (fruData.empty())
1234-
{
1235-
lg2::error("Empty FRU data\n");
1236-
return false;
1237-
}
1238-
1239-
// Extract area name (prefix before underscore)
1240-
std::string areaName = propertyName.substr(0, propertyName.find('_'));
1241-
auto areaIterator =
1242-
std::find(fruAreaNames.begin(), fruAreaNames.end(), areaName);
1243-
if (areaIterator == fruAreaNames.end())
1244-
{
1245-
lg2::error("Failed to get FRU area for property: {AREA}", "AREA",
1246-
areaName);
1247-
return false;
1248-
}
1249-
1250-
fruAreas fruAreaToUpdate = static_cast<fruAreas>(
1251-
std::distance(fruAreaNames.begin(), areaIterator));
1252-
1253-
std::vector<std::vector<uint8_t>> areasData;
1254-
if (!disassembleFruData(fruData, areasData))
1255-
{
1256-
lg2::error("Failed to disassemble Fru Data");
1257-
return false;
1258-
}
1259-
1260-
std::vector<uint8_t>& areaData =
1261-
areasData[static_cast<size_t>(fruAreaToUpdate)];
1262-
if (areaData.empty())
1223+
bool success = updateAddProperty(propertyValue, propertyName, fruData);
1224+
if (!success)
12631225
{
1264-
// If ENABLE_FRU_AREA_RESIZE is not defined then return with failure
1265-
#ifndef ENABLE_FRU_AREA_RESIZE
12661226
lg2::error(
1267-
"FRU area {AREA} not present and ENABLE_FRU_AREA_RESIZE is not set. "
1268-
"Returning failure.",
1269-
"AREA", areaName);
1270-
return false;
1271-
#endif
1272-
if (!createDummyArea(fruAreaToUpdate, areaData))
1273-
{
1274-
lg2::error("Failed to create dummy area for {AREA}", "AREA",
1275-
areaName);
1276-
return false;
1277-
}
1278-
}
1279-
1280-
if (!setField(fruAreaToUpdate, areaData, propertyName, propertyValue))
1281-
{
1282-
lg2::error("Failed to set field value for property: {PROPERTY}",
1283-
"PROPERTY", propertyName);
1284-
return false;
1285-
}
1286-
1287-
if (!assembleFruData(fruData, areasData))
1288-
{
1289-
lg2::error("Failed to reassemble FRU data");
1290-
return false;
1291-
}
1292-
1293-
if (fruData.empty())
1294-
{
1295-
lg2::error("FRU data is empty after assembly");
1227+
"Failed to update the property on bus {BUS}, address {ADDRESS}",
1228+
"BUS", bus, "ADDRESS", address);
12961229
return false;
12971230
}
12981231

src/fru_device/fru_utils.cpp

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,3 +1667,86 @@ bool isFieldEditable(std::string_view fieldName)
16671667
// Match against editable fields
16681668
return std::ranges::contains(editableFields, subField);
16691669
}
1670+
1671+
bool updateAddProperty(const std::string& propertyValue,
1672+
const std::string& propertyName,
1673+
std::vector<uint8_t>& fruData)
1674+
{
1675+
// Validate field length: must be 2–63 characters
1676+
const size_t len = propertyValue.length();
1677+
if (len == 1 || len > 63)
1678+
{
1679+
lg2::error(
1680+
"FRU field data must be 0 or between 2 and 63 characters. Invalid Length: {LEN}",
1681+
"LEN", len);
1682+
return false;
1683+
}
1684+
1685+
if (fruData.empty())
1686+
{
1687+
lg2::error("Empty FRU data\n");
1688+
return false;
1689+
}
1690+
1691+
// Extract area name (prefix before underscore)
1692+
std::string areaName = propertyName.substr(0, propertyName.find('_'));
1693+
auto areaIterator =
1694+
std::find(fruAreaNames.begin(), fruAreaNames.end(), areaName);
1695+
if (areaIterator == fruAreaNames.end())
1696+
{
1697+
lg2::error("Failed to get FRU area for property: {AREA}", "AREA",
1698+
areaName);
1699+
return false;
1700+
}
1701+
1702+
fruAreas fruAreaToUpdate = static_cast<fruAreas>(
1703+
std::distance(fruAreaNames.begin(), areaIterator));
1704+
1705+
std::vector<std::vector<uint8_t>> areasData;
1706+
if (!disassembleFruData(fruData, areasData))
1707+
{
1708+
lg2::error("Failed to disassemble Fru Data");
1709+
return false;
1710+
}
1711+
1712+
std::vector<uint8_t>& areaData =
1713+
areasData[static_cast<size_t>(fruAreaToUpdate)];
1714+
if (areaData.empty())
1715+
{
1716+
// If ENABLE_FRU_AREA_RESIZE is not defined then return with failure
1717+
#ifndef ENABLE_FRU_AREA_RESIZE
1718+
lg2::error(
1719+
"FRU area {AREA} not present and ENABLE_FRU_AREA_RESIZE is not set. "
1720+
"Returning failure.",
1721+
"AREA", areaName);
1722+
return false;
1723+
#endif
1724+
if (!createDummyArea(fruAreaToUpdate, areaData))
1725+
{
1726+
lg2::error("Failed to create dummy area for {AREA}", "AREA",
1727+
areaName);
1728+
return false;
1729+
}
1730+
}
1731+
1732+
if (!setField(fruAreaToUpdate, areaData, propertyName, propertyValue))
1733+
{
1734+
lg2::error("Failed to set field value for property: {PROPERTY}",
1735+
"PROPERTY", propertyName);
1736+
return false;
1737+
}
1738+
1739+
if (!assembleFruData(fruData, areasData))
1740+
{
1741+
lg2::error("Failed to reassemble FRU data");
1742+
return false;
1743+
}
1744+
1745+
if (fruData.empty())
1746+
{
1747+
lg2::error("FRU data is empty after assembly");
1748+
return false;
1749+
}
1750+
1751+
return true;
1752+
}

src/fru_device/fru_utils.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,7 @@ bool assembleFruData(std::vector<uint8_t>& fruData,
226226

227227
bool setField(const fruAreas& fruAreaToUpdate, std::vector<uint8_t>& areaData,
228228
const std::string& propertyName, const std::string& value);
229+
230+
bool updateAddProperty(const std::string& propertyValue,
231+
const std::string& propertyName,
232+
std::vector<uint8_t>& data);

0 commit comments

Comments
 (0)