summaryrefslogtreecommitdiffstats
path: root/flashrom.c
diff options
context:
space:
mode:
authorSegher Boessenkool <segher@kernel.crashing.org>2008-08-12 11:58:00 +0000
committerSegher Boessenkool <segher@kernel.crashing.org>2008-08-12 11:58:00 +0000
commit0d29b60641438d4383eec5410a31c3acaa9f807a (patch)
tree35cdb3595d9b3499d5840583db844e9665f12e1b /flashrom.c
parentbff9bf24c77e5536539ea5bf86cf665bc471e680 (diff)
downloadast2050-flashrom-0d29b60641438d4383eec5410a31c3acaa9f807a.zip
ast2050-flashrom-0d29b60641438d4383eec5410a31c3acaa9f807a.tar.gz
Fix error -EINVAL on mmap()
Don't calculate "flash_baseaddr" until the final value of "size" is known, otherwise we end up trying to map a page right after the end of memory. Fixes #112. Corresponding to flashrom svn r308 and coreboot v2 svn r3502. Signed-off-by: Segher Boessenkool <segher@kernel.crashing.org> Acked-by: Stefan Reinauer <stepan@coresystems.de>
Diffstat (limited to 'flashrom.c')
-rw-r--r--flashrom.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/flashrom.c b/flashrom.c
index 4fd509c..03a8eeb 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -116,14 +116,6 @@ struct flashchip *probe_flash(struct flashchip *flash, int force)
size = flash->total_size * 1024;
-#ifdef TS5300
- // FIXME: Wrong place for this decision
- // FIXME: This should be autodetected. It is trivial.
- flash_baseaddr = 0x9400000;
-#else
- flash_baseaddr = (0xffffffff - size + 1);
-#endif
-
/* If getpagesize() > size ->
* "Can't mmap memory using /dev/mem: Invalid argument"
* This should never happen as we don't support any flash chips
@@ -139,6 +131,14 @@ struct flashchip *probe_flash(struct flashchip *flash, int force)
size = getpagesize();
}
+#ifdef TS5300
+ // FIXME: Wrong place for this decision
+ // FIXME: This should be autodetected. It is trivial.
+ flash_baseaddr = 0x9400000;
+#else
+ flash_baseaddr = (0xffffffff - size + 1);
+#endif
+
bios = mmap(0, size, PROT_WRITE | PROT_READ, MAP_SHARED,
fd_mem, (off_t) flash_baseaddr);
if (bios == MAP_FAILED) {
OpenPOWER on IntegriCloud