From: OpenOCD-Gerrit <ope...@us...> - 2020-07-07 04:24:44
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via ef14384b681af4f731f768bb866457832af6925f (commit) from a2e6982a1816a0229bd5644156f3025a0e8cb6ce (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit ef14384b681af4f731f768bb866457832af6925f Author: Marc Schink <de...@za...> Date: Sun Jun 7 17:00:13 2020 +0200 flash/nor: Use proper data types in driver API Use 'unsigned int' and 'bool' instead of 'int' where appropriate. While at it, fix some coding style issues. No new Clang analyzer warnings. Change-Id: I700802c9ee81c3c7ae73108f0f8f06b15a4345f8 Signed-off-by: Marc Schink <de...@za...> Reviewed-on: http://openocd.zylin.com/4929 Tested-by: jenkins Reviewed-by: Tomas Vanek <va...@fb...> Reviewed-by: Antonio Borneo <bor...@gm...> diff --git a/src/flash/nor/aduc702x.c b/src/flash/nor/aduc702x.c index b6e19376c..b7d2299f7 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 7c5596d48..5e0a666ea 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 b41b15c07..1e2a4b176 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 c9ffa653b..415f3932c 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 5b56c4241..26cde19bc 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 d4bfe5310..4ee4ff853 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 039746c16..7dfdf0d29 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 6e89099ab..0bd5f5995 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 c551f2722..88ebbf23c 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 baa86acd0..ab79e8cf7 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 9a53369a7..13d1d263f 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 93f6872bd..4ec1161af 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 fbce20d55..232f6ba0a 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 176211a07..f0a855074 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 c8de7d002..5e88aa61b 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 50ab207c1..19fb6b2c2 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 aef7a04f9..effa1d5c0 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 043ff13c8..b1a36623d 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 ff5cb60c4..9f897e3e2 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; /*... [truncated message content] |