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
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