summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuncan Laurie <dlaurie@chromium.org>2012-08-14 15:48:08 -0700
committerDuncan Laurie <dlaurie@chromium.org>2012-08-14 19:32:59 -0700
commit61712d4b0a869c1fb686f5d6556395cf0681e1a4 (patch)
tree3db620c0d36976fce3de5be1dd304ec463674fe0
parentcd4564e6679ff41f2164ebe3d4062d66c4ff18d7 (diff)
downloadvboot-61712d4b0a869c1fb686f5d6556395cf0681e1a4.tar.gz
(firmware-parrot)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: I992ae88e1e25e229410f36101135f08dd019a899 Signed-off-by: Duncan Laurie <dlaurie@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/30340 Reviewed-by: Jay Kim <yongjaek@chromium.org> Reviewed-by: Marc Jones <marc.jones@se-eng.com>
-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 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 */