summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@chromium.org>2012-08-01 18:44:05 -0700
committerBill Richardson <wfrichar@chromium.org>2012-10-24 17:48:53 -0700
commit4b6ca4033965ca4e51ed38e5195db03115698521 (patch)
tree5677f19839b43432b2fd00ed790ebc1f82ce9caa
parent2e33e2ad13d3a2fe50a14c7f05c90826dd86b7db (diff)
downloadvboot-4b6ca4033965ca4e51ed38e5195db03115698521.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. Original-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> (cherry picked from commit b321dbb6bc819d4b7b5a2831dbda0816d3f772d8) Change-Id: Ideae5beba64466328276db030a0a8cfd9c52bd7d Reviewed-on: https://gerrit.chromium.org/gerrit/36512 Reviewed-by: Simon Glass <sjg@chromium.org> Tested-by: Bill Richardson <wfrichar@chromium.org>
-rw-r--r--firmware/lib/vboot_api_kernel.c9
-rw-r--r--firmware/lib/vboot_kernel.c20
2 files changed, 21 insertions, 8 deletions
diff --git a/firmware/lib/vboot_api_kernel.c b/firmware/lib/vboot_api_kernel.c
index 898d9bea..c97caba7 100644
--- a/firmware/lib/vboot_api_kernel.c
+++ b/firmware/lib/vboot_api_kernel.c
@@ -638,8 +638,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)
@@ -748,6 +754,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 190dc1bf..44064b95 100644
--- a/firmware/lib/vboot_kernel.c
+++ b/firmware/lib/vboot_kernel.c
@@ -159,9 +159,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;
@@ -404,12 +402,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 */