aboutsummaryrefslogtreecommitdiff
path: root/util/cbfstool/cbfstool.c
diff options
context:
space:
mode:
authorAaron Durbin <adurbin@chromium.org>2015-10-01 17:02:45 -0500
committerAaron Durbin <adurbin@chromium.org>2015-10-02 12:17:21 +0000
commit8a414a0943931bcedcfcbc5159d9a4b7e52a432f (patch)
tree0f48073f7c95de36d2f70a5a5a4dea96213c56cc /util/cbfstool/cbfstool.c
parent3c96e808f0bbe2957fc26bdc5e04900a8c5af58c (diff)
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@chromium.org> Reviewed-on: http://review.coreboot.org/11778 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
Diffstat (limited to 'util/cbfstool/cbfstool.c')
-rw-r--r--util/cbfstool/cbfstool.c46
1 files changed, 45 insertions, 1 deletions
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)