meta-phosphor: static-norootfs-init: support factory-reset

Add support to check the uboot environment for 'factory-reset' as
programmed by phosphor-bmc-code-mgmt's FactoryReset interface.

Tested:

Ran the following and observed the file missing after reboot:
```
touch /var/DELETE_THIS_FILE
busctl call xyz.openbmc_project.Software.BMC.Updater \
    /xyz/openbmc_project/software \
    xyz.openbmc_project.Common.FactoryReset Reset
reboot
```

During the reboot observed the following message, along with ubiformat
messages:
```
Formatting persistent volume:
factory-reset
```

Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I7c0d73cedc6414a590a0f99b68c843c88a7aded7
diff --git a/meta-phosphor/recipes-phosphor/initrdscripts/phosphor-static-norootfs-init.bb b/meta-phosphor/recipes-phosphor/initrdscripts/phosphor-static-norootfs-init.bb
index 61762a5..789431b 100644
--- a/meta-phosphor/recipes-phosphor/initrdscripts/phosphor-static-norootfs-init.bb
+++ b/meta-phosphor/recipes-phosphor/initrdscripts/phosphor-static-norootfs-init.bb
@@ -8,6 +8,7 @@
     init \
     10-early-mounts \
     20-udev \
+    21-factory-reset \
     30-ubiattach-or-format \
     50-mount-persistent \
     "
@@ -33,6 +34,8 @@
 }
 
 RDEPENDS:${PN} += " \
+    ${@d.getVar('PREFERRED_PROVIDER_u-boot-fw-utils', True) or \
+        'u-boot-fw-utils'} \
     ${VIRTUAL-RUNTIME_base-utils} \
     mtd-utils-ubifs \
     udev \
diff --git a/meta-phosphor/recipes-phosphor/initrdscripts/phosphor-static-norootfs-init/21-factory-reset b/meta-phosphor/recipes-phosphor/initrdscripts/phosphor-static-norootfs-init/21-factory-reset
new file mode 100644
index 0000000..0c435f8
--- /dev/null
+++ b/meta-phosphor/recipes-phosphor/initrdscripts/phosphor-static-norootfs-init/21-factory-reset
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+if [ ! -x /sbin/fw_printenv ]; then
+    exit 1
+fi
+
+# Need to create /run/lock so fw_printenv can create lockfile.
+mkdir /run/lock
+
+# Check uboot keys for 'factory-reset'
+if /sbin/fw_printenv openbmcinit openbmconce | grep -q factory-reset ; then
+    echo "factory-reset" >> /run/format-persist
+fi
diff --git a/meta-phosphor/recipes-phosphor/initrdscripts/phosphor-static-norootfs-init/30-ubiattach-or-format b/meta-phosphor/recipes-phosphor/initrdscripts/phosphor-static-norootfs-init/30-ubiattach-or-format
index 8a0cbc6..39aa876 100644
--- a/meta-phosphor/recipes-phosphor/initrdscripts/phosphor-static-norootfs-init/30-ubiattach-or-format
+++ b/meta-phosphor/recipes-phosphor/initrdscripts/phosphor-static-norootfs-init/30-ubiattach-or-format
@@ -4,7 +4,16 @@
     exit 1
 fi
 
-if ! ubiattach -p /dev/mtd/rwfs > /dev/null ; then
+if [ ! -e /run/format-persist ]; then
+    if ! ubiattach -p /dev/mtd/rwfs > /dev/null ; then
+        echo "unformatted-ubi" >> /run/format-persist
+    fi
+fi
+
+if [ -e /run/format-persist ]; then
+    echo "Formatting persistent volume: "
+    cat /run/format-persist
+
     if ! ubiformat --yes /dev/mtd/rwfs ; then
         exit 1
     fi