diff options
author | Bill Richardson <wfrichar@chromium.org> | 2014-07-15 12:52:19 -0700 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2014-07-31 22:46:27 +0000 |
commit | 6f3961507e73f90cec665896dece884e86be560a (patch) | |
tree | 0f11e2ca91c3c5be6ed30748b0d9224c6ede456a /futility/dump_kernel_config_lib.c | |
parent | b52d7b7acb14743747489ed7323b416bc001503b (diff) | |
download | vboot-6f3961507e73f90cec665896dece884e86be560a.tar.gz |
futility: Add remaining vboot binary utilities
This change adds these formerly external utilities into the futility binary:
dev_sign_file
dump_kernel_config
gbb_utility
vbutil_firmware
vbutil_kernel
These target binaries will remain independent of futility, since they are
not directly related to verified boot:
cgpt
crossystem
tpm_init_temp_fix
tpmc
Also, dumpRSAPublicKey is removed from the target, since it is only used on
the build host to create new keypairs.
This change also add several additional tests.
BUG=chromium:224734
BRANCH=ToT
CQ-DEPEND=CL:210391,CL:210568,CL:210587
TEST=manual
make runtests
make clean
Also build and test:
- normal image
- test image
- recovery image
- firmware shellball
Note that this CL depends on simultaneous changes to the chromeos-initramfs
ebuild.
Change-Id: If791b5e9b5aac218ceafa9f45fc1785f16b91a64
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/210403
Diffstat (limited to 'futility/dump_kernel_config_lib.c')
-rw-r--r-- | futility/dump_kernel_config_lib.c | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/futility/dump_kernel_config_lib.c b/futility/dump_kernel_config_lib.c new file mode 100644 index 00000000..63c2899f --- /dev/null +++ b/futility/dump_kernel_config_lib.c @@ -0,0 +1,119 @@ +/* Copyright 2012 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * Exports the kernel commandline from a given partition/image. + */ + +#include <stdio.h> +#include <string.h> +#include <sys/mman.h> + +#include "host_common.h" +#include "kernel_blob.h" +#include "vboot_api.h" +#include "vboot_host.h" + +static uint8_t* GetKernelConfig(uint8_t* blob, size_t blob_size, + uint64_t kernel_body_load_address) { + + VbKeyBlockHeader* key_block; + VbKernelPreambleHeader* preamble; + uint32_t now = 0; + uint32_t offset = 0; + + /* Skip the key block */ + key_block = (VbKeyBlockHeader*)blob; + now += key_block->key_block_size; + if (now + blob > blob + blob_size) { + VbExError("key_block_size advances past the end of the blob\n"); + return NULL; + } + + /* Open up the preamble */ + preamble = (VbKernelPreambleHeader*)(blob + now); + now += preamble->preamble_size; + if (now + blob > blob + blob_size) { + VbExError("preamble_size advances past the end of the blob\n"); + return NULL; + } + + /* Read body_load_address from preamble if no kernel_body_load_address */ + if (kernel_body_load_address == USE_PREAMBLE_LOAD_ADDR) + kernel_body_load_address = preamble->body_load_address; + + /* The x86 kernels have a pointer to the kernel commandline in the zeropage + * table, but that's irrelevant for ARM. Both types keep the config blob in + * the same place, so just go find it. */ + offset = preamble->bootloader_address - + (kernel_body_load_address + CROS_PARAMS_SIZE + + CROS_CONFIG_SIZE) + now; + if (offset > blob_size) { + VbExError("params are outside of the memory blob: %x\n", offset); + return NULL; + } + return blob + offset; +} + +static void* MMapFile(const char* filename, size_t *size) { + FILE* f; + uint8_t* buf; + long file_size = 0; + + f = fopen(filename, "rb"); + if (!f) { + VBDEBUG(("Unable to open file %s\n", filename)); + return NULL; + } + + fseek(f, 0, SEEK_END); + file_size = ftell(f); + rewind(f); + + if (file_size <= 0) { + fclose(f); + return NULL; + } + *size = (size_t) file_size; + + /* Uses a host primitive as this is not meant for firmware use. */ + buf = mmap(NULL, *size, PROT_READ, MAP_PRIVATE, fileno(f), 0); + if (buf == MAP_FAILED) { + VbExError("Failed to mmap the file %s\n", filename); + fclose(f); + return NULL; + } + + fclose(f); + return buf; +} + + +char *FindKernelConfig(const char *infile, uint64_t kernel_body_load_address) +{ + uint8_t* blob; + size_t blob_size; + uint8_t *config = NULL; + char *newstr = NULL; + + blob = MMapFile(infile, &blob_size); + if (!blob) { + VbExError("Error reading input file\n"); + return 0; + } + + config = GetKernelConfig(blob, blob_size, kernel_body_load_address); + if (!config) { + VbExError("Error parsing input file\n"); + munmap(blob, blob_size); + return 0; + } + + newstr = strndup((char *)config, CROS_CONFIG_SIZE); + if (!newstr) + VbExError("Can't allocate new string\n"); + + munmap(blob, blob_size); + + return newstr; +} |