smbios-mdr: Expose Firmware Inventory Information

SMBIOS Type 45 defines the data structure to expose Firmware
Inventory information. Added patch which exposes the same
on the DBus.

Introduced fw-inventory-dbus meson option which by default,
will be disabled. When enabled fw-inventory is exposed to dbus

Introduced expose-firmware-component-name meson option which
by default, will be disabled. When enabled fw-component name is
exposed as dbus object

Tested:
1) No crash is seen when firmware is flashed with change
2) Firmware Inventory information is available under dbus tree
```
busctl tree xyz.openbmc_project.Smbios.MDR_V2
`- /xyz
  `- /xyz/openbmc_project
    |- /xyz/openbmc_project/Smbios
    | `- /xyz/openbmc_project/Smbios/MDR_V2
    `- /xyz/openbmc_project/software
      `- /xyz/openbmc_project/software/UEFI
```

Change-Id: If5b367f21dedc0addef4f7b1d4c6dac6a5dc17c2
Signed-off-by: Prithvi Pai <ppai@nvidia.com>
diff --git a/include/smbios_mdrv2.hpp b/include/smbios_mdrv2.hpp
index 2be6dad..c2f1b4b 100644
--- a/include/smbios_mdrv2.hpp
+++ b/include/smbios_mdrv2.hpp
@@ -157,6 +157,13 @@
     uint64_t structTableAddr;
 } __attribute__((packed));
 
+struct StructureHeader
+{
+    uint8_t type;
+    uint8_t length;
+    uint16_t handle;
+} __attribute__((packed));
+
 static constexpr const char* cpuSuffix = "/chassis/motherboard/cpu";
 
 static constexpr const char* dimmSuffix = "/chassis/motherboard/dimm";
@@ -167,6 +174,8 @@
 
 static constexpr const char* tpmSuffix = "/chassis/motherboard/tpm";
 
+static constexpr const char* firmwarePath = "/xyz/openbmc_project/software";
+
 constexpr std::array<SMBIOSVersion, 8> supportedSMBIOSVersions{
     SMBIOSVersion{3, 0}, SMBIOSVersion{3, 2}, SMBIOSVersion{3, 3},
     SMBIOSVersion{3, 4}, SMBIOSVersion{3, 5}, SMBIOSVersion{3, 6},
@@ -192,7 +201,10 @@
     systemEventLogType = 15,
     physicalMemoryArrayType = 16,
     memoryDeviceType = 17,
+    systemPowerSupply = 39,
+    onboardDevicesExtended = 41,
     tpmDeviceType = 43,
+    firmwareInventoryInformationType = 45,
 } SmbiosType;
 
 static constexpr uint8_t separateLen = 2;
@@ -256,6 +268,51 @@
     return nullptr;
 }
 
+static inline uint8_t* smbiosSkipEntryPoint(uint8_t* smbiosDataIn)
+{
+    const std::string anchorString30 = "_SM3_";
+    if (smbiosDataIn == nullptr)
+    {
+        return nullptr;
+    }
+
+    // Jump to starting address of the SMBIOS Structure Table from Entry Point
+    auto anchor = reinterpret_cast<const char*>(smbiosDataIn);
+    if (std::string_view(anchor, anchorString30.length())
+            .compare(anchorString30) == 0)
+    {
+        auto epStructure =
+            reinterpret_cast<const EntryPointStructure30*>(smbiosDataIn);
+        if (epStructure->structTableAddr < mdrSMBIOSSize)
+        {
+            smbiosDataIn += epStructure->structTableAddr;
+        }
+    }
+
+    return smbiosDataIn;
+}
+
+static inline uint8_t* smbiosHandlePtr(uint8_t* smbiosDataIn, uint16_t handle)
+{
+    auto ptr = smbiosSkipEntryPoint(smbiosDataIn);
+    struct StructureHeader* header;
+    while (ptr != nullptr)
+    {
+        header = reinterpret_cast<struct StructureHeader*>(ptr);
+        if (header->length < sizeof(StructureHeader))
+        {
+            return nullptr;
+        }
+
+        if (header->handle == handle)
+        {
+            return ptr;
+        }
+        ptr = smbiosNextPtr(ptr);
+    }
+    return nullptr;
+}
+
 static inline std::string positionToString(uint8_t positionNum,
                                            uint8_t structLen, uint8_t* dataIn)
 {