Abstract mapping/unmapping of flash regions
Flash mapping/unmapping was performed without an abstraction layer,
so even the dummy flasher caused memory mappings to be set up. Add
map/unmap functions to the external flasher abstraction.
Fix a possible scribble-over-low-memory corner case which fortunately
never triggered so far.
With this patch, --programmer dummy works fine as non-root.
Corresponding to flashrom svn r493.
Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Acked-by: Uwe Hermann <uwe@hermann-uwe.de>
diff --git a/flashrom.c b/flashrom.c
index 981d835..e00789d 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -40,6 +40,8 @@
{
.init = internal_init,
.shutdown = internal_shutdown,
+ .map_flash_region = physmap,
+ .unmap_flash_region = physunmap,
.chip_readb = internal_chip_readb,
.chip_readw = internal_chip_readw,
.chip_readl = internal_chip_readl,
@@ -51,6 +53,8 @@
{
.init = dummy_init,
.shutdown = dummy_shutdown,
+ .map_flash_region = dummy_map,
+ .unmap_flash_region = dummy_unmap,
.chip_readb = dummy_chip_readb,
.chip_readw = dummy_chip_readw,
.chip_readl = dummy_chip_readl,
@@ -66,7 +70,7 @@
{
size_t size = flash->total_size * 1024;
/* Flash registers live 4 MByte below the flash. */
- flash->virtual_registers = physmap("flash chip registers", (0xFFFFFFFF - 0x400000 - size + 1), size);
+ flash->virtual_registers = programmer_map_flash_region("flash chip registers", (0xFFFFFFFF - 0x400000 - size + 1), size);
}
int read_memmapped(struct flashchip *flash, uint8_t *buf)
@@ -98,23 +102,8 @@
size = flash->total_size * 1024;
- /* If getpagesize() > size ->
- * "Can't mmap memory using /dev/mem: Invalid argument"
- * This should never happen as we don't support any flash chips
- * smaller than 4k or 8k (yet).
- */
-
- if (getpagesize() > size) {
- /*
- * if a flash size of 0 is mapped, we map a single page
- * so we can probe in that area whether we know the
- * vendor at least.
- */
- size = getpagesize();
- }
-
base = flashbase ? flashbase : (0xffffffff - size + 1);
- flash->virtual_memory = physmap("flash chip", base, size);
+ flash->virtual_memory = programmer_map_flash_region("flash chip", base, size);
if (force)
break;
@@ -127,7 +116,8 @@
break;
notfound:
- physunmap((void *)flash->virtual_memory, size);
+ /* The intermediate cast to unsigned long works around a gcc warning bug. */
+ programmer_unmap_flash_region((void *)(unsigned long)flash->virtual_memory, size);
}
if (!flash || !flash->name)