Add more specific recovery reasons for EC software sync.

Software sync will, of course, work perfectly, so these will never be needed.

BUG=none
TEST=none (hey, it all works perfectly)

Change-Id: I0014dfb99507c5eb00de73b77edb7538b598658f
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/28495
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
diff --git a/firmware/include/vboot_nvstorage.h b/firmware/include/vboot_nvstorage.h
index 2b80caf..fbc847f 100644
--- a/firmware/include/vboot_nvstorage.h
+++ b/firmware/include/vboot_nvstorage.h
@@ -97,10 +97,20 @@
 /* Recovery mode TPM initialization requires a system reboot.  The system was
  * already in recovery mode for some other reason when this happened. */
 #define VBNV_RECOVERY_RO_TPM_REBOOT   0x21
-/* Other EC software sync error */
+/* EC software sync - other error */
 #define VBNV_RECOVERY_EC_SOFTWARE_SYNC 0x22
-/* Unable to determine active EC image */
+/* EC software sync - unable to determine active EC image */
 #define VBNV_RECOVERY_EC_UNKNOWN_IMAGE 0x23
+/* EC software sync - error obtaining EC image hash */
+#define VBNV_RECOVERY_EC_HASH         0x24
+/* EC software sync - error obtaining expected EC image */
+#define VBNV_RECOVERY_EC_EXPECTED_IMAGE 0x25
+/* EC software sync - error updating EC */
+#define VBNV_RECOVERY_EC_UPDATE       0x26
+/* EC software sync - unable to jump to EC-RW */
+#define VBNV_RECOVERY_EC_JUMP_RW      0x27
+/* EC software sync - unable to protect / unprotect EC-RW */
+#define VBNV_RECOVERY_EC_PROTECT      0x28
 /* Unspecified/unknown error in read-only firmware */
 #define VBNV_RECOVERY_RO_UNSPECIFIED  0x3F
 /* User manually requested recovery by pressing a key at developer
diff --git a/firmware/lib/vboot_api_kernel.c b/firmware/lib/vboot_api_kernel.c
index e38a949..578031d 100644
--- a/firmware/lib/vboot_api_kernel.c
+++ b/firmware/lib/vboot_api_kernel.c
@@ -355,14 +355,14 @@
     VBDEBUG(("VbExEcProtectRW() needs reboot\n"));
   } else if (rv != VBERROR_SUCCESS) {
     VBDEBUG(("VbExEcProtectRW() returned %d\n", rv));
-    VbSetRecoveryRequest(VBNV_RECOVERY_EC_SOFTWARE_SYNC);
+    VbSetRecoveryRequest(VBNV_RECOVERY_EC_PROTECT);
   }
   return rv;
 }
 
 VbError_t VbEcSoftwareSync(VbSharedDataHeader *shared) {
   int in_rw = 0;
-  int rv = VbExEcRunningRW(&in_rw);
+  int rv;
   const uint8_t *ec_hash;
   int ec_hash_size;
   const uint8_t *expected;
@@ -371,6 +371,9 @@
   int need_update;
   int i;
 
+  /* Determine whether the EC is in RO or RW */
+  rv = VbExEcRunningRW(&in_rw);
+
   if (shared->recovery_reason) {
     /* Recovery mode; just verify the EC is in RO code */
     if (rv == VBERROR_SUCCESS && in_rw == 1) {
@@ -432,13 +435,13 @@
   rv = VbExEcHashRW(&ec_hash, &ec_hash_size);
   if (rv) {
       VBDEBUG(("VbEcSoftwareSync() - VbExEcHashRW() returned %d\n", rv));
-      VbSetRecoveryRequest(VBNV_RECOVERY_EC_SOFTWARE_SYNC);
+      VbSetRecoveryRequest(VBNV_RECOVERY_EC_HASH);
       return VBERROR_EC_REBOOT_TO_RO_REQUIRED;
   }
   if (ec_hash_size != SHA256_DIGEST_SIZE) {
       VBDEBUG(("VbEcSoftwareSync() - VbExEcHashRW() returned wrong size %d\n",
                ec_hash_size));
-      VbSetRecoveryRequest(VBNV_RECOVERY_EC_SOFTWARE_SYNC);
+      VbSetRecoveryRequest(VBNV_RECOVERY_EC_HASH);
       return VBERROR_EC_REBOOT_TO_RO_REQUIRED;
   }
 
@@ -455,7 +458,7 @@
     &expected, &expected_size);
   if (rv) {
     VBDEBUG(("VbEcSoftwareSync() - VbExEcGetExpectedRW() returned %d\n", rv));
-    VbSetRecoveryRequest(VBNV_RECOVERY_EC_SOFTWARE_SYNC);
+    VbSetRecoveryRequest(VBNV_RECOVERY_EC_EXPECTED_IMAGE);
     return VBERROR_EC_REBOOT_TO_RO_REQUIRED;
   }
   VBDEBUG(("VbEcSoftwareSync() - expected len = %d\n", expected_size));
@@ -502,7 +505,7 @@
       return rv;
     } else if (rv != VBERROR_SUCCESS) {
       VBDEBUG(("VbEcSoftwareSync() - VbExEcUpdateRW() returned %d\n", rv));
-      VbSetRecoveryRequest(VBNV_RECOVERY_EC_SOFTWARE_SYNC);
+      VbSetRecoveryRequest(VBNV_RECOVERY_EC_UPDATE);
       return VBERROR_EC_REBOOT_TO_RO_REQUIRED;
     }
 
@@ -522,7 +525,7 @@
   rv = VbExEcJumpToRW();
   if (rv != VBERROR_SUCCESS) {
     VBDEBUG(("VbEcSoftwareSync() - VbExEcJumpToRW() returned %d\n", rv));
-    VbSetRecoveryRequest(VBNV_RECOVERY_EC_SOFTWARE_SYNC);
+    VbSetRecoveryRequest(VBNV_RECOVERY_EC_JUMP_RW);
     return VBERROR_EC_REBOOT_TO_RO_REQUIRED;
   }
 
diff --git a/firmware/lib/vboot_display.c b/firmware/lib/vboot_display.c
index ffaa707..3cb1b8e 100644
--- a/firmware/lib/vboot_display.c
+++ b/firmware/lib/vboot_display.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
  * Use of this source code is governed by a BSD-style license that can be
  * found in the LICENSE file.
  *
@@ -446,7 +446,17 @@
   case VBNV_RECOVERY_EC_SOFTWARE_SYNC:
     return "EC software sync error";
   case VBNV_RECOVERY_EC_UNKNOWN_IMAGE:
-    return "Unable to determine active EC image";
+    return "EC software sync unable to determine active EC image";
+  case VBNV_RECOVERY_EC_HASH:
+    return "EC software sync error obtaining EC image hash";
+  case VBNV_RECOVERY_EC_EXPECTED_IMAGE:
+    return "EC software sync error obtaining expected EC image from BIOS";
+  case VBNV_RECOVERY_EC_UPDATE:
+    return "EC software sync error updating EC";
+  case VBNV_RECOVERY_EC_JUMP_RW:
+    return "EC software sync unable to jump to EC-RW";
+  case VBNV_RECOVERY_EC_PROTECT:
+    return "EC software sync protection error";
   case VBNV_RECOVERY_RO_UNSPECIFIED:
     return "Unspecified/unknown error in RO firmware";
   case VBNV_RECOVERY_RW_DEV_SCREEN: