Make LoadKernel() pass back the kernel partition's UniqueGuid.

LoadKernel already returns the partition number for the selected kernel.
This change makes it also return the GPT Entry's UniqueGuid, which will
eventually be passed to the kernel itself, so the kernel can determine which
of several possible devices it has booted from. It doesn't know for certain
because the BIOS and the kernel may enumerate the devices in a different
order.

BUG=chromium-os:4984

Review URL: http://codereview.chromium.org/3056014
diff --git a/firmware/include/load_kernel_fw.h b/firmware/include/load_kernel_fw.h
index 31c3081..4cca8bd 100644
--- a/firmware/include/load_kernel_fw.h
+++ b/firmware/include/load_kernel_fw.h
@@ -44,6 +44,7 @@
                                  * (1...M) */
   uint64_t bootloader_address;  /* Address of bootloader image in RAM */
   uint64_t bootloader_size;     /* Size of bootloader image in bytes */
+  uint8_t  partition_guid[16];  /* UniquePartitionGuid for boot partition */
 } LoadKernelParams;
 
 int LoadKernel(LoadKernelParams* params);
@@ -62,6 +63,7 @@
   uint64_t original_address;    /* Absolute bootloader start adddress,
                                  * as returned from LoadKernel() in
                                  * LoadKernelParams.bootloader_start */
+  uint8_t  partition_guid[16];  /* UniquePartitionGuid for boot partition */
 } KernelBootloaderOptions;
 
 
diff --git a/firmware/lib/cgptlib/cgptlib_internal.c b/firmware/lib/cgptlib/cgptlib_internal.c
index c3fd1f3..a0c1688 100644
--- a/firmware/lib/cgptlib/cgptlib_internal.c
+++ b/firmware/lib/cgptlib/cgptlib_internal.c
@@ -346,3 +346,9 @@
   e->attrs.fields.gpt_att |= (tries << CGPT_ATTRIBUTE_TRIES_OFFSET) &
       CGPT_ATTRIBUTE_TRIES_MASK;
 }
+
+void GetCurrentKernelUniqueGuid(GptData *gpt, void *dest) {
+  GptEntry* entries = (GptEntry*)gpt->primary_entries;
+  GptEntry* e = entries + gpt->current_kernel;
+  Memcpy(dest, &e->unique, sizeof(Guid));
+}
diff --git a/firmware/lib/cgptlib/include/cgptlib_internal.h b/firmware/lib/cgptlib/include/cgptlib_internal.h
index 95e5b4e..66ceef1 100644
--- a/firmware/lib/cgptlib/include/cgptlib_internal.h
+++ b/firmware/lib/cgptlib/include/cgptlib_internal.h
@@ -112,4 +112,7 @@
 /* Returns 1 if the entry is a Chrome OS kernel partition, else 0. */
 int IsKernelEntry(const GptEntry* e);
 
+/* Copies the current kernel partition's UniquePartitionGuid to the dest */
+void GetCurrentKernelUniqueGuid(GptData *gpt, void *dest);
+
 #endif /* VBOOT_REFERENCE_CGPTLIB_INTERNAL_H_ */
diff --git a/firmware/lib/vboot_kernel.c b/firmware/lib/vboot_kernel.c
index c045380..0420f25 100644
--- a/firmware/lib/vboot_kernel.c
+++ b/firmware/lib/vboot_kernel.c
@@ -10,12 +10,12 @@
 
 #include "boot_device.h"
 #include "cgptlib.h"
+#include "cgptlib_internal.h"
 #include "load_kernel_fw.h"
 #include "rollback_index.h"
 #include "utility.h"
 #include "vboot_common.h"
 
-
 #define KBUF_SIZE 65536  /* Bytes to read at start of kernel partition */
 
 
@@ -131,7 +131,6 @@
 
   /* Sanity Checks */
   if (!params ||
-      !params->header_sign_key_blob ||
       !params->bytes_per_lba ||
       !params->ending_lba ||
       !params->kernel_buffer ||
@@ -350,6 +349,7 @@
        * Adjust here, until cgptlib is fixed. */
       good_partition = gpt.current_kernel + 1;
       params->partition_number = gpt.current_kernel + 1;
+      GetCurrentKernelUniqueGuid(&gpt, &params->partition_guid);
       params->bootloader_address = preamble->bootloader_address;
       params->bootloader_size = preamble->bootloader_size;
       /* If we're in developer or recovery mode, there's no rollback
diff --git a/firmware/version.c b/firmware/version.c
index b5d9dca..e246bd9 100644
--- a/firmware/version.c
+++ b/firmware/version.c
@@ -1 +1 @@
-char* VbootVersion = "VBOOv=0249c1a3";
+char* VbootVersion = "VBOOv=5d5d1959";
diff --git a/utility/load_kernel_test.c b/utility/load_kernel_test.c
index c391c61..4ac9330 100644
--- a/utility/load_kernel_test.c
+++ b/utility/load_kernel_test.c
@@ -135,6 +135,25 @@
     printf("Partition number:   %" PRIu64 "\n", lkp.partition_number);
     printf("Bootloader address: %" PRIu64 "\n", lkp.bootloader_address);
     printf("Bootloader size:    %" PRIu64 "\n", lkp.bootloader_size);
+    printf("Partition guid:     "
+           "%02x%02x%02x%02x-%02x%02x-%02x%02x"
+           "-%02x%02x-%02x%02x%02x%02x%02x%02x\n",
+           lkp.partition_guid[3],
+           lkp.partition_guid[2],
+           lkp.partition_guid[1],
+           lkp.partition_guid[0],
+           lkp.partition_guid[5],
+           lkp.partition_guid[4],
+           lkp.partition_guid[7],
+           lkp.partition_guid[6],
+           lkp.partition_guid[8],
+           lkp.partition_guid[9],
+           lkp.partition_guid[10],
+           lkp.partition_guid[11],
+           lkp.partition_guid[12],
+           lkp.partition_guid[13],
+           lkp.partition_guid[14],
+           lkp.partition_guid[15]);
   }
 
   fclose(image_file);