summaryrefslogtreecommitdiff
path: root/tests/cgptlib_test.c
diff options
context:
space:
mode:
authorDan Ehrenberg <dehrenberg@chromium.org>2014-11-06 16:22:24 -0800
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-11-14 22:46:54 +0000
commita524a3a51591618c1395cb9e1238ee72b3f5e767 (patch)
treee3ba27f590375e71ff40d8df29c9e04466a743bb /tests/cgptlib_test.c
parent837b408c92d02108cbb16a97769675f39598d576 (diff)
downloadvboot-a524a3a51591618c1395cb9e1238ee72b3f5e767.tar.gz
vboot: cgpt: fix my_lba of the secondary GPT
Previously, my_lba of the secondary GPT was recorded as if that GPT was written at the end of the device. This patch tweaks my_lba to report where it is in the random-access GPT address space, namely at the end of that space. TEST=Compiled it into the firmware and observed the firmware to update the my_lba field of the secondary GPT. BRANCH=none BUG=chromium:425677 Signed-off-by: Dan Ehrenberg <dehrenberg@chromium.org> Change-Id: I88791fb2cff1086351ca8a3adeef675c4a88cc9a Reviewed-on: https://chromium-review.googlesource.com/228942 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Commit-Queue: Daniel Ehrenberg <dehrenberg@chromium.org> Tested-by: Daniel Ehrenberg <dehrenberg@chromium.org>
Diffstat (limited to 'tests/cgptlib_test.c')
-rw-r--r--tests/cgptlib_test.c94
1 files changed, 47 insertions, 47 deletions
diff --git a/tests/cgptlib_test.c b/tests/cgptlib_test.c
index 12b366ad..fc166fda 100644
--- a/tests/cgptlib_test.c
+++ b/tests/cgptlib_test.c
@@ -461,15 +461,15 @@ static int SignatureTest(void)
GptHeader *h2 = (GptHeader *)gpt->secondary_header;
int i;
- EXPECT(1 == CheckHeader(NULL, 0, gpt->drive_sectors, GPT_STORED_ON_DEVICE));
+ EXPECT(1 == CheckHeader(NULL, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
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_STORED_ON_DEVICE));
- EXPECT(1 == CheckHeader(h2, 1, gpt->drive_sectors, GPT_STORED_ON_DEVICE));
+ 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));
}
return TEST_OK;
@@ -503,9 +503,9 @@ static int RevisionTest(void)
h2->revision = cases[i].value_to_test;
RefreshCrc32(gpt);
- EXPECT(CheckHeader(h1, 0, gpt->drive_sectors, GPT_STORED_ON_DEVICE) ==
+ EXPECT(CheckHeader(h1, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE) ==
cases[i].expect_rv);
- EXPECT(CheckHeader(h2, 1, gpt->drive_sectors, GPT_STORED_ON_DEVICE) ==
+ EXPECT(CheckHeader(h2, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE) ==
cases[i].expect_rv);
}
return TEST_OK;
@@ -536,9 +536,9 @@ static int SizeTest(void)
h2->size = cases[i].value_to_test;
RefreshCrc32(gpt);
- EXPECT(CheckHeader(h1, 0, gpt->drive_sectors, GPT_STORED_ON_DEVICE) ==
+ EXPECT(CheckHeader(h1, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE) ==
cases[i].expect_rv);
- EXPECT(CheckHeader(h2, 1, gpt->drive_sectors, GPT_STORED_ON_DEVICE) ==
+ EXPECT(CheckHeader(h2, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE) ==
cases[i].expect_rv);
}
return TEST_OK;
@@ -555,12 +555,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_STORED_ON_DEVICE));
- EXPECT(1 == CheckHeader(h2, 1, gpt->drive_sectors, GPT_STORED_ON_DEVICE));
+ 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));
/* Refresh the CRC; should pass now */
RefreshCrc32(gpt);
- EXPECT(0 == CheckHeader(h1, 0, gpt->drive_sectors, GPT_STORED_ON_DEVICE));
- EXPECT(0 == CheckHeader(h2, 1, gpt->drive_sectors, GPT_STORED_ON_DEVICE));
+ 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));
return TEST_OK;
}
@@ -576,8 +576,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_STORED_ON_DEVICE));
- EXPECT(1 == CheckHeader(h2, 1, gpt->drive_sectors, GPT_STORED_ON_DEVICE));
+ 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));
#ifdef PADDING_CHECKED
/* TODO: padding check is currently disabled */
@@ -585,8 +585,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_STORED_ON_DEVICE));
- EXPECT(1 == CheckHeader(h2, 1, gpt->drive_sectors, GPT_STORED_ON_DEVICE));
+ 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));
#endif
return TEST_OK;
@@ -624,9 +624,9 @@ static int SizeOfPartitionEntryTest(void) {
cases[i].value_to_test;
RefreshCrc32(gpt);
- EXPECT(CheckHeader(h1, 0, gpt->drive_sectors, GPT_STORED_ON_DEVICE) ==
+ EXPECT(CheckHeader(h1, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE) ==
cases[i].expect_rv);
- EXPECT(CheckHeader(h2, 1, gpt->drive_sectors, GPT_STORED_ON_DEVICE) ==
+ EXPECT(CheckHeader(h2, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE) ==
cases[i].expect_rv);
}
@@ -647,11 +647,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_STORED_ON_DEVICE));
- EXPECT(1 == CheckHeader(h2, 1, gpt->drive_sectors, GPT_STORED_ON_DEVICE));
+ 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));
/* But it's okay to have less if the GPT structs are stored elsewhere. */
- EXPECT(0 == CheckHeader(h1, 0, gpt->drive_sectors, GPT_STORED_OFF_DEVICE));
- EXPECT(0 == CheckHeader(h2, 1, gpt->drive_sectors, GPT_STORED_OFF_DEVICE));
+ 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));
return TEST_OK;
}
@@ -666,37 +666,37 @@ static int MyLbaTest(void)
/* myLBA depends on primary vs secondary flag */
BuildTestGptData(gpt);
- EXPECT(1 == CheckHeader(h1, 1, gpt->drive_sectors, GPT_STORED_ON_DEVICE));
- EXPECT(1 == CheckHeader(h2, 0, gpt->drive_sectors, GPT_STORED_ON_DEVICE));
+ 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));
BuildTestGptData(gpt);
h1->my_lba--;
h2->my_lba--;
RefreshCrc32(gpt);
- EXPECT(1 == CheckHeader(h1, 0, gpt->drive_sectors, GPT_STORED_ON_DEVICE));
- EXPECT(1 == CheckHeader(h2, 1, gpt->drive_sectors, GPT_STORED_ON_DEVICE));
+ 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));
BuildTestGptData(gpt);
h1->my_lba = 2;
h2->my_lba--;
RefreshCrc32(gpt);
- EXPECT(1 == CheckHeader(h1, 0, gpt->drive_sectors, GPT_STORED_ON_DEVICE));
- EXPECT(1 == CheckHeader(h2, 1, gpt->drive_sectors, GPT_STORED_ON_DEVICE));
+ 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));
/* 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_STORED_ON_DEVICE));
- EXPECT(0 == CheckHeader(h2, 1, gpt->drive_sectors, GPT_STORED_ON_DEVICE));
+ 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));
BuildTestGptData(gpt);
h1->alternate_lba--;
h2->alternate_lba--;
RefreshCrc32(gpt);
- EXPECT(0 == CheckHeader(h1, 0, gpt->drive_sectors, GPT_STORED_ON_DEVICE));
- EXPECT(0 == CheckHeader(h2, 1, gpt->drive_sectors, GPT_STORED_ON_DEVICE));
+ 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));
BuildTestGptData(gpt);
h1->entries_lba++;
@@ -706,19 +706,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_STORED_ON_DEVICE));
+ EXPECT(0 == CheckHeader(h1, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
/*
* 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_STORED_ON_DEVICE));
+ EXPECT(1 == CheckHeader(h2, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
BuildTestGptData(gpt);
h1->entries_lba--;
h2->entries_lba--;
RefreshCrc32(gpt);
- EXPECT(1 == CheckHeader(h1, 0, gpt->drive_sectors, GPT_STORED_ON_DEVICE));
- EXPECT(1 == CheckHeader(h2, 1, gpt->drive_sectors, GPT_STORED_ON_DEVICE));
+ 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));
return TEST_OK;
}
@@ -767,9 +767,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_STORED_ON_DEVICE) ==
+ EXPECT(CheckHeader(h1, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE) ==
cases[i].primary_rv);
- EXPECT(CheckHeader(h2, 1, gpt->drive_sectors, GPT_STORED_ON_DEVICE) ==
+ EXPECT(CheckHeader(h2, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE) ==
cases[i].secondary_rv);
}
@@ -1981,26 +1981,26 @@ static int CheckHeaderOffDevice()
// 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_STORED_ON_DEVICE));
+ gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
// But off device, it is okay to accept this GPT header.
EXPECT(0 == CheckHeader(primary_header, 0, gpt->drive_sectors,
- GPT_STORED_OFF_DEVICE));
+ gpt->gpt_drive_sectors, GPT_STORED_OFF_DEVICE));
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_STORED_ON_DEVICE));
+ gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
// But off device, it is okay.
EXPECT(0 == CheckHeader(primary_header, 0, gpt->drive_sectors,
- GPT_STORED_OFF_DEVICE));
+ gpt->gpt_drive_sectors, GPT_STORED_OFF_DEVICE));
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_STORED_OFF_DEVICE));
+ gpt->gpt_drive_sectors, GPT_STORED_OFF_DEVICE));
// Repeat for secondary header.
BuildTestGptData(gpt);
@@ -2008,22 +2008,22 @@ static int CheckHeaderOffDevice()
secondary_header->first_usable_lba = 0;
RefreshCrc32(gpt);
EXPECT(1 == CheckHeader(secondary_header, 1, gpt->drive_sectors,
- GPT_STORED_ON_DEVICE));
+ gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
EXPECT(0 == CheckHeader(secondary_header, 1, gpt->drive_sectors,
- GPT_STORED_OFF_DEVICE));
+ gpt->gpt_drive_sectors, GPT_STORED_OFF_DEVICE));
BuildTestGptData(gpt);
secondary_header->number_of_entries = 100;
RefreshCrc32(gpt);
EXPECT(1 == CheckHeader(secondary_header, 1, gpt->drive_sectors,
- GPT_STORED_ON_DEVICE));
+ gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
EXPECT(0 == CheckHeader(secondary_header, 1, gpt->drive_sectors,
- GPT_STORED_OFF_DEVICE));
+ gpt->gpt_drive_sectors, GPT_STORED_OFF_DEVICE));
secondary_header->number_of_entries = MIN_NUMBER_OF_ENTRIES - 1;
RefreshCrc32(gpt);
EXPECT(1 == CheckHeader(secondary_header, 1, gpt->drive_sectors,
- GPT_STORED_OFF_DEVICE));
+ gpt->gpt_drive_sectors, GPT_STORED_OFF_DEVICE));
return TEST_OK;
}