Add a helper function copyRestFRUArea to updateFRUProperty
Refactoring updateFRUProperty function and created a new helper
function copyRestFRUArea. Moved this function to fru_utils.cpp
as it is common for all fru-device deamons and avoid code
duplication.
This patch is created based on suggestion on the below patch.
https://gerrit.openbmc.org/c/openbmc/entity-manager/+/51555
TESTED : Built Facebook YosemiteV2 images and loaded
on the target hardware. Verified all the fru's read and write.
Signed-off-by: Kumar Thangavel <thangavel.k@hcl.com>
Change-Id: I3a3ac6ff3190f0d91f5806e4824400cca0a590e4
Signed-off-by: Kumar Thangavel <thangavel.k@hcl.com>
diff --git a/src/fru_device.cpp b/src/fru_device.cpp
index 446d5c4..1e668ba 100644
--- a/src/fru_device.cpp
+++ b/src/fru_device.cpp
@@ -1107,42 +1107,20 @@
struct FruArea fruAreaParams
{};
- size_t fruDataIter = 0;
- if (!findFruAreaLocationAndField(fruData, propertyName, fruAreaParams,
- fruDataIter))
+ if (!findFruAreaLocationAndField(fruData, propertyName, fruAreaParams))
{
std::cerr << "findFruAreaLocationAndField failed \n";
return false;
}
- ssize_t fieldLength = 0;
-
- // Push post update fru field bytes to a vector
- fieldLength = getFieldLength(fruData[fruAreaParams.updateFieldLoc]);
- if (fieldLength < 0)
+ std::vector<uint8_t> restFRUAreaFieldsData;
+ if (!copyRestFRUArea(fruData, propertyName, fruAreaParams,
+ restFRUAreaFieldsData))
{
- std::cerr << "Property " << propertyName << " not present \n";
+ std::cerr << "copyRestFRUArea failed \n";
return false;
}
- fruDataIter += 1 + fieldLength;
- size_t restFRUFieldsLoc = fruDataIter;
- size_t endOfFieldsLoc = 0;
- while ((fieldLength = getFieldLength(fruData[fruDataIter])) >= 0)
- {
- if (fruDataIter >= (fruAreaParams.start + fruAreaParams.size))
- {
- fruDataIter = fruAreaParams.start + fruAreaParams.size;
- break;
- }
- fruDataIter += 1 + fieldLength;
- }
- endOfFieldsLoc = fruDataIter;
-
- std::vector<uint8_t> restFRUAreaFieldsData;
- std::copy_n(fruData.begin() + restFRUFieldsLoc,
- endOfFieldsLoc - restFRUFieldsLoc + 1,
- std::back_inserter(restFRUAreaFieldsData));
// Push post update fru areas if any
unsigned int nextFRUAreaLoc = 0;
@@ -1151,7 +1129,7 @@
{
unsigned int fruAreaLoc =
fruData[getHeaderAreaFieldOffset(nextFRUArea)] * fruBlockSize;
- if ((fruAreaLoc > endOfFieldsLoc) &&
+ if ((fruAreaLoc > fruAreaParams.restFieldsEnd) &&
((nextFRUAreaLoc == 0) || (fruAreaLoc < nextFRUAreaLoc)))
{
nextFRUAreaLoc = fruAreaLoc;
@@ -1200,10 +1178,13 @@
fruData.begin() + fruAreaParams.updateFieldLoc);
// Copy remaining data to main fru area - post updated fru field vector
- restFRUFieldsLoc = fruAreaParams.updateFieldLoc + updatePropertyReqLen;
- size_t fruAreaDataEnd = restFRUFieldsLoc + restFRUAreaFieldsData.size();
+ fruAreaParams.restFieldsLoc =
+ fruAreaParams.updateFieldLoc + updatePropertyReqLen;
+ size_t fruAreaDataEnd =
+ fruAreaParams.restFieldsLoc + restFRUAreaFieldsData.size();
+
std::copy(restFRUAreaFieldsData.begin(), restFRUAreaFieldsData.end(),
- fruData.begin() + restFRUFieldsLoc);
+ fruData.begin() + fruAreaParams.restFieldsLoc);
// Update final fru with new fru area length and checksum
unsigned int nextFRUAreaNewLoc = updateFRUAreaLenAndChecksum(