From 9731119b32ce4a5e0498cb20f47aad5069717c55 Mon Sep 17 00:00:00 2001 From: Patrick Georgi Date: Mon, 7 Dec 2015 23:14:07 +0100 Subject: 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 Reviewed-on: https://review.coreboot.org/12683 Reviewed-by: Aaron Durbin Tested-by: build bot (Jenkins) --- util/cbfstool/cbfstool.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'util') 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; } -- cgit v1.2.3