factory_install: Add RMA_AUTORUN flag.

RMA flow should be as easy as possible. By adding a flag RMA_AUTORUN
in lsb-factory, we can avoid asking the user to select from various
options in the menu. When the flag is set to true, the script will
do RSU when HWWP is on, and do install when HWWP is off.

BUG=b:118785701
TEST=None
CQ-DEPEND=CL:1322469

Change-Id: Ib2f056c874a01551da7e0edd5d29ed4d368c3eec
Reviewed-on: https://chromium-review.googlesource.com/1322289
Commit-Ready: Cheng-Han Yang <chenghan@chromium.org>
Tested-by: Cheng-Han Yang <chenghan@chromium.org>
Reviewed-by: Wei-Han Chen <stimim@chromium.org>
diff --git a/factory_install.sh b/factory_install.sh
index 8848e70..47d27ae 100644
--- a/factory_install.sh
+++ b/factory_install.sh
@@ -37,9 +37,10 @@
 # - Override this for The default action if no keys were pressed before timeout.
 DEFAULT_ACTION="$(findLSBValue FACTORY_INSTALL_DEFAULT_ACTION)"
 
-# Variables prepared by make_factory_package or netboot initramfs code.
+# Variables prepared by image_tool or netboot initramfs code.
 NETBOOT_RAMFS="$(findLSBValue NETBOOT_RAMFS)"
 FACTORY_INSTALL_FROM_USB="$(findLSBValue FACTORY_INSTALL_FROM_USB)"
+RMA_AUTORUN="$(findLSBValue RMA_AUTORUN)"
 
 # Global variables
 DST_DRIVE=""
@@ -1327,8 +1328,16 @@
 
   # Read default options
   if [ "${NETBOOT_RAMFS}" = 1 ]; then
-    log "Netbooting. Set default action to (I)nstall."
+    log "Netbooting. Set default action to (I) Install."
     DEFAULT_ACTION=i
+  elif [ "${RMA_AUTORUN}" = "true" ]; then
+    if crossystem 'wpsw_cur?1' 2>/dev/null; then
+      log "Hardware write protect on. Set default action to (E) Reset Cr50."
+      DEFAULT_ACTION=e
+    else
+      log "Hardware write protect off. Set default action to (I) Install."
+      DEFAULT_ACTION=i
+    fi
   fi
 
   # Sanity check default action