flashrom: Check all mmap() calls and print helpful Linux error message.
authorPeter Stuge <peter@stuge.se>
Fri, 23 Jan 2009 05:23:06 +0000 (05:23 +0000)
committerPeter Stuge <peter@stuge.se>
Fri, 23 Jan 2009 05:23:06 +0000 (05:23 +0000)
Signed-off-by: Peter Stuge <peter@stuge.se>
Acked-by: Peter Stuge <peter@stuge.se>
git-svn-id: svn://svn.coreboot.org/coreboot/trunk@3890 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1

util/flashrom/cbtable.c
util/flashrom/chipset_enable.c
util/flashrom/flash.h
util/flashrom/flashrom.c

index cc3a73c329deb8ebb903f8944ae180aee5f00035..e4ae0f9d5cbd3371d9b5ff82aff66606c2344b8c 100644 (file)
@@ -191,6 +191,7 @@ int coreboot_init(void)
                       0x00000000);
        if (low_1MB == MAP_FAILED) {
                perror("Can't mmap memory using " MEM_DEV);
+               mmap_errmsg();
                exit(-2);
        }
        lb_table = 0;
index 52d154961ede10be3affa3101e3f6ad0f19269a3..d7eb7fa13df7988ae88d636eaa5e59d332173828 100644 (file)
@@ -220,6 +220,7 @@ static int enable_flash_vt8237s_spi(struct pci_dev *dev, const char *name)
 
        if (spibar == MAP_FAILED) {
                perror("Can't mmap memory using " MEM_DEV);
+               mmap_errmsg();
                exit(1);
        }
 
@@ -255,6 +256,7 @@ static int enable_flash_ich_dc_spi(struct pci_dev *dev, const char *name,
                    (off_t) tmp);
        if (rcrb == MAP_FAILED) {
                perror("Can't mmap memory using " MEM_DEV);
+               mmap_errmsg();
                exit(1);
        }
 
@@ -681,6 +683,7 @@ static int enable_flash_sb600(struct pci_dev *dev, const char *name)
                            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 @@ static int get_flashbase_sc520(struct pci_dev *dev, const char *name)
 
        if (mmcr == MAP_FAILED) {
                perror("Can't mmap Elan SC520 specific registers using " MEM_DEV);
+               mmap_errmsg();
                exit(1);
        }
 
index 282a44d8c78eb3beee67a856ef6a6838f9f02a92..3d86836a5ab3c4b2541bf4ea3f2e28175341e9a8 100644 (file)
@@ -480,6 +480,7 @@ extern int verbose;
 #define printf_debug(x...) { if (verbose) printf(x); }
 
 /* flashrom.c */
+void mmap_errmsg();
 int map_flash_registers(struct flashchip *flash);
 
 /* layout.c */
index 7e52fbc8dc6b9d4072588fec6fed9d73249a432b..26585fb72e25340eaba22bec8e8e231e4fea32d1 100644 (file)
@@ -84,6 +84,17 @@ struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
        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 @@ int map_flash_registers(struct flashchip *flash)
 
        if (registers == MAP_FAILED) {
                perror("Can't mmap registers using " MEM_DEV);
+               mmap_errmsg();
                exit(1);
        }
        flash->virtual_registers = registers;
@@ -139,13 +151,7 @@ struct flashchip *probe_flash(struct flashchip *first_flash, int force)
                            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;