summaryrefslogtreecommitdiffstats
path: root/layout.c
diff options
context:
space:
mode:
authorStefan Tauner <stefan.tauner@alumni.tuwien.ac.at>2013-09-23 14:21:06 +0000
committerStefan Tauner <stefan.tauner@alumni.tuwien.ac.at>2013-09-23 14:21:06 +0000
commit8268fdb90227af0293d2fbfcf92f971af44cb001 (patch)
tree4a5f50d844a729a5806abfed35e79169ca9fd6d2 /layout.c
parenta6a0d2000a1197e90faaf8d9e7697c96f1deb934 (diff)
downloadast2050-flashrom-8268fdb90227af0293d2fbfcf92f971af44cb001.zip
ast2050-flashrom-8268fdb90227af0293d2fbfcf92f971af44cb001.tar.gz
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 <stefan.tauner@alumni.tuwien.ac.at> Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Diffstat (limited to 'layout.c')
-rw-r--r--layout.c32
1 files changed, 28 insertions, 4 deletions
diff --git a/layout.c b/layout.c
index 86351b8..08cc776 100644
--- a/layout.c
+++ b/layout.c
@@ -29,15 +29,15 @@
#define MAX_ROMLAYOUT 32
typedef struct {
- unsigned int start;
- unsigned int end;
+ chipoff_t start;
+ chipoff_t end;
unsigned int included;
char name[256];
} romentry_t;
/* rom_entries store the entries specified in a layout file and associated run-time data */
static romentry_t rom_entries[MAX_ROMLAYOUT];
-static int num_rom_entries = 0; /* the number of valid rom_entries */
+static int num_rom_entries = 0; /* the number of successfully parsed rom_entries */
/* include_args holds the arguments specified at the command line with -i. They must be processed at some point
* so that desired regions are marked as "included" in the rom_entries list. */
@@ -232,7 +232,31 @@ romentry_t *get_next_included_romentry(unsigned int start)
return best_entry;
}
-int handle_romentries(const struct flashctx *flash, uint8_t *oldcontents, uint8_t *newcontents)
+/* Validate and - if needed - normalize layout entries. */
+int normalize_romentries(const struct flashctx *flash)
+{
+ chipsize_t total_size = flash->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;
OpenPOWER on IntegriCloud