diff options
author | Randall Spangler <rspangler@chromium.org> | 2013-01-11 10:55:11 -0800 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-01-11 16:14:24 -0800 |
commit | 17f8d341099120da78a6ca71165834eefb0960ed (patch) | |
tree | a43c898fc4b547d45a1b16990d556d894108b612 /utility | |
parent | 5d9bbf2bbd7b8dfad45d8ddfea6512987736e523 (diff) | |
download | vboot-17f8d341099120da78a6ca71165834eefb0960ed.tar.gz |
Rename files and defines to simplify makefile.
BUG=chromium-os:26317
BRANCH=none
TEST=manual
sudo emerge vboot_reference
emerge-link vboot_reference chromeos-u-boot chromeos-installer
emerge-daisy vboot_reference chromeos-u-boot chromeos-installer
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Change-Id: I8c55ca40f3f0cacf08530ab63c886fe351bcee8e
Reviewed-on: https://gerrit.chromium.org/gerrit/41152
Diffstat (limited to 'utility')
-rw-r--r-- | utility/bmpblk_utility.cc | 4 | ||||
-rw-r--r-- | utility/crossystem.c (renamed from utility/crossystem_main.c) | 0 | ||||
-rw-r--r-- | utility/dump_kernel_config.c | 137 | ||||
-rw-r--r-- | utility/dump_kernel_config_lib.c | 88 | ||||
-rw-r--r-- | utility/dump_kernel_config_main.c | 103 | ||||
-rw-r--r-- | utility/eficompress.c | 4 | ||||
-rw-r--r-- | utility/efidecompress.c | 4 | ||||
-rw-r--r-- | utility/gbb_utility.cc | 4 |
8 files changed, 172 insertions, 172 deletions
diff --git a/utility/bmpblk_utility.cc b/utility/bmpblk_utility.cc index 386d2d44..ea04c222 100644 --- a/utility/bmpblk_utility.cc +++ b/utility/bmpblk_utility.cc @@ -630,7 +630,7 @@ namespace vboot_reference { } // namespace vboot_reference -#ifdef WITH_UTIL_MAIN +#ifndef FOR_LIBRARY ////////////////////////////////////////////////////////////////////////////// // Command line utilities. @@ -772,4 +772,4 @@ namespace vboot_reference { return 0; } -#endif // WITH_UTIL_MAIN +#endif // FOR_LIBRARY diff --git a/utility/crossystem_main.c b/utility/crossystem.c index 91465002..91465002 100644 --- a/utility/crossystem_main.c +++ b/utility/crossystem.c diff --git a/utility/dump_kernel_config.c b/utility/dump_kernel_config.c index a6989e1c..20a51871 100644 --- a/utility/dump_kernel_config.c +++ b/utility/dump_kernel_config.c @@ -5,84 +5,99 @@ * Exports the kernel commandline from a given partition/image. */ + +#include <getopt.h> #include <stdio.h> #include <sys/mman.h> +#include <unistd.h> #include "dump_kernel_config.h" -#include "host_common.h" #include "kernel_blob.h" #include "vboot_api.h" -uint8_t* find_kernel_config(uint8_t* blob, uint64_t blob_size, - uint64_t kernel_body_load_address) { +enum { + OPT_KLOADADDR = 1000, +}; - VbKeyBlockHeader* key_block; - VbKernelPreambleHeader* preamble; - uint32_t now = 0; - uint32_t offset = 0; +static struct option long_opts[] = { + { "kloadaddr", 1, NULL, OPT_KLOADADDR }, + { NULL, 0, NULL, 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; - } +/* Print help and return error */ +static int PrintHelp(void) { + puts("dump_kernel_config - Prints the kernel command line\n" + "\n" + "Usage: dump_kernel_config [--kloadaddr <ADDRESS>] " + "<image/blockdevice>\n" + "\n" + ""); + return 1; +} - /* 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; - } +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; + int parse_error = 0; + char *e; + int i; - /* Read body_load_address from preamble if no kernel_body_load_address */ - if (kernel_body_load_address == CROS_NO_ENTRY_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; -} + while (((i = getopt_long(argc, argv, ":", long_opts, NULL)) != -1) && + !parse_error) { + switch (i) { + default: + case '?': + /* Unhandled option */ + parse_error = 1; + break; -void* MapFile(const char* filename, size_t *size) { - FILE* f; - uint8_t* buf; - long file_size = 0; + case 0: + /* silently handled option */ + break; - f = fopen(filename, "rb"); - if (!f) { - VBDEBUG(("Unable to open file %s\n", filename)); - return NULL; + case OPT_KLOADADDR: + kernel_body_load_address = strtoul(optarg, &e, 0); + if (!*optarg || (e && *e)) { + fprintf(stderr, "Invalid --kloadaddr\n"); + parse_error = 1; + } + break; + } } - fseek(f, 0, SEEK_END); - file_size = ftell(f); - rewind(f); + if (optind >= argc) { + fprintf(stderr, "Expected argument after options\n"); + parse_error = 1; + } else + infile = argv[optind]; + + if (parse_error) + return PrintHelp(); - if (file_size <= 0) { - fclose(f); - return NULL; + if (!infile || !*infile) { + VbExError("Must specify filename\n"); + return 1; } - *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; + + /* Map the kernel image blob. */ + blob = MapFile(infile, &blob_size); + if (!blob) { + VbExError("Error reading input file\n"); + return 1; + } + + config = find_kernel_config(blob, (uint64_t)blob_size, + kernel_body_load_address); + if (!config) { + VbExError("Error parsing input file\n"); + munmap(blob, blob_size); + return 1; } - fclose(f); - return buf; + printf("%.*s", CROS_CONFIG_SIZE, config); + munmap(blob, blob_size); + return 0; } diff --git a/utility/dump_kernel_config_lib.c b/utility/dump_kernel_config_lib.c new file mode 100644 index 00000000..a6989e1c --- /dev/null +++ b/utility/dump_kernel_config_lib.c @@ -0,0 +1,88 @@ +/* Copyright (c) 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 <sys/mman.h> + +#include "dump_kernel_config.h" +#include "host_common.h" +#include "kernel_blob.h" +#include "vboot_api.h" + +uint8_t* find_kernel_config(uint8_t* blob, uint64_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 == CROS_NO_ENTRY_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; +} + +void* MapFile(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; +} diff --git a/utility/dump_kernel_config_main.c b/utility/dump_kernel_config_main.c deleted file mode 100644 index 20a51871..00000000 --- a/utility/dump_kernel_config_main.c +++ /dev/null @@ -1,103 +0,0 @@ -/* Copyright (c) 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 <getopt.h> -#include <stdio.h> -#include <sys/mman.h> -#include <unistd.h> - -#include "dump_kernel_config.h" -#include "kernel_blob.h" -#include "vboot_api.h" - -enum { - OPT_KLOADADDR = 1000, -}; - -static struct option long_opts[] = { - { "kloadaddr", 1, NULL, OPT_KLOADADDR }, - { NULL, 0, NULL, 0 } -}; - -/* Print help and return error */ -static int PrintHelp(void) { - puts("dump_kernel_config - Prints the kernel command line\n" - "\n" - "Usage: dump_kernel_config [--kloadaddr <ADDRESS>] " - "<image/blockdevice>\n" - "\n" - ""); - return 1; -} - -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; - int parse_error = 0; - char *e; - int i; - - while (((i = getopt_long(argc, argv, ":", long_opts, NULL)) != -1) && - !parse_error) { - switch (i) { - default: - case '?': - /* Unhandled option */ - parse_error = 1; - break; - - case 0: - /* silently handled option */ - break; - - case OPT_KLOADADDR: - kernel_body_load_address = strtoul(optarg, &e, 0); - if (!*optarg || (e && *e)) { - fprintf(stderr, "Invalid --kloadaddr\n"); - parse_error = 1; - } - break; - } - } - - if (optind >= argc) { - fprintf(stderr, "Expected argument after options\n"); - parse_error = 1; - } else - infile = argv[optind]; - - if (parse_error) - return PrintHelp(); - - if (!infile || !*infile) { - VbExError("Must specify filename\n"); - return 1; - } - - /* Map the kernel image blob. */ - blob = MapFile(infile, &blob_size); - if (!blob) { - VbExError("Error reading input file\n"); - return 1; - } - - config = find_kernel_config(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", CROS_CONFIG_SIZE, config); - munmap(blob, blob_size); - return 0; -} diff --git a/utility/eficompress.c b/utility/eficompress.c index b5987006..dfa0d71f 100644 --- a/utility/eficompress.c +++ b/utility/eficompress.c @@ -1609,7 +1609,7 @@ Returns: } -#ifdef STANDALONE +#ifndef FOR_LIBRARY int main(int argc, char *argv[]) { char *progname; @@ -1729,4 +1729,4 @@ done1: return retval; } -#endif // STANDALONE +#endif // FOR_LIBRARY diff --git a/utility/efidecompress.c b/utility/efidecompress.c index 5e7e14d7..02587205 100644 --- a/utility/efidecompress.c +++ b/utility/efidecompress.c @@ -1008,7 +1008,7 @@ Returns: } -#ifdef STANDALONE +#ifndef FOR_LIBRARY int main(int argc, char *argv[]) { char *progname; @@ -1159,4 +1159,4 @@ done1: return retval; } -#endif // STANDALONE +#endif // FOR_LIBRARY diff --git a/utility/gbb_utility.cc b/utility/gbb_utility.cc index 544e1848..52135d01 100644 --- a/utility/gbb_utility.cc +++ b/utility/gbb_utility.cc @@ -475,7 +475,7 @@ bool GoogleBinaryBlockUtil::set_recovery_key(const string &value) { } // namespace vboot_reference -#ifdef WITH_UTIL_MAIN +#ifndef FOR_LIBRARY /////////////////////////////////////////////////////////////////////// // command line utilities @@ -870,4 +870,4 @@ int main(int argc, char *argv[]) { return 0; } -#endif // WITH_UTIL_MAIN +#endif // FOR_LIBRARY |