ifdfake: allow "base+size" description of regions
This is more in line with how fmd/fmap specify ranges. Change-Id: Iecf8250e84d6eb267711ded446909b21147f1a9c Signed-off-by: Patrick Georgi <pgeorgi@chromium.org> Reviewed-on: http://review.coreboot.org/11623 Tested-by: build bot (Jenkins) Reviewed-by: Aaron Durbin <adurbin@chromium.org>
This commit is contained in:
parent
239c74231b
commit
a9992d3da5
|
@ -91,24 +91,39 @@ static void write_image(const region_t regions[], const char *const image)
|
|||
static int parse_region(const char *_arg, region_t *const region)
|
||||
{
|
||||
char *const start = strdup(_arg);
|
||||
int size_spec = 0;
|
||||
unsigned long first, second;
|
||||
if (!start) {
|
||||
fprintf(stderr, "Out of memory.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
char *const colon = strchr(start, ':');
|
||||
char *colon = strchr(start, ':');
|
||||
if (!colon) {
|
||||
colon = strchr(start, '+');
|
||||
if (!colon) {
|
||||
free(start);
|
||||
return -1;
|
||||
}
|
||||
size_spec = 1;
|
||||
}
|
||||
*colon = '\0';
|
||||
|
||||
char *const end = colon + 1;
|
||||
|
||||
errno = 0;
|
||||
region->base = strtoul(start, NULL, 0);
|
||||
region->limit = strtoul(end, NULL, 0);
|
||||
first = strtoul(start, NULL, 0);
|
||||
second = strtoul(end, NULL, 0);
|
||||
|
||||
if (size_spec) {
|
||||
region->base = first;
|
||||
region->size = second;
|
||||
region->limit = region->base + region->size - 1;
|
||||
} else {
|
||||
region->base = first;
|
||||
region->limit = second;
|
||||
region->size = region->limit - region->base + 1;
|
||||
}
|
||||
|
||||
free(start);
|
||||
if (errno) {
|
||||
|
|
Loading…
Reference in New Issue