fstab: require service file to mount /var - fixes BMC factory reset

This commit adds a service file requirement to fstab for mounting
the ubi0:rwfs volume to /var. The required file is
obmc-flash-bmc-reset.service, which, when called, will perform a
BMC factory reset if the corresponding environment variable is set.

This functionality was moved out of obmc-flash-bmc-ubirw.service because
the factory reset is not the only procedure that calls that service.
Moving this function to a new service avoids unexpected behaviors.

Resolves openbmc/openbmc#2326

Change-Id: If2a9c650f315cff23040194ec87f16c05622c85e
Signed-off-by: Michael Tritz <mtritz@us.ibm.com>
diff --git a/common/recipes-phosphor/flash/phosphor-software-manager/obmc-flash-bmc b/common/recipes-phosphor/flash/phosphor-software-manager/obmc-flash-bmc
index 2025a05..1a20660 100644
--- a/common/recipes-phosphor/flash/phosphor-software-manager/obmc-flash-bmc
+++ b/common/recipes-phosphor/flash/phosphor-software-manager/obmc-flash-bmc
@@ -100,11 +100,6 @@
   rw="${rwmtd#mtd}"
   ubidev="/dev/ubi${rw}"
 
-  if [ "$(fw_printenv rwreset 2>/dev/null)" == "rwreset=true" ]; then
-    ubi_remove "${name}"
-    fw_setenv rwreset
-  fi
-
   # Create a ubi volume of size 4MB, that is the current size of the rwfs image
   vol="$(findubi "${name}")"
   if [ -z "${vol}" ]; then
@@ -328,6 +323,19 @@
   fi
 }
 
+factory_reset() {
+    # A lock file for printenv exists on /var, which isn't mounted when this
+    # function is called. We have to read the rwreset variable out of file.
+    ubootmtd="$(findmtd "u-boot-env")"
+    grep -q -x "rwreset=true" /dev/$ubootmtd
+    if [ "$?" = "0" ]; then
+      ubi_remove "rwfs"
+      reqmtd="bmc"
+      name="rwfs"
+      ubi_rw
+    fi
+}
+
 case "$1" in
   mtduboot)
     reqmtd="$2"
@@ -388,6 +396,9 @@
   rebootguarddisable)
     rebootguarddisable
     ;;
+  reset)
+    factory_reset
+    ;;
   *)
     echo "Invalid argument"
     exit 1