crossystem: Add fw_other_slot_failed

Add a read-only crossystem property for VB2_NV_FW_OTHER_SLOT_FAILED,
which says whether the other firmware slot had failed when the device
last switched away from it. This helps debug A/B slot selection, e.g.
why a single failure leads to recovery instead of trying the other
slot.

Firmware without the field never sets the bit, so the property reads 0
there.

BRANCH=none
BUG=b:184304285
TEST=make run2tests USE_FLASHROM=0
TAG=agy
CONV=22503f2d-2161-4a37-9f9d-fe851ee04c47

Change-Id: I31ce1186a3993af465464b49aa220dd36a6a6964
Signed-off-by: Yu-Ping Wu <yupingso@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/8842419
Reviewed-by: Julius Werner <jwerner@chromium.org>
Commit-Queue: Yu-Ping Wu <yupingso@chromium.org>
Tested-by: Yu-Ping Wu <yupingso@chromium.org>
diff --git a/host/lib/crossystem.c b/host/lib/crossystem.c
index 6bcc758..2dcdf1d 100644
--- a/host/lib/crossystem.c
+++ b/host/lib/crossystem.c
@@ -478,6 +478,8 @@
 		value = vb2_get_nv_storage(VB2_NV_TPM_REQUESTED_REBOOT);
 	} else if (!strcasecmp(name,"fw_try_count")) {
 		value = vb2_get_nv_storage(VB2_NV_TRY_COUNT);
+	} else if (!strcasecmp(name, "fw_other_slot_failed")) {
+		value = vb2_get_nv_storage(VB2_NV_FW_OTHER_SLOT_FAILED);
 	} else if (!strcasecmp(name,"fw_vboot2")) {
 		value = GetVdatInt(VDAT_INT_FW_BOOT2);
 	} else if (!strcasecmp(name,"fwupdate_tries")) {
diff --git a/utility/crossystem.c b/utility/crossystem.c
index c51c56f..ea3383f 100644
--- a/utility/crossystem.c
+++ b/utility/crossystem.c
@@ -56,6 +56,8 @@
   {"ecfw_act", IS_STRING, "Active EC firmware"},
   {"post_ec_sync_delay", CAN_WRITE,
    "Short delay after EC software sync (persistent, writable, eve only)"},
+  {"fw_other_slot_failed", 0,
+   "Other firmware slot had failed at the last slot switch"},
   {"fw_prev_result", IS_STRING, "Firmware result of previous boot"},
   {"fw_prev_tried", IS_STRING, "Firmware tried on previous boot (A or B)"},
   {"fw_result", IS_STRING|CAN_WRITE, "Firmware result this boot"},