Fix HW Keyword Handling

This commit fixes how we handle multiple planar passes.
For HW keywords above 2, we do not have an entry in the
system type map.

We cannot keep adding a new entry to the system type to dev.
tree map every time we get a new planar pass (when the new pass
does not need a new device tree).

This commit makes use of existing code that handles
constraints in the systems JSON and enables us to default
to a system type (which is basically our JSON name) when the
constraint is not met.

Tested:
Tested on a pass 4 planar and ensured we load the right device
tree.

Signed-off-by: Santosh Puranik <santosh.puranik@in.ibm.com>
Change-Id: Ibaf9785314ca3920072663d52fffecfca28c9445
diff --git a/ibm_vpd_app.cpp b/ibm_vpd_app.cpp
index c5c1452..7f9e383 100644
--- a/ibm_vpd_app.cpp
+++ b/ibm_vpd_app.cpp
@@ -40,14 +40,6 @@
 using namespace openpower::vpd::exceptions;
 using namespace phosphor::logging;
 
-static const deviceTreeMap deviceTreeSystemTypeMap = {
-    {RAINIER_2U, "conf-aspeed-bmc-ibm-rainier-p1.dtb"},
-    {RAINIER_2U_V2, "conf-aspeed-bmc-ibm-rainier.dtb"},
-    {RAINIER_4U, "conf-aspeed-bmc-ibm-rainier-4u-p1.dtb"},
-    {RAINIER_4U_V2, "conf-aspeed-bmc-ibm-rainier-4u.dtb"},
-    {RAINIER_1S4U, "conf-aspeed-bmc-ibm-rainier-1s4u.dtb"},
-    {EVEREST, "conf-aspeed-bmc-ibm-everest.dtb"}};
-
 /**
  * @brief Returns the power state for chassis0
  */
@@ -674,6 +666,13 @@
 {
     // Init with default dtb
     string newDeviceTree = "conf-aspeed-bmc-ibm-rainier-p1.dtb";
+    static const deviceTreeMap deviceTreeSystemTypeMap = {
+        {RAINIER_2U, "conf-aspeed-bmc-ibm-rainier-p1.dtb"},
+        {RAINIER_2U_V2, "conf-aspeed-bmc-ibm-rainier.dtb"},
+        {RAINIER_4U, "conf-aspeed-bmc-ibm-rainier-4u-p1.dtb"},
+        {RAINIER_4U_V2, "conf-aspeed-bmc-ibm-rainier-4u.dtb"},
+        {RAINIER_1S4U, "conf-aspeed-bmc-ibm-rainier-1s4u.dtb"},
+        {EVEREST, "conf-aspeed-bmc-ibm-everest.dtb"}};
 
     if (deviceTreeSystemTypeMap.find(systemType) !=
         deviceTreeSystemTypeMap.end())
@@ -1171,38 +1170,7 @@
         // set the U-boot environment variable for device-tree
         if constexpr (is_same<T, Parsed>::value)
         {
-            const string imKeyword = getIM(vpdMap);
-            const string hwKeyword = getHW(vpdMap);
-            string systemType = imKeyword;
-
-            // check If system has constraint then append HW version to it.
-            ifstream sysJson(SYSTEM_JSON);
-            if (!sysJson)
-            {
-                throw((VpdJsonException("Failed to access Json path",
-                                        SYSTEM_JSON)));
-            }
-
-            try
-            {
-                auto systemJson = json::parse(sysJson);
-                if (systemJson["system"].find(imKeyword) !=
-                    systemJson["system"].end())
-                {
-                    if (systemJson["system"][imKeyword].find("constraint") !=
-                        systemJson["system"][imKeyword].end())
-                    {
-                        systemType += "_" + hwKeyword;
-                    }
-                }
-            }
-            catch (const json::parse_error& ex)
-            {
-                throw((VpdJsonException("System Json parsing failed",
-                                        SYSTEM_JSON)));
-            }
-
-            setDevTreeEnv(systemType);
+            setDevTreeEnv(fs::path(getSystemsJson(vpdMap)).filename());
         }
     }