diff options
author | Patrick Georgi <pgeorgi@chromium.org> | 2015-12-07 23:14:07 +0100 |
---|---|---|
committer | Patrick Georgi <pgeorgi@google.com> | 2015-12-09 00:21:56 +0100 |
commit | 9731119b32ce4a5e0498cb20f47aad5069717c55 (patch) | |
tree | 01dee3ded9e29a1a87616ee4d1fd8c27676dc7c5 /util/cbfstool | |
parent | 72c83a8e231cd4fbc5b9fcec53e4b7b26ce4f144 (diff) |
cbfstool: make top-aligned address work per-region
The former interpretation sprung from the x86 way of doing things
(assuming top-alignment to 4GB). Extend the mechanism to work with CBFS
regions residing elsewhere.
It's compatible with x86 because the default region there resides at the
old location, so things fall in place. It also makes more complex
layouts and non-x86 layouts work with negative base addresses.
Change-Id: Ibcde973d85bad5d1195d657559f527695478f46c
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Reviewed-on: https://review.coreboot.org/12683
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Tested-by: build bot (Jenkins)
Diffstat (limited to 'util/cbfstool')
-rw-r--r-- | util/cbfstool/cbfstool.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c index 7f05f71b88..252929628f 100644 --- a/util/cbfstool/cbfstool.c +++ b/util/cbfstool/cbfstool.c @@ -101,7 +101,7 @@ 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 flash image. Works in either + * "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 * confused with a top-aliged *address*, which is its arithmetic inverse. */ @@ -110,6 +110,14 @@ static unsigned convert_to_from_top_aligned(const struct buffer *region, { assert(region); + /* cover the situation where a negative base address is given by the + * user. Callers of this function negate it, so it'll be a positive + * number smaller than the region. + */ + if ((offset > 0) && (offset < region->size)) { + return region->size - offset; + } + size_t image_size = partitioned_file_total_size(param.image_file); return image_size - region->offset - offset; } |