diff options
author | Matt Spinler <spinler@us.ibm.com> | 2019-07-10 11:04:21 -0500 |
---|---|---|
committer | Matt Spinler <spinler@us.ibm.com> | 2019-07-26 13:40:59 -0500 |
commit | d3335dfa7a13d94d6aca0d77b62f163e9babee05 (patch) | |
tree | e86482ad267924cad0f5ae5e90dc3bd702b80e6f /extensions/openpower-pels/private_header.cpp | |
parent | 1b5c72b57c67a5dac581061ea92f7234500b68f0 (diff) | |
download | phosphor-logging-d3335dfa7a13d94d6aca0d77b62f163e9babee05.tar.gz phosphor-logging-d3335dfa7a13d94d6aca0d77b62f163e9babee05.zip |
PEL: Add PrivateHeader class
The first section in a PEL is always the 'Private Header' section. This
commit adds a class to represent that. Right now, the only constructor
available is filling in its data fields from a PEL stream.
The Section base class, which will be the base class of all PEL
sections, is also being introduced here. It contains the section header
structure, and a valid flag that derived classes can use.
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: Ia5806017155fe1ef29ea57bf8ab202ff861bde2e
Diffstat (limited to 'extensions/openpower-pels/private_header.cpp')
-rw-r--r-- | extensions/openpower-pels/private_header.cpp | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/extensions/openpower-pels/private_header.cpp b/extensions/openpower-pels/private_header.cpp new file mode 100644 index 0000000..7611a75 --- /dev/null +++ b/extensions/openpower-pels/private_header.cpp @@ -0,0 +1,90 @@ +#include "private_header.hpp" + +#include <phosphor-logging/log.hpp> + +namespace openpower +{ +namespace pels +{ + +using namespace phosphor::logging; + +PrivateHeader::PrivateHeader(Stream& pel) +{ + try + { + pel >> *this; + validate(); + } + catch (const std::exception& e) + { + log<level::ERR>("Cannot unflatten private header", + entry("ERROR=%s", e.what())); + _valid = false; + } +} + +void PrivateHeader::validate() +{ + bool failed = false; + + if (header().id != privateHeaderSectionID) + { + log<level::ERR>("Invalid private header section ID", + entry("ID=0x%X", header().id)); + failed = true; + } + + if (header().version != privateHeaderVersion) + { + log<level::ERR>("Invalid private header version", + entry("VERSION=0x%X", header().version)); + failed = true; + } + + if (_sectionCount < minSectionCount) + { + log<level::ERR>("Invalid section count in private header", + entry("SECTION_COUNT=0x%X", _sectionCount)); + failed = true; + } + + _valid = (failed) ? false : true; +} + +Stream& operator>>(Stream& s, PrivateHeader& ph) +{ + s >> ph._header >> ph._createTimestamp >> ph._commitTimestamp >> + ph._creatorID >> ph._logType >> ph._reservedByte >> ph._sectionCount >> + ph._obmcLogID >> ph._creatorVersion >> ph._plid >> ph._id; + return s; +} + +Stream& operator<<(Stream& s, PrivateHeader& ph) +{ + s << ph._header << ph._createTimestamp << ph._commitTimestamp + << ph._creatorID << ph._logType << ph._reservedByte << ph._sectionCount + << ph._obmcLogID << ph._creatorVersion << ph._plid << ph._id; + return s; +} + +Stream& operator>>(Stream& s, CreatorVersion& cv) +{ + for (size_t i = 0; i < sizeof(CreatorVersion); i++) + { + s >> cv.version[i]; + } + return s; +} + +Stream& operator<<(Stream& s, CreatorVersion& cv) +{ + for (size_t i = 0; i < sizeof(CreatorVersion); i++) + { + s << cv.version[i]; + } + return s; +} + +} // namespace pels +} // namespace openpower |