Support new flashmap layout in dev_debug_vboot.

Make dev_debug_vboot look first for the new section names, then the old ones.

Change-Id: I723f022bbbb23257c7c57db9543d7c35f524f95d

BUG=chromium-os:12611
TEST=manual

Rerun the steps that reproduce the problem as reported in the initial bug
report. You should see much more information.

Review URL: http://codereview.chromium.org/6621003
diff --git a/utility/dev_debug_vboot b/utility/dev_debug_vboot
index a171eb4..55cdd73 100755
--- a/utility/dev_debug_vboot
+++ b/utility/dev_debug_vboot
@@ -47,9 +47,9 @@
   echo "+" "$@" "| head" >> "$LOGFILE"
   "$@" | head >> "$LOGFILE" 2>&1
 }
+
 logdie() {
   echo "+" "$@" >> "$LOGFILE"
-  "$@" >> "$LOGFILE" 2>&1
   die "$@"
 }
 
@@ -75,6 +75,19 @@
   log ls -la /root/.force_update_firmware
 }
 
+# Search for files from the FMAP, in the order listed. Return the first one
+# found or die if none are there.
+find_name() {
+  for fn in "$@"; do
+    if [ -e "$fn" ]; then
+      echo "$fn"
+      return
+    fi
+  done
+  echo "+ no files named $@" >> "$LOGFILE"
+  exit 1
+}
+
 # Here we go...
 umask 022
 trap cleanup EXIT
@@ -129,18 +142,31 @@
 info "Extracting BIOS components..."
 log dump_fmap -x ${BIOS} || logdie "Unable to extract BIOS components"
 
+# Find the FMAP regions we're interested in. Look first for the new names, then
+# the old names.
+area_gbb=$(find_name       GBB       GBB_Area) || \
+  logdie "no area_gbb"
+area_vblock_a=$(find_name  VBLOCK_A  Firmware_A_Key) || \
+  logdie "no area_vblock_a"
+area_vblock_b=$(find_name  VBLOCK_B  Firmware_B_Key) || \
+  logdie "no area_vblock_b"
+area_fw_main_a=$(find_name FW_MAIN_A Firmware_A_Data) || \
+  logdie "no area_fw_main_a"
+area_fw_main_b=$(find_name FW_MAIN_B Firmware_B_Data) || \
+  logdie "no area_fw_main_a"
+
 info "Pulling root and recovery keys from GBB..."
 log gbb_utility -g --rootkey rootkey.vbpubk --recoverykey recoverykey.vbpubk \
-  GBB_Area || logdie "Unable to extract keys from GBB"
+  "$area_gbb" || logdie "Unable to extract keys from GBB"
 log vbutil_key --unpack rootkey.vbpubk
 log vbutil_key --unpack recoverykey.vbpubk
 
 infon "Verify firmware A with root key... "
-log vbutil_firmware --verify Firmware_A_Key --signpubkey rootkey.vbpubk \
-  --fv Firmware_A_Data --kernelkey kernel_subkey_a.vbpubk ; result
+log vbutil_firmware --verify "$area_vblock_a" --signpubkey rootkey.vbpubk \
+  --fv "$area_fw_main_a" --kernelkey kernel_subkey_a.vbpubk ; result
 infon "Verify firmware B with root key... "
-log vbutil_firmware --verify Firmware_B_Key --signpubkey rootkey.vbpubk \
-  --fv Firmware_B_Data --kernelkey kernel_subkey_b.vbpubk ; result
+log vbutil_firmware --verify "$area_vblock_b" --signpubkey rootkey.vbpubk \
+  --fv "$area_fw_main_b" --kernelkey kernel_subkey_b.vbpubk ; result
 
 for key in kernel_subkey_a.vbpubk kernel_subkey_b.vbpubk; do
   infon "Test $key... "
diff --git a/utility/dump_fmap.c b/utility/dump_fmap.c
index bd7abac..ab2043c 100644
--- a/utility/dump_fmap.c
+++ b/utility/dump_fmap.c
@@ -57,7 +57,8 @@
                 progname, buf, strerror(errno));
         retval = 1;
       } else {
-        if (1 != fwrite(base_of_rom + ah->area_offset, ah->area_size, 1, fp)) {
+        if (ah->area_size &&
+            1 != fwrite(base_of_rom + ah->area_offset, ah->area_size, 1, fp)) {
           fprintf(stderr, "%s: can't write %s: %s\n",
                   progname, buf, strerror(errno));
           retval = 1;