Push those changes forward where needed to prevent new sign conversion warnings where possible.
---
this is a crude rework of the reverted patch. i have tried to push unsignedness wherever possible, but there are some problems: ffs, min, max and some library/system calls require signed ints or return them or both.
Signed-off-by: Stefan Tauner stefan.tauner@student.tuwien.ac.at --- 82802ab.c | 2 +- buspirate_spi.c | 3 ++- chipdrivers.h | 28 ++++++++++++++-------------- dediprog.c | 20 ++++++++++---------- dummyflasher.c | 26 +++++++++++++------------- flash.h | 20 +++++++++++--------- flashrom.c | 27 +++++++++++++++------------ ft2232_spi.c | 19 ++++++++++--------- it87spi.c | 15 ++++++++------- jedec.c | 26 +++++++++++++------------- linux_spi.c | 16 ++++++++-------- m29f400bt.c | 2 +- pm49fl00x.c | 6 +++--- programmer.h | 14 +++++++------- serprog.c | 11 +++++------ spi.c | 14 +++++++------- spi25.c | 27 +++++++++++++-------------- sst28sf040.c | 2 +- sst49lfxxxc.c | 2 +- w39.c | 12 ++++++------ wbsio_spi.c | 4 ++-- 21 files changed, 151 insertions(+), 145 deletions(-)
diff --git a/82802ab.c b/82802ab.c index ff2f535..8f671c9 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/buspirate_spi.c b/buspirate_spi.c index a556185..fd06b59 100644 --- a/buspirate_spi.c +++ b/buspirate_spi.c @@ -295,7 +295,8 @@ static int buspirate_spi_send_command(unsigned int writecnt, unsigned int readcn const unsigned char *writearr, unsigned char *readarr) { static unsigned char *buf = NULL; - int i = 0, ret = 0; + unsigned int i = 0; + int ret = 0;
if (writecnt > 16 || readcnt > 16 || (readcnt + writecnt) > 16) return SPI_INVALID_LENGTH; diff --git a/chipdrivers.h b/chipdrivers.h index 958c59a..42df4c7 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); @@ -94,8 +94,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); @@ -104,7 +104,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 */ @@ -114,7 +114,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/dediprog.c b/dediprog.c index 58eeb44..ca2d3e0 100644 --- a/dediprog.c +++ b/dediprog.c @@ -206,13 +206,13 @@ static int dediprog_set_spi_speed(uint16_t speed) * @return 0 on success, 1 on failure */ static int dediprog_spi_bulk_read(struct flashchip *flash, uint8_t *buf, - int start, int len) + unsigned int start, unsigned int len) { int ret; - int i; + unsigned int i; /* chunksize must be 512, other sizes will NOT work at all. */ - const int chunksize = 0x200; - const int count = len / chunksize; + const unsigned int chunksize = 0x200; + const unsigned int count = len / chunksize; const char count_and_chunk[] = {count & 0xff, (count >> 8) & 0xff, chunksize & 0xff, @@ -253,14 +253,14 @@ static int dediprog_spi_bulk_read(struct flashchip *flash, uint8_t *buf, return 0; }
-static int dediprog_spi_read(struct flashchip *flash, uint8_t *buf, int start, - int len) +static int dediprog_spi_read(struct flashchip *flash, uint8_t *buf, + unsigned int start, unsigned int len) { int ret; /* chunksize must be 512, other sizes will NOT work at all. */ - const int chunksize = 0x200; - int residue = start % chunksize ? chunksize - start % chunksize : 0; - int bulklen; + const unsigned int chunksize = 0x200; + unsigned int residue = start % chunksize ? chunksize - start % chunksize : 0; + unsigned int bulklen;
dediprog_set_leds(PASS_OFF|BUSY_ON|ERROR_OFF);
@@ -300,7 +300,7 @@ static int dediprog_spi_read(struct flashchip *flash, uint8_t *buf, int start, }
static int dediprog_spi_write_256(struct flashchip *flash, uint8_t *buf, - int start, int len) + unsigned int start, unsigned int len) { int ret;
diff --git a/dummyflasher.c b/dummyflasher.c index be8f552..d4b1cb8 100644 --- a/dummyflasher.c +++ b/dummyflasher.c @@ -46,24 +46,24 @@ enum emu_chip { }; static enum emu_chip emu_chip = EMULATE_NONE; static char *emu_persistent_image = NULL; -static int emu_chip_size = 0; +static unsigned int emu_chip_size = 0; #if EMULATE_SPI_CHIP -static int emu_max_byteprogram_size = 0; -static int emu_max_aai_size = 0; -static int emu_jedec_se_size = 0; -static int emu_jedec_be_52_size = 0; -static int emu_jedec_be_d8_size = 0; -static int emu_jedec_ce_60_size = 0; -static int emu_jedec_ce_c7_size = 0; +static unsigned int emu_max_byteprogram_size = 0; +static unsigned int emu_max_aai_size = 0; +static unsigned int emu_jedec_se_size = 0; +static unsigned int emu_jedec_be_52_size = 0; +static unsigned int emu_jedec_be_d8_size = 0; +static unsigned int emu_jedec_ce_60_size = 0; +static unsigned int emu_jedec_ce_c7_size = 0; #endif #endif
-static int spi_write_256_chunksize = 256; +static unsigned 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, @@ -299,8 +299,8 @@ void dummy_chip_readn(uint8_t *buf, const chipaddr addr, size_t len) static int emulate_spi_chip_response(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr) { - int offs; - static int aai_offs; + unsigned int offs; + static int unsigned aai_offs; static int aai_active = 0;
if (writecnt == 0) { @@ -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 535c1b8..e7bfd4e 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;
/* @@ -121,8 +121,10 @@ struct flashchip {
int (*probe) (struct flashchip *flash);
- /* Delay after "enter/exit ID mode" commands in microseconds. */ - int probe_timing; + /* Delay after "enter/exit ID mode" commands in microseconds. + * NB: negative values have special meanings, see TIMING_* below. + */ + signed int probe_timing;
/* * Erase blocks and associated erase function. Any chip erase function @@ -143,8 +145,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 +204,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,8 +212,8 @@ 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 need_erase(uint8_t *have, uint8_t *want, int len, enum write_granularity gran); +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, unsigned int len, enum write_granularity gran); char *strcat_realloc(char *dest, const char *src); void print_version(void); void print_banner(void); diff --git a/flashrom.c b/flashrom.c index c565a43..4e2921a 100644 --- a/flashrom.c +++ b/flashrom.c @@ -564,7 +564,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);
@@ -687,7 +687,7 @@ static unsigned int count_usable_erasers(const struct flashchip *flash) }
/* start is an offset to the base address of the flash chip */ -int check_erased_range(struct flashchip *flash, int start, int len) +int check_erased_range(struct flashchip *flash, unsigned int start, unsigned int len) { int ret; uint8_t *cmpbuf = malloc(len); @@ -710,10 +710,10 @@ 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; + unsigned int i; uint8_t *readbuf = malloc(len); int ret = 0, failcount = 0;
@@ -791,10 +791,10 @@ out_free: * @gran write granularity (enum, not count) * @return 0 if no erase is needed, 1 otherwise */ -int need_erase(uint8_t *have, uint8_t *want, int len, enum write_granularity gran) +int need_erase(uint8_t *have, uint8_t *want, unsigned int len, enum write_granularity gran) { int result = 0; - int i, j, limit; + unsigned int i, j, limit;
switch (gran) { case write_gran_1bit: @@ -857,11 +857,13 @@ int need_erase(uint8_t *have, uint8_t *want, int len, enum write_granularity gra * in relation to the max write length of the programmer and the max write * length of the chip. */ -static int get_next_write(uint8_t *have, uint8_t *want, int len, - int *first_start, enum write_granularity gran) +static unsigned int get_next_write(uint8_t *have, uint8_t *want, unsigned int len, + unsigned int *first_start, + enum write_granularity gran) { - int need_write = 0, rel_start = 0, first_len = 0; - int i, limit, stride; + int need_write = 0; + unsigned int rel_start = 0, first_len = 0; + unsigned int i, limit, stride;
switch (gran) { case write_gran_1bit: @@ -1182,7 +1184,7 @@ notfound: int verify_flash(struct flashchip *flash, uint8_t *buf) { int ret; - int total_size = flash->total_size * 1024; + unsigned int total_size = flash->total_size * 1024;
msg_cinfo("Verifying flash... ");
@@ -1360,7 +1362,8 @@ static int erase_and_write_block_helper(struct flashchip *flash, unsigned int addr, unsigned int len)) { - int starthere = 0, lenhere = 0, ret = 0, skip = 1, writecount = 0; + unsigned int starthere = 0, lenhere = 0; + int ret = 0, skip = 1, writecount = 0; enum write_granularity gran = write_gran_256bytes; /* FIXME */
/* curcontents and newcontents are opaque to walk_eraseregions, and diff --git a/ft2232_spi.c b/ft2232_spi.c index 8ab89fa..8f00685 100644 --- a/ft2232_spi.c +++ b/ft2232_spi.c @@ -106,10 +106,10 @@ static const char *get_ft2232_vendorname(int ft2232_vid, int ft2232_type) }
static int send_buf(struct ftdi_context *ftdic, const unsigned char *buf, - int size) + unsigned int size) { int r; - r = ftdi_write_data(ftdic, (unsigned char *) buf, size); + r = ftdi_write_data(ftdic, (unsigned char *) buf, (int)size); if (r < 0) { msg_perr("ftdi_write_data: %d, %s\n", r, ftdi_get_error_string(ftdic)); @@ -119,19 +119,19 @@ static int send_buf(struct ftdi_context *ftdic, const unsigned char *buf, }
static int get_buf(struct ftdi_context *ftdic, const unsigned char *buf, - int size) + unsigned int size) { int r;
while (size > 0) { - r = ftdi_read_data(ftdic, (unsigned char *) buf, size); + r = ftdi_read_data(ftdic, (unsigned char *) buf, (int)size); if (r < 0) { msg_perr("ftdi_read_data: %d, %s\n", r, ftdi_get_error_string(ftdic)); return 1; } - buf += r; - size -= r; + buf += (unsigned int)r; + size -= (unsigned int)r; } return 0; } @@ -332,9 +332,10 @@ static int ft2232_spi_send_command(unsigned int writecnt, unsigned int readcnt, struct ftdi_context *ftdic = &ftdic_context; static unsigned char *buf = NULL; /* failed is special. We use bitwise ops, but it is essentially bool. */ - int i = 0, ret = 0, failed = 0; - int bufsize; - static int oldbufsize = 0; + int ret = 0, failed = 0; + unsigned int i = 0; + unsigned int bufsize; + static unsigned int oldbufsize = 0;
if (writecnt > 65536 || readcnt > 65536) return SPI_INVALID_LENGTH; diff --git a/it87spi.c b/it87spi.c index 5fe74ce..c93a4a1 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, @@ -313,9 +313,10 @@ static int it8716f_spi_send_command(unsigned int writecnt, unsigned int readcnt,
/* Page size is usually 256 bytes */ static int it8716f_spi_page_program(struct flashchip *flash, uint8_t *buf, - int start) + unsigned int start) { - int i, result; + unsigned int i; + int result; chipaddr bios = flash->virtual_memory;
result = spi_write_enable(); @@ -340,7 +341,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;
@@ -358,7 +359,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 @@ -374,7 +375,7 @@ static int it8716f_spi_chip_write_256(struct flashchip *flash, uint8_t *buf, (flash->page_size > 256)) { spi_chip_write_1(flash, buf, start, len); } else { - int lenhere; + unsigned int lenhere;
if (start % flash->page_size) { /* start to the end of the page or to start + len, diff --git a/jedec.c b/jedec.c index cf34bcd..8004863 100644 --- a/jedec.c +++ b/jedec.c @@ -91,7 +91,7 @@ void data_polling_jedec(chipaddr dst, uint8_t data) msg_cdbg("%s: excessive loops, i=0x%x\n", __func__, i); }
-static int getaddrmask(struct flashchip *flash) +static unsigned int getaddrmask(struct flashchip *flash) { switch (flash->feature_bits & FEATURE_ADDR_MASK) { case FEATURE_ADDR_FULL: @@ -355,12 +355,12 @@ 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; chipaddr olddst; - int mask; + unsigned int mask;
mask = getaddrmask(flash);
@@ -376,14 +376,14 @@ 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; chipaddr bios = flash->virtual_memory; chipaddr dst = bios + start; chipaddr d = dst; - int mask; + unsigned int mask;
mask = getaddrmask(flash);
@@ -424,15 +424,15 @@ 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; + unsigned int i, starthere, lenhere; /* FIXME: page_size is the wrong variable. We need max_writechunk_size * in struct flashchip to do this properly. All chips using * write_jedec have page_size set to max_writechunk_size, so * we're OK for now. */ - int page_size = flash->page_size; + unsigned int page_size = flash->page_size;
/* Warning: This loop has a very unusual condition and body. * The loop needs to go through each page with at least one affected @@ -461,7 +461,7 @@ int write_jedec(struct flashchip *flash, uint8_t *buf, int start, int len) int erase_chip_block_jedec(struct flashchip *flash, unsigned int addr, unsigned int blocksize) { - int mask; + unsigned int mask;
mask = getaddrmask(flash); if ((addr != 0) || (blocksize != flash->total_size * 1024)) { @@ -474,7 +474,7 @@ int erase_chip_block_jedec(struct flashchip *flash, unsigned int addr,
int probe_jedec(struct flashchip *flash) { - int mask; + unsigned int mask;
mask = getaddrmask(flash); return probe_jedec_common(flash, mask); @@ -482,7 +482,7 @@ int probe_jedec(struct flashchip *flash)
int erase_sector_jedec(struct flashchip *flash, unsigned int page, unsigned int size) { - int mask; + unsigned int mask;
mask = getaddrmask(flash); return erase_sector_jedec_common(flash, page, size, mask); @@ -490,7 +490,7 @@ int erase_sector_jedec(struct flashchip *flash, unsigned int page, unsigned int
int erase_block_jedec(struct flashchip *flash, unsigned int page, unsigned int size) { - int mask; + unsigned int mask;
mask = getaddrmask(flash); return erase_block_jedec_common(flash, page, size, mask); @@ -498,7 +498,7 @@ int erase_block_jedec(struct flashchip *flash, unsigned int page, unsigned int s
int erase_chip_jedec(struct flashchip *flash) { - int mask; + unsigned int mask;
mask = getaddrmask(flash); return erase_chip_jedec_common(flash, mask); diff --git a/linux_spi.c b/linux_spi.c index de82def..44a2fcd 100644 --- a/linux_spi.c +++ b/linux_spi.c @@ -36,10 +36,10 @@ static int fd = -1; static int linux_spi_shutdown(void *data); static int linux_spi_send_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *txbuf, unsigned char *rxbuf); -static int linux_spi_read(struct flashchip *flash, uint8_t *buf, int start, - int len); +static int linux_spi_read(struct flashchip *flash, uint8_t *buf, + unsigned int start, unsigned int len); static int linux_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_linux = { .type = SPI_CONTROLLER_LINUX, @@ -131,14 +131,14 @@ static int linux_spi_send_command(unsigned int writecnt, unsigned int readcnt, return 0; }
-static int linux_spi_read(struct flashchip *flash, uint8_t *buf, int start, - int len) +static int linux_spi_read(struct flashchip *flash, uint8_t *buf, + unsigned int start, unsigned int len) { - return spi_read_chunked(flash, buf, start, len, getpagesize()); + return spi_read_chunked(flash, buf, start, len, (unsigned)getpagesize()); }
static int linux_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, getpagesize() - 4); + return spi_write_chunked(flash, buf, start, len, ((unsigned)getpagesize()) - 4); } 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/pm49fl00x.c b/pm49fl00x.c index 28052e5..13992a3 100644 --- a/pm49fl00x.c +++ b/pm49fl00x.c @@ -22,10 +22,10 @@
#include "flash.h"
-static void write_lockbits_49fl00x(chipaddr bios, int size, - unsigned char bits, int block_size) +static void write_lockbits_49fl00x(chipaddr bios, unsigned int size, + unsigned char bits, unsigned int block_size) { - int i, left = size; + unsigned int i, left = size;
for (i = 0; left >= block_size; i++, left -= block_size) { /* pm49fl002 */ diff --git a/programmer.h b/programmer.h index 73b94c1..c92713a 100644 --- a/programmer.h +++ b/programmer.h @@ -556,23 +556,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 */ @@ -610,7 +610,7 @@ void serprog_chip_readn(uint8_t *buf, const chipaddr addr, size_t len); 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, int start, int len); +int serprog_spi_read(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len); #endif
/* serial.c */ diff --git a/serprog.c b/serprog.c index 9d554c9..94ae1c6 100644 --- a/serprog.c +++ b/serprog.c @@ -707,7 +707,7 @@ uint8_t serprog_chip_readb(const chipaddr addr) /* Local version that really does the job, doesn't care of max_read_n. */ static void sp_do_read_n(uint8_t * buf, const chipaddr addr, size_t len) { - int rd_bytes = 0; + unsigned int rd_bytes = 0; unsigned char sbuf[6]; msg_pspew("%s: addr=0x%lx len=%lu\n", __func__, addr, (unsigned long)len); /* Stream the read-n -- as above. */ @@ -725,7 +725,7 @@ static void sp_do_read_n(uint8_t * buf, const chipaddr addr, size_t len) int r = read(sp_fd, buf + rd_bytes, len - rd_bytes); if (r <= 0) sp_die("Error: cannot read read-n data"); - rd_bytes += r; + rd_bytes += (unsigned int)r; } while (rd_bytes != len); return; } @@ -795,11 +795,10 @@ int serprog_spi_send_command(unsigned int writecnt, unsigned int readcnt, * 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, int start, int len) +int serprog_spi_read(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len) { - int i; - int cur_len; - const int max_read = spi_programmer_serprog.max_data_read; + unsigned int i, cur_len; + const unsigned int max_read = spi_programmer_serprog.max_data_read; for (i = 0; i < len; i += cur_len) { int ret; cur_len = min(max_read, (len - i)); diff --git a/spi.c b/spi.c index f02f091..60f77b0 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,9 +121,9 @@ 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; + unsigned int addrbase = 0; if (!spi_programmer->read) { msg_perr("%s called, but SPI read is unsupported on this " "hardware. Please report a bug at " @@ -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..8e85136 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,12 +972,11 @@ 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; - int page_size = flash->page_size; - int toread; + unsigned int i, j, starthere, lenhere, toread; + unsigned int page_size = flash->page_size;
/* Warning: This loop has a very unusual condition and body. * The loop needs to go through each page with at least one affected @@ -1012,17 +1011,16 @@ 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; + unsigned int i, j, starthere, lenhere, towrite; /* FIXME: page_size is the wrong variable. We need max_writechunk_size * in struct flashchip to do this properly. All chips using * spi_chip_write_256 have page_size set to max_writechunk_size, so * we're OK for now. */ - int page_size = flash->page_size; - int towrite; + unsigned int page_size = flash->page_size;
/* Warning: This loop has a very unusual condition and body. * The loop needs to go through each page with at least one affected @@ -1061,9 +1059,10 @@ 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; + unsigned int i; + int result = 0;
for (i = start; i < start + len; i++) { result = spi_byte_program(i, buf[i - start]); @@ -1076,7 +1075,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/sst49lfxxxc.c b/sst49lfxxxc.c index 28f6cd0..c3ef823 100644 --- a/sst49lfxxxc.c +++ b/sst49lfxxxc.c @@ -35,7 +35,7 @@ static int write_lockbits_block_49lfxxxc(struct flashchip *flash, unsigned long static int write_lockbits_49lfxxxc(struct flashchip *flash, unsigned char bits) { chipaddr registers = flash->virtual_registers; - int i, left = flash->total_size * 1024; + unsigned int i, left = flash->total_size * 1024; unsigned long address;
msg_cdbg("\nbios=0x%08lx\n", registers); diff --git a/w39.c b/w39.c index 2e9aa4f..a2c1014 100644 --- a/w39.c +++ b/w39.c @@ -21,7 +21,7 @@
#include "flash.h"
-static int printlock_w39_fwh_block(struct flashchip *flash, int offset) +static int printlock_w39_fwh_block(struct flashchip *flash, unsigned int offset) { chipaddr wrprotect = flash->virtual_registers + offset + 2; uint8_t locking; @@ -59,7 +59,7 @@ static int printlock_w39_fwh_block(struct flashchip *flash, int offset) return (locking & ((1 << 2) | (1 << 0))) ? -1 : 0; }
-static int unlock_w39_fwh_block(struct flashchip *flash, int offset) +static int unlock_w39_fwh_block(struct flashchip *flash, unsigned int offset) { chipaddr wrprotect = flash->virtual_registers + offset + 2; uint8_t locking; @@ -80,7 +80,7 @@ static int unlock_w39_fwh_block(struct flashchip *flash, int offset) return 0; }
-static uint8_t w39_idmode_readb(struct flashchip *flash, int offset) +static uint8_t w39_idmode_readb(struct flashchip *flash, unsigned int offset) { chipaddr bios = flash->virtual_memory; uint8_t val; @@ -127,7 +127,7 @@ static int printlock_w39_bootblock_64k16k(uint8_t lock) return 0; }
-static int printlock_w39_common(struct flashchip *flash, int offset) +static int printlock_w39_common(struct flashchip *flash, unsigned int offset) { uint8_t lock;
@@ -138,7 +138,7 @@ static int printlock_w39_common(struct flashchip *flash, int offset)
static int printlock_w39_fwh(struct flashchip *flash) { - int i, total_size = flash->total_size * 1024; + unsigned int i, total_size = flash->total_size * 1024; int ret = 0; /* Print lock status of the complete chip */ @@ -150,7 +150,7 @@ static int printlock_w39_fwh(struct flashchip *flash)
static int unlock_w39_fwh(struct flashchip *flash) { - int i, total_size = flash->total_size * 1024; + unsigned int i, total_size = flash->total_size * 1024; /* Unlock the complete chip */ for (i = 0; i < total_size; i += flash->page_size) 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); }