mmc: Add support for update/delete hostfw

The hostfw image file can be delivered in the code update
tarball. If it is, then update it (copy the file to the
hostfw partition directory.

To delete it, need to first unmount the secondary (non-
running) hostfw mount, then delete the file.

Change-Id: I352dd017114d58b79f9e624983841eafce5badf1
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/obmc-flash-bmc b/obmc-flash-bmc
index 4611d91..c7f9e14 100644
--- a/obmc-flash-bmc
+++ b/obmc-flash-bmc
@@ -489,6 +489,14 @@
   # Run this after sgdisk for labels to take effect.
   partprobe
 
+  # Update hostfw
+  if [ -f ${imgpath}/${version}/image-hostfw ]; then
+    hostfwdir=$(grep "hostfw " /proc/mounts | cut -d " " -f 2)
+    cp ${imgpath}/${version}/image-hostfw ${hostfwdir}/hostfw-${label}
+    mkdir -p ${hostfwdir}/alternate
+    mount ${hostfwdir}/hostfw-${label} ${hostfwdir}/alternate -o ro
+  fi
+
   # Store the label where the other properties like purpose and priority are
   # preserved via the storePriority() function in the serialize files, so that
   # it can be used for the remove function.
@@ -512,6 +520,17 @@
   fi
   dd if=/dev/zero of=/dev/disk/by-partlabel/boot-${label} count=2048
   dd if=/dev/zero of=/dev/disk/by-partlabel/rofs-${label} count=2048
+
+  hostfw_alt="hostfw/alternate"
+  if grep -q "${hostfw_alt}" /proc/mounts; then
+    hostfw_alt=$(grep "${hostfw_alt}" /proc/mounts | cut -d " " -f 2)
+    umount "${hostfw_alt}"
+  fi
+  hostfw_base="hostfw "
+  if grep -q "${hostfw_base}" /proc/mounts; then
+    hostfw_base=$(grep "${hostfw_base}" /proc/mounts | cut -d " " -f 2)
+    rm -f ${hostfw_base}/hostfw-${label}
+  fi
 }
 
 # Set the requested version as primary for the BMC to boot from upon reboot.