aboutsummaryrefslogtreecommitdiff
path: root/src/flash/nor/tms470.c
diff options
context:
space:
mode:
authorMarc Schink <dev@zapb.de>2020-06-07 17:00:13 +0200
committerTomas Vanek <vanekt@fbl.cz>2020-07-07 05:23:54 +0100
commitef14384b681af4f731f768bb866457832af6925f (patch)
treea8cb953d765484d4cd627eaa7ea71d9be6699866 /src/flash/nor/tms470.c
parenta2e6982a1816a0229bd5644156f3025a0e8cb6ce (diff)
downloadriscv-openocd-ef14384b681af4f731f768bb866457832af6925f.zip
riscv-openocd-ef14384b681af4f731f768bb866457832af6925f.tar.gz
riscv-openocd-ef14384b681af4f731f768bb866457832af6925f.tar.bz2
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 <dev@zapb.de> Reviewed-on: http://openocd.zylin.com/4929 Tested-by: jenkins Reviewed-by: Tomas Vanek <vanekt@fbl.cz> Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Diffstat (limited to 'src/flash/nor/tms470.c')
-rw-r--r--src/flash/nor/tms470.c39
1 files changed, 20 insertions, 19 deletions
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");