Files
OpenCellular/utility/dump_kernel_config.c
Che-Liang Chiou 036922ed8a Read kernel body load address from preamble by default
The default behavior of dump_kernel_config is changed from using
CROS_32BIT_ENTRY_ADDR to reading from kernel preamble.  The main
motivation for this change is in preparation for ARM boards of which
kernel body load address cannot be CROS_32BIT_ENTRY_ADDR.  Since we do
not want that all ARM calling sides of dump_kernel_config have to carry
the kloadaddr argument, it would be better to let dump_kernel_config
read this address from the kernel preamble by default.

BUG=chromium-os:28077
TEST=Run dump_kernel_config w/ and w/o this change

Change-Id: I5eddcc35e5970dfce02cc66208438c57351f1c81
Reviewed-on: https://gerrit.chromium.org/gerrit/19660
Tested-by: Che-Liang Chiou <clchiou@chromium.org>
Reviewed-by: Don Garrett <dgarrett@chromium.org>
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Commit-Ready: Che-Liang Chiou <clchiou@chromium.org>
2012-04-06 04:08:54 -07:00

90 lines
2.4 KiB
C

/* 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 "dump_kernel_config.h"
#include <stdio.h>
#include <sys/mman.h>
#include "host_common.h"
#include "kernel_blob.h"
uint8_t* find_kernel_config(uint8_t* blob, uint64_t blob_size,
uint64_t kernel_body_load_address) {
VbKeyBlockHeader* key_block;
VbKernelPreambleHeader* preamble;
struct linux_kernel_params *params;
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;
}