[coreboot-gerrit] New patch to review for coreboot: cbfstool: relocate FSP blobs on cbfstool add

Aaron Durbin (adurbin@chromium.org) gerrit at coreboot.org
Thu Oct 1 22:58:46 CET 2015


Aaron Durbin (adurbin at chromium.org) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/11778

-gerrit

commit 393bdd983a0c7f4732f81216aefbcc2e96c32b71
Author: Aaron Durbin <adurbin at chromium.org>
Date:   Thu Oct 1 17:02:45 2015 -0500

    cbfstool: relocate FSP blobs on cbfstool add
    
    When adding an FSP blob relocate it to its final
    destination. This allows FSP to not be hard coded in
    the cbfs. In order for the include paths to work
    correctly w/ the edk 2 headers we need to supply
    a neutered ProcessorBind.h to match up with the
    tool environment such that one can get the UEFI
    Platform Initialization type definitions.
    
    BUG=chrome-os-partner:44827
    BRANCH=None
    TEST=Built glados and booted. Also added FSP with -b and manually
         adjusted location in fsp cache-as-ram. Booted as well.
    
    Change-Id: I830d93578fdf745a51195109cf18d94a83ee8cd3
    Signed-off-by: Aaron Durbin <adurbin at chromium.org>
---
 util/cbfstool/Makefile.inc    |  10 ++++
 util/cbfstool/ProcessorBind.h | 103 ++++++++++++++++++++++++++++++++++++++++++
 util/cbfstool/cbfstool.c      |  46 ++++++++++++++++++-
 3 files changed, 158 insertions(+), 1 deletion(-)

diff --git a/util/cbfstool/Makefile.inc b/util/cbfstool/Makefile.inc
index 4994757..093636a 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 ?=
 
 ifeq ($(shell uname -s | cut -c-7 2>/dev/null), MINGW32)
@@ -89,6 +95,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 0000000..68463fb
--- /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 2876702..8048c83 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)



More information about the coreboot-gerrit mailing list