summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorAaron Durbin <adurbin@chromium.org>2016-05-04 16:07:15 -0500
committerAaron Durbin <adurbin@chromium.org>2016-05-06 16:49:01 +0200
commitab00d779ed323c1b58af687c1e2ad78536d3822f (patch)
tree6a7d94a88180eb36d41d516c57813a9e0387cece /util
parent6366d92803fdd43882592263f70ad83114359c64 (diff)
util/cbfstool: fix x86 execute-in-place semantics for all fmd regions
A previous patch [1] to make top-aligned addresses work within per fmap regions caused a significant regression in the semantics of adding programs that need to be execute-in-place (XIP) on x86 systems. Correct the regression by providing new function, convert_to_from_absolute_top_aligned(), which top aligns against the entire boot media. [1] 9731119b cbfstool: make top-aligned address work per-region Change-Id: I3b685abadcfc76dab8846eec21e9114a23577578 Signed-off-by: Aaron Durbin <adurbin@chromium.org> Reviewed-on: https://review.coreboot.org/14608 Tested-by: build bot (Jenkins) Reviewed-by: Duncan Laurie <dlaurie@google.com> Reviewed-by: Furquan Shaikh <furquan@google.com>
Diffstat (limited to 'util')
-rw-r--r--util/cbfstool/cbfstool.c32
1 files changed, 25 insertions, 7 deletions
diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c
index 1d1577f92d..b1b410f084 100644
--- a/util/cbfstool/cbfstool.c
+++ b/util/cbfstool/cbfstool.c
@@ -106,6 +106,21 @@ static bool region_is_modern_cbfs(const char *region)
/*
* Converts between offsets from the start of the specified image region and
+ * "top-aligned" offsets from the top of the entire boot media. See comment
+ * below for convert_to_from_top_aligned() about forming addresses.
+ */
+static unsigned convert_to_from_absolute_top_aligned(
+ const struct buffer *region, unsigned offset)
+{
+ assert(region);
+
+ size_t image_size = partitioned_file_total_size(param.image_file);
+
+ return image_size - region->offset - offset;
+}
+
+/*
+ * Converts between offsets from the start of the specified image region and
* "top-aligned" offsets from the top of the image region. Works in either
* direction: pass in one type of offset and receive the other type.
* N.B. A top-aligned offset is always a positive number, and should not be
@@ -123,8 +138,7 @@ static unsigned convert_to_from_top_aligned(const struct buffer *region,
return region->size - offset;
}
- size_t image_size = partitioned_file_total_size(param.image_file);
- return image_size - region->offset - offset;
+ return convert_to_from_absolute_top_aligned(region, offset);
}
static int do_cbfs_locate(int32_t *cbfs_addr, size_t metadata_size)
@@ -462,8 +476,8 @@ static int cbfstool_convert_fsp(struct buffer *buffer,
/* Ensure the address is a memory mapped one. */
if (!IS_TOP_ALIGNED_ADDRESS(address))
- address = -convert_to_from_top_aligned(param.image_region,
- address);
+ address = -convert_to_from_absolute_top_aligned(
+ param.image_region, address);
/* Create a copy of the buffer to attempt relocation. */
if (buffer_create(&fsp, buffer_size(buffer), "fsp"))
@@ -498,9 +512,13 @@ static int cbfstool_convert_mkstage(struct buffer *buffer, uint32_t *offset,
return 1;
}
- /* Pass in a top aligned address. */
- address = -convert_to_from_top_aligned(param.image_region,
- address);
+ /*
+ * Ensure the address is a memory mapped one. This assumes
+ * x86 semantics about th boot media being directly mapped
+ * below 4GiB in the CPU address space.
+ **/
+ address = -convert_to_from_absolute_top_aligned(
+ param.image_region, address);
*offset = address;
ret = parse_elf_to_xip_stage(buffer, &output, offset,