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>
Index: flashrom-patches/cbtable.c
===================================================================
--- flashrom-patches.orig/cbtable.c	2010-08-16 20:28:49.000000000 +0200
+++ flashrom-patches/cbtable.c	2010-08-16 20:32:32.048812200 +0200
@@ -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-patches/flash.h
===================================================================
--- flashrom-patches.orig/flash.h	2010-08-16 20:28:49.000000000 +0200
+++ flashrom-patches/flash.h	2010-08-16 20:44:59.316553500 +0200
@@ -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-patches/physmap.c
===================================================================
--- flashrom-patches.orig/physmap.c	2010-08-16 20:28:49.000000000 +0200
+++ flashrom-patches/physmap.c	2010-08-16 20:44:49.284978600 +0200
@@ -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;
@@ -151,7 +151,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 +171,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 +197,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 +216,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);
