aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDan Ehrenberg <dehrenberg@chromium.org>2014-12-02 08:21:57 -0800
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-12-15 22:44:33 +0000
commit3f4d8d05ba4e32990c8584bd47cdf082d4604232 (patch)
treea9c9b82c4ad25192f3ecbe921795c0961d0cbbfa /tests
parent3200401242aec1521e7c4a8b1906366fcabfb1a2 (diff)
downloadvboot_reference-3f4d8d05ba4e32990c8584bd47cdf082d4604232.tar.gz
vboot: Plumb the two disk sizes and external GPT param through
This patch reinstates the external GPT support which was previously committed and reverted. Improvements since last time include: - Cleaned-up internal interface based on code review - Function correctly on legacy bootloaders (e.g., depthcharge before NAND-related patches are added) - Better comments - Treat new field values = 0 -> not use new feature - Tests are added to ensure external GPT flag is passed down properly The original commit had change-id I5a77e417aea8ee9442d18c200d1b073aa5375ecf Its commit message is reproduced below, and then an additional test. ---- To support an external GPT, disks have two new attributes: - A binary flag indicating whether the GPT is in the same address space as the payloads or a separate one. - The number of sectors of the streaming portion of storage, as opposed to the portion containing the GPT. These have been added elsewhere to GptData (in cgptlib) and BlockDev (in depthcharge). This patch adds the plumbing between those, including in the DiskInfo interface between the firmware and vboot. BUG=chromium:425677 BRANCH=none TEST=Interactively wrote the GPT with cgpt and observed the following boot with depthcharge to read the GPT from SPI and then read from the proper locations in NAND flash. TEST=make runalltests passes. TEST=boots from USB with depthcharge from HEAD. Change-Id: Ia7956517a7b9da0301f01fac5a10204f6d78cf4f Signed-off-by: Dan Ehrenberg <dehrenberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/234640 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/vboot_api_kernel_tests.c12
-rw-r--r--tests/vboot_kernel_tests.c23
2 files changed, 32 insertions, 3 deletions
diff --git a/tests/vboot_api_kernel_tests.c b/tests/vboot_api_kernel_tests.c
index bccad0de..05662f52 100644
--- a/tests/vboot_api_kernel_tests.c
+++ b/tests/vboot_api_kernel_tests.c
@@ -37,6 +37,7 @@ typedef struct {
disk_desc_t disks_to_provide[MAX_TEST_DISKS];
int disk_count_to_return;
VbError_t loadkernel_return_val[MAX_TEST_DISKS];
+ uint8_t external_expected[MAX_TEST_DISKS];
/* outputs from test */
uint32_t expected_recovery_request_val;
@@ -67,13 +68,16 @@ test_case_t test[] = {
{512, 100, 0, 0},
/* still wrong flags */
{512, 100, -1, 0},
- {512, 100, VB_DISK_FLAG_REMOVABLE, pickme},
+ {512, 100,
+ VB_DISK_FLAG_REMOVABLE | VB_DISK_FLAG_EXTERNAL_GPT,
+ pickme},
/* already got one */
{512, 100, VB_DISK_FLAG_REMOVABLE, "holygrail"},
},
.disk_count_to_return = DEFAULT_COUNT,
.diskgetinfo_return_val = VBERROR_SUCCESS,
.loadkernel_return_val = {0, 1, 1, 1, 1, 1, 1, 1, 1, 1,},
+ .external_expected = {1, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
.expected_recovery_request_val = VBNV_RECOVERY_NOT_REQUESTED,
.expected_to_find_disk = pickme,
@@ -182,6 +186,7 @@ static uint32_t got_recovery_request_val;
static const char *got_find_disk;
static const char *got_load_disk;
static uint32_t got_return_val;
+static uint32_t got_external_mismatch;
/**
* Reset mock data (for use before each test)
@@ -229,6 +234,7 @@ VbError_t VbExDiskGetInfo(VbDiskInfo **infos_ptr, uint32_t *count,
mock_disks[num_disks].bytes_per_lba =
t->disks_to_provide[i].bytes_per_lba;
mock_disks[num_disks].lba_count =
+ mock_disks[num_disks].streaming_lba_count =
t->disks_to_provide[i].lba_count;
mock_disks[num_disks].flags =
t->disks_to_provide[i].flags;
@@ -275,6 +281,9 @@ VbError_t LoadKernel(LoadKernelParams *params, VbCommonParams *cparams)
VBDEBUG(("%s(%d): got_find_disk = %s\n", __FUNCTION__,
load_kernel_calls,
got_find_disk ? got_find_disk : "0"));
+ if (t->external_expected[load_kernel_calls] !=
+ !!(params->boot_flags & BOOT_FLAG_EXTERNAL_GPT))
+ got_external_mismatch++;
return t->loadkernel_return_val[load_kernel_calls++];
}
@@ -306,6 +315,7 @@ static void VbTryLoadKernelTest(void)
TEST_PTR_EQ(got_load_disk, t->expected_to_load_disk,
" load disk");
}
+ TEST_EQ(got_external_mismatch, 0, " external GPT errors");
}
}
diff --git a/tests/vboot_kernel_tests.c b/tests/vboot_kernel_tests.c
index 41ac7add..e19ac114 100644
--- a/tests/vboot_kernel_tests.c
+++ b/tests/vboot_kernel_tests.c
@@ -50,6 +50,7 @@ static int preamble_verify_fail;
static int verify_data_fail;
static RSAPublicKey *mock_data_key;
static int mock_data_key_allocated;
+static int gpt_flag_external;
static uint8_t gbb_data[sizeof(GoogleBinaryBlockHeader) + 2048];
static GoogleBinaryBlockHeader *gbb = (GoogleBinaryBlockHeader*)gbb_data;
@@ -126,6 +127,8 @@ static void ResetMocks(void)
mock_data_key = (RSAPublicKey *)"TestDataKey";
mock_data_key_allocated = 0;
+ gpt_flag_external = 0;
+
memset(gbb, 0, sizeof(*gbb));
gbb->major_version = GBB_MAJOR_VER;
gbb->minor_version = GBB_MINOR_VER;
@@ -150,7 +153,8 @@ static void ResetMocks(void)
lkp.gbb_data = gbb;
lkp.gbb_size = sizeof(gbb_data);
lkp.bytes_per_lba = 512;
- lkp.ending_lba = 1023;
+ lkp.streaming_lba_count = 1024;
+ lkp.gpt_lba_count = 1024;
lkp.kernel_buffer = kernel_buffer;
lkp.kernel_buffer_size = sizeof(kernel_buffer);
lkp.disk_handle = (VbExDiskHandle_t)1;
@@ -215,6 +219,9 @@ int GptNextKernelEntry(GptData *gpt, uint64_t *start_sector, uint64_t *size)
if (!p->size)
return GPT_ERROR_NO_VALID_KERNEL;
+ if (gpt->flags & GPT_FLAG_EXTERNAL)
+ gpt_flag_external++;
+
gpt->current_kernel = mock_part_next;
*start_sector = p->start;
*size = p->size;
@@ -522,7 +529,7 @@ static void InvalidParamsTest(void)
"Bad lba size");
ResetMocks();
- lkp.ending_lba = 0;
+ lkp.streaming_lba_count = 0;
TEST_EQ(LoadKernel(&lkp, &cparams), VBERROR_INVALID_PARAMETER,
"Bad lba count");
@@ -541,6 +548,11 @@ static void InvalidParamsTest(void)
TEST_EQ(LoadKernel(&lkp, &cparams), VBERROR_NO_KERNEL_FOUND,
"Bad GPT");
+ ResetMocks();
+ lkp.gpt_lba_count = 0;
+ TEST_EQ(LoadKernel(&lkp, &cparams), VBERROR_NO_KERNEL_FOUND,
+ "GPT size = 0");
+
/* This causes the stream open call to fail */
ResetMocks();
lkp.disk_handle = NULL;
@@ -560,6 +572,7 @@ static void LoadKernelTest(void)
TEST_EQ(lkp.bootloader_address, 0xbeadd008, " bootloader addr");
TEST_EQ(lkp.bootloader_size, 0x1234, " bootloader size");
TEST_STR_EQ((char *)lkp.partition_guid, "FakeGuid", " guid");
+ TEST_EQ(gpt_flag_external, 0, "GPT was internal");
VbNvGet(&vnc, VBNV_RECOVERY_REQUEST, &u);
TEST_EQ(u, 0, " recovery request");
@@ -742,6 +755,12 @@ static void LoadKernelTest(void)
ResetMocks();
verify_data_fail = 1;
TEST_EQ(LoadKernel(&lkp, &cparams), VBERROR_INVALID_KERNEL_FOUND, "Bad data");
+
+ /* Check that EXTERNAL_GPT flag makes it down */
+ ResetMocks();
+ lkp.boot_flags |= BOOT_FLAG_EXTERNAL_GPT;
+ TEST_EQ(LoadKernel(&lkp, &cparams), 0, "Succeed external GPT");
+ TEST_EQ(gpt_flag_external, 1, "GPT was external");
}
int main(void)