summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Ehrenberg <dehrenberg@chromium.org>2014-12-09 13:42:15 -0800
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-12-11 03:12:14 +0000
commitb3d38f5c620da89662deb1a08971c5025d6c1132 (patch)
tree1a401569a1d4faf8c45c32708a1b3856b707e190
parentcfe83a827d40b310003fc6996b9978d8cf301444 (diff)
downloadvboot-b3d38f5c620da89662deb1a08971c5025d6c1132.tar.gz
vboot: GPT interface cleanup
- Rename drive_sectors to streaming_drive_sectors, to contrast with gpt_drive_sectors - Replace stored_on_device field with flags field for future extensibility BUG=chromium:433433 TEST=make runtests BRANCH=none Change-Id: I785a3b735b8eb96f647a334659329db3ee43eb80 Signed-off-by: Dan Ehrenberg <dehrenberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/234283 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
-rw-r--r--cgpt/cgpt_boot.c4
-rw-r--r--cgpt/cgpt_common.c19
-rw-r--r--cgpt/cgpt_create.c9
-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
-rw-r--r--tests/cgptlib_test.c120
-rw-r--r--tests/vboot_kernel_tests.c34
10 files changed, 130 insertions, 123 deletions
diff --git a/cgpt/cgpt_boot.c b/cgpt/cgpt_boot.c
index f4323962..d8976c42 100644
--- a/cgpt/cgpt_boot.c
+++ b/cgpt/cgpt_boot.c
@@ -99,8 +99,8 @@ int CgptBoot(CgptBootParams *params) {
drive.pmbr.part[0].l_cyl = 0xff;
drive.pmbr.part[0].f_lba = htole32(1);
uint32_t max = 0xffffffff;
- if (drive.gpt.drive_sectors < 0xffffffff)
- max = drive.gpt.drive_sectors - 1;
+ if (drive.gpt.streaming_drive_sectors < 0xffffffff)
+ max = drive.gpt.streaming_drive_sectors - 1;
drive.pmbr.part[0].num_sect = htole32(max);
}
diff --git a/cgpt/cgpt_common.c b/cgpt/cgpt_common.c
index 1438dfb3..b580e33a 100644
--- a/cgpt/cgpt_common.c
+++ b/cgpt/cgpt_common.c
@@ -150,11 +150,11 @@ static int GptLoad(struct drive *drive, uint32_t sector_bytes) {
(long long unsigned int)drive->size, drive->gpt.sector_bytes);
return -1;
}
- drive->gpt.drive_sectors = drive->size / drive->gpt.sector_bytes;
+ drive->gpt.streaming_drive_sectors = drive->size / drive->gpt.sector_bytes;
/* TODO(namnguyen): Remove this and totally trust gpt_drive_sectors. */
- if (drive->gpt.stored_on_device == GPT_STORED_ON_DEVICE) {
- drive->gpt.gpt_drive_sectors = drive->gpt.drive_sectors;
+ if (!(drive->gpt.flags & GPT_FLAG_EXTERNAL)) {
+ drive->gpt.gpt_drive_sectors = drive->gpt.streaming_drive_sectors;
} /* Else, we trust gpt.gpt_drive_sectors. */
// Read the data.
@@ -171,9 +171,9 @@ static int GptLoad(struct drive *drive, uint32_t sector_bytes) {
return -1;
}
GptHeader* primary_header = (GptHeader*)drive->gpt.primary_header;
- if (CheckHeader(primary_header, 0, drive->gpt.drive_sectors,
+ if (CheckHeader(primary_header, 0, drive->gpt.streaming_drive_sectors,
drive->gpt.gpt_drive_sectors,
- drive->gpt.stored_on_device) == 0) {
+ drive->gpt.flags) == 0) {
if (CGPT_OK != Load(drive, &drive->gpt.primary_entries,
primary_header->entries_lba,
drive->gpt.sector_bytes, GPT_ENTRIES_SECTORS)) {
@@ -184,9 +184,9 @@ static int GptLoad(struct drive *drive, uint32_t sector_bytes) {
Warning("Primary GPT header is invalid\n");
}
GptHeader* secondary_header = (GptHeader*)drive->gpt.secondary_header;
- if (CheckHeader(secondary_header, 1, drive->gpt.drive_sectors,
+ if (CheckHeader(secondary_header, 1, drive->gpt.streaming_drive_sectors,
drive->gpt.gpt_drive_sectors,
- drive->gpt.stored_on_device) == 0) {
+ drive->gpt.flags) == 0) {
if (CGPT_OK != Load(drive, &drive->gpt.secondary_entries,
secondary_header->entries_lba,
drive->gpt.sector_bytes, GPT_ENTRIES_SECTORS)) {
@@ -284,7 +284,6 @@ int DriveOpen(const char *drive_path, struct drive *drive, int mode,
// Clear struct for proper error handling.
memset(drive, 0, sizeof(struct drive));
- drive->gpt.stored_on_device = GPT_STORED_ON_DEVICE;
drive->fd = open(drive_path, mode | O_LARGEFILE | O_NOFOLLOW);
if (drive->fd == -1) {
@@ -303,10 +302,10 @@ int DriveOpen(const char *drive_path, struct drive *drive, int mode,
drive->gpt.gpt_drive_sectors = gpt_drive_size / sector_bytes;
if (drive_size == 0) {
drive->size = gpt_drive_size;
- drive->gpt.stored_on_device = GPT_STORED_ON_DEVICE;
+ drive->gpt.flags = 0;
} else {
drive->size = drive_size;
- drive->gpt.stored_on_device = GPT_STORED_OFF_DEVICE;
+ drive->gpt.flags = GPT_FLAG_EXTERNAL;
}
diff --git a/cgpt/cgpt_create.c b/cgpt/cgpt_create.c
index 298e2ae5..2265c8f9 100644
--- a/cgpt/cgpt_create.c
+++ b/cgpt/cgpt_create.c
@@ -46,14 +46,15 @@ static int GptCreate(struct drive *drive, CgptCreateParams *params) {
h->my_lba = GPT_PMBR_SECTORS; /* The second sector on drive. */
h->alternate_lba = drive->gpt.gpt_drive_sectors - GPT_HEADER_SECTORS;
h->entries_lba = h->my_lba + GPT_HEADER_SECTORS;
- if (drive->gpt.stored_on_device == GPT_STORED_ON_DEVICE) {
+ if (!(drive->gpt.flags & GPT_FLAG_EXTERNAL)) {
h->entries_lba += params->padding;
h->first_usable_lba = h->entries_lba + GPT_ENTRIES_SECTORS;
- h->last_usable_lba = (drive->gpt.drive_sectors - GPT_HEADER_SECTORS -
+ h->last_usable_lba = (drive->gpt.streaming_drive_sectors -
+ GPT_HEADER_SECTORS -
GPT_ENTRIES_SECTORS - 1);
} else {
h->first_usable_lba = params->padding;
- h->last_usable_lba = (drive->gpt.drive_sectors - 1);
+ h->last_usable_lba = (drive->gpt.streaming_drive_sectors - 1);
}
if (CGPT_OK != GenerateGuid(&h->disk_uuid)) {
Error("Unable to generate new GUID.\n");
@@ -61,7 +62,7 @@ static int GptCreate(struct drive *drive, CgptCreateParams *params) {
}
h->size_of_entry = sizeof(GptEntry);
h->number_of_entries = TOTAL_ENTRIES_SIZE / h->size_of_entry;
- if (drive->gpt.stored_on_device != GPT_STORED_ON_DEVICE) {
+ if (drive->gpt.flags & GPT_FLAG_EXTERNAL) {
// We might have smaller space for the GPT table. Scale accordingly.
size_t half_size_sectors = drive->gpt.gpt_drive_sectors / 2;
if (half_size_sectors < GPT_HEADER_SECTORS) {
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;
diff --git a/tests/cgptlib_test.c b/tests/cgptlib_test.c
index fd5cda16..e81f50e7 100644
--- a/tests/cgptlib_test.c
+++ b/tests/cgptlib_test.c
@@ -149,7 +149,8 @@ static void BuildTestGptData(GptData *gpt)
Guid chromeos_rootfs = GPT_ENT_TYPE_CHROMEOS_ROOTFS;
gpt->sector_bytes = DEFAULT_SECTOR_SIZE;
- gpt->drive_sectors = gpt->gpt_drive_sectors = DEFAULT_DRIVE_SECTORS;
+ gpt->streaming_drive_sectors =
+ gpt->gpt_drive_sectors = DEFAULT_DRIVE_SECTORS;
gpt->current_kernel = CGPT_KERNEL_ENTRY_NOT_FOUND;
gpt->valid_headers = MASK_BOTH;
gpt->valid_entries = MASK_BOTH;
@@ -255,7 +256,8 @@ static int ParameterTests(void)
for (i = 0; i < ARRAY_SIZE(cases); ++i) {
BuildTestGptData(gpt);
gpt->sector_bytes = cases[i].sector_bytes;
- gpt->drive_sectors = gpt->gpt_drive_sectors = cases[i].drive_sectors;
+ gpt->streaming_drive_sectors =
+ gpt->gpt_drive_sectors = cases[i].drive_sectors;
EXPECT(cases[i].expected_retval == CheckParameters(gpt));
}
@@ -350,15 +352,15 @@ static int SignatureTest(void)
GptHeader *h2 = (GptHeader *)gpt->secondary_header;
int i;
- EXPECT(1 == CheckHeader(NULL, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
+ EXPECT(1 == CheckHeader(NULL, 0, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
for (i = 0; i < 8; ++i) {
BuildTestGptData(gpt);
h1->signature[i] ^= 0xff;
h2->signature[i] ^= 0xff;
RefreshCrc32(gpt);
- EXPECT(1 == CheckHeader(h1, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
- EXPECT(1 == CheckHeader(h2, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
+ EXPECT(1 == CheckHeader(h1, 0, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
+ EXPECT(1 == CheckHeader(h2, 1, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
}
return TEST_OK;
@@ -392,9 +394,9 @@ static int RevisionTest(void)
h2->revision = cases[i].value_to_test;
RefreshCrc32(gpt);
- EXPECT(CheckHeader(h1, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE) ==
+ EXPECT(CheckHeader(h1, 0, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0) ==
cases[i].expect_rv);
- EXPECT(CheckHeader(h2, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE) ==
+ EXPECT(CheckHeader(h2, 1, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0) ==
cases[i].expect_rv);
}
return TEST_OK;
@@ -425,9 +427,9 @@ static int SizeTest(void)
h2->size = cases[i].value_to_test;
RefreshCrc32(gpt);
- EXPECT(CheckHeader(h1, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE) ==
+ EXPECT(CheckHeader(h1, 0, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0) ==
cases[i].expect_rv);
- EXPECT(CheckHeader(h2, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE) ==
+ EXPECT(CheckHeader(h2, 1, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0) ==
cases[i].expect_rv);
}
return TEST_OK;
@@ -444,12 +446,12 @@ static int CrcFieldTest(void)
/* Modify a field that the header verification doesn't care about */
h1->entries_crc32++;
h2->entries_crc32++;
- EXPECT(1 == CheckHeader(h1, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
- EXPECT(1 == CheckHeader(h2, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
+ EXPECT(1 == CheckHeader(h1, 0, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
+ EXPECT(1 == CheckHeader(h2, 1, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
/* Refresh the CRC; should pass now */
RefreshCrc32(gpt);
- EXPECT(0 == CheckHeader(h1, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
- EXPECT(0 == CheckHeader(h2, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
+ EXPECT(0 == CheckHeader(h1, 0, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
+ EXPECT(0 == CheckHeader(h2, 1, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
return TEST_OK;
}
@@ -465,8 +467,8 @@ static int ReservedFieldsTest(void)
h1->reserved_zero ^= 0x12345678; /* whatever random */
h2->reserved_zero ^= 0x12345678; /* whatever random */
RefreshCrc32(gpt);
- EXPECT(1 == CheckHeader(h1, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
- EXPECT(1 == CheckHeader(h2, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
+ EXPECT(1 == CheckHeader(h1, 0, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
+ EXPECT(1 == CheckHeader(h2, 1, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
#ifdef PADDING_CHECKED
/* TODO: padding check is currently disabled */
@@ -474,8 +476,8 @@ static int ReservedFieldsTest(void)
h1->padding[12] ^= 0x34; /* whatever random */
h2->padding[56] ^= 0x78; /* whatever random */
RefreshCrc32(gpt);
- EXPECT(1 == CheckHeader(h1, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
- EXPECT(1 == CheckHeader(h2, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
+ EXPECT(1 == CheckHeader(h1, 0, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
+ EXPECT(1 == CheckHeader(h2, 1, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
#endif
return TEST_OK;
@@ -513,9 +515,9 @@ static int SizeOfPartitionEntryTest(void) {
cases[i].value_to_test;
RefreshCrc32(gpt);
- EXPECT(CheckHeader(h1, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE) ==
+ EXPECT(CheckHeader(h1, 0, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0) ==
cases[i].expect_rv);
- EXPECT(CheckHeader(h2, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE) ==
+ EXPECT(CheckHeader(h2, 1, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0) ==
cases[i].expect_rv);
}
@@ -536,11 +538,11 @@ static int NumberOfPartitionEntriesTest(void)
h1->number_of_entries--;
h2->number_of_entries /= 2;
RefreshCrc32(gpt);
- EXPECT(1 == CheckHeader(h1, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
- EXPECT(1 == CheckHeader(h2, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
+ EXPECT(1 == CheckHeader(h1, 0, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
+ EXPECT(1 == CheckHeader(h2, 1, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
/* But it's okay to have less if the GPT structs are stored elsewhere. */
- EXPECT(0 == CheckHeader(h1, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_OFF_DEVICE));
- EXPECT(0 == CheckHeader(h2, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_OFF_DEVICE));
+ EXPECT(0 == CheckHeader(h1, 0, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, GPT_FLAG_EXTERNAL));
+ EXPECT(0 == CheckHeader(h2, 1, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, GPT_FLAG_EXTERNAL));
return TEST_OK;
}
@@ -555,37 +557,37 @@ static int MyLbaTest(void)
/* myLBA depends on primary vs secondary flag */
BuildTestGptData(gpt);
- EXPECT(1 == CheckHeader(h1, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
- EXPECT(1 == CheckHeader(h2, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
+ EXPECT(1 == CheckHeader(h1, 1, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
+ EXPECT(1 == CheckHeader(h2, 0, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
BuildTestGptData(gpt);
h1->my_lba--;
h2->my_lba--;
RefreshCrc32(gpt);
- EXPECT(1 == CheckHeader(h1, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
- EXPECT(1 == CheckHeader(h2, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
+ EXPECT(1 == CheckHeader(h1, 0, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
+ EXPECT(1 == CheckHeader(h2, 1, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
BuildTestGptData(gpt);
h1->my_lba = 2;
h2->my_lba--;
RefreshCrc32(gpt);
- EXPECT(1 == CheckHeader(h1, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
- EXPECT(1 == CheckHeader(h2, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
+ EXPECT(1 == CheckHeader(h1, 0, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
+ EXPECT(1 == CheckHeader(h2, 1, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
/* We should ignore the alternate_lba field entirely */
BuildTestGptData(gpt);
h1->alternate_lba++;
h2->alternate_lba++;
RefreshCrc32(gpt);
- EXPECT(0 == CheckHeader(h1, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
- EXPECT(0 == CheckHeader(h2, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
+ EXPECT(0 == CheckHeader(h1, 0, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
+ EXPECT(0 == CheckHeader(h2, 1, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
BuildTestGptData(gpt);
h1->alternate_lba--;
h2->alternate_lba--;
RefreshCrc32(gpt);
- EXPECT(0 == CheckHeader(h1, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
- EXPECT(0 == CheckHeader(h2, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
+ EXPECT(0 == CheckHeader(h1, 0, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
+ EXPECT(0 == CheckHeader(h2, 1, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
BuildTestGptData(gpt);
h1->entries_lba++;
@@ -595,19 +597,19 @@ static int MyLbaTest(void)
* We support a padding between primary GPT header and its entries. So
* this still passes.
*/
- EXPECT(0 == CheckHeader(h1, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
+ EXPECT(0 == CheckHeader(h1, 0, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
/*
* But the secondary table should fail because it would overlap the
* header, which is now lying after its entry array.
*/
- EXPECT(1 == CheckHeader(h2, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
+ EXPECT(1 == CheckHeader(h2, 1, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
BuildTestGptData(gpt);
h1->entries_lba--;
h2->entries_lba--;
RefreshCrc32(gpt);
- EXPECT(1 == CheckHeader(h1, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
- EXPECT(1 == CheckHeader(h2, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
+ EXPECT(1 == CheckHeader(h1, 0, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
+ EXPECT(1 == CheckHeader(h2, 1, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
return TEST_OK;
}
@@ -656,9 +658,9 @@ static int FirstUsableLbaAndLastUsableLbaTest(void)
h2->last_usable_lba = cases[i].secondary_last_usable_lba;
RefreshCrc32(gpt);
- EXPECT(CheckHeader(h1, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE) ==
+ EXPECT(CheckHeader(h1, 0, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0) ==
cases[i].primary_rv);
- EXPECT(CheckHeader(h2, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE) ==
+ EXPECT(CheckHeader(h2, 1, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0) ==
cases[i].secondary_rv);
}
@@ -1424,50 +1426,50 @@ static int CheckHeaderOffDevice()
RefreshCrc32(gpt);
// GPT is stored on the same device so first usable lba should not
// start at 0.
- EXPECT(1 == CheckHeader(primary_header, 0, gpt->drive_sectors,
- gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
+ EXPECT(1 == CheckHeader(primary_header, 0, gpt->streaming_drive_sectors,
+ gpt->gpt_drive_sectors, 0));
// But off device, it is okay to accept this GPT header.
- EXPECT(0 == CheckHeader(primary_header, 0, gpt->drive_sectors,
- gpt->gpt_drive_sectors, GPT_STORED_OFF_DEVICE));
+ EXPECT(0 == CheckHeader(primary_header, 0, gpt->streaming_drive_sectors,
+ gpt->gpt_drive_sectors, GPT_FLAG_EXTERNAL));
BuildTestGptData(gpt);
primary_header->number_of_entries = 100;
RefreshCrc32(gpt);
// Normally, number of entries is 128. So this should fail.
- EXPECT(1 == CheckHeader(primary_header, 0, gpt->drive_sectors,
- gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
+ EXPECT(1 == CheckHeader(primary_header, 0, gpt->streaming_drive_sectors,
+ gpt->gpt_drive_sectors, 0));
// But off device, it is okay.
- EXPECT(0 == CheckHeader(primary_header, 0, gpt->drive_sectors,
- gpt->gpt_drive_sectors, GPT_STORED_OFF_DEVICE));
+ EXPECT(0 == CheckHeader(primary_header, 0, gpt->streaming_drive_sectors,
+ gpt->gpt_drive_sectors, GPT_FLAG_EXTERNAL));
primary_header->number_of_entries = MIN_NUMBER_OF_ENTRIES - 1;
RefreshCrc32(gpt);
// However, too few entries is not good.
- EXPECT(1 == CheckHeader(primary_header, 0, gpt->drive_sectors,
- gpt->gpt_drive_sectors, GPT_STORED_OFF_DEVICE));
+ EXPECT(1 == CheckHeader(primary_header, 0, gpt->streaming_drive_sectors,
+ gpt->gpt_drive_sectors, GPT_FLAG_EXTERNAL));
// Repeat for secondary header.
BuildTestGptData(gpt);
GptHeader* secondary_header = (GptHeader*)gpt->secondary_header;
secondary_header->first_usable_lba = 0;
RefreshCrc32(gpt);
- EXPECT(1 == CheckHeader(secondary_header, 1, gpt->drive_sectors,
- gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
- EXPECT(0 == CheckHeader(secondary_header, 1, gpt->drive_sectors,
- gpt->gpt_drive_sectors, GPT_STORED_OFF_DEVICE));
+ EXPECT(1 == CheckHeader(secondary_header, 1, gpt->streaming_drive_sectors,
+ gpt->gpt_drive_sectors, 0));
+ EXPECT(0 == CheckHeader(secondary_header, 1, gpt->streaming_drive_sectors,
+ gpt->gpt_drive_sectors, GPT_FLAG_EXTERNAL));
BuildTestGptData(gpt);
secondary_header->number_of_entries = 100;
RefreshCrc32(gpt);
- EXPECT(1 == CheckHeader(secondary_header, 1, gpt->drive_sectors,
- gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
- EXPECT(0 == CheckHeader(secondary_header, 1, gpt->drive_sectors,
- gpt->gpt_drive_sectors, GPT_STORED_OFF_DEVICE));
+ EXPECT(1 == CheckHeader(secondary_header, 1, gpt->streaming_drive_sectors,
+ gpt->gpt_drive_sectors, 0));
+ EXPECT(0 == CheckHeader(secondary_header, 1, gpt->streaming_drive_sectors,
+ gpt->gpt_drive_sectors, GPT_FLAG_EXTERNAL));
secondary_header->number_of_entries = MIN_NUMBER_OF_ENTRIES - 1;
RefreshCrc32(gpt);
- EXPECT(1 == CheckHeader(secondary_header, 1, gpt->drive_sectors,
- gpt->gpt_drive_sectors, GPT_STORED_OFF_DEVICE));
+ EXPECT(1 == CheckHeader(secondary_header, 1, gpt->streaming_drive_sectors,
+ gpt->gpt_drive_sectors, GPT_FLAG_EXTERNAL));
return TEST_OK;
}
diff --git a/tests/vboot_kernel_tests.c b/tests/vboot_kernel_tests.c
index c546ed12..6f47ae35 100644
--- a/tests/vboot_kernel_tests.c
+++ b/tests/vboot_kernel_tests.c
@@ -289,7 +289,7 @@ static void ReadWriteGptTest(void)
GptHeader *h;
g.sector_bytes = MOCK_SECTOR_SIZE;
- g.drive_sectors = g.gpt_drive_sectors = MOCK_SECTOR_COUNT;
+ g.streaming_drive_sectors = g.gpt_drive_sectors = MOCK_SECTOR_COUNT;
g.valid_headers = g.valid_entries = MASK_BOTH;
ResetMocks();
@@ -315,11 +315,11 @@ static void ReadWriteGptTest(void)
Memset(mock_gpt_primary, '\0', sizeof(*mock_gpt_primary));
TEST_EQ(AllocAndReadGptData(handle, &g), 0,
"AllocAndRead primary invalid");
- TEST_EQ(CheckHeader(mock_gpt_primary, 0, g.drive_sectors,
- g.gpt_drive_sectors, GPT_STORED_ON_DEVICE),
+ TEST_EQ(CheckHeader(mock_gpt_primary, 0, g.streaming_drive_sectors,
+ g.gpt_drive_sectors, 0),
1, "Primary header is invalid");
- TEST_EQ(CheckHeader(mock_gpt_secondary, 1, g.drive_sectors,
- g.gpt_drive_sectors, GPT_STORED_ON_DEVICE),
+ TEST_EQ(CheckHeader(mock_gpt_secondary, 1, g.streaming_drive_sectors,
+ g.gpt_drive_sectors, 0),
0, "Secondary header is valid");
TEST_CALLS("VbExDiskRead(h, 1, 1)\n"
"VbExDiskRead(h, 1023, 1)\n"
@@ -334,11 +334,11 @@ static void ReadWriteGptTest(void)
Memset(mock_gpt_secondary, '\0', sizeof(*mock_gpt_secondary));
TEST_EQ(AllocAndReadGptData(handle, &g), 0,
"AllocAndRead secondary invalid");
- TEST_EQ(CheckHeader(mock_gpt_primary, 0, g.drive_sectors,
- g.gpt_drive_sectors, GPT_STORED_ON_DEVICE),
+ TEST_EQ(CheckHeader(mock_gpt_primary, 0, g.streaming_drive_sectors,
+ g.gpt_drive_sectors, 0),
0, "Primary header is valid");
- TEST_EQ(CheckHeader(mock_gpt_secondary, 1, g.drive_sectors,
- g.gpt_drive_sectors, GPT_STORED_ON_DEVICE),
+ TEST_EQ(CheckHeader(mock_gpt_secondary, 1, g.streaming_drive_sectors,
+ g.gpt_drive_sectors, 0),
1, "Secondary header is invalid");
TEST_CALLS("VbExDiskRead(h, 1, 1)\n"
"VbExDiskRead(h, 2, 32)\n"
@@ -354,11 +354,11 @@ static void ReadWriteGptTest(void)
Memset(mock_gpt_secondary, '\0', sizeof(*mock_gpt_secondary));
TEST_EQ(AllocAndReadGptData(handle, &g), 1,
"AllocAndRead primary and secondary invalid");
- TEST_EQ(CheckHeader(mock_gpt_primary, 0, g.drive_sectors,
- g.gpt_drive_sectors, GPT_STORED_ON_DEVICE),
+ TEST_EQ(CheckHeader(mock_gpt_primary, 0, g.streaming_drive_sectors,
+ g.gpt_drive_sectors, 0),
1, "Primary header is invalid");
- TEST_EQ(CheckHeader(mock_gpt_secondary, 1, g.drive_sectors,
- g.gpt_drive_sectors, GPT_STORED_ON_DEVICE),
+ TEST_EQ(CheckHeader(mock_gpt_secondary, 1, g.streaming_drive_sectors,
+ g.gpt_drive_sectors, 0),
1, "Secondary header is invalid");
TEST_CALLS("VbExDiskRead(h, 1, 1)\n"
"VbExDiskRead(h, 1023, 1)\n");
@@ -385,8 +385,8 @@ static void ReadWriteGptTest(void)
"VbExDiskRead(h, 991, 32)\n"
"VbExDiskWrite(h, 1, 1)\n"
"VbExDiskWrite(h, 2, 32)\n");
- TEST_EQ(CheckHeader(mock_gpt_primary, 0, g.drive_sectors,
- g.gpt_drive_sectors, GPT_STORED_ON_DEVICE),
+ TEST_EQ(CheckHeader(mock_gpt_primary, 0, g.streaming_drive_sectors,
+ g.gpt_drive_sectors, 0),
0, "Fix Primary GPT: Primary header is valid");
/*
@@ -410,8 +410,8 @@ static void ReadWriteGptTest(void)
"VbExDiskRead(h, 1023, 1)\n"
"VbExDiskWrite(h, 1023, 1)\n"
"VbExDiskWrite(h, 991, 32)\n");
- TEST_EQ(CheckHeader(mock_gpt_secondary, 1, g.drive_sectors,
- g.gpt_drive_sectors, GPT_STORED_ON_DEVICE),
+ TEST_EQ(CheckHeader(mock_gpt_secondary, 1, g.streaming_drive_sectors,
+ g.gpt_drive_sectors, 0),
0, "Fix Secondary GPT: Secondary header is valid");
/* Data which is changed is written */