Introduce a type "chipaddr" to abstract the offsets within flash regions

Use chipaddr instead of volatile uint8_t * because when we access chips
in external flashers, they are not accessed via pointers at all.

Benefits: This allows us to differentiate between volatile machine
memory accesses and flash chip accesses. It also enforces usage
of chip_{read,write}[bwl] to access flash chips, so nobody will
unintentionally use pointers to access chips anymore. Some unneeded
casts are removed as well. Grepping for chip operations and machine
memory operations doesn't yield any false positives anymore.

Compile tested on 32 bit and 64 bit Linux.

Corresponding to flashrom svn r519.

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Acked-by: Uwe Hermann <uwe@hermann-uwe.de>
diff --git a/jedec.c b/jedec.c
index b2ab519..ce7679e 100644
--- a/jedec.c
+++ b/jedec.c
@@ -35,7 +35,7 @@
 	return (val ^ (val >> 1)) & 0x1;
 }
 
-void toggle_ready_jedec(volatile uint8_t *dst)
+void toggle_ready_jedec(chipaddr dst)
 {
 	unsigned int i = 0;
 	uint8_t tmp1, tmp2;
@@ -51,7 +51,7 @@
 	}
 }
 
-void data_polling_jedec(volatile uint8_t *dst, uint8_t data)
+void data_polling_jedec(chipaddr dst, uint8_t data)
 {
 	unsigned int i = 0;
 	uint8_t tmp;
@@ -66,7 +66,7 @@
 	}
 }
 
-void unprotect_jedec(volatile uint8_t *bios)
+void unprotect_jedec(chipaddr bios)
 {
 	chip_writeb(0xAA, bios + 0x5555);
 	chip_writeb(0x55, bios + 0x2AAA);
@@ -78,7 +78,7 @@
 	usleep(200);
 }
 
-void protect_jedec(volatile uint8_t *bios)
+void protect_jedec(chipaddr bios)
 {
 	chip_writeb(0xAA, bios + 0x5555);
 	chip_writeb(0x55, bios + 0x2AAA);
@@ -89,7 +89,7 @@
 
 int probe_jedec(struct flashchip *flash)
 {
-	volatile uint8_t *bios = flash->virtual_memory;
+	chipaddr bios = flash->virtual_memory;
 	uint8_t id1, id2;
 	uint32_t largeid1, largeid2;
 	uint32_t flashcontent1, flashcontent2;
@@ -161,7 +161,7 @@
 	return 0;
 }
 
-int erase_sector_jedec(volatile uint8_t *bios, unsigned int page)
+int erase_sector_jedec(chipaddr bios, unsigned int page)
 {
 	/*  Issue the Sector Erase command   */
 	chip_writeb(0xAA, bios + 0x5555);
@@ -184,7 +184,7 @@
 	return 0;
 }
 
-int erase_block_jedec(volatile uint8_t *bios, unsigned int block)
+int erase_block_jedec(chipaddr bios, unsigned int block)
 {
 	/*  Issue the Sector Erase command   */
 	chip_writeb(0xAA, bios + 0x5555);
@@ -209,7 +209,7 @@
 
 int erase_chip_jedec(struct flashchip *flash)
 {
-	volatile uint8_t *bios = flash->virtual_memory;
+	chipaddr bios = flash->virtual_memory;
 
 	/*  Issue the JEDEC Chip Erase command   */
 	chip_writeb(0xAA, bios + 0x5555);
@@ -231,11 +231,11 @@
 	return 0;
 }
 
-int write_page_write_jedec(volatile uint8_t *bios, uint8_t *src,
-			   volatile uint8_t *dst, int page_size)
+int write_page_write_jedec(chipaddr bios, uint8_t *src,
+			   chipaddr dst, int page_size)
 {
 	int i, tried = 0, start_index = 0, ok;
-	volatile uint8_t *d = dst;
+	chipaddr d = dst;
 	uint8_t *s = src;
 
 retry:
@@ -272,14 +272,14 @@
 		goto retry;
 	}
 	if (!ok) {
-		fprintf(stderr, " page %d failed!\n",
-			(unsigned int)(d - bios) / page_size);
+		fprintf(stderr, " page 0x%lx failed!\n",
+			(d - bios) / page_size);
 	}
 	return !ok;
 }
 
-int write_byte_program_jedec(volatile uint8_t *bios, uint8_t *src,
-			     volatile uint8_t *dst)
+int write_byte_program_jedec(chipaddr bios, uint8_t *src,
+			     chipaddr dst)
 {
 	int tried = 0, ok = 1;
 
@@ -308,8 +308,8 @@
 	return !ok;
 }
 
-int write_sector_jedec(volatile uint8_t *bios, uint8_t *src,
-		       volatile uint8_t *dst, unsigned int page_size)
+int write_sector_jedec(chipaddr bios, uint8_t *src,
+		       chipaddr dst, unsigned int page_size)
 {
 	int i;
 
@@ -326,12 +326,12 @@
 	int i;
 	int total_size = flash->total_size * 1024;
 	int page_size = flash->page_size;
-	volatile uint8_t *bios = flash->virtual_memory;
+	chipaddr bios = flash->virtual_memory;
 
 	erase_chip_jedec(flash);
 	// dumb check if erase was successful.
 	for (i = 0; i < total_size; i++) {
-		if (chip_readb(bios + i) != (uint8_t) 0xff) {
+		if (chip_readb(bios + i) != 0xff) {
 			printf("ERASE FAILED @%d, val %02x!\n", i, chip_readb(bios + i));
 			return -1;
 		}