summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/include/gpt_misc.h12
-rw-r--r--firmware/lib/cgptlib/cgptlib_internal.c34
-rw-r--r--firmware/lib/cgptlib/include/cgptlib_internal.h5
-rw-r--r--firmware/lib/gpt_misc.c10
-rw-r--r--firmware/lib/vboot_kernel.c6
5 files changed, 36 insertions, 31 deletions
diff --git a/firmware/include/gpt_misc.h b/firmware/include/gpt_misc.h
index 53b30347..e15f7dc8 100644
--- a/firmware/include/gpt_misc.h
+++ b/firmware/include/gpt_misc.h
@@ -57,10 +57,8 @@ enum {
GPT_UPDATE_ENTRY_BAD = 2,
};
-enum {
- GPT_STORED_ON_DEVICE = 0, /* The GPT is stored on the same device. */
- GPT_STORED_OFF_DEVICE = 1, /* The GPT is stored on another place. */
-};
+/* If this bit is 1, the GPT is stored in another from the streaming data */
+#define GPT_FLAG_EXTERNAL 0x1
/*
* A note about stored_on_device and gpt_drive_sectors:
@@ -88,11 +86,11 @@ typedef struct {
/* Size of a LBA sector, in bytes */
uint32_t sector_bytes;
/* Size of drive (that the partitions are on) in LBA sectors */
- uint64_t drive_sectors;
- /* Are the GPT structures stored on the same device */
- uint8_t stored_on_device;
+ uint64_t streaming_drive_sectors;
/* Size of the device that holds the GPT structures, 512-byte sectors */
uint64_t gpt_drive_sectors;
+ /* Flags */
+ uint32_t flags;
/* Outputs */
/* Which inputs have been modified? GPT_MODIFIED_* */
diff --git a/firmware/lib/cgptlib/cgptlib_internal.c b/firmware/lib/cgptlib/cgptlib_internal.c
index 9bcfbd81..e7bb2e60 100644
--- a/firmware/lib/cgptlib/cgptlib_internal.c
+++ b/firmware/lib/cgptlib/cgptlib_internal.c
@@ -20,12 +20,13 @@ int CheckParameters(GptData *gpt)
return GPT_ERROR_INVALID_SECTOR_SIZE;
/*
- * gpt_drive_sectors should be reasonable. It cannot be unset, and it cannot
- * differ from drive_sectors if the GPT structs are stored on same device.
+ * gpt_drive_sectors should be reasonable. It cannot be unset, and it
+ * cannot differ from streaming_drive_sectors if the GPT structs are
+ * stored on same device.
*/
if (gpt->gpt_drive_sectors == 0 ||
- (gpt->stored_on_device == GPT_STORED_ON_DEVICE &&
- gpt->gpt_drive_sectors != gpt->drive_sectors)) {
+ (!(gpt->flags & GPT_FLAG_EXTERNAL) &&
+ gpt->gpt_drive_sectors != gpt->streaming_drive_sectors)) {
return GPT_ERROR_INVALID_SECTOR_NUMBER;
}
@@ -53,8 +54,9 @@ uint32_t HeaderCrc(GptHeader *h)
return crc32;
}
-int CheckHeader(GptHeader *h, int is_secondary, uint64_t drive_sectors,
- uint64_t gpt_drive_sectors, uint8_t stored_on_device)
+int CheckHeader(GptHeader *h, int is_secondary,
+ uint64_t streaming_drive_sectors,
+ uint64_t gpt_drive_sectors, uint32_t flags)
{
if (!h)
return 1;
@@ -91,7 +93,7 @@ int CheckHeader(GptHeader *h, int is_secondary, uint64_t drive_sectors,
return 1;
if ((h->number_of_entries < MIN_NUMBER_OF_ENTRIES) ||
(h->number_of_entries > MAX_NUMBER_OF_ENTRIES) ||
- (stored_on_device == GPT_STORED_ON_DEVICE &&
+ (!(flags & GPT_FLAG_EXTERNAL) &&
h->number_of_entries * h->size_of_entry != TOTAL_ENTRIES_SIZE))
return 1;
@@ -116,8 +118,8 @@ int CheckHeader(GptHeader *h, int is_secondary, uint64_t drive_sectors,
if (h->first_usable_lba > h->last_usable_lba)
return 1;
- if (stored_on_device != GPT_STORED_ON_DEVICE) {
- if (h->last_usable_lba >= drive_sectors) {
+ if (flags & GPT_FLAG_EXTERNAL) {
+ if (h->last_usable_lba >= streaming_drive_sectors) {
return 1;
}
return 0;
@@ -131,7 +133,8 @@ int CheckHeader(GptHeader *h, int is_secondary, uint64_t drive_sectors,
/* TODO(namnguyen): Also check for padding between header & entries. */
if (h->first_usable_lba < 2 + GPT_ENTRIES_SECTORS)
return 1;
- if (h->last_usable_lba >= drive_sectors - 1 - GPT_ENTRIES_SECTORS)
+ if (h->last_usable_lba >=
+ streaming_drive_sectors - 1 - GPT_ENTRIES_SECTORS)
return 1;
/* Success */
@@ -245,13 +248,13 @@ int GptSanityCheck(GptData *gpt)
return retval;
/* Check both headers; we need at least one valid header. */
- if (0 == CheckHeader(header1, 0, gpt->drive_sectors,
- gpt->gpt_drive_sectors, gpt->stored_on_device)) {
+ if (0 == CheckHeader(header1, 0, gpt->streaming_drive_sectors,
+ gpt->gpt_drive_sectors, gpt->flags)) {
gpt->valid_headers |= MASK_PRIMARY;
goodhdr = header1;
}
- if (0 == CheckHeader(header2, 1, gpt->drive_sectors,
- gpt->gpt_drive_sectors, gpt->stored_on_device)) {
+ if (0 == CheckHeader(header2, 1, gpt->streaming_drive_sectors,
+ gpt->gpt_drive_sectors, gpt->flags)) {
gpt->valid_headers |= MASK_SECONDARY;
if (!goodhdr)
goodhdr = header2;
@@ -332,7 +335,8 @@ void GptRepair(GptData *gpt)
/* Secondary is good, primary is bad */
Memcpy(header1, header2, sizeof(GptHeader));
header1->my_lba = GPT_PMBR_SECTORS; /* Second sector. */
- header1->alternate_lba = gpt->drive_sectors - GPT_HEADER_SECTORS;
+ header1->alternate_lba =
+ gpt->streaming_drive_sectors - GPT_HEADER_SECTORS;
/* TODO (namnguyen): Preserve (header, entries) padding. */
header1->entries_lba = header1->my_lba + 1;
header1->header_crc32 = HeaderCrc(header1);
diff --git a/firmware/lib/cgptlib/include/cgptlib_internal.h b/firmware/lib/cgptlib/include/cgptlib_internal.h
index 825bbbb2..8dc05914 100644
--- a/firmware/lib/cgptlib/include/cgptlib_internal.h
+++ b/firmware/lib/cgptlib/include/cgptlib_internal.h
@@ -90,8 +90,9 @@ int CheckParameters(GptData* gpt);
*
* Returns 0 if header is valid, 1 if invalid.
*/
-int CheckHeader(GptHeader *h, int is_secondary, uint64_t drive_sectors,
- uint64_t gpt_drive_sectors, uint8_t stored_on_device);
+int CheckHeader(GptHeader *h, int is_secondary,
+ uint64_t streaming_drive_sectors,
+ uint64_t gpt_drive_sectors, uint32_t flags);
/**
* Calculate and return the header CRC.
diff --git a/firmware/lib/gpt_misc.c b/firmware/lib/gpt_misc.c
index dc15d915..975e853b 100644
--- a/firmware/lib/gpt_misc.c
+++ b/firmware/lib/gpt_misc.c
@@ -48,9 +48,10 @@ int AllocAndReadGptData(VbExDiskHandle_t disk_handle, GptData *gptdata)
/* Only read primary GPT if the primary header is valid */
GptHeader* primary_header = (GptHeader*)gptdata->primary_header;
- if (0 == CheckHeader(primary_header, 0, gptdata->drive_sectors,
+ if (0 == CheckHeader(primary_header, 0,
+ gptdata->streaming_drive_sectors,
gptdata->gpt_drive_sectors,
- gptdata->stored_on_device)) {
+ gptdata->flags)) {
primary_valid = 1;
if (0 != VbExDiskRead(disk_handle,
primary_header->entries_lba,
@@ -68,9 +69,10 @@ int AllocAndReadGptData(VbExDiskHandle_t disk_handle, GptData *gptdata)
/* Only read secondary GPT if the secondary header is valid */
GptHeader* secondary_header = (GptHeader*)gptdata->secondary_header;
- if (0 == CheckHeader(secondary_header, 1, gptdata->drive_sectors,
+ if (0 == CheckHeader(secondary_header, 1,
+ gptdata->streaming_drive_sectors,
gptdata->gpt_drive_sectors,
- gptdata->stored_on_device)) {
+ gptdata->flags)) {
secondary_valid = 1;
if (0 != VbExDiskRead(disk_handle,
secondary_header->entries_lba,
diff --git a/firmware/lib/vboot_kernel.c b/firmware/lib/vboot_kernel.c
index 62e62967..5dd75de8 100644
--- a/firmware/lib/vboot_kernel.c
+++ b/firmware/lib/vboot_kernel.c
@@ -115,10 +115,10 @@ VbError_t LoadKernel(LoadKernelParams *params, VbCommonParams *cparams)
/* Read GPT data */
gpt.sector_bytes = (uint32_t)blba;
- gpt.drive_sectors = params->ending_lba + 1;
+ gpt.streaming_drive_sectors = params->ending_lba + 1;
/* TODO: Set stored_on_device and gpt_drive_sectors appropriately */
- gpt.stored_on_device = GPT_STORED_ON_DEVICE;
- gpt.gpt_drive_sectors = gpt.drive_sectors;
+ gpt.gpt_drive_sectors = gpt.streaming_drive_sectors;
+ gpt.flags = 0;
if (0 != AllocAndReadGptData(params->disk_handle, &gpt)) {
VBDEBUG(("Unable to read GPT data\n"));
shcall->check_result = VBSD_LKC_CHECK_GPT_READ_ERROR;