obmc-init: Add factory reset support

In obmc-init.sh, there is "clean-rwfs-filesystem" that clean the rwfs
during boot, but it backs up the files in whitelist, so it is not a
*real* factory reset.

Add a new "factory-reset" option, and when it exists, erase the rwfs
without restoring files in whitelist.

Tested: Set openbmconce=factory-reset in u-boot env, and verify the rwfs
        is erased during boot without restore;
        Set openbmconce=clean-rwfs-filesystem in u-boot env, and verify
        that rwfs is erased with whitelist restored.

Change-Id: Ifdc76da46fe273e9c942f30444173e51f8106fcc
Signed-off-by: Lei YU <mine260309@gmail.com>
diff --git a/common/recipes-phosphor/initrdscripts/files/obmc-init.sh b/common/recipes-phosphor/initrdscripts/files/obmc-init.sh
index afa8ac1..305b2dd 100644
--- a/common/recipes-phosphor/initrdscripts/files/obmc-init.sh
+++ b/common/recipes-phosphor/initrdscripts/files/obmc-init.sh
@@ -281,6 +281,15 @@
 	touch $trigger
 fi
 
+if grep -w factory-reset $optfile
+then
+	echo "Factory reset requested."
+	touch $trigger
+	do_save=--no-save-files
+else
+	do_save=--save-files
+fi
+
 if test "x$force_rwfst_jffs2" = xy -a $rwfst != jffs2 -a ! -f $trigger
 then
 	echo "Converting read-write overlay filesystem to jffs2 forced."
@@ -294,15 +303,20 @@
 		debug_takeover "Flash update requested but $update missing!"
 	elif test -f $trigger -a ! -s $trigger
 	then
-		echo "Saving selected files from read-write overlay filesystem."
-		$update --no-restore-files
+		if [ $do_save = "--save-files" ]
+		then
+			echo "Saving selected files from read-write overlay filesystem."
+		else
+			echo "No files will be selected for save."
+		fi
+		$update --no-restore-files $do_save
 		echo "Clearing read-write overlay filesystem."
 		flash_eraseall /dev/$rwfs
 		echo "Restoring saved files to read-write overlay filesystem."
 		touch $trigger
 		$update --no-save-files --clean-saved-files
 	else
-		$update --clean-saved-files
+		$update --clean-saved-files $do_save
 	fi
 
 	rwfst=$(probe_fs_type $rwdev)