Add check-value support and check /proc/cmdline for cros_nodebug

Change-Id: I35158810184be03f18d98893e4dd640088384579

BUG=12904
TEST=manual

crossystem fwb_tries=1
crossystem fwb_tries?1 && echo YES || echo NO --> YES
crossystem fwb_tries?0x01 && echo YES || echo NO --> YES
crossystem fwb_tries?0 && echo YES || echo NO --> NO

crossystem fwb_tries=0
crossystem fwb_tries?0 && echo YES || echo NO --> YES
crossystem fwb_tries?1 && echo YES || echo NO --> NO
crossystem fwb_tries?0x01 && echo YES || echo NO --> NO

crossystem ecfw_act --> RW (if it's not, change RW to RO in the tests below)
crossystem ecfw_act?RW && echo YES || echo NO --> YES
crossystem ecfw_act?BOB && echo YES || echo NO --> NO

For the following tests, boot Alex with dev switch on and fwb_tries=1
Expected output of `crossystem mainfw_type mainfw_act cros_debug` under each of the following scenarios:
* Neither "cros_debug" nor" cros_nodebug" in kernel command line: normal B 1
* Kernel command line changed to include "cros_nodebug": normal B 0
* Kernel command line changed to include "cros_nodebugg": normal B 1
* Kernel command line changed to include "ccros_nodebug": normal B 1

Review URL: http://codereview.chromium.org/6665005
diff --git a/utility/crossystem_main.c b/utility/crossystem_main.c
index 584de59..90ad718 100644
--- a/utility/crossystem_main.c
+++ b/utility/crossystem_main.c
@@ -70,8 +70,11 @@
          "    Prints the current value(s) of the parameter(s).\n"
          "  %s [param1=value1] [param2=value2 [...]]]\n"
          "    Sets the parameter(s) to the specified value(s).\n"
+         "  %s [param1?value1] [param2?value2 [...]]]\n"
+         "    Checks if the parameter(s) all contain the specified value(s).\n"
+         "Stops at the first error."
          "\n"
-         "Valid parameters:\n", progname, progname, progname);
+         "Valid parameters:\n", progname, progname, progname, progname);
   for (p = sys_param_list; p->name; p++)
     printf("  %-22s  %s\n", p->name, p->desc);
 }
@@ -101,7 +104,7 @@
     return (0 == VbSetSystemPropertyString(p->name, value) ? 0 : 1);
   } else {
     char* e;
-    int i = strtol(value, &e, 0);
+    int i = (int)strtol(value, &e, 0);
     if (!*value || (e && *e))
       return 1;
     return (0 == VbSetSystemPropertyInt(p->name, i) ? 0 : 1);
@@ -109,6 +112,28 @@
 }
 
 
+/* Compares the parameter with the expected value.
+ *
+ * Returns 0 if success (match), non-zero if error (mismatch). */
+int CheckParam(const Param* p, char* expect) {
+  if (p->is_string) {
+    char buf[256];
+    const char* v = VbGetSystemPropertyString(p->name, buf, sizeof(buf));
+    if (!v || 0 != strcmp(v, expect))
+      return 1;
+  } else {
+    char* e;
+    int i = (int)strtol(expect, &e, 0);
+    int v = VbGetSystemPropertyInt(p->name);
+    if (!*expect || (e && *e))
+      return 1;
+    if (v == -1 || i != v)
+      return 1;
+  }
+  return 0;
+}
+
+
 /* Print the specified parameter.
  *
  * Returns 0 if success, non-zero if error. */
@@ -179,19 +204,28 @@
 
   /* Otherwise, loop through params and get/set them */
   for (i = 1; i < argc && retval == 0; i++) {
-    char* name = strtok(argv[i], "=");
-    char* value = strtok(NULL, "=");
+    int has_set = (NULL != strchr(argv[i], '='));
+    int has_expect = (NULL != strchr(argv[i], '?'));
+    char* name = strtok(argv[i], "=?");
+    char* value = strtok(NULL, "=?");
     const Param* p = FindParam(name);
     if (!p) {
       fprintf(stderr, "Invalid parameter name: %s\n", name);
       PrintHelp(progname);
       return 1;
     }
+    if (has_set && has_expect) {
+      fprintf(stderr, "Use either = or ? in a parameter, but not both.\n");
+      PrintHelp(progname);
+      return 1;
+    }
 
     if (i > 1)
       printf(" ");  /* Output params space-delimited */
-    if (value)
+    if (has_set)
       retval = SetParam(p, value);
+    else if (has_expect)
+      retval = CheckParam(p, value);
     else
       retval = PrintParam(p);
   }