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
This commit is contained in:
Bill Richardson
2010-07-23 17:22:25 -07:00
parent e272940ec5
commit 5deb67f225
6 changed files with 33 additions and 3 deletions

View File

@@ -44,6 +44,7 @@ typedef struct LoadKernelParams {
* (1...M) */ * (1...M) */
uint64_t bootloader_address; /* Address of bootloader image in RAM */ uint64_t bootloader_address; /* Address of bootloader image in RAM */
uint64_t bootloader_size; /* Size of bootloader image in bytes */ uint64_t bootloader_size; /* Size of bootloader image in bytes */
uint8_t partition_guid[16]; /* UniquePartitionGuid for boot partition */
} LoadKernelParams; } LoadKernelParams;
int LoadKernel(LoadKernelParams* params); int LoadKernel(LoadKernelParams* params);
@@ -62,6 +63,7 @@ typedef struct KernelBootloaderOptions {
uint64_t original_address; /* Absolute bootloader start adddress, uint64_t original_address; /* Absolute bootloader start adddress,
* as returned from LoadKernel() in * as returned from LoadKernel() in
* LoadKernelParams.bootloader_start */ * LoadKernelParams.bootloader_start */
uint8_t partition_guid[16]; /* UniquePartitionGuid for boot partition */
} KernelBootloaderOptions; } KernelBootloaderOptions;

View File

@@ -346,3 +346,9 @@ void SetEntryTries(GptEntry* e, int tries) {
e->attrs.fields.gpt_att |= (tries << CGPT_ATTRIBUTE_TRIES_OFFSET) & e->attrs.fields.gpt_att |= (tries << CGPT_ATTRIBUTE_TRIES_OFFSET) &
CGPT_ATTRIBUTE_TRIES_MASK; 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));
}

View File

@@ -112,4 +112,7 @@ int IsUnusedEntry(const GptEntry* e);
/* Returns 1 if the entry is a Chrome OS kernel partition, else 0. */ /* Returns 1 if the entry is a Chrome OS kernel partition, else 0. */
int IsKernelEntry(const GptEntry* e); 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_ */ #endif /* VBOOT_REFERENCE_CGPTLIB_INTERNAL_H_ */

View File

@@ -10,12 +10,12 @@
#include "boot_device.h" #include "boot_device.h"
#include "cgptlib.h" #include "cgptlib.h"
#include "cgptlib_internal.h"
#include "load_kernel_fw.h" #include "load_kernel_fw.h"
#include "rollback_index.h" #include "rollback_index.h"
#include "utility.h" #include "utility.h"
#include "vboot_common.h" #include "vboot_common.h"
#define KBUF_SIZE 65536 /* Bytes to read at start of kernel partition */ #define KBUF_SIZE 65536 /* Bytes to read at start of kernel partition */
@@ -131,7 +131,6 @@ int LoadKernel(LoadKernelParams* params) {
/* Sanity Checks */ /* Sanity Checks */
if (!params || if (!params ||
!params->header_sign_key_blob ||
!params->bytes_per_lba || !params->bytes_per_lba ||
!params->ending_lba || !params->ending_lba ||
!params->kernel_buffer || !params->kernel_buffer ||
@@ -350,6 +349,7 @@ int LoadKernel(LoadKernelParams* params) {
* Adjust here, until cgptlib is fixed. */ * Adjust here, until cgptlib is fixed. */
good_partition = gpt.current_kernel + 1; good_partition = gpt.current_kernel + 1;
params->partition_number = gpt.current_kernel + 1; params->partition_number = gpt.current_kernel + 1;
GetCurrentKernelUniqueGuid(&gpt, &params->partition_guid);
params->bootloader_address = preamble->bootloader_address; params->bootloader_address = preamble->bootloader_address;
params->bootloader_size = preamble->bootloader_size; params->bootloader_size = preamble->bootloader_size;
/* If we're in developer or recovery mode, there's no rollback /* If we're in developer or recovery mode, there's no rollback

View File

@@ -1 +1 @@
char* VbootVersion = "VBOOv=0249c1a3"; char* VbootVersion = "VBOOv=5d5d1959";

View File

@@ -135,6 +135,25 @@ int main(int argc, char* argv[]) {
printf("Partition number: %" PRIu64 "\n", lkp.partition_number); printf("Partition number: %" PRIu64 "\n", lkp.partition_number);
printf("Bootloader address: %" PRIu64 "\n", lkp.bootloader_address); printf("Bootloader address: %" PRIu64 "\n", lkp.bootloader_address);
printf("Bootloader size: %" PRIu64 "\n", lkp.bootloader_size); 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); fclose(image_file);