diff options
Diffstat (limited to 'util')
-rw-r--r-- | util/cbfstool/Makefile.inc | 10 | ||||
-rw-r--r-- | util/cbfstool/ProcessorBind.h | 103 | ||||
-rw-r--r-- | util/cbfstool/cbfstool.c | 46 |
3 files changed, 158 insertions, 1 deletions
diff --git a/util/cbfstool/Makefile.inc b/util/cbfstool/Makefile.inc index 32c9282113..bd9bbeb5c2 100644 --- a/util/cbfstool/Makefile.inc +++ b/util/cbfstool/Makefile.inc @@ -10,6 +10,7 @@ cbfsobj += rmodule.o cbfsobj += xdr.o cbfsobj += fit.o cbfsobj += partitioned_file.o +cbfsobj += fsp1_1_relocate.o # LZMA cbfsobj += lzma.o cbfsobj += LzFind.o @@ -59,6 +60,11 @@ TOOLCPPFLAGS += -I$(top)/src/commonlib/include TOOLCPPFLAGS += -DNEED_VB2_SHA_LIBRARY TOOLCPPFLAGS += -I$(top)/3rdparty/vboot/firmware/include TOOLCPPFLAGS += -I$(top)/3rdparty/vboot/firmware/2lib/include +# UEFI header file support. It's not pretty, but that's what we currently +# have right now. +TOOLCPPFLAGS += -I$(top)/src +TOOLCPPFLAGS += -I$(top)/src/vendorcode/intel/edk2/uefi_2.4/MdePkg/Include + TOOLLDFLAGS ?= HOSTCFLAGS += -fms-extensions @@ -90,6 +96,10 @@ $(objutil)/cbfstool/%.o: $(top)/3rdparty/vboot/firmware/2lib/%.c printf " HOSTCC $(subst $(objutil)/,,$(@))\n" $(HOSTCC) $(TOOLCPPFLAGS) $(TOOLCFLAGS) $(HOSTCFLAGS) -c -o $@ $< +$(objutil)/cbfstool/%.o: $(top)/src/commonlib/%.c + printf " HOSTCC $(subst $(objutil)/,,$(@))\n" + $(HOSTCC) $(TOOLCPPFLAGS) $(TOOLCFLAGS) $(HOSTCFLAGS) -c -o $@ $< + $(objutil)/cbfstool/cbfstool: $(addprefix $(objutil)/cbfstool/,$(cbfsobj)) printf " HOSTCC $(subst $(objutil)/,,$(@)) (link)\n" $(HOSTCC) $(TOOLLDFLAGS) -o $@ $(addprefix $(objutil)/cbfstool/,$(cbfsobj)) diff --git a/util/cbfstool/ProcessorBind.h b/util/cbfstool/ProcessorBind.h new file mode 100644 index 0000000000..68463fb3ed --- /dev/null +++ b/util/cbfstool/ProcessorBind.h @@ -0,0 +1,103 @@ +/** @file + Processor or Compiler specific defines and types for IA-32 architecture. + +Copyright 2015 Google Inc. +Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR> +This program and the accompanying materials are licensed and made available under +the terms and conditions of the BSD License that accompanies this distribution. +The full text of the license may be found at +http://opensource.org/licenses/bsd-license.php. + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#ifndef __PROCESSOR_BIND_H__ +#define __PROCESSOR_BIND_H__ + + +/* + * This to mimic a processor binding for EDK. This is just to provide the + * processor types. + */ +#include <inttypes.h> + +/// +/// Define the processor type so other code can make processor based choices. +/// +#define MDE_CPU_IA32 + +/// +/// 8-byte unsigned value. +/// +typedef uint64_t UINT64; +/// +/// 8-byte signed value. +/// +typedef int64_t INT64; +/// +/// 4-byte unsigned value. +/// +typedef uint32_t UINT32; +/// +/// 4-byte signed value. +/// +typedef int32_t INT32; +/// +/// 2-byte unsigned value. +/// +typedef uint16_t UINT16; +/// +/// 2-byte Character. Unless otherwise specified all strings are stored in the +/// UTF-16 encoding format as defined by Unicode 2.1 and ISO/IEC 10646 standards. +/// +typedef uint16_t CHAR16; +/// +/// 2-byte signed value. +/// +typedef int16_t INT16; +/// +/// Logical Boolean. 1-byte value containing 0 for FALSE or a 1 for TRUE. Other +/// values are undefined. +/// +typedef unsigned char BOOLEAN; +/// +/// 1-byte unsigned value. +/// +typedef unsigned char UINT8; +/// +/// 1-byte Character +/// +typedef char CHAR8; +/// +/// 1-byte signed value +/// +typedef signed char INT8; + +/// +/// Unsigned value of native width. (4 bytes on supported 32-bit processor instructions; +/// 8 bytes on supported 64-bit processor instructions.) +/// +typedef uintptr_t UINTN; +/// +/// Signed value of native width. (4 bytes on supported 32-bit processor instructions; +/// 8 bytes on supported 64-bit processor instructions.) +/// +typedef intptr_t INTN; + +// +// Processor specific defines +// + +/// +/// A value of native width with the highest bit set. +// Not needed for non-runtime, but it shouldb +/// +//#define MAX_BIT 0x80000000 + +// No API requirements as this is not for runtime. +#define EFIAPI + +#endif + diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c index 2876702cac..8048c834de 100644 --- a/util/cbfstool/cbfstool.c +++ b/util/cbfstool/cbfstool.c @@ -32,6 +32,7 @@ #include "cbfs_sections.h" #include "fit.h" #include "partitioned_file.h" +#include <commonlib/fsp1_1.h> #define SECTION_WITH_FIT_TABLE "BOOTBLOCK" @@ -387,6 +388,38 @@ static int cbfstool_convert_raw(struct buffer *buffer, return 0; } +static int cbfstool_convert_fsp(struct buffer *buffer, + uint32_t *offset, struct cbfs_file *header) +{ + uint32_t address; + struct buffer fsp; + + address = *offset; + + /* Ensure the address is a memory mapped one. */ + if (!IS_TOP_ALIGNED_ADDRESS(address)) + address = -convert_to_from_top_aligned(param.image_region, + address); + + /* Create a copy of the buffer to attempt relocation. */ + if (buffer_create(&fsp, buffer_size(buffer), "fsp")) + return -1; + + memcpy(buffer_get(&fsp), buffer_get(buffer), buffer_size(buffer)); + + /* Replace the buffer contents w/ the relocated ones on success. */ + if (fsp1_1_relocate(address, buffer_get(&fsp), buffer_size(&fsp)) > 0) { + buffer_delete(buffer); + buffer_clone(buffer, &fsp); + } else { + buffer_delete(&fsp); + WARN("FSP was not a 1.1 variant.\n"); + } + + /* Let the raw path handle all the cbfs metadata logic. */ + return cbfstool_convert_raw(buffer, offset, header); +} + static int cbfstool_convert_mkstage(struct buffer *buffer, uint32_t *offset, struct cbfs_file *header) { @@ -472,12 +505,23 @@ static int cbfstool_convert_mkflatpayload(struct buffer *buffer, static int cbfs_add(void) { int32_t address; + convert_buffer_t convert; if (param.alignment && param.baseaddress) { ERROR("Cannot specify both alignment and base address\n"); return 1; } + convert = cbfstool_convert_raw; + + /* Set the alignment to 4KiB minimum for FSP blobs when no base address + * is provided so that relocation can occur. */ + if (param.type == CBFS_COMPONENT_FSP) { + if (!param.baseaddress_assigned) + param.alignment = 4*1024; + convert = cbfstool_convert_fsp; + } + if (param.alignment) { /* CBFS compression file attribute is unconditionally added. */ size_t metadata_sz = sizeof(struct cbfs_file_attr_compression); @@ -491,7 +535,7 @@ static int cbfs_add(void) param.type, param.baseaddress, param.headeroffset, - cbfstool_convert_raw); + convert); } static int cbfs_add_stage(void) |