PEL: Print component names in peltool

Every PEL section has a 2 byte component ID field in its header that
peltool prints.  Currently, it just prints the hex version, like
"0x1000".

There are JSON files in the flash already that contain mappings of
component IDs to to component names, and this commit starts looking
up the component names from those files and using those in the peltool
output.

An example of a file is:
/usr/share/phosphor-logging/pels/O_component_ids.json:
{
    "1000": "bmc common function",
    "2000": "bmc error logging",
    ...
}

Where the 'O' in the filename is the creator ID field of the PEL.  There
is also a file for hostboot, which is B_component_ids.json.

Also, for PELs with a PHYP creator ID, just convert the ID to two
characters, like 0x4552 - > "ER" as that is what they are.

peltool output examples:
    "Created by": "bmc error logging",
    "Created by": "hostboot: errl",
    "Created by": "IO",

This matches what is already done by the python peltool.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: Id616739e1b7ca67c85dc7efa85dc34acf6aca9b5
diff --git a/extensions/openpower-pels/user_data_json.cpp b/extensions/openpower-pels/user_data_json.cpp
index bf6152b..0e3ac24 100644
--- a/extensions/openpower-pels/user_data_json.cpp
+++ b/extensions/openpower-pels/user_data_json.cpp
@@ -48,17 +48,19 @@
  * the outer {}.  If the input JSON isn't a JSON object (dict), then
  * one will be created with the input added to a 'Data' key.
  *
+ * @param[in] creatorID - The creator ID for the PEL
+ *
  * @param[in] json - The JSON to convert to a string
  *
  * @return std::string - The JSON string
  */
 std::string prettyJSON(uint16_t componentID, uint8_t subType, uint8_t version,
-                       const orderedJSON& json)
+                       uint8_t creatorID, const orderedJSON& json)
 {
     orderedJSON output;
     output[pv::sectionVer] = std::to_string(version);
     output[pv::subSection] = std::to_string(subType);
-    output[pv::createdBy] = getNumberString("0x%04X", componentID);
+    output[pv::createdBy] = getComponentName(componentID, creatorID);
 
     if (!json.is_object())
     {
@@ -103,12 +105,13 @@
  * @param[in] componentID - The comp ID from the UserData section header
  * @param[in] subType - The subtype from the UserData section header
  * @param[in] version - The version from the UserData section header
+ * @param[in] creatorID - The creator ID for the PEL
  * @param[in] data - The CBOR data
  *
  * @return std::string - The JSON string
  */
 std::string getCBORJSON(uint16_t componentID, uint8_t subType, uint8_t version,
-                        const std::vector<uint8_t>& data)
+                        uint8_t creatorID, const std::vector<uint8_t>& data)
 {
     // The CBOR parser needs the pad bytes added to 4 byte align
     // removed.  The number of bytes added to the pad is on the
@@ -131,7 +134,7 @@
 
     orderedJSON json = orderedJSON::from_cbor(cborData);
 
-    return prettyJSON(componentID, subType, version, json);
+    return prettyJSON(componentID, subType, version, creatorID, json);
 }
 
 /**
@@ -144,12 +147,13 @@
  * @param[in] componentID - The comp ID from the UserData section header
  * @param[in] subType - The subtype from the UserData section header
  * @param[in] version - The version from the UserData section header
+ * @param[in] creatorID - The creator ID for the PEL
  * @param[in] data - The CBOR data
  *
  * @return std::string - The JSON string
  */
 std::string getTextJSON(uint16_t componentID, uint8_t subType, uint8_t version,
-                        const std::vector<uint8_t>& data)
+                        uint8_t creatorID, const std::vector<uint8_t>& data)
 {
     std::vector<std::string> text;
     size_t startPos = 0;
@@ -183,7 +187,7 @@
     }
 
     orderedJSON json = text;
-    return prettyJSON(componentID, subType, version, json);
+    return prettyJSON(componentID, subType, version, creatorID, json);
 }
 
 /**
@@ -200,7 +204,7 @@
  */
 std::optional<std::string>
     getBuiltinFormatJSON(uint16_t componentID, uint8_t subType, uint8_t version,
-                         const std::vector<uint8_t>& data)
+                         const std::vector<uint8_t>& data, uint8_t creatorID)
 {
     switch (subType)
     {
@@ -210,15 +214,15 @@
 
             orderedJSON json = orderedJSON::parse(jsonString);
 
-            return prettyJSON(componentID, subType, version, json);
+            return prettyJSON(componentID, subType, version, creatorID, json);
         }
         case static_cast<uint8_t>(UserDataFormat::cbor):
         {
-            return getCBORJSON(componentID, subType, version, data);
+            return getCBORJSON(componentID, subType, version, creatorID, data);
         }
         case static_cast<uint8_t>(UserDataFormat::text):
         {
-            return getTextJSON(componentID, subType, version, data);
+            return getTextJSON(componentID, subType, version, creatorID, data);
         }
         default:
             break;
@@ -342,7 +346,8 @@
                         (json.is_array() && json.size() > 0) ||
                         (json.is_string() && json != ""))
                     {
-                        return prettyJSON(componentID, subType, version, json);
+                        return prettyJSON(componentID, subType, version,
+                                          creatorID, json);
                     }
                 }
                 catch (const std::exception& e)
@@ -406,7 +411,8 @@
         if (pv::creatorIDs.at(getNumberString("%c", creatorID)) == "BMC" &&
             componentID == static_cast<uint16_t>(ComponentID::phosphorLogging))
         {
-            return getBuiltinFormatJSON(componentID, subType, version, data);
+            return getBuiltinFormatJSON(componentID, subType, version, data,
+                                        creatorID);
         }
         else if (std::find(plugins.begin(), plugins.end(),
                            subsystem + component) != plugins.end())