Use size_t for sizes in flash functions. Fix all sign compare warnings.

This commit is contained in:
Gareth McMullin 2015-03-14 15:18:22 -07:00
parent f5c856af3b
commit 6f5b1873d7
15 changed files with 73 additions and 72 deletions

View File

@ -10,7 +10,6 @@ endif
BUILDDATE := `date +"%Y%m%d"` BUILDDATE := `date +"%Y%m%d"`
CFLAGS += -Wall -Wextra -Wno-char-subscripts\ CFLAGS += -Wall -Wextra -Wno-char-subscripts\
-Wno-sign-compare \
-O2 -std=gnu99 -g3 -DBUILDDATE=\"$(BUILDDATE)\"\ -O2 -std=gnu99 -g3 -DBUILDDATE=\"$(BUILDDATE)\"\
-I. -Iinclude -Iplatforms/common -I$(PLATFORM_DIR) \ -I. -Iinclude -Iplatforms/common -I$(PLATFORM_DIR) \
-DVERSION_SUFFIX=\"`../scripts/setlocalversion`\" -MD -DVERSION_SUFFIX=\"`../scripts/setlocalversion`\" -MD

View File

@ -757,13 +757,13 @@ static bool cortexm_vector_catch(target *t, int argc, char *argv[])
const char *vectors[] = {"reset", NULL, NULL, NULL, "mm", "nocp", const char *vectors[] = {"reset", NULL, NULL, NULL, "mm", "nocp",
"chk", "stat", "bus", "int", "hard"}; "chk", "stat", "bus", "int", "hard"};
uint32_t tmp = 0; uint32_t tmp = 0;
unsigned i, j; unsigned i;
if ((argc < 3) || ((argv[1][0] != 'e') && (argv[1][0] != 'd'))) { if ((argc < 3) || ((argv[1][0] != 'e') && (argv[1][0] != 'd'))) {
gdb_out("usage: monitor vector_catch (enable|disable) " gdb_out("usage: monitor vector_catch (enable|disable) "
"(hard|int|bus|stat|chk|nocp|mm|reset)\n"); "(hard|int|bus|stat|chk|nocp|mm|reset)\n");
} else { } else {
for (j = 0; j < argc; j++) for (int j = 0; j < argc; j++)
for (i = 0; i < sizeof(vectors) / sizeof(char*); i++) { for (i = 0; i < sizeof(vectors) / sizeof(char*); i++) {
if (vectors[i] && !strcmp(vectors[i], argv[j])) if (vectors[i] && !strcmp(vectors[i], argv[j]))
tmp |= 1 << i; tmp |= 1 << i;

View File

@ -180,9 +180,9 @@ struct target_s {
/* Flash memory access functions */ /* Flash memory access functions */
const char *xml_mem_map; 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, 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 */ /* Host I/O support */
void (*hostio_reply)(target *t, int32_t retcode, uint32_t errcode); void (*hostio_reply)(target *t, int32_t retcode, uint32_t errcode);

View File

@ -54,9 +54,9 @@
#define KL25_PAGESIZE 0x400 #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, 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[] = "<?xml version=\"1.0\"?>" static const char kl25_xml_memory_map[] = "<?xml version=\"1.0\"?>"
/* "<!DOCTYPE memory-map " /* "<!DOCTYPE memory-map "
@ -121,7 +121,7 @@ kl25_command(struct target_s *t, uint8_t cmd, uint32_t addr, const uint8_t data[
return true; return true;
} }
static int kl25_flash_erase(struct target_s *t, uint32_t addr, int len) static int kl25_flash_erase(struct target_s *t, uint32_t addr, size_t len)
{ {
addr &= ~(KL25_PAGESIZE - 1); addr &= ~(KL25_PAGESIZE - 1);
len = (len + KL25_PAGESIZE - 1) & ~(KL25_PAGESIZE - 1); len = (len + KL25_PAGESIZE - 1) & ~(KL25_PAGESIZE - 1);
@ -135,7 +135,7 @@ static int kl25_flash_erase(struct target_s *t, uint32_t addr, int len)
} }
static int kl25_flash_write(struct target_s *t, uint32_t dest, static int kl25_flash_write(struct target_s *t, uint32_t dest,
const uint8_t *src, int len) const uint8_t *src, size_t len)
{ {
/* FIXME handle misaligned start and end of sections */ /* FIXME handle misaligned start and end of sections */
if ((dest & 3) || (len & 3)) if ((dest & 3) || (len & 3))

View File

@ -31,9 +31,9 @@
#include "adiv5.h" #include "adiv5.h"
#include "target.h" #include "target.h"
static int lmi_flash_erase(struct target_s *target, uint32_t addr, int len); static int lmi_flash_erase(struct target_s *target, uint32_t addr, size_t len);
static int lmi_flash_write(struct target_s *target, uint32_t dest, static int lmi_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 lmi_driver_str[] = "TI Stellaris/Tiva"; static const char lmi_driver_str[] = "TI Stellaris/Tiva";
@ -119,7 +119,7 @@ bool lmi_probe(struct target_s *target)
return false; return false;
} }
int lmi_flash_erase(struct target_s *target, uint32_t addr, int len) int lmi_flash_erase(struct target_s *target, uint32_t addr, size_t len)
{ {
ADIv5_AP_t *ap = adiv5_target_ap(target); ADIv5_AP_t *ap = adiv5_target_ap(target);
uint32_t tmp; uint32_t tmp;
@ -151,7 +151,7 @@ int lmi_flash_erase(struct target_s *target, uint32_t addr, int len)
} }
int lmi_flash_write(struct target_s *target, uint32_t dest, int lmi_flash_write(struct target_s *target, uint32_t dest,
const uint8_t *src, int len) const uint8_t *src, size_t len)
{ {
uint32_t data[(len>>2)+2]; uint32_t data[(len>>2)+2];
data[0] = dest; data[0] = dest;

View File

@ -63,9 +63,9 @@ static const char lpc8xx_driver[] = "lpc8xx";
static const char lpc11xx_driver[] = "lpc11xx"; static const char lpc11xx_driver[] = "lpc11xx";
static void lpc11x_iap_call(struct target_s *target, struct flash_param *param, unsigned param_len); 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_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, 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; * 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 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)) if (addr % flash_page_size(target))
@ -249,7 +249,7 @@ lpc11xx_flash_erase(struct target_s *target, uint32_t addr, int len)
} }
static int 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 first_chunk = dest / IAP_PGM_CHUNKSIZE;
unsigned last_chunk = (dest + len - 1) / 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++) { 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 */ /* first and last chunk may require special handling */
if ((chunk == first_chunk) || (chunk == last_chunk)) { 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)); memset(flash_pgm.data, 0xff, sizeof(flash_pgm.data));
/* copy as much as fits */ /* copy as much as fits */
int copylen = IAP_PGM_CHUNKSIZE - chunk_offset; size_t copylen = IAP_PGM_CHUNKSIZE - chunk_offset;
if (copylen > len) if (copylen > len)
copylen = len; copylen = len;
memcpy(&flash_pgm.data[chunk_offset], src, copylen); memcpy(&flash_pgm.data[chunk_offset], src, copylen);

View File

@ -127,9 +127,9 @@ static void lpc43xx_iap_call(struct target_s *target, struct flash_param *param,
unsigned param_len); unsigned param_len);
static int lpc43xx_flash_prepare(struct target_s *target, static int lpc43xx_flash_prepare(struct target_s *target,
uint32_t addr, int len); 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, 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_set_internal_clock(struct target_s *target);
static void lpc43xx_wdt_set_period(struct target_s *target); static void lpc43xx_wdt_set_period(struct target_s *target);
static void lpc43xx_wdt_pet(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; 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; 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, 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 first_chunk = dest / IAP_PGM_CHUNKSIZE;
unsigned last_chunk = (dest + len - 1) / 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)); memset(flash_pgm.data, 0xff, sizeof(flash_pgm.data));
/* copy as much as fits */ /* copy as much as fits */
int copylen = IAP_PGM_CHUNKSIZE - chunk_offset; size_t copylen = IAP_PGM_CHUNKSIZE - chunk_offset;
if (copylen > len) if (copylen > len)
copylen = len; copylen = len;

