mmc: Handle missing pnor.toc file

The pnor.toc file is a mboxd implemenation, and therefore will not exist
once the host uses PLDM instead, which uses .lid files instead of pnor
partition files. As part of the transition, the pnor.toc file is being
built into a .lid file for images that do not contain pnor partition
files. Handle this transition by creating a symlink from pnor partition
file to .lid file. This would remain in place until all the PLDM support
from the hostboot side is in place and mboxd is removed.

Tested: Verified rainier powers on and mboxd starts successfully, and
the volatile partition gets cleared.

Change-Id: I59364c0abf100dab5a38d277f0587d0dd221b53d
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/functions.cpp b/functions.cpp
index 0404d00..db7f529 100644
--- a/functions.cpp
+++ b/functions.cpp
@@ -220,6 +220,16 @@
         return;
     }
 
+    // Create a symlink for pnor.toc
+    static const auto tocLid = "81e00994.lid";
+    auto tocLidPath = hostFirmwareDirectory / tocLid;
+    if (std::filesystem::exists(tocLidPath))
+    {
+        static const auto tocName = "pnor.toc";
+        auto tocLinkPath = hostFirmwareDirectory / tocName;
+        makeCallback(linkCallback, tocLid, tocLinkPath, errorCallback);
+    }
+
     for (; directoryIterator != std::filesystem::end(directoryIterator);
          directoryIterator.increment(ec))
     {
diff --git a/mmc/obmc-flash-bios b/mmc/obmc-flash-bios
index 60490b2..478e63f 100644
--- a/mmc/obmc-flash-bios
+++ b/mmc/obmc-flash-bios
@@ -35,11 +35,11 @@
   fi
   if [ "${running_label}" != "${boot_label}" ]; then
     # Copy off the preserved partitions
-    # A line in the pnor.toc looks like this:
+    # A line in the pnor.toc (81e00994.lid) looks like this:
     # partition05=SECBOOT,0x00381000,0x003a5000,00,ECC,PRESERVED
     rm -f ${prsv_dir}/*
-    if [ -f ${ro_dir}/pnor.toc ]; then
-      prsvs=$(grep PRESERVED ${ro_dir}/pnor.toc)
+    if [ -f "${ro_dir}/81e00994.lid" ]; then
+      prsvs=$(grep PRESERVED "${ro_dir}/81e00994.lid")
       for prsv in ${prsvs}; do
         prsv=${prsv##partition*=}
         prsv=$(echo "${prsv}" | cut -d "," -f 1)
diff --git a/mmc/openpower-update-bios-attr-table.service b/mmc/openpower-update-bios-attr-table.service
index 898cb7e..6dbb608 100644
--- a/mmc/openpower-update-bios-attr-table.service
+++ b/mmc/openpower-update-bios-attr-table.service
@@ -3,6 +3,7 @@
 After=org.open_power.Software.Host.Updater.service
 After=obmc-flash-bios-init.service
 After=openpower-process-host-firmware.service
+Before=mboxd.service
 
 [Service]
 Type=oneshot
diff --git a/vpnor/obmc-vpnor-util b/vpnor/obmc-vpnor-util
index 380f974..e69390e 100644
--- a/vpnor/obmc-vpnor-util
+++ b/vpnor/obmc-vpnor-util
@@ -15,6 +15,9 @@
   # toc partition string format:
   # partition27=HB_VOLATILE,0x02ba9000,0x02bae000,00,ECC,VOLATILE,READWRITE
   tocFilePath="${PNOR_RO_ACTIVE_PATH}${PNOR_TOC_FILE}"
+  if [ ! -f "${tocFilePath}" ]; then
+    tocFilePath="${PNOR_RW_ACTIVE_PATH}${PNOR_TOC_FILE}"
+  fi
   mapfile -t volatiles < <(grep VOLATILE "${tocFilePath}" | grep -Eo '^partition([0-9]+)=([A-Za-z0-9_]+)')
   for (( index=0; index<${#volatiles[@]}; index++ )); do
     volatileName="$(echo "${volatiles[${index}]}" | awk -F '=' '{print $2}')"
@@ -29,6 +32,11 @@
       echo "Clear $prsvVolatile"
       rm "${prsvVolatile}"
     fi
+
+    if [ ! -f "${PNOR_RO_ACTIVE_PATH}${volatileName}" ]; then
+      cp -a "${PNOR_RO_ACTIVE_PATH}81e0066f.lid" "${PNOR_PRSV_ACTIVE_PATH}"
+      ln -s "81e0066f.lid" "${PNOR_PRSV_ACTIVE_PATH}${volatileName}"
+    fi
   done
   # Always reset the sensor after clearing
   busctl set-property "$service" /org/open_power/control/volatile xyz.openbmc_project.Object.Enable Enabled b false