API to read VPD keyword from hardware
This commit adds up a new method in Impl class
to read a given VPD keyword directly from hardware.
Vpd-tool is one such user of this method.
Signed-off-by: Priyanga Ramasamy <priyanga24@in.ibm.com>
Change-Id: I2bb3d3522a958d0970b20c078b7132ace7ebf692
diff --git a/impl.cpp b/impl.cpp
index a0a45d9..9447ca9 100644
--- a/impl.cpp
+++ b/impl.cpp
@@ -511,6 +511,57 @@
checkHeader();
}
+std::string Impl::readKwFromHw(const std::string& record,
+ const std::string& keyword)
+{
+ // Check if the VHDR record is present
+ checkHeader();
+
+ auto iterator = vpd.cbegin();
+
+ // Read the table of contents record
+ std::size_t ptLen = readTOC(iterator);
+
+ // Read the table of contents record, to get offsets
+ // to other records.
+ auto offsets = readPT(iterator, ptLen);
+ for (const auto& offset : offsets)
+ {
+ // Jump to record name
+ auto nameOffset = offset + sizeof(RecordId) + sizeof(RecordSize) +
+ // Skip past the RT keyword, which contains
+ // the record name.
+ lengths::KW_NAME + sizeof(KwSize);
+ // Get record name
+ auto iterator = vpd.cbegin();
+ std::advance(iterator, nameOffset);
+
+ std::string name(iterator, iterator + lengths::RECORD_NAME);
+ if (name != record)
+ {
+ continue;
+ }
+ else
+ {
+ processRecord(offset);
+ const auto& itr = out.find(record);
+ if (itr != out.end())
+ {
+ const auto& kwValItr = (itr->second).find(keyword);
+ if (kwValItr != (itr->second).end())
+ {
+ return kwValItr->second;
+ }
+ else
+ {
+ return "";
+ }
+ }
+ }
+ }
+ return "";
+}
+
} // namespace parser
} // namespace vpd
-} // namespace openpower
+} // namespace openpower
\ No newline at end of file