mmc: Add staging directory

Add a staging directory for PLDM to use as a temporary
holding space during inband update where the host would
send individual image files and PLDM needs to reconstruct
the code update tarball before calling the BMC updater
to do an update.

Clear the directory after a successful update. This cleanup
will eventually be handled by PLDM.

Tested: New directory and symlink created.

Change-Id: I9a2eacb0f57696e799e983625c2a32efbe122e89
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/mmc/obmc-flash-bios b/mmc/obmc-flash-bios
index c77cf8e..3fd03c2 100644
--- a/mmc/obmc-flash-bios
+++ b/mmc/obmc-flash-bios
@@ -5,6 +5,7 @@
   ro_dir="${base_dir}/running-ro"
   running_dir="${base_dir}/running"
   prsv_dir="${base_dir}/prsv"
+  staging_dir="${base_dir}/staging"
 
   if [ ! -d "${ro_dir}" ]; then
     mkdir -p "${ro_dir}"
@@ -15,6 +16,9 @@
   if [ ! -d "${prsv_dir}" ]; then
     mkdir -p "${prsv_dir}"
   fi
+  if [ ! -d "${staging_dir}" ]; then
+    mkdir -p "${staging_dir}"
+  fi
 
   # Mount the image that corresponds to the boot label as read-only to be used
   # to populate the running directory.
@@ -49,6 +53,9 @@
     cp -p ${prsv_dir}/* ${running_dir}/ 2>/dev/null || true
     rm -f ${prsv_dir}/*
 
+    # Clean up the staging dir in case of a failed update
+    rm -rf ${staging_dir}/*
+
     # Save the label
     echo "${boot_label}" > "${running_label_file}"
 
diff --git a/vpnor/obmc-vpnor-util b/vpnor/obmc-vpnor-util
index 30854bf..a2a6586 100644
--- a/vpnor/obmc-vpnor-util
+++ b/vpnor/obmc-vpnor-util
@@ -49,8 +49,10 @@
   MMC_RO_PATH="${MMC_BASE_PATH}/running-ro"
   MMC_RUNNING_PATH="${MMC_BASE_PATH}/running"
   MMC_ALTERNATE_PATH="${MMC_BASE_PATH}/alternate"
+  MMC_STAGING_PATH="${MMC_BASE_PATH}/staging"
   HOSTFW_RUNNING_PATH="${HOSTFW_ACTIVE_PATH}/running"
   HOSTFW_ALTERNATE_PATH="${HOSTFW_ACTIVE_PATH}/alternate"
+  HOSTFW_STAGING_PATH="${HOSTFW_ACTIVE_PATH}/staging"
 
   # Get a list of all active PNOR versions
   data="$(ls -d ${PNOR_RO_PREFIX}* 2>/dev/null)"
@@ -96,6 +98,10 @@
           rm -f ${HOSTFW_ALTERNATE_PATH}
           ln -sfv ${MMC_ALTERNATE_PATH} ${HOSTFW_ALTERNATE_PATH}
       fi
+      if [[ $(readlink -f "${HOSTFW_STAGING_PATH}") != ${MMC_STAGING_PATH} ]]; then
+          rm -f ${HOSTFW_STAGING_PATH}
+          ln -sfv ${MMC_STAGING_PATH} ${HOSTFW_STAGING_PATH}
+      fi
   fi
 
   if [ ! -d "${PNOR_ACTIVE_PATH}" ]; then