Revert "Unsignify lengths and addresses in chip functions and structs"

- probe_timing was changed to unsigned although we use negative values
  for special cases
- some code was not changed along hence did no longer compile:
  * dediprog's read and write functions
  * linux_spi's read and write functions
- it introduced a number of new sign conversion warnings
  (http://paste.flashrom.org/view.php?id=832)

To be safe this patch reverts all changes made in r1448, a corrected
patch will follow later.

Thanks to idwer for pointing out the problem first!

Corresponding to flashrom svn r1450.

Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
Acked-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
diff --git a/82802ab.c b/82802ab.c
index 8f671c9..ff2f535 100644
--- a/82802ab.c
+++ b/82802ab.c
@@ -141,7 +141,7 @@
 }
 
 /* chunksize is 1 */
-int write_82802ab(struct flashchip *flash, uint8_t *src, unsigned int start, unsigned int len)
+int write_82802ab(struct flashchip *flash, uint8_t *src, int start, int len)
 {
 	int i;
 	chipaddr dst = flash->virtual_memory + start;
diff --git a/chipdrivers.h b/chipdrivers.h
index 42df4c7..958c59a 100644
--- a/chipdrivers.h
+++ b/chipdrivers.h
@@ -41,9 +41,9 @@
 int spi_block_erase_d8(struct flashchip *flash, unsigned int addr, unsigned int blocklen);
 int spi_block_erase_60(struct flashchip *flash, unsigned int addr, unsigned int blocklen);
 int spi_block_erase_c7(struct flashchip *flash, unsigned int addr, unsigned int blocklen);
-int spi_chip_write_1(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len);
-int spi_chip_write_256(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len);
-int spi_chip_read(struct flashchip *flash, uint8_t *buf, unsigned int start, int unsigned len);
+int spi_chip_write_1(struct flashchip *flash, uint8_t *buf, int start, int len);
+int spi_chip_write_256(struct flashchip *flash, uint8_t *buf, int start, int len);
+int spi_chip_read(struct flashchip *flash, uint8_t *buf, int start, int len);
 uint8_t spi_read_status_register(void);
 int spi_write_status_register(struct flashchip *flash, int status);
 void spi_prettyprint_status_register_bit(uint8_t status, int bit);
@@ -51,12 +51,12 @@
 void spi_prettyprint_status_register_welwip(uint8_t status);
 int spi_prettyprint_status_register(struct flashchip *flash);
 int spi_disable_blockprotect(struct flashchip *flash);
-int spi_byte_program(unsigned int addr, uint8_t databyte);
-int spi_nbyte_program(unsigned int addr, uint8_t *bytes, unsigned int len);
-int spi_nbyte_read(unsigned int addr, uint8_t *bytes, unsigned int len);
-int spi_read_chunked(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len, unsigned int chunksize);
-int spi_write_chunked(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len, unsigned int chunksize);
-int spi_aai_write(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len);
+int spi_byte_program(int addr, uint8_t databyte);
+int spi_nbyte_program(int addr, uint8_t *bytes, int len);
+int spi_nbyte_read(int addr, uint8_t *bytes, int len);
+int spi_read_chunked(struct flashchip *flash, uint8_t *buf, int start, int len, int chunksize);
+int spi_write_chunked(struct flashchip *flash, uint8_t *buf, int start, int len, int chunksize);
+int spi_aai_write(struct flashchip *flash, uint8_t *buf, int start, int len);
 
 /* a25.c */
 int spi_prettyprint_status_register_amic_a25l05p(struct flashchip *flash);
@@ -81,7 +81,7 @@
 uint8_t wait_82802ab(struct flashchip *flash);
 int probe_82802ab(struct flashchip *flash);
 int erase_block_82802ab(struct flashchip *flash, unsigned int page, unsigned int pagesize);
-int write_82802ab(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len);
+int write_82802ab(struct flashchip *flash, uint8_t *buf, int start, int len);
 void print_status_82802ab(uint8_t status);
 int unlock_82802ab(struct flashchip *flash);
 int unlock_28f004s5(struct flashchip *flash);
@@ -94,8 +94,8 @@
 int write_byte_program_jedec(chipaddr bios, uint8_t *src,
 			     chipaddr dst);
 int probe_jedec(struct flashchip *flash);
-int write_jedec(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len);
-int write_jedec_1(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len);
+int write_jedec(struct flashchip *flash, uint8_t *buf, int start, int len);
+int write_jedec_1(struct flashchip *flash, uint8_t *buf, int start, int len);
 int erase_sector_jedec(struct flashchip *flash, unsigned int page, unsigned int pagesize);
 int erase_block_jedec(struct flashchip *flash, unsigned int page, unsigned int blocksize);
 int erase_chip_block_jedec(struct flashchip *flash, unsigned int page, unsigned int blocksize);
@@ -104,7 +104,7 @@
 int probe_m29f400bt(struct flashchip *flash);
 int block_erase_m29f400bt(struct flashchip *flash, unsigned int start, unsigned int len);
 int block_erase_chip_m29f400bt(struct flashchip *flash, unsigned int start, unsigned int len);
-int write_m29f400bt(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len);
+int write_m29f400bt(struct flashchip *flash, uint8_t *buf, int start, int len);
 void protect_m29f400bt(chipaddr bios);
 
 /* pm49fl00x.c */
@@ -114,7 +114,7 @@
 /* sst28sf040.c */
 int erase_chip_28sf040(struct flashchip *flash, unsigned int addr, unsigned int blocklen);
 int erase_sector_28sf040(struct flashchip *flash, unsigned int address, unsigned int sector_size);
-int write_28sf040(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len);
+int write_28sf040(struct flashchip *flash, uint8_t *buf, int start, int len);
 int unprotect_28sf040(struct flashchip *flash);
 int protect_28sf040(struct flashchip *flash);
 
diff --git a/dummyflasher.c b/dummyflasher.c
index 84650e7..be8f552 100644
--- a/dummyflasher.c
+++ b/dummyflasher.c
@@ -63,7 +63,7 @@
 static int dummy_spi_send_command(unsigned int writecnt, unsigned int readcnt,
 		      const unsigned char *writearr, unsigned char *readarr);
 static int dummy_spi_write_256(struct flashchip *flash, uint8_t *buf,
-			       unsigned int start, unsigned int len);
+			       int start, int len);
 
 static const struct spi_programmer spi_programmer_dummyflasher = {
 	.type		= SPI_CONTROLLER_DUMMY,
@@ -528,7 +528,7 @@
 }
 
 static int dummy_spi_write_256(struct flashchip *flash, uint8_t *buf,
-			       unsigned int start, unsigned int len)
+			       int start, int len)
 {
 	return spi_write_chunked(flash, buf, start, len,
 				 spi_write_256_chunksize);
diff --git a/flash.h b/flash.h
index 13bb43a..535c1b8 100644
--- a/flash.h
+++ b/flash.h
@@ -108,9 +108,9 @@
 	uint32_t model_id;
 
 	/* Total chip size in kilobytes */
-	unsigned int total_size;
+	int total_size;
 	/* Chip page size in bytes */
-	unsigned int page_size;
+	int page_size;
 	int feature_bits;
 
 	/*
@@ -122,7 +122,7 @@
 	int (*probe) (struct flashchip *flash);
 
 	/* Delay after "enter/exit ID mode" commands in microseconds. */
-	unsigned int probe_timing;
+	int probe_timing;
 
 	/*
 	 * Erase blocks and associated erase function. Any chip erase function
@@ -143,8 +143,8 @@
 
 	int (*printlock) (struct flashchip *flash);
 	int (*unlock) (struct flashchip *flash);
-	int (*write) (struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len);
-	int (*read) (struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len);
+	int (*write) (struct flashchip *flash, uint8_t *buf, int start, int len);
+	int (*read) (struct flashchip *flash, uint8_t *buf, int start, int len);
 	struct {
 		uint16_t min;
 		uint16_t max;
@@ -202,7 +202,7 @@
 extern const char flashrom_version[];
 extern char *chip_to_probe;
 void map_flash_registers(struct flashchip *flash);
-int read_memmapped(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len);
+int read_memmapped(struct flashchip *flash, uint8_t *buf, int start, int len);
 int erase_flash(struct flashchip *flash);
 int probe_flash(int startchip, struct flashchip *fill_flash, int force);
 int read_flash_to_file(struct flashchip *flash, const char *filename);
@@ -210,7 +210,7 @@
 int max(int a, int b);
 void tolower_string(char *str);
 char *extract_param(char **haystack, const char *needle, const char *delim);
-int verify_range(struct flashchip *flash, uint8_t *cmpbuf, unsigned int start, unsigned int len, const char *message);
+int verify_range(struct flashchip *flash, uint8_t *cmpbuf, int start, int len, const char *message);
 int need_erase(uint8_t *have, uint8_t *want, int len, enum write_granularity gran);
 char *strcat_realloc(char *dest, const char *src);
 void print_version(void);
diff --git a/flashrom.c b/flashrom.c
index e2afd44..c565a43 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -564,7 +564,7 @@
 	flash->virtual_registers = (chipaddr)programmer_map_flash_region("flash chip registers", (0xFFFFFFFF - 0x400000 - size + 1), size);
 }
 
-int read_memmapped(struct flashchip *flash, uint8_t *buf, unsigned int start, int unsigned len)
+int read_memmapped(struct flashchip *flash, uint8_t *buf, int start, int len)
 {
 	chip_readn(buf, flash->virtual_memory + start, len);
 
@@ -710,7 +710,7 @@
  * @message	string to print in the "FAILED" message
  * @return	0 for success, -1 for failure
  */
-int verify_range(struct flashchip *flash, uint8_t *cmpbuf, unsigned int start, unsigned int len,
+int verify_range(struct flashchip *flash, uint8_t *cmpbuf, int start, int len,
 		 const char *message)
 {
 	int i;
diff --git a/it87spi.c b/it87spi.c
index bfbb063..5fe74ce 100644
--- a/it87spi.c
+++ b/it87spi.c
@@ -106,9 +106,9 @@
 static int it8716f_spi_send_command(unsigned int writecnt, unsigned int readcnt,
 			const unsigned char *writearr, unsigned char *readarr);
 static int it8716f_spi_chip_read(struct flashchip *flash, uint8_t *buf,
-				 unsigned int start, unsigned int len);
+				 int start, int len);
 static int it8716f_spi_chip_write_256(struct flashchip *flash, uint8_t *buf,
-				      unsigned int start, unsigned int len);
+				      int start, int len);
 
 static const struct spi_programmer spi_programmer_it87xx = {
 	.type		= SPI_CONTROLLER_IT87XX,
@@ -340,7 +340,7 @@
  * Need to read this big flash using firmware cycles 3 byte at a time.
  */
 static int it8716f_spi_chip_read(struct flashchip *flash, uint8_t *buf,
-				 unsigned int start, unsigned int len)
+				 int start, int len)
 {
 	fast_spi = 0;
 
@@ -358,7 +358,7 @@
 }
 
 static int it8716f_spi_chip_write_256(struct flashchip *flash, uint8_t *buf,
-				      unsigned int start, unsigned int len)
+				      int start, int len)
 {
 	/*
 	 * IT8716F only allows maximum of 512 kb SPI chip size for memory
diff --git a/jedec.c b/jedec.c
index 9ecb990..cf34bcd 100644
--- a/jedec.c
+++ b/jedec.c
@@ -355,7 +355,7 @@
 }
 
 /* chunksize is 1 */
-int write_jedec_1(struct flashchip *flash, uint8_t *src, unsigned int start, unsigned int len)
+int write_jedec_1(struct flashchip *flash, uint8_t *src, int start, int len)
 {
 	int i, failed = 0;
 	chipaddr dst = flash->virtual_memory + start;
@@ -376,7 +376,7 @@
 	return failed;
 }
 
-int write_page_write_jedec_common(struct flashchip *flash, uint8_t *src, unsigned int start, unsigned int page_size)
+int write_page_write_jedec_common(struct flashchip *flash, uint8_t *src, int start, int page_size)
 {
 	int i, tried = 0, failed;
 	uint8_t *s = src;
@@ -424,7 +424,7 @@
  * This function is a slightly modified copy of spi_write_chunked.
  * Each page is written separately in chunks with a maximum size of chunksize.
  */
-int write_jedec(struct flashchip *flash, uint8_t *buf, unsigned int start, int unsigned len)
+int write_jedec(struct flashchip *flash, uint8_t *buf, int start, int len)
 {
 	int i, starthere, lenhere;
 	/* FIXME: page_size is the wrong variable. We need max_writechunk_size
diff --git a/m29f400bt.c b/m29f400bt.c
index 61bfa2e..e0d41d4 100644
--- a/m29f400bt.c
+++ b/m29f400bt.c
@@ -28,7 +28,7 @@
    functions. */
 
 /* chunksize is 1 */
-int write_m29f400bt(struct flashchip *flash, uint8_t *src, unsigned int start, unsigned int len)
+int write_m29f400bt(struct flashchip *flash, uint8_t *src, int start, int len)
 {
 	int i;
 	chipaddr bios = flash->virtual_memory;
diff --git a/programmer.h b/programmer.h
index c92713a..73b94c1 100644
--- a/programmer.h
+++ b/programmer.h
@@ -556,23 +556,23 @@
 #define MAX_DATA_WRITE_UNLIMITED 256
 struct spi_programmer {
 	enum spi_controller type;
-	unsigned int max_data_read;
-	unsigned int max_data_write;
+	int max_data_read;
+	int max_data_write;
 	int (*command)(unsigned int writecnt, unsigned int readcnt,
 		   const unsigned char *writearr, unsigned char *readarr);
 	int (*multicommand)(struct spi_command *cmds);
 
 	/* Optimized functions for this programmer */
-	int (*read)(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len);
-	int (*write_256)(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len);
+	int (*read)(struct flashchip *flash, uint8_t *buf, int start, int len);
+	int (*write_256)(struct flashchip *flash, uint8_t *buf, int start, int len);
 };
 
 extern const struct spi_programmer *spi_programmer;
 int default_spi_send_command(unsigned int writecnt, unsigned int readcnt,
 			     const unsigned char *writearr, unsigned char *readarr);
 int default_spi_send_multicommand(struct spi_command *cmds);
-int default_spi_read(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len);
-int default_spi_write_256(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len);
+int default_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
+int default_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len);
 void register_spi_programmer(const struct spi_programmer *programmer);
 
 /* ichspi.c */
@@ -610,7 +610,7 @@
 void serprog_delay(int delay);
 int serprog_spi_send_command(unsigned int writecnt, unsigned int readcnt,
 			const unsigned char *writearr, unsigned char *readarr);
-int serprog_spi_read(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len);
+int serprog_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
 #endif
 
 /* serial.c */
diff --git a/serprog.c b/serprog.c
index a4aef08..9d554c9 100644
--- a/serprog.c
+++ b/serprog.c
@@ -795,7 +795,7 @@
  * the advantage that it is much faster for most chips, but breaks those with
  * non-contiguous address space (like AT45DB161D). When spi_read_chunked is
  * fixed this method can be removed. */
-int serprog_spi_read(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len)
+int serprog_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len)
 {
 	int i;
 	int cur_len;
diff --git a/spi.c b/spi.c
index 77cfb1e..f02f091 100644
--- a/spi.c
+++ b/spi.c
@@ -97,9 +97,9 @@
 	return result;
 }
 
-int default_spi_read(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len)
+int default_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len)
 {
-	unsigned int max_data = spi_programmer->max_data_read;
+	int max_data = spi_programmer->max_data_read;
 	if (max_data == MAX_DATA_UNSPECIFIED) {
 		msg_perr("%s called, but SPI read chunk size not defined "
 			 "on this hardware. Please report a bug at "
@@ -109,9 +109,9 @@
 	return spi_read_chunked(flash, buf, start, len, max_data);
 }
 
-int default_spi_write_256(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len)
+int default_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len)
 {
-	unsigned int max_data = spi_programmer->max_data_write;
+	int max_data = spi_programmer->max_data_write;
 	if (max_data == MAX_DATA_UNSPECIFIED) {
 		msg_perr("%s called, but SPI write chunk size not defined "
 			 "on this hardware. Please report a bug at "
@@ -121,7 +121,7 @@
 	return spi_write_chunked(flash, buf, start, len, max_data);
 }
 
-int spi_chip_read(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len)
+int spi_chip_read(struct flashchip *flash, uint8_t *buf, int start, int len)
 {
 	int addrbase = 0;
 	if (!spi_programmer->read) {
@@ -160,7 +160,7 @@
  * .write_256 = spi_chip_write_1
  */
 /* real chunksize is up to 256, logical chunksize is 256 */
-int spi_chip_write_256(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len)
+int spi_chip_write_256(struct flashchip *flash, uint8_t *buf, int start, int len)
 {
 	if (!spi_programmer->write_256) {
 		msg_perr("%s called, but SPI page write is unsupported on this "
diff --git a/spi25.c b/spi25.c
index 444a8b6..937ee5d 100644
--- a/spi25.c
+++ b/spi25.c
@@ -844,7 +844,7 @@
 	return ret;
 }
 
-int spi_byte_program(unsigned int addr, uint8_t databyte)
+int spi_byte_program(int addr, uint8_t databyte)
 {
 	int result;
 	struct spi_command cmds[] = {
@@ -879,7 +879,7 @@
 	return result;
 }
 
-int spi_nbyte_program(unsigned int addr, uint8_t *bytes, unsigned int len)
+int spi_nbyte_program(int addr, uint8_t *bytes, int len)
 {
 	int result;
 	/* FIXME: Switch to malloc based on len unless that kills speed. */
@@ -954,7 +954,7 @@
 	return 0;
 }
 
-int spi_nbyte_read(unsigned int address, uint8_t *bytes, unsigned int len)
+int spi_nbyte_read(int address, uint8_t *bytes, int len)
 {
 	const unsigned char cmd[JEDEC_READ_OUTSIZE] = {
 		JEDEC_READ,
@@ -972,7 +972,7 @@
  * FIXME: Use the chunk code from Michael Karcher instead.
  * Each page is read separately in chunks with a maximum size of chunksize.
  */
-int spi_read_chunked(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len, unsigned int chunksize)
+int spi_read_chunked(struct flashchip *flash, uint8_t *buf, int start, int len, int chunksize)
 {
 	int rc = 0;
 	int i, j, starthere, lenhere;
@@ -1012,7 +1012,7 @@
  * FIXME: Use the chunk code from Michael Karcher instead.
  * Each page is written separately in chunks with a maximum size of chunksize.
  */
-int spi_write_chunked(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len, unsigned int chunksize)
+int spi_write_chunked(struct flashchip *flash, uint8_t *buf, int start, int len, int chunksize)
 {
 	int rc = 0;
 	int i, j, starthere, lenhere;
@@ -1061,7 +1061,7 @@
  * (e.g. due to size constraints in IT87* for over 512 kB)
  */
 /* real chunksize is 1, logical chunksize is 1 */
-int spi_chip_write_1(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len)
+int spi_chip_write_1(struct flashchip *flash, uint8_t *buf, int start, int len)
 {
 	int i, result = 0;
 
@@ -1076,7 +1076,7 @@
 	return 0;
 }
 
-int spi_aai_write(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len)
+int spi_aai_write(struct flashchip *flash, uint8_t *buf, int start, int len)
 {
 	uint32_t pos = start;
 	int result;
diff --git a/sst28sf040.c b/sst28sf040.c
index 2038d53..d621cc7 100644
--- a/sst28sf040.c
+++ b/sst28sf040.c
@@ -76,7 +76,7 @@
 }
 
 /* chunksize is 1 */
-int write_28sf040(struct flashchip *flash, uint8_t *src, unsigned int start, unsigned int len)
+int write_28sf040(struct flashchip *flash, uint8_t *src, int start, int len)
 {
 	int i;
 	chipaddr bios = flash->virtual_memory;
diff --git a/wbsio_spi.c b/wbsio_spi.c
index bc31e99..851c87f 100644
--- a/wbsio_spi.c
+++ b/wbsio_spi.c
@@ -62,7 +62,7 @@
 
 static int wbsio_spi_send_command(unsigned int writecnt, unsigned int readcnt,
 		      const unsigned char *writearr, unsigned char *readarr);
-static int wbsio_spi_read(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len);
+static int wbsio_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
 
 static const struct spi_programmer spi_programmer_wbsio = {
 	.type = SPI_CONTROLLER_WBSIO,
@@ -194,7 +194,7 @@
 	return 0;
 }
 
-static int wbsio_spi_read(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len)
+static int wbsio_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len)
 {
 	return read_memmapped(flash, buf, start, len);
 }