factory_install: Assume device in factory mode if cr50 version is 0.0.*.

When the device is booted into factory shim right after manufactured,
it is in factory mode but its cr50 is in a default old version and does
not support '-I' option and factory mode. In this case, treat it as
factory mode enabled to avoid turning on factory mode.

BUG=b:119289254
TEST=Manually test on DUT.

Change-Id: I2ae6d8ffa2937a29fd23d29e6fea5df84c4fc248
Reviewed-on: https://chromium-review.googlesource.com/1329381
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 bba7c94..9e5e841 100644
--- a/factory_install.sh
+++ b/factory_install.sh
@@ -163,7 +163,20 @@
   exit 1
 }
 
+get_cr50_rw_version() {
+  echo "$(${GSCTOOL} -a -f | grep 'RW' | grep -oE '[0-9]+.[0-9]+.[0-9]+')"
+}
+
 is_cr50_factory_mode_enabled() {
+  # If the cr50 RW version is 0.0.*, the device is booted to install shim
+  # straight from factory. The cr50 firmware does not support '-I' option and
+  # factory mode, so we treat it as factory mode enabled to avoid turning on
+  # factory mode.
+  local rw_version="$(get_cr50_rw_version)"
+  if [[ "${rw_version}" = '0.0.'* ]]; then
+    echo "Cr50 version is ${rw_version}. Assume factory mode enabled."
+    return 0
+  fi
   # The pattern of output is:
   # State: Locked
   # Password: None