struct flash_bank **bank)
{
const char *name = CMD_ARGV[name_index];
- *bank = get_flash_bank_by_name(name);
+ int retval = get_flash_bank_by_name(name, bank);
+ if (retval != ERROR_OK)
+ return retval;
if (*bank)
return ERROR_OK;
{
command_print(CMD_CTX, "flash '%s' found at 0x%8.8" PRIx32, p->driver->name, p->base);
}
- else if (retval == ERROR_FLASH_BANK_INVALID)
- {
- command_print(CMD_CTX, "probing failed for flash bank '#%s' at 0x%8.8" PRIx32,
- CMD_ARGV[0], p->base);
- }
- else
- {
- command_print(CMD_CTX, "unknown error when probing flash bank '#%s' at 0x%8.8" PRIx32,
- CMD_ARGV[0], p->base);
- }
}
else
{
command_print(CMD_CTX, "flash bank '#%s' is out of bounds", CMD_ARGV[0]);
+ retval = ERROR_FAIL;
}
- return ERROR_OK;
+ return retval;
}
COMMAND_HANDLER(handle_flash_erase_check_command)
{
struct flash_bank *p;
int retval = ERROR_OK;
- int address;
- int length;
+ uint32_t address;
+ uint32_t length;
bool do_pad = false;
bool do_unlock = false;
struct target *target = get_current_target(CMD_CTX);
return ERROR_COMMAND_SYNTAX_ERROR;
}
- COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], address);
- COMMAND_PARSE_NUMBER(int, CMD_ARGV[1], length);
+ COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], address);
+ COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], length);
if (length <= 0)
{
return ERROR_COMMAND_SYNTAX_ERROR;
}
- p = get_flash_bank_by_addr(target, address);
- if (p == NULL)
- {
- return ERROR_FAIL;
- }
+ retval = get_flash_bank_by_addr(target, address, true, &p);
+ if (retval != ERROR_OK)
+ return retval;
/* We can't know if we did a resume + halt, in which case we no longer know the erased state */
flash_set_dirty();
if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK))
{
command_print(CMD_CTX, "erased address 0x%8.8x (length %i)"
- " in %fs (%0.3f kb/s)", address, length,
+ " in %fs (%0.3f KiB/s)", address, length,
duration_elapsed(&bench), duration_kbps(&bench, length));
}
if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK))
{
command_print(CMD_CTX, "wrote %" PRIu32 " bytes from file %s "
- "in %fs (%0.3f kb/s)", written, CMD_ARGV[0],
+ "in %fs (%0.3f KiB/s)", written, CMD_ARGV[0],
duration_elapsed(&bench), duration_kbps(&bench, written));
}
uint32_t cur_size = 0;
uint32_t chunk_count;
struct target *target = get_current_target(CMD_CTX);
- uint32_t i;
+ unsigned i;
uint32_t wordsize;
int retval = ERROR_OK;
{
struct flash_bank *bank;
- bank = get_flash_bank_by_addr(target, address);
- if (bank == NULL)
- {
- retval = ERROR_FAIL;
+ retval = get_flash_bank_by_addr(target, address, true, &bank );
+ if (retval != ERROR_OK)
goto done;
- }
cur_size = MIN((count * wordsize - wrote), chunksize);
err = flash_driver_write(bank, chunk, address - bank->base + wrote, cur_size);
goto done;
}
- err = target_read_buffer(target, address + wrote, cur_size, readback);
+ err = flash_driver_read(bank, readback, address - bank->base + wrote, cur_size);
if (err != ERROR_OK)
{
retval = err;
goto done;
}
- unsigned i;
for (i = 0; i < cur_size; i++)
{
if (readback[i]!=chunk[i])
{
- LOG_ERROR("Verfication error address 0x%08" PRIx32 ", read back 0x%02x, expected 0x%02x",
+ LOG_ERROR("Verification error address 0x%08" PRIx32 ", read back 0x%02x, expected 0x%02x",
address + wrote + i, readback[i], chunk[i]);
retval = ERROR_FAIL;
goto done;
}
}
- if (duration_measure(&bench) == ERROR_OK)
+ if ((retval == ERROR_OK) && (duration_measure(&bench) == ERROR_OK))
{
command_print(CMD_CTX, "wrote %" PRIu32 " bytes to 0x%8.8" PRIx32
- " in %fs (%0.3f kb/s)", wrote, address,
+ " in %fs (%0.3f KiB/s)", wrote, address,
duration_elapsed(&bench), duration_kbps(&bench, wrote));
}
return ERROR_OK;
}
- buffer = malloc(fileio.size);
+ buffer = malloc(fileio_size(&fileio));
size_t buf_cnt;
- if (fileio_read(&fileio, fileio.size, buffer, &buf_cnt) != ERROR_OK)
+ if (fileio_read(&fileio, fileio_size(&fileio), buffer, &buf_cnt) != ERROR_OK)
{
free(buffer);
fileio_close(&fileio);
if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK))
{
command_print(CMD_CTX, "wrote %ld bytes from file %s to flash bank %u"
- " at offset 0x%8.8" PRIx32 " in %fs (%0.3f kb/s)",
- (long)fileio.size, CMD_ARGV[1], p->bank_number, offset,
- duration_elapsed(&bench), duration_kbps(&bench, fileio.size));
+ " at offset 0x%8.8" PRIx32 " in %fs (%0.3f KiB/s)",
+ (long)fileio_size(&fileio), CMD_ARGV[1], p->bank_number, offset,
+ duration_elapsed(&bench), duration_kbps(&bench, fileio_size(&fileio)));
}
fileio_close(&fileio);
}
/* check the flash bank name is unique */
- if (get_flash_bank_by_name(bank_name) != NULL)
+ if (get_flash_bank_by_name_noprobe(bank_name) != NULL)
{
/* flash bank name already exists */
LOG_ERROR("flash bank name '%s' already exists", bank_name);