PEL: Pass FFDC files into PEL

In the case where an OpenBMC event log was created with the
'createWithFFDCFiles' D-Bus method, there needs to be UserData PEL
sections created with the contents of these files.

This commit passes these files into the PEL constructor, which then does
the creating.  If any of this would cause the PEL size to go over 16KB,
then that section will be trimmed so it fits in the 16KB, and no more
additional sections will be added.

The function that actually reads the FFDC file and creates the UserData
section is stubbed out and will be implemented in a future commit.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: Id27802c91326381a4b80fbe78ab62471cefe0286
diff --git a/extensions/openpower-pels/pel.cpp b/extensions/openpower-pels/pel.cpp
index 167d28a..d6c404d 100644
--- a/extensions/openpower-pels/pel.cpp
+++ b/extensions/openpower-pels/pel.cpp
@@ -42,7 +42,7 @@
 
 PEL::PEL(const message::Entry& regEntry, uint32_t obmcLogID, uint64_t timestamp,
          phosphor::logging::Entry::Level severity,
-         const AdditionalData& additionalData,
+         const AdditionalData& additionalData, const PelFFDC& ffdcFiles,
          const DataInterfaceBase& dataIface)
 {
     _ph = std::make_unique<PrivateHeader>(regEntry.componentID, obmcLogID,
@@ -87,6 +87,39 @@
         }
     }
 
+    // Add any FFDC files into UserData sections
+    for (const auto& file : ffdcFiles)
+    {
+        ud = util::makeFFDCuserDataSection(regEntry.componentID, file);
+        if (!ud)
+        {
+            log<level::WARNING>(
+                "Could not make PEL FFDC UserData section from file",
+                entry("COMPONENT_ID=0x%02X", regEntry.componentID),
+                entry("SUBTYPE=0x%X", file.subType),
+                entry("VERSION=0x%X", file.version));
+            continue;
+        }
+
+        // Shrink it if necessary
+        if (size() + ud->header().size > _maxPELSize)
+        {
+            if (!ud->shrink(_maxPELSize - size()))
+            {
+                log<level::WARNING>(
+                    "Could not shrink FFDC UserData section",
+                    entry("COMPONENT_ID=0x%02X", regEntry.componentID),
+                    entry("SUBTYPE=0x%X", file.subType),
+                    entry("VERSION=0x%X", file.version));
+
+                // Give up adding FFDC
+                break;
+            }
+        }
+
+        _optionalSections.push_back(std::move(ud));
+    }
+
     _ph->setSectionCount(2 + _optionalSections.size());
 
     checkRulesAndFix();
@@ -441,6 +474,12 @@
     return makeJSONUserDataSection(json);
 }
 
+std::unique_ptr<UserData> makeFFDCuserDataSection(uint16_t componentID,
+                                                  const PelFFDCfile& file)
+{
+    return std::unique_ptr<UserData>();
+}
+
 } // namespace util
 
 } // namespace pels