1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-29 07:53:44 +02:00

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>
This commit is contained in:
Segher Boessenkool 2008-08-12 11:58:00 +00:00
parent bff9bf24c7
commit 0d29b60641

View File

@ -116,14 +116,6 @@ struct flashchip *probe_flash(struct flashchip *flash, int force)
size = flash->total_size * 1024; 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 -> /* If getpagesize() > size ->
* "Can't mmap memory using /dev/mem: Invalid argument" * "Can't mmap memory using /dev/mem: Invalid argument"
* This should never happen as we don't support any flash chips * 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(); 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, bios = mmap(0, size, PROT_WRITE | PROT_READ, MAP_SHARED,
fd_mem, (off_t) flash_baseaddr); fd_mem, (off_t) flash_baseaddr);
if (bios == MAP_FAILED) { if (bios == MAP_FAILED) {