From 8268fdb90227af0293d2fbfcf92f971af44cb001 Mon Sep 17 00:00:00 2001 From: Stefan Tauner Date: Mon, 23 Sep 2013 14:21:06 +0000 Subject: layout: Verify layout entries before building a new image using them This fixes a SEGFAULT if a layout entry is included that addresses memory outside the current chip's address range. flashrom will only abort if the offending region(s) is/are included else it will just warn. It will print warnings for regions with negative or zero-length address ranges and bail out after checking all of them. Also, abort for non-write operations if a layout file is given because there is no layout support for other operations yet. Corresponding to flashrom svn r1751. Signed-off-by: Stefan Tauner Acked-by: Carl-Daniel Hailfinger --- cli_classic.c | 6 ++++++ flash.h | 11 ++++++++++- flashrom.c | 11 ++++++++--- layout.c | 32 ++++++++++++++++++++++++++++---- 4 files changed, 52 insertions(+), 8 deletions(-) diff --git a/cli_classic.c b/cli_classic.c index 70bccb5..a0c2d64 100644 --- a/cli_classic.c +++ b/cli_classic.c @@ -370,6 +370,12 @@ int main(int argc, char *argv[]) ret = 1; goto out; } + if (layoutfile != NULL && !write_it) { + msg_gerr("Layout files are currently supported for write operations only.\n"); + ret = 1; + goto out; + } + if (process_include_args()) { ret = 1; goto out; diff --git a/flash.h b/flash.h index 7b88477..e320ced 100644 --- a/flash.h +++ b/flash.h @@ -45,6 +45,14 @@ typedef uintptr_t chipaddr; #define PRIxPTR_WIDTH ((int)(sizeof(uintptr_t)*2)) +/* Types and macros regarding the maximum flash space size supported by generic code. */ +typedef uint32_t chipoff_t; /* Able to store any addressable offset within a supported flash memory. */ +typedef uint32_t chipsize_t; /* Able to store the number of bytes of any supported flash memory. */ +#define FL_MAX_CHIPADDR_BITS (24) +#define FL_MAX_CHIPADDR ((chipoff_t)(1ULL<chip->total_size * 1024; + int ret = 0; + + int i; + for (i = 0; i < num_rom_entries; i++) { + if (rom_entries[i].start >= total_size || rom_entries[i].end >= total_size) { + msg_gwarn("Warning: Address range of region \"%s\" exceeds the current chip's " + "address space.\n", rom_entries[i].name); + if (rom_entries[i].included) + ret = 1; + } + if (rom_entries[i].start > rom_entries[i].end) { + msg_gerr("Error: Size of the address range of region \"%s\" is not positive.\n", + rom_entries[i].name); + ret = 1; + } + } + + return ret; +} + +int build_new_image(const struct flashctx *flash, uint8_t *oldcontents, uint8_t *newcontents) { unsigned int start = 0; romentry_t *entry; -- cgit v1.1