Verify machine name

Verifying machine name from os-release file vs MANIFEST file in
image. Also supporting backword compatibility for older version
where machine name is not defined.

Tested: tested this with latest image build and manifest file patch

Signed-off-by: Vijay Khemka <vijaykhemka@fb.com>
Change-Id: Icb0ac3f884ea1131e2ffd2bde6b8a37185dc55ea
diff --git a/version.cpp b/version.cpp
index ca7e29c..adaaeb9 100644
--- a/version.cpp
+++ b/version.cpp
@@ -93,6 +93,33 @@
     return (hexId.substr(0, 8));
 }
 
+std::string Version::getBMCMachine(const std::string& releaseFilePath)
+{
+    std::string machineKey = "OPENBMC_TARGET_MACHINE=";
+    std::string machine{};
+    std::ifstream efile(releaseFilePath);
+    std::string line;
+
+    while (getline(efile, line))
+    {
+        if (line.substr(0, machineKey.size()).find(machineKey) !=
+            std::string::npos)
+        {
+            std::size_t pos = line.find_first_of('"') + 1;
+            machine = line.substr(pos, line.find_last_of('"') - pos);
+            break;
+        }
+    }
+
+    if (machine.empty())
+    {
+        log<level::ERR>("Unable to find OPENBMC_TARGET_MACHINE");
+        elog<InternalFailure>();
+    }
+
+    return machine;
+}
+
 std::string Version::getBMCVersion(const std::string& releaseFilePath)
 {
     std::string versionKey = "VERSION_ID=";