fix clearing kernel attributes

Change-Id: Id353323d268835cbcc1fb13c8669cee420c8fb6a

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

Make sure your chromeos install on the hard drive has 2 good kernel
partitions. Do:

sudo cgpt show /dev/sda

If partition 2 has success=1, do:

sudo dd if=/dev/sda2 of=/dev/sda4 bs=1M
sudo dd if=/dev/sda3 of=/dev/sda5 bs=1M
cgpt add -i 4 -S 1 -P 2

(if instead partition 4 has success=1, do:)

sudo dd if=/dev/sda4 of=/dev/sda2 bs=1M
sudo dd if=/dev/sda5 of=/dev/sda3 bs=1M
cgpt add -i 2 -S 1 -P 2

Reboot and do the following:

sudo cgpt show /dev/sda

If the partition you just marked active still has success=1
priority=2, the bug is fixed.  If it has success=0 priority=0, the bug
is still there.

Review URL: http://codereview.chromium.org/3324014
diff --git a/firmware/lib/vboot_kernel.c b/firmware/lib/vboot_kernel.c
index 7512535..3369b6d 100644
--- a/firmware/lib/vboot_kernel.c
+++ b/firmware/lib/vboot_kernel.c
@@ -213,10 +213,15 @@
       found_partitions++;
 
       /* Read the first part of the kernel partition  */
-      if (part_size < kbuf_sectors)
+      if (part_size < kbuf_sectors) {
+        VBDEBUG(("Partition too small to hold kernel.\n"));
         goto bad_kernel;
-      if (0 != BootDeviceReadLBA(part_start, kbuf_sectors, kbuf))
+      }
+
+      if (0 != BootDeviceReadLBA(part_start, kbuf_sectors, kbuf)) {
+        VBDEBUG(("Unable to read start of partition.\n"));
         goto bad_kernel;
+      }
 
       /* Verify the key block.  In developer mode, we ignore the key
        * and use only the SHA-512 hash to verify the key block. */
@@ -255,8 +260,10 @@
 
       /* Get the key for preamble/data verification from the key block */
       data_key = PublicKeyToRSA(&key_block->data_key);
-      if (!data_key)
+      if (!data_key) {
+        VBDEBUG(("Data key bad.\n"));
         goto bad_kernel;
+      }
 
       /* Verify the preamble, which follows the key block */
       preamble = (VbKernelPreambleHeader*)(kbuf + key_block->key_block_size);
@@ -285,9 +292,9 @@
 
       /* If we already have a good kernel, no need to read another
        * one; we only needed to look at the versions to check for
-       * rollback. */
+       * rollback.  So skip to the next kernel preamble. */
       if (-1 != good_partition)
-        goto bad_kernel;
+        continue;
 
       /* Verify body load address matches what we expect */
       if ((preamble->body_load_address != (size_t)params->kernel_buffer) &&