diff options
author | Bill Richardson <wfrichar@chromium.org> | 2013-03-28 17:31:24 -0700 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-03-29 11:40:36 -0700 |
commit | 28b65ca99f4042fcc1218a4c18297f7ffb32ea15 (patch) | |
tree | 523c876b1c62ff1aba5c77d0b261fa2c3e0f4525 | |
parent | 661ae9e9cbaad430b87b443712d2608f9ce59883 (diff) | |
download | vboot-28b65ca99f4042fcc1218a4c18297f7ffb32ea15.tar.gz |
Simplify the exported FindKernelConfig() function.
FindKernelConfig() is used to extract the kernel cmdline from a kernel
partition. It's only used in the chromeos-installer, but was a bit awkward.
This changes the calling parameters to make it simpler.
BUG=chromium:221544
BRANCH=none
TEST=manual
CQ-DEPEND=CL:46835
FEATURES=test sudo emerge vboot_reference
FEATURES=test emerge-$BOARD vboot_reference
Change-Id: Ib7192175d72ad51387d8d122ead4490a4aa62300
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/46834
-rw-r--r-- | utility/dump_kernel_config.c | 26 | ||||
-rw-r--r-- | utility/dump_kernel_config_lib.c | 39 | ||||
-rw-r--r-- | utility/include/dump_kernel_config.h | 13 |
3 files changed, 51 insertions, 27 deletions
diff --git a/utility/dump_kernel_config.c b/utility/dump_kernel_config.c index 0a8e0279..e733a0d0 100644 --- a/utility/dump_kernel_config.c +++ b/utility/dump_kernel_config.c @@ -36,11 +36,9 @@ static int PrintHelp(void) { } int main(int argc, char* argv[]) { - uint8_t* blob; - size_t blob_size; - char* infile = NULL; - uint8_t *config = NULL; - uint64_t kernel_body_load_address = CROS_NO_ENTRY_ADDR; + char *infile = NULL; + char *config = NULL; + uint64_t kernel_body_load_address = USE_PREAMBLE_LOAD_ADDR; int parse_error = 0; char *e; int i; @@ -82,22 +80,12 @@ int main(int argc, char* argv[]) { return 1; } - /* Map the kernel image blob. */ - blob = MMapFile(infile, &blob_size); - if (!blob) { - VbExError("Error reading input file\n"); + config = FindKernelConfig(infile, kernel_body_load_address); + if (!config) return 1; - } - config = FindKernelConfig(blob, (uint64_t)blob_size, - kernel_body_load_address); - if (!config) { - VbExError("Error parsing input file\n"); - munmap(blob, blob_size); - return 1; - } + printf("%s", config); - printf("%.*s", CROS_CONFIG_SIZE, config); - munmap(blob, blob_size); + free(config); return 0; } diff --git a/utility/dump_kernel_config_lib.c b/utility/dump_kernel_config_lib.c index 9559a739..464e349b 100644 --- a/utility/dump_kernel_config_lib.c +++ b/utility/dump_kernel_config_lib.c @@ -6,6 +6,7 @@ */ #include <stdio.h> +#include <string.h> #include <sys/mman.h> #include "dump_kernel_config.h" @@ -13,8 +14,8 @@ #include "kernel_blob.h" #include "vboot_api.h" -uint8_t* FindKernelConfig(uint8_t* blob, uint64_t blob_size, - uint64_t kernel_body_load_address) { +static uint8_t* GetKernelConfig(uint8_t* blob, size_t blob_size, + uint64_t kernel_body_load_address) { VbKeyBlockHeader* key_block; VbKernelPreambleHeader* preamble; @@ -38,7 +39,7 @@ uint8_t* FindKernelConfig(uint8_t* blob, uint64_t blob_size, } /* Read body_load_address from preamble if no kernel_body_load_address */ - if (kernel_body_load_address == CROS_NO_ENTRY_ADDR) + 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 @@ -54,7 +55,7 @@ uint8_t* FindKernelConfig(uint8_t* blob, uint64_t blob_size, return blob + offset; } -void* MMapFile(const char* filename, size_t *size) { +static void* MMapFile(const char* filename, size_t *size) { FILE* f; uint8_t* buf; long file_size = 0; @@ -86,3 +87,33 @@ void* MMapFile(const char* filename, size_t *size) { 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; +} diff --git a/utility/include/dump_kernel_config.h b/utility/include/dump_kernel_config.h index 2289da72..cacc5619 100644 --- a/utility/include/dump_kernel_config.h +++ b/utility/include/dump_kernel_config.h @@ -2,7 +2,7 @@ * 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. + * Exports the kernel commandline from a given partition/image file. */ #ifndef DUMP_KERNEL_CONFIG_UTILITY_H_ @@ -11,9 +11,14 @@ #include <inttypes.h> #include <stdlib.h> -uint8_t* FindKernelConfig(uint8_t* blob, uint64_t blob_size, - uint64_t kernel_body_load_address); +/* TODO(wfrichar): This needs a better location */ +#define MAX_KERNEL_CONFIG_SIZE 4096 -void* MMapFile(const char* filename, size_t *size); +/* Use this to obtain the body load address from the kernel preamble */ +#define USE_PREAMBLE_LOAD_ADDR (~0) + +/* Returns a new copy of the kernel cmdline. The caller must free it. */ +char *FindKernelConfig(const char *filename, + uint64_t kernel_body_load_address); #endif // DUMP_KERNEL_CONFIG_UTILITY_H_ |