View File

@ -27,9 +27,9 @@
#include "command.h" #include "command.h"
#include "gdb_packet.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, 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_erase_all(target *t);
static bool nrf51_cmd_read_hwid(target *t); static bool nrf51_cmd_read_hwid(target *t);
@ -163,7 +163,7 @@ bool nrf51_probe(struct target_s *target)
return false; 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); 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, 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); ADIv5_AP_t *ap = adiv5_target_ap(target);
uint32_t offset = dest % 4; uint32_t offset = dest % 4;

View File

@ -121,7 +121,7 @@ void platform_init(int argc, char **argv)
{ {
int err; int err;
int c; int c;
int index = 0; unsigned index = 0;
char *serial = NULL; char *serial = NULL;
char * cablename = "ftdi"; char * cablename = "ftdi";
uint8_t ftdi_init[9] = {TCK_DIVISOR, 0x01, 0x00, SET_BITS_LOW, 0,0, uint8_t ftdi_init[9] = {TCK_DIVISOR, 0x01, 0x00, SET_BITS_LOW, 0,0,

View File

@ -28,9 +28,9 @@
#include "command.h" #include "command.h"
#include "gdb_packet.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, 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_get(target *t);
static bool sam3x_cmd_gpnvm_set(target *t, int argc, char *argv[]); 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; 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 offset;
uint32_t base = sam3x_flash_base(target, addr, &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, 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; unsigned page_size;
if (strcmp(target->driver, "Atmel SAM4S") == 0) { 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++) { 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 */ /* first and last chunk may require special handling */
if ((chunk == first_chunk) || (chunk == last_chunk)) { 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)); memset(buf, 0xff, sizeof(buf));
/* copy as much as fits */ /* copy as much as fits */
int copylen = page_size - offset; size_t copylen = page_size - offset;
if (copylen > len) if (copylen > len)
copylen = len; copylen = len;
memcpy(&buf[offset], src, copylen); memcpy(&buf[offset], src, copylen);

View File

@ -40,9 +40,9 @@
#include "gdb_packet.h" #include "gdb_packet.h"
#include "cortexm.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, 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_erase_all(target *t);
static bool samd_cmd_lock_flash(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 * 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); 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 * Write flash page by page
*/ */
static int samd_flash_write(struct target_s *target, uint32_t dest, 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); ADIv5_AP_t *ap = adiv5_target_ap(target);

View File

@ -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 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, int 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, int len, static int stm32f1_flash_erase(struct target_s *target, uint32_t addr, size_t len,
uint32_t pagesize); uint32_t pagesize);
static int stm32f1_flash_write(struct target_s *target, uint32_t dest, 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 stm32f1_driver_str[] = "STM32, Medium density.";
static const char stm32hd_driver_str[] = "STM32, High 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); 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); ADIv5_AP_t *ap = adiv5_target_ap(target);
uint16_t sr; uint16_t sr;
@ -264,18 +265,18 @@ static int stm32f1_flash_erase(struct target_s *target, uint32_t addr, int len,
return 0; 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); 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); return stm32f1_flash_erase(target, addr, len, 0x400);
} }
static int stm32f1_flash_write(struct target_s *target, uint32_t dest, 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); ADIv5_AP_t *ap = adiv5_target_ap(target);
uint32_t offset = dest % 4; uint32_t offset = dest % 4;

View File

@ -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, 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"; 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); ADIv5_AP_t *ap = adiv5_target_ap(target);
uint16_t sr; 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, 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); ADIv5_AP_t *ap = adiv5_target_ap(target);
uint32_t offset = dest % 4; uint32_t offset = dest % 4;

View File

@ -125,32 +125,32 @@
static int inhibit_stubs; /* Local option to force non-stub flash IO */ static int inhibit_stubs; /* Local option to force non-stub flash IO */
static int stm32lx_nvm_erase(struct target_s* target, 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, static int stm32lx_nvm_write(struct target_s* target,
uint32_t destination, uint32_t destination,
const uint8_t* source, const uint8_t* source,
int size); size_t size);
static int stm32lx_nvm_prog_erase(struct target_s* target, 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, static int stm32lx_nvm_prog_write(struct target_s* target,
uint32_t destination, uint32_t destination,
const uint8_t* source, const uint8_t* source,
int size); size_t size);
static int stm32lx_nvm_prog_erase_stubbed(struct target_s* target, 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, static int stm32lx_nvm_prog_write_stubbed(struct target_s* target,
uint32_t destination, uint32_t destination,
const uint8_t* source, const uint8_t* source,
int size); size_t size);
static int stm32lx_nvm_data_erase(struct target_s* target, 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, static int stm32lx_nvm_data_write(struct target_s* target,
uint32_t destination, uint32_t destination,
const uint8_t* source, const uint8_t* source,
int size); size_t size);
static bool stm32lx_cmd_option (target* t, int argc, char** argv); static bool stm32lx_cmd_option (target* t, int argc, char** argv);
static bool stm32lx_cmd_eeprom (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 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. */ array is erased for all pages from addr to addr+len inclusive. */
static int stm32lx_nvm_prog_erase_stubbed(struct target_s* target, 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; struct stm32lx_nvm_stub_info info;
const uint32_t nvm = stm32lx_nvm_phys(target); 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, static int stm32lx_nvm_prog_write_stubbed(struct target_s* target,
uint32_t destination, uint32_t destination,
const uint8_t* source, const uint8_t* source,
int size) size_t size)
{ {
struct stm32lx_nvm_stub_info info; struct stm32lx_nvm_stub_info info;
const uint32_t nvm = stm32lx_nvm_phys(target); 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 /** Erase a region of NVM for STM32Lx. This is the lead function and
it will invoke an implementation, stubbed or not depending on the it will invoke an implementation, stubbed or not depending on the
options and the range of addresses. */ 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) if (addr >= STM32Lx_NVM_EEPROM_PHYS)
return stm32lx_nvm_data_erase(target, addr, size); 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, static int stm32lx_nvm_write(struct target_s* target,
uint32_t destination, uint32_t destination,
const uint8_t* source, const uint8_t* source,
int size) size_t size)
{ {
if (destination >= STM32Lx_NVM_EEPROM_PHYS) if (destination >= STM32Lx_NVM_EEPROM_PHYS)
return stm32lx_nvm_data_write(target, destination, source, 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 flash array is erased for all pages from addr to addr+len
inclusive. NVM register file address chosen from target. */ inclusive. NVM register file address chosen from target. */
static int stm32lx_nvm_prog_erase(struct target_s* 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); ADIv5_AP_t* ap = adiv5_target_ap(target);
const size_t page_size = stm32lx_nvm_prog_page_size(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, static int stm32lx_nvm_prog_write(struct target_s* target,
uint32_t destination, uint32_t destination,
const uint8_t* source_8, const uint8_t* source_8,
int size) size_t size)
{ {
ADIv5_AP_t* ap = adiv5_target_ap(target); ADIv5_AP_t* ap = adiv5_target_ap(target);
const uint32_t nvm = stm32lx_nvm_phys(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 addr+len, inclusive, on a word boundary. NVM register file
address chosen from target. */ address chosen from target. */
static int stm32lx_nvm_data_erase(struct target_s* 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); ADIv5_AP_t* ap = adiv5_target_ap(target);
const size_t page_size = stm32lx_nvm_data_page_size(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, static int stm32lx_nvm_data_write(struct target_s* target,
uint32_t destination, uint32_t destination,
const uint8_t* source_8, const uint8_t* source_8,
int size) size_t size)
{ {
ADIv5_AP_t* ap = adiv5_target_ap(target); ADIv5_AP_t* ap = adiv5_target_ap(target);
const uint32_t nvm = stm32lx_nvm_phys(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; goto usage;
/* Report the current option values */ /* 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 addr = STM32Lx_NVM_OPT_PHYS + i;
uint32_t val = adiv5_ap_mem_read(ap, addr); uint32_t val = adiv5_ap_mem_read(ap, addr);
gdb_outf("0x%08x: 0x%04x 0x%04x %s\n", gdb_outf("0x%08x: 0x%04x 0x%04x %s\n",

View File

@ -35,9 +35,10 @@
#include "command.h" #include "command.h"
#include "gdb_packet.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, 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"; 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); 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); ADIv5_AP_t *ap = adiv5_target_ap(target);
uint16_t sr; 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, 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); ADIv5_AP_t *ap = adiv5_target_ap(target);
uint16_t sr; uint16_t sr;