factory_reset: only check write protection when device is in PVT phase.

When resetting device back to shipping mode, software write protection
should be checked in order to make sure it is enabled correctly. But for
pre-PVT devices, write protection is allowed to remain disabled. As the
result, we should check write protection only if this device is in PVT
phase.

BUG=b:80481691
TEST=manaully test in the DUT.

Change-Id: I4efc0358beb1b903b0305b073558ff176e93a531
Reviewed-on: https://chromium-review.googlesource.com/1084518
Commit-Ready: Marco Chen <marcochen@chromium.org>
Tested-by: Marco Chen <marcochen@chromium.org>
Reviewed-by: Marco Chen <marcochen@chromium.org>
diff --git a/factory_install.sh b/factory_install.sh
index 293ed0d..6e19af9 100644
--- a/factory_install.sh
+++ b/factory_install.sh
@@ -161,6 +161,23 @@
   exit 1
 }
 
+is_pvt_phase() {
+  # If there is any error then pvt phase is returned as a safer default
+  # option.
+  output=$(gsctool -a -i 2>&1) || return 0
+
+  board_id="$(echo "${output}" | awk '/Board ID/ {gsub(/.*: /,""); print}')"
+  board_flags="0x$(echo "${board_id}" | sed 's/.*://')"
+
+  # If board phase is not 0x0 then this is a development board.
+  pre_pvt=$(( board_flags & 0x7F ))
+  if (( pre_pvt > 0 )); then
+    return ${pre_pvt}
+  fi
+
+  return 0
+}
+
 config_tty() {
   stty opost
 
@@ -991,8 +1008,8 @@
     return
   fi
 
-  check_fw_swwp host && check_fw_swwp ec || \
-    die "SW write protect is not enabled."
+  check_fw_swwp host && check_fw_swwp ec || ! is_pvt_phase || \
+    die "SW write protect is not enabled in the device with PVT phase."
 
   reset_chromeos_device
   factory_reset