On 16.08.2010 23:57, Patrick Georgi wrote:
implement libpayload support and improve life for DOS based flashrom, too:
1.physmap-allow-NULL changes the physmap* behaviour to use -1 as error code instead of 0. That way, 1:1 mapped memory can be supported properly because 0 is not a magic number anymore. -1 on the other hand is a rather unlikely memory offset, so that should be safe.
Change physmap behaviour to use -1 instead of 0 as error code, to allow flashrom to work with 1:1 mappings
Signed-off-by: Patrick Georgi patrick.georgi@coresystems.de
I have changed the OSX code to treat NULL as error.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net Acked-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Index: flashrom-patrick_physmap_err_ptr/flash.h =================================================================== --- flashrom-patrick_physmap_err_ptr/flash.h (Revision 1180) +++ flashrom-patrick_physmap_err_ptr/flash.h (Arbeitskopie) @@ -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); Index: flashrom-patrick_physmap_err_ptr/cbtable.c =================================================================== --- flashrom-patrick_physmap_err_ptr/cbtable.c (Revision 1180) +++ flashrom-patrick_physmap_err_ptr/cbtable.c (Arbeitskopie) @@ -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; Index: flashrom-patrick_physmap_err_ptr/physmap.c =================================================================== --- flashrom-patrick_physmap_err_ptr/physmap.c (Revision 1180) +++ flashrom-patrick_physmap_err_ptr/physmap.c (Arbeitskopie) @@ -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);