struct fespi_flash_bank {
- int probed;
+ bool probed;
target_addr_t ctrl_base;
const struct flash_device *dev;
};
/* TODO !!! What is the right naming convention here? */
static const struct fespi_target target_devices[] = {
/* name, tap_idcode, ctrl_base */
- { "Freedom E310-G000 SPI Flash", 0x10e31913 , 0x10014000 },
- { "Freedom E310-G002 SPI Flash", 0x20000913 , 0x10014000 },
- { NULL, 0, 0 }
+ { "Freedom E310-G000 SPI Flash", 0x10e31913, 0x10014000 },
+ { "Freedom E310-G002 SPI Flash", 0x20000913, 0x10014000 },
+ { NULL, 0, 0 }
};
FLASH_BANK_COMMAND_HANDLER(fespi_flash_bank_command)
return ERROR_COMMAND_SYNTAX_ERROR;
fespi_info = malloc(sizeof(struct fespi_flash_bank));
- if (fespi_info == NULL) {
+ if (!fespi_info) {
LOG_ERROR("not enough memory");
return ERROR_FAIL;
}
bank->driver_priv = fespi_info;
- fespi_info->probed = 0;
+ fespi_info->probed = false;
fespi_info->ctrl_base = 0;
if (CMD_ARGC >= 7) {
COMMAND_PARSE_ADDRESS(CMD_ARGV[6], fespi_info->ctrl_base);
int result = target_write_u32(target, fespi_info->ctrl_base + address, value);
if (result != ERROR_OK) {
- LOG_ERROR("fespi_write_reg() error writing 0x%x to " TARGET_ADDR_FMT,
+ LOG_ERROR("fespi_write_reg() error writing 0x%" PRIx32 " to " TARGET_ADDR_FMT,
value, fespi_info->ctrl_base + address);
return result;
}
break;
int64_t now = timeval_ms();
if (now - start > 1000) {
- LOG_ERROR("rxfifo didn't go positive (value=0x%x).", value);
+ LOG_ERROR("rxfifo didn't go positive (value=0x%" PRIx32 ").", value);
return ERROR_TARGET_TIMEOUT;
}
}
uint32_t ii;
if (offset & 0xFF000000) {
- LOG_ERROR("FESPI interface does not support greater than 3B addressing, can't write to offset 0x%x",
+ LOG_ERROR("FESPI interface does not support greater than 3B addressing, can't write to offset 0x%" PRIx32,
offset);
return ERROR_FAIL;
}
break;
}
case STEP_WRITE_REG:
- if (4 > bytes_left) {
+ if (bytes_left < 4) {
finish_early = true;
break;
}
offset += 3;
break;
case STEP_SET_DIR:
- if (3 > bytes_left) {
+ if (bytes_left < 3) {
finish_early = true;
break;
}
break;
case STEP_TXWM_WAIT:
case STEP_WIP_WAIT:
- if (2 > bytes_left) {
+ if (bytes_left < 2) {
finish_early = true;
break;
}
const uint8_t *buffer, uint32_t chip_offset, uint32_t len)
{
if (chip_offset & 0xFF000000) {
- LOG_ERROR("FESPI interface does not support greater than 3B addressing, can't write to offset 0x%x",
+ LOG_ERROR("FESPI interface does not support greater than 3B addressing, can't write to offset 0x%" PRIx32,
chip_offset);
return ERROR_FAIL;
}
if (fespi_info->probed)
free(bank->sectors);
- fespi_info->probed = 0;
+ fespi_info->probed = false;
if (fespi_info->ctrl_base == 0) {
for (target_device = target_devices ; target_device->name ; ++target_device)
/* create and fill sectors array */
bank->num_sectors = fespi_info->dev->size_in_bytes / sectorsize;
sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
- if (sectors == NULL) {
+ if (!sectors) {
LOG_ERROR("not enough memory");
return ERROR_FAIL;
}
}
bank->sectors = sectors;
- fespi_info->probed = 1;
+ fespi_info->probed = true;
return ERROR_OK;
}
return ERROR_OK;
}
-static int get_fespi_info(struct flash_bank *bank, char *buf, int buf_size)
+static int get_fespi_info(struct flash_bank *bank, struct command_invocation *cmd)
{
struct fespi_flash_bank *fespi_info = bank->driver_priv;
if (!(fespi_info->probed)) {
- snprintf(buf, buf_size,
- "\nFESPI flash bank not probed yet\n");
+ command_print_sameline(cmd, "\nFESPI flash bank not probed yet\n");
return ERROR_OK;
}
- snprintf(buf, buf_size, "\nFESPI flash information:\n"
+ command_print_sameline(cmd, "\nFESPI flash information:\n"
" Device \'%s\' (ID 0x%08" PRIx32 ")\n",
fespi_info->dev->name, fespi_info->dev->device_id);