init: Add init script to setup /etc mount before starting systemd

Systemd requires /etc mounted and ready at init time. Previously, we
were mounting /etc as an overlay from the persistant filesystem after
systemd started. This caused a variety of issues with systemd and
associated applications (journal, etc).
This change also adds factory reset functionality.

Resolves openbmc/openbmc#2542

Change-Id: Ib8a38e99df39f833026fe4475670a7ec2b9c8d4d
Signed-off-by: Edward A. James <eajames@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 1a20660..40ec068 100644
--- a/common/recipes-phosphor/flash/phosphor-software-manager/obmc-flash-bmc
+++ b/common/recipes-phosphor/flash/phosphor-software-manager/obmc-flash-bmc
@@ -59,6 +59,14 @@
   echo "${n}"
 }
 
+# Set the u-boot env command that performs the factory reset if requested
+set_do_rwreset() {
+  if ! fw_printenv do_rwreset; then
+    fw_setenv do_rwreset "if test \"\${rwreset}\" = \"true\"; then ubi remove rwfs; ubi create rwfs 0x400000; fi"
+    fw_setenv obmc_bootcmd "ubi part obmc-ubi; run do_rwreset; ubi read \${loadaddr} \${kernelname}; bootm \${loadaddr}"
+  fi
+}
+
 # Make space on flash before creating new volumes. This can be enhanced
 # determine current flash usage. For now only keep a "keepmax" number of them
 ubi_remove_volumes()
@@ -239,6 +247,8 @@
       fi
     done
   done
+
+  set_do_rwreset
 }
 
 # Read the current env variable and set it on the alternate boot env
@@ -323,19 +333,6 @@
   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"
@@ -396,9 +393,6 @@
   rebootguarddisable)
     rebootguarddisable
     ;;
-  reset)
-    factory_reset
-    ;;
   *)
     echo "Invalid argument"
     exit 1