aboutsummaryrefslogtreecommitdiff
path: root/src/flash/nor
diff options
context:
space:
mode:
authorAntonio Borneo <borneo.antonio@gmail.com>2021-07-03 17:18:53 +0200
committerAntonio Borneo <borneo.antonio@gmail.com>2021-07-24 10:38:31 +0100
commitc0c7d6fe8b04f521a7262303083ef5eb6ebaf4e5 (patch)
treeceb6cb092f7bbf31a9ca0677c6a67364d4a52ed2 /src/flash/nor
parent54e699b2601036e384a124657aa1fbdd9ff2dc87 (diff)
downloadriscv-openocd-c0c7d6fe8b04f521a7262303083ef5eb6ebaf4e5.zip
riscv-openocd-c0c7d6fe8b04f521a7262303083ef5eb6ebaf4e5.tar.gz
riscv-openocd-c0c7d6fe8b04f521a7262303083ef5eb6ebaf4e5.tar.bz2
openocd: fix Yoda conditions with checkpatch
The new checkpatch can automatically fix the code, but this feature is still error prone and not complete. Patch generated automatically through the new checkpatch with flags "--types CONSTANT_COMPARISON --fix-inplace". Some Yoda condition is detected by checkpatch but not fixed; it will be fixed manually in a following commit. Change-Id: Ifaaa1159e63dbd1db6aa3c017125df9874fa9703 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/6355 Tested-by: jenkins
Diffstat (limited to 'src/flash/nor')
-rw-r--r--src/flash/nor/avrf.c16
-rw-r--r--src/flash/nor/cc26xx.c8
-rw-r--r--src/flash/nor/cc3220sf.c14
-rw-r--r--src/flash/nor/efm32.c6
-rw-r--r--src/flash/nor/fespi.c6
-rw-r--r--src/flash/nor/msp432.c26
-rw-r--r--src/flash/nor/tms470.c2
7 files changed, 39 insertions, 39 deletions
diff --git a/src/flash/nor/avrf.c b/src/flash/nor/avrf.c
index 4fa4e0d..a5a2cbd 100644
--- a/src/flash/nor/avrf.c
+++ b/src/flash/nor/avrf.c
@@ -134,7 +134,7 @@ static int avr_jtagprg_chiperase(struct avr_common *avr)
&poll_value,
0x3380,
AVR_JTAG_REG_PROGRAMMING_COMMAND_LEN);
- if (ERROR_OK != mcu_execute_queue())
+ if (mcu_execute_queue() != ERROR_OK)
return ERROR_FAIL;
LOG_DEBUG("poll_value = 0x%04" PRIx32 "", poll_value);
} while (!(poll_value & 0x0200));
@@ -195,7 +195,7 @@ static int avr_jtagprg_writeflashpage(struct avr_common *avr,
&poll_value,
0x3700,
AVR_JTAG_REG_PROGRAMMING_COMMAND_LEN);
- if (ERROR_OK != mcu_execute_queue())
+ if (mcu_execute_queue() != ERROR_OK)
return ERROR_FAIL;
LOG_DEBUG("poll_value = 0x%04" PRIx32 "", poll_value);
} while (!(poll_value & 0x0200));
@@ -266,7 +266,7 @@ static int avrf_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t o
LOG_DEBUG("offset is 0x%08" PRIx32 "", offset);
LOG_DEBUG("count is %" PRIu32 "", count);
- if (ERROR_OK != avr_jtagprg_enterprogmode(avr))
+ if (avr_jtagprg_enterprogmode(avr) != ERROR_OK)
return ERROR_FAIL;
if (bank->size > 0x20000)
@@ -315,7 +315,7 @@ static int avrf_probe(struct flash_bank *bank)
avrf_info->probed = false;
avr_jtag_read_jtagid(avr, &device_id);
- if (ERROR_OK != mcu_execute_queue())
+ if (mcu_execute_queue() != ERROR_OK)
return ERROR_FAIL;
LOG_INFO("device id = 0x%08" PRIx32 "", device_id);
@@ -380,7 +380,7 @@ static int avrf_info(struct flash_bank *bank, struct command_invocation *cmd)
}
avr_jtag_read_jtagid(avr, &device_id);
- if (ERROR_OK != mcu_execute_queue())
+ if (mcu_execute_queue() != ERROR_OK)
return ERROR_FAIL;
LOG_INFO("device id = 0x%08" PRIx32 "", device_id);
@@ -420,9 +420,9 @@ static int avrf_mass_erase(struct flash_bank *bank)
return ERROR_TARGET_NOT_HALTED;
}
- if ((ERROR_OK != avr_jtagprg_enterprogmode(avr))
- || (ERROR_OK != avr_jtagprg_chiperase(avr))
- || (ERROR_OK != avr_jtagprg_leaveprogmode(avr)))
+ if ((avr_jtagprg_enterprogmode(avr) != ERROR_OK)
+ || (avr_jtagprg_chiperase(avr) != ERROR_OK)
+ || (avr_jtagprg_leaveprogmode(avr) != ERROR_OK))
return ERROR_FAIL;
return ERROR_OK;
diff --git a/src/flash/nor/cc26xx.c b/src/flash/nor/cc26xx.c
index 0895798..f6b5632 100644
--- a/src/flash/nor/cc26xx.c
+++ b/src/flash/nor/cc26xx.c
@@ -148,7 +148,7 @@ static int cc26xx_init(struct flash_bank *bank)
return retval;
/* Confirm the defined working address is the area we need to use */
- if (CC26XX_ALGO_BASE_ADDRESS != cc26xx_bank->working_area->address)
+ if (cc26xx_bank->working_area->address != CC26XX_ALGO_BASE_ADDRESS)
return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
/* Write flash helper algorithm into target memory */
@@ -211,7 +211,7 @@ static int cc26xx_mass_erase(struct flash_bank *bank)
int retval;
- if (TARGET_HALTED != target->state) {
+ if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED;
}
@@ -275,7 +275,7 @@ static int cc26xx_erase(struct flash_bank *bank, unsigned int first,
uint32_t length;
int retval;
- if (TARGET_HALTED != target->state) {
+ if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED;
}
@@ -327,7 +327,7 @@ static int cc26xx_write(struct flash_bank *bank, const uint8_t *buffer,
uint32_t index;
int retval;
- if (TARGET_HALTED != target->state) {
+ if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED;
}
diff --git a/src/flash/nor/cc3220sf.c b/src/flash/nor/cc3220sf.c
index 522b21a..b296538 100644
--- a/src/flash/nor/cc3220sf.c
+++ b/src/flash/nor/cc3220sf.c
@@ -42,7 +42,7 @@ static int cc3220sf_mass_erase(struct flash_bank *bank)
int retval = ERROR_OK;
- if (TARGET_HALTED != target->state) {
+ if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED;
}
@@ -118,7 +118,7 @@ static int cc3220sf_erase(struct flash_bank *bank, unsigned int first,
int retval = ERROR_OK;
- if (TARGET_HALTED != target->state) {
+ if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED;
}
@@ -192,7 +192,7 @@ static int cc3220sf_write(struct flash_bank *bank, const uint8_t *buffer,
int retval = ERROR_OK;
- if (TARGET_HALTED != target->state) {
+ if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED;
}
@@ -295,7 +295,7 @@ static int cc3220sf_write(struct flash_bank *bank, const uint8_t *buffer,
/* Check that the head value was written to flash */
result = buf_get_u32(reg_params[2].value, 0, 32);
- if (0 != result) {
+ if (result != 0) {
retval = ERROR_FAIL;
LOG_ERROR("cc3220sf: Flash operation failed");
}
@@ -359,7 +359,7 @@ static int cc3220sf_write(struct flash_bank *bank, const uint8_t *buffer,
/* Check that all words were written to flash */
result = buf_get_u32(reg_params[2].value, 0, 32);
- if (0 != result) {
+ if (result != 0) {
retval = ERROR_FAIL;
LOG_ERROR("cc3220sf: Flash operation failed");
break;
@@ -369,7 +369,7 @@ static int cc3220sf_write(struct flash_bank *bank, const uint8_t *buffer,
}
/* Do one word write for any final bytes less than a full word */
- if ((retval == ERROR_OK) && (0 != tail_count)) {
+ if ((retval == ERROR_OK) && (tail_count != 0)) {
uint8_t tail[4];
/* Set starting byte offset for data to write */
@@ -409,7 +409,7 @@ static int cc3220sf_write(struct flash_bank *bank, const uint8_t *buffer,
/* Check that the tail was written to flash */
result = buf_get_u32(reg_params[2].value, 0, 32);
- if (0 != result) {
+ if (result != 0) {
retval = ERROR_FAIL;
LOG_ERROR("cc3220sf: Flash operation failed");
}
diff --git a/src/flash/nor/efm32.c b/src/flash/nor/efm32.c
index c8ce908..ab0186d 100644
--- a/src/flash/nor/efm32.c
+++ b/src/flash/nor/efm32.c
@@ -386,7 +386,7 @@ static int efm32x_wait_status(struct flash_bank *bank, int timeout,
LOG_DEBUG("status: 0x%" PRIx32 "", status);
- if (((status & wait_mask) == 0) && (0 == wait_for_set))
+ if (((status & wait_mask) == 0) && (wait_for_set == 0))
break;
else if (((status & wait_mask) != 0) && wait_for_set)
break;
@@ -457,7 +457,7 @@ static int efm32x_erase(struct flash_bank *bank, unsigned int first,
struct target *target = bank->target;
int ret = 0;
- if (TARGET_HALTED != target->state) {
+ if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED;
}
@@ -958,7 +958,7 @@ static int efm32x_probe(struct flash_bank *bank)
LOG_INFO("flash size = %dkbytes", efm32_mcu_info.flash_sz_kib);
LOG_INFO("flash page size = %dbytes", efm32_mcu_info.page_size);
- assert(0 != efm32_mcu_info.page_size);
+ assert(efm32_mcu_info.page_size != 0);
int num_pages = efm32_mcu_info.flash_sz_kib * 1024 /
efm32_mcu_info.page_size;
diff --git a/src/flash/nor/fespi.c b/src/flash/nor/fespi.c
index 99ec67d..150e91a 100644
--- a/src/flash/nor/fespi.c
+++ b/src/flash/nor/fespi.c
@@ -538,7 +538,7 @@ static unsigned as_compile(struct algorithm_steps *as, uint8_t *target,
break;
}
case STEP_WRITE_REG:
- if (4 > bytes_left) {
+ if (bytes_left < 4) {
finish_early = true;
break;
}
@@ -546,7 +546,7 @@ static unsigned as_compile(struct algorithm_steps *as, uint8_t *target,
offset += 3;
break;
case STEP_SET_DIR:
- if (3 > bytes_left) {
+ if (bytes_left < 3) {
finish_early = true;
break;
}
@@ -555,7 +555,7 @@ static unsigned as_compile(struct algorithm_steps *as, uint8_t *target,
break;
case STEP_TXWM_WAIT:
case STEP_WIP_WAIT:
- if (2 > bytes_left) {
+ if (bytes_left < 2) {
finish_early = true;
break;
}
diff --git a/src/flash/nor/msp432.c b/src/flash/nor/msp432.c
index 23d4982..667349f 100644
--- a/src/flash/nor/msp432.c
+++ b/src/flash/nor/msp432.c
@@ -209,7 +209,7 @@ static int msp432_wait_return_code(struct target *target)
int retval = ERROR_OK;
start_ms = timeval_ms();
- while ((0 == return_code) || (return_code == FLASH_BUSY)) {
+ while ((return_code == 0) || (return_code == FLASH_BUSY)) {
retval = target_read_u32(target, ALGO_RETURN_CODE_ADDR, &return_code);
if (retval != ERROR_OK)
return retval;
@@ -322,11 +322,11 @@ static int msp432_init(struct flash_bank *bank)
"msp432: Unrecognized MSP432P4 Device ID and Hardware "
"Rev (%04" PRIX32 ", %02" PRIX32 ")", msp432_bank->device_id,
msp432_bank->hardware_rev);
- } else if (MSP432P401X_DEPR == msp432_bank->device_type) {
+ } else if (msp432_bank->device_type == MSP432P401X_DEPR) {
LOG_WARNING(
"msp432: MSP432P401x pre-production device (deprecated "
"silicon)\n" SUPPORT_MESSAGE);
- } else if (MSP432E4X_GUESS == msp432_bank->device_type) {
+ } else if (msp432_bank->device_type == MSP432E4X_GUESS) {
/* Explicit device type check failed. Report this. */
LOG_WARNING(
"msp432: Unrecognized MSP432E4 DID0 and DID1 values "
@@ -343,7 +343,7 @@ static int msp432_init(struct flash_bank *bank)
return retval;
/* Confirm the defined working address is the area we need to use */
- if (ALGO_BASE_ADDR != msp432_bank->working_area->address)
+ if (msp432_bank->working_area->address != ALGO_BASE_ADDR)
return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
/* Write flash helper algorithm into target memory */
@@ -432,7 +432,7 @@ static int msp432_mass_erase(struct flash_bank *bank, bool all)
int retval;
- if (TARGET_HALTED != target->state) {
+ if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED;
}
@@ -501,7 +501,7 @@ COMMAND_HANDLER(msp432_mass_erase_command)
msp432_bank = bank->driver_priv;
- if (MSP432E4 == msp432_bank->family_type) {
+ if (msp432_bank->family_type == MSP432E4) {
/* MSP432E4 does not have main vs info regions, ignore "all" */
all = false;
}
@@ -510,7 +510,7 @@ COMMAND_HANDLER(msp432_mass_erase_command)
if (retval != ERROR_OK)
return retval;
- if (MSP432E4 == msp432_bank->family_type) {
+ if (msp432_bank->family_type == MSP432E4) {
/* MSP432E4 does not have main vs info regions */
LOG_INFO("msp432: Mass erase of flash is complete");
} else {
@@ -537,7 +537,7 @@ COMMAND_HANDLER(msp432_bsl_command)
msp432_bank = bank->driver_priv;
- if (MSP432E4 == msp432_bank->family_type) {
+ if (msp432_bank->family_type == MSP432E4) {
LOG_WARNING("msp432: MSP432E4 does not have a BSL region");
return ERROR_OK;
}
@@ -602,7 +602,7 @@ static int msp432_erase(struct flash_bank *bank, unsigned int first,
int retval;
- if (TARGET_HALTED != target->state) {
+ if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED;
}
@@ -680,7 +680,7 @@ static int msp432_write(struct flash_bank *bank, const uint8_t *buffer,
int retval;
- if (TARGET_HALTED != target->state) {
+ if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED;
}
@@ -829,7 +829,7 @@ static int msp432_probe(struct flash_bank *bank)
if (retval != ERROR_OK)
return retval;
- if (0 == size) {
+ if (size == 0) {
/* This is likely an MSP432E4 */
msp432_bank->family_type = MSP432E4;
@@ -864,7 +864,7 @@ static int msp432_probe(struct flash_bank *bank)
msp432_bank->device_type = msp432_device_type(msp432_bank->family_type,
msp432_bank->device_id, msp432_bank->hardware_rev);
- if (MSP432P4 == msp432_bank->family_type) {
+ if (msp432_bank->family_type == MSP432P4) {
/* Set up MSP432P4 specific flash parameters */
if (is_main) {
retval = target_read_u32(target, P4_FLASH_MAIN_SIZE_REG, &size);
@@ -981,7 +981,7 @@ static int msp432_info(struct flash_bank *bank, struct command_invocation *cmd)
switch (msp432_bank->device_type) {
case MSP432P401X_DEPR:
- if (0xFFFF == msp432_bank->device_id) {
+ if (msp432_bank->device_id == 0xFFFF) {
/* Very early pre-production silicon currently deprecated */
command_print_sameline(cmd, "MSP432P401x pre-production device (deprecated silicon)\n"
SUPPORT_MESSAGE);
diff --git a/src/flash/nor/tms470.c b/src/flash/nor/tms470.c
index 5078314..37f0933 100644
--- a/src/flash/nor/tms470.c
+++ b/src/flash/nor/tms470.c
@@ -437,7 +437,7 @@ static int tms470_try_flash_keys(struct target *target, const uint32_t *key_set)
target_write_u32(target, 0xFFE89C0C, key_set[i]);
}
- if (ERROR_OK == tms470_check_flash_unlocked(target)) {
+ if (tms470_check_flash_unlocked(target) == ERROR_OK) {
/*
* There seems to be a side-effect of reading the FMPKEY
* register in that it re-enables the protection. So we