diff options
author | Joel Kitching <kitching@google.com> | 2021-04-22 21:03:35 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-06-15 19:35:54 +0000 |
commit | 43fa783cbf6014d23d8b23b5eb7b4e63b17864ec (patch) | |
tree | 31102ed2b9c528accadbc35358eb6031ff3c1fbf /tests | |
parent | 39ea3ade28b733521b480da161c61848764a3096 (diff) | |
download | vboot-43fa783cbf6014d23d8b23b5eb7b4e63b17864ec.tar.gz |
vboot/vboot_kernel: pass VbDiskInfo into LoadKernel
Pass VbDiskInfo struct into LoadKernel, rather than copying all
of its members into LoadKernelParams. Remove the unused members
from LoadKernelParams.
This CL is part of a series to merge vboot1 and vboot2.0
kernel verification code; see b/181739551.
BUG=b:181739551
TEST=make clean && make runtests
BRANCH=none
Signed-off-by: Joel Kitching <kitching@google.com>
Change-Id: I60957426388c88b16e570b717addb5eaf65b5e4f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/2846281
Reviewed-by: Joel Kitching <kitching@chromium.org>
Tested-by: Joel Kitching <kitching@chromium.org>
Commit-Queue: Joel Kitching <kitching@chromium.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/vboot_api_kernel_tests.c | 5 | ||||
-rw-r--r-- | tests/vboot_kernel_tests.c | 15 | ||||
-rw-r--r-- | tests/verify_kernel.c | 20 |
3 files changed, 24 insertions, 16 deletions
diff --git a/tests/vboot_api_kernel_tests.c b/tests/vboot_api_kernel_tests.c index bcb5d046..b5e1e7c3 100644 --- a/tests/vboot_api_kernel_tests.c +++ b/tests/vboot_api_kernel_tests.c @@ -395,14 +395,15 @@ vb2_error_t VbExDiskFreeInfo(VbDiskInfo *infos, return VB2_SUCCESS; } -vb2_error_t LoadKernel(struct vb2_context *c, LoadKernelParams *params) +vb2_error_t LoadKernel(struct vb2_context *c, LoadKernelParams *params, + VbDiskInfo *disk_info) { got_find_disk = (const char *)params->disk_handle; VB2_DEBUG("%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)) + !!(disk_info->flags & VB_DISK_FLAG_EXTERNAL_GPT)) got_external_mismatch++; return t->loadkernel_return_val[load_kernel_calls++]; } diff --git a/tests/vboot_kernel_tests.c b/tests/vboot_kernel_tests.c index 7d088ae6..6bfb3ae8 100644 --- a/tests/vboot_kernel_tests.c +++ b/tests/vboot_kernel_tests.c @@ -55,6 +55,7 @@ static int gpt_flag_external; static struct vb2_gbb_header gbb; static VbExDiskHandle_t handle; static LoadKernelParams lkp; +static VbDiskInfo disk_info; static struct vb2_keyblock kbh; static struct vb2_kernel_preamble kph; static struct vb2_secdata_fwmp *fwmp; @@ -136,13 +137,16 @@ static void ResetMocks(void) gbb.flags = 0; memset(&lkp, 0, sizeof(lkp)); - lkp.bytes_per_lba = 512; - 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; + memset(&disk_info, 0, sizeof(disk_info)); + disk_info.bytes_per_lba = 512; + disk_info.streaming_lba_count = 1024; + disk_info.lba_count = 1024; + disk_info.handle = lkp.disk_handle; + memset(&kbh, 0, sizeof(kbh)); kbh.data_key.key_version = 2; kbh.keyblock_flags = -1; @@ -592,7 +596,7 @@ static void ReadWriteGptTest(void) static void TestLoadKernel(int expect_retval, const char *test_name) { - TEST_EQ(LoadKernel(ctx, &lkp), expect_retval, test_name); + TEST_EQ(LoadKernel(ctx, &lkp, &disk_info), expect_retval, test_name); } /** @@ -607,6 +611,7 @@ static void InvalidParamsTest(void) /* This causes the stream open call to fail */ ResetMocks(); lkp.disk_handle = NULL; + disk_info.handle = NULL; TestLoadKernel(VB2_ERROR_LK_INVALID_KERNEL_FOUND, "Bad disk handle"); } @@ -861,7 +866,7 @@ static void LoadKernelTest(void) /* Check that EXTERNAL_GPT flag makes it down */ ResetMocks(); - lkp.boot_flags |= BOOT_FLAG_EXTERNAL_GPT; + disk_info.flags |= VB_DISK_FLAG_EXTERNAL_GPT; TestLoadKernel(0, "Succeed external GPT"); TEST_EQ(gpt_flag_external, 1, "GPT was external"); diff --git a/tests/verify_kernel.c b/tests/verify_kernel.c index fe68a1b4..7c2ce917 100644 --- a/tests/verify_kernel.c +++ b/tests/verify_kernel.c @@ -24,15 +24,16 @@ static struct vb2_shared_data *sd; static uint8_t *diskbuf; static LoadKernelParams params; +static VbDiskInfo disk_info; vb2_error_t VbExDiskRead(VbExDiskHandle_t handle, uint64_t lba_start, uint64_t lba_count, void *buffer) { if (handle != (VbExDiskHandle_t)1) return VB2_ERROR_UNKNOWN; - if (lba_start >= params.streaming_lba_count) + if (lba_start >= disk_info.streaming_lba_count) return VB2_ERROR_UNKNOWN; - if (lba_start + lba_count > params.streaming_lba_count) + if (lba_start + lba_count > disk_info.streaming_lba_count) return VB2_ERROR_UNKNOWN; memcpy(buffer, diskbuf + lba_start * 512, lba_count * 512); @@ -44,9 +45,9 @@ vb2_error_t VbExDiskWrite(VbExDiskHandle_t handle, uint64_t lba_start, { if (handle != (VbExDiskHandle_t)1) return VB2_ERROR_UNKNOWN; - if (lba_start >= params.streaming_lba_count) + if (lba_start >= disk_info.streaming_lba_count) return VB2_ERROR_UNKNOWN; - if (lba_start + lba_count > params.streaming_lba_count) + if (lba_start + lba_count > disk_info.streaming_lba_count) return VB2_ERROR_UNKNOWN; memcpy(diskbuf + lba_start * 512, buffer, lba_count * 512); @@ -87,9 +88,10 @@ int main(int argc, char *argv[]) /* Set up params */ params.disk_handle = (VbExDiskHandle_t)1; - params.bytes_per_lba = 512; - params.streaming_lba_count = disk_bytes / 512; - params.gpt_lba_count = params.streaming_lba_count; + disk_info.handle = (VbExDiskHandle_t)1; + disk_info.bytes_per_lba = 512; + disk_info.streaming_lba_count = disk_bytes / 512; + disk_info.lba_count = disk_info.streaming_lba_count; params.kernel_buffer_size = 16 * 1024 * 1024; params.kernel_buffer = malloc(params.kernel_buffer_size); @@ -99,7 +101,7 @@ int main(int argc, char *argv[]) } /* TODO(chromium:441893): support dev-mode flag and external gpt flag */ - params.boot_flags = 0; + disk_info.flags = 0; if (vb2api_init(&workbuf, sizeof(workbuf), &ctx)) { fprintf(stderr, "Can't initialize workbuf\n"); @@ -132,7 +134,7 @@ int main(int argc, char *argv[]) vb2_secdata_kernel_init(ctx); /* Try loading kernel */ - rv = LoadKernel(ctx, ¶ms); + rv = LoadKernel(ctx, ¶ms, &disk_info); if (rv != VB2_SUCCESS) { fprintf(stderr, "LoadKernel() failed with code %d\n", rv); return 1; |