diff options
author | Vadim Bendebury <vbendeb@chromium.org> | 2012-08-01 18:44:05 -0700 |
---|---|---|
committer | Gerrit <chrome-bot@google.com> | 2012-08-14 14:04:20 -0700 |
commit | b321dbb6bc819d4b7b5a2831dbda0816d3f772d8 (patch) | |
tree | 19109130df08a58df69e12cc4dc93815ee02273b | |
parent | 3e894ba453fe76b46cf5d269a596ff190927b92e (diff) | |
download | vboot-b321dbb6bc819d4b7b5a2831dbda0816d3f772d8.tar.gz |
Get kernel size/load address from vboot headers
Presently kernel load address and buffer size are programmed in the
u-boot device tree. There is no reason for this: the address and size
are part of the vboot encapsulation headers. Duplicating this
information hardcoded in the device tree does not bring any benefit
and is in fact harmful, as it is easy to get out of sync.
A better way of doing things is to derive kernel load address and size
from the appropriate vboot header. ARM people object to this, as they
want the very same kernel blob operate on devices with DRAM mapped to
different address ranges.
The suggested solution is to exclude the kernel memory section from
the device tree on the platforms where the load address could be
safely taken from the vboot header. In this case u-boot will pass
address of zero to vboot, which will know to derive the address/size
from the appropriate header. vboot then rewrites fields of the u-boot
supplied structure with actual address and size of the kernel blob.
There is no sanity check yet, as it is presumed that there is enough
memory to load any kernel and u-boot does not use the space above
0x100000 for at least 16 megabytes (the kernel partition size). On x86
platform the check could be verify that the top of the kernel space is
well below the stack.
BUG=chrome-os-partner:11994
TEST=manual
. with the appropriate u-boot change run a Link target through a
FAFT cycle, observe it succeed.
Change-Id: I3c2c2cefb1e31d16ac497a01894bf32638479ed7
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/29038
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Doug Anderson <dianders@chromium.org>
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Commit-Ready: Bill Richardson <wfrichar@chromium.org>
-rw-r--r-- | firmware/lib/vboot_api_kernel.c | 9 | ||||
-rw-r--r-- | firmware/lib/vboot_kernel.c | 20 |
2 files changed, 21 insertions, 8 deletions
diff --git a/firmware/lib/vboot_api_kernel.c b/firmware/lib/vboot_api_kernel.c index 8b5b2034..20296dd1 100644 --- a/firmware/lib/vboot_api_kernel.c +++ b/firmware/lib/vboot_api_kernel.c @@ -669,8 +669,14 @@ VbError_t VbSelectAndLoadKernel(VbCommonParams* cparams, p.shared_data_size = cparams->shared_data_size; p.gbb_data = cparams->gbb_data; p.gbb_size = cparams->gbb_size; + + /* + * this could be set to NULL, in which case the vboot header information + * about the load address and size will be used + */ p.kernel_buffer = kparams->kernel_buffer; p.kernel_buffer_size = kparams->kernel_buffer_size; + p.nv_context = &vnc; p.boot_flags = 0; if (shared->flags & VBSD_BOOT_DEV_SWITCH_ON) @@ -779,6 +785,9 @@ VbSelectAndLoadKernel_exit: /* Stop timer */ shared->timer_vb_select_and_load_kernel_exit = VbExGetTimer(); + kparams->kernel_buffer = p.kernel_buffer; + kparams->kernel_buffer_size = p.kernel_buffer_size; + VBDEBUG(("VbSelectAndLoadKernel() returning %d\n", (int)retval)); /* Pass through return value from boot path */ diff --git a/firmware/lib/vboot_kernel.c b/firmware/lib/vboot_kernel.c index 1dffc7b3..cf97bee5 100644 --- a/firmware/lib/vboot_kernel.c +++ b/firmware/lib/vboot_kernel.c @@ -147,9 +147,7 @@ VbError_t LoadKernel(LoadKernelParams* params) { /* Sanity Checks */ if (!params || !params->bytes_per_lba || - !params->ending_lba || - !params->kernel_buffer || - !params->kernel_buffer_size) { + !params->ending_lba) { VBDEBUG(("LoadKernel() called with invalid params\n")); retval = VBERROR_INVALID_PARAMETER; goto LoadKernelExit; @@ -392,12 +390,18 @@ VbError_t LoadKernel(LoadKernelParams* params) { } body_offset_sectors = body_offset / blba; - /* Verify kernel body fits in the buffer */ body_sectors = (preamble->body_signature.data_size + blba - 1) / blba; - if (body_sectors * blba > params->kernel_buffer_size) { - VBDEBUG(("Kernel body doesn't fit in memory.\n")); - shpart->check_result = VBSD_LKP_CHECK_BODY_EXCEEDS_MEM; - goto bad_kernel; + if (!params->kernel_buffer) { + /* Get kernel load address and size from the header. */ + params->kernel_buffer = (void*) ((long)preamble->body_load_address); + params->kernel_buffer_size = body_sectors * blba; + } else { + /* Verify kernel body fits in the buffer */ + if (body_sectors * blba > params->kernel_buffer_size) { + VBDEBUG(("Kernel body doesn't fit in memory.\n")); + shpart->check_result = VBSD_LKP_CHECK_BODY_EXCEEDS_MEM; + goto bad_kernel; + } } /* Verify kernel body fits in the partition */ |