common & fw-update: Improving Logs (lg2)

This commit corrects the severity level of logs and also formats the
message string, fixing the ill-defined message string of the logs as
mentioned in the anti-pattern document [1]. Additionally, based on the
requirement this commit adds more debug information to logs.

[1]: https://github.com/openbmc/docs/blob/master/anti-patterns.md#ill-defined-data-structuring-in-lg2-message-strings

Change-Id: I1481c025b6dc6a9200a13de38a4fe55b81bb25ea
Signed-off-by: Riya Dixit <riyadixitagra@gmail.com>
diff --git a/fw-update/package_parser.cpp b/fw-update/package_parser.cpp
index 8454770..e13a8d5 100644
--- a/fw-update/package_parser.cpp
+++ b/fw-update/package_parser.cpp
@@ -41,8 +41,9 @@
             &compImageSetVersionStr, &recordDescriptors, &fwDevicePkgData);
         if (rc)
         {
-            error("Decoding firmware device ID record failed, RC={RC}", "RC",
-                  rc);
+            error(
+                "Failed to decode firmware device ID record, response code '{RC}'",
+                "RC", rc);
             throw InternalFailure();
         }
 
@@ -59,7 +60,8 @@
             if (rc)
             {
                 error(
-                    "Decoding descriptor type, length and value failed, RC={RC}",
+                    "Failed to decode descriptor type value of type '{TYPE}' and  length '{LENGTH}', response code '{RC}'",
+                    "TYPE", descriptorType, "LENGTH", recordDescriptors.length,
                     "RC", rc);
                 throw InternalFailure();
             }
@@ -83,8 +85,9 @@
                 if (rc)
                 {
                     error(
-                        "Decoding Vendor-defined descriptor value failed, RC={RC}",
-                        "RC", rc);
+                        "Failed to decode vendor-defined descriptor value of type '{TYPE}' and  length '{LENGTH}', response code '{RC}'",
+                        "TYPE", descriptorType, "LENGTH",
+                        recordDescriptors.length, "RC", rc);
                     throw InternalFailure();
                 }
 
@@ -153,8 +156,9 @@
                                               &compImageInfo, &compVersion);
         if (rc)
         {
-            error("Decoding component image information failed, RC={RC}", "RC",
-                  rc);
+            error(
+                "Failed to decode component image information, response code '{RC}'",
+                "RC", rc);
             throw InternalFailure();
         }
 
@@ -199,8 +203,9 @@
             auto cmpVersion = std::get<static_cast<size_t>(
                 ComponentImageInfoPos::CompVersionPos)>(componentImageInfo);
             error(
-                "Validating the component location offset failed, COMP_VERSION={COMP_VERS}",
-                "COMP_VERS", cmpVersion);
+                "Failed to validate the component location offset '{OFFSET}' for version '{COMPONENT_VERSION}' and package size '{SIZE}'",
+                "OFFSET", compLocOffset, "COMPONENT_VERSION", cmpVersion,
+                "SIZE", calcPkgSize);
             throw InternalFailure();
         }
 
@@ -210,8 +215,8 @@
     if (calcPkgSize != pkgSize)
     {
         error(
-            "Package size does not match calculated package size, PKG_SIZE={PKG_SIZE}, CALC_PKG_SIZE={CAL_PKG_SIZE}",
-            "PKG_SIZE", pkgSize, "CAL_PKG_SIZE", calcPkgSize);
+            "Failed to match package size '{PKG_SIZE}' to calculated package size '{CALCULATED_PACKAGE_SIZE}'.",
+            "PKG_SIZE", pkgSize, "CALCULATED_PACKAGE_SIZE", calcPkgSize);
         throw InternalFailure();
     }
 }
@@ -221,15 +226,15 @@
 {
     if (pkgHeaderSize != pkgHdr.size())
     {
-        error("Package header size is invalid, PKG_HDR_SIZE={PKG_HDR_SIZE}",
-              "PKG_HDR_SIZE", pkgHeaderSize);
+        error("Invalid package header size '{PKG_HDR_SIZE}' ", "PKG_HDR_SIZE",
+              pkgHeaderSize);
         throw InternalFailure();
     }
 
     size_t offset = sizeof(pldm_package_header_information) + pkgVersion.size();
     if (offset + sizeof(DeviceIDRecordCount) >= pkgHeaderSize)
     {
-        error("Parsing package header failed, PKG_HDR_SIZE={PKG_HDR_SIZE}",
+        error("Failed to parse package header of size '{PKG_HDR_SIZE}'",
               "PKG_HDR_SIZE", pkgHeaderSize);
         throw InternalFailure();
     }
@@ -240,14 +245,13 @@
     offset = parseFDIdentificationArea(deviceIdRecCount, pkgHdr, offset);
     if (deviceIdRecCount != fwDeviceIDRecords.size())
     {
-        error(
-            "DeviceIDRecordCount entries not found, DEVICE_ID_REC_COUNT={DREC_CNT}",
-            "DREC_CNT", deviceIdRecCount);
+        error("Failed to find DeviceIDRecordCount {DREC_CNT} entries",
+              "DREC_CNT", deviceIdRecCount);
         throw InternalFailure();
     }
     if (offset + sizeof(ComponentImageCount) >= pkgHeaderSize)
     {
-        error("Parsing package header failed, PKG_HDR_SIZE={PKG_HDR_SIZE}",
+        error("Failed to parsing package header of size '{PKG_HDR_SIZE}'",
               "PKG_HDR_SIZE", pkgHeaderSize);
         throw InternalFailure();
     }
@@ -259,15 +263,14 @@
     offset = parseCompImageInfoArea(compImageCount, pkgHdr, offset);
     if (compImageCount != componentImageInfos.size())
     {
-        error(
-            "ComponentImageCount entries not found, COMP_IMAGE_COUNT={COMP_IMG_CNT}",
-            "COMP_IMG_CNT", compImageCount);
+        error("Failed to find ComponentImageCount '{COMP_IMG_CNT}' entries",
+              "COMP_IMG_CNT", compImageCount);
         throw InternalFailure();
     }
 
     if (offset + sizeof(PackageHeaderChecksum) != pkgHeaderSize)
     {
-        error("Parsing package header failed, PKG_HDR_SIZE={PKG_HDR_SIZE}",
+        error("Failed to parse package header of size '{PKG_HDR_SIZE}'",
               "PKG_HDR_SIZE", pkgHeaderSize);
         throw InternalFailure();
     }
@@ -279,8 +282,9 @@
     if (calcChecksum != checksum)
     {
         error(
-            "Parsing package header failed, CALC_CHECKSUM={CHK_SUM}, PKG_HDR_CHECKSUM={PKG_HDR_CHK_SUM}",
-            "CHK_SUM", calcChecksum, "PKG_HDR_CHK_SUM", checksum);
+            "Failed to parse package header for calculated checksum '{CALCULATED_CHECKSUM}' and header checksum '{PACKAGE_HEADER_CHECKSUM}'",
+            "CALCULATED_CHECKSUM", calcChecksum, "PACKAGE_HEADER_CHECKSUM",
+            checksum);
         throw InternalFailure();
     }
 
@@ -300,8 +304,9 @@
                                               &pkgHeader, &pkgVersion);
     if (rc)
     {
-        error("Decoding PLDM package header information failed, RC={RC}", "RC",
-              rc);
+        error(
+            "Failed to decode PLDM package header information, response code '{RC}'",
+            "RC", rc);
         return nullptr;
     }