Author: hailfinger
Date: Sun Sep 26 00:53:44 2010
New Revision: 1181
URL: http://flashrom.org/trac/flashrom/changeset/1181

Log:
Implement libpayload support and improve life for DOS
based flashrom, too:

Change the physmap* behaviour to use (void*)-1 as error code instead
of NULL. That way, 1:1 mapped memory can be supported properly
because (void*)0 is not a magic pointer anymore.
(void*)-1 on the other hand is a rather unlikely memory offset, so that
should be safe.
  
Signed-off-by: Patrick Georgi <[email protected]>
Signed-off-by: Carl-Daniel Hailfinger <[email protected]>
Acked-by: Carl-Daniel Hailfinger <[email protected]>

Modified:
   trunk/cbtable.c
   trunk/flash.h
   trunk/physmap.c

Modified: trunk/cbtable.c
==============================================================================
--- trunk/cbtable.c     Mon Sep 20 19:23:38 2010        (r1180)
+++ trunk/cbtable.c     Sun Sep 26 00:53:44 2010        (r1181)
@@ -212,7 +212,7 @@
        start = 0x0;
 #endif
        table_area = physmap_try_ro("low megabyte", start, BYTES_TO_MAP - 
start);
-       if (!table_area) {
+       if (ERROR_PTR == table_area) {
                msg_perr("Failed getting access to coreboot low tables.\n");
                return -1;
        }
@@ -228,7 +228,7 @@
                        start &= ~(getpagesize() - 1);
                        physunmap(table_area, BYTES_TO_MAP);
                        table_area = physmap_try_ro("high tables", start, 
BYTES_TO_MAP);
-                       if (!table_area) {
+                       if (ERROR_PTR == table_area) {
                                msg_perr("Failed getting access to coreboot "
                                         "high tables.\n");
                                return -1;

Modified: trunk/flash.h
==============================================================================
--- trunk/flash.h       Mon Sep 20 19:23:38 2010        (r1180)
+++ trunk/flash.h       Sun Sep 26 00:53:44 2010        (r1181)
@@ -33,6 +33,8 @@
 #undef max
 #endif
 
+#define ERROR_PTR ((void*)-1)
+
 typedef unsigned long chipaddr;
 
 int register_shutdown(void (*function) (void *data), void *data);

Modified: trunk/physmap.c
==============================================================================
--- trunk/physmap.c     Mon Sep 20 19:23:38 2010        (r1180)
+++ trunk/physmap.c     Sun Sep 26 00:53:44 2010        (r1181)
@@ -52,11 +52,11 @@
        realmem_map = valloc(1024 * 1024);
 
        if (!realmem_map) {
-               return NULL;
+               return ERROR_PTR;
        }
 
        if (__djgpp_map_physical_memory(realmem_map, (1024 * 1024), 0)) {
-               return NULL;
+               return ERROR_PTR;
        }
 
        return realmem_map + phys_addr;
@@ -69,7 +69,7 @@
 
        /* enable 4GB limit on DS descriptor */
        if (!__djgpp_nearptr_enable()) {
-               return NULL;
+               return ERROR_PTR;
        }
 
        if ((phys_addr + len - 1) < (1024 * 1024)) {
@@ -82,7 +82,7 @@
        ret =  __dpmi_physical_address_mapping (&mi);
 
        if (ret != 0) {
-               return NULL;
+               return ERROR_PTR;
        }
 
        return (void *) mi.address + __djgpp_conventional_base;
@@ -112,7 +112,12 @@
 
 static void *sys_physmap(unsigned long phys_addr, size_t len)
 {
-       return map_physical(phys_addr, len);
+       /* The short form of ?: is a GNU extension.
+        * FIXME: map_physical returns NULL both for errors and for success
+        * if the region is mapped at virtual address zero. If in doubt, report
+        * an error until a better interface exists.
+        */
+       return map_physical(phys_addr, len) ? : ERROR_PTR;
 }
 
 /* The OS X driver does not differentiate between mapping types. */
@@ -151,7 +156,7 @@
 
        virt_addr = mmap(0, len, PROT_WRITE | PROT_READ, MAP_SHARED,
                         fd_mem, (off_t)phys_addr);
-       return MAP_FAILED == virt_addr ? NULL : virt_addr;
+       return MAP_FAILED == virt_addr ? ERROR_PTR : virt_addr;
 }
 
 /* For reading DMI/coreboot/whatever tables. We should never write, and we
@@ -171,7 +176,7 @@
 
        virt_addr = mmap(0, len, PROT_READ, MAP_SHARED,
                         fd_mem_cached, (off_t)phys_addr);
-       return MAP_FAILED == virt_addr ? NULL : virt_addr;
+       return MAP_FAILED == virt_addr ? ERROR_PTR : virt_addr;
 }
 
 void physunmap(void *virt_addr, size_t len)
@@ -197,7 +202,7 @@
        if (len == 0) {
                msg_pspew("Not mapping %s, zero size at 0x%08lx.\n",
                             descr, phys_addr);
-               return NULL;
+               return ERROR_PTR;
        }
                
        if ((getpagesize() - 1) & len) {
@@ -216,7 +221,7 @@
                virt_addr = sys_physmap_rw_uncached(phys_addr, len);
        }
 
-       if (NULL == virt_addr) {
+       if (ERROR_PTR == virt_addr) {
                if (NULL == descr)
                        descr = "memory";
                msg_perr("Error accessing %s, 0x%lx bytes at 0x%08lx\n", descr, 
(unsigned long)len, phys_addr);

_______________________________________________
flashrom mailing list
[email protected]
http://www.flashrom.org/mailman/listinfo/flashrom

Reply via email to