Add version support for AFM

This change adds AFM version support under FirmwareInventory.

Tested: D-Bus version objects are created and also it's shown
        up under FirmwareInventory.

root@intel-obmc:/tmp# busctl tree xyz.openbmc_project.PFR.Manager
└─/xyz
  └─/xyz/openbmc_project
    ├─/xyz/openbmc_project/pfr
    └─/xyz/openbmc_project/software
      ├─/xyz/openbmc_project/software/afm_active
      ├─/xyz/openbmc_project/software/afm_recovery
      ├─/xyz/openbmc_project/software/bios_recovery
      ├─/xyz/openbmc_project/software/bmc_recovery
      └─/xyz/openbmc_project/software/cpld_recovery

{
    "@odata.id": "/redfish/v1/UpdateService/FirmwareInventory/afm_active",
    "@odata.type": "#SoftwareInventory.v1_1_0.SoftwareInventory",
    "Description": "Other image",
    "Id": "afm_active",
    "Name": "Software Inventory",
    "Status": {
        "Health": "OK",
        "HealthRollup": "OK",
        "State": "Enabled"
    },
    "Updateable": true,
    "Version": ""
}

Signed-off-by: Vikram Bodireddy <vikram.bodireddy@linux.intel.com>
Change-Id: I4233803354d686a736a2614e9f205b294d39f8d6
diff --git a/libpfr/inc/pfr.hpp b/libpfr/inc/pfr.hpp
index c0d3c11..e327b69 100644
--- a/libpfr/inc/pfr.hpp
+++ b/libpfr/inc/pfr.hpp
@@ -27,7 +27,9 @@
     biosActive,
     biosRecovery,
     bmcActive,
-    bmcRecovery
+    bmcRecovery,
+    afmActive,
+    afmRecovery
 };
 
 enum class ActionType
diff --git a/libpfr/src/pfr.cpp b/libpfr/src/pfr.cpp
index 64476f4..856a39c 100644
--- a/libpfr/src/pfr.cpp
+++ b/libpfr/src/pfr.cpp
@@ -53,6 +53,10 @@
 static constexpr uint8_t pchRecoveryMinorVersion = 0x1C;
 static constexpr uint8_t CPLDHashRegStart = 0x20;
 static constexpr uint8_t pfrRoTValue = 0xDE;
+static constexpr uint8_t afmActiveMajorVersion = 0x75;
+static constexpr uint8_t afmActiveMinorVersion = 0x76;
+static constexpr uint8_t afmRecoveryMajorVersion = 0x78;
+static constexpr uint8_t afmRecoveryMinorVersion = 0x79;
 
 static constexpr uint8_t ufmLockedMask = (0x1 << 0x04);
 static constexpr uint8_t ufmProvisionedMask = (0x1 << 0x05);
@@ -366,6 +370,16 @@
         {
             return readBMCVersionFromSPI(imgType);
         }
+        case (ImageType::afmActive):
+        {
+            return readVersionFromCPLD(afmActiveMajorVersion,
+                                       afmActiveMinorVersion);
+        }
+        case (ImageType::afmRecovery):
+        {
+            return readVersionFromCPLD(afmRecoveryMajorVersion,
+                                       afmRecoveryMinorVersion);
+        }
         default:
             // Invalid image Type.
             return "";
diff --git a/service/src/mainapp.cpp b/service/src/mainapp.cpp
index ba714fe..dfbf582 100644
--- a/service/src/mainapp.cpp
+++ b/service/src/mainapp.cpp
@@ -51,6 +51,10 @@
                         versionPurposeHost),
         std::make_tuple("cpld_recovery", ImageType::cpldRecovery,
                         versionPurposeOther),
+        std::make_tuple("afm_active", ImageType::afmActive,
+                        versionPurposeOther),
+        std::make_tuple("afm_recovery", ImageType::afmRecovery,
+                        versionPurposeOther),
 };
 
 // Recovery reason map.
diff --git a/service/src/pfr_mgr.cpp b/service/src/pfr_mgr.cpp
index 479cf5f..5245075 100644
--- a/service/src/pfr_mgr.cpp
+++ b/service/src/pfr_mgr.cpp
@@ -61,7 +61,7 @@
 
     if ((imgType == ImageType::bmcActive) ||
         (imgType == ImageType::biosActive) ||
-        (imgType == ImageType::cpldActive))
+        (imgType == ImageType::cpldActive) || (imgType == ImageType::afmActive))
     {
         // Running images so set Activations to "Active"
         activation =
@@ -75,7 +75,8 @@
         // BIOS version is read from SMBIOS. Since it provides more
         // version information, Lets expose those as functional.
         // Down the line, Redundant inventory objects need to be addressed.
-        if (imgType == ImageType::cpldActive)
+        if ((imgType == ImageType::cpldActive) ||
+            (imgType == ImageType::afmActive))
         {
             associations.emplace("functional", "software_version", objPath);
         }