Update vpd read and write flow

The commit implement changes to log Pel and call out
FRU and record in case of any ECC failure while reading
the vpd data for the FRU and continue with the processing
of rest of the records.

In case of write, BMC reboot is blocked till the VPD is
updated. Doing this will restrict any data/Ecc corruption
due to BMC reboot while VPD data is being updated.

Tested:
Corrupted vpd for tpm_wilson then triggered collection of
vpd for the FRU.
Pel was logged calling out the FRU

'''
root@rain127bmc:~# ibm-read-vpd --file /sys/bus/i2c/drivers/at24/0-0051/eeprom
root@rain127bmc:~# peltool -a
[
{
"Private Header": {
    "Section Version":          "1",
    "Sub-section type":         "0",
    "Created by":               "0x4000",
    "Created at":               "06/10/2022 06:36:59",
    "Committed at":             "06/10/2022 06:36:59",
    "Creator Subsystem":        "BMC",
    "CSSVER":                   "",
    "Platform Log Id":          "0x50002B35",
    "Entry Id":                 "0x50002B35",
    "BMC Event Log Id":         "10"
},
"User Header": {
    "Section Version":          "1",
    "Sub-section type":         "0",
    "Log Committed by":         "0x2000",
    "Subsystem":                "CEC Hardware - VPD Interface",
    "Event Scope":              "Entire Platform",
    "Event Severity":           "Predictive Error",
    "Event Type":               "Not Applicable",
    "Action Flags": [
                                "Service Action Required",
                                "Report Externally",
                                "HMC Call Home"
    ],
    "Host Transmission":        "Not Sent",
    "HMC Transmission":         "Not Sent"
},
"Primary SRC": {
    "Section Version":          "1",
    "Sub-section type":         "1",
    "Created by":               "0x4000",
    "SRC Version":              "0x02",
    "SRC Format":               "0x55",
    "Virtual Progress SRC":     "False",
    "I5/OS Service Event Bit":  "False",
    "Hypervisor Dump Initiated":"False",
    "Backplane CCIN":           "2E43",
    "Terminate FW Error":       "False",
    "Deconfigured":             "False",
    "Guarded":                  "False",
    "Error Details": {
        "Message":              "A VPD ecc exception occurred."
    },
    "Valid Word Count":         "0x09",
    "Reference Code":           "BD554002",
    "Hex Word 2":               "00080255",
    "Hex Word 3":               "2E430010",
    "Hex Word 4":               "00000000",
    "Hex Word 5":               "00000000",
    "Hex Word 6":               "00000000",
    "Hex Word 7":               "00000000",
    "Hex Word 8":               "00000000",
    "Hex Word 9":               "00000000",
    "Callout Section": {
        "Callout Count":        "1",
        "Callouts": [{
            "FRU Type":         "Normal Hardware FRU",
            "Priority":         "Mandatory, replace all with this type as a unit",
            "Location Code":    "U78DB.ND0.WZS002U-P0-C22",
            "Part Number":      "02WF429",
            "CCIN":             "6B59",
            "Serial Number":    "Y131UF09S00H"
        }]
    }
},
"Extended User Header": {
    "Section Version":          "1",
    "Sub-section type":         "0",
    "Created by":               "0x2000",
    "Reporting Machine Type":   "9105-42A",
    "Reporting Serial Number":  "13BE990",
    "FW Released Ver":          "",
    "FW SubSys Version":        "fw1020.00-58.9",
    "Common Ref Time":          "00/00/0000 00:00:00",
    "Symptom Id Len":           "20",
    "Symptom Id":               "BD554002_2E430010"
},
"Failing MTMS": {
    "Section Version":          "1",
    "Sub-section type":         "0",
    "Created by":               "0x2000",
    "Machine Type Model":       "9105-42A",
    "Serial Number":            "13BE990"
},
"User Data 0": {
    "Section Version": "1",
    "Sub-section type": "1",
    "Created by": "0x2000",
    "BMCState": "Ready",
    "BootState": "SecondaryProcInit",
    "ChassisState": "On",
    "FW Version ID": "fw1020.00-58.9-3-gb29698f8cf",
    "HostState": "Running",
    "System IM": "50001000"
},
"User Data 1": {
    "Section Version": "1",
    "Sub-section type": "1",
    "Created by": "0x2000",
    "CALLOUT_INVENTORY_PATH": "/xyz/openbmc_project/inventory/system/chassis/motherboard/tpm_wilson",
    "DESCRIPTION": "ERROR: ECC check did not pass for the Record:VINI"
}
}
]
'''

Signed-off-by: Sunny Srivastava <sunnsr25@in.ibm.com>
Change-Id: Ie7c7fff5699d8b89d5aa0995f4074ccb3fdd6c37
diff --git a/impl.cpp b/impl.cpp
index 9447ca9..99bc074 100644
--- a/impl.cpp
+++ b/impl.cpp
@@ -3,6 +3,7 @@
 #include "const.hpp"
 #include "defines.hpp"
 #include "ibm_vpd_utils.hpp"
+#include "types.hpp"
 #include "vpd_exceptions.hpp"
 
 #include <algorithm>
@@ -147,13 +148,13 @@
 
     if (eccLength == 0 || eccOffset == 0)
     {
-        throw(VpdEccException("Could not find ECC's offset or Length"));
+        throw(VpdEccException("Could not find ECC's offset or Length."));
     }
 
     if (recordOffset == 0 || recordLength == 0)
     {
-        throw(VpdDataException(
-            "Could not find VPD record offset or VPD record length"));
+        throw(VpdDataException("Could not find VPD record offset or VPD record "
+                               "length."));
     }
 
     auto vpdPtr = vpd.cbegin();
@@ -264,19 +265,44 @@
         offsets.push_back(offset);
 
 #ifdef IPZ_PARSER
-        // Verify the ECC for this Record
-        int rc = recordEccCheck(iterator);
+        std::string recordName(iteratorToRecName,
+                               iteratorToRecName + lengths::RECORD_NAME);
 
-        if (rc != eccStatus::SUCCESS)
+        try
         {
-            std::string recordName(iteratorToRecName,
-                                   iteratorToRecName + lengths::RECORD_NAME);
+            // Verify the ECC for this Record
+            int rc = recordEccCheck(iterator);
 
-            std::string errorMsg =
-                std::string("ERROR: ECC check did not pass for the Record:") +
-                recordName;
-            throw(VpdEccException(errorMsg));
+            if (rc != eccStatus::SUCCESS)
+            {
+                std::string errorMsg =
+                    std::string("ERROR: ECC check did not pass.");
+                throw(VpdEccException(errorMsg));
+            }
         }
+        catch (const VpdEccException& ex)
+        {
+            std::string errMsg =
+                std::string{ex.what()} + " Record: " + recordName;
+
+            inventory::PelAdditionalData additionalData{};
+            additionalData.emplace("DESCRIPTION", errMsg);
+            additionalData.emplace("CALLOUT_INVENTORY_PATH", inventoryPath);
+            createPEL(additionalData, PelSeverity::WARNING,
+                      errIntfForEccCheckFail);
+        }
+        catch (const VpdDataException& ex)
+        {
+            std::string errMsg =
+                std::string{ex.what()} + " Record: " + recordName;
+
+            inventory::PelAdditionalData additionalData{};
+            additionalData.emplace("DESCRIPTION", errMsg);
+            additionalData.emplace("CALLOUT_INVENTORY_PATH", inventoryPath);
+            createPEL(additionalData, PelSeverity::WARNING,
+                      errIntfForInvalidVPD);
+        }
+
 #endif
 
         // Jump record size, record length, ECC offset and ECC length