functions: Create symlinks for hostfw elements

Create symlinks for the hostfw elements to point to their corresponding
lid files. The hostfw image would not have the hostfw element files,
only lid files. The symlinks allow applications such as mboxd and
openpower-proc-control to read data for the appropriate system type
since the symlink would be pointing to the right lid file depending on
system type.

No need to hardcode the symlink for HBB, this is done automatically now
based on the JSON file.

Tested:
Verified all element files pointed to the right lid file, ex:

lrwxrwxrwx    1 root     root            12 Jul 26 16:08 DEVTREE ->
81e00673.lid
lrwxrwxrwx    1 root     root            12 Jul 26 16:08 HBB ->
81e0065a.lid

Change-Id: Ia5791be0980301022c64c2469be92ab4add61a75
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/functions.cpp b/functions.cpp
index f35ab9c..88c7841 100644
--- a/functions.cpp
+++ b/functions.cpp
@@ -220,16 +220,6 @@
         return;
     }
 
-    // Create a symlink from HBB to the corresponding LID file if it exists
-    static const auto hbbLid = "81e0065a.lid";
-    auto hbbLidPath = hostFirmwareDirectory / hbbLid;
-    if (std::filesystem::exists(hbbLidPath))
-    {
-        static const auto hbbName = "HBB";
-        auto hbbLinkPath = hostFirmwareDirectory / hbbName;
-        makeCallback(linkCallback, hbbLid, hbbLinkPath, errorCallback);
-    }
-
     for (; directoryIterator != std::filesystem::end(directoryIterator);
          directoryIterator.increment(ec))
     {
@@ -348,6 +338,23 @@
         // Build the bios attribute string with format:
         // "element1=lid1,element2=lid2,elementN=lidN,"
         biosAttrStr += a.first + "=" + a.second + ",";
+
+        // Create symlinks from the hostfw elements to their corresponding
+        // lid files if they don't exist
+        auto elementFilePath =
+            std::filesystem::path("/media/hostfw/running") / a.first;
+        if (!std::filesystem::exists(elementFilePath))
+        {
+            std::error_code ec;
+            auto lidName = a.second + ".lid";
+            std::filesystem::create_symlink(lidName, elementFilePath, ec);
+            if (ec)
+            {
+                log<level::ERR>("Error creating symlink",
+                                entry("TARGET=%s", lidName.c_str()),
+                                entry("LINK=%s", elementFilePath.c_str()));
+            }
+        }
     }
 
     return biosAttrStr;