use crossystem for developer mode and nonchrome detection

Adds crossystem use for developer mode detection and nonchrome detection.
[This allows systems with missing or damaged TPMs or bad firmware to
 go through recovery as nonchrome systems.]

(testing in progress)
TEST=create a devkeys x86-alex image, boot it and install it in both modes
     same thing for x86-mario
     boot x86-mario, goto a shell, run crossystem mainfw_act to ensure it never says nonchrome
     again for a nonchrome system
BUG=chromium-os:13399,chromium-os:8762

Change-Id: I538fe37fbed29537132da15c844b75ce726634bf

R=gauravsh@chromium.org

Review URL: http://codereview.chromium.org/6724018
diff --git a/init b/init
index 52cd73b..1b8bd4f 100644
--- a/init
+++ b/init
@@ -572,15 +572,15 @@
   return 1
 }
 
+is_nonchrome() {
+  crossystem mainfw_type?nonchrome
+}
+
 is_developer_mode() {
-  # See Firmware High-Level Spec for details on CHSW values
-  CHSW=$(cat /sys/devices/platform/chromeos_acpi/CHSW)
-  # If the switch is unsupported, treat as developer mode.
-  [ -z "$CHSW" ] && return 0
-  if [ $CHSW -gt 0 -a $((CHSW & 32)) -eq 32 ]; then
-    return 0
-  fi
-  return 1
+  # Legacy/unsupported systems are mapped to developer mode.
+  is_nonchrome && return 0
+  # Otherwise the exit status will be accurate.
+  crossystem devsw_boot?1
 }
 
 lock_tpm() {
@@ -590,11 +590,17 @@
     tpmc startup
     tpmc ctest
     if ! tpmc block; then
-      log "An unrecoverable error occurred with your security device"
-      log "Please power down and try again."
-      dlog "Failed to lock bGlobalLock."
-      on_error
-      return 1  # Never reached.
+      if is_nonchrome; then
+        log "No security chip appears to exist in this non-Chrome device."
+        log "The security of your experience will suffer."
+        # Forge onward.
+      else
+        log "An unrecoverable error occurred with your security device"
+        log "Please power down and try again."
+        dlog "Failed to lock bGlobalLock."
+        on_error
+        return 1  # Never reached.
+      fi
     fi
     TPM_B_LOCKED=y
   fi
@@ -690,6 +696,14 @@
   # If not, we must be a recovery kernel.
   NEWROOT_MNT="$USB_MNT"
 
+  if is_nonchrome; then
+    log " "
+    log "Your computer does not appear to a Chrome computer!"
+    log " "
+    log "Your experience with Chromium OS will be suboptimal."
+    log " "
+  fi
+
   # Always lock the TPM.  If a NVRAM reset is ever needed, we can change it.
   lock_tpm || on_error