Fix WP polarity on Mario

Note that both the current and boot settings are incorrect as reported
by the BIOS.  This fixes both.

Change-Id: Iebd2b4ac91232444e538f6e2763a22cb227f2e4f

BUG=chrome-os-partner:2078
TEST=manual

Run crossystem on Mario and Alex with WP enabled, disabled and check
Verify true hardware WP status by doing:
   flashrom --wp-enable
   flashrom --wp-status
   flashrom --wp-disable
   flashrom --wp-status
On a system with hardware WP enabled, the disable step should fail and write
protect will still report enabled.

Review URL: http://codereview.chromium.org/6531035
diff --git a/host/lib/crossystem.c b/host/lib/crossystem.c
index c3bee75..277749b 100644
--- a/host/lib/crossystem.c
+++ b/host/lib/crossystem.c
@@ -83,6 +83,16 @@
 }
 
 
+/* Return true if the FWID starts with the specified string. */
+static int FwidStartsWith(const char *start) {
+  char fwid[128];
+  if (!VbGetSystemPropertyString("fwid", fwid, sizeof(fwid)))
+    return 0;
+
+  return 0 == strncmp(fwid, start, strlen(start));
+}
+
+
 /* Read a GPIO of the specified signal type (see ACPI GPIO SignalType).
  *
  * Returns 1 if the signal is asserted, 0 if not asserted, or -1 if error. */
@@ -155,25 +165,31 @@
  *
  * Returns the property value, or -1 if error. */
 int VbGetSystemPropertyInt(const char* name) {
+  int value = -1;
 
   if (!strcasecmp(name,"devsw_cur")) {
-    return ReadGpio(GPIO_SIGNAL_TYPE_DEV);
+    value = ReadGpio(GPIO_SIGNAL_TYPE_DEV);
   } else if (!strcasecmp(name,"devsw_boot")) {
-    return ReadFileBit(ACPI_CHSW_PATH, CHSW_DEV_BOOT);
+    value = ReadFileBit(ACPI_CHSW_PATH, CHSW_DEV_BOOT);
   } else if (!strcasecmp(name,"recoverysw_cur")) {
-    return ReadGpio(GPIO_SIGNAL_TYPE_RECOVERY);
+    value = ReadGpio(GPIO_SIGNAL_TYPE_RECOVERY);
   } else if (!strcasecmp(name,"recoverysw_boot")) {
-    return ReadFileBit(ACPI_CHSW_PATH, CHSW_RECOVERY_BOOT);
+    value = ReadFileBit(ACPI_CHSW_PATH, CHSW_RECOVERY_BOOT);
   } else if (!strcasecmp(name,"recoverysw_ec_boot")) {
-    return ReadFileBit(ACPI_CHSW_PATH, CHSW_RECOVERY_EC_BOOT);
+    value = ReadFileBit(ACPI_CHSW_PATH, CHSW_RECOVERY_EC_BOOT);
   } else if (!strcasecmp(name,"wpsw_cur")) {
-    return ReadGpio(GPIO_SIGNAL_TYPE_WP);
+    value = ReadGpio(GPIO_SIGNAL_TYPE_WP);
+    if (-1 != value && FwidStartsWith("Mario."))
+      value = 1 - value;  /* Mario reports this backwards */
   } else if (!strcasecmp(name,"wpsw_boot")) {
-    return ReadFileBit(ACPI_CHSW_PATH, CHSW_WP_BOOT);
-  } else
-    return -1;
+    value = ReadFileBit(ACPI_CHSW_PATH, CHSW_WP_BOOT);
+    if (-1 != value && FwidStartsWith("Mario."))
+      value = 1 - value;  /* Mario reports this backwards */
+  }
 
   /* TODO: remaining properties from spec */
+
+  return value;
 }