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>
This commit is contained in:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user