aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/flash/nor/aduc702x.c6
-rw-r--r--src/flash/nor/aducm360.c6
-rw-r--r--src/flash/nor/ambiqmicro.c20
-rw-r--r--src/flash/nor/at91sam3.c19
-rw-r--r--src/flash/nor/at91sam4.c34
-rw-r--r--src/flash/nor/at91sam4l.c32
-rw-r--r--src/flash/nor/at91sam7.c42
-rw-r--r--src/flash/nor/at91samd.c19
-rw-r--r--src/flash/nor/ath79.c29
-rw-r--r--src/flash/nor/atsame5.c19
-rw-r--r--src/flash/nor/atsamv.c29
-rw-r--r--src/flash/nor/avrf.c5
-rw-r--r--src/flash/nor/bluenrg-x.c13
-rw-r--r--src/flash/nor/cc26xx.c3
-rw-r--r--src/flash/nor/cc3220sf.c9
-rw-r--r--src/flash/nor/cfi.c63
-rw-r--r--src/flash/nor/cfi.h5
-rw-r--r--src/flash/nor/core.c65
-rw-r--r--src/flash/nor/core.h23
-rw-r--r--src/flash/nor/driver.h6
-rw-r--r--src/flash/nor/dsp5680xx_flash.c14
-rw-r--r--src/flash/nor/efm32.c12
-rw-r--r--src/flash/nor/em357.c17
-rw-r--r--src/flash/nor/esirisc_flash.c5
-rw-r--r--src/flash/nor/faux.c6
-rw-r--r--src/flash/nor/fespi.c27
-rw-r--r--src/flash/nor/fm3.c13
-rw-r--r--src/flash/nor/fm4.c22
-rw-r--r--src/flash/nor/imp.h10
-rw-r--r--src/flash/nor/jtagspi.c27
-rw-r--r--src/flash/nor/kinetis.c28
-rw-r--r--src/flash/nor/kinetis_ke.c27
-rw-r--r--src/flash/nor/lpc2000.c26
-rw-r--r--src/flash/nor/lpc288x.c20
-rw-r--r--src/flash/nor/lpc2900.c63
-rw-r--r--src/flash/nor/lpcspifi.c25
-rw-r--r--src/flash/nor/max32xxx.c37
-rw-r--r--src/flash/nor/mdr.c7
-rw-r--r--src/flash/nor/mrvlqspi.c21
-rw-r--r--src/flash/nor/msp432.c9
-rw-r--r--src/flash/nor/niietcm4.c23
-rw-r--r--src/flash/nor/nrf5.c12
-rw-r--r--src/flash/nor/numicro.c15
-rw-r--r--src/flash/nor/ocl.c6
-rw-r--r--src/flash/nor/pic32mx.c12
-rw-r--r--src/flash/nor/psoc4.c24
-rw-r--r--src/flash/nor/psoc5lp.c51
-rw-r--r--src/flash/nor/psoc6.c16
-rw-r--r--src/flash/nor/renesas_rpchf.c16
-rw-r--r--src/flash/nor/sh_qspi.c27
-rw-r--r--src/flash/nor/sim3x.c16
-rw-r--r--src/flash/nor/stellaris.c26
-rw-r--r--src/flash/nor/stm32f1x.c14
-rw-r--r--src/flash/nor/stm32f2x.c35
-rw-r--r--src/flash/nor/stm32h7x.c26
-rw-r--r--src/flash/nor/stm32l4x.c19
-rw-r--r--src/flash/nor/stm32lx.c15
-rw-r--r--src/flash/nor/stmsmi.c27
-rw-r--r--src/flash/nor/str7x.c22
-rw-r--r--src/flash/nor/str9x.c23
-rw-r--r--src/flash/nor/str9xpec.c48
-rw-r--r--src/flash/nor/swm050.c12
-rw-r--r--src/flash/nor/tcl.c18
-rw-r--r--src/flash/nor/tms470.c39
-rw-r--r--src/flash/nor/virtual.c6
-rw-r--r--src/flash/nor/w600.c5
-rw-r--r--src/flash/nor/xcf.c41
-rw-r--r--src/flash/nor/xmc1xxx.c22
-rw-r--r--src/flash/nor/xmc4xxx.c34
-rw-r--r--src/server/gdb_server.c15
70 files changed, 773 insertions, 755 deletions
diff --git a/src/flash/nor/aduc702x.c b/src/flash/nor/aduc702x.c
index b6e1937..b7d2299 100644
--- a/src/flash/nor/aduc702x.c
+++ b/src/flash/nor/aduc702x.c
@@ -57,13 +57,12 @@ static int aduc702x_build_sector_list(struct flash_bank *bank)
{
/* aduc7026_struct flash_bank *aduc7026_info = bank->driver_priv; */
- int i = 0;
uint32_t offset = 0;
/* sector size is 512 */
bank->num_sectors = bank->size / 512;
bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
- for (i = 0; i < bank->num_sectors; ++i) {
+ for (unsigned int i = 0; i < bank->num_sectors; ++i) {
bank->sectors[i].offset = offset;
bank->sectors[i].size = 512;
offset += bank->sectors[i].size;
@@ -74,7 +73,8 @@ static int aduc702x_build_sector_list(struct flash_bank *bank)
return ERROR_OK;
}
-static int aduc702x_erase(struct flash_bank *bank, int first, int last)
+static int aduc702x_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
/* int res; */
int x;
diff --git a/src/flash/nor/aducm360.c b/src/flash/nor/aducm360.c
index 7c5596d..5e0a666 100644
--- a/src/flash/nor/aducm360.c
+++ b/src/flash/nor/aducm360.c
@@ -85,13 +85,12 @@ FLASH_BANK_COMMAND_HANDLER(aducm360_flash_bank_command)
/* ----------------------------------------------------------------------- */
static int aducm360_build_sector_list(struct flash_bank *bank)
{
- int i = 0;
uint32_t offset = 0;
/* sector size is 512 */
bank->num_sectors = bank->size / FLASH_SECTOR_SIZE;
bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
- for (i = 0; i < bank->num_sectors; ++i) {
+ for (unsigned i = 0; i < bank->num_sectors; ++i) {
bank->sectors[i].offset = offset;
bank->sectors[i].size = FLASH_SECTOR_SIZE;
offset += bank->sectors[i].size;
@@ -164,7 +163,8 @@ static int aducm360_page_erase(struct target *target, uint32_t padd)
}
/* ----------------------------------------------------------------------- */
-static int aducm360_erase(struct flash_bank *bank, int first, int last)
+static int aducm360_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
int res = ERROR_OK;
int i;
diff --git a/src/flash/nor/ambiqmicro.c b/src/flash/nor/ambiqmicro.c
index b41b15c..1e2a4b1 100644
--- a/src/flash/nor/ambiqmicro.c
+++ b/src/flash/nor/ambiqmicro.c
@@ -427,7 +427,8 @@ static int ambiqmicro_mass_erase(struct flash_bank *bank)
}
-static int ambiqmicro_erase(struct flash_bank *bank, int first, int last)
+static int ambiqmicro_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct ambiqmicro_flash_bank *ambiqmicro_info = bank->driver_priv;
struct target *target = bank->target;
@@ -447,14 +448,14 @@ static int ambiqmicro_erase(struct flash_bank *bank, int first, int last)
* Check pages.
* Fix num_pages for the device.
*/
- if ((first < 0) || (last < first) || (last >= (int)ambiqmicro_info->num_pages))
+ if ((last < first) || (last >= ambiqmicro_info->num_pages))
return ERROR_FLASH_SECTOR_INVALID;
/*
* Just Mass Erase if all pages are given.
* TODO: Fix num_pages for the device
*/
- if ((first == 0) && (last == ((int)ambiqmicro_info->num_pages-1)))
+ if ((first == 0) && (last == (ambiqmicro_info->num_pages - 1)))
return ambiqmicro_mass_erase(bank);
/*
@@ -502,7 +503,7 @@ static int ambiqmicro_erase(struct flash_bank *bank, int first, int last)
/*
* Erase the pages.
*/
- LOG_INFO("Erasing pages %d to %d on bank %d", first, last, bank->bank_number);
+ LOG_INFO("Erasing pages %u to %u on bank %u", first, last, bank->bank_number);
/*
* passed pc, addr = ROM function, handle breakpoints, not debugging.
@@ -512,7 +513,7 @@ static int ambiqmicro_erase(struct flash_bank *bank, int first, int last)
if (retval != ERROR_OK)
return retval;
- LOG_INFO("%d pages erased!", 1+(last-first));
+ LOG_INFO("%u pages erased!", 1+(last-first));
if (first == 0) {
/*
@@ -527,7 +528,8 @@ static int ambiqmicro_erase(struct flash_bank *bank, int first, int last)
return retval;
}
-static int ambiqmicro_protect(struct flash_bank *bank, int set, int first, int last)
+static int ambiqmicro_protect(struct flash_bank *bank, int set,
+ unsigned int first, unsigned int last)
{
/* struct ambiqmicro_flash_bank *ambiqmicro_info = bank->driver_priv;
* struct target *target = bank->target; */
@@ -679,7 +681,7 @@ static int ambiqmicro_probe(struct flash_bank *bank)
bank->size = ambiqmicro_info->pagesize * ambiqmicro_info->num_pages;
bank->num_sectors = ambiqmicro_info->num_pages;
bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
- for (int i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
bank->sectors[i].offset = i * ambiqmicro_info->pagesize;
bank->sectors[i].size = ambiqmicro_info->pagesize;
bank->sectors[i].is_erased = -1;
@@ -775,8 +777,6 @@ static int ambiqmicro_otp_program(struct flash_bank *bank,
COMMAND_HANDLER(ambiqmicro_handle_mass_erase_command)
{
- int i;
-
if (CMD_ARGC < 1)
return ERROR_COMMAND_SYNTAX_ERROR;
@@ -787,7 +787,7 @@ COMMAND_HANDLER(ambiqmicro_handle_mass_erase_command)
if (ambiqmicro_mass_erase(bank) == ERROR_OK) {
/* set all sectors as erased */
- for (i = 0; i < bank->num_sectors; i++)
+ for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_erased = 1;
command_print(CMD, "ambiqmicro mass erase complete");
diff --git a/src/flash/nor/at91sam3.c b/src/flash/nor/at91sam3.c
index c9ffa65..415f393 100644
--- a/src/flash/nor/at91sam3.c
+++ b/src/flash/nor/at91sam3.c
@@ -3171,12 +3171,11 @@ static int sam3_GetDetails(struct sam3_bank_private *pPrivate)
static int _sam3_probe(struct flash_bank *bank, int noise)
{
- unsigned x;
int r;
struct sam3_bank_private *pPrivate;
- LOG_DEBUG("Begin: Bank: %d, Noise: %d", bank->bank_number, noise);
+ LOG_DEBUG("Begin: Bank: %u, Noise: %d", bank->bank_number, noise);
if (bank->target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED;
@@ -3201,7 +3200,7 @@ static int _sam3_probe(struct flash_bank *bank, int noise)
return r;
/* update the flash bank size */
- for (x = 0; x < SAM3_MAX_FLASH_BANKS; x++) {
+ for (unsigned int x = 0; x < SAM3_MAX_FLASH_BANKS; x++) {
if (bank->base == pPrivate->pChip->details.bank[x].base_address) {
bank->size = pPrivate->pChip->details.bank[x].size_bytes;
break;
@@ -3216,7 +3215,7 @@ static int _sam3_probe(struct flash_bank *bank, int noise)
}
bank->num_sectors = pPrivate->nsectors;
- for (x = 0; ((int)(x)) < bank->num_sectors; x++) {
+ for (unsigned int x = 0; x < bank->num_sectors; x++) {
bank->sectors[x].size = pPrivate->sector_size;
bank->sectors[x].offset = x * (pPrivate->sector_size);
/* mark as unknown */
@@ -3252,7 +3251,8 @@ static int sam3_auto_probe(struct flash_bank *bank)
return _sam3_probe(bank, 0);
}
-static int sam3_erase(struct flash_bank *bank, int first, int last)
+static int sam3_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct sam3_bank_private *pPrivate;
int r;
@@ -3273,7 +3273,7 @@ static int sam3_erase(struct flash_bank *bank, int first, int last)
if (!(pPrivate->probed))
return ERROR_FLASH_BANK_NOT_PROBED;
- if ((first == 0) && ((last + 1) == ((int)(pPrivate->nsectors)))) {
+ if ((first == 0) && ((last + 1) == pPrivate->nsectors)) {
/* whole chip */
LOG_DEBUG("Here");
return FLASHD_EraseEntireBank(pPrivate);
@@ -3282,7 +3282,8 @@ static int sam3_erase(struct flash_bank *bank, int first, int last)
return ERROR_OK;
}
-static int sam3_protect(struct flash_bank *bank, int set, int first, int last)
+static int sam3_protect(struct flash_bank *bank, int set, unsigned int first,
+ unsigned int last)
{
struct sam3_bank_private *pPrivate;
int r;
@@ -3298,9 +3299,9 @@ static int sam3_protect(struct flash_bank *bank, int set, int first, int last)
return ERROR_FLASH_BANK_NOT_PROBED;
if (set)
- r = FLASHD_Lock(pPrivate, (unsigned)(first), (unsigned)(last));
+ r = FLASHD_Lock(pPrivate, first, last);
else
- r = FLASHD_Unlock(pPrivate, (unsigned)(first), (unsigned)(last));
+ r = FLASHD_Unlock(pPrivate, first, last);
LOG_DEBUG("End: r=%d", r);
return r;
diff --git a/src/flash/nor/at91sam4.c b/src/flash/nor/at91sam4.c
index 5b56c42..26cde19 100644
--- a/src/flash/nor/at91sam4.c
+++ b/src/flash/nor/at91sam4.c
@@ -2608,12 +2608,11 @@ static int sam4_info(struct flash_bank *bank, char *buf, int buf_size)
static int sam4_probe(struct flash_bank *bank)
{
- unsigned x;
int r;
struct sam4_bank_private *pPrivate;
- LOG_DEBUG("Begin: Bank: %d", bank->bank_number);
+ LOG_DEBUG("Begin: Bank: %u", bank->bank_number);
if (bank->target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED;
@@ -2638,7 +2637,7 @@ static int sam4_probe(struct flash_bank *bank)
return r;
/* update the flash bank size */
- for (x = 0; x < SAM4_MAX_FLASH_BANKS; x++) {
+ for (unsigned int x = 0; x < SAM4_MAX_FLASH_BANKS; x++) {
if (bank->base == pPrivate->pChip->details.bank[x].base_address) {
bank->size = pPrivate->pChip->details.bank[x].size_bytes;
LOG_DEBUG("SAM4 Set flash bank to " TARGET_ADDR_FMT " - "
@@ -2656,7 +2655,7 @@ static int sam4_probe(struct flash_bank *bank)
}
bank->num_sectors = pPrivate->nsectors;
- for (x = 0; ((int)(x)) < bank->num_sectors; x++) {
+ for (unsigned int x = 0; x < bank->num_sectors; x++) {
bank->sectors[x].size = pPrivate->sector_size;
bank->sectors[x].offset = x * (pPrivate->sector_size);
/* mark as unknown */
@@ -2693,11 +2692,11 @@ static int sam4_auto_probe(struct flash_bank *bank)
return sam4_probe(bank);
}
-static int sam4_erase(struct flash_bank *bank, int first, int last)
+static int sam4_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct sam4_bank_private *pPrivate;
int r;
- int i;
int pageCount;
/*16 pages equals 8KB - Same size as a lock region*/
pageCount = 16;
@@ -2719,26 +2718,26 @@ static int sam4_erase(struct flash_bank *bank, int first, int last)
if (!(pPrivate->probed))
return ERROR_FLASH_BANK_NOT_PROBED;
- if ((first == 0) && ((last + 1) == ((int)(pPrivate->nsectors)))) {
+ if ((first == 0) && ((last + 1) == pPrivate->nsectors)) {
/* whole chip */
LOG_DEBUG("Here");
return FLASHD_EraseEntireBank(pPrivate);
}
LOG_INFO("sam4 does not auto-erase while programming (Erasing relevant sectors)");
- LOG_INFO("sam4 First: 0x%08x Last: 0x%08x", (unsigned int)(first), (unsigned int)(last));
- for (i = first; i <= last; i++) {
+ LOG_INFO("sam4 First: 0x%08x Last: 0x%08x", first, last);
+ for (unsigned int i = first; i <= last; i++) {
/*16 pages equals 8KB - Same size as a lock region*/
r = FLASHD_ErasePages(pPrivate, (i * pageCount), pageCount, &status);
- LOG_INFO("Erasing sector: 0x%08x", (unsigned int)(i));
+ LOG_INFO("Erasing sector: 0x%08x", i);
if (r != ERROR_OK)
- LOG_ERROR("SAM4: Error performing Erase page @ lock region number %d",
- (unsigned int)(i));
+ LOG_ERROR("SAM4: Error performing Erase page @ lock region number %u",
+ i);
if (status & (1 << 2)) {
- LOG_ERROR("SAM4: Lock Region %d is locked", (unsigned int)(i));
+ LOG_ERROR("SAM4: Lock Region %u is locked", i);
return ERROR_FAIL;
}
if (status & (1 << 1)) {
- LOG_ERROR("SAM4: Flash Command error @lock region %d", (unsigned int)(i));
+ LOG_ERROR("SAM4: Flash Command error @lock region %u", i);
return ERROR_FAIL;
}
}
@@ -2746,7 +2745,8 @@ static int sam4_erase(struct flash_bank *bank, int first, int last)
return ERROR_OK;
}
-static int sam4_protect(struct flash_bank *bank, int set, int first, int last)
+static int sam4_protect(struct flash_bank *bank, int set, unsigned int first,
+ unsigned int last)
{
struct sam4_bank_private *pPrivate;
int r;
@@ -2762,9 +2762,9 @@ static int sam4_protect(struct flash_bank *bank, int set, int first, int last)
return ERROR_FLASH_BANK_NOT_PROBED;
if (set)
- r = FLASHD_Lock(pPrivate, (unsigned)(first), (unsigned)(last));
+ r = FLASHD_Lock(pPrivate, first, last);
else
- r = FLASHD_Unlock(pPrivate, (unsigned)(first), (unsigned)(last));
+ r = FLASHD_Unlock(pPrivate, first, last);
LOG_DEBUG("End: r=%d", r);
return r;
diff --git a/src/flash/nor/at91sam4l.c b/src/flash/nor/at91sam4l.c
index d4bfe53..4ee4ff8 100644
--- a/src/flash/nor/at91sam4l.c
+++ b/src/flash/nor/at91sam4l.c
@@ -125,7 +125,7 @@ struct sam4l_info {
uint32_t page_size;
int num_pages;
int sector_size;
- int pages_per_sector;
+ unsigned int pages_per_sector;
bool probed;
struct target *target;
@@ -335,7 +335,7 @@ static int sam4l_probe(struct flash_bank *bank)
/* Fill out the sector information: all SAM4L sectors are the same size and
* there is always a fixed number of them. */
- for (int i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
bank->sectors[i].size = chip->sector_size;
bank->sectors[i].offset = i * chip->sector_size;
/* mark as unknown */
@@ -375,13 +375,14 @@ static int sam4l_protect_check(struct flash_bank *bank)
return res;
st >>= 16; /* There are 16 lock region bits in the upper half word */
- for (int i = 0; i < bank->num_sectors; i++)
- bank->sectors[i].is_protected = !!(st & (1<<i));
+ for (unsigned int i = 0; i < bank->num_sectors; i++)
+ bank->sectors[i].is_protected = !!(st & (1<<i));
return ERROR_OK;
}
-static int sam4l_protect(struct flash_bank *bank, int set, int first, int last)
+static int sam4l_protect(struct flash_bank *bank, int set, unsigned int first,
+ unsigned int last)
{
struct sam4l_info *chip = (struct sam4l_info *)bank->driver_priv;
@@ -398,7 +399,7 @@ static int sam4l_protect(struct flash_bank *bank, int set, int first, int last)
/* Make sure the pages make sense. */
if (first >= bank->num_sectors || last >= bank->num_sectors) {
- LOG_ERROR("Protect range %d - %d not valid (%d sectors total)", first, last,
+ LOG_ERROR("Protect range %u - %u not valid (%u sectors total)", first, last,
bank->num_sectors);
return ERROR_FAIL;
}
@@ -406,7 +407,7 @@ static int sam4l_protect(struct flash_bank *bank, int set, int first, int last)
/* Try to lock or unlock each sector in the range. This is done by locking
* a region containing one page in that sector, we arbitrarily choose the 0th
* page in the sector. */
- for (int i = first; i <= last; i++) {
+ for (unsigned int i = first; i <= last; i++) {
int res;
res = sam4l_flash_command(bank->target,
@@ -420,7 +421,8 @@ static int sam4l_protect(struct flash_bank *bank, int set, int first, int last)
return ERROR_OK;
}
-static int sam4l_erase(struct flash_bank *bank, int first, int last)
+static int sam4l_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
int ret;
struct sam4l_info *chip = (struct sam4l_info *)bank->driver_priv;
@@ -438,7 +440,7 @@ static int sam4l_erase(struct flash_bank *bank, int first, int last)
/* Make sure the pages make sense. */
if (first >= bank->num_sectors || last >= bank->num_sectors) {
- LOG_ERROR("Erase range %d - %d not valid (%d sectors total)", first, last,
+ LOG_ERROR("Erase range %u - %u not valid (%u sectors total)", first, last,
bank->num_sectors);
return ERROR_FAIL;
}
@@ -453,19 +455,19 @@ static int sam4l_erase(struct flash_bank *bank, int first, int last)
return ret;
}
} else {
- LOG_DEBUG("Erasing sectors %d through %d...\n", first, last);
+ LOG_DEBUG("Erasing sectors %u through %u...\n", first, last);
/* For each sector... */
- for (int i = first; i <= last; i++) {
+ for (unsigned int i = first; i <= last; i++) {
/* For each page in that sector... */
- for (int j = 0; j < chip->pages_per_sector; j++) {
- int pn = i * chip->pages_per_sector + j;
+ for (unsigned int j = 0; j < chip->pages_per_sector; j++) {
+ unsigned int pn = i * chip->pages_per_sector + j;
bool is_erased = false;
/* Issue the page erase */
ret = sam4l_flash_command(bank->target, SAM4L_FCMD_EP, pn);
if (ret != ERROR_OK) {
- LOG_ERROR("Erasing page %d failed", pn);
+ LOG_ERROR("Erasing page %u failed", pn);
return ret;
}
@@ -474,7 +476,7 @@ static int sam4l_erase(struct flash_bank *bank, int first, int last)
return ret;
if (!is_erased) {
- LOG_DEBUG("Page %d was not erased.", pn);
+ LOG_DEBUG("Page %u was not erased.", pn);
return ERROR_FAIL;
}
}
diff --git a/src/flash/nor/at91sam7.c b/src/flash/nor/at91sam7.c
index 039746c..7dfdf0d 100644
--- a/src/flash/nor/at91sam7.c
+++ b/src/flash/nor/at91sam7.c
@@ -702,17 +702,15 @@ FLASH_BANK_COMMAND_HANDLER(at91sam7_flash_bank_command)
uint32_t bank_size;
uint32_t ext_freq = 0;
- int chip_width;
- int bus_width;
- int banks_num;
- int num_sectors;
+ unsigned int chip_width;
+ unsigned int bus_width;
+ unsigned int banks_num;
+ unsigned int num_sectors;
uint16_t pages_per_sector;
uint16_t page_size;
uint16_t num_nvmbits;
- int bnk, sec;
-
at91sam7_info = malloc(sizeof(struct at91sam7_flash_bank));
t_bank->driver_priv = at91sam7_info;
@@ -729,11 +727,11 @@ FLASH_BANK_COMMAND_HANDLER(at91sam7_flash_bank_command)
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], base_address);
- COMMAND_PARSE_NUMBER(int, CMD_ARGV[3], chip_width);
- COMMAND_PARSE_NUMBER(int, CMD_ARGV[4], bus_width);
+ COMMAND_PARSE_NUMBER(uint, CMD_ARGV[3], chip_width);
+ COMMAND_PARSE_NUMBER(uint, CMD_ARGV[4], bus_width);
- COMMAND_PARSE_NUMBER(int, CMD_ARGV[8], banks_num);
- COMMAND_PARSE_NUMBER(int, CMD_ARGV[9], num_sectors);
+ COMMAND_PARSE_NUMBER(uint, CMD_ARGV[8], banks_num);
+ COMMAND_PARSE_NUMBER(uint, CMD_ARGV[9], num_sectors);
COMMAND_PARSE_NUMBER(u16, CMD_ARGV[10], pages_per_sector);
COMMAND_PARSE_NUMBER(u16, CMD_ARGV[11], page_size);
COMMAND_PARSE_NUMBER(u16, CMD_ARGV[12], num_nvmbits);
@@ -754,7 +752,7 @@ FLASH_BANK_COMMAND_HANDLER(at91sam7_flash_bank_command)
/* calculate bank size */
bank_size = num_sectors * pages_per_sector * page_size;
- for (bnk = 0; bnk < banks_num; bnk++) {
+ for (unsigned int bnk = 0; bnk < banks_num; bnk++) {
if (bnk > 0) {
if (!t_bank->next) {
/* create a new bank element */
@@ -780,7 +778,7 @@ FLASH_BANK_COMMAND_HANDLER(at91sam7_flash_bank_command)
/* allocate sectors */
t_bank->sectors = malloc(num_sectors * sizeof(struct flash_sector));
- for (sec = 0; sec < num_sectors; sec++) {
+ for (unsigned int sec = 0; sec < num_sectors; sec++) {
t_bank->sectors[sec].offset = sec * pages_per_sector * page_size;
t_bank->sectors[sec].size = pages_per_sector * page_size;
t_bank->sectors[sec].is_erased = -1;
@@ -801,10 +799,10 @@ FLASH_BANK_COMMAND_HANDLER(at91sam7_flash_bank_command)
return ERROR_OK;
}
-static int at91sam7_erase(struct flash_bank *bank, int first, int last)
+static int at91sam7_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct at91sam7_flash_bank *at91sam7_info = bank->driver_priv;
- int sec;
uint32_t nbytes, pos;
uint8_t *buffer;
uint8_t erase_all;
@@ -817,7 +815,7 @@ static int at91sam7_erase(struct flash_bank *bank, int first, int last)
return ERROR_TARGET_NOT_HALTED;
}
- if ((first < 0) || (last < first) || (last >= bank->num_sectors))
+ if ((last < first) || (last >= bank->num_sectors))
return ERROR_FLASH_SECTOR_INVALID;
erase_all = 0;
@@ -847,16 +845,16 @@ static int at91sam7_erase(struct flash_bank *bank, int first, int last)
}
/* mark erased sectors */
- for (sec = first; sec <= last; sec++)
+ for (unsigned int sec = first; sec <= last; sec++)
bank->sectors[sec].is_erased = 1;
return ERROR_OK;
}
-static int at91sam7_protect(struct flash_bank *bank, int set, int first, int last)
+static int at91sam7_protect(struct flash_bank *bank, int set,
+ unsigned int first, unsigned int last)
{
uint32_t cmd;
- int sector;
uint32_t pagen;
struct at91sam7_flash_bank *at91sam7_info = bank->driver_priv;
@@ -869,14 +867,14 @@ static int at91sam7_protect(struct flash_bank *bank, int set, int first, int las
return ERROR_TARGET_NOT_HALTED;
}
- if ((first < 0) || (last < first) || (last >= bank->num_sectors))
+ if ((last < first) || (last >= bank->num_sectors))
return ERROR_FLASH_SECTOR_INVALID;
/* Configure the flash controller timing */
at91sam7_read_clock_info(bank);
at91sam7_set_flash_mode(bank, FMR_TIMING_NVBITS);
- for (sector = first; sector <= last; sector++) {
+ for (unsigned int sector = first; sector <= last; sector++) {
if (set)
cmd = SLB;
else
@@ -956,7 +954,7 @@ static int at91sam7_write(struct flash_bank *bank, const uint8_t *buffer, uint32
/* Send Write Page command to Flash Controller */
if (at91sam7_flash_command(bank, WP, pagen) != ERROR_OK)
return ERROR_FLASH_OPERATION_FAILED;
- LOG_DEBUG("Write flash bank:%i page number:%" PRIi32 "", bank->bank_number, pagen);
+ LOG_DEBUG("Write flash bank:%u page number:%" PRIi32 "", bank->bank_number, pagen);
}
return ERROR_OK;
@@ -1018,7 +1016,7 @@ static int get_at91sam7_info(struct flash_bank *bank, char *buf, int buf_size)
printed = snprintf(buf,
buf_size,
- " Pagesize: %i bytes | Lockbits(%i): %i 0x%4.4x | Pages in lock region: %i\n",
+ " Pagesize: %i bytes | Lockbits(%u): %i 0x%4.4x | Pages in lock region: %i\n",
at91sam7_info->pagesize,
bank->num_sectors,
at91sam7_info->num_lockbits_on,
diff --git a/src/flash/nor/at91samd.c b/src/flash/nor/at91samd.c
index 6e89099..0bd5f59 100644
--- a/src/flash/nor/at91samd.c
+++ b/src/flash/nor/at91samd.c
@@ -398,7 +398,7 @@ static const struct samd_part *samd_find_part(uint32_t id)
static int samd_protect_check(struct flash_bank *bank)
{
- int res, prot_block;
+ int res;
uint16_t lock;
res = target_read_u16(bank->target,
@@ -407,7 +407,7 @@ static int samd_protect_check(struct flash_bank *bank)
return res;
/* Lock bits are active-low */
- for (prot_block = 0; prot_block < bank->num_prot_blocks; prot_block++)
+ for (unsigned int prot_block = 0; prot_block < bank->num_prot_blocks; prot_block++)
bank->prot_blocks[prot_block].is_protected = !(lock & (1u<<prot_block));
return ERROR_OK;
@@ -725,10 +725,10 @@ static int samd_modify_user_row(struct target *target, uint64_t value,
return samd_modify_user_row_masked(target, value << startb, mask);
}
-static int samd_protect(struct flash_bank *bank, int set, int first_prot_bl, int last_prot_bl)
+static int samd_protect(struct flash_bank *bank, int set,
+ unsigned int first, unsigned int last)
{
int res = ERROR_OK;
- int prot_block;
/* We can issue lock/unlock region commands with the target running but
* the settings won't persist unless we're able to modify the LOCK regions
@@ -738,7 +738,7 @@ static int samd_protect(struct flash_bank *bank, int set, int first_prot_bl, int
return ERROR_TARGET_NOT_HALTED;
}
- for (prot_block = first_prot_bl; prot_block <= last_prot_bl; prot_block++) {
+ for (unsigned int prot_block = first; prot_block <= last; prot_block++) {
if (set != bank->prot_blocks[prot_block].is_protected) {
/* Load an address that is within this protection block (we use offset 0) */
res = target_write_u32(bank->target,
@@ -763,7 +763,7 @@ static int samd_protect(struct flash_bank *bank, int set, int first_prot_bl, int
res = samd_modify_user_row(bank->target,
set ? (uint64_t)0 : (uint64_t)UINT64_MAX,
- 48 + first_prot_bl, 48 + last_prot_bl);
+ 48 + first, 48 + last);
if (res != ERROR_OK)
LOG_WARNING("SAMD: protect settings were not made persistent!");
@@ -775,9 +775,10 @@ exit:
return res;
}
-static int samd_erase(struct flash_bank *bank, int first_sect, int last_sect)
+static int samd_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
- int res, s;
+ int res;
struct samd_info *chip = (struct samd_info *)bank->driver_priv;
if (bank->target->state != TARGET_HALTED) {
@@ -792,7 +793,7 @@ static int samd_erase(struct flash_bank *bank, int first_sect, int last_sect)
}
/* For each sector to be erased */
- for (s = first_sect; s <= last_sect; s++) {
+ for (unsigned int s = first; s <= last; s++) {
res = samd_erase_row(bank->target, bank->sectors[s].offset);
if (res != ERROR_OK) {
LOG_ERROR("SAMD: failed to erase sector %d at 0x%08" PRIx32, s, bank->sectors[s].offset);
diff --git a/src/flash/nor/ath79.c b/src/flash/nor/ath79.c
index c551f27..88ebbf2 100644
--- a/src/flash/nor/ath79.c
+++ b/src/flash/nor/ath79.c
@@ -498,21 +498,21 @@ static int ath79_erase_sector(struct flash_bank *bank, int sector)
return wait_till_ready(bank, ATH79_MAX_TIMEOUT);
}
-static int ath79_erase(struct flash_bank *bank, int first, int last)
+static int ath79_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct target *target = bank->target;
struct ath79_flash_bank *ath79_info = bank->driver_priv;
int retval = ERROR_OK;
- int sector;
- LOG_DEBUG("%s: from sector %d to sector %d", __func__, first, last);
+ LOG_DEBUG("%s: from sector %u to sector %u", __func__, first, last);
if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED;
}
- if ((first < 0) || (last < first) || (last >= bank->num_sectors)) {
+ if ((last < first) || (last >= bank->num_sectors)) {
LOG_ERROR("Flash sector invalid");
return ERROR_FLASH_SECTOR_INVALID;
}
@@ -525,14 +525,14 @@ static int ath79_erase(struct flash_bank *bank, int first, int last)
if (ath79_info->dev->erase_cmd == 0x00)
return ERROR_FLASH_OPER_UNSUPPORTED;
- for (sector = first; sector <= last; sector++) {
+ for (unsigned sector = first; sector <= last; sector++) {
if (bank->sectors[sector].is_protected) {
- LOG_ERROR("Flash sector %d protected", sector);
+ LOG_ERROR("Flash sector %u protected", sector);
return ERROR_FAIL;
}
}
- for (sector = first; sector <= last; sector++) {
+ for (unsigned int sector = first; sector <= last; sector++) {
retval = ath79_erase_sector(bank, sector);
if (retval != ERROR_OK)
break;
@@ -542,12 +542,10 @@ static int ath79_erase(struct flash_bank *bank, int first, int last)
return retval;
}
-static int ath79_protect(struct flash_bank *bank, int set,
- int first, int last)
+static int ath79_protect(struct flash_bank *bank, int set, unsigned int first,
+ unsigned int last)
{
- int sector;
-
- for (sector = first; sector <= last; sector++)
+ for (unsigned int sector = first; sector <= last; sector++)
bank->sectors[sector].is_protected = set;
return ERROR_OK;
}
@@ -648,7 +646,6 @@ static int ath79_write(struct flash_bank *bank, const uint8_t *buffer,
uint32_t offset, uint32_t count)
{
struct target *target = bank->target;
- int sector;
LOG_DEBUG("%s: offset=0x%08" PRIx32 " count=0x%08" PRIx32,
__func__, offset, count);
@@ -664,7 +661,7 @@ static int ath79_write(struct flash_bank *bank, const uint8_t *buffer,
}
/* Check sector protection */
- for (sector = 0; sector < bank->num_sectors; sector++) {
+ for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
/* Start offset in or before this sector? */
/* End offset in or behind this sector? */
struct flash_sector *bs = &bank->sectors[sector];
@@ -672,7 +669,7 @@ static int ath79_write(struct flash_bank *bank, const uint8_t *buffer,
if ((offset < (bs->offset + bs->size)) &&
((offset + count - 1) >= bs->offset) &&
bs->is_protected) {
- LOG_ERROR("Flash sector %d protected", sector);
+ LOG_ERROR("Flash sector %u protected", sector);
return ERROR_FAIL;
}
}
@@ -845,7 +842,7 @@ static int ath79_probe(struct flash_bank *bank)
return ERROR_FAIL;
}
- for (int sector = 0; sector < bank->num_sectors; sector++) {
+ for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
sectors[sector].offset = sector * sectorsize;
sectors[sector].size = sectorsize;
sectors[sector].is_erased = 0;
diff --git a/src/flash/nor/atsame5.c b/src/flash/nor/atsame5.c
index baa86ac..ab79e8c 100644
--- a/src/flash/nor/atsame5.c
+++ b/src/flash/nor/atsame5.c
@@ -231,7 +231,7 @@ static const struct samd_part *samd_find_part(uint32_t id)
static int same5_protect_check(struct flash_bank *bank)
{
- int res, prot_block;
+ int res;
uint32_t lock;
res = target_read_u32(bank->target,
@@ -240,7 +240,7 @@ static int same5_protect_check(struct flash_bank *bank)
return res;
/* Lock bits are active-low */
- for (prot_block = 0; prot_block < bank->num_prot_blocks; prot_block++)
+ for (unsigned int prot_block = 0; prot_block < bank->num_prot_blocks; prot_block++)
bank->prot_blocks[prot_block].is_protected = !(lock & (1u<<prot_block));
return ERROR_OK;
@@ -569,10 +569,10 @@ static int same5_modify_user_row(struct target *target, uint32_t value,
buf_val, buf_mask, 0, 8);
}
-static int same5_protect(struct flash_bank *bank, int set, int first_prot_bl, int last_prot_bl)
+static int same5_protect(struct flash_bank *bank, int set, unsigned int first,
+ unsigned int last)
{
int res = ERROR_OK;
- int prot_block;
/* We can issue lock/unlock region commands with the target running but
* the settings won't persist unless we're able to modify the LOCK regions
@@ -582,7 +582,7 @@ static int same5_protect(struct flash_bank *bank, int set, int first_prot_bl, in
return ERROR_TARGET_NOT_HALTED;
}
- for (prot_block = first_prot_bl; prot_block <= last_prot_bl; prot_block++) {
+ for (unsigned int prot_block = first; prot_block <= last; prot_block++) {
if (set != bank->prot_blocks[prot_block].is_protected) {
/* Load an address that is within this protection block (we use offset 0) */
res = target_write_u32(bank->target,
@@ -606,7 +606,7 @@ static int same5_protect(struct flash_bank *bank, int set, int first_prot_bl, in
const uint8_t unlock[4] = { 0xff, 0xff, 0xff, 0xff };
uint8_t mask[4] = { 0, 0, 0, 0 };
- buf_set_u32(mask, first_prot_bl, last_prot_bl + 1 - first_prot_bl, 0xffffffff);
+ buf_set_u32(mask, first, last + 1 - first, 0xffffffff);
res = same5_modify_user_row_masked(bank->target,
set ? lock : unlock, mask, 8, 4);
@@ -621,9 +621,10 @@ exit:
return res;
}
-static int same5_erase(struct flash_bank *bank, int first_sect, int last_sect)
+static int same5_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
- int res, s;
+ int res;
struct samd_info *chip = (struct samd_info *)bank->driver_priv;
if (bank->target->state != TARGET_HALTED) {
@@ -636,7 +637,7 @@ static int same5_erase(struct flash_bank *bank, int first_sect, int last_sect)
return ERROR_FLASH_BANK_NOT_PROBED;
/* For each sector to be erased */
- for (s = first_sect; s <= last_sect; s++) {
+ for (unsigned int s = first; s <= last; s++) {
res = same5_erase_block(bank->target, bank->sectors[s].offset);
if (res != ERROR_OK) {
LOG_ERROR("SAM: failed to erase sector %d at 0x%08" PRIx32, s, bank->sectors[s].offset);
diff --git a/src/flash/nor/atsamv.c b/src/flash/nor/atsamv.c
index 9a53369..13d1d26 100644
--- a/src/flash/nor/atsamv.c
+++ b/src/flash/nor/atsamv.c
@@ -328,7 +328,7 @@ static int samv_protect_check(struct flash_bank *bank)
if (r != ERROR_OK)
return r;
- for (int x = 0; x < bank->num_sectors; x++)
+ for (unsigned int x = 0; x < bank->num_sectors; x++)
bank->sectors[x].is_protected = (!!(v[x >> 5] & (1 << (x % 32))));
return ERROR_OK;
}
@@ -384,7 +384,7 @@ static int samv_probe(struct flash_bank *bank)
bank->base = SAMV_FLASH_BASE;
bank->num_sectors = bank->size / SAMV_SECTOR_SIZE;
bank->sectors = calloc(bank->num_sectors, sizeof(struct flash_sector));
- for (int s = 0; s < (int)bank->num_sectors; s++) {
+ for (unsigned int s = 0; s < bank->num_sectors; s++) {
bank->sectors[s].size = SAMV_SECTOR_SIZE;
bank->sectors[s].offset = s * SAMV_SECTOR_SIZE;
bank->sectors[s].is_erased = -1;
@@ -406,7 +406,8 @@ static int samv_auto_probe(struct flash_bank *bank)
return samv_probe(bank);
}
-static int samv_erase(struct flash_bank *bank, int first, int last)
+static int samv_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
const int page_count = 32; /* 32 pages equals 16 KB lock region */
@@ -420,31 +421,31 @@ static int samv_erase(struct flash_bank *bank, int first, int last)
return r;
/* easy case: we've been requested to erase the entire flash */
- if ((first == 0) && ((last + 1) == (int)(bank->num_sectors)))
+ if ((first == 0) && ((last + 1) == bank->num_sectors))
return samv_efc_perform_command(bank->target, SAMV_EFC_FCMD_EA, 0, NULL);
- LOG_INFO("erasing lock regions %d-%d...", first, last);
+ LOG_INFO("erasing lock regions %u-%u...", first, last);
- for (int i = first; i <= last; i++) {
+ for (unsigned int i = first; i <= last; i++) {
uint32_t status;
r = samv_erase_pages(bank->target, (i * page_count), page_count, &status);
- LOG_INFO("erasing lock region %d", i);
+ LOG_INFO("erasing lock region %u", i);
if (r != ERROR_OK)
- LOG_ERROR("error performing erase page @ lock region number %d",
- (unsigned int)(i));
+ LOG_ERROR("error performing erase page @ lock region number %u", i);
if (status & (1 << 2)) {
- LOG_ERROR("lock region %d is locked", (unsigned int)(i));
+ LOG_ERROR("lock region %u is locked", i);
return ERROR_FAIL;
}
if (status & (1 << 1)) {
- LOG_ERROR("flash command error @lock region %d", (unsigned int)(i));
+ LOG_ERROR("flash command error @lock region %u", i);
return ERROR_FAIL;
}
}
return ERROR_OK;
}
-static int samv_protect(struct flash_bank *bank, int set, int first, int last)
+static int samv_protect(struct flash_bank *bank, int set, unsigned int first,
+ unsigned int last)
{
if (bank->target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
@@ -453,9 +454,9 @@ static int samv_protect(struct flash_bank *bank, int set, int first, int last)
int r;
if (set)
- r = samv_flash_lock(bank->target, (unsigned)(first), (unsigned)(last));
+ r = samv_flash_lock(bank->target, first, last);
else
- r = samv_flash_unlock(bank->target, (unsigned)(first), (unsigned)(last));
+ r = samv_flash_unlock(bank->target, first, last);
return r;
}
diff --git a/src/flash/nor/avrf.c b/src/flash/nor/avrf.c
index 93f6872..4ec1161 100644
--- a/src/flash/nor/avrf.c
+++ b/src/flash/nor/avrf.c
@@ -218,7 +218,8 @@ FLASH_BANK_COMMAND_HANDLER(avrf_flash_bank_command)
return ERROR_OK;
}
-static int avrf_erase(struct flash_bank *bank, int first, int last)
+static int avrf_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct target *target = bank->target;
struct avr_common *avr = target->arch_info;
@@ -442,7 +443,7 @@ COMMAND_HANDLER(avrf_handle_mass_erase_command)
if (avrf_mass_erase(bank) == ERROR_OK) {
/* set all sectors as erased */
- for (int i = 0; i < bank->num_sectors; i++)
+ for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_erased = 1;
command_print(CMD, "avr mass erase complete");
diff --git a/src/flash/nor/bluenrg-x.c b/src/flash/nor/bluenrg-x.c
index fbce20d..232f6ba 100644
--- a/src/flash/nor/bluenrg-x.c
+++ b/src/flash/nor/bluenrg-x.c
@@ -123,12 +123,13 @@ static inline int bluenrgx_write_flash_reg(struct flash_bank *bank, uint32_t reg
return target_write_u32(bank->target, bluenrgx_get_flash_reg(bank, reg_offset), value);
}
-static int bluenrgx_erase(struct flash_bank *bank, int first, int last)
+static int bluenrgx_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
int retval = ERROR_OK;
struct bluenrgx_flash_bank *bluenrgx_info = bank->driver_priv;
- int num_sectors = (last - first + 1);
- int mass_erase = (num_sectors == bank->num_sectors);
+ unsigned int num_sectors = (last - first + 1);
+ const bool mass_erase = (num_sectors == bank->num_sectors);
struct target *target = bank->target;
uint32_t address, command;
@@ -181,9 +182,9 @@ static int bluenrgx_erase(struct flash_bank *bank, int first, int last)
} else {
command = FLASH_CMD_ERASE_PAGE;
- for (int i = first; i <= last; i++) {
+ for (unsigned int i = first; i <= last; i++) {
address = bank->base+i*FLASH_PAGE_SIZE(bluenrgx_info);
- LOG_DEBUG("address = %08x, index = %d", address, i);
+ LOG_DEBUG("address = %08x, index = %u", address, i);
if (bluenrgx_write_flash_reg(bank, FLASH_REG_IRQRAW, 0x3f) != ERROR_OK) {
LOG_ERROR("Register write failed");
@@ -399,7 +400,7 @@ static int bluenrgx_probe(struct flash_bank *bank)
bank->num_sectors = bank->size/FLASH_PAGE_SIZE(bluenrgx_info);
bank->sectors = realloc(bank->sectors, sizeof(struct flash_sector) * bank->num_sectors);
- for (int i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
bank->sectors[i].offset = i * FLASH_PAGE_SIZE(bluenrgx_info);
bank->sectors[i].size = FLASH_PAGE_SIZE(bluenrgx_info);
bank->sectors[i].is_erased = -1;
diff --git a/src/flash/nor/cc26xx.c b/src/flash/nor/cc26xx.c
index 176211a..f0a8550 100644
--- a/src/flash/nor/cc26xx.c
+++ b/src/flash/nor/cc26xx.c
@@ -264,7 +264,8 @@ FLASH_BANK_COMMAND_HANDLER(cc26xx_flash_bank_command)
return ERROR_OK;
}
-static int cc26xx_erase(struct flash_bank *bank, int first, int last)
+static int cc26xx_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct target *target = bank->target;
struct cc26xx_bank *cc26xx_bank = bank->driver_priv;
diff --git a/src/flash/nor/cc3220sf.c b/src/flash/nor/cc3220sf.c
index c8de7d0..5e88aa6 100644
--- a/src/flash/nor/cc3220sf.c
+++ b/src/flash/nor/cc3220sf.c
@@ -106,7 +106,8 @@ FLASH_BANK_COMMAND_HANDLER(cc3220sf_flash_bank_command)
return ERROR_OK;
}
-static int cc3220sf_erase(struct flash_bank *bank, int first, int last)
+static int cc3220sf_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct target *target = bank->target;
bool done;
@@ -129,7 +130,7 @@ static int cc3220sf_erase(struct flash_bank *bank, int first, int last)
}
/* Erase requested sectors one by one */
- for (int i = first; i <= last; i++) {
+ for (unsigned int i = first; i <= last; i++) {
/* Determine address of sector to erase */
address = FLASH_BASE_ADDR + i * FLASH_SECTOR_SIZE;
@@ -431,7 +432,7 @@ static int cc3220sf_probe(struct flash_bank *bank)
uint32_t base;
uint32_t size;
- int num_sectors;
+ unsigned int num_sectors;
base = FLASH_BASE_ADDR;
size = FLASH_NUM_SECTORS * FLASH_SECTOR_SIZE;
@@ -452,7 +453,7 @@ static int cc3220sf_probe(struct flash_bank *bank)
bank->write_end_alignment = 0;
bank->num_sectors = num_sectors;
- for (int i = 0; i < num_sectors; i++) {
+ for (unsigned int i = 0; i < num_sectors; i++) {
bank->sectors[i].offset = i * FLASH_SECTOR_SIZE;
bank->sectors[i].size = FLASH_SECTOR_SIZE;
bank->sectors[i].is_erased = -1;
diff --git a/src/flash/nor/cfi.c b/src/flash/nor/cfi.c
index 50ab207..19fb6b2 100644
--- a/src/flash/nor/cfi.c
+++ b/src/flash/nor/cfi.c
@@ -162,10 +162,10 @@ static void cfi_command(struct flash_bank *bank, uint8_t cmd, uint8_t *cmd_buf)
cmd_buf[i] = 0;
if (cfi_info->endianness == TARGET_LITTLE_ENDIAN) {
- for (int i = bank->bus_width; i > 0; i--)
+ for (unsigned int i = bank->bus_width; i > 0; i--)
*cmd_buf++ = (i & (bank->chip_width - 1)) ? 0x0 : cmd;
} else {
- for (int i = 1; i <= bank->bus_width; i++)
+ for (unsigned int i = 1; i <= bank->bus_width; i++)
*cmd_buf++ = (i & (bank->chip_width - 1)) ? 0x0 : cmd;
}
}
@@ -217,13 +217,13 @@ static int cfi_get_u8(struct flash_bank *bank, int sector, uint32_t offset, uint
return retval;
if (cfi_info->endianness == TARGET_LITTLE_ENDIAN) {
- for (int i = 0; i < bank->bus_width / bank->chip_width; i++)
+ for (unsigned int i = 0; i < bank->bus_width / bank->chip_width; i++)
data[0] |= data[i];
*val = data[0];
} else {
uint8_t value = 0;
- for (int i = 0; i < bank->bus_width / bank->chip_width; i++)
+ for (unsigned int i = 0; i < bank->bus_width / bank->chip_width; i++)
value |= data[bank->bus_width - 1 - i];
*val = value;
@@ -877,14 +877,15 @@ FLASH_BANK_COMMAND_HANDLER(cfi_flash_bank_command)
return cfi_flash_bank_cmd(bank, CMD_ARGC, CMD_ARGV);
}
-static int cfi_intel_erase(struct flash_bank *bank, int first, int last)
+static int cfi_intel_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
int retval;
struct cfi_flash_bank *cfi_info = bank->driver_priv;
cfi_intel_clear_status_register(bank);
- for (int i = first; i <= last; i++) {
+ for (unsigned int i = first; i <= last; i++) {
retval = cfi_send_command(bank, 0x20, cfi_flash_address(bank, i, 0x0));
if (retval != ERROR_OK)
return retval;
@@ -905,7 +906,7 @@ static int cfi_intel_erase(struct flash_bank *bank, int first, int last)
if (retval != ERROR_OK)
return retval;
- LOG_ERROR("couldn't erase block %i of flash bank at base "
+ LOG_ERROR("couldn't erase block %u of flash bank at base "
TARGET_ADDR_FMT, i, bank->base);
return ERROR_FLASH_OPERATION_FAILED;
}
@@ -931,13 +932,14 @@ int cfi_spansion_unlock_seq(struct flash_bank *bank)
return ERROR_OK;
}
-static int cfi_spansion_erase(struct flash_bank *bank, int first, int last)
+static int cfi_spansion_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
int retval;
struct cfi_flash_bank *cfi_info = bank->driver_priv;
struct cfi_spansion_pri_ext *pri_ext = cfi_info->pri_ext;
- for (int i = first; i <= last; i++) {
+ for (unsigned int i = first; i <= last; i++) {
retval = cfi_spansion_unlock_seq(bank);
if (retval != ERROR_OK)
return retval;
@@ -970,7 +972,8 @@ static int cfi_spansion_erase(struct flash_bank *bank, int first, int last)
return cfi_send_command(bank, 0xf0, cfi_flash_address(bank, 0, 0x0));
}
-int cfi_erase(struct flash_bank *bank, int first, int last)
+int cfi_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct cfi_flash_bank *cfi_info = bank->driver_priv;
@@ -979,7 +982,7 @@ int cfi_erase(struct flash_bank *bank, int first, int last)
return ERROR_TARGET_NOT_HALTED;
}
- if ((first < 0) || (last < first) || (last >= bank->num_sectors))
+ if ((last < first) || (last >= bank->num_sectors))
return ERROR_FLASH_SECTOR_INVALID;
if (cfi_info->qry[0] != 'Q')
@@ -999,7 +1002,8 @@ int cfi_erase(struct flash_bank *bank, int first, int last)
return ERROR_OK;
}
-static int cfi_intel_protect(struct flash_bank *bank, int set, int first, int last)
+static int cfi_intel_protect(struct flash_bank *bank, int set,
+ unsigned int first, unsigned int last)
{
int retval;
struct cfi_flash_bank *cfi_info = bank->driver_priv;
@@ -1016,7 +1020,7 @@ static int cfi_intel_protect(struct flash_bank *bank, int set, int first, int la
cfi_intel_clear_status_register(bank);
- for (int i = first; i <= last; i++) {
+ for (unsigned int i = first; i <= last; i++) {
retval = cfi_send_command(bank, 0x60, cfi_flash_address(bank, i, 0x0));
if (retval != ERROR_OK)
return retval;
@@ -1087,7 +1091,7 @@ static int cfi_intel_protect(struct flash_bank *bank, int set, int first, int la
* 3. re-protect what should be protected.
*
*/
- for (int i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
if (bank->sectors[i].is_protected == 1) {
cfi_intel_clear_status_register(bank);
@@ -1110,7 +1114,8 @@ static int cfi_intel_protect(struct flash_bank *bank, int set, int first, int la
return cfi_send_command(bank, 0xff, cfi_flash_address(bank, 0, 0x0));
}
-int cfi_protect(struct flash_bank *bank, int set, int first, int last)
+int cfi_protect(struct flash_bank *bank, int set, unsigned int first,
+ unsigned int last)
{
struct cfi_flash_bank *cfi_info = bank->driver_priv;
@@ -1146,7 +1151,7 @@ static uint32_t cfi_command_val(struct flash_bank *bank, uint8_t cmd)
case 4:
return target_buffer_get_u32(target, buf);
default:
- LOG_ERROR("Unsupported bank buswidth %d, can't do block memory writes",
+ LOG_ERROR("Unsupported bank buswidth %u, can't do block memory writes",
bank->bus_width);
return 0;
}
@@ -1266,7 +1271,7 @@ static int cfi_intel_write_block(struct flash_bank *bank, const uint8_t *buffer,
target_code_size = sizeof(word_32_code);
break;
default:
- LOG_ERROR("Unsupported bank buswidth %d, can't do block memory writes",
+ LOG_ERROR("Unsupported bank buswidth %u, can't do block memory writes",
bank->bus_width);
return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
}
@@ -1502,7 +1507,7 @@ static int cfi_spansion_write_block_mips(struct flash_bank *bank, const uint8_t
}
break;
default:
- LOG_ERROR("Unsupported bank buswidth %d, can't do block memory writes",
+ LOG_ERROR("Unsupported bank buswidth %u, can't do block memory writes",
bank->bus_width);
return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
}
@@ -1881,7 +1886,7 @@ static int cfi_spansion_write_block(struct flash_bank *bank, const uint8_t *buff
target_code_size = sizeof(armv4_5_word_32_code);
break;
default:
- LOG_ERROR("Unsupported bank buswidth %d, can't do block memory writes",
+ LOG_ERROR("Unsupported bank buswidth %u, can't do block memory writes",
bank->bus_width);
return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
}
@@ -2286,7 +2291,7 @@ static int cfi_read(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, u
return retval;
/* take only bytes we need */
- for (int i = align; (i < bank->bus_width) && (count > 0); i++, count--)
+ for (unsigned int i = align; (i < bank->bus_width) && (count > 0); i++, count--)
*buffer++ = current_word[i];
read_p += bank->bus_width;
@@ -2312,7 +2317,7 @@ static int cfi_read(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, u
return retval;
/* take only bytes we need */
- for (int i = 0; (i < bank->bus_width) && (count > 0); i++, count--)
+ for (unsigned int i = 0; (i < bank->bus_width) && (count > 0); i++, count--)
*buffer++ = current_word[i];
}
@@ -2355,9 +2360,7 @@ static int cfi_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t of
return retval;
/* replace only bytes that must be written */
- for (int i = align;
- (i < bank->bus_width) && (count > 0);
- i++, count--)
+ for (unsigned int i = align; (i < bank->bus_width) && (count > 0); i++, count--)
if (cfi_info->data_swap)
/* data bytes are swapped (reverse endianness) */
current_word[bank->bus_width - i] = *buffer++;
@@ -2440,7 +2443,7 @@ static int cfi_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t of
}
/* try the slow way? */
if (fallback) {
- for (int i = 0; i < bank->bus_width; i++)
+ for (unsigned int i = 0; i < bank->bus_width; i++)
current_word[i] = *buffer++;
retval = cfi_write_word(bank, current_word, write_p);
@@ -2475,7 +2478,7 @@ static int cfi_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t of
return retval;
/* replace only bytes that must be written */
- for (int i = 0; (i < bank->bus_width) && (count > 0); i++, count--)
+ for (unsigned int i = 0; (i < bank->bus_width) && (count > 0); i++, count--)
if (cfi_info->data_swap)
/* data bytes are swapped (reverse endianness) */
current_word[bank->bus_width - i] = *buffer++;
@@ -2576,7 +2579,7 @@ int cfi_probe(struct flash_bank *bank)
{
struct cfi_flash_bank *cfi_info = bank->driver_priv;
struct target *target = bank->target;
- int num_sectors = 0;
+ unsigned int num_sectors = 0;
int sector = 0;
uint32_t unlock1 = 0x555;
uint32_t unlock2 = 0x2aa;
@@ -2640,7 +2643,7 @@ int cfi_probe(struct flash_bank *bank)
cfi_info->device_id = target_buffer_get_u32(target, value_buf1);
break;
default:
- LOG_ERROR("Unsupported bank chipwidth %d, can't probe memory",
+ LOG_ERROR("Unsupported bank chipwidth %u, can't probe memory",
bank->chip_width);
return ERROR_FLASH_OPERATION_FAILED;
}
@@ -2928,7 +2931,7 @@ static int cfi_intel_protect_check(struct flash_bank *bank)
if (retval != ERROR_OK)
return retval;
- for (int i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
uint8_t block_status;
retval = cfi_get_u8(bank, i, 0x2, &block_status);
if (retval != ERROR_OK)
@@ -2957,7 +2960,7 @@ static int cfi_spansion_protect_check(struct flash_bank *bank)
if (retval != ERROR_OK)
return retval;
- for (int i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
uint8_t block_status;
retval = cfi_get_u8(bank, i, 0x2, &block_status);
if (retval != ERROR_OK)
diff --git a/src/flash/nor/cfi.h b/src/flash/nor/cfi.h
index aef7a04..effa1d5 100644
--- a/src/flash/nor/cfi.h
+++ b/src/flash/nor/cfi.h
@@ -154,8 +154,9 @@ struct cfi_fixup {
const void *param;
};
-int cfi_erase(struct flash_bank *bank, int first, int last);
-int cfi_protect(struct flash_bank *bank, int set, int first, int last);
+int cfi_erase(struct flash_bank *bank, unsigned int first, unsigned int last);
+int cfi_protect(struct flash_bank *bank, int set, unsigned int first,
+ unsigned int last);
int cfi_probe(struct flash_bank *bank);
int cfi_auto_probe(struct flash_bank *bank);
int cfi_protect_check(struct flash_bank *bank);
diff --git a/src/flash/nor/core.c b/src/flash/nor/core.c
index 043ff13..b1a3662 100644
--- a/src/flash/nor/core.c
+++ b/src/flash/nor/core.c
@@ -37,21 +37,23 @@
static struct flash_bank *flash_banks;
-int flash_driver_erase(struct flash_bank *bank, int first, int last)
+int flash_driver_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
int retval;
retval = bank->driver->erase(bank, first, last);
if (retval != ERROR_OK)
- LOG_ERROR("failed erasing sectors %d to %d", first, last);
+ LOG_ERROR("failed erasing sectors %u to %u", first, last);
return retval;
}
-int flash_driver_protect(struct flash_bank *bank, int set, int first, int last)
+int flash_driver_protect(struct flash_bank *bank, int set, unsigned int first,
+ unsigned int last)
{
int retval;
- int num_blocks;
+ unsigned int num_blocks;
if (bank->num_prot_blocks)
num_blocks = bank->num_prot_blocks;
@@ -60,7 +62,7 @@ int flash_driver_protect(struct flash_bank *bank, int set, int first, int last)
/* callers may not supply illegal parameters ... */
- if (first < 0 || first > last || last >= num_blocks) {
+ if (first > last || last >= num_blocks) {
LOG_ERROR("illegal protection block range");
return ERROR_FAIL;
}
@@ -86,7 +88,7 @@ int flash_driver_protect(struct flash_bank *bank, int set, int first, int last)
*/
retval = bank->driver->protect(bank, set, first, last);
if (retval != ERROR_OK)
- LOG_ERROR("failed setting protection for blocks %d to %d", first, last);
+ LOG_ERROR("failed setting protection for blocks %u to %u", first, last);
return retval;
}
@@ -157,10 +159,10 @@ struct flash_bank *flash_bank_list(void)
return flash_banks;
}
-struct flash_bank *get_flash_bank_by_num_noprobe(int num)
+struct flash_bank *get_flash_bank_by_num_noprobe(unsigned int num)
{
struct flash_bank *p;
- int i = 0;
+ unsigned int i = 0;
for (p = flash_banks; p; p = p->next) {
if (i++ == num)
@@ -170,10 +172,10 @@ struct flash_bank *get_flash_bank_by_num_noprobe(int num)
return NULL;
}
-int flash_get_bank_count(void)
+unsigned int flash_get_bank_count(void)
{
struct flash_bank *p;
- int i = 0;
+ unsigned int i = 0;
for (p = flash_banks; p; p = p->next)
i++;
return i;
@@ -249,7 +251,7 @@ int get_flash_bank_by_name(const char *name, struct flash_bank **bank_result)
return ERROR_OK;
}
-int get_flash_bank_by_num(int num, struct flash_bank **bank)
+int get_flash_bank_by_num(unsigned int num, struct flash_bank **bank)
{
struct flash_bank *p = get_flash_bank_by_num_noprobe(num);
int retval;
@@ -306,7 +308,6 @@ static int default_flash_mem_blank_check(struct flash_bank *bank)
{
struct target *target = bank->target;
const int buffer_size = 1024;
- int i;
uint32_t nBytes;
int retval = ERROR_OK;
@@ -317,7 +318,7 @@ static int default_flash_mem_blank_check(struct flash_bank *bank)
uint8_t *buffer = malloc(buffer_size);
- for (i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
uint32_t j;
bank->sectors[i].is_erased = 1;
@@ -353,7 +354,6 @@ done:
int default_flash_blank_check(struct flash_bank *bank)
{
struct target *target = bank->target;
- int i;
int retval;
if (bank->target->state != TARGET_HALTED) {
@@ -366,14 +366,14 @@ int default_flash_blank_check(struct flash_bank *bank)
if (block_array == NULL)
return default_flash_mem_blank_check(bank);
- for (i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
block_array[i].address = bank->base + bank->sectors[i].offset;
block_array[i].size = bank->sectors[i].size;
block_array[i].result = UINT32_MAX; /* erase state unknown */
}
bool fast_check = true;
- for (i = 0; i < bank->num_sectors; ) {
+ for (unsigned int i = 0; i < bank->num_sectors; ) {
retval = target_blank_check_memory(target,
block_array + i, bank->num_sectors - i,
bank->erased_value);
@@ -388,7 +388,7 @@ int default_flash_blank_check(struct flash_bank *bank)
}
if (fast_check) {
- for (i = 0; i < bank->num_sectors; i++)
+ for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_erased = block_array[i].result;
retval = ERROR_OK;
} else {
@@ -418,7 +418,8 @@ int default_flash_blank_check(struct flash_bank *bank)
static int flash_iterate_address_range_inner(struct target *target,
char *pad_reason, target_addr_t addr, uint32_t length,
bool iterate_protect_blocks,
- int (*callback)(struct flash_bank *bank, int first, int last))
+ int (*callback)(struct flash_bank *bank, unsigned int first,
+ unsigned int last))
{
struct flash_bank *c;
struct flash_sector *block_array;
@@ -547,7 +548,8 @@ static int flash_iterate_address_range_inner(struct target *target,
static int flash_iterate_address_range(struct target *target,
char *pad_reason, target_addr_t addr, uint32_t length,
bool iterate_protect_blocks,
- int (*callback)(struct flash_bank *bank, int first, int last))
+ int (*callback)(struct flash_bank *bank, unsigned int first,
+ unsigned int last))
{
struct flash_bank *c;
int retval = ERROR_OK;
@@ -585,7 +587,8 @@ int flash_erase_address_range(struct target *target,
addr, length, false, &flash_driver_erase);
}
-static int flash_driver_unprotect(struct flash_bank *bank, int first, int last)
+static int flash_driver_unprotect(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
return flash_driver_protect(bank, 0, first, last);
}
@@ -627,8 +630,7 @@ target_addr_t flash_write_align_start(struct flash_bank *bank, target_addr_t add
if (bank->write_start_alignment == FLASH_WRITE_ALIGN_SECTOR) {
uint32_t offset = addr - bank->base;
uint32_t aligned = 0;
- int sect;
- for (sect = 0; sect < bank->num_sectors; sect++) {
+ for (unsigned int sect = 0; sect < bank->num_sectors; sect++) {
if (bank->sectors[sect].offset > offset)
break;
@@ -652,8 +654,7 @@ target_addr_t flash_write_align_end(struct flash_bank *bank, target_addr_t addr)
if (bank->write_end_alignment == FLASH_WRITE_ALIGN_SECTOR) {
uint32_t offset = addr - bank->base;
uint32_t aligned = 0;
- int sect;
- for (sect = 0; sect < bank->num_sectors; sect++) {
+ for (unsigned int sect = 0; sect < bank->num_sectors; sect++) {
aligned = bank->sectors[sect].offset + bank->sectors[sect].size - 1;
if (aligned >= offset)
break;
@@ -676,7 +677,7 @@ static bool flash_write_check_gap(struct flash_bank *bank,
return false;
if (bank->minimal_write_gap == FLASH_WRITE_GAP_SECTOR) {
- int sect;
+ unsigned int sect;
uint32_t offset1 = addr1 - bank->base;
/* find the sector following the one containing addr1 */
for (sect = 0; sect < bank->num_sectors; sect++) {
@@ -697,7 +698,7 @@ static bool flash_write_check_gap(struct flash_bank *bank,
int flash_write_unlock(struct target *target, struct image *image,
- uint32_t *written, int erase, bool unlock)
+ uint32_t *written, bool erase, bool unlock)
{
int retval = ERROR_OK;
@@ -847,12 +848,11 @@ int flash_write_unlock(struct target *target, struct image *image,
/* If we're applying any sector automagic, then pad this
* (maybe-combined) segment to the end of its last sector.
*/
- int sector;
uint32_t offset_start = run_address - c->base;
uint32_t offset_end = offset_start + run_size;
uint32_t end = offset_end, delta;
- for (sector = 0; sector < c->num_sectors; sector++) {
+ for (unsigned int sector = 0; sector < c->num_sectors; sector++) {
end = c->sectors[sector].offset
+ c->sectors[sector].size;
if (offset_end <= end)
@@ -955,20 +955,19 @@ done:
}
int flash_write(struct target *target, struct image *image,
- uint32_t *written, int erase)
+ uint32_t *written, bool erase)
{
return flash_write_unlock(target, image, written, erase, false);
}
-struct flash_sector *alloc_block_array(uint32_t offset, uint32_t size, int num_blocks)
+struct flash_sector *alloc_block_array(uint32_t offset, uint32_t size,
+ unsigned int num_blocks)
{
- int i;
-
struct flash_sector *array = calloc(num_blocks, sizeof(struct flash_sector));
if (array == NULL)
return NULL;
- for (i = 0; i < num_blocks; i++) {
+ for (unsigned int i = 0; i < num_blocks; i++) {
array[i].offset = offset;
array[i].size = size;
array[i].is_erased = -1;
diff --git a/src/flash/nor/core.h b/src/flash/nor/core.h
index ff5cb60..9f897e3 100644
--- a/src/flash/nor/core.h
+++ b/src/flash/nor/core.h
@@ -93,12 +93,12 @@ struct flash_bank {
const struct flash_driver *driver; /**< Driver for this bank. */
void *driver_priv; /**< Private driver storage pointer */
- int bank_number; /**< The 'bank' (or chip number) of this instance. */
+ unsigned int bank_number; /**< The 'bank' (or chip number) of this instance. */
target_addr_t base; /**< The base address of this bank */
uint32_t size; /**< The size of this chip bank, in bytes */
- int chip_width; /**< Width of the chip in bytes (1,2,4 bytes) */
- int bus_width; /**< Maximum bus width, in bytes (1,2,4 bytes) */
+ unsigned int chip_width; /**< Width of the chip in bytes (1,2,4 bytes) */
+ unsigned int bus_width; /**< Maximum bus width, in bytes (1,2,4 bytes) */
/** Erased value. Defaults to 0xFF. */
uint8_t erased_value;
@@ -124,7 +124,7 @@ struct flash_bank {
* be set initially to 0, and the flash driver must set this to
* some non-zero value during "probe()" or "auto_probe()".
*/
- int num_sectors;
+ unsigned int num_sectors;
/** Array of sectors, allocated and initialized by the flash driver */
struct flash_sector *sectors;
@@ -134,7 +134,7 @@ struct flash_bank {
* Driver probe can set protection blocks array to work with
* protection granularity different than sector size.
*/
- int num_prot_blocks;
+ unsigned int num_prot_blocks;
/** Array of protection blocks, allocated and initialized by the flash driver */
struct flash_sector *prot_blocks;
@@ -179,12 +179,12 @@ target_addr_t flash_write_align_end(struct flash_bank *bank, target_addr_t addr)
* @param target The target with the flash to be programmed.
* @param image The image that will be programmed to flash.
* @param written On return, contains the number of bytes written.
- * @param erase If non-zero, indicates the flash driver should first
+ * @param erase Indicates whether the flash driver should first
* erase the corresponding banks or sectors before programming.
* @returns ERROR_OK if successful; otherwise, an error code.
*/
int flash_write(struct target *target,
- struct image *image, uint32_t *written, int erase);
+ struct image *image, uint32_t *written, bool erase);
/**
* Forces targets to re-examine their erase/protection state.
@@ -193,7 +193,7 @@ int flash_write(struct target *target,
void flash_set_dirty(void);
/** @returns The number of flash banks currently defined. */
-int flash_get_bank_count(void);
+unsigned int flash_get_bank_count(void);
/** Deallocates bank->driver_priv */
void default_flash_free_driver_priv(struct flash_bank *bank);
@@ -240,7 +240,7 @@ struct flash_bank *get_flash_bank_by_name_noprobe(const char *name);
* @param bank returned bank if fn returns ERROR_OK
* @returns ERROR_OK if successful
*/
-int get_flash_bank_by_num(int num, struct flash_bank **bank);
+int get_flash_bank_by_num(unsigned int num, struct flash_bank **bank);
/**
* Retrieves @a bank from a command argument, reporting errors parsing
* the bank identifier or retrieving the specified bank. The bank
@@ -258,7 +258,7 @@ COMMAND_HELPER(flash_command_get_bank, unsigned name_index,
* @param num The flash bank number.
* @returns A struct flash_bank for flash bank @a num, or NULL.
*/
-struct flash_bank *get_flash_bank_by_num_noprobe(int num);
+struct flash_bank *get_flash_bank_by_num_noprobe(unsigned int num);
/**
* Returns the flash bank located at a specified address.
* @param target The target, presumed to contain one or more banks.
@@ -275,6 +275,7 @@ int get_flash_bank_by_addr(struct target *target, target_addr_t addr, bool check
* @param num_blocks Number of blocks in array.
* @returns A struct flash_sector pointer or NULL when allocation failed.
*/
-struct flash_sector *alloc_block_array(uint32_t offset, uint32_t size, int num_blocks);
+struct flash_sector *alloc_block_array(uint32_t offset, uint32_t size,
+ unsigned int num_blocks);
#endif /* OPENOCD_FLASH_NOR_CORE_H */
diff --git a/src/flash/nor/driver.h b/src/flash/nor/driver.h
index 9c56d4e..ea8657b 100644
--- a/src/flash/nor/driver.h
+++ b/src/flash/nor/driver.h
@@ -104,7 +104,8 @@ struct flash_driver {
* @param last The number of the last sector to erase, typically N-1.
* @returns ERROR_OK if successful; otherwise, an error code.
*/
- int (*erase)(struct flash_bank *bank, int first, int last);
+ int (*erase)(struct flash_bank *bank, unsigned int first,
+ unsigned int last);
/**
* Bank/sector protection routine (target-specific).
@@ -123,7 +124,8 @@ struct flash_driver {
* @param last The last sector to (un)project, typically N-1.
* @returns ERROR_OK if successful; otherwise, an error code.
*/
- int (*protect)(struct flash_bank *bank, int set, int first, int last);
+ int (*protect)(struct flash_bank *bank, int set, unsigned int first,
+ unsigned int last);
/**
* Program data into the flash. Note CPU address will be
diff --git a/src/flash/nor/dsp5680xx_flash.c b/src/flash/nor/dsp5680xx_flash.c
index da67585..f06f143 100644
--- a/src/flash/nor/dsp5680xx_flash.c
+++ b/src/flash/nor/dsp5680xx_flash.c
@@ -48,9 +48,8 @@ static int dsp5680xx_build_sector_list(struct flash_bank *bank)
uint32_t offset = HFM_FLASH_BASE_ADDR;
bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
- int i;
- for (i = 0; i < bank->num_sectors; ++i) {
+ for (unsigned int i = 0; i < bank->num_sectors; ++i) {
bank->sectors[i].offset = i * HFM_SECTOR_SIZE;
bank->sectors[i].size = HFM_SECTOR_SIZE;
offset += bank->sectors[i].size;
@@ -120,8 +119,8 @@ static int dsp5680xx_flash_protect_check(struct flash_bank *bank)
*
* @return
*/
-static int dsp5680xx_flash_protect(struct flash_bank *bank, int set, int first,
- int last)
+static int dsp5680xx_flash_protect(struct flash_bank *bank, int set,
+ unsigned int first, unsigned int last)
{
/**
* This applies security to flash module after next reset, it does
@@ -204,7 +203,8 @@ static int dsp5680xx_probe(struct flash_bank *bank)
*
* @return
*/
-static int dsp5680xx_flash_erase(struct flash_bank *bank, int first, int last)
+static int dsp5680xx_flash_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
int retval;
@@ -212,14 +212,14 @@ static int dsp5680xx_flash_erase(struct flash_bank *bank, int first, int last)
if ((!(first | last)) || ((first == 0) && (last == (HFM_SECTOR_COUNT - 1))))
last = HFM_SECTOR_COUNT - 1;
if (retval == ERROR_OK)
- for (int i = first; i <= last; i++)
+ for (unsigned int i = first; i <= last; i++)
bank->sectors[i].is_erased = 1;
else
/**
* If an error occurred unknown status
*is set even though some sector could have been correctly erased.
*/
- for (int i = first; i <= last; i++)
+ for (unsigned int i = first; i <= last; i++)
bank->sectors[i].is_erased = -1;
return retval;
}
diff --git a/src/flash/nor/efm32.c b/src/flash/nor/efm32.c
index fe4ddd4..2c323b0 100644
--- a/src/flash/nor/efm32.c
+++ b/src/flash/nor/efm32.c
@@ -467,7 +467,8 @@ static int efm32x_erase_page(struct flash_bank *bank, uint32_t addr)
EFM32_MSC_STATUS_BUSY_MASK, 0);
}
-static int efm32x_erase(struct flash_bank *bank, int first, int last)
+static int efm32x_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct target *target = bank->target;
int ret = 0;
@@ -484,7 +485,7 @@ static int efm32x_erase(struct flash_bank *bank, int first, int last)
return ret;
}
- for (int i = first; i <= last; i++) {
+ for (unsigned int i = first; i <= last; i++) {
ret = efm32x_erase_page(bank, bank->sectors[i].offset);
if (ERROR_OK != ret)
LOG_ERROR("Failed to erase page %d", i);
@@ -614,7 +615,8 @@ static int efm32x_set_page_lock(struct flash_bank *bank, size_t page, int set)
return ERROR_OK;
}
-static int efm32x_protect(struct flash_bank *bank, int set, int first, int last)
+static int efm32x_protect(struct flash_bank *bank, int set, unsigned int first,
+ unsigned int last)
{
struct target *target = bank->target;
int ret = 0;
@@ -629,7 +631,7 @@ static int efm32x_protect(struct flash_bank *bank, int set, int first, int last)
return ERROR_TARGET_NOT_HALTED;
}
- for (int i = first; i <= last; i++) {
+ for (unsigned int i = first; i <= last; i++) {
ret = efm32x_set_page_lock(bank, i, set);
if (ERROR_OK != ret) {
LOG_ERROR("Failed to set lock on page %d", i);
@@ -1040,7 +1042,7 @@ static int efm32x_protect_check(struct flash_bank *bank)
assert(NULL != bank->sectors);
- for (int i = 0; i < bank->num_sectors; i++)
+ for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_protected = efm32x_get_page_lock(bank, i);
return ERROR_OK;
diff --git a/src/flash/nor/em357.c b/src/flash/nor/em357.c
index 38fb731..a93c81e 100644
--- a/src/flash/nor/em357.c
+++ b/src/flash/nor/em357.c
@@ -343,10 +343,10 @@ static int em357_protect_check(struct flash_bank *bank)
return ERROR_OK;
}
-static int em357_erase(struct flash_bank *bank, int first, int last)
+static int em357_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct target *target = bank->target;
- int i;
if (bank->target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
@@ -367,7 +367,7 @@ static int em357_erase(struct flash_bank *bank, int first, int last)
if (retval != ERROR_OK)
return retval;
- for (i = first; i <= last; i++) {
+ for (unsigned int i = first; i <= last; i++) {
retval = target_write_u32(target, EM357_FLASH_CR, FLASH_PER);
if (retval != ERROR_OK)
return retval;
@@ -393,12 +393,13 @@ static int em357_erase(struct flash_bank *bank, int first, int last)
return ERROR_OK;
}
-static int em357_protect(struct flash_bank *bank, int set, int first, int last)
+static int em357_protect(struct flash_bank *bank, int set, unsigned int first,
+ unsigned int last)
{
struct em357_flash_bank *em357_info = NULL;
struct target *target = bank->target;
uint16_t prot_reg[4] = {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF};
- int i, reg, bit;
+ int reg, bit;
int status;
uint32_t protection;
@@ -431,7 +432,7 @@ static int em357_protect(struct flash_bank *bank, int set, int first, int last)
prot_reg[1] = (uint16_t)(protection >> 8);
prot_reg[2] = (uint16_t)(protection >> 16);
- for (i = first; i <= last; i++) {
+ for (unsigned int i = first; i <= last; i++) {
reg = (i / em357_info->ppage_size) / 8;
bit = (i / em357_info->ppage_size) - (reg * 8);
@@ -870,8 +871,6 @@ static int em357_mass_erase(struct flash_bank *bank)
COMMAND_HANDLER(em357_handle_mass_erase_command)
{
- int i;
-
if (CMD_ARGC < 1)
return ERROR_COMMAND_SYNTAX_ERROR;
@@ -883,7 +882,7 @@ COMMAND_HANDLER(em357_handle_mass_erase_command)
retval = em357_mass_erase(bank);
if (retval == ERROR_OK) {
/* set all sectors as erased */
- for (i = 0; i < bank->num_sectors; i++)
+ for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_erased = 1;
command_print(CMD, "em357 mass erase complete");
diff --git a/src/flash/nor/esirisc_flash.c b/src/flash/nor/esirisc_flash.c
index 3bed065..a5785a9 100644
--- a/src/flash/nor/esirisc_flash.c
+++ b/src/flash/nor/esirisc_flash.c
@@ -252,7 +252,8 @@ static int esirisc_flash_recall(struct flash_bank *bank)
return esirisc_flash_control(bank, CONTROL_R);
}
-static int esirisc_flash_erase(struct flash_bank *bank, int first, int last)
+static int esirisc_flash_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct esirisc_flash_bank *esirisc_info = bank->driver_priv;
struct target *target = bank->target;
@@ -263,7 +264,7 @@ static int esirisc_flash_erase(struct flash_bank *bank, int first, int last)
(void)esirisc_flash_disable_protect(bank);
- for (int page = first; page < last; ++page) {
+ for (unsigned int page = first; page < last; ++page) {
uint32_t address = page * FLASH_PAGE_SIZE;
target_write_u32(target, esirisc_info->cfg + ADDRESS, address);
diff --git a/src/flash/nor/faux.c b/src/flash/nor/faux.c
index a894d03..d6c6b2d 100644
--- a/src/flash/nor/faux.c
+++ b/src/flash/nor/faux.c
@@ -56,11 +56,10 @@ FLASH_BANK_COMMAND_HANDLER(faux_flash_bank_command)
bank->driver_priv = info;
/* Use 0x10000 as a fixed sector size. */
- int i = 0;
uint32_t offset = 0;
bank->num_sectors = bank->size/sectorSize;
bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
- for (i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
bank->sectors[i].offset = offset;
bank->sectors[i].size = sectorSize;
offset += bank->sectors[i].size;
@@ -78,7 +77,8 @@ FLASH_BANK_COMMAND_HANDLER(faux_flash_bank_command)
return ERROR_OK;
}
-static int faux_erase(struct flash_bank *bank, int first, int last)
+static int faux_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct faux_flash_bank *info = bank->driver_priv;
memset(info->memory + first*sectorSize, 0xff, sectorSize*(last-first + 1));
diff --git a/src/flash/nor/fespi.c b/src/flash/nor/fespi.c
index 05489fd..134fba6 100644
--- a/src/flash/nor/fespi.c
+++ b/src/flash/nor/fespi.c
@@ -359,21 +359,21 @@ static int fespi_erase_sector(struct flash_bank *bank, int sector)
return ERROR_OK;
}
-static int fespi_erase(struct flash_bank *bank, int first, int last)
+static int fespi_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct target *target = bank->target;
struct fespi_flash_bank *fespi_info = bank->driver_priv;
int retval = ERROR_OK;
- int sector;
- LOG_DEBUG("%s: from sector %d to sector %d", __func__, first, last);
+ LOG_DEBUG("%s: from sector %u to sector %u", __func__, first, last);
if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED;
}
- if ((first < 0) || (last < first) || (last >= bank->num_sectors)) {
+ if ((last < first) || (last >= bank->num_sectors)) {
LOG_ERROR("Flash sector invalid");
return ERROR_FLASH_SECTOR_INVALID;
}
@@ -383,9 +383,9 @@ static int fespi_erase(struct flash_bank *bank, int first, int last)
return ERROR_FLASH_BANK_NOT_PROBED;
}
- for (sector = first; sector <= last; sector++) {
+ for (unsigned int sector = first; sector <= last; sector++) {
if (bank->sectors[sector].is_protected) {
- LOG_ERROR("Flash sector %d protected", sector);
+ LOG_ERROR("Flash sector %u protected", sector);
return ERROR_FAIL;
}
}
@@ -410,7 +410,7 @@ static int fespi_erase(struct flash_bank *bank, int first, int last)
if (retval != ERROR_OK)
goto done;
- for (sector = first; sector <= last; sector++) {
+ for (unsigned int sector = first; sector <= last; sector++) {
retval = fespi_erase_sector(bank, sector);
if (retval != ERROR_OK)
goto done;
@@ -425,11 +425,9 @@ done:
}
static int fespi_protect(struct flash_bank *bank, int set,
- int first, int last)
+ unsigned int first, unsigned int last)
{
- int sector;
-
- for (sector = first; sector <= last; sector++)
+ for (unsigned int sector = first; sector <= last; sector++)
bank->sectors[sector].is_protected = set;
return ERROR_OK;
}
@@ -735,7 +733,6 @@ static int fespi_write(struct flash_bank *bank, const uint8_t *buffer,
struct target *target = bank->target;
struct fespi_flash_bank *fespi_info = bank->driver_priv;
uint32_t cur_count, page_size, page_offset;
- int sector;
int retval = ERROR_OK;
LOG_DEBUG("%s: offset=0x%08" PRIx32 " count=0x%08" PRIx32,
@@ -752,14 +749,14 @@ static int fespi_write(struct flash_bank *bank, const uint8_t *buffer,
}
/* Check sector protection */
- for (sector = 0; sector < bank->num_sectors; sector++) {
+ for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
/* Start offset in or before this sector? */
/* End offset in or behind this sector? */
if ((offset <
(bank->sectors[sector].offset + bank->sectors[sector].size))
&& ((offset + count - 1) >= bank->sectors[sector].offset)
&& bank->sectors[sector].is_protected) {
- LOG_ERROR("Flash sector %d protected", sector);
+ LOG_ERROR("Flash sector %u protected", sector);
return ERROR_FAIL;
}
}
@@ -994,7 +991,7 @@ static int fespi_probe(struct flash_bank *bank)
return ERROR_FAIL;
}
- for (int sector = 0; sector < bank->num_sectors; sector++) {
+ for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
sectors[sector].offset = sector * sectorsize;
sectors[sector].size = sectorsize;
sectors[sector].is_erased = -1;
diff --git a/src/flash/nor/fm3.c b/src/flash/nor/fm3.c
index eeefa3f..1dd9ae5 100644
--- a/src/flash/nor/fm3.c
+++ b/src/flash/nor/fm3.c
@@ -201,13 +201,14 @@ static int fm3_busy_wait(struct target *target, uint32_t offset, int timeout_ms)
return retval;
}
-static int fm3_erase(struct flash_bank *bank, int first, int last)
+static int fm3_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct fm3_flash_bank *fm3_info = bank->driver_priv;
struct target *target = bank->target;
int retval = ERROR_OK;
uint32_t u32DummyRead;
- int sector, odd;
+ int odd;
uint32_t u32FlashType;
uint32_t u32FlashSeqAddress1;
uint32_t u32FlashSeqAddress2;
@@ -260,7 +261,7 @@ static int fm3_erase(struct flash_bank *bank, int first, int last)
0x00, 0xBE, /* BKPT #0 */
};
- LOG_INFO("Fujitsu MB9[A/B]FXXX: Sector Erase ... (%d to %d)", first, last);
+ LOG_INFO("Fujitsu MB9[A/B]FXXX: Sector Erase ... (%u to %u)", first, last);
/* disable HW watchdog */
retval = target_write_u32(target, 0x40011C00, 0x1ACCE551);
@@ -304,7 +305,7 @@ static int fm3_erase(struct flash_bank *bank, int first, int last)
init_reg_param(&reg_params[2], "r2", 32, PARAM_OUT); /* offset */
/* write code buffer and use Flash sector erase code within fm3 */
- for (sector = first ; sector <= last ; sector++) {
+ for (unsigned int sector = first ; sector <= last ; sector++) {
uint32_t offset = bank->sectors[sector].offset;
for (odd = 0; odd < 2 ; odd++) {
@@ -943,8 +944,6 @@ static int fm3_chip_erase(struct flash_bank *bank)
COMMAND_HANDLER(fm3_handle_chip_erase_command)
{
- int i;
-
if (CMD_ARGC < 1)
return ERROR_COMMAND_SYNTAX_ERROR;
@@ -955,7 +954,7 @@ COMMAND_HANDLER(fm3_handle_chip_erase_command)
if (fm3_chip_erase(bank) == ERROR_OK) {
/* set all sectors as erased */
- for (i = 0; i < bank->num_sectors; i++)
+ for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_erased = 1;
command_print(CMD, "fm3 chip erase complete");
diff --git a/src/flash/nor/fm4.c b/src/flash/nor/fm4.c
index 7e3a1c5..4daec78 100644
--- a/src/flash/nor/fm4.c
+++ b/src/flash/nor/fm4.c
@@ -98,14 +98,15 @@ static int fm4_enter_flash_cpu_rom_mode(struct target *target)
return ERROR_OK;
}
-static int fm4_flash_erase(struct flash_bank *bank, int first, int last)
+static int fm4_flash_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct target *target = bank->target;
struct working_area *workarea;
struct reg_param reg_params[4];
struct armv7m_algorithm armv7m_algo;
unsigned i;
- int retval, sector;
+ int retval;
const uint8_t erase_sector_code[] = {
#include "../../../contrib/loaders/flash/fm4/erase.inc"
};
@@ -115,7 +116,7 @@ static int fm4_flash_erase(struct flash_bank *bank, int first, int last)
return ERROR_TARGET_NOT_HALTED;
}
- LOG_DEBUG("Spansion FM4 erase sectors %d to %d", first, last);
+ LOG_DEBUG("Spansion FM4 erase sectors %u to %u", first, last);
retval = fm4_disable_hw_watchdog(target);
if (retval != ERROR_OK)
@@ -145,7 +146,7 @@ static int fm4_flash_erase(struct flash_bank *bank, int first, int last)
init_reg_param(&reg_params[2], "r2", 32, PARAM_OUT);
init_reg_param(&reg_params[3], "r3", 32, PARAM_IN);
- for (sector = first; sector <= last; sector++) {
+ for (unsigned int sector = first; sector <= last; sector++) {
uint32_t addr = bank->base + bank->sectors[sector].offset;
uint32_t result;
@@ -347,7 +348,6 @@ static int mb9bf_probe(struct flash_bank *bank)
{
struct fm4_flash_bank *fm4_bank = bank->driver_priv;
uint32_t flash_addr = bank->base;
- int i;
switch (fm4_bank->variant) {
case mb9bfx64:
@@ -369,10 +369,10 @@ static int mb9bf_probe(struct flash_bank *bank)
return ERROR_FLASH_OPER_UNSUPPORTED;
}
- LOG_DEBUG("%d sectors", bank->num_sectors);
+ LOG_DEBUG("%u sectors", bank->num_sectors);
bank->sectors = calloc(bank->num_sectors,
sizeof(struct flash_sector));
- for (i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
if (i < 4)
bank->sectors[i].size = 8 * 1024;
else if (i == 4)
@@ -409,7 +409,8 @@ static int s6e2cc_probe(struct flash_bank *bank)
struct fm4_flash_bank *fm4_bank = bank->driver_priv;
uint32_t u32_value;
uint32_t flash_addr = bank->base;
- int i, retval, num_sectors, num_extra_sectors;
+ int retval;
+ unsigned int i, num_extra_sectors, num_sectors;
retval = target_read_u32(target, DFCTRLR, &u32_value);
if (retval != ERROR_OK)
@@ -435,7 +436,7 @@ static int s6e2cc_probe(struct flash_bank *bank)
num_extra_sectors = (fm4_bank->macro_nr == 0) ? 1 : 4;
bank->num_sectors = num_sectors + num_extra_sectors;
- LOG_DEBUG("%d sectors", bank->num_sectors);
+ LOG_DEBUG("%u sectors", bank->num_sectors);
bank->sectors = calloc(bank->num_sectors,
sizeof(struct flash_sector));
for (i = 0; i < num_sectors; i++) {
@@ -466,12 +467,11 @@ static int s6e2cc_probe(struct flash_bank *bank)
static int s6e2dh_probe(struct flash_bank *bank)
{
uint32_t flash_addr = bank->base;
- int i;
bank->num_sectors = 10;
bank->sectors = calloc(bank->num_sectors,
sizeof(struct flash_sector));
- for (i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
if (i < 4)
bank->sectors[i].size = 8 * 1024;
else if (i == 4)
diff --git a/src/flash/nor/imp.h b/src/flash/nor/imp.h
index 87475a3..06fb2a2 100644
--- a/src/flash/nor/imp.h
+++ b/src/flash/nor/imp.h
@@ -18,6 +18,8 @@
#ifndef OPENOCD_FLASH_NOR_IMP_H
#define OPENOCD_FLASH_NOR_IMP_H
+#include <stdbool.h>
+
/* this is an internal header */
#include "core.h"
#include "driver.h"
@@ -35,8 +37,10 @@ void flash_bank_add(struct flash_bank *bank);
*/
struct flash_bank *flash_bank_list(void);
-int flash_driver_erase(struct flash_bank *bank, int first, int last);
-int flash_driver_protect(struct flash_bank *bank, int set, int first, int last);
+int flash_driver_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last);
+int flash_driver_protect(struct flash_bank *bank, int set, unsigned int first,
+ unsigned int last);
int flash_driver_write(struct flash_bank *bank,
uint8_t *buffer, uint32_t offset, uint32_t count);
int flash_driver_read(struct flash_bank *bank,
@@ -44,6 +48,6 @@ int flash_driver_read(struct flash_bank *bank,
/* write (optional verify) an image to flash memory of the given target */
int flash_write_unlock(struct target *target, struct image *image,
- uint32_t *written, int erase, bool unlock);
+ uint32_t *written, bool erase, bool unlock);
#endif /* OPENOCD_FLASH_NOR_IMP_H */
diff --git a/src/flash/nor/jtagspi.c b/src/flash/nor/jtagspi.c
index d841579..ce3f9ca 100644
--- a/src/flash/nor/jtagspi.c
+++ b/src/flash/nor/jtagspi.c
@@ -216,7 +216,7 @@ static int jtagspi_probe(struct flash_bank *bank)
return ERROR_FAIL;
}
- for (int sector = 0; sector < bank->num_sectors; sector++) {
+ for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
sectors[sector].offset = sector * sectorsize;
sectors[sector].size = sectorsize;
sectors[sector].is_erased = -1;
@@ -299,7 +299,7 @@ static int jtagspi_bulk_erase(struct flash_bank *bank)
return retval;
}
-static int jtagspi_sector_erase(struct flash_bank *bank, int sector)
+static int jtagspi_sector_erase(struct flash_bank *bank, unsigned int sector)
{
struct jtagspi_flash_bank *info = bank->driver_priv;
int retval;
@@ -310,19 +310,19 @@ static int jtagspi_sector_erase(struct flash_bank *bank, int sector)
return retval;
jtagspi_cmd(bank, info->dev->erase_cmd, &bank->sectors[sector].offset, NULL, 0);
retval = jtagspi_wait(bank, JTAGSPI_MAX_TIMEOUT);
- LOG_INFO("sector %d took %" PRId64 " ms", sector, timeval_ms() - t0);
+ LOG_INFO("sector %u took %" PRId64 " ms", sector, timeval_ms() - t0);
return retval;
}
-static int jtagspi_erase(struct flash_bank *bank, int first, int last)
+static int jtagspi_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
- int sector;
struct jtagspi_flash_bank *info = bank->driver_priv;
int retval = ERROR_OK;
- LOG_DEBUG("erase from sector %d to sector %d", first, last);
+ LOG_DEBUG("erase from sector %u to sector %u", first, last);
- if ((first < 0) || (last < first) || (last >= bank->num_sectors)) {
+ if ((last < first) || (last >= bank->num_sectors)) {
LOG_ERROR("Flash sector invalid");
return ERROR_FLASH_SECTOR_INVALID;
}
@@ -332,9 +332,9 @@ static int jtagspi_erase(struct flash_bank *bank, int first, int last)
return ERROR_FLASH_BANK_NOT_PROBED;
}
- for (sector = first; sector <= last; sector++) {
+ for (unsigned int sector = first; sector <= last; sector++) {
if (bank->sectors[sector].is_protected) {
- LOG_ERROR("Flash sector %d protected", sector);
+ LOG_ERROR("Flash sector %u protected", sector);
return ERROR_FAIL;
}
}
@@ -352,7 +352,7 @@ static int jtagspi_erase(struct flash_bank *bank, int first, int last)
if (info->dev->erase_cmd == 0x00)
return ERROR_FLASH_OPER_UNSUPPORTED;
- for (sector = first; sector <= last; sector++) {
+ for (unsigned int sector = first; sector <= last; sector++) {
retval = jtagspi_sector_erase(bank, sector);
if (retval != ERROR_OK) {
LOG_ERROR("Sector erase failed.");
@@ -363,11 +363,10 @@ static int jtagspi_erase(struct flash_bank *bank, int first, int last)
return retval;
}
-static int jtagspi_protect(struct flash_bank *bank, int set, int first, int last)
+static int jtagspi_protect(struct flash_bank *bank, int set, unsigned int first,
+ unsigned int last)
{
- int sector;
-
- for (sector = first; sector <= last; sector++)
+ for (unsigned int sector = first; sector <= last; sector++)
bank->sectors[sector].is_protected = set;
return ERROR_OK;
}
diff --git a/src/flash/nor/kinetis.c b/src/flash/nor/kinetis.c
index 084e009..6753f0f 100644
--- a/src/flash/nor/kinetis.c
+++ b/src/flash/nor/kinetis.c
@@ -1338,7 +1338,8 @@ static int kinetis_write_block(struct flash_bank *bank, const uint8_t *buffer,
return retval;
}
-static int kinetis_protect(struct flash_bank *bank, int set, int first, int last)
+static int kinetis_protect(struct flash_bank *bank, int set, unsigned int first,
+ unsigned int last)
{
if (allow_fcf_writes) {
LOG_ERROR("Protection setting is possible with 'kinetis fcf_source protection' only!");
@@ -1350,7 +1351,7 @@ static int kinetis_protect(struct flash_bank *bank, int set, int first, int last
return ERROR_FLASH_BANK_INVALID;
}
- for (int i = first; i < bank->num_prot_blocks && i <= last; i++)
+ for (unsigned int i = first; i < bank->num_prot_blocks && i <= last; i++)
bank->prot_blocks[i].is_protected = set;
LOG_INFO("Protection bits will be written at the next FCF sector erase or write.");
@@ -1392,7 +1393,7 @@ static int kinetis_protect_check(struct flash_bank *bank)
}
b = k_bank->protection_block;
- for (int i = 0; i < bank->num_prot_blocks; i++) {
+ for (unsigned int i = 0; i < bank->num_prot_blocks; i++) {
if ((fprot >> b) & 1)
bank->prot_blocks[i].is_protected = 0;
else
@@ -1439,7 +1440,7 @@ static int kinetis_fill_fcf(struct flash_bank *bank, uint8_t *fcf)
assert(bank_iter->prot_blocks);
if (k_bank->flash_class == FC_PFLASH) {
- for (int i = 0; i < bank_iter->num_prot_blocks; i++) {
+ for (unsigned int i = 0; i < bank_iter->num_prot_blocks; i++) {
if (bank_iter->prot_blocks[i].is_protected == 1)
fprot &= ~pflash_bit;
@@ -1447,7 +1448,7 @@ static int kinetis_fill_fcf(struct flash_bank *bank, uint8_t *fcf)
}
} else if (k_bank->flash_class == FC_FLEX_NVM) {
- for (int i = 0; i < bank_iter->num_prot_blocks; i++) {
+ for (unsigned int i = 0; i < bank_iter->num_prot_blocks; i++) {
if (bank_iter->prot_blocks[i].is_protected == 1)
fdprot &= ~dflash_bit;
@@ -1616,7 +1617,8 @@ static void kinetis_invalidate_flash_cache(struct kinetis_chip *k_chip)
}
-static int kinetis_erase(struct flash_bank *bank, int first, int last)
+static int kinetis_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
int result;
struct kinetis_flash_bank *k_bank = bank->driver_priv;
@@ -1639,13 +1641,13 @@ static int kinetis_erase(struct flash_bank *bank, int first, int last)
* requested erase is PFlash or NVM and encompasses the entire
* block. Should be quicker.
*/
- for (int i = first; i <= last; i++) {
+ for (unsigned int i = first; i <= last; i++) {
/* set command and sector address */
result = kinetis_ftfx_command(bank->target, FTFx_CMD_SECTERASE, k_bank->prog_base + bank->sectors[i].offset,
0, 0, 0, 0, 0, 0, 0, 0, NULL);
if (result != ERROR_OK) {
- LOG_WARNING("erase sector %d failed", i);
+ LOG_WARNING("erase sector %u failed", i);
return ERROR_FLASH_OPERATION_FAILED;
}
@@ -2689,7 +2691,7 @@ static int kinetis_probe(struct flash_bank *bank)
if (bank->size > limit) {
bank->size = limit;
- LOG_DEBUG("FlexNVM bank %d limited to 0x%08" PRIx32 " due to active EEPROM backup",
+ LOG_DEBUG("FlexNVM bank %u limited to 0x%08" PRIx32 " due to active EEPROM backup",
k_bank->bank_number, limit);
}
@@ -2698,7 +2700,7 @@ static int kinetis_probe(struct flash_bank *bank)
k_bank->bank_number, size_k, k_bank->prog_base, k_bank->sector_size);
} else {
- LOG_ERROR("Cannot determine parameters for bank %d, only %d banks on device",
+ LOG_ERROR("Cannot determine parameters for bank %u, only %u banks on device",
k_bank->bank_number, num_blocks);
return ERROR_FLASH_BANK_INVALID;
}
@@ -2732,7 +2734,7 @@ static int kinetis_probe(struct flash_bank *bank)
}
if (k_bank->sector_size == 0) {
- LOG_ERROR("Unknown sector size for bank %d", bank->bank_number);
+ LOG_ERROR("Unknown sector size for bank %u", bank->bank_number);
return ERROR_FLASH_BANK_INVALID;
}
@@ -2827,7 +2829,7 @@ static int kinetis_blank_check(struct flash_bank *bank)
if (block_dirty) {
/* the whole bank is not erased, check sector-by-sector */
- for (int i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
/* normal margin */
result = kinetis_ftfx_command(bank->target, FTFx_CMD_SECTSTAT,
k_bank->prog_base + bank->sectors[i].offset,
@@ -2843,7 +2845,7 @@ static int kinetis_blank_check(struct flash_bank *bank)
}
} else {
/* the whole bank is erased, update all sectors */
- for (int i = 0; i < bank->num_sectors; i++)
+ for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_erased = 1;
}
} else {
diff --git a/src/flash/nor/kinetis_ke.c b/src/flash/nor/kinetis_ke.c
index cfc0492..206d6f7 100644
--- a/src/flash/nor/kinetis_ke.c
+++ b/src/flash/nor/kinetis_ke.c
@@ -764,7 +764,8 @@ static int kinetis_ke_write_words(struct flash_bank *bank, const uint8_t *buffer
return retval;
}
-static int kinetis_ke_protect(struct flash_bank *bank, int set, int first, int last)
+static int kinetis_ke_protect(struct flash_bank *bank, int set,
+ unsigned int first, unsigned int last)
{
LOG_WARNING("kinetis_ke_protect not supported yet");
/* FIXME: TODO */
@@ -809,7 +810,7 @@ static int kinetis_ke_protect_check(struct flash_bank *bank)
if (fpopen && fpldis && fphdis) {
LOG_WARNING("No flash protection found.");
- for (uint32_t i = 0; i < (uint32_t) bank->num_sectors; i++)
+ for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_protected = 0;
kinfo->protection_size = 0;
@@ -840,7 +841,7 @@ static int kinetis_ke_protect_check(struct flash_bank *bank)
/* hprot_from indicates from where the upper region is protected */
hprot_from = (0x8000 - hprot_size) / kinfo->sector_size;
- for (uint32_t i = 0; i < (uint32_t) bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
/* Check if the sector is in the lower region */
if (bank->sectors[i].offset < 0x4000) {
@@ -964,9 +965,10 @@ COMMAND_HANDLER(kinetis_ke_securing_test)
return kinetis_ke_ftmrx_command(bank, 2, FCCOBIX, FCCOBHI, FCCOBLO, &fstat);
}
-static int kinetis_ke_erase(struct flash_bank *bank, int first, int last)
+static int kinetis_ke_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
- int result, i;
+ int result;
uint8_t FCCOBIX[2], FCCOBHI[2], FCCOBLO[2], fstat;
bool fcf_erased = false;
@@ -982,7 +984,7 @@ static int kinetis_ke_erase(struct flash_bank *bank, int first, int last)
if (result != ERROR_OK)
return result;
- for (i = first; i <= last; i++) {
+ for (unsigned int i = first; i <= last; i++) {
FCCOBIX[0] = 0;
FCCOBHI[0] = FTMRX_CMD_ERASESECTOR;
FCCOBLO[0] = (bank->base + bank->sectors[i].offset) >> 16;
@@ -994,7 +996,7 @@ static int kinetis_ke_erase(struct flash_bank *bank, int first, int last)
result = kinetis_ke_ftmrx_command(bank, 2, FCCOBIX, FCCOBHI, FCCOBLO, &fstat);
if (result != ERROR_OK) {
- LOG_WARNING("erase sector %d failed", i);
+ LOG_WARNING("erase sector %u failed", i);
return ERROR_FLASH_OPERATION_FAILED;
}
@@ -1066,7 +1068,7 @@ static int kinetis_ke_write(struct flash_bank *bank, const uint8_t *buffer,
static int kinetis_ke_probe(struct flash_bank *bank)
{
- int result, i;
+ int result;
uint32_t offset = 0;
struct target *target = bank->target;
struct kinetis_ke_flash_bank *kinfo = bank->driver_priv;
@@ -1151,7 +1153,7 @@ static int kinetis_ke_probe(struct flash_bank *bank)
assert(bank->num_sectors > 0);
bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
- for (i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
bank->sectors[i].offset = offset;
bank->sectors[i].size = kinfo->sector_size;
offset += kinfo->sector_size;
@@ -1207,9 +1209,7 @@ static int kinetis_ke_blank_check(struct flash_bank *bank)
if (fstat & (FTMRX_FSTAT_MGSTAT0_MASK | FTMRX_FSTAT_MGSTAT1_MASK)) {
/* the whole bank is not erased, check sector-by-sector */
- int i;
-
- for (i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
FCCOBIX[0] = 0;
FCCOBHI[0] = FTMRX_CMD_SECTIONERASED;
FCCOBLO[0] = (bank->base + bank->sectors[i].offset) >> 16;
@@ -1235,8 +1235,7 @@ static int kinetis_ke_blank_check(struct flash_bank *bank)
}
} else {
/* the whole bank is erased, update all sectors */
- int i;
- for (i = 0; i < bank->num_sectors; i++)
+ for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_erased = 1;
}
diff --git a/src/flash/nor/lpc2000.c b/src/flash/nor/lpc2000.c
index 2a69af6..6758b43 100644
--- a/src/flash/nor/lpc2000.c
+++ b/src/flash/nor/lpc2000.c
@@ -432,7 +432,7 @@ static int lpc2000_build_sector_list(struct flash_bank *bank)
bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
- for (int i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
if (i < 8) {
bank->sectors[i].offset = offset;
bank->sectors[i].size = 4 * 1024;
@@ -494,7 +494,7 @@ static int lpc2000_build_sector_list(struct flash_bank *bank)
bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
- for (int i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
bank->sectors[i].offset = offset;
/* sectors 0-15 are 4kB-sized, 16 and above are 32kB-sized for LPC17xx/LPC40xx devices */
bank->sectors[i].size = (i < 16) ? 4 * 1024 : 32 * 1024;
@@ -524,7 +524,7 @@ static int lpc2000_build_sector_list(struct flash_bank *bank)
bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
- for (int i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
bank->sectors[i].offset = offset;
/* sectors 0-7 are 8kB-sized, 8 and above are 64kB-sized for LPC43xx devices */
bank->sectors[i].size = (i < 8) ? 8 * 1024 : 64 * 1024;
@@ -568,7 +568,7 @@ static int lpc2000_build_sector_list(struct flash_bank *bank)
bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
- for (int i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
bank->sectors[i].offset = offset;
/* all sectors are 1kB-sized for LPC8xx devices */
bank->sectors[i].size = 1 * 1024;
@@ -599,7 +599,7 @@ static int lpc2000_build_sector_list(struct flash_bank *bank)
bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
- for (int i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
bank->sectors[i].offset = offset;
bank->sectors[i].size = (i < LPC11xx_REG_SECTORS ? 4 : 32) * 1024;
offset += bank->sectors[i].size;
@@ -629,7 +629,7 @@ static int lpc2000_build_sector_list(struct flash_bank *bank)
bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
- for (int i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
bank->sectors[i].offset = offset;
/* all sectors are 4kB-sized */
bank->sectors[i].size = 4 * 1024;
@@ -657,7 +657,7 @@ static int lpc2000_build_sector_list(struct flash_bank *bank)
bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
- for (int i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
bank->sectors[i].offset = offset;
/* all sectors are 32kB-sized */
bank->sectors[i].size = 32 * 1024;
@@ -863,9 +863,10 @@ static int lpc2000_iap_call(struct flash_bank *bank, struct working_area *iap_wo
return status_code;
}
-static int lpc2000_iap_blank_check(struct flash_bank *bank, int first, int last)
+static int lpc2000_iap_blank_check(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
- if ((first < 0) || (last >= bank->num_sectors))
+ if (last >= bank->num_sectors)
return ERROR_FLASH_SECTOR_INVALID;
uint32_t param_table[5] = {0};
@@ -881,7 +882,7 @@ static int lpc2000_iap_blank_check(struct flash_bank *bank, int first, int last)
if (lpc2000_info->variant == lpc4300)
param_table[2] = lpc2000_info->lpc4300_bank;
- for (int i = first; i <= last && retval == ERROR_OK; i++) {
+ for (unsigned int i = first; i <= last && retval == ERROR_OK; i++) {
/* check single sector */
param_table[0] = param_table[1] = i;
int status_code = lpc2000_iap_call(bank, iap_working_area, 53, param_table, result_table);
@@ -978,7 +979,8 @@ FLASH_BANK_COMMAND_HANDLER(lpc2000_flash_bank_command)
return ERROR_OK;
}
-static int lpc2000_erase(struct flash_bank *bank, int first, int last)
+static int lpc2000_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
if (bank->target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
@@ -1078,7 +1080,7 @@ static int lpc2000_write(struct flash_bank *bank, const uint8_t *buffer, uint32_
int first_sector = 0;
int last_sector = 0;
- for (int i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
if (offset >= bank->sectors[i].offset)
first_sector = i;
if (offset + DIV_ROUND_UP(count, dst_min_alignment) * dst_min_alignment > bank->sectors[i].offset)
diff --git a/src/flash/nor/lpc288x.c b/src/flash/nor/lpc288x.c
index 8852c85..13450ef 100644
--- a/src/flash/nor/lpc288x.c
+++ b/src/flash/nor/lpc288x.c
@@ -232,17 +232,17 @@ static uint32_t lpc288x_system_ready(struct flash_bank *bank)
return ERROR_OK;
}
-static int lpc288x_erase(struct flash_bank *bank, int first, int last)
+static int lpc288x_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
uint32_t status;
- int sector;
struct target *target = bank->target;
status = lpc288x_system_ready(bank); /* probed? halted? */
if (status != ERROR_OK)
return status;
- if ((first < 0) || (last < first) || (last >= bank->num_sectors)) {
+ if ((last < first) || (last >= bank->num_sectors)) {
LOG_INFO("Bad sector range");
return ERROR_FLASH_SECTOR_INVALID;
}
@@ -250,7 +250,7 @@ static int lpc288x_erase(struct flash_bank *bank, int first, int last)
/* Configure the flash controller timing */
lpc288x_set_flash_clk(bank);
- for (sector = first; sector <= last; sector++) {
+ for (unsigned int sector = first; sector <= last; sector++) {
if (lpc288x_wait_status_busy(bank, 1000) != ERROR_OK)
return ERROR_FLASH_OPERATION_FAILED;
@@ -272,7 +272,6 @@ static int lpc288x_write(struct flash_bank *bank, const uint8_t *buffer, uint32_
struct target *target = bank->target;
uint32_t bytes_remaining = count;
uint32_t first_sector, last_sector, sector, page;
- int i;
/* probed? halted? */
status = lpc288x_system_ready(bank);
@@ -283,7 +282,7 @@ static int lpc288x_write(struct flash_bank *bank, const uint8_t *buffer, uint32_
first_sector = last_sector = 0xffffffff;
/* validate the write range... */
- for (i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
if ((offset >= bank->sectors[i].offset) &&
(offset < (bank->sectors[i].offset + bank->sectors[i].size)) &&
(first_sector == 0xffffffff)) {
@@ -379,9 +378,10 @@ static int lpc288x_probe(struct flash_bank *bank)
return ERROR_OK;
}
-static int lpc288x_protect(struct flash_bank *bank, int set, int first, int last)
+static int lpc288x_protect(struct flash_bank *bank, int set, unsigned int first,
+ unsigned int last)
{
- int lockregion, status;
+ int status;
uint32_t value;
struct target *target = bank->target;
@@ -390,13 +390,13 @@ static int lpc288x_protect(struct flash_bank *bank, int set, int first, int last
if (status != ERROR_OK)
return status;
- if ((first < 0) || (last < first) || (last >= bank->num_sectors))
+ if ((last < first) || (last >= bank->num_sectors))
return ERROR_FLASH_SECTOR_INVALID;
/* Configure the flash controller timing */
lpc288x_set_flash_clk(bank);
- for (lockregion = first; lockregion <= last; lockregion++) {
+ for (unsigned int lockregion = first; lockregion <= last; lockregion++) {
if (set) {
/* write an odd value to base addy to protect... */
value = 0x01;
diff --git a/src/flash/nor/lpc2900.c b/src/flash/nor/lpc2900.c
index 5412c93..af8bba0 100644
--- a/src/flash/nor/lpc2900.c
+++ b/src/flash/nor/lpc2900.c
@@ -283,9 +283,9 @@ static uint32_t lpc2900_read_security_status(struct flash_bank *bank)
* Anything else is undefined (is_protected = -1). This is treated as
* a protected sector!
*/
- int sector;
- int index_t;
- for (sector = 0; sector < bank->num_sectors; sector++) {
+ for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
+ unsigned int index_t;
+
/* Convert logical sector number to physical sector number */
if (sector <= 4)
index_t = sector + 11;
@@ -356,14 +356,13 @@ static uint32_t lpc2900_run_bist128(struct flash_bank *bank,
* @param bank Pointer to the flash bank descriptor
* @param offset Offset address relative to bank start
*/
-static uint32_t lpc2900_address2sector(struct flash_bank *bank,
+static unsigned int lpc2900_address2sector(struct flash_bank *bank,
uint32_t offset)
{
uint32_t address = bank->base + offset;
/* Run through all sectors of this bank */
- int sector;
- for (sector = 0; sector < bank->num_sectors; sector++) {
+ for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
/* Return immediately if address is within the current sector */
if (address < (bank->sectors[sector].offset + bank->sectors[sector].size))
return sector;
@@ -728,9 +727,9 @@ COMMAND_HANDLER(lpc2900_handle_secure_sector_command)
lpc2900_info->risky = 0;
/* Read sector range, and do a sanity check. */
- int first, last;
- COMMAND_PARSE_NUMBER(int, CMD_ARGV[1], first);
- COMMAND_PARSE_NUMBER(int, CMD_ARGV[2], last);
+ unsigned int first, last;
+ COMMAND_PARSE_NUMBER(uint, CMD_ARGV[1], first);
+ COMMAND_PARSE_NUMBER(uint, CMD_ARGV[2], last);
if ((first >= bank->num_sectors) ||
(last >= bank->num_sectors) ||
(first > last)) {
@@ -739,12 +738,11 @@ COMMAND_HANDLER(lpc2900_handle_secure_sector_command)
}
uint8_t page[FLASH_PAGE_SIZE];
- int sector;
/* Sectors in page 6 */
if ((first <= 4) || (last >= 8)) {
memset(&page, 0xff, FLASH_PAGE_SIZE);
- for (sector = first; sector <= last; sector++) {
+ for (unsigned int sector = first; sector <= last; sector++) {
if (sector <= 4)
memset(&page[0xB0 + 16*sector], 0, 16);
else if (sector >= 8)
@@ -761,7 +759,7 @@ COMMAND_HANDLER(lpc2900_handle_secure_sector_command)
/* Sectors in page 7 */
if ((first <= 7) && (last >= 5)) {
memset(&page, 0xff, FLASH_PAGE_SIZE);
- for (sector = first; sector <= last; sector++) {
+ for (unsigned int sector = first; sector <= last; sector++) {
if ((sector >= 5) && (sector <= 7))
memset(&page[0x00 + 16*(sector - 5)], 0, 16);
}
@@ -945,11 +943,12 @@ FLASH_BANK_COMMAND_HANDLER(lpc2900_flash_bank_command)
* @param first First sector to be erased
* @param last Last sector (including) to be erased
*/
-static int lpc2900_erase(struct flash_bank *bank, int first, int last)
+static int lpc2900_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
uint32_t status;
- int sector;
- int last_unsecured_sector;
+ unsigned int last_unsecured_sector;
+ bool has_unsecured_sector;
struct target *target = bank->target;
struct lpc2900_flash_bank *lpc2900_info = bank->driver_priv;
@@ -959,7 +958,7 @@ static int lpc2900_erase(struct flash_bank *bank, int first, int last)
return status;
/* Sanity check on sector range */
- if ((first < 0) || (last < first) || (last >= bank->num_sectors)) {
+ if ((last < first) || (last >= bank->num_sectors)) {
LOG_INFO("Bad sector range");
return ERROR_FLASH_SECTOR_INVALID;
}
@@ -974,16 +973,19 @@ static int lpc2900_erase(struct flash_bank *bank, int first, int last)
* a special way.
*/
last_unsecured_sector = -1;
- for (sector = first; sector <= last; sector++) {
- if (!bank->sectors[sector].is_protected)
+ has_unsecured_sector = false;
+ for (unsigned int sector = first; sector <= last; sector++) {
+ if (!bank->sectors[sector].is_protected) {
last_unsecured_sector = sector;
+ has_unsecured_sector = true;
+ }
}
/* Exit now, in case of the rare constellation where all sectors in range
* are secured. This is regarded a success, since erasing/programming of
* secured sectors shall be handled transparently.
*/
- if (last_unsecured_sector == -1)
+ if (!has_unsecured_sector)
return ERROR_OK;
/* Enable flash block and set the correct CRA clock of 66 kHz */
@@ -998,7 +1000,7 @@ static int lpc2900_erase(struct flash_bank *bank, int first, int last)
FLASH_ERASE_TIME));
/* Sectors are marked for erasure, then erased all together */
- for (sector = first; sector <= last_unsecured_sector; sector++) {
+ for (unsigned int sector = first; sector <= last_unsecured_sector; sector++) {
/* Only mark sectors that aren't secured. Any attempt to erase a group
* of sectors will fail if any single one of them is secured!
*/
@@ -1059,7 +1061,6 @@ static int lpc2900_write(struct flash_bank *bank, const uint8_t *buffer,
uint32_t num_bytes;
struct target *target = bank->target;
struct lpc2900_flash_bank *lpc2900_info = bank->driver_priv;
- int sector;
int retval;
static const uint32_t write_target_code[] = {
@@ -1111,7 +1112,7 @@ static int lpc2900_write(struct flash_bank *bank, const uint8_t *buffer,
lpc2900_read_security_status(bank);
/* Unprotect all involved sectors */
- for (sector = 0; sector < bank->num_sectors; sector++) {
+ for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
/* Start address in or before this sector?
* End address in or behind this sector? */
if (((bank->base + offset) <
@@ -1179,7 +1180,7 @@ static int lpc2900_write(struct flash_bank *bank, const uint8_t *buffer,
while (count != 0) {
uint32_t this_npages;
const uint8_t *this_buffer;
- int start_sector = lpc2900_address2sector(bank, offset);
+ unsigned int start_sector = lpc2900_address2sector(bank, offset);
/* First page / last page / rest */
if (offset % FLASH_PAGE_SIZE) {
@@ -1208,7 +1209,7 @@ static int lpc2900_write(struct flash_bank *bank, const uint8_t *buffer,
this_buffer = buffer;
/* Make sure we stop at the next secured sector */
- sector = start_sector + 1;
+ unsigned int sector = start_sector + 1;
while (sector < bank->num_sectors) {
/* Secured? */
if (bank->sectors[sector].is_protected) {
@@ -1230,7 +1231,7 @@ static int lpc2900_write(struct flash_bank *bank, const uint8_t *buffer,
/* Skip the current sector if it is secured */
if (bank->sectors[start_sector].is_protected) {
- LOG_DEBUG("Skip secured sector %d",
+ LOG_DEBUG("Skip secured sector %u",
start_sector);
/* Stop if this is the last sector */
@@ -1371,7 +1372,6 @@ static int lpc2900_probe(struct flash_bank *bank)
{
struct lpc2900_flash_bank *lpc2900_info = bank->driver_priv;
struct target *target = bank->target;
- int i = 0;
uint32_t offset;
@@ -1467,8 +1467,8 @@ static int lpc2900_probe(struct flash_bank *bank)
}
/* Show detected device */
- LOG_INFO("Flash bank %d: Device %s, %" PRIu32
- " KiB in %d sectors",
+ LOG_INFO("Flash bank %u: Device %s, %" PRIu32
+ " KiB in %u sectors",
bank->bank_number,
lpc2900_info->target_name, bank->size / KiB,
bank->num_sectors);
@@ -1487,7 +1487,7 @@ static int lpc2900_probe(struct flash_bank *bank)
bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
offset = 0;
- for (i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
bank->sectors[i].offset = offset;
bank->sectors[i].is_erased = -1;
bank->sectors[i].is_protected = -1;
@@ -1501,7 +1501,7 @@ static int lpc2900_probe(struct flash_bank *bank)
* that has more than 19 sectors. Politely ask for a fix then.
*/
bank->sectors[i].size = 0;
- LOG_ERROR("Never heard about sector %d", i);
+ LOG_ERROR("Never heard about sector %u", i);
}
offset += bank->sectors[i].size;
@@ -1538,8 +1538,7 @@ static int lpc2900_erase_check(struct flash_bank *bank)
/* Use the BIST (Built-In Selft Test) to generate a signature of each flash
* sector. Compare against the expected signature of an empty sector.
*/
- int sector;
- for (sector = 0; sector < bank->num_sectors; sector++) {
+ for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
uint32_t signature[4];
status = lpc2900_run_bist128(bank, bank->sectors[sector].offset,
bank->sectors[sector].offset + (bank->sectors[sector].size - 1), signature);
diff --git a/src/flash/nor/lpcspifi.c b/src/flash/nor/lpcspifi.c
index 04ac3bb..8616c04 100644
--- a/src/flash/nor/lpcspifi.c
+++ b/src/flash/nor/lpcspifi.c
@@ -414,7 +414,8 @@ static int lpcspifi_bulk_erase(struct flash_bank *bank)
return retval;
}
-static int lpcspifi_erase(struct flash_bank *bank, int first, int last)
+static int lpcspifi_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct target *target = bank->target;
struct lpcspifi_flash_bank *lpcspifi_info = bank->driver_priv;
@@ -422,16 +423,15 @@ static int lpcspifi_erase(struct flash_bank *bank, int first, int last)
struct armv7m_algorithm armv7m_info;
struct working_area *erase_algorithm;
int retval = ERROR_OK;
- int sector;
- LOG_DEBUG("erase from sector %d to sector %d", first, last);
+ LOG_DEBUG("erase from sector %u to sector %u", first, last);
if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED;
}
- if ((first < 0) || (last < first) || (last >= bank->num_sectors)) {
+ if ((last < first) || (last >= bank->num_sectors)) {
LOG_ERROR("Flash sector invalid");
return ERROR_FLASH_SECTOR_INVALID;
}
@@ -441,9 +441,9 @@ static int lpcspifi_erase(struct flash_bank *bank, int first, int last)
return ERROR_FLASH_BANK_NOT_PROBED;
}
- for (sector = first; sector <= last; sector++) {
+ for (unsigned int sector = first; sector <= last; sector++) {
if (bank->sectors[sector].is_protected) {
- LOG_ERROR("Flash sector %d protected", sector);
+ LOG_ERROR("Flash sector %u protected", sector);
return ERROR_FAIL;
}
}
@@ -571,11 +571,9 @@ static int lpcspifi_erase(struct flash_bank *bank, int first, int last)
}
static int lpcspifi_protect(struct flash_bank *bank, int set,
- int first, int last)
+ unsigned int first, unsigned int last)
{
- int sector;
-
- for (sector = first; sector <= last; sector++)
+ for (unsigned int sector = first; sector <= last; sector++)
bank->sectors[sector].is_protected = set;
return ERROR_OK;
}
@@ -590,7 +588,6 @@ static int lpcspifi_write(struct flash_bank *bank, const uint8_t *buffer,
struct reg_param reg_params[5];
struct armv7m_algorithm armv7m_info;
struct working_area *write_algorithm;
- int sector;
int retval = ERROR_OK;
LOG_DEBUG("offset=0x%08" PRIx32 " count=0x%08" PRIx32,
@@ -607,14 +604,14 @@ static int lpcspifi_write(struct flash_bank *bank, const uint8_t *buffer,
}
/* Check sector protection */
- for (sector = 0; sector < bank->num_sectors; sector++) {
+ for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
/* Start offset in or before this sector? */
/* End offset in or behind this sector? */
if ((offset <
(bank->sectors[sector].offset + bank->sectors[sector].size))
&& ((offset + count - 1) >= bank->sectors[sector].offset)
&& bank->sectors[sector].is_protected) {
- LOG_ERROR("Flash sector %d protected", sector);
+ LOG_ERROR("Flash sector %u protected", sector);
return ERROR_FAIL;
}
}
@@ -902,7 +899,7 @@ static int lpcspifi_probe(struct flash_bank *bank)
return ERROR_FAIL;
}
- for (int sector = 0; sector < bank->num_sectors; sector++) {
+ for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
sectors[sector].offset = sector * sectorsize;
sectors[sector].size = sectorsize;
sectors[sector].is_erased = -1;
diff --git a/src/flash/nor/max32xxx.c b/src/flash/nor/max32xxx.c
index 3bf4b22..20ebbbf 100644
--- a/src/flash/nor/max32xxx.c
+++ b/src/flash/nor/max32xxx.c
@@ -209,21 +209,20 @@ static int max32xxx_protect_check(struct flash_bank *bank)
{
struct max32xxx_flash_bank *info = bank->driver_priv;
struct target *target = bank->target;
- int i;
uint32_t temp_reg;
if (info->probed == 0)
return ERROR_FLASH_BANK_NOT_PROBED;
if (!info->max326xx) {
- for (i = 0; i < bank->num_sectors; i++)
+ for (unsigned i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_protected = -1;
return ERROR_FLASH_OPER_UNSUPPORTED;
}
/* Check the protection */
- for (i = 0; i < bank->num_sectors; i++) {
+ for (unsigned i = 0; i < bank->num_sectors; i++) {
if (i%32 == 0)
target_read_u32(target, info->flc_base + FLSH_PROT + ((i/32)*4), &temp_reg);
@@ -235,9 +234,9 @@ static int max32xxx_protect_check(struct flash_bank *bank)
return ERROR_OK;
}
-static int max32xxx_erase(struct flash_bank *bank, int first, int last)
+static int max32xxx_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
- int banknr;
uint32_t flsh_cn, flsh_int;
struct max32xxx_flash_bank *info = bank->driver_priv;
struct target *target = bank->target;
@@ -252,7 +251,7 @@ static int max32xxx_erase(struct flash_bank *bank, int first, int last)
if (info->probed == 0)
return ERROR_FLASH_BANK_NOT_PROBED;
- if ((first < 0) || (last < first) || (last >= bank->num_sectors))
+ if ((last < first) || (last >= bank->num_sectors))
return ERROR_FLASH_SECTOR_INVALID;
if ((first == 0) && (last == (bank->num_sectors - 1)))
@@ -265,11 +264,11 @@ static int max32xxx_erase(struct flash_bank *bank, int first, int last)
return retval;
int erased = 0;
- for (banknr = first; banknr <= last; banknr++) {
+ for (unsigned int banknr = first; banknr <= last; banknr++) {
/* Check the protection */
if (bank->sectors[banknr].is_protected == 1) {
- LOG_WARNING("Flash sector %d is protected", banknr);
+ LOG_WARNING("Flash sector %u is protected", banknr);
continue;
} else
erased = 1;
@@ -311,7 +310,7 @@ static int max32xxx_erase(struct flash_bank *bank, int first, int last)
}
if (!erased) {
- LOG_ERROR("All pages protected %d to %d", first, last);
+ LOG_ERROR("All pages protected %u to %u", first, last);
max32xxx_flash_op_post(bank);
return ERROR_FAIL;
}
@@ -322,11 +321,11 @@ static int max32xxx_erase(struct flash_bank *bank, int first, int last)
return ERROR_OK;
}
-static int max32xxx_protect(struct flash_bank *bank, int set, int first, int last)
+static int max32xxx_protect(struct flash_bank *bank, int set,
+ unsigned int first, unsigned int last)
{
struct max32xxx_flash_bank *info = bank->driver_priv;
struct target *target = bank->target;
- int page;
uint32_t temp_reg;
if (bank->target->state != TARGET_HALTED) {
@@ -340,11 +339,11 @@ static int max32xxx_protect(struct flash_bank *bank, int set, int first, int las
if (!info->max326xx)
return ERROR_FLASH_OPER_UNSUPPORTED;
- if ((first < 0) || (last < first) || (last >= bank->num_sectors))
+ if ((last < first) || (last >= bank->num_sectors))
return ERROR_FLASH_SECTOR_INVALID;
/* Setup the protection on the pages given */
- for (page = first; page <= last; page++) {
+ for (unsigned int page = first; page <= last; page++) {
if (set) {
/* Set the write/erase bit for this page */
target_read_u32(target, info->flc_base + FLSH_PROT + (page/32), &temp_reg);
@@ -662,7 +661,7 @@ static int max32xxx_probe(struct flash_bank *bank)
bank->num_sectors = info->flash_size / info->sector_size;
bank->sectors = calloc(bank->num_sectors, sizeof(struct flash_sector));
- for (int i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
bank->sectors[i].offset = i * info->sector_size;
bank->sectors[i].size = info->sector_size;
bank->sectors[i].is_erased = -1;
@@ -713,9 +712,9 @@ static int max32xxx_mass_erase(struct flash_bank *bank)
return ERROR_FLASH_BANK_NOT_PROBED;
int not_protected = 0;
- for (int i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
if (bank->sectors[i].is_protected == 1)
- LOG_WARNING("Flash sector %d is protected", i);
+ LOG_WARNING("Flash sector %u is protected", i);
else
not_protected = 1;
}
@@ -767,7 +766,6 @@ static int max32xxx_mass_erase(struct flash_bank *bank)
COMMAND_HANDLER(max32xxx_handle_mass_erase_command)
{
- int i;
struct flash_bank *bank;
int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
@@ -781,7 +779,7 @@ COMMAND_HANDLER(max32xxx_handle_mass_erase_command)
if (max32xxx_mass_erase(bank) == ERROR_OK) {
/* set all sectors as erased */
- for (i = 0; i < bank->num_sectors; i++)
+ for (unsigned i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_erased = 1;
command_print(CMD, "max32xxx mass erase complete");
@@ -908,7 +906,6 @@ COMMAND_HANDLER(max32xxx_handle_protection_check_command)
struct flash_bank *bank;
int retval;
struct max32xxx_flash_bank *info;
- int i;
if (CMD_ARGC < 1) {
command_print(CMD, "max32xxx protection_check <bank>");
@@ -928,7 +925,7 @@ COMMAND_HANDLER(max32xxx_handle_protection_check_command)
}
LOG_WARNING("s:<sector number> a:<address> p:<protection bit>");
- for (i = 0; i < bank->num_sectors; i += 4) {
+ for (unsigned i = 0; i < bank->num_sectors; i += 4) {
LOG_WARNING("s:%03d a:0x%06x p:%d | s:%03d a:0x%06x p:%d | s:%03d a:0x%06x p:%d | s:%03d a:0x%06x p:%d",
(i+0), (i+0)*info->sector_size, bank->sectors[(i+0)].is_protected,
(i+1), (i+1)*info->sector_size, bank->sectors[(i+1)].is_protected,
diff --git a/src/flash/nor/mdr.c b/src/flash/nor/mdr.c
index 3796259..6e5b7b9 100644
--- a/src/flash/nor/mdr.c
+++ b/src/flash/nor/mdr.c
@@ -124,11 +124,12 @@ static int mdr_mass_erase(struct flash_bank *bank)
return retval;
}
-static int mdr_erase(struct flash_bank *bank, int first, int last)
+static int mdr_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct target *target = bank->target;
struct mdr_flash_bank *mdr_info = bank->driver_priv;
- int i, retval, retval2;
+ int retval, retval2;
unsigned int j;
uint32_t flash_cmd, cur_per_clock;
@@ -173,7 +174,7 @@ static int mdr_erase(struct flash_bank *bank, int first, int last)
}
unsigned int page_size = bank->size / mdr_info->page_count;
- for (i = first; i <= last; i++) {
+ for (unsigned int i = first; i <= last; i++) {
for (j = 0; j < mdr_info->sec_count; j++) {
retval = target_write_u32(target, FLASH_ADR, (i * page_size) | (j << 2));
if (retval != ERROR_OK)
diff --git a/src/flash/nor/mrvlqspi.c b/src/flash/nor/mrvlqspi.c
index 7a06b3d..57461be 100644
--- a/src/flash/nor/mrvlqspi.c
+++ b/src/flash/nor/mrvlqspi.c
@@ -527,21 +527,21 @@ static int mrvlqspi_bulk_erase(struct flash_bank *bank)
return mrvlqspi_flash_busy_status(bank, CHIP_ERASE_TIMEOUT);
}
-static int mrvlqspi_flash_erase(struct flash_bank *bank, int first, int last)
+static int mrvlqspi_flash_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct target *target = bank->target;
struct mrvlqspi_flash_bank *mrvlqspi_info = bank->driver_priv;
int retval = ERROR_OK;
- int sector;
- LOG_DEBUG("erase from sector %d to sector %d", first, last);
+ LOG_DEBUG("erase from sector %u to sector %u", first, last);
if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED;
}
- if ((first < 0) || (last < first) || (last >= bank->num_sectors)) {
+ if ((last < first) || (last >= bank->num_sectors)) {
LOG_ERROR("Flash sector invalid");
return ERROR_FLASH_SECTOR_INVALID;
}
@@ -551,9 +551,9 @@ static int mrvlqspi_flash_erase(struct flash_bank *bank, int first, int last)
return ERROR_FLASH_BANK_NOT_PROBED;
}
- for (sector = first; sector <= last; sector++) {
+ for (unsigned int sector = first; sector <= last; sector++) {
if (bank->sectors[sector].is_protected) {
- LOG_ERROR("Flash sector %d protected", sector);
+ LOG_ERROR("Flash sector %u protected", sector);
return ERROR_FAIL;
}
}
@@ -576,7 +576,7 @@ static int mrvlqspi_flash_erase(struct flash_bank *bank, int first, int last)
if (mrvlqspi_info->dev->erase_cmd == 0x00)
return ERROR_FLASH_OPER_UNSUPPORTED;
- for (sector = first; sector <= last; sector++) {
+ for (unsigned int sector = first; sector <= last; sector++) {
retval = mrvlqspi_block_erase(bank,
sector * mrvlqspi_info->dev->sectorsize);
if (retval != ERROR_OK)
@@ -597,7 +597,6 @@ static int mrvlqspi_flash_write(struct flash_bank *bank, const uint8_t *buffer,
struct reg_param reg_params[6];
struct armv7m_algorithm armv7m_info;
struct working_area *write_algorithm;
- int sector;
LOG_DEBUG("offset=0x%08" PRIx32 " count=0x%08" PRIx32,
offset, count);
@@ -613,14 +612,14 @@ static int mrvlqspi_flash_write(struct flash_bank *bank, const uint8_t *buffer,
}
/* Check sector protection */
- for (sector = 0; sector < bank->num_sectors; sector++) {
+ for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
/* Start offset in or before this sector? */
/* End offset in or behind this sector? */
if ((offset <
(bank->sectors[sector].offset + bank->sectors[sector].size))
&& ((offset + count - 1) >= bank->sectors[sector].offset)
&& bank->sectors[sector].is_protected) {
- LOG_ERROR("Flash sector %d protected", sector);
+ LOG_ERROR("Flash sector %u protected", sector);
return ERROR_FAIL;
}
}
@@ -888,7 +887,7 @@ static int mrvlqspi_probe(struct flash_bank *bank)
return ERROR_FAIL;
}
- for (int sector = 0; sector < bank->num_sectors; sector++) {
+ for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
sectors[sector].offset = sector * sectorsize;
sectors[sector].size = sectorsize;
sectors[sector].is_erased = -1;
diff --git a/src/flash/nor/msp432.c b/src/flash/nor/msp432.c
index 95c99b9..0c925bd 100644
--- a/src/flash/nor/msp432.c
+++ b/src/flash/nor/msp432.c
@@ -590,7 +590,8 @@ FLASH_BANK_COMMAND_HANDLER(msp432_flash_bank_command)
return ERROR_OK;
}
-static int msp432_erase(struct flash_bank *bank, int first, int last)
+static int msp432_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct target *target = bank->target;
struct msp432_bank *msp432_bank = bank->driver_priv;
@@ -628,7 +629,7 @@ static int msp432_erase(struct flash_bank *bank, int first, int last)
}
/* Erase requested sectors one by one */
- for (int i = first; i <= last; i++) {
+ for (unsigned int i = first; i <= last; i++) {
/* Skip TVL (read-only) sector of the info bank */
if (is_info && 1 == i)
@@ -809,7 +810,7 @@ static int msp432_probe(struct flash_bank *bank)
uint32_t sector_length;
uint32_t size;
- int num_sectors;
+ unsigned int num_sectors;
bool is_main = FLASH_BASE == bank->base;
bool is_info = P4_FLASH_INFO_BASE == bank->base;
@@ -918,7 +919,7 @@ static int msp432_probe(struct flash_bank *bank)
bank->num_sectors = num_sectors;
msp432_bank->sector_length = sector_length;
- for (int i = 0; i < num_sectors; i++) {
+ for (unsigned int i = 0; i < num_sectors; i++) {
bank->sectors[i].offset = i * sector_length;
bank->sectors[i].size = sector_length;
bank->sectors[i].is_erased = -1;
diff --git a/src/flash/nor/niietcm4.c b/src/flash/nor/niietcm4.c
index 7b67bb8..1ab0a5a 100644
--- a/src/flash/nor/niietcm4.c
+++ b/src/flash/nor/niietcm4.c
@@ -330,7 +330,8 @@ static int niietcm4_uflash_page_erase(struct flash_bank *bank, int page_num, int
/**
* Enable or disable protection of userflash pages
*/
-static int niietcm4_uflash_protect(struct flash_bank *bank, int mem_type, int set, int first, int last)
+static int niietcm4_uflash_protect(struct flash_bank *bank, int mem_type,
+ int set, unsigned int first, unsigned int last)
{
int retval;
if (mem_type == INFO_MEM_TYPE) {
@@ -359,7 +360,7 @@ static int niietcm4_uflash_protect(struct flash_bank *bank, int mem_type, int se
if (retval != ERROR_OK)
return retval;
/* modify dump */
- for (int i = first; i <= last; i++) {
+ for (unsigned int i = first; i <= last; i++) {
uint32_t reg_num = i/8;
uint32_t bit_num = i%8;
if (set)
@@ -563,7 +564,7 @@ COMMAND_HANDLER(niietcm4_handle_uflash_erase_command)
return retval;
}
- command_print(CMD, "Erase %s userflash pages %d through %d done!", CMD_ARGV[0], first, last);
+ command_print(CMD, "Erase %s userflash pages %u through %u done!", CMD_ARGV[0], first, last);
return retval;
}
@@ -693,11 +694,11 @@ COMMAND_HANDLER(niietcm4_handle_uflash_protect_command)
int set;
if (strcmp("on", CMD_ARGV[3]) == 0) {
- command_print(CMD, "Try to enable %s userflash sectors %d through %d protection. Please wait ... ",
+ command_print(CMD, "Try to enable %s userflash sectors %u through %u protection. Please wait ... ",
CMD_ARGV[0], first, last);
set = 1;
} else if (strcmp("off", CMD_ARGV[3]) == 0) {
- command_print(CMD, "Try to disable %s userflash sectors %d through %d protection. Please wait ... ",
+ command_print(CMD, "Try to disable %s userflash sectors %u through %u protection. Please wait ... ",
CMD_ARGV[0], first, last);
set = 0;
} else
@@ -1111,7 +1112,7 @@ static int niietcm4_protect_check(struct flash_bank *bank)
} else {
uflash_addr = BF_LOCK_ADDR;
uflash_cmd = UFMC_MAGIC_KEY | UFMC_READ_IFB;
- for (int i = 0; i < bank->num_sectors/8; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors/8; i++) {
retval = target_write_u32(target, UFMA, uflash_addr);
if (retval != ERROR_OK)
return retval;
@@ -1163,7 +1164,8 @@ static int niietcm4_mass_erase(struct flash_bank *bank)
return retval;
}
-static int niietcm4_erase(struct flash_bank *bank, int first, int last)
+static int niietcm4_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct target *target = bank->target;
struct niietcm4_flash_bank *niietcm4_info = bank->driver_priv;
@@ -1188,7 +1190,7 @@ static int niietcm4_erase(struct flash_bank *bank, int first, int last)
/* erasing pages */
unsigned int page_size = bank->size / bank->num_sectors;
- for (int i = first; i <= last; i++) {
+ for (unsigned int i = first; i <= last; i++) {
/* current page addr */
flash_addr = i*page_size;
retval = target_write_u32(target, FMA, flash_addr);
@@ -1211,7 +1213,8 @@ static int niietcm4_erase(struct flash_bank *bank, int first, int last)
return retval;
}
-static int niietcm4_protect(struct flash_bank *bank, int set, int first, int last)
+static int niietcm4_protect(struct flash_bank *bank, int set,
+ unsigned int first, unsigned int last)
{
struct target *target = bank->target;
struct niietcm4_flash_bank *niietcm4_info = bank->driver_priv;
@@ -1251,7 +1254,7 @@ static int niietcm4_protect(struct flash_bank *bank, int set, int first, int las
if (retval != ERROR_OK)
return retval;
/* modify dump */
- for (int i = first; i <= last; i++) {
+ for (unsigned int i = first; i <= last; i++) {
uint32_t reg_num = i/8;
uint32_t bit_num = i%8;
if (set)
diff --git a/src/flash/nor/nrf5.c b/src/flash/nor/nrf5.c
index fa67e2b..a79aa78 100644
--- a/src/flash/nor/nrf5.c
+++ b/src/flash/nor/nrf5.c
@@ -451,7 +451,7 @@ static int nrf5_protect_check_bprot(struct flash_bank *bank)
uint32_t bprot_reg = 0;
int res;
- for (int i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
unsigned int bit = i % 32;
if (bit == 0) {
unsigned int n_reg = i / 32;
@@ -505,14 +505,15 @@ static int nrf5_protect_check(struct flash_bank *bank)
}
}
- for (int i = 0; i < bank->num_sectors; i++)
+ for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_protected =
clenr0 != 0xFFFFFFFF && bank->sectors[i].offset < clenr0;
return ERROR_OK;
}
-static int nrf5_protect(struct flash_bank *bank, int set, int first, int last)
+static int nrf5_protect(struct flash_bank *bank, int set, unsigned int first,
+ unsigned int last)
{
int res;
uint32_t clenr0, ppfc;
@@ -1027,7 +1028,8 @@ error:
return res;
}
-static int nrf5_erase(struct flash_bank *bank, int first, int last)
+static int nrf5_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
int res;
struct nrf5_info *chip;
@@ -1037,7 +1039,7 @@ static int nrf5_erase(struct flash_bank *bank, int first, int last)
return res;
/* For each sector to be erased */
- for (int s = first; s <= last && res == ERROR_OK; s++)
+ for (unsigned int s = first; s <= last && res == ERROR_OK; s++)
res = nrf5_erase_page(bank, chip, &bank->sectors[s]);
return res;
diff --git a/src/flash/nor/numicro.c b/src/flash/nor/numicro.c
index a485282..c212cbc 100644
--- a/src/flash/nor/numicro.c
+++ b/src/flash/nor/numicro.c
@@ -1433,7 +1433,7 @@ static int numicro_protect_check(struct flash_bank *bank)
{
struct target *target = bank->target;
uint32_t set, config[2];
- int i, retval = ERROR_OK;
+ int retval = ERROR_OK;
if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
@@ -1467,25 +1467,26 @@ static int numicro_protect_check(struct flash_bank *bank)
set = 0;
}
- for (i = 0; i < bank->num_sectors; i++)
+ for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_protected = set;
return ERROR_OK;
}
-static int numicro_erase(struct flash_bank *bank, int first, int last)
+static int numicro_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct target *target = bank->target;
uint32_t timeout, status;
- int i, retval = ERROR_OK;
+ int retval = ERROR_OK;
if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED;
}
- LOG_INFO("Nuvoton NuMicro: Sector Erase ... (%d to %d)", first, last);
+ LOG_INFO("Nuvoton NuMicro: Sector Erase ... (%u to %u)", first, last);
retval = numicro_init_isp(target);
if (retval != ERROR_OK)
@@ -1495,8 +1496,8 @@ static int numicro_erase(struct flash_bank *bank, int first, int last)
if (retval != ERROR_OK)
return retval;
- for (i = first; i <= last; i++) {
- LOG_DEBUG("erasing sector %d at address " TARGET_ADDR_FMT, i,
+ for (unsigned int i = first; i <= last; i++) {
+ LOG_DEBUG("erasing sector %u at address " TARGET_ADDR_FMT, i,
bank->base + bank->sectors[i].offset);
retval = target_write_u32(target, NUMICRO_FLASH_ISPADR, bank->base + bank->sectors[i].offset);
if (retval != ERROR_OK)
diff --git a/src/flash/nor/ocl.c b/src/flash/nor/ocl.c
index d2a6594..813537d 100644
--- a/src/flash/nor/ocl.c
+++ b/src/flash/nor/ocl.c
@@ -51,7 +51,8 @@ FLASH_BANK_COMMAND_HANDLER(ocl_flash_bank_command)
return ERROR_OK;
}
-static int ocl_erase(struct flash_bank *bank, int first, int last)
+static int ocl_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct ocl_priv *ocl = bank->driver_priv;
int retval;
@@ -207,7 +208,6 @@ static int ocl_probe(struct flash_bank *bank)
int retval;
uint32_t dcc_buffer[1];
int sectsize;
- int i;
/* purge pending data in DCC */
embeddedice_receive(ocl->jtag_info, dcc_buffer, 1);
@@ -276,7 +276,7 @@ static int ocl_probe(struct flash_bank *bank)
return ERROR_FLASH_BANK_INVALID;
}
sectsize = bank->size / bank->num_sectors;
- for (i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
bank->sectors[i].offset = i * sectsize;
bank->sectors[i].size = sectsize;
bank->sectors[i].is_erased = -1;
diff --git a/src/flash/nor/pic32mx.c b/src/flash/nor/pic32mx.c
index 81ffdc4..570a2cf 100644
--- a/src/flash/nor/pic32mx.c
+++ b/src/flash/nor/pic32mx.c
@@ -271,8 +271,7 @@ static int pic32mx_protect_check(struct flash_bank *bank)
uint32_t config0_address;
uint32_t devcfg0;
- int s;
- int num_pages;
+ unsigned int s, num_pages;
if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
@@ -321,10 +320,10 @@ static int pic32mx_protect_check(struct flash_bank *bank)
return ERROR_OK;
}
-static int pic32mx_erase(struct flash_bank *bank, int first, int last)
+static int pic32mx_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct target *target = bank->target;
- int i;
uint32_t status;
if (bank->target->state != TARGET_HALTED) {
@@ -345,7 +344,7 @@ static int pic32mx_erase(struct flash_bank *bank, int first, int last)
return ERROR_OK;
}
- for (i = first; i <= last; i++) {
+ for (unsigned int i = first; i <= last; i++) {
target_write_u32(target, PIC32MX_NVMADDR, Virt2Phys(bank->base + bank->sectors[i].offset));
status = pic32mx_nvm_exec(bank, NVMCON_OP_PAGE_ERASE, 10);
@@ -360,7 +359,8 @@ static int pic32mx_erase(struct flash_bank *bank, int first, int last)
return ERROR_OK;
}
-static int pic32mx_protect(struct flash_bank *bank, int set, int first, int last)
+static int pic32mx_protect(struct flash_bank *bank, int set, unsigned int first,
+ unsigned int last)
{
struct target *target = bank->target;
diff --git a/src/flash/nor/psoc4.c b/src/flash/nor/psoc4.c
index 1eb6a26..be9a886 100644
--- a/src/flash/nor/psoc4.c
+++ b/src/flash/nor/psoc4.c
@@ -157,7 +157,7 @@ const struct psoc4_chip_family psoc4_families[] = {
struct psoc4_flash_bank {
uint32_t row_size;
uint32_t user_bank_size;
- int num_macros;
+ unsigned int num_macros;
bool probed;
uint8_t cmd_program_row;
uint16_t family_id;
@@ -496,16 +496,15 @@ static int psoc4_protect_check(struct flash_bank *bank)
uint32_t prot_addr = PSOC4_SFLASH_MACRO0;
int retval;
- int s = 0;
- int m, i;
uint8_t bf[PSOC4_ROWS_PER_MACRO/8];
+ unsigned int s = 0;
- for (m = 0; m < psoc4_info->num_macros; m++, prot_addr += PSOC4_SFLASH_MACRO_SIZE) {
+ for (unsigned int m = 0; m < psoc4_info->num_macros; m++, prot_addr += PSOC4_SFLASH_MACRO_SIZE) {
retval = target_read_memory(target, prot_addr, 4, PSOC4_ROWS_PER_MACRO/32, bf);
if (retval != ERROR_OK)
return retval;
- for (i = 0; i < PSOC4_ROWS_PER_MACRO && s < bank->num_sectors; i++, s++)
+ for (unsigned int i = 0; i < PSOC4_ROWS_PER_MACRO && s < bank->num_sectors; i++, s++)
bank->sectors[s].is_protected = bf[i/8] & (1 << (i%8)) ? 1 : 0;
}
@@ -515,7 +514,6 @@ static int psoc4_protect_check(struct flash_bank *bank)
static int psoc4_mass_erase(struct flash_bank *bank)
{
- int i;
int retval = psoc4_flash_prepare(bank);
if (retval != ERROR_OK)
return retval;
@@ -528,14 +526,15 @@ static int psoc4_mass_erase(struct flash_bank *bank)
if (retval == ERROR_OK)
/* set all sectors as erased */
- for (i = 0; i < bank->num_sectors; i++)
+ for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_erased = 1;
return retval;
}
-static int psoc4_erase(struct flash_bank *bank, int first, int last)
+static int psoc4_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct psoc4_flash_bank *psoc4_info = bank->driver_priv;
if (psoc4_info->cmd_program_row == PSOC4_CMD_WRITE_ROW) {
@@ -552,7 +551,8 @@ static int psoc4_erase(struct flash_bank *bank, int first, int last)
}
-static int psoc4_protect(struct flash_bank *bank, int set, int first, int last)
+static int psoc4_protect(struct flash_bank *bank, int set, unsigned int first,
+ unsigned int last)
{
struct target *target = bank->target;
struct psoc4_flash_bank *psoc4_info = bank->driver_priv;
@@ -567,8 +567,8 @@ static int psoc4_protect(struct flash_bank *bank, int set, int first, int last)
uint32_t *sysrq_buffer = NULL;
const int param_sz = 8;
int chip_prot = PSOC4_CHIP_PROT_OPEN;
- int i, m, sect;
- int num_bits = bank->num_sectors;
+ unsigned int i;
+ unsigned int num_bits = bank->num_sectors;
if (num_bits > PSOC4_ROWS_PER_MACRO)
num_bits = PSOC4_ROWS_PER_MACRO;
@@ -584,7 +584,7 @@ static int psoc4_protect(struct flash_bank *bank, int set, int first, int last)
for (i = first; i <= last && i < bank->num_sectors; i++)
bank->sectors[i].is_protected = set;
- for (m = 0, sect = 0; m < psoc4_info->num_macros; m++) {
+ for (unsigned int m = 0, sect = 0; m < psoc4_info->num_macros; m++) {
uint8_t *p = (uint8_t *)(sysrq_buffer + 2);
memset(p, 0, prot_sz);
for (i = 0; i < num_bits && sect < bank->num_sectors; i++, sect++) {
diff --git a/src/flash/nor/psoc5lp.c b/src/flash/nor/psoc5lp.c
index 7f801f2..17cc6d8 100644
--- a/src/flash/nor/psoc5lp.c
+++ b/src/flash/nor/psoc5lp.c
@@ -657,7 +657,8 @@ static int psoc5lp_nvl_read(struct flash_bank *bank,
return ERROR_OK;
}
-static int psoc5lp_nvl_erase(struct flash_bank *bank, int first, int last)
+static int psoc5lp_nvl_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
LOG_WARNING("There is no erase operation for NV Latches");
return ERROR_FLASH_OPER_UNSUPPORTED;
@@ -665,9 +666,7 @@ static int psoc5lp_nvl_erase(struct flash_bank *bank, int first, int last)
static int psoc5lp_nvl_erase_check(struct flash_bank *bank)
{
- int i;
-
- for (i = 0; i < bank->num_sectors; i++)
+ for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_erased = 0;
return ERROR_OK;
@@ -861,11 +860,12 @@ struct psoc5lp_eeprom_flash_bank {
const struct psoc5lp_device *device;
};
-static int psoc5lp_eeprom_erase(struct flash_bank *bank, int first, int last)
+static int psoc5lp_eeprom_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
- int i, retval;
+ int retval;
- for (i = first; i <= last; i++) {
+ for (unsigned int i = first; i <= last; i++) {
retval = psoc5lp_spc_erase_sector(bank->target,
SPC_ARRAY_EEPROM, i);
if (retval != ERROR_OK)
@@ -951,7 +951,7 @@ static int psoc5lp_eeprom_probe(struct flash_bank *bank)
struct psoc5lp_eeprom_flash_bank *psoc_eeprom_bank = bank->driver_priv;
uint32_t flash_addr = bank->base;
uint32_t val;
- int i, retval;
+ int retval;
if (psoc_eeprom_bank->probed)
return ERROR_OK;
@@ -979,7 +979,7 @@ static int psoc5lp_eeprom_probe(struct flash_bank *bank)
bank->num_sectors = DIV_ROUND_UP(bank->size, EEPROM_SECTOR_SIZE);
bank->sectors = calloc(bank->num_sectors,
sizeof(struct flash_sector));
- for (i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
bank->sectors[i].size = EEPROM_SECTOR_SIZE;
bank->sectors[i].offset = flash_addr - bank->base;
bank->sectors[i].is_erased = -1;
@@ -1064,27 +1064,28 @@ struct psoc5lp_flash_bank {
* are used for driver private flash operations */
};
-static int psoc5lp_erase(struct flash_bank *bank, int first, int last)
+static int psoc5lp_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct psoc5lp_flash_bank *psoc_bank = bank->driver_priv;
- int i, retval;
+ int retval;
if (!psoc_bank->ecc_enabled) {
/* Silently avoid erasing sectors twice */
if (last >= first + bank->num_sectors / 2) {
- LOG_DEBUG("Skipping duplicate erase of sectors %d to %d",
+ LOG_DEBUG("Skipping duplicate erase of sectors %u to %u",
first + bank->num_sectors / 2, last);
last = first + (bank->num_sectors / 2) - 1;
}
/* Check for any remaining ECC sectors */
if (last >= bank->num_sectors / 2) {
- LOG_WARNING("Skipping erase of ECC region sectors %d to %d",
+ LOG_WARNING("Skipping erase of ECC region sectors %u to %u",
bank->num_sectors / 2, last);
last = (bank->num_sectors / 2) - 1;
}
}
- for (i = first; i <= last; i++) {
+ for (unsigned int i = first; i <= last; i++) {
retval = psoc5lp_spc_erase_sector(bank->target,
i / SECTORS_PER_BLOCK, i % SECTORS_PER_BLOCK);
if (retval != ERROR_OK)
@@ -1099,14 +1100,14 @@ static int psoc5lp_erase_check(struct flash_bank *bank)
{
struct psoc5lp_flash_bank *psoc_bank = bank->driver_priv;
struct target *target = bank->target;
- int i, retval;
+ int retval;
if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED;
}
- int num_sectors = bank->num_sectors;
+ unsigned int num_sectors = bank->num_sectors;
if (psoc_bank->ecc_enabled)
num_sectors *= 2; /* count both std and ecc sector always */
@@ -1115,14 +1116,14 @@ static int psoc5lp_erase_check(struct flash_bank *bank)
if (block_array == NULL)
return ERROR_FAIL;
- for (i = 0; i < num_sectors; i++) {
+ for (unsigned int i = 0; i < num_sectors; i++) {
block_array[i].address = bank->base + bank->sectors[i].offset;
block_array[i].size = bank->sectors[i].size;
block_array[i].result = UINT32_MAX; /* erase state unknown */
}
bool fast_check = true;
- for (i = 0; i < num_sectors; ) {
+ for (unsigned int i = 0; i < num_sectors; ) {
retval = armv7m_blank_check_memory(target,
block_array + i, num_sectors - i,
bank->erased_value);
@@ -1138,14 +1139,14 @@ static int psoc5lp_erase_check(struct flash_bank *bank)
if (fast_check) {
if (psoc_bank->ecc_enabled) {
- for (i = 0; i < bank->num_sectors; i++)
+ for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_erased =
(block_array[i].result != 1)
? block_array[i].result
: block_array[i + bank->num_sectors].result;
/* if std sector is erased, use status of ecc sector */
} else {
- for (i = 0; i < num_sectors; i++)
+ for (unsigned int i = 0; i < num_sectors; i++)
bank->sectors[i].is_erased = block_array[i].result;
}
retval = ERROR_OK;
@@ -1350,7 +1351,7 @@ static int psoc5lp_protect_check(struct flash_bank *bank)
struct psoc5lp_flash_bank *psoc_bank = bank->driver_priv;
uint8_t row_data[ROW_SIZE];
const unsigned protection_bytes_per_sector = ROWS_PER_SECTOR * 2 / 8;
- unsigned i, j, k, num_sectors;
+ unsigned i, k, num_sectors;
int retval;
if (bank->target->state != TARGET_HALTED) {
@@ -1370,7 +1371,7 @@ static int psoc5lp_protect_check(struct flash_bank *bank)
else
num_sectors = SECTORS_PER_BLOCK;
- for (j = 0; j < num_sectors; j++) {
+ for (unsigned int j = 0; j < num_sectors; j++) {
int sector_nr = i * SECTORS_PER_BLOCK + j;
struct flash_sector *sector = &bank->sectors[sector_nr];
struct flash_sector *ecc_sector;
@@ -1416,7 +1417,7 @@ static int psoc5lp_probe(struct flash_bank *bank)
struct psoc5lp_flash_bank *psoc_bank = bank->driver_priv;
uint32_t flash_addr = bank->base;
uint8_t nvl[4], temp[2];
- int i, retval;
+ int retval;
if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
@@ -1447,7 +1448,7 @@ static int psoc5lp_probe(struct flash_bank *bank)
bank->sectors = calloc(bank->num_sectors * 2,
sizeof(struct flash_sector));
- for (i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
bank->sectors[i].size = SECTOR_SIZE;
bank->sectors[i].offset = flash_addr - bank->base;
bank->sectors[i].is_erased = -1;
@@ -1456,7 +1457,7 @@ static int psoc5lp_probe(struct flash_bank *bank)
flash_addr += bank->sectors[i].size;
}
flash_addr = 0x48000000;
- for (i = bank->num_sectors; i < bank->num_sectors * 2; i++) {
+ for (unsigned int i = bank->num_sectors; i < bank->num_sectors * 2; i++) {
bank->sectors[i].size = ROWS_PER_SECTOR * ROW_ECC_SIZE;
bank->sectors[i].offset = flash_addr - bank->base;
bank->sectors[i].is_erased = -1;
diff --git a/src/flash/nor/psoc6.c b/src/flash/nor/psoc6.c
index a8f8d3f..3eb2fc2 100644
--- a/src/flash/nor/psoc6.c
+++ b/src/flash/nor/psoc6.c
@@ -450,7 +450,7 @@ static int psoc6_protect_check(struct flash_bank *bank)
break;
}
- for (int i = 0; i < bank->num_sectors; i++)
+ for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_protected = is_protected;
return ERROR_OK;
@@ -460,7 +460,8 @@ static int psoc6_protect_check(struct flash_bank *bank)
* @brief Dummy function, Life Cycle transition is not currently supported
* @return ERROR_OK always
*************************************************************************************************/
-static int psoc6_protect(struct flash_bank *bank, int set, int first, int last)
+static int psoc6_protect(struct flash_bank *bank, int set, unsigned int first,
+ unsigned int last)
{
(void)bank;
(void)set;
@@ -609,7 +610,7 @@ static int psoc6_probe(struct flash_bank *bank)
return ERROR_FLASH_BANK_INVALID;
}
- size_t num_sectors = bank_size / row_sz;
+ unsigned int num_sectors = bank_size / row_sz;
bank->size = bank_size;
bank->chip_width = 4;
bank->bus_width = 4;
@@ -618,7 +619,7 @@ static int psoc6_probe(struct flash_bank *bank)
bank->num_sectors = num_sectors;
bank->sectors = calloc(num_sectors, sizeof(struct flash_sector));
- for (size_t i = 0; i < num_sectors; i++) {
+ for (unsigned int i = 0; i < num_sectors; i++) {
bank->sectors[i].size = row_sz;
bank->sectors[i].offset = i * row_sz;
bank->sectors[i].is_erased = -1;
@@ -717,7 +718,8 @@ static int psoc6_erase_row(struct flash_bank *bank, struct working_area *wa, uin
* @param last last sector to erase
* @return ERROR_OK in case of success, ERROR_XXX code otherwise
*************************************************************************************************/
-static int psoc6_erase(struct flash_bank *bank, int first, int last)
+static int psoc6_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct target *target = bank->target;
struct psoc6_target_info *psoc6_info = bank->driver_priv;
@@ -740,7 +742,7 @@ static int psoc6_erase(struct flash_bank *bank, int first, int last)
goto exit;
/* Number of rows in single sector */
- const int rows_in_sector = sector_size / psoc6_info->row_sz;
+ const unsigned int rows_in_sector = sector_size / psoc6_info->row_sz;
while (last >= first) {
/* Erase Sector if we are on sector boundary and erase size covers whole sector */
@@ -750,7 +752,7 @@ static int psoc6_erase(struct flash_bank *bank, int first, int last)
if (hr != ERROR_OK)
goto exit_free_wa;
- for (int i = first; i < first + rows_in_sector; i++)
+ for (unsigned int i = first; i < first + rows_in_sector; i++)
bank->sectors[i].is_erased = 1;
first += rows_in_sector;
diff --git a/src/flash/nor/renesas_rpchf.c b/src/flash/nor/renesas_rpchf.c
index 3f03f92..933b6e5 100644
--- a/src/flash/nor/renesas_rpchf.c
+++ b/src/flash/nor/renesas_rpchf.c
@@ -497,7 +497,6 @@ static int rpchf_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t
int align; /* number of unaligned bytes */
uint8_t current_word[CFI_MAX_BUS_WIDTH * 4]; /* word (bus_width size) currently being
*programmed */
- int i;
int retval;
if (bank->target->state != TARGET_HALTED) {
@@ -523,14 +522,13 @@ static int rpchf_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t
return retval;
/* replace only bytes that must be written */
- for (i = align;
- (i < bank->bus_width) && (count > 0);
- i++, count--)
+ for (unsigned int i = align; (i < bank->bus_width) && (count > 0); i++, count--) {
if (cfi_info->data_swap)
/* data bytes are swapped (reverse endianness) */
current_word[bank->bus_width - i] = *buffer++;
else
current_word[i] = *buffer++;
+ }
retval = cfi_write_word(bank, current_word, write_p);
if (retval != ERROR_OK)
@@ -547,12 +545,12 @@ static int rpchf_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t
/* fall back to memory writes */
while (count >= (uint32_t)bank->bus_width) {
- int fallback;
+ bool fallback;
if ((write_p & 0xff) == 0) {
LOG_INFO("Programming at 0x%08" PRIx32 ", count 0x%08"
PRIx32 " bytes remaining", write_p, count);
}
- fallback = 1;
+ fallback = true;
if ((bufferwsize > 0) && (count >= buffersize) &&
!(write_p & buffermask)) {
retval = rpchf_write_words(bank, buffer, bufferwsize, write_p);
@@ -560,13 +558,13 @@ static int rpchf_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t
buffer += buffersize;
write_p += buffersize;
count -= buffersize;
- fallback = 0;
+ fallback = false;
} else if (retval != ERROR_FLASH_OPER_UNSUPPORTED)
return retval;
}
/* try the slow way? */
if (fallback) {
- for (i = 0; i < bank->bus_width; i++)
+ for (unsigned int i = 0; i < bank->bus_width; i++)
current_word[i] = *buffer++;
retval = cfi_write_word(bank, current_word, write_p);
@@ -593,7 +591,7 @@ static int rpchf_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t
return retval;
/* replace only bytes that must be written */
- for (i = 0; (i < bank->bus_width) && (count > 0); i++, count--)
+ for (unsigned int i = 0; (i < bank->bus_width) && (count > 0); i++, count--)
if (cfi_info->data_swap)
/* data bytes are swapped (reverse endianness) */
current_word[bank->bus_width - i] = *buffer++;
diff --git a/src/flash/nor/sh_qspi.c b/src/flash/nor/sh_qspi.c
index 862e43a..e6c9be4 100644
--- a/src/flash/nor/sh_qspi.c
+++ b/src/flash/nor/sh_qspi.c
@@ -437,21 +437,21 @@ static int sh_qspi_erase_sector(struct flash_bank *bank, int sector)
return wait_till_ready(bank, 3000);
}
-static int sh_qspi_erase(struct flash_bank *bank, int first, int last)
+static int sh_qspi_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct target *target = bank->target;
struct sh_qspi_flash_bank *info = bank->driver_priv;
int retval = ERROR_OK;
- int sector;
- LOG_DEBUG("%s: from sector %d to sector %d", __func__, first, last);
+ LOG_DEBUG("%s: from sector %u to sector %u", __func__, first, last);
if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED;
}
- if ((first < 0) || (last < first) || (last >= bank->num_sectors)) {
+ if ((last < first) || (last >= bank->num_sectors)) {
LOG_ERROR("Flash sector invalid");
return ERROR_FLASH_SECTOR_INVALID;
}
@@ -464,14 +464,14 @@ static int sh_qspi_erase(struct flash_bank *bank, int first, int last)
if (info->dev->erase_cmd == 0x00)
return ERROR_FLASH_OPER_UNSUPPORTED;
- for (sector = first; sector <= last; sector++) {
+ for (unsigned int sector = first; sector <= last; sector++) {
if (bank->sectors[sector].is_protected) {
- LOG_ERROR("Flash sector %d protected", sector);
+ LOG_ERROR("Flash sector %u protected", sector);
return ERROR_FAIL;
}
}
- for (sector = first; sector <= last; sector++) {
+ for (unsigned int sector = first; sector <= last; sector++) {
retval = sh_qspi_erase_sector(bank, sector);
if (retval != ERROR_OK)
break;
@@ -493,7 +493,6 @@ static int sh_qspi_write(struct flash_bank *bank, const uint8_t *buffer,
uint32_t chunk;
bool addr4b = !!(info->dev->size_in_bytes > (1UL << 24));
int ret = ERROR_OK;
- int sector;
LOG_DEBUG("%s: offset=0x%08" PRIx32 " count=0x%08" PRIx32,
__func__, offset, count);
@@ -515,7 +514,7 @@ static int sh_qspi_write(struct flash_bank *bank, const uint8_t *buffer,
}
/* Check sector protection */
- for (sector = 0; sector < bank->num_sectors; sector++) {
+ for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
/* Start offset in or before this sector? */
/* End offset in or behind this sector? */
struct flash_sector *bs = &bank->sectors[sector];
@@ -523,7 +522,7 @@ static int sh_qspi_write(struct flash_bank *bank, const uint8_t *buffer,
if ((offset < (bs->offset + bs->size)) &&
((offset + count - 1) >= bs->offset) &&
bs->is_protected) {
- LOG_ERROR("Flash sector %d protected", sector);
+ LOG_ERROR("Flash sector %u protected", sector);
return ERROR_FAIL;
}
}
@@ -685,11 +684,9 @@ static int read_flash_id(struct flash_bank *bank, uint32_t *id)
}
static int sh_qspi_protect(struct flash_bank *bank, int set,
- int first, int last)
+ unsigned int first, unsigned int last)
{
- int sector;
-
- for (sector = first; sector <= last; sector++)
+ for (unsigned int sector = first; sector <= last; sector++)
bank->sectors[sector].is_protected = set;
return ERROR_OK;
@@ -820,7 +817,7 @@ static int sh_qspi_probe(struct flash_bank *bank)
return ERROR_FAIL;
}
- for (int sector = 0; sector < bank->num_sectors; sector++) {
+ for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
sectors[sector].offset = sector * sectorsize;
sectors[sector].size = sectorsize;
sectors[sector].is_erased = 0;
diff --git a/src/flash/nor/sim3x.c b/src/flash/nor/sim3x.c
index 4e39705..d2d254e 100644
--- a/src/flash/nor/sim3x.c
+++ b/src/flash/nor/sim3x.c
@@ -277,9 +277,10 @@ static int sim3x_erase_page(struct flash_bank *bank, uint32_t addr)
return ERROR_FAIL;
}
-static int sim3x_flash_erase(struct flash_bank *bank, int first, int last)
+static int sim3x_flash_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
- int ret, i;
+ int ret;
uint32_t temp;
struct sim3x_info *sim3x_info;
struct target *target;
@@ -302,7 +303,7 @@ static int sim3x_flash_erase(struct flash_bank *bank, int first, int last)
}
/* erase pages */
- for (i = first; i <= last; i++) {
+ for (unsigned int i = first; i <= last; i++) {
ret = sim3x_erase_page(bank, bank->sectors[i].offset);
if (ret != ERROR_OK)
return ret;
@@ -311,7 +312,7 @@ static int sim3x_flash_erase(struct flash_bank *bank, int first, int last)
target = bank->target;
/* Wait until busy */
- for (i = 0; i < FLASH_BUSY_TIMEOUT; i++) {
+ for (unsigned int i = 0; i < FLASH_BUSY_TIMEOUT; i++) {
ret = target_read_u32(target, FLASHCTRL0_CONFIG_ALL, &temp);
if (ret != ERROR_OK)
return ret;
@@ -547,7 +548,7 @@ static int sim3x_flash_lock_check(struct flash_bank *bank)
static int sim3x_flash_protect_check(struct flash_bank *bank)
{
- int ret, i;
+ int ret;
struct sim3x_info *sim3x_info;
/* Check if target is halted */
@@ -562,13 +563,14 @@ static int sim3x_flash_protect_check(struct flash_bank *bank)
sim3x_info = bank->driver_priv;
- for (i = 0; i < bank->num_sectors; i++)
+ for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_protected = sim3x_info->flash_locked;
return ERROR_OK;
}
-static int sim3x_flash_protect(struct flash_bank *bank, int set, int first, int last)
+static int sim3x_flash_protect(struct flash_bank *bank, int set,
+ unsigned int first, unsigned int last)
{
int ret;
uint8_t lock_word[4];
diff --git a/src/flash/nor/stellaris.c b/src/flash/nor/stellaris.c
index 9c4c4bc..9763644 100644
--- a/src/flash/nor/stellaris.c
+++ b/src/flash/nor/stellaris.c
@@ -803,12 +803,11 @@ static int stellaris_protect_check(struct flash_bank *bank)
stellaris->num_pages;
uint32_t fmppe_addr;
int status = ERROR_OK;
- unsigned i;
if (stellaris->did1 == 0)
return ERROR_FLASH_BANK_NOT_PROBED;
- for (i = 0; i < (unsigned) bank->num_sectors; i++)
+ for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_protected = -1;
/* Read each Flash Memory Protection Program Enable (FMPPE) register
@@ -828,7 +827,7 @@ static int stellaris_protect_check(struct flash_bank *bank)
uint32_t fmppe;
target_read_u32(target, fmppe_addr, &fmppe);
- for (i = 0; i < 32 && lockbitnum + i < lockbitcnt; i++) {
+ for (unsigned int i = 0; i < 32 && lockbitnum + i < lockbitcnt; i++) {
bool protect = !(fmppe & (1 << i));
if (bits_per_page) {
bank->sectors[page++].is_protected = protect;
@@ -844,9 +843,9 @@ static int stellaris_protect_check(struct flash_bank *bank)
return status;
}
-static int stellaris_erase(struct flash_bank *bank, int first, int last)
+static int stellaris_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
- int banknr;
uint32_t flash_fmc, flash_cris;
struct stellaris_flash_bank *stellaris_info = bank->driver_priv;
struct target *target = bank->target;
@@ -859,10 +858,10 @@ static int stellaris_erase(struct flash_bank *bank, int first, int last)
if (stellaris_info->did1 == 0)
return ERROR_FLASH_BANK_NOT_PROBED;
- if ((first < 0) || (last < first) || (last >= (int)stellaris_info->num_pages))
+ if ((last < first) || (last >= stellaris_info->num_pages))
return ERROR_FLASH_SECTOR_INVALID;
- if ((first == 0) && (last == ((int)stellaris_info->num_pages-1)))
+ if ((first == 0) && (last == (stellaris_info->num_pages - 1)))
return stellaris_mass_erase(bank);
/* Refresh flash controller timing */
@@ -877,7 +876,7 @@ static int stellaris_erase(struct flash_bank *bank, int first, int last)
* it might want to process those IRQs.
*/
- for (banknr = first; banknr <= last; banknr++) {
+ for (unsigned int banknr = first; banknr <= last; banknr++) {
/* Address is first word in page */
target_write_u32(target, FLASH_FMA, banknr * stellaris_info->pagesize);
/* Write erase command */
@@ -902,7 +901,8 @@ static int stellaris_erase(struct flash_bank *bank, int first, int last)
return ERROR_OK;
}
-static int stellaris_protect(struct flash_bank *bank, int set, int first, int last)
+static int stellaris_protect(struct flash_bank *bank, int set,
+ unsigned int first, unsigned int last)
{
struct stellaris_flash_bank *stellaris = bank->driver_priv;
struct target *target = bank->target;
@@ -952,7 +952,7 @@ static int stellaris_protect(struct flash_bank *bank, int set, int first, int la
else
fmppe_addr = SCB_BASE | FMPPE;
- int page = 0;
+ unsigned int page = 0;
unsigned int lockbitnum, lockbitcnt = flash_sizek / 2;
/* Every lock bit always corresponds to a 2k region */
for (lockbitnum = 0; lockbitnum < lockbitcnt; lockbitnum += 32) {
@@ -1259,7 +1259,7 @@ static int stellaris_probe(struct flash_bank *bank)
bank->size = stellaris_info->num_pages * stellaris_info->pagesize;
bank->num_sectors = stellaris_info->num_pages;
bank->sectors = calloc(bank->num_sectors, sizeof(struct flash_sector));
- for (int i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
bank->sectors[i].offset = i * stellaris_info->pagesize;
bank->sectors[i].size = stellaris_info->pagesize;
bank->sectors[i].is_erased = -1;
@@ -1321,8 +1321,6 @@ static int stellaris_mass_erase(struct flash_bank *bank)
COMMAND_HANDLER(stellaris_handle_mass_erase_command)
{
- int i;
-
if (CMD_ARGC < 1)
return ERROR_COMMAND_SYNTAX_ERROR;
@@ -1333,7 +1331,7 @@ COMMAND_HANDLER(stellaris_handle_mass_erase_command)
if (stellaris_mass_erase(bank) == ERROR_OK) {
/* set all sectors as erased */
- for (i = 0; i < bank->num_sectors; i++)
+ for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_erased = 1;
command_print(CMD, "stellaris mass erase complete");
diff --git a/src/flash/nor/stm32f1x.c b/src/flash/nor/stm32f1x.c
index 990b48a..a07bd84 100644
--- a/src/flash/nor/stm32f1x.c
+++ b/src/flash/nor/stm32f1x.c
@@ -359,13 +359,14 @@ static int stm32x_protect_check(struct flash_bank *bank)
if (retval != ERROR_OK)
return retval;
- for (int i = 0; i < bank->num_prot_blocks; i++)
+ for (unsigned int i = 0; i < bank->num_prot_blocks; i++)
bank->prot_blocks[i].is_protected = (protection & (1 << i)) ? 0 : 1;
return ERROR_OK;
}
-static int stm32x_erase(struct flash_bank *bank, int first, int last)
+static int stm32x_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct target *target = bank->target;
@@ -385,7 +386,7 @@ static int stm32x_erase(struct flash_bank *bank, int first, int last)
if (retval != ERROR_OK)
return retval;
- for (int i = first; i <= last; i++) {
+ for (unsigned int i = first; i <= last; i++) {
retval = target_write_u32(target, stm32x_get_flash_reg(bank, STM32_FLASH_CR), FLASH_PER);
if (retval != ERROR_OK)
return retval;
@@ -412,7 +413,8 @@ static int stm32x_erase(struct flash_bank *bank, int first, int last)
return ERROR_OK;
}
-static int stm32x_protect(struct flash_bank *bank, int set, int first, int last)
+static int stm32x_protect(struct flash_bank *bank, int set, unsigned int first,
+ unsigned int last)
{
struct target *target = bank->target;
struct stm32x_flash_bank *stm32x_info = bank->driver_priv;
@@ -432,7 +434,7 @@ static int stm32x_protect(struct flash_bank *bank, int set, int first, int last)
return retval;
}
- for (int i = first; i <= last; i++) {
+ for (unsigned int i = first; i <= last; i++) {
if (set)
stm32x_info->option_bytes.protection &= ~(1 << i);
else
@@ -1499,7 +1501,7 @@ COMMAND_HANDLER(stm32x_handle_mass_erase_command)
retval = stm32x_mass_erase(bank);
if (retval == ERROR_OK) {
/* set all sectors as erased */
- for (int i = 0; i < bank->num_sectors; i++)
+ for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_erased = 1;
command_print(CMD, "stm32x mass erase complete");
diff --git a/src/flash/nor/stm32f2x.c b/src/flash/nor/stm32f2x.c
index c1283bb..c00b423 100644
--- a/src/flash/nor/stm32f2x.c
+++ b/src/flash/nor/stm32f2x.c
@@ -230,7 +230,7 @@ static int stm32x_otp_disable(struct flash_bank *bank)
{
struct stm32x_flash_bank *stm32x_info = bank->driver_priv;
- LOG_INFO("OTP memory bank #%d is disabled for write commands.",
+ LOG_INFO("OTP memory bank #%u is disabled for write commands.",
bank->bank_number);
stm32x_info->otp_unlocked = false;
return ERROR_OK;
@@ -241,11 +241,11 @@ static int stm32x_otp_enable(struct flash_bank *bank)
struct stm32x_flash_bank *stm32x_info = bank->driver_priv;
if (!stm32x_info->otp_unlocked) {
- LOG_INFO("OTP memory bank #%d is is enabled for write commands.",
+ LOG_INFO("OTP memory bank #%u is is enabled for write commands.",
bank->bank_number);
stm32x_info->otp_unlocked = true;
} else {
- LOG_WARNING("OTP memory bank #%d is is already enabled for write commands.",
+ LOG_WARNING("OTP memory bank #%u is is already enabled for write commands.",
bank->bank_number);
}
return ERROR_OK;
@@ -522,13 +522,13 @@ static int stm32x_otp_read_protect(struct flash_bank *bank)
{
struct target *target = bank->target;
uint32_t lock_base;
- int i, retval;
+ int retval;
uint8_t lock;
lock_base = stm32x_otp_is_f7(bank) ? STM32F7_OTP_LOCK_BASE
: STM32F2_OTP_LOCK_BASE;
- for (i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
retval = target_read_u8(target, lock_base + i, &lock);
if (retval != ERROR_OK)
return retval;
@@ -538,14 +538,15 @@ static int stm32x_otp_read_protect(struct flash_bank *bank)
return ERROR_OK;
}
-static int stm32x_otp_protect(struct flash_bank *bank, int first, int last)
+static int stm32x_otp_protect(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct target *target = bank->target;
uint32_t lock_base;
int i, retval;
uint8_t lock;
- assert((0 <= first) && (first <= last) && (last < bank->num_sectors));
+ assert((first <= last) && (last < bank->num_sectors));
lock_base = stm32x_otp_is_f7(bank) ? STM32F7_OTP_LOCK_BASE
: STM32F2_OTP_LOCK_BASE;
@@ -599,18 +600,18 @@ static int stm32x_protect_check(struct flash_bank *bank)
return ERROR_OK;
}
-static int stm32x_erase(struct flash_bank *bank, int first, int last)
+static int stm32x_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct stm32x_flash_bank *stm32x_info = bank->driver_priv;
struct target *target = bank->target;
- int i;
if (stm32x_is_otp(bank)) {
LOG_ERROR("Cannot erase OTP memory");
return ERROR_FAIL;
}
- assert((0 <= first) && (first <= last) && (last < bank->num_sectors));
+ assert((first <= last) && (last < bank->num_sectors));
if (bank->target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
@@ -633,7 +634,7 @@ static int stm32x_erase(struct flash_bank *bank, int first, int last)
4. Wait for the BSY bit to be cleared
*/
- for (i = first; i <= last; i++) {
+ for (unsigned int i = first; i <= last; i++) {
unsigned int snb;
if (stm32x_info->has_large_mem && i >= 12)
snb = (i - 12) | 0x10;
@@ -659,7 +660,8 @@ static int stm32x_erase(struct flash_bank *bank, int first, int last)
return ERROR_OK;
}
-static int stm32x_protect(struct flash_bank *bank, int set, int first, int last)
+static int stm32x_protect(struct flash_bank *bank, int set, unsigned int first,
+ unsigned int last)
{
struct target *target = bank->target;
struct stm32x_flash_bank *stm32x_info = bank->driver_priv;
@@ -683,7 +685,7 @@ static int stm32x_protect(struct flash_bank *bank, int set, int first, int last)
return retval;
}
- for (int i = first; i <= last; i++) {
+ for (unsigned int i = first; i <= last; i++) {
if (set)
stm32x_info->option_bytes.protection &= ~(1 << i);
else
@@ -894,7 +896,8 @@ static int stm32x_write(struct flash_bank *bank, const uint8_t *buffer,
return target_write_u32(target, STM32_FLASH_CR, FLASH_LOCK);
}
-static void setup_sector(struct flash_bank *bank, int i, int size)
+static void setup_sector(struct flash_bank *bank, unsigned int i,
+ unsigned int size)
{
assert(i < bank->num_sectors);
bank->sectors[i].offset = bank->size;
@@ -1559,8 +1562,6 @@ static int stm32x_mass_erase(struct flash_bank *bank)
COMMAND_HANDLER(stm32x_handle_mass_erase_command)
{
- int i;
-
if (CMD_ARGC < 1) {
command_print(CMD, "stm32x mass_erase <bank>");
return ERROR_COMMAND_SYNTAX_ERROR;
@@ -1574,7 +1575,7 @@ COMMAND_HANDLER(stm32x_handle_mass_erase_command)
retval = stm32x_mass_erase(bank);
if (retval == ERROR_OK) {
/* set all sectors as erased */
- for (i = 0; i < bank->num_sectors; i++)
+ for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_erased = 1;
command_print(CMD, "stm32x mass erase complete");
diff --git a/src/flash/nor/stm32h7x.c b/src/flash/nor/stm32h7x.c
index 7b6fdb3..26def3f 100644
--- a/src/flash/nor/stm32h7x.c
+++ b/src/flash/nor/stm32h7x.c
@@ -441,13 +441,14 @@ static int stm32x_protect_check(struct flash_bank *bank)
return retval;
}
- for (int i = 0; i < bank->num_prot_blocks; i++)
+ for (unsigned int i = 0; i < bank->num_prot_blocks; i++)
bank->prot_blocks[i].is_protected = protection & (1 << i) ? 0 : 1;
return ERROR_OK;
}
-static int stm32x_erase(struct flash_bank *bank, int first, int last)
+static int stm32x_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct stm32h7x_flash_bank *stm32x_info = bank->driver_priv;
int retval, retval2;
@@ -472,24 +473,24 @@ static int stm32x_erase(struct flash_bank *bank, int first, int last)
3. Set the STRT bit in the FLASH_CR register
4. Wait for flash operations completion
*/
- for (int i = first; i <= last; i++) {
- LOG_DEBUG("erase sector %d", i);
+ for (unsigned int i = first; i <= last; i++) {
+ LOG_DEBUG("erase sector %u", i);
retval = stm32x_write_flash_reg(bank, FLASH_CR,
stm32x_info->part_info->compute_flash_cr(FLASH_SER | FLASH_PSIZE_64, i));
if (retval != ERROR_OK) {
- LOG_ERROR("Error erase sector %d", i);
+ LOG_ERROR("Error erase sector %u", i);
goto flash_lock;
}
retval = stm32x_write_flash_reg(bank, FLASH_CR,
stm32x_info->part_info->compute_flash_cr(FLASH_SER | FLASH_PSIZE_64 | FLASH_START, i));
if (retval != ERROR_OK) {
- LOG_ERROR("Error erase sector %d", i);
+ LOG_ERROR("Error erase sector %u", i);
goto flash_lock;
}
retval = stm32x_wait_flash_op_queue(bank, FLASH_ERASE_TIMEOUT);
if (retval != ERROR_OK) {
- LOG_ERROR("erase time-out or operation error sector %d", i);
+ LOG_ERROR("erase time-out or operation error sector %u", i);
goto flash_lock;
}
bank->sectors[i].is_erased = 1;
@@ -503,7 +504,8 @@ flash_lock:
return (retval == ERROR_OK) ? retval2 : retval;
}
-static int stm32x_protect(struct flash_bank *bank, int set, int first, int last)
+static int stm32x_protect(struct flash_bank *bank, int set, unsigned int first,
+ unsigned int last)
{
struct target *target = bank->target;
uint32_t protection;
@@ -520,7 +522,7 @@ static int stm32x_protect(struct flash_bank *bank, int set, int first, int last)
return retval;
}
- for (int i = first; i <= last; i++) {
+ for (unsigned int i = first; i <= last; i++) {
if (set)
protection &= ~(1 << i);
else
@@ -766,7 +768,7 @@ static int stm32x_probe(struct flash_bank *bank)
else if (bank->base == FLASH_BANK1_ADDRESS)
stm32x_info->flash_regs_base = FLASH_REG_BASE_B1;
else {
- LOG_WARNING("Flash register base not defined for bank %d", bank->bank_number);
+ LOG_WARNING("Flash register base not defined for bank %u", bank->bank_number);
return ERROR_FAIL;
}
LOG_DEBUG("flash_regs_base: 0x%" PRIx32, stm32x_info->flash_regs_base);
@@ -828,7 +830,7 @@ static int stm32x_probe(struct flash_bank *bank)
}
}
- LOG_INFO("Bank (%d) size is %d kb, base address is 0x%" PRIx32,
+ LOG_INFO("Bank (%u) size is %d kb, base address is 0x%" PRIx32,
bank->bank_number, flash_size_in_kb, (uint32_t) bank->base);
/* if the user sets the size manually then ignore the probed value
@@ -1068,7 +1070,7 @@ COMMAND_HANDLER(stm32x_handle_mass_erase_command)
retval = stm32x_mass_erase(bank);
if (retval == ERROR_OK) {
/* set all sectors as erased */
- for (int i = 0; i < bank->num_sectors; i++)
+ for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_erased = 1;
command_print(CMD, "stm32h7x mass erase complete");
diff --git a/src/flash/nor/stm32l4x.c b/src/flash/nor/stm32l4x.c
index 94fcd32..edd0130 100644
--- a/src/flash/nor/stm32l4x.c
+++ b/src/flash/nor/stm32l4x.c
@@ -129,7 +129,7 @@ struct stm32l4_part_info {
struct stm32l4_flash_bank {
bool probed;
uint32_t idcode;
- int bank1_sectors;
+ unsigned int bank1_sectors;
bool dual_bank_mode;
int hole_sectors;
uint32_t user_bank_size;
@@ -548,7 +548,7 @@ static int stm32l4_protect_check(struct flash_bank *bank)
const uint8_t wrp2b_start = wrp2br & stm32l4_info->wrpxxr_mask;
const uint8_t wrp2b_end = (wrp2br >> 16) & stm32l4_info->wrpxxr_mask;
- for (int i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
if (i < stm32l4_info->bank1_sectors) {
if (((i >= wrp1a_start) &&
(i <= wrp1a_end)) ||
@@ -573,13 +573,13 @@ static int stm32l4_protect_check(struct flash_bank *bank)
return ERROR_OK;
}
-static int stm32l4_erase(struct flash_bank *bank, int first, int last)
+static int stm32l4_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct stm32l4_flash_bank *stm32l4_info = bank->driver_priv;
- int i;
int retval, retval2;
- assert((0 <= first) && (first <= last) && (last < bank->num_sectors));
+ assert((first <= last) && (last < bank->num_sectors));
if (bank->target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
@@ -601,7 +601,7 @@ static int stm32l4_erase(struct flash_bank *bank, int first, int last)
4. Wait for the BSY bit to be cleared
*/
- for (i = first; i <= last; i++) {
+ for (unsigned int i = first; i <= last; i++) {
uint32_t erase_flags;
erase_flags = FLASH_PER | FLASH_STRT;
@@ -631,7 +631,8 @@ err_lock:
return retval2;
}
-static int stm32l4_protect(struct flash_bank *bank, int set, int first, int last)
+static int stm32l4_protect(struct flash_bank *bank, int set, unsigned int first,
+ unsigned int last)
{
struct target *target = bank->target;
struct stm32l4_flash_bank *stm32l4_info = bank->driver_priv;
@@ -1053,7 +1054,7 @@ static int stm32l4_probe(struct flash_bank *bank)
return ERROR_FAIL;
}
- for (int i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
bank->sectors[i].offset = i * page_size_kb * 1024;
/* in dual bank configuration, if there is a gap between banks
* we fix up the sector offset to consider this gap */
@@ -1169,7 +1170,7 @@ COMMAND_HANDLER(stm32l4_handle_mass_erase_command)
retval = stm32l4_mass_erase(bank);
if (retval == ERROR_OK) {
/* set all sectors as erased */
- for (int i = 0; i < bank->num_sectors; i++)
+ for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_erased = 1;
command_print(CMD, "stm32l4x mass erase complete");
diff --git a/src/flash/nor/stm32lx.c b/src/flash/nor/stm32lx.c
index c3f9c72..9c817c9 100644
--- a/src/flash/nor/stm32lx.c
+++ b/src/flash/nor/stm32lx.c
@@ -319,7 +319,7 @@ COMMAND_HANDLER(stm32lx_handle_mass_erase_command)
retval = stm32lx_mass_erase(bank);
if (retval == ERROR_OK) {
/* set all sectors as erased */
- for (int i = 0; i < bank->num_sectors; i++)
+ for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_erased = 1;
command_print(CMD, "stm32lx mass erase complete");
@@ -387,7 +387,7 @@ static int stm32lx_protect_check(struct flash_bank *bank)
if (retval != ERROR_OK)
return retval;
- for (int i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
if (wrpr & (1 << i))
bank->sectors[i].is_protected = 1;
else
@@ -396,7 +396,8 @@ static int stm32lx_protect_check(struct flash_bank *bank)
return ERROR_OK;
}
-static int stm32lx_erase(struct flash_bank *bank, int first, int last)
+static int stm32lx_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
int retval;
@@ -413,7 +414,7 @@ static int stm32lx_erase(struct flash_bank *bank, int first, int last)
/*
* Loop over the selected sectors and erase them
*/
- for (int i = first; i <= last; i++) {
+ for (unsigned int i = first; i <= last; i++) {
retval = stm32lx_erase_sector(bank, i);
if (retval != ERROR_OK)
return retval;
@@ -819,7 +820,7 @@ static int stm32lx_probe(struct flash_bank *bank)
bank->base, base_address, second_bank_base);
return ERROR_FAIL;
}
- LOG_INFO("STM32L flash has dual banks. Bank (%d) size is %dkb, base address is 0x%" PRIx32,
+ LOG_INFO("STM32L flash has dual banks. Bank (%u) size is %dkb, base address is 0x%" PRIx32,
bank->bank_number, flash_size_in_kb, base_address);
} else {
LOG_INFO("STM32L flash size is %dkb, base address is 0x%" PRIx32, flash_size_in_kb, base_address);
@@ -833,7 +834,7 @@ static int stm32lx_probe(struct flash_bank *bank)
}
/* calculate numbers of sectors (4kB per sector) */
- int num_sectors = (flash_size_in_kb * 1024) / FLASH_SECTOR_SIZE;
+ unsigned int num_sectors = (flash_size_in_kb * 1024) / FLASH_SECTOR_SIZE;
if (bank->sectors) {
free(bank->sectors);
@@ -849,7 +850,7 @@ static int stm32lx_probe(struct flash_bank *bank)
return ERROR_FAIL;
}
- for (int i = 0; i < num_sectors; i++) {
+ for (unsigned int i = 0; i < num_sectors; i++) {
bank->sectors[i].offset = i * FLASH_SECTOR_SIZE;
bank->sectors[i].size = FLASH_SECTOR_SIZE;
bank->sectors[i].is_erased = -1;
diff --git a/src/flash/nor/stmsmi.c b/src/flash/nor/stmsmi.c
index f56b9b7..e63401e 100644
--- a/src/flash/nor/stmsmi.c
+++ b/src/flash/nor/stmsmi.c
@@ -313,22 +313,22 @@ static int smi_erase_sector(struct flash_bank *bank, int sector)
return ERROR_OK;
}
-static int stmsmi_erase(struct flash_bank *bank, int first, int last)
+static int stmsmi_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct target *target = bank->target;
struct stmsmi_flash_bank *stmsmi_info = bank->driver_priv;
uint32_t io_base = stmsmi_info->io_base;
int retval = ERROR_OK;
- int sector;
- LOG_DEBUG("%s: from sector %d to sector %d", __func__, first, last);
+ LOG_DEBUG("%s: from sector %u to sector %u", __func__, first, last);
if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED;
}
- if ((first < 0) || (last < first) || (last >= bank->num_sectors)) {
+ if ((last < first) || (last >= bank->num_sectors)) {
LOG_ERROR("Flash sector invalid");
return ERROR_FLASH_SECTOR_INVALID;
}
@@ -338,9 +338,9 @@ static int stmsmi_erase(struct flash_bank *bank, int first, int last)
return ERROR_FLASH_BANK_NOT_PROBED;
}
- for (sector = first; sector <= last; sector++) {
+ for (unsigned int sector = first; sector <= last; sector++) {
if (bank->sectors[sector].is_protected) {
- LOG_ERROR("Flash sector %d protected", sector);
+ LOG_ERROR("Flash sector %u protected", sector);
return ERROR_FAIL;
}
}
@@ -348,7 +348,7 @@ static int stmsmi_erase(struct flash_bank *bank, int first, int last)
if (stmsmi_info->dev->erase_cmd == 0x00)
return ERROR_FLASH_OPER_UNSUPPORTED;
- for (sector = first; sector <= last; sector++) {
+ for (unsigned int sector = first; sector <= last; sector++) {
retval = smi_erase_sector(bank, sector);
if (retval != ERROR_OK)
break;
@@ -361,11 +361,9 @@ static int stmsmi_erase(struct flash_bank *bank, int first, int last)
}
static int stmsmi_protect(struct flash_bank *bank, int set,
- int first, int last)
+ unsigned int first, unsigned int last)
{
- int sector;
-
- for (sector = first; sector <= last; sector++)
+ for (unsigned int sector = first; sector <= last; sector++)
bank->sectors[sector].is_protected = set;
return ERROR_OK;
}
@@ -402,7 +400,6 @@ static int stmsmi_write(struct flash_bank *bank, const uint8_t *buffer,
struct stmsmi_flash_bank *stmsmi_info = bank->driver_priv;
uint32_t io_base = stmsmi_info->io_base;
uint32_t cur_count, page_size, page_offset;
- int sector;
int retval = ERROR_OK;
LOG_DEBUG("%s: offset=0x%08" PRIx32 " count=0x%08" PRIx32,
@@ -419,14 +416,14 @@ static int stmsmi_write(struct flash_bank *bank, const uint8_t *buffer,
}
/* Check sector protection */
- for (sector = 0; sector < bank->num_sectors; sector++) {
+ for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
/* Start offset in or before this sector? */
/* End offset in or behind this sector? */
if ((offset <
(bank->sectors[sector].offset + bank->sectors[sector].size))
&& ((offset + count - 1) >= bank->sectors[sector].offset)
&& bank->sectors[sector].is_protected) {
- LOG_ERROR("Flash sector %d protected", sector);
+ LOG_ERROR("Flash sector %u protected", sector);
return ERROR_FAIL;
}
}
@@ -609,7 +606,7 @@ static int stmsmi_probe(struct flash_bank *bank)
return ERROR_FAIL;
}
- for (int sector = 0; sector < bank->num_sectors; sector++) {
+ for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
sectors[sector].offset = sector * sectorsize;
sectors[sector].size = sectorsize;
sectors[sector].is_erased = -1;
diff --git a/src/flash/nor/str7x.c b/src/flash/nor/str7x.c
index eaef197..dd72f53 100644
--- a/src/flash/nor/str7x.c
+++ b/src/flash/nor/str7x.c
@@ -138,7 +138,7 @@ static int str7x_build_block_list(struct flash_bank *bank)
struct str7x_flash_bank *str7x_info = bank->driver_priv;
int i;
- int num_sectors;
+ unsigned int num_sectors;
int b0_sectors = 0, b1_sectors = 0;
switch (bank->size) {
@@ -306,7 +306,6 @@ static int str7x_protect_check(struct flash_bank *bank)
struct str7x_flash_bank *str7x_info = bank->driver_priv;
struct target *target = bank->target;
- int i;
uint32_t flash_flags;
if (bank->target->state != TARGET_HALTED) {
@@ -319,7 +318,7 @@ static int str7x_protect_check(struct flash_bank *bank)
if (retval != ERROR_OK)
return retval;
- for (i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
if (flash_flags & str7x_info->sector_bits[i])
bank->sectors[i].is_protected = 0;
else
@@ -329,12 +328,12 @@ static int str7x_protect_check(struct flash_bank *bank)
return ERROR_OK;
}
-static int str7x_erase(struct flash_bank *bank, int first, int last)
+static int str7x_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct str7x_flash_bank *str7x_info = bank->driver_priv;
struct target *target = bank->target;
- int i;
uint32_t cmd;
uint32_t sectors = 0;
int err;
@@ -344,7 +343,7 @@ static int str7x_erase(struct flash_bank *bank, int first, int last)
return ERROR_TARGET_NOT_HALTED;
}
- for (i = first; i <= last; i++)
+ for (unsigned int i = first; i <= last; i++)
sectors |= str7x_info->sector_bits[i];
LOG_DEBUG("sectors: 0x%" PRIx32 "", sectors);
@@ -377,17 +376,17 @@ static int str7x_erase(struct flash_bank *bank, int first, int last)
if (err != ERROR_OK)
return err;
- for (i = first; i <= last; i++)
+ for (unsigned int i = first; i <= last; i++)
bank->sectors[i].is_erased = 1;
return ERROR_OK;
}
-static int str7x_protect(struct flash_bank *bank, int set, int first, int last)
+static int str7x_protect(struct flash_bank *bank, int set, unsigned int first,
+ unsigned int last)
{
struct str7x_flash_bank *str7x_info = bank->driver_priv;
struct target *target = bank->target;
- int i;
uint32_t cmd;
uint32_t protect_blocks;
@@ -399,7 +398,7 @@ static int str7x_protect(struct flash_bank *bank, int set, int first, int last)
protect_blocks = 0xFFFFFFFF;
if (set) {
- for (i = first; i <= last; i++)
+ for (unsigned int i = first; i <= last; i++)
protect_blocks &= ~(str7x_info->sector_bits[i]);
}
@@ -568,7 +567,6 @@ static int str7x_write(struct flash_bank *bank, const uint8_t *buffer,
uint32_t cmd;
int retval;
uint32_t check_address = offset;
- int i;
if (bank->target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
@@ -580,7 +578,7 @@ static int str7x_write(struct flash_bank *bank, const uint8_t *buffer,
return ERROR_FLASH_DST_BREAKS_ALIGNMENT;
}
- for (i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
uint32_t sec_start = bank->sectors[i].offset;
uint32_t sec_end = sec_start + bank->sectors[i].size;
diff --git a/src/flash/nor/str9x.c b/src/flash/nor/str9x.c
index 85cbe6a..d49875c 100644
--- a/src/flash/nor/str9x.c
+++ b/src/flash/nor/str9x.c
@@ -68,7 +68,7 @@ static int str9x_build_block_list(struct flash_bank *bank)
struct str9x_flash_bank *str9x_info = bank->driver_priv;
int i;
- int num_sectors;
+ unsigned int num_sectors;
int b0_sectors = 0, b1_sectors = 0;
uint32_t offset = 0;
@@ -164,7 +164,6 @@ static int str9x_protect_check(struct flash_bank *bank)
struct str9x_flash_bank *str9x_info = bank->driver_priv;
struct target *target = bank->target;
- int i;
uint32_t adr;
uint32_t status = 0;
uint16_t hstatus = 0;
@@ -211,7 +210,7 @@ static int str9x_protect_check(struct flash_bank *bank)
if (retval != ERROR_OK)
return retval;
- for (i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
if (status & str9x_info->sector_bits[i])
bank->sectors[i].is_protected = 1;
else
@@ -221,10 +220,10 @@ static int str9x_protect_check(struct flash_bank *bank)
return ERROR_OK;
}
-static int str9x_erase(struct flash_bank *bank, int first, int last)
+static int str9x_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct target *target = bank->target;
- int i;
uint32_t adr;
uint8_t status;
uint8_t erase_cmd;
@@ -250,7 +249,7 @@ static int str9x_erase(struct flash_bank *bank, int first, int last)
/* this is so the compiler can *know* */
assert(total_timeout > 0);
- for (i = first; i <= last; i++) {
+ for (unsigned int i = first; i <= last; i++) {
int retval;
adr = bank->base + bank->sectors[i].offset;
@@ -301,17 +300,16 @@ static int str9x_erase(struct flash_bank *bank, int first, int last)
break;
}
- for (i = first; i <= last; i++)
+ for (unsigned int i = first; i <= last; i++)
bank->sectors[i].is_erased = 1;
return ERROR_OK;
}
-static int str9x_protect(struct flash_bank *bank,
- int set, int first, int last)
+static int str9x_protect(struct flash_bank *bank, int set, unsigned int first,
+ unsigned int last)
{
struct target *target = bank->target;
- int i;
uint32_t adr;
uint8_t status;
@@ -320,7 +318,7 @@ static int str9x_protect(struct flash_bank *bank,
return ERROR_TARGET_NOT_HALTED;
}
- for (i = first; i <= last; i++) {
+ for (unsigned int i = first; i <= last; i++) {
/* Level One Protection */
adr = bank->base + bank->sectors[i].offset;
@@ -468,7 +466,6 @@ static int str9x_write(struct flash_bank *bank,
int retval;
uint32_t check_address = offset;
uint32_t bank_adr;
- int i;
if (bank->target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
@@ -480,7 +477,7 @@ static int str9x_write(struct flash_bank *bank,
return ERROR_FLASH_DST_BREAKS_ALIGNMENT;
}
- for (i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
uint32_t sec_start = bank->sectors[i].offset;
uint32_t sec_end = sec_start + bank->sectors[i].size;
diff --git a/src/flash/nor/str9xpec.c b/src/flash/nor/str9xpec.c
index 6e1ecf3..9946b06 100644
--- a/src/flash/nor/str9xpec.c
+++ b/src/flash/nor/str9xpec.c
@@ -74,7 +74,8 @@ struct str9xpec_flash_controller {
uint8_t options[8];
};
-static int str9xpec_erase_area(struct flash_bank *bank, int first, int last);
+static int str9xpec_erase_area(struct flash_bank *bank, unsigned int first,
+ unsigned int last);
static int str9xpec_set_address(struct flash_bank *bank, uint8_t sector);
static int str9xpec_write_options(struct flash_bank *bank);
@@ -210,7 +211,7 @@ static int str9xpec_build_block_list(struct flash_bank *bank)
struct str9xpec_flash_controller *str9xpec_info = bank->driver_priv;
int i;
- int num_sectors;
+ unsigned int num_sectors;
int b0_sectors = 0, b1_sectors = 0;
uint32_t offset = 0;
int b1_size = 0x2000;
@@ -303,12 +304,12 @@ FLASH_BANK_COMMAND_HANDLER(str9xpec_flash_bank_command)
return ERROR_OK;
}
-static int str9xpec_blank_check(struct flash_bank *bank, int first, int last)
+static int str9xpec_blank_check(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct scan_field field;
uint8_t status;
struct jtag_tap *tap;
- int i;
uint8_t *buffer = NULL;
struct str9xpec_flash_controller *str9xpec_info = bank->driver_priv;
@@ -323,9 +324,9 @@ static int str9xpec_blank_check(struct flash_bank *bank, int first, int last)
buffer = calloc(DIV_ROUND_UP(64, 8), 1);
- LOG_DEBUG("blank check: first_bank: %i, last_bank: %i", first, last);
+ LOG_DEBUG("blank check: first_bank: %u, last_bank: %u", first, last);
- for (i = first; i <= last; i++)
+ for (unsigned int i = first; i <= last; i++)
buf_set_u32(buffer, str9xpec_info->sector_bits[i], 1, 1);
/* execute ISC_BLANK_CHECK command */
@@ -348,7 +349,7 @@ static int str9xpec_blank_check(struct flash_bank *bank, int first, int last)
status = str9xpec_isc_status(tap);
- for (i = first; i <= last; i++) {
+ for (unsigned int i = first; i <= last; i++) {
if (buf_get_u32(buffer, str9xpec_info->sector_bits[i], 1))
bank->sectors[i].is_erased = 0;
else
@@ -367,13 +368,12 @@ static int str9xpec_blank_check(struct flash_bank *bank, int first, int last)
static int str9xpec_protect_check(struct flash_bank *bank)
{
uint8_t status;
- int i;
struct str9xpec_flash_controller *str9xpec_info = bank->driver_priv;
status = str9xpec_read_config(bank);
- for (i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
if (buf_get_u32(str9xpec_info->options, str9xpec_info->sector_bits[i], 1))
bank->sectors[i].is_protected = 1;
else
@@ -385,12 +385,12 @@ static int str9xpec_protect_check(struct flash_bank *bank)
return ERROR_OK;
}
-static int str9xpec_erase_area(struct flash_bank *bank, int first, int last)
+static int str9xpec_erase_area(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct scan_field field;
uint8_t status;
struct jtag_tap *tap;
- int i;
uint8_t *buffer = NULL;
struct str9xpec_flash_controller *str9xpec_info = bank->driver_priv;
@@ -405,17 +405,17 @@ static int str9xpec_erase_area(struct flash_bank *bank, int first, int last)
buffer = calloc(DIV_ROUND_UP(64, 8), 1);
- LOG_DEBUG("erase: first_bank: %i, last_bank: %i", first, last);
+ LOG_DEBUG("erase: first_bank: %u, last_bank: %u", first, last);
/* last bank: 0xFF signals a full erase (unlock complete device) */
/* last bank: 0xFE signals a option byte erase */
if (last == 0xFF) {
- for (i = 0; i < 64; i++)
+ for (unsigned int i = 0; i < 64; i++)
buf_set_u32(buffer, i, 1, 1);
} else if (last == 0xFE)
buf_set_u32(buffer, 49, 1, 1);
else {
- for (i = first; i <= last; i++)
+ for (unsigned int i = first; i <= last; i++)
buf_set_u32(buffer, str9xpec_info->sector_bits[i], 1, 1);
}
@@ -444,7 +444,8 @@ static int str9xpec_erase_area(struct flash_bank *bank, int first, int last)
return status;
}
-static int str9xpec_erase(struct flash_bank *bank, int first, int last)
+static int str9xpec_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
int status;
@@ -504,10 +505,10 @@ static int str9xpec_unlock_device(struct flash_bank *bank)
return status;
}
-static int str9xpec_protect(struct flash_bank *bank, int set, int first, int last)
+static int str9xpec_protect(struct flash_bank *bank, int set,
+ unsigned int first, unsigned int last)
{
uint8_t status;
- int i;
struct str9xpec_flash_controller *str9xpec_info = bank->driver_priv;
@@ -516,7 +517,7 @@ static int str9xpec_protect(struct flash_bank *bank, int set, int first, int las
if ((status & ISC_STATUS_ERROR) != STR9XPEC_ISC_SUCCESS)
return ERROR_FLASH_OPERATION_FAILED;
- LOG_DEBUG("protect: first_bank: %i, last_bank: %i", first, last);
+ LOG_DEBUG("protect: first_bank: %u, last_bank: %u", first, last);
/* last bank: 0xFF signals a full device protect */
if (last == 0xFF) {
@@ -527,7 +528,7 @@ static int str9xpec_protect(struct flash_bank *bank, int set, int first, int las
status = str9xpec_unlock_device(bank);
}
} else {
- for (i = first; i <= last; i++) {
+ for (unsigned int i = first; i <= last; i++) {
if (set)
buf_set_u32(str9xpec_info->options, str9xpec_info->sector_bits[i], 1, 1);
else
@@ -575,9 +576,8 @@ static int str9xpec_write(struct flash_bank *bank, const uint8_t *buffer,
struct jtag_tap *tap;
struct scan_field field;
uint8_t *scanbuf;
- int i;
- int first_sector = 0;
- int last_sector = 0;
+ unsigned int first_sector = 0;
+ unsigned int last_sector = 0;
tap = str9xpec_info->tap;
@@ -592,7 +592,7 @@ static int str9xpec_write(struct flash_bank *bank, const uint8_t *buffer,
return ERROR_FLASH_DST_BREAKS_ALIGNMENT;
}
- for (i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
uint32_t sec_start = bank->sectors[i].offset;
uint32_t sec_end = sec_start + bank->sectors[i].size;
@@ -621,7 +621,7 @@ static int str9xpec_write(struct flash_bank *bank, const uint8_t *buffer,
LOG_DEBUG("ISC_PROGRAM");
- for (i = first_sector; i <= last_sector; i++) {
+ for (unsigned int i = first_sector; i <= last_sector; i++) {
str9xpec_set_address(bank, str9xpec_info->sector_bits[i]);
dwords_remaining = dwords_remaining < (bank->sectors[i].size/8)
diff --git a/src/flash/nor/swm050.c b/src/flash/nor/swm050.c
index 241207d..020a1da 100644
--- a/src/flash/nor/swm050.c
+++ b/src/flash/nor/swm050.c
@@ -38,11 +38,11 @@
#define SWM050_SYSCTL_CFG_0 0x400F0000
#define SWM050_SYSCTL_DBLF 0x400F0008
-static int swm050_erase(struct flash_bank *bank, int first, int last)
+static int swm050_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct target *target = bank->target;
- int retval, curr_page;
- uint32_t curr_addr;
+ int retval;
if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
@@ -54,8 +54,8 @@ static int swm050_erase(struct flash_bank *bank, int first, int last)
if (retval != ERROR_OK)
return retval;
- for (curr_page = first; curr_page <= last; curr_page++) {
- curr_addr = bank->base + (SWM050_FLASH_PAGE_SIZE * curr_page);
+ for (unsigned int curr_page = first; curr_page <= last; curr_page++) {
+ uint32_t curr_addr = bank->base + (SWM050_FLASH_PAGE_SIZE * curr_page);
/* Perform write */
retval = target_write_u32(target, curr_addr, SWM050_FLASH_KEY);
if (retval != ERROR_OK)
@@ -169,7 +169,7 @@ FLASH_BANK_COMMAND_HANDLER(swm050_flash_bank_command)
if (!bank->sectors)
return ERROR_FAIL;
- for (int i = 0; i < bank->num_sectors; i++)
+ for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_protected = 0;
return ERROR_OK;
diff --git a/src/flash/nor/tcl.c b/src/flash/nor/tcl.c
index fb2053b..3bdaf0b 100644
--- a/src/flash/nor/tcl.c
+++ b/src/flash/nor/tcl.c
@@ -112,8 +112,8 @@ COMMAND_HANDLER(handle_flash_info_command)
LOG_INFO("Flash protection check is not implemented.");
command_print(CMD,
- "#%d : %s at " TARGET_ADDR_FMT ", size 0x%8.8" PRIx32
- ", buswidth %i, chipwidth %i",
+ "#%u : %s at " TARGET_ADDR_FMT ", size 0x%8.8" PRIx32
+ ", buswidth %u, chipwidth %u",
p->bank_number,
p->driver->name,
p->base,
@@ -199,7 +199,6 @@ COMMAND_HANDLER(handle_flash_erase_check_command)
if (ERROR_OK != retval)
return retval;
- int j;
retval = p->driver->erase_check(p);
if (retval == ERROR_OK)
command_print(CMD, "successfully checked erase state");
@@ -211,7 +210,7 @@ COMMAND_HANDLER(handle_flash_erase_check_command)
p->base);
}
- for (j = 0; j < p->num_sectors; j++) {
+ for (unsigned int j = 0; j < p->num_sectors; j++) {
char *erase_state;
if (p->sectors[j].is_erased == 0)
@@ -325,7 +324,7 @@ COMMAND_HANDLER(handle_flash_erase_command)
return ERROR_FAIL;
}
- if (!(last <= (uint32_t)(p->num_sectors - 1))) {
+ if (!(last <= (p->num_sectors - 1))) {
command_print(CMD, "ERROR: "
"last sector must be <= %" PRIu32,
p->num_sectors - 1);
@@ -339,7 +338,7 @@ COMMAND_HANDLER(handle_flash_erase_command)
if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK)) {
command_print(CMD, "erased sectors %" PRIu32 " "
- "through %" PRIu32 " on flash bank %d "
+ "through %" PRIu32 " on flash bank %u "
"in %fs", first, last, p->bank_number, duration_elapsed(&bench));
}
@@ -1007,11 +1006,10 @@ COMMAND_HANDLER(handle_flash_verify_bank_command)
void flash_set_dirty(void)
{
struct flash_bank *c;
- int i;
/* set all flash to require erasing */
for (c = flash_bank_list(); c; c = c->next) {
- for (i = 0; i < c->num_sectors; i++)
+ for (unsigned int i = 0; i < c->num_sectors; i++)
c->sectors[i].is_erased = 0;
}
}
@@ -1243,8 +1241,8 @@ COMMAND_HANDLER(handle_flash_bank_command)
c->driver = driver;
COMMAND_PARSE_NUMBER(target_addr, CMD_ARGV[1], c->base);
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], c->size);
- COMMAND_PARSE_NUMBER(int, CMD_ARGV[3], c->chip_width);
- COMMAND_PARSE_NUMBER(int, CMD_ARGV[4], c->bus_width);
+ COMMAND_PARSE_NUMBER(uint, CMD_ARGV[3], c->chip_width);
+ COMMAND_PARSE_NUMBER(uint, CMD_ARGV[4], c->bus_width);
c->default_padded_value = c->erased_value = 0xff;
c->minimal_write_gap = FLASH_WRITE_GAP_SECTOR;
diff --git a/src/flash/nor/tms470.c b/src/flash/nor/tms470.c
index bc16aca..0d3f487 100644
--- a/src/flash/nor/tms470.c
+++ b/src/flash/nor/tms470.c
@@ -801,10 +801,11 @@ static const struct command_registration tms470_command_handlers[] = {
/* ---------------------------------------------------------------------- */
-static int tms470_erase(struct flash_bank *bank, int first, int last)
+static int tms470_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct tms470_flash_bank *tms470_info = bank->driver_priv;
- int sector, result = ERROR_OK;
+ int result = ERROR_OK;
if (bank->target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
@@ -813,9 +814,9 @@ static int tms470_erase(struct flash_bank *bank, int first, int last)
tms470_read_part_info(bank);
- if ((first < 0) || (first >= bank->num_sectors) || (last < 0) ||
- (last >= bank->num_sectors) || (first > last)) {
- LOG_ERROR("Sector range %d to %d invalid.", first, last);
+ if ((first >= bank->num_sectors) || (last >= bank->num_sectors) ||
+ (first > last)) {
+ LOG_ERROR("Sector range %u to %u invalid.", first, last);
return ERROR_FLASH_SECTOR_INVALID;
}
@@ -823,8 +824,8 @@ static int tms470_erase(struct flash_bank *bank, int first, int last)
if (result != ERROR_OK)
return result;
- for (sector = first; sector <= last; sector++) {
- LOG_INFO("Erasing tms470 bank %d sector %d...", tms470_info->ordinal, sector);
+ for (unsigned int sector = first; sector <= last; sector++) {
+ LOG_INFO("Erasing tms470 bank %u sector %u...", tms470_info->ordinal, sector);
result = tms470_erase_sector(bank, sector);
@@ -840,12 +841,12 @@ static int tms470_erase(struct flash_bank *bank, int first, int last)
/* ---------------------------------------------------------------------- */
-static int tms470_protect(struct flash_bank *bank, int set, int first, int last)
+static int tms470_protect(struct flash_bank *bank, int set, unsigned int first,
+ unsigned int last)
{
struct tms470_flash_bank *tms470_info = bank->driver_priv;
struct target *target = bank->target;
uint32_t fmmac2, fmbsea, fmbseb;
- int sector;
if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
@@ -854,9 +855,9 @@ static int tms470_protect(struct flash_bank *bank, int set, int first, int last)
tms470_read_part_info(bank);
- if ((first < 0) || (first >= bank->num_sectors) || (last < 0) ||
- (last >= bank->num_sectors) || (first > last)) {
- LOG_ERROR("Sector range %d to %d invalid.", first, last);
+ if ((first >= bank->num_sectors) || (last >= bank->num_sectors) ||
+ (first > last)) {
+ LOG_ERROR("Sector range %u to %u invalid.", first, last);
return ERROR_FLASH_SECTOR_INVALID;
}
@@ -868,7 +869,7 @@ static int tms470_protect(struct flash_bank *bank, int set, int first, int last)
target_read_u32(target, 0xFFE88008, &fmbsea);
target_read_u32(target, 0xFFE8800C, &fmbseb);
- for (sector = 0; sector < bank->num_sectors; sector++) {
+ for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
if (sector < 16) {
fmbsea = set ? fmbsea & ~(1 << sector) : fmbsea | (1 << sector);
bank->sectors[sector].is_protected = set ? 1 : 0;
@@ -1004,7 +1005,7 @@ static int tms470_erase_check(struct flash_bank *bank)
{
struct target *target = bank->target;
struct tms470_flash_bank *tms470_info = bank->driver_priv;
- int sector, result = ERROR_OK;
+ int result = ERROR_OK;
uint32_t fmmac2, fmbac2, glbctrl, orig_fmregopt;
static uint8_t buffer[64 * 1024];
@@ -1043,10 +1044,10 @@ static int tms470_erase_check(struct flash_bank *bank)
* word at a time. Here we read an entire sector and inspect it in
* an attempt to reduce the JTAG overhead.
*/
- for (sector = 0; sector < bank->num_sectors; sector++) {
+ for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
uint32_t i, addr = bank->base + bank->sectors[sector].offset;
- LOG_INFO("checking flash bank %d sector %d", tms470_info->ordinal, sector);
+ LOG_INFO("checking flash bank %u sector %u", tms470_info->ordinal, sector);
target_read_buffer(target, addr, bank->sectors[sector].size, buffer);
@@ -1079,7 +1080,7 @@ static int tms470_protect_check(struct flash_bank *bank)
{
struct target *target = bank->target;
struct tms470_flash_bank *tms470_info = bank->driver_priv;
- int sector, result = ERROR_OK;
+ int result = ERROR_OK;
uint32_t fmmac2, fmbsea, fmbseb;
if (target->state != TARGET_HALTED) {
@@ -1097,7 +1098,7 @@ static int tms470_protect_check(struct flash_bank *bank)
target_read_u32(target, 0xFFE88008, &fmbsea);
target_read_u32(target, 0xFFE8800C, &fmbseb);
- for (sector = 0; sector < bank->num_sectors; sector++) {
+ for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
int protected;
if (sector < 16) {
@@ -1108,7 +1109,7 @@ static int tms470_protect_check(struct flash_bank *bank)
bank->sectors[sector].is_protected = protected;
}
- LOG_DEBUG("bank %d sector %d is %s",
+ LOG_DEBUG("bank %u sector %u is %s",
tms470_info->ordinal,
sector,
protected ? "protected" : "not protected");
diff --git a/src/flash/nor/virtual.c b/src/flash/nor/virtual.c
index fa51537..c9e1942 100644
--- a/src/flash/nor/virtual.c
+++ b/src/flash/nor/virtual.c
@@ -75,7 +75,8 @@ FLASH_BANK_COMMAND_HANDLER(virtual_flash_bank_command)
return ERROR_OK;
}
-static int virtual_protect(struct flash_bank *bank, int set, int first, int last)
+static int virtual_protect(struct flash_bank *bank, int set, unsigned int first,
+ unsigned int last)
{
struct flash_bank *master_bank = virtual_get_master_bank(bank);
int retval;
@@ -107,7 +108,8 @@ static int virtual_protect_check(struct flash_bank *bank)
return ERROR_OK;
}
-static int virtual_erase(struct flash_bank *bank, int first, int last)
+static int virtual_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct flash_bank *master_bank = virtual_get_master_bank(bank);
int retval;
diff --git a/src/flash/nor/w600.c b/src/flash/nor/w600.c
index 3a6f3ff..ce3bc6e 100644
--- a/src/flash/nor/w600.c
+++ b/src/flash/nor/w600.c
@@ -204,7 +204,8 @@ static int w600_start(struct flash_bank *bank, uint32_t cmd, uint32_t addr,
return retval;
}
-static int w600_erase(struct flash_bank *bank, int first, int last)
+static int w600_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
int retval = ERROR_OK;
@@ -217,7 +218,7 @@ static int w600_erase(struct flash_bank *bank, int first, int last)
return ERROR_FAIL;
}
- for (int i = first; i <= last; i++) {
+ for (unsigned int i = first; i <= last; i++) {
retval = w600_start(bank, QFLASH_CMD_SE,
QFLASH_ADDR(bank->sectors[i].offset), 0);
if (retval != ERROR_OK)
diff --git a/src/flash/nor/xcf.c b/src/flash/nor/xcf.c
index ba35c2c..ded5e5e 100644
--- a/src/flash/nor/xcf.c
+++ b/src/flash/nor/xcf.c
@@ -114,13 +114,11 @@ static void fill_sector_table(struct flash_bank *bank)
/* Note: is_erased and is_protected fields must be set here to an unknown
* state, they will be correctly filled from other API calls. */
- int i = 0;
-
- for (i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
bank->sectors[i].is_erased = -1;
bank->sectors[i].is_protected = -1;
}
- for (i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
bank->sectors[i].size = XCF_DATA_SECTOR_SIZE;
bank->sectors[i].offset = i * XCF_DATA_SECTOR_SIZE;
}
@@ -218,10 +216,10 @@ static int sector_state(uint8_t wrpt, int sector)
return 1;
}
-static uint8_t fill_select_block(int first, int last)
+static uint8_t fill_select_block(unsigned int first, unsigned int last)
{
uint8_t ret = 0;
- for (int i = first; i <= last; i++)
+ for (unsigned int i = first; i <= last; i++)
ret |= 1 << i;
return ret;
}
@@ -319,23 +317,26 @@ static int isc_program_register(struct flash_bank *bank, const uint8_t *cmd,
return isc_wait_erase_program(bank, timeout_ms);
}
-static int isc_clear_protect(struct flash_bank *bank, int first, int last)
+static int isc_clear_protect(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
uint8_t select_block[3] = {0x0, 0x0, 0x0};
select_block[0] = fill_select_block(first, last);
return isc_set_register(bank, CMD_XSC_UNLOCK, select_block, 24, 0);
}
-static int isc_set_protect(struct flash_bank *bank, int first, int last)
+static int isc_set_protect(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
uint8_t wrpt[2] = {0xFF, 0xFF};
- for (int i = first; i <= last; i++)
+ for (unsigned int i = first; i <= last; i++)
wrpt[0] &= ~(1 << i);
return isc_program_register(bank, CMD_XSC_DATA_WRPT, wrpt, 16, 0);
}
-static int isc_erase_sectors(struct flash_bank *bank, int first, int last)
+static int isc_erase_sectors(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
uint8_t select_block[3] = {0, 0, 0};
select_block[0] = fill_select_block(first, last);
@@ -438,7 +439,7 @@ static int read_write_data(struct flash_bank *bank, const uint8_t *w_buffer,
goto EXIT;
}
- if ((offset + count) > (uint32_t)(bank->num_sectors * XCF_DATA_SECTOR_SIZE)) {
+ if ((offset + count) > (bank->num_sectors * XCF_DATA_SECTOR_SIZE)) {
ret = ERROR_FLASH_DST_OUT_OF_BANK;
goto EXIT;
}
@@ -491,7 +492,7 @@ static int read_write_data(struct flash_bank *bank, const uint8_t *w_buffer,
/* Set 'done' flags for all data sectors because driver supports
* only single revision. */
if (write_flag) {
- for (int i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
ret = isc_set_data_done(bank, i);
if (ERROR_OK != ret)
goto EXIT;
@@ -511,12 +512,12 @@ static uint16_t isc_read_ccb(struct flash_bank *bank)
return le_to_h_u16(ccb);
}
-static int gucr_num(const struct flash_bank *bank)
+static unsigned int gucr_num(const struct flash_bank *bank)
{
return bank->num_sectors;
}
-static int sucr_num(const struct flash_bank *bank)
+static unsigned int sucr_num(const struct flash_bank *bank)
{
return bank->num_sectors + 1;
}
@@ -642,7 +643,7 @@ static int xcf_probe(struct flash_bank *bank)
LOG_INFO("device id = 0x%X ", bank->target->tap->idcode);
LOG_INFO("flash size = %d configuration bits",
bank->num_sectors * XCF_DATA_SECTOR_SIZE * 8);
- LOG_INFO("number of sectors = %d", bank->num_sectors);
+ LOG_INFO("number of sectors = %u", bank->num_sectors);
return ERROR_OK;
}
@@ -665,7 +666,7 @@ static int xcf_protect_check(struct flash_bank *bank)
isc_read_register(bank, CMD_XSC_DATA_WRPT, wrpt, 16);
isc_leave(bank);
- for (int i = 0; i < bank->num_sectors; i++)
+ for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_protected = sector_state(wrpt[0], i);
return ERROR_OK;
@@ -696,13 +697,14 @@ static int xcf_erase_check(struct flash_bank *bank)
isc_leave(bank);
- for (int i = 0; i < bank->num_sectors; i++)
+ for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_erased = sector_state(blankreg, i);
return ERROR_OK;
}
-static int xcf_erase(struct flash_bank *bank, int first, int last)
+static int xcf_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
if ((first >= bank->num_sectors)
|| (last >= bank->num_sectors)
@@ -728,7 +730,8 @@ static int xcf_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t of
return read_write_data(bank, buffer, NULL, true, offset, count);
}
-static int xcf_protect(struct flash_bank *bank, int set, int first, int last)
+static int xcf_protect(struct flash_bank *bank, int set, unsigned int first,
+ unsigned int last)
{
int ret;
diff --git a/src/flash/nor/xmc1xxx.c b/src/flash/nor/xmc1xxx.c
index 7589771..eda1823 100644
--- a/src/flash/nor/xmc1xxx.c
+++ b/src/flash/nor/xmc1xxx.c
@@ -76,19 +76,20 @@ static int xmc1xxx_nvm_check_idle(struct target *target)
return retval;
}
-static int xmc1xxx_erase(struct flash_bank *bank, int first, int last)
+static int xmc1xxx_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct target *target = bank->target;
struct working_area *workarea;
struct reg_param reg_params[3];
struct armv7m_algorithm armv7m_algo;
unsigned i;
- int retval, sector;
+ int retval;
const uint8_t erase_code[] = {
#include "../../../contrib/loaders/flash/xmc1xxx/erase.inc"
};
- LOG_DEBUG("Infineon XMC1000 erase sectors %d to %d", first, last);
+ LOG_DEBUG("Infineon XMC1000 erase sectors %u to %u", first, last);
if (bank->target->state != TARGET_HALTED) {
LOG_WARNING("Cannot communicate... target not halted.");
@@ -139,7 +140,7 @@ static int xmc1xxx_erase(struct flash_bank *bank, int first, int last)
goto err_run;
}
- for (sector = first; sector <= last; sector++)
+ for (unsigned int sector = first; sector <= last; sector++)
bank->sectors[sector].is_erased = 1;
err_run:
@@ -161,7 +162,7 @@ static int xmc1xxx_erase_check(struct flash_bank *bank)
struct armv7m_algorithm armv7m_algo;
uint16_t val;
unsigned i;
- int retval, sector;
+ int retval;
const uint8_t erase_check_code[] = {
#include "../../../contrib/loaders/flash/xmc1xxx/erase_check.inc"
};
@@ -192,7 +193,7 @@ static int xmc1xxx_erase_check(struct flash_bank *bank)
buf_set_u32(reg_params[0].value, 0, 32, NVM_BASE);
- for (sector = 0; sector < bank->num_sectors; sector++) {
+ for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
uint32_t start = bank->base + bank->sectors[sector].offset;
buf_set_u32(reg_params[1].value, 0, 32, start);
buf_set_u32(reg_params[2].value, 0, 32, start + bank->sectors[sector].size);
@@ -379,7 +380,8 @@ err_alloc_code:
static int xmc1xxx_protect_check(struct flash_bank *bank)
{
uint32_t nvmconf;
- int i, num_protected, retval;
+ unsigned int num_protected;
+ int retval;
if (bank->target->state != TARGET_HALTED) {
LOG_WARNING("Cannot communicate... target not halted.");
@@ -395,7 +397,7 @@ static int xmc1xxx_protect_check(struct flash_bank *bank)
num_protected = (nvmconf >> 4) & 0xff;
- for (i = 0; i < bank->num_sectors; i++)
+ for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_protected = (i < num_protected) ? 1 : 0;
return ERROR_OK;
@@ -442,7 +444,7 @@ static int xmc1xxx_probe(struct flash_bank *bank)
struct xmc1xxx_flash_bank *xmc_bank = bank->driver_priv;
uint32_t flash_addr = bank->base;
uint32_t idchip, flsize;
- int i, retval;
+ int retval;
if (xmc_bank->probed)
return ERROR_OK;
@@ -475,7 +477,7 @@ static int xmc1xxx_probe(struct flash_bank *bank)
bank->size = bank->num_sectors * 4 * 1024;
bank->sectors = calloc(bank->num_sectors,
sizeof(struct flash_sector));
- for (i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
if (i == 0) {
bank->sectors[i].size = 0x200;
bank->sectors[i].offset = 0xE00;
diff --git a/src/flash/nor/xmc4xxx.c b/src/flash/nor/xmc4xxx.c
index d6a1ad4..aa26693 100644
--- a/src/flash/nor/xmc4xxx.c
+++ b/src/flash/nor/xmc4xxx.c
@@ -280,7 +280,7 @@ static int xmc4xxx_load_bank_layout(struct flash_bank *bank)
/* At this point, we know which flash controller ID we're
* talking to and simply need to fill out the bank structure accordingly */
- LOG_DEBUG("%d sectors", bank->num_sectors);
+ LOG_DEBUG("%u sectors", bank->num_sectors);
switch (bank->num_sectors) {
case 8:
@@ -296,7 +296,7 @@ static int xmc4xxx_load_bank_layout(struct flash_bank *bank)
capacity = sector_capacity_16;
break;
default:
- LOG_ERROR("Unexpected number of sectors, %d\n",
+ LOG_ERROR("Unexpected number of sectors, %u\n",
bank->num_sectors);
return ERROR_FAIL;
}
@@ -307,7 +307,7 @@ static int xmc4xxx_load_bank_layout(struct flash_bank *bank)
uint32_t total_offset = 0;
bank->sectors = calloc(bank->num_sectors,
sizeof(struct flash_sector));
- for (int i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
bank->sectors[i].size = capacity[i] * 1024;
bank->sectors[i].offset = total_offset;
bank->sectors[i].is_erased = -1;
@@ -408,7 +408,7 @@ static int xmc4xxx_probe(struct flash_bank *bank)
}
static int xmc4xxx_get_sector_start_addr(struct flash_bank *bank,
- int sector, uint32_t *ret_addr)
+ unsigned int sector, uint32_t *ret_addr)
{
/* Make sure we understand this sector */
if (sector > bank->num_sectors)
@@ -538,7 +538,8 @@ static int xmc4xxx_erase_sector(struct flash_bank *bank, uint32_t address,
return res;
}
-static int xmc4xxx_erase(struct flash_bank *bank, int first, int last)
+static int xmc4xxx_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct xmc4xxx_flash_bank *fb = bank->driver_priv;
int res;
@@ -556,14 +557,14 @@ static int xmc4xxx_erase(struct flash_bank *bank, int first, int last)
uint32_t tmp_addr;
/* Loop through the sectors and erase each one */
- for (int i = first; i <= last; i++) {
+ for (unsigned int i = first; i <= last; i++) {
res = xmc4xxx_get_sector_start_addr(bank, i, &tmp_addr);
if (res != ERROR_OK) {
- LOG_ERROR("Invalid sector %d", i);
+ LOG_ERROR("Invalid sector %u", i);
return res;
}
- LOG_DEBUG("Erasing sector %d @ 0x%08"PRIx32, i, tmp_addr);
+ LOG_DEBUG("Erasing sector %u @ 0x%08"PRIx32, i, tmp_addr);
res = xmc4xxx_erase_sector(bank, tmp_addr, false);
if (res != ERROR_OK) {
@@ -925,7 +926,7 @@ static int xmc4xxx_get_info_command(struct flash_bank *bank, char *buf, int buf_
snprintf(prot_str, sizeof(prot_str), "\nFlash is read protected");
bool otp_enabled = false;
- for (int i = 0; i < bank->num_sectors; i++)
+ for (unsigned int i = 0; i < bank->num_sectors; i++)
if (fb->write_prot_otp[i])
otp_enabled = true;
@@ -934,7 +935,7 @@ static int xmc4xxx_get_info_command(struct flash_bank *bank, char *buf, int buf_
char otp_str[14];
if (otp_enabled) {
strcat(prot_str, "\nOTP Protection is enabled for sectors:\n");
- for (int i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
if (fb->write_prot_otp[i]) {
snprintf(otp_str, sizeof(otp_str), "- %d\n", i);
strncat(prot_str, otp_str, sizeof(prot_str) - strlen(prot_str) - 1);
@@ -1028,7 +1029,7 @@ static int xmc4xxx_flash_unprotect(struct flash_bank *bank, int32_t level)
/* Reference: "XMC4500 Flash Protection.pptx" app note */
static int xmc4xxx_flash_protect(struct flash_bank *bank, int level, bool read_protect,
- int first, int last)
+ unsigned int first, unsigned int last)
{
/* User configuration block buffers */
uint8_t ucp0_buf[8 * sizeof(uint32_t)] = {0};
@@ -1087,7 +1088,7 @@ static int xmc4xxx_flash_protect(struct flash_bank *bank, int level, bool read_p
/* We need to fill out the procon register representation
* that we will be writing to the device */
- for (int i = first; i <= last; i++)
+ for (unsigned int i = first; i <= last; i++)
procon |= 1 << i;
/* If read protection is requested, set the appropriate bit
@@ -1144,7 +1145,8 @@ static int xmc4xxx_flash_protect(struct flash_bank *bank, int level, bool read_p
return ERROR_OK;
}
-static int xmc4xxx_protect(struct flash_bank *bank, int set, int first, int last)
+static int xmc4xxx_protect(struct flash_bank *bank, int set, unsigned int first,
+ unsigned int last)
{
int ret;
struct xmc4xxx_flash_bank *fb = bank->driver_priv;
@@ -1193,7 +1195,7 @@ static int xmc4xxx_protect_check(struct flash_bank *bank)
return ret;
}
- int sectors = bank->num_sectors;
+ unsigned int sectors = bank->num_sectors;
/* On devices with 12 sectors, sectors 10 & 11 are ptected
* together instead of individually */
@@ -1201,7 +1203,7 @@ static int xmc4xxx_protect_check(struct flash_bank *bank)
sectors--;
/* Clear the protection status */
- for (int i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
bank->sectors[i].is_protected = 0;
fb->write_prot_otp[i] = false;
}
@@ -1214,7 +1216,7 @@ static int xmc4xxx_protect_check(struct flash_bank *bank)
/* Check for write protection on every available
* sector */
- for (int j = 0; j < sectors; j++) {
+ for (unsigned int j = 0; j < sectors; j++) {
int set = (protection[i] & (1 << j)) ? 1 : 0;
bank->sectors[j].is_protected |= set;
diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c
index 6a9e261..0e0b595 100644
--- a/src/server/gdb_server.c
+++ b/src/server/gdb_server.c
@@ -996,8 +996,7 @@ static int gdb_new_connection(struct connection *connection)
* This will cause an auto_probe to be invoked, which is either
* a no-op or it will fail when the target isn't ready(e.g. not halted).
*/
- int i;
- for (i = 0; i < flash_get_bank_count(); i++) {
+ for (unsigned int i = 0; i < flash_get_bank_count(); i++) {
struct flash_bank *p;
p = get_flash_bank_by_num_noprobe(i);
if (p->target != target)
@@ -1831,8 +1830,7 @@ static int gdb_memory_map(struct connection *connection,
int length;
char *separator;
target_addr_t ram_start = 0;
- int i;
- int target_flash_banks = 0;
+ unsigned int target_flash_banks = 0;
/* skip command character */
packet += 23;
@@ -1848,7 +1846,7 @@ static int gdb_memory_map(struct connection *connection,
*/
banks = malloc(sizeof(struct flash_bank *)*flash_get_bank_count());
- for (i = 0; i < flash_get_bank_count(); i++) {
+ for (unsigned int i = 0; i < flash_get_bank_count(); i++) {
p = get_flash_bank_by_num_noprobe(i);
if (p->target != target)
continue;
@@ -1864,8 +1862,7 @@ static int gdb_memory_map(struct connection *connection,
qsort(banks, target_flash_banks, sizeof(struct flash_bank *),
compare_bank);
- for (i = 0; i < target_flash_banks; i++) {
- int j;
+ for (unsigned int i = 0; i < target_flash_banks; i++) {
unsigned sector_size = 0;
unsigned group_len = 0;
@@ -1883,7 +1880,7 @@ static int gdb_memory_map(struct connection *connection,
* smaller ones at the end (maybe 32KB). STR7 will have
* regions with 8KB, 32KB, and 64KB sectors; etc.
*/
- for (j = 0; j < p->num_sectors; j++) {
+ for (unsigned int j = 0; j < p->num_sectors; j++) {
/* Maybe start a new group of sectors. */
if (sector_size == 0) {
@@ -3117,7 +3114,7 @@ static int gdb_v_packet(struct connection *connection,
target_call_event_callbacks(target,
TARGET_EVENT_GDB_FLASH_WRITE_START);
result = flash_write(target, gdb_connection->vflash_image,
- &written, 0);
+ &written, false);
target_call_event_callbacks(target,
TARGET_EVENT_GDB_FLASH_WRITE_END);
if (result != ERROR_OK) {