i don't like the use of generic "int" qualifiers at all, even more the unsigned version for things like absolute addresses, lengths and sizes. of course negative values make sense in return types to indicate errors and in the case a function returns the length of actually bytes written on success and negative values on errors it makes sense to keep the parameters the same type (else the parameter length might be too big to return it on success).
i would also like to change the types to more accurate ones someday (uint32_t etc.) instead, but i think that is not important as signedness.
i want to assure myself that no one objects changing the following things to unsigned before i create a patch (which should be straight forward, but of course i will need to change quite many lines and also check that all functions will stay correct...). please speak up now or forever hold your peace etc... :)
spi_programmer: int max_data_read; int max_data_write;
(start + len parameters of:) 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); (the return values just indicate success and failure with 0 and 1)
struct flashchip: int total_size; (should also be converted to bytes instead of kB... i know this is on the todo already)
int page_size;
(start + len parameters of:) int (*write) (struct flashchip *flash, uint8_t *buf, int start, int len); int (*read) (struct flashchip *flash, uint8_t *buf, int start, int len); (again, the return value just indicates success, not bytes written) };
--- compile tested with gcc 4.4.5 and clang 2.8
Signed-off-by: Stefan Tauner stefan.tauner@student.tuwien.ac.at --- 82802ab.c | 2 +- chipdrivers.h | 28 ++++++++++++++-------------- dummyflasher.c | 4 ++-- flash.h | 14 +++++++------- flashrom.c | 4 ++-- it87spi.c | 8 ++++---- jedec.c | 6 +++--- m29f400bt.c | 2 +- programmer.h | 12 ++++++------ spi.c | 12 ++++++------ spi25.c | 14 +++++++------- sst28sf040.c | 2 +- wbsio_spi.c | 4 ++-- 13 files changed, 56 insertions(+), 56 deletions(-)
diff --git a/82802ab.c b/82802ab.c index cd59c07..f940b32 100644 --- a/82802ab.c +++ b/82802ab.c @@ -141,7 +141,7 @@ int erase_block_82802ab(struct flashchip *flash, unsigned int page, }
/* chunksize is 1 */ -int write_82802ab(struct flashchip *flash, uint8_t *src, int start, int len) +int write_82802ab(struct flashchip *flash, uint8_t *src, unsigned int start, unsigned int len) { int i; chipaddr dst = flash->virtual_memory + start; diff --git a/chipdrivers.h b/chipdrivers.h index 3f5b503..b1088ec 100644 --- a/chipdrivers.h +++ b/chipdrivers.h @@ -41,9 +41,9 @@ int spi_block_erase_d7(struct flashchip *flash, unsigned int addr, unsigned int 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, 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); +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); 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_bp3210(uint8_t status, int bp); 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(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); +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);
/* a25.c */ int spi_prettyprint_status_register_amic_a25l05p(struct flashchip *flash); @@ -81,7 +81,7 @@ int spi_disable_blockprotect_at25fs040(struct flashchip *flash); 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, int start, int len); +int write_82802ab(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len); void print_status_82802ab(uint8_t status); int unlock_82802ab(struct flashchip *flash); int unlock_28f004s5(struct flashchip *flash); @@ -93,8 +93,8 @@ void data_polling_jedec(chipaddr dst, uint8_t data); 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, int start, int len); -int write_jedec_1(struct flashchip *flash, uint8_t *buf, int start, int len); +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 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); @@ -103,7 +103,7 @@ int erase_chip_block_jedec(struct flashchip *flash, unsigned int page, unsigned 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, int start, int len); +int write_m29f400bt(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len); void protect_m29f400bt(chipaddr bios);
/* pm49fl00x.c */ @@ -113,7 +113,7 @@ int lock_49fl00x(struct flashchip *flash); /* 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, int start, int len); +int write_28sf040(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len); int unprotect_28sf040(struct flashchip *flash); int protect_28sf040(struct flashchip *flash);
diff --git a/dummyflasher.c b/dummyflasher.c index be8f552..84650e7 100644 --- a/dummyflasher.c +++ b/dummyflasher.c @@ -63,7 +63,7 @@ static int spi_write_256_chunksize = 256; 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, - int start, int len); + unsigned int start, unsigned int len);
static const struct spi_programmer spi_programmer_dummyflasher = { .type = SPI_CONTROLLER_DUMMY, @@ -528,7 +528,7 @@ static int dummy_spi_send_command(unsigned int writecnt, unsigned int readcnt, }
static int dummy_spi_write_256(struct flashchip *flash, uint8_t *buf, - int start, int len) + unsigned int start, unsigned int len) { return spi_write_chunked(flash, buf, start, len, spi_write_256_chunksize); diff --git a/flash.h b/flash.h index 3d47a16..fd52595 100644 --- a/flash.h +++ b/flash.h @@ -108,9 +108,9 @@ struct flashchip { uint32_t model_id;
/* Total chip size in kilobytes */ - int total_size; + unsigned int total_size; /* Chip page size in bytes */ - int page_size; + unsigned int page_size; int feature_bits;
/* @@ -122,7 +122,7 @@ struct flashchip { int (*probe) (struct flashchip *flash);
/* Delay after "enter/exit ID mode" commands in microseconds. */ - int probe_timing; + unsigned int probe_timing;
/* * Erase blocks and associated erase function. Any chip erase function @@ -143,8 +143,8 @@ struct flashchip {
int (*printlock) (struct flashchip *flash); int (*unlock) (struct flashchip *flash); - int (*write) (struct flashchip *flash, uint8_t *buf, int start, int len); - int (*read) (struct flashchip *flash, uint8_t *buf, int start, int len); + 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); struct { uint16_t min; uint16_t max; @@ -202,7 +202,7 @@ extern int verbose; 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, int start, int len); +int read_memmapped(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned 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 min(int a, int b); 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, int start, int len, const char *message); +int verify_range(struct flashchip *flash, uint8_t *cmpbuf, unsigned int start, unsigned 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 d897ac7..add218a 100644 --- a/flashrom.c +++ b/flashrom.c @@ -603,7 +603,7 @@ void map_flash_registers(struct flashchip *flash) 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, int start, int len) +int read_memmapped(struct flashchip *flash, uint8_t *buf, unsigned int start, int unsigned len) { chip_readn(buf, flash->virtual_memory + start, len);
@@ -749,7 +749,7 @@ int check_erased_range(struct flashchip *flash, int start, int len) * @message string to print in the "FAILED" message * @return 0 for success, -1 for failure */ -int verify_range(struct flashchip *flash, uint8_t *cmpbuf, int start, int len, +int verify_range(struct flashchip *flash, uint8_t *cmpbuf, unsigned int start, unsigned int len, const char *message) { int i; diff --git a/it87spi.c b/it87spi.c index 46779ee..18aac74 100644 --- a/it87spi.c +++ b/it87spi.c @@ -106,9 +106,9 @@ void probe_superio_ite(void) 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, - int start, int len); + unsigned int start, unsigned int len); static int it8716f_spi_chip_write_256(struct flashchip *flash, uint8_t *buf, - int start, int len); + unsigned int start, unsigned int len);
static const struct spi_programmer spi_programmer_it87xx = { .type = SPI_CONTROLLER_IT87XX, @@ -342,7 +342,7 @@ static int it8716f_spi_page_program(struct flashchip *flash, uint8_t *buf, * 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, - int start, int len) + unsigned int start, unsigned int len) { fast_spi = 0;
@@ -360,7 +360,7 @@ static int it8716f_spi_chip_read(struct flashchip *flash, uint8_t *buf, }
static int it8716f_spi_chip_write_256(struct flashchip *flash, uint8_t *buf, - int start, int len) + unsigned int start, unsigned int len) { /* * IT8716F only allows maximum of 512 kb SPI chip size for memory diff --git a/jedec.c b/jedec.c index cf34bcd..9ecb990 100644 --- a/jedec.c +++ b/jedec.c @@ -355,7 +355,7 @@ retry: }
/* chunksize is 1 */ -int write_jedec_1(struct flashchip *flash, uint8_t *src, int start, int len) +int write_jedec_1(struct flashchip *flash, uint8_t *src, unsigned int start, unsigned int len) { int i, failed = 0; chipaddr dst = flash->virtual_memory + start; @@ -376,7 +376,7 @@ int write_jedec_1(struct flashchip *flash, uint8_t *src, int start, int len) return failed; }
-int write_page_write_jedec_common(struct flashchip *flash, uint8_t *src, int start, int page_size) +int write_page_write_jedec_common(struct flashchip *flash, uint8_t *src, unsigned int start, unsigned int page_size) { int i, tried = 0, failed; uint8_t *s = src; @@ -424,7 +424,7 @@ retry: * 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, int start, int len) +int write_jedec(struct flashchip *flash, uint8_t *buf, unsigned int start, int unsigned 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 e0d41d4..61bfa2e 100644 --- a/m29f400bt.c +++ b/m29f400bt.c @@ -28,7 +28,7 @@ functions. */
/* chunksize is 1 */ -int write_m29f400bt(struct flashchip *flash, uint8_t *src, int start, int len) +int write_m29f400bt(struct flashchip *flash, uint8_t *src, unsigned int start, unsigned int len) { int i; chipaddr bios = flash->virtual_memory; diff --git a/programmer.h b/programmer.h index 6a28dbe..2241274 100644 --- a/programmer.h +++ b/programmer.h @@ -547,23 +547,23 @@ extern const int spi_programmer_count; #define MAX_DATA_WRITE_UNLIMITED 256 struct spi_programmer { enum spi_controller type; - int max_data_read; - int max_data_write; + unsigned int max_data_read; + unsigned 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, int start, int len); - int (*write_256)(struct flashchip *flash, uint8_t *buf, int start, int len); + 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); };
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, int start, int len); -int default_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len); +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); void register_spi_programmer(const struct spi_programmer *programmer);
/* ichspi.c */ diff --git a/spi.c b/spi.c index f02f091..77cfb1e 100644 --- a/spi.c +++ b/spi.c @@ -97,9 +97,9 @@ int default_spi_send_multicommand(struct spi_command *cmds) return result; }
-int default_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len) +int default_spi_read(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len) { - int max_data = spi_programmer->max_data_read; + unsigned 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 @@ int default_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len) return spi_read_chunked(flash, buf, start, len, max_data); }
-int default_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len) +int default_spi_write_256(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len) { - int max_data = spi_programmer->max_data_write; + unsigned 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 @@ int default_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int return spi_write_chunked(flash, buf, start, len, max_data); }
-int spi_chip_read(struct flashchip *flash, uint8_t *buf, int start, int len) +int spi_chip_read(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len) { int addrbase = 0; if (!spi_programmer->read) { @@ -160,7 +160,7 @@ int spi_chip_read(struct flashchip *flash, uint8_t *buf, int start, int len) * .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, int start, int len) +int spi_chip_write_256(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned 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 937ee5d..444a8b6 100644 --- a/spi25.c +++ b/spi25.c @@ -844,7 +844,7 @@ int spi_write_status_register(struct flashchip *flash, int status) return ret; }
-int spi_byte_program(int addr, uint8_t databyte) +int spi_byte_program(unsigned int addr, uint8_t databyte) { int result; struct spi_command cmds[] = { @@ -879,7 +879,7 @@ int spi_byte_program(int addr, uint8_t databyte) return result; }
-int spi_nbyte_program(int addr, uint8_t *bytes, int len) +int spi_nbyte_program(unsigned int addr, uint8_t *bytes, unsigned int len) { int result; /* FIXME: Switch to malloc based on len unless that kills speed. */ @@ -954,7 +954,7 @@ int spi_disable_blockprotect(struct flashchip *flash) return 0; }
-int spi_nbyte_read(int address, uint8_t *bytes, int len) +int spi_nbyte_read(unsigned int address, uint8_t *bytes, unsigned int len) { const unsigned char cmd[JEDEC_READ_OUTSIZE] = { JEDEC_READ, @@ -972,7 +972,7 @@ int spi_nbyte_read(int address, uint8_t *bytes, int len) * 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, int start, int len, int chunksize) +int spi_read_chunked(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len, unsigned int chunksize) { int rc = 0; int i, j, starthere, lenhere; @@ -1012,7 +1012,7 @@ int spi_read_chunked(struct flashchip *flash, uint8_t *buf, int start, int len, * 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, int start, int len, int chunksize) +int spi_write_chunked(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len, unsigned int chunksize) { int rc = 0; int i, j, starthere, lenhere; @@ -1061,7 +1061,7 @@ int spi_write_chunked(struct flashchip *flash, uint8_t *buf, int start, int len, * (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, int start, int len) +int spi_chip_write_1(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len) { int i, result = 0;
@@ -1076,7 +1076,7 @@ int spi_chip_write_1(struct flashchip *flash, uint8_t *buf, int start, int len) return 0; }
-int spi_aai_write(struct flashchip *flash, uint8_t *buf, int start, int len) +int spi_aai_write(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len) { uint32_t pos = start; int result; diff --git a/sst28sf040.c b/sst28sf040.c index d621cc7..2038d53 100644 --- a/sst28sf040.c +++ b/sst28sf040.c @@ -76,7 +76,7 @@ int erase_sector_28sf040(struct flashchip *flash, unsigned int address, unsigned }
/* chunksize is 1 */ -int write_28sf040(struct flashchip *flash, uint8_t *src, int start, int len) +int write_28sf040(struct flashchip *flash, uint8_t *src, unsigned int start, unsigned int len) { int i; chipaddr bios = flash->virtual_memory; diff --git a/wbsio_spi.c b/wbsio_spi.c index 851c87f..bc31e99 100644 --- a/wbsio_spi.c +++ b/wbsio_spi.c @@ -62,7 +62,7 @@ done:
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, int start, int len); +static int wbsio_spi_read(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len);
static const struct spi_programmer spi_programmer_wbsio = { .type = SPI_CONTROLLER_WBSIO, @@ -194,7 +194,7 @@ static int wbsio_spi_send_command(unsigned int writecnt, unsigned int readcnt, return 0; }
-static int wbsio_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len) +static int wbsio_spi_read(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len) { return read_memmapped(flash, buf, start, len); }