From 6f5b1873d7b986fe7b3bc1f267bae9f7649630a5 Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Sat, 14 Mar 2015 15:18:22 -0700 Subject: [PATCH] Use size_t for sizes in flash functions. Fix all sign compare warnings. --- src/Makefile | 1 - src/cortexm.c | 4 ++-- src/include/target.h | 4 ++-- src/kinetis.c | 8 ++++---- src/lmi.c | 8 ++++---- src/lpc11xx.c | 12 +++++------ src/lpc43xx.c | 10 +++++----- src/nrf51.c | 8 ++++---- src/platforms/libftdi/platform.c | 2 +- src/sam3x.c | 12 +++++------ src/samd.c | 8 ++++---- src/stm32f1.c | 17 ++++++++-------- src/stm32f4.c | 8 ++++---- src/stm32l0.c | 34 ++++++++++++++++---------------- src/stm32l1.c | 9 +++++---- 15 files changed, 73 insertions(+), 72 deletions(-) diff --git a/src/Makefile b/src/Makefile index 7ea7865..80e86fe 100644 --- a/src/Makefile +++ b/src/Makefile @@ -10,7 +10,6 @@ endif BUILDDATE := `date +"%Y%m%d"` CFLAGS += -Wall -Wextra -Wno-char-subscripts\ - -Wno-sign-compare \ -O2 -std=gnu99 -g3 -DBUILDDATE=\"$(BUILDDATE)\"\ -I. -Iinclude -Iplatforms/common -I$(PLATFORM_DIR) \ -DVERSION_SUFFIX=\"`../scripts/setlocalversion`\" -MD diff --git a/src/cortexm.c b/src/cortexm.c index b3b657f..b1d3569 100644 --- a/src/cortexm.c +++ b/src/cortexm.c @@ -757,13 +757,13 @@ static bool cortexm_vector_catch(target *t, int argc, char *argv[]) const char *vectors[] = {"reset", NULL, NULL, NULL, "mm", "nocp", "chk", "stat", "bus", "int", "hard"}; uint32_t tmp = 0; - unsigned i, j; + unsigned i; if ((argc < 3) || ((argv[1][0] != 'e') && (argv[1][0] != 'd'))) { gdb_out("usage: monitor vector_catch (enable|disable) " "(hard|int|bus|stat|chk|nocp|mm|reset)\n"); } else { - for (j = 0; j < argc; j++) + for (int j = 0; j < argc; j++) for (i = 0; i < sizeof(vectors) / sizeof(char*); i++) { if (vectors[i] && !strcmp(vectors[i], argv[j])) tmp |= 1 << i; diff --git a/src/include/target.h b/src/include/target.h index a2369e3..5db79a7 100644 --- a/src/include/target.h +++ b/src/include/target.h @@ -180,9 +180,9 @@ struct target_s { /* Flash memory access functions */ const char *xml_mem_map; - int (*flash_erase)(struct target_s *target, uint32_t addr, int len); + int (*flash_erase)(struct target_s *target, uint32_t addr, size_t len); int (*flash_write)(struct target_s *target, uint32_t dest, - const uint8_t *src, int len); + const uint8_t *src, size_t len); /* Host I/O support */ void (*hostio_reply)(target *t, int32_t retcode, uint32_t errcode); diff --git a/src/kinetis.c b/src/kinetis.c index 4b7cf31..b260d2a 100644 --- a/src/kinetis.c +++ b/src/kinetis.c @@ -54,9 +54,9 @@ #define KL25_PAGESIZE 0x400 -static int kl25_flash_erase(struct target_s *target, uint32_t addr, int len); +static int kl25_flash_erase(struct target_s *target, uint32_t addr, size_t len); static int kl25_flash_write(struct target_s *target, uint32_t dest, - const uint8_t *src, int len); + const uint8_t *src, size_t len); static const char kl25_xml_memory_map[] = "" /* ">2)+2]; data[0] = dest; diff --git a/src/lpc11xx.c b/src/lpc11xx.c index d9e918e..b6309c2 100644 --- a/src/lpc11xx.c +++ b/src/lpc11xx.c @@ -63,9 +63,9 @@ static const char lpc8xx_driver[] = "lpc8xx"; static const char lpc11xx_driver[] = "lpc11xx"; static void lpc11x_iap_call(struct target_s *target, struct flash_param *param, unsigned param_len); static int lpc11xx_flash_prepare(struct target_s *target, uint32_t addr, int len); -static int lpc11xx_flash_erase(struct target_s *target, uint32_t addr, int len); +static int lpc11xx_flash_erase(struct target_s *target, uint32_t addr, size_t len); static int lpc11xx_flash_write(struct target_s *target, uint32_t dest, const uint8_t *src, - int len); + size_t len); /* * Note that this memory map is actually for the largest of the lpc11xx devices; @@ -220,7 +220,7 @@ lpc11xx_flash_prepare(struct target_s *target, uint32_t addr, int len) } static int -lpc11xx_flash_erase(struct target_s *target, uint32_t addr, int len) +lpc11xx_flash_erase(struct target_s *target, uint32_t addr, size_t len) { if (addr % flash_page_size(target)) @@ -249,7 +249,7 @@ lpc11xx_flash_erase(struct target_s *target, uint32_t addr, int len) } static int -lpc11xx_flash_write(struct target_s *target, uint32_t dest, const uint8_t *src, int len) +lpc11xx_flash_write(struct target_s *target, uint32_t dest, const uint8_t *src, size_t len) { unsigned first_chunk = dest / IAP_PGM_CHUNKSIZE; unsigned last_chunk = (dest + len - 1) / IAP_PGM_CHUNKSIZE; @@ -258,7 +258,7 @@ lpc11xx_flash_write(struct target_s *target, uint32_t dest, const uint8_t *src, for (chunk = first_chunk; chunk <= last_chunk; chunk++) { - DEBUG("chunk %u len %d\n", chunk, len); + DEBUG("chunk %u len %zu\n", chunk, len); /* first and last chunk may require special handling */ if ((chunk == first_chunk) || (chunk == last_chunk)) { @@ -266,7 +266,7 @@ lpc11xx_flash_write(struct target_s *target, uint32_t dest, const uint8_t *src, memset(flash_pgm.data, 0xff, sizeof(flash_pgm.data)); /* copy as much as fits */ - int copylen = IAP_PGM_CHUNKSIZE - chunk_offset; + size_t copylen = IAP_PGM_CHUNKSIZE - chunk_offset; if (copylen > len) copylen = len; memcpy(&flash_pgm.data[chunk_offset], src, copylen); diff --git a/src/lpc43xx.c b/src/lpc43xx.c index 3940fed..eca7338 100644 --- a/src/lpc43xx.c +++ b/src/lpc43xx.c @@ -127,9 +127,9 @@ static void lpc43xx_iap_call(struct target_s *target, struct flash_param *param, unsigned param_len); static int lpc43xx_flash_prepare(struct target_s *target, uint32_t addr, int len); -static int lpc43xx_flash_erase(struct target_s *target, uint32_t addr, int len); +static int lpc43xx_flash_erase(struct target_s *target, uint32_t addr, size_t len); static int lpc43xx_flash_write(struct target_s *target, - uint32_t dest, const uint8_t *src, int len); + uint32_t dest, const uint8_t *src, size_t len); static void lpc43xx_set_internal_clock(struct target_s *target); static void lpc43xx_wdt_set_period(struct target_s *target); static void lpc43xx_wdt_pet(struct target_s *target); @@ -384,7 +384,7 @@ static int lpc43xx_flash_prepare(struct target_s *target, uint32_t addr, int len return 0; } -static int lpc43xx_flash_erase(struct target_s *target, uint32_t addr, int len) +static int lpc43xx_flash_erase(struct target_s *target, uint32_t addr, size_t len) { struct flash_program flash_pgm; @@ -433,7 +433,7 @@ static void lpc43xx_set_internal_clock(struct target_s *target) } static int lpc43xx_flash_write(struct target_s *target, - uint32_t dest, const uint8_t *src, int len) + uint32_t dest, const uint8_t *src, size_t len) { unsigned first_chunk = dest / IAP_PGM_CHUNKSIZE; unsigned last_chunk = (dest + len - 1) / IAP_PGM_CHUNKSIZE; @@ -455,7 +455,7 @@ static int lpc43xx_flash_write(struct target_s *target, memset(flash_pgm.data, 0xff, sizeof(flash_pgm.data)); /* copy as much as fits */ - int copylen = IAP_PGM_CHUNKSIZE - chunk_offset; + size_t copylen = IAP_PGM_CHUNKSIZE - chunk_offset; if (copylen > len) copylen = len; diff --git a/src/nrf51.c b/src/nrf51.c index 6c1a8b9..55c9a58 100644 --- a/src/nrf51.c +++ b/src/nrf51.c @@ -27,9 +27,9 @@ #include "command.h" #include "gdb_packet.h" -static int nrf51_flash_erase(struct target_s *target, uint32_t addr, int len); +static int nrf51_flash_erase(struct target_s *target, uint32_t addr, size_t len); static int nrf51_flash_write(struct target_s *target, uint32_t dest, - const uint8_t *src, int len); + const uint8_t *src, size_t len); static bool nrf51_cmd_erase_all(target *t); static bool nrf51_cmd_read_hwid(target *t); @@ -163,7 +163,7 @@ bool nrf51_probe(struct target_s *target) return false; } -static int nrf51_flash_erase(struct target_s *target, uint32_t addr, int len) +static int nrf51_flash_erase(struct target_s *target, uint32_t addr, size_t len) { ADIv5_AP_t *ap = adiv5_target_ap(target); @@ -210,7 +210,7 @@ static int nrf51_flash_erase(struct target_s *target, uint32_t addr, int len) } static int nrf51_flash_write(struct target_s *target, uint32_t dest, - const uint8_t *src, int len) + const uint8_t *src, size_t len) { ADIv5_AP_t *ap = adiv5_target_ap(target); uint32_t offset = dest % 4; diff --git a/src/platforms/libftdi/platform.c b/src/platforms/libftdi/platform.c index e53f011..634090d 100644 --- a/src/platforms/libftdi/platform.c +++ b/src/platforms/libftdi/platform.c @@ -121,7 +121,7 @@ void platform_init(int argc, char **argv) { int err; int c; - int index = 0; + unsigned index = 0; char *serial = NULL; char * cablename = "ftdi"; uint8_t ftdi_init[9] = {TCK_DIVISOR, 0x01, 0x00, SET_BITS_LOW, 0,0, diff --git a/src/sam3x.c b/src/sam3x.c index 902f267..7141cb5 100644 --- a/src/sam3x.c +++ b/src/sam3x.c @@ -28,9 +28,9 @@ #include "command.h" #include "gdb_packet.h" -static int sam3x_flash_erase(struct target_s *target, uint32_t addr, int len); +static int sam3x_flash_erase(struct target_s *target, uint32_t addr, size_t len); static int sam3x_flash_write(struct target_s *target, uint32_t dest, - const uint8_t *src, int len); + const uint8_t *src, size_t len); static bool sam3x_cmd_gpnvm_get(target *t); static bool sam3x_cmd_gpnvm_set(target *t, int argc, char *argv[]); @@ -285,7 +285,7 @@ sam3x_flash_base(struct target_s *target, uint32_t addr, uint32_t *offset) return SAM3N_EEFC_BASE; } -static int sam3x_flash_erase(struct target_s *target, uint32_t addr, int len) +static int sam3x_flash_erase(struct target_s *target, uint32_t addr, size_t len) { uint32_t offset; uint32_t base = sam3x_flash_base(target, addr, &offset); @@ -341,7 +341,7 @@ static int sam3x_flash_erase(struct target_s *target, uint32_t addr, int len) } static int sam3x_flash_write(struct target_s *target, uint32_t dest, - const uint8_t *src, int len) + const uint8_t *src, size_t len) { unsigned page_size; if (strcmp(target->driver, "Atmel SAM4S") == 0) { @@ -359,7 +359,7 @@ static int sam3x_flash_write(struct target_s *target, uint32_t dest, for (unsigned chunk = first_chunk; chunk <= last_chunk; chunk++) { - DEBUG("chunk %u len %d\n", chunk, len); + DEBUG("chunk %u len %zu\n", chunk, len); /* first and last chunk may require special handling */ if ((chunk == first_chunk) || (chunk == last_chunk)) { @@ -367,7 +367,7 @@ static int sam3x_flash_write(struct target_s *target, uint32_t dest, memset(buf, 0xff, sizeof(buf)); /* copy as much as fits */ - int copylen = page_size - offset; + size_t copylen = page_size - offset; if (copylen > len) copylen = len; memcpy(&buf[offset], src, copylen); diff --git a/src/samd.c b/src/samd.c index 1a7a553..6f73956 100644 --- a/src/samd.c +++ b/src/samd.c @@ -40,9 +40,9 @@ #include "gdb_packet.h" #include "cortexm.h" -static int samd_flash_erase(struct target_s *target, uint32_t addr, int len); +static int samd_flash_erase(struct target_s *target, uint32_t addr, size_t len); static int samd_flash_write(struct target_s *target, uint32_t dest, - const uint8_t *src, int len); + const uint8_t *src, size_t len); static bool samd_cmd_erase_all(target *t); static bool samd_cmd_lock_flash(target *t); @@ -479,7 +479,7 @@ static void samd_unlock_current_address(struct target_s *target) /** * Erase flash row by row */ -static int samd_flash_erase(struct target_s *target, uint32_t addr, int len) +static int samd_flash_erase(struct target_s *target, uint32_t addr, size_t len) { ADIv5_AP_t *ap = adiv5_target_ap(target); @@ -515,7 +515,7 @@ static int samd_flash_erase(struct target_s *target, uint32_t addr, int len) * Write flash page by page */ static int samd_flash_write(struct target_s *target, uint32_t dest, - const uint8_t *src, int len) + const uint8_t *src, size_t len) { ADIv5_AP_t *ap = adiv5_target_ap(target); diff --git a/src/stm32f1.c b/src/stm32f1.c index 017196a..405bc1a 100644 --- a/src/stm32f1.c +++ b/src/stm32f1.c @@ -45,12 +45,12 @@ const struct command_s stm32f1_cmd_list[] = { }; -static int stm32md_flash_erase(struct target_s *target, uint32_t addr, int len); -static int stm32hd_flash_erase(struct target_s *target, uint32_t addr, int len); -static int stm32f1_flash_erase(struct target_s *target, uint32_t addr, int len, +static int stm32md_flash_erase(struct target_s *target, uint32_t addr, size_t len); +static int stm32hd_flash_erase(struct target_s *target, uint32_t addr, size_t len); +static int stm32f1_flash_erase(struct target_s *target, uint32_t addr, size_t len, uint32_t pagesize); static int stm32f1_flash_write(struct target_s *target, uint32_t dest, - const uint8_t *src, int len); + const uint8_t *src, size_t len); static const char stm32f1_driver_str[] = "STM32, Medium density."; static const char stm32hd_driver_str[] = "STM32, High density."; @@ -229,7 +229,8 @@ static void stm32f1_flash_unlock(ADIv5_AP_t *ap) adiv5_ap_mem_write(ap, FLASH_KEYR, KEY2); } -static int stm32f1_flash_erase(struct target_s *target, uint32_t addr, int len, uint32_t pagesize) +static int stm32f1_flash_erase(struct target_s *target, uint32_t addr, + size_t len, uint32_t pagesize) { ADIv5_AP_t *ap = adiv5_target_ap(target); uint16_t sr; @@ -264,18 +265,18 @@ static int stm32f1_flash_erase(struct target_s *target, uint32_t addr, int len, return 0; } -static int stm32hd_flash_erase(struct target_s *target, uint32_t addr, int len) +static int stm32hd_flash_erase(struct target_s *target, uint32_t addr, size_t len) { return stm32f1_flash_erase(target, addr, len, 0x800); } -static int stm32md_flash_erase(struct target_s *target, uint32_t addr, int len) +static int stm32md_flash_erase(struct target_s *target, uint32_t addr, size_t len) { return stm32f1_flash_erase(target, addr, len, 0x400); } static int stm32f1_flash_write(struct target_s *target, uint32_t dest, - const uint8_t *src, int len) + const uint8_t *src, size_t len) { ADIv5_AP_t *ap = adiv5_target_ap(target); uint32_t offset = dest % 4; diff --git a/src/stm32f4.c b/src/stm32f4.c index bc3572f..fac097a 100644 --- a/src/stm32f4.c +++ b/src/stm32f4.c @@ -46,9 +46,9 @@ const struct command_s stm32f4_cmd_list[] = { }; -static int stm32f4_flash_erase(struct target_s *target, uint32_t addr, int len); +static int stm32f4_flash_erase(struct target_s *target, uint32_t addr, size_t len); static int stm32f4_flash_write(struct target_s *target, uint32_t dest, - const uint8_t *src, int len); + const uint8_t *src, size_t len); static const char stm32f4_driver_str[] = "STM32F4xx"; @@ -189,7 +189,7 @@ static void stm32f4_flash_unlock(ADIv5_AP_t *ap) } } -static int stm32f4_flash_erase(struct target_s *target, uint32_t addr, int len) +static int stm32f4_flash_erase(struct target_s *target, uint32_t addr, size_t len) { ADIv5_AP_t *ap = adiv5_target_ap(target); uint16_t sr; @@ -237,7 +237,7 @@ static int stm32f4_flash_erase(struct target_s *target, uint32_t addr, int len) } static int stm32f4_flash_write(struct target_s *target, uint32_t dest, - const uint8_t *src, int len) + const uint8_t *src, size_t len) { ADIv5_AP_t *ap = adiv5_target_ap(target); uint32_t offset = dest % 4; diff --git a/src/stm32l0.c b/src/stm32l0.c index 0de028f..2e30035 100644 --- a/src/stm32l0.c +++ b/src/stm32l0.c @@ -125,32 +125,32 @@ static int inhibit_stubs; /* Local option to force non-stub flash IO */ static int stm32lx_nvm_erase(struct target_s* target, - uint32_t addr, int len); + uint32_t addr, size_t len); static int stm32lx_nvm_write(struct target_s* target, uint32_t destination, const uint8_t* source, - int size); + size_t size); static int stm32lx_nvm_prog_erase(struct target_s* target, - uint32_t addr, int len); + uint32_t addr, size_t len); static int stm32lx_nvm_prog_write(struct target_s* target, uint32_t destination, const uint8_t* source, - int size); + size_t size); static int stm32lx_nvm_prog_erase_stubbed(struct target_s* target, - uint32_t addr, int len); + uint32_t addr, size_t len); static int stm32lx_nvm_prog_write_stubbed(struct target_s* target, uint32_t destination, const uint8_t* source, - int size); + size_t size); static int stm32lx_nvm_data_erase(struct target_s* target, - uint32_t addr, int len); + uint32_t addr, size_t len); static int stm32lx_nvm_data_write(struct target_s* target, uint32_t destination, const uint8_t* source, - int size); + size_t size); static bool stm32lx_cmd_option (target* t, int argc, char** argv); static bool stm32lx_cmd_eeprom (target* t, int argc, char** argv); @@ -371,7 +371,7 @@ static bool stm32lx_nvm_opt_unlock(ADIv5_AP_t* ap, uint32_t nvm) when the MCU hasn't entered a fault state(see NOTES). The flash array is erased for all pages from addr to addr+len inclusive. */ static int stm32lx_nvm_prog_erase_stubbed(struct target_s* target, - uint32_t addr, int size) + uint32_t addr, size_t size) { struct stm32lx_nvm_stub_info info; const uint32_t nvm = stm32lx_nvm_phys(target); @@ -417,7 +417,7 @@ static int stm32lx_nvm_prog_erase_stubbed(struct target_s* target, static int stm32lx_nvm_prog_write_stubbed(struct target_s* target, uint32_t destination, const uint8_t* source, - int size) + size_t size) { struct stm32lx_nvm_stub_info info; const uint32_t nvm = stm32lx_nvm_phys(target); @@ -491,7 +491,7 @@ static int stm32lx_nvm_prog_write_stubbed(struct target_s* target, /** Erase a region of NVM for STM32Lx. This is the lead function and it will invoke an implementation, stubbed or not depending on the options and the range of addresses. */ -static int stm32lx_nvm_erase(struct target_s* target, uint32_t addr, int size) +static int stm32lx_nvm_erase(struct target_s* target, uint32_t addr, size_t size) { if (addr >= STM32Lx_NVM_EEPROM_PHYS) return stm32lx_nvm_data_erase(target, addr, size); @@ -515,7 +515,7 @@ static int stm32lx_nvm_erase(struct target_s* target, uint32_t addr, int size) static int stm32lx_nvm_write(struct target_s* target, uint32_t destination, const uint8_t* source, - int size) + size_t size) { if (destination >= STM32Lx_NVM_EEPROM_PHYS) return stm32lx_nvm_data_write(target, destination, source, @@ -556,7 +556,7 @@ static int stm32lx_nvm_write(struct target_s* target, flash array is erased for all pages from addr to addr+len inclusive. NVM register file address chosen from target. */ static int stm32lx_nvm_prog_erase(struct target_s* target, - uint32_t addr, int len) + uint32_t addr, size_t len) { ADIv5_AP_t* ap = adiv5_target_ap(target); const size_t page_size = stm32lx_nvm_prog_page_size(target); @@ -617,7 +617,7 @@ static int stm32lx_nvm_prog_erase(struct target_s* target, static int stm32lx_nvm_prog_write(struct target_s* target, uint32_t destination, const uint8_t* source_8, - int size) + size_t size) { ADIv5_AP_t* ap = adiv5_target_ap(target); const uint32_t nvm = stm32lx_nvm_phys(target); @@ -705,7 +705,7 @@ static int stm32lx_nvm_prog_write(struct target_s* target, addr+len, inclusive, on a word boundary. NVM register file address chosen from target. */ static int stm32lx_nvm_data_erase(struct target_s* target, - uint32_t addr, int len) + uint32_t addr, size_t len) { ADIv5_AP_t* ap = adiv5_target_ap(target); const size_t page_size = stm32lx_nvm_data_page_size(target); @@ -763,7 +763,7 @@ static int stm32lx_nvm_data_erase(struct target_s* target, static int stm32lx_nvm_data_write(struct target_s* target, uint32_t destination, const uint8_t* source_8, - int size) + size_t size) { ADIv5_AP_t* ap = adiv5_target_ap(target); const uint32_t nvm = stm32lx_nvm_phys(target); @@ -933,7 +933,7 @@ static bool stm32lx_cmd_option(target* t, int argc, char** argv) goto usage; /* Report the current option values */ - for(int i = 0; i < opt_size; i += sizeof(uint32_t)) { + for(unsigned i = 0; i < opt_size; i += sizeof(uint32_t)) { uint32_t addr = STM32Lx_NVM_OPT_PHYS + i; uint32_t val = adiv5_ap_mem_read(ap, addr); gdb_outf("0x%08x: 0x%04x 0x%04x %s\n", diff --git a/src/stm32l1.c b/src/stm32l1.c index 227f67c..86298e5 100644 --- a/src/stm32l1.c +++ b/src/stm32l1.c @@ -35,9 +35,10 @@ #include "command.h" #include "gdb_packet.h" -static int stm32l1_flash_erase(struct target_s *target, uint32_t addr, int len); +static int stm32l1_flash_erase(struct target_s *target, uint32_t addr, + size_t len); static int stm32l1_flash_write(struct target_s *target, uint32_t dest, - const uint8_t *src, int len); + const uint8_t *src, size_t len); static const char stm32l1_driver_str[] = "STM32L1xx"; @@ -112,7 +113,7 @@ static void stm32l1_flash_unlock(ADIv5_AP_t *ap) adiv5_ap_mem_write(ap, STM32L1_FLASH_PRGKEYR, STM32L1_PRGKEY2); } -static int stm32l1_flash_erase(struct target_s *target, uint32_t addr, int len) +static int stm32l1_flash_erase(struct target_s *target, uint32_t addr, size_t len) { ADIv5_AP_t *ap = adiv5_target_ap(target); uint16_t sr; @@ -150,7 +151,7 @@ static int stm32l1_flash_erase(struct target_s *target, uint32_t addr, int len) } static int stm32l1_flash_write(struct target_s *target, uint32_t dest, - const uint8_t *src, int len) + const uint8_t *src, size_t len) { ADIv5_AP_t *ap = adiv5_target_ap(target); uint16_t sr;