Author: stuge Date: 2009-01-23 06:23:06 +0100 (Fri, 23 Jan 2009) New Revision: 3890
Modified: trunk/util/flashrom/cbtable.c trunk/util/flashrom/chipset_enable.c trunk/util/flashrom/flash.h trunk/util/flashrom/flashrom.c Log: flashrom: Check all mmap() calls and print helpful Linux error message.
Signed-off-by: Peter Stuge peter@stuge.se Acked-by: Peter Stuge peter@stuge.se
Modified: trunk/util/flashrom/cbtable.c =================================================================== --- trunk/util/flashrom/cbtable.c 2009-01-22 22:53:59 UTC (rev 3889) +++ trunk/util/flashrom/cbtable.c 2009-01-23 05:23:06 UTC (rev 3890) @@ -191,6 +191,7 @@ 0x00000000); if (low_1MB == MAP_FAILED) { perror("Can't mmap memory using " MEM_DEV); + mmap_errmsg(); exit(-2); } lb_table = 0;
Modified: trunk/util/flashrom/chipset_enable.c =================================================================== --- trunk/util/flashrom/chipset_enable.c 2009-01-22 22:53:59 UTC (rev 3889) +++ trunk/util/flashrom/chipset_enable.c 2009-01-23 05:23:06 UTC (rev 3890) @@ -220,6 +220,7 @@
if (spibar == MAP_FAILED) { perror("Can't mmap memory using " MEM_DEV); + mmap_errmsg(); exit(1); }
@@ -255,6 +256,7 @@ (off_t) tmp); if (rcrb == MAP_FAILED) { perror("Can't mmap memory using " MEM_DEV); + mmap_errmsg(); exit(1); }
@@ -681,6 +683,7 @@ fd_mem, (off_t)tmp); if (sb600_spibar == MAP_FAILED) { perror("Can't mmap memory using " MEM_DEV); + mmap_errmsg(); exit(1); } sb600_spibar += low_bits; @@ -837,6 +840,7 @@
if (mmcr == MAP_FAILED) { perror("Can't mmap Elan SC520 specific registers using " MEM_DEV); + mmap_errmsg(); exit(1); }
Modified: trunk/util/flashrom/flash.h =================================================================== --- trunk/util/flashrom/flash.h 2009-01-22 22:53:59 UTC (rev 3889) +++ trunk/util/flashrom/flash.h 2009-01-23 05:23:06 UTC (rev 3890) @@ -480,6 +480,7 @@ #define printf_debug(x...) { if (verbose) printf(x); }
/* flashrom.c */ +void mmap_errmsg(); int map_flash_registers(struct flashchip *flash);
/* layout.c */
Modified: trunk/util/flashrom/flashrom.c =================================================================== --- trunk/util/flashrom/flashrom.c 2009-01-22 22:53:59 UTC (rev 3889) +++ trunk/util/flashrom/flashrom.c 2009-01-23 05:23:06 UTC (rev 3890) @@ -84,6 +84,17 @@ return NULL; }
+void mmap_errmsg() +{ + if (EINVAL == errno) { + fprintf(stderr, "In Linux this error can be caused by the CONFIG_NONPROMISC_DEVMEM (<2.6.27),\n"); + fprintf(stderr, "CONFIG_STRICT_DEVMEM (>=2.6.27) and CONFIG_X86_PAT kernel options.\n"); + fprintf(stderr, "Please check if either is enabled in your kernel before reporting a failure.\n"); + fprintf(stderr, "You can override CONFIG_X86_PAT at boot with the nopat kernel parameter but\n"); + fprintf(stderr, "disabling the other option unfortunately requires a kernel recompile. Sorry!\n"); + } +} + int map_flash_registers(struct flashchip *flash) { volatile uint8_t *registers; @@ -94,6 +105,7 @@
if (registers == MAP_FAILED) { perror("Can't mmap registers using " MEM_DEV); + mmap_errmsg(); exit(1); } flash->virtual_registers = registers; @@ -139,13 +151,7 @@ fd_mem, (off_t) base); if (bios == MAP_FAILED) { perror("Can't mmap memory using " MEM_DEV); - if (EINVAL == errno) { - fprintf(stderr, "In Linux this error can be caused by the CONFIG_NONPROMISC_DEVMEM (<2.6.27),\n"); - fprintf(stderr, "CONFIG_STRICT_DEVMEM (>=2.6.27) and CONFIG_X86_PAT kernel options.\n"); - fprintf(stderr, "Please check if either is enabled in your kernel before reporting a failure.\n"); - fprintf(stderr, "You can override CONFIG_X86_PAT at boot with the nopat kernel parameter but\n"); - fprintf(stderr, "disabling the other option unfortunately requires a kernel recompile. Sorry!\n"); - } + mmap_errmsg(); exit(1); } flash->virtual_memory = bios;