mmc: Add read-only directory to support mboxd

The mboxd implementation assumes that there is a read-only and
read-write directory. During a write request, mboxd copies the
contents of the read-only to the read-write directory. To continue
to support mboxd, mount a read-only directory of the hostfw image
for mboxd to use. Otherwise the write command fails (can't copy
the file to itself) and mboxd exits.

Tested: Verified mboxd didn't fail and system powered on.

Change-Id: Idcb8ff0c5eee0179d5d70e60e5e01c7d0f76b880
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/mmc/obmc-flash-bios b/mmc/obmc-flash-bios
index 0a496ec..4cc6bb5 100644
--- a/mmc/obmc-flash-bios
+++ b/mmc/obmc-flash-bios
@@ -2,9 +2,13 @@
 
 mmc_init() {
   base_dir="/media/hostfw"
+  ro_dir="${base_dir}/running-ro"
   running_dir="${base_dir}/running"
   prsv_dir="${base_dir}/prsv"
 
+  if [ ! -d "${ro_dir}" ]; then
+    mkdir -p "${ro_dir}"
+  fi
   if [ ! -d "${running_dir}" ]; then
     mkdir -p ${running_dir}
   fi
@@ -12,8 +16,12 @@
     mkdir -p "${prsv_dir}"
   fi
 
-  # Determine if the running dir contains the running version
+  # Mount the image that corresponds to the boot label as read-only to be used
+  # to populate the running directory.
   boot_label="$(fw_printenv -n bootside)"
+  mount ${base_dir}/hostfw-${boot_label} ${ro_dir} -o ro
+
+  # Determine if the running dir contains the running version
   running_label=""
   running_label_file="${running_dir}/partlabel"
   if [ -f "${running_label_file}" ]; then
@@ -34,16 +42,11 @@
     fi
 
     # Copy contents of running image to running dir
-    tmp_dir="/tmp/hostfw"
-    mkdir -p "${tmp_dir}"
-    mount ${base_dir}/hostfw-${boot_label} ${tmp_dir} -o ro
     rm -f ${running_dir}/*
-    cp -p ${tmp_dir}/* ${running_dir}/
-    umount ${tmp_dir}
-    rm -rf ${tmp_dir}
+    cp -p ${ro_dir}/* ${running_dir}/
 
-    # Restore the preserved partitions
-    cp -p ${prsv_dir}/* ${running_dir}/ || true
+    # Restore the preserved partitions. Ignore error, there may be none.
+    cp -p ${prsv_dir}/* ${running_dir}/ 2>/dev/null || true
     rm -f ${prsv_dir}/*
 
     # Save the label