extern flash_driver_t ecosflash_flash;
extern flash_driver_t lpc288x_flash;
extern flash_driver_t ocl_flash;
+extern flash_driver_t pic32mx_flash;
flash_driver_t *flash_drivers[] = {
- &lpc2000_flash,
- &cfi_flash,
- &at91sam7_flash,
- &at91sam7_old_flash,
- &str7x_flash,
- &str9x_flash,
- &aduc702x_flash,
- &stellaris_flash,
- &str9xpec_flash,
- &stm32x_flash,
- &tms470_flash,
- &ecosflash_flash,
- &lpc288x_flash,
- &ocl_flash,
- NULL,
+ &lpc2000_flash,
+ &cfi_flash,
+ &at91sam7_flash,
+ &at91sam7_old_flash,
+ &str7x_flash,
+ &str9x_flash,
+ &aduc702x_flash,
+ &stellaris_flash,
+ &str9xpec_flash,
+ &stm32x_flash,
+ &tms470_flash,
+ &ecosflash_flash,
+ &lpc288x_flash,
+ &ocl_flash,
+ &pic32mx_flash,
+ NULL,
};
-
-
flash_bank_t *flash_banks;
static command_t *flash_cmd;
{
flash_cmd = register_command(cmd_ctx, NULL, "flash", NULL, COMMAND_ANY, NULL);
- register_command(cmd_ctx, flash_cmd, "bank", handle_flash_bank_command, COMMAND_CONFIG, "flash_bank <driver> <base> <size> <chip_width> <bus_width> <target> [driver_options ...]");
+ register_command(cmd_ctx, flash_cmd, "bank", handle_flash_bank_command, COMMAND_CONFIG, "flash bank <driver> <base> <size> <chip_width> <bus_width> <target> [driver_options ...]");
return ERROR_OK;
}
return JIM_ERR;
}
- if (!flash_banks)
- {
- return JIM_ERR;
- }
-
Jim_Obj *list=Jim_NewListObj(interp, NULL, 0);
for (p = flash_banks; p; p = p->next)
{
int flash_init_drivers(struct command_context_s *cmd_ctx)
{
+ register_jim(cmd_ctx, "ocd_flash_banks", jim_flash_banks, "return information about the flash banks");
+
if (flash_banks)
{
- register_jim(cmd_ctx, "ocd_flash_banks", jim_flash_banks, "return information about the flash banks");
-
register_command(cmd_ctx, flash_cmd, "info", handle_flash_info_command, COMMAND_EXEC,
"print info about flash bank <num>");
register_command(cmd_ctx, flash_cmd, "probe", handle_flash_probe_command, COMMAND_EXEC,
"erase address range <address> <length>");
register_command(cmd_ctx, flash_cmd, "fillw", handle_flash_fill_command, COMMAND_EXEC,
- "fill with pattern <address> <word_pattern> <count>");
+ "fill with pattern (no autoerase) <address> <word_pattern> <count>");
register_command(cmd_ctx, flash_cmd, "fillh", handle_flash_fill_command, COMMAND_EXEC,
"fill with pattern <address> <halfword_pattern> <count>");
register_command(cmd_ctx, flash_cmd, "fillb", handle_flash_fill_command, COMMAND_EXEC,
/* put flash bank in linked list */
if (flash_banks)
{
+ int bank_num = 0;
/* find last flash bank */
- for (p = flash_banks; p && p->next; p = p->next);
+ for (p = flash_banks; p && p->next; p = p->next) bank_num++;
if (p)
p->next = c;
+ c->bank_number = bank_num + 1;
}
else
{
flash_banks = c;
+ c->bank_number = 0;
}
found = 1;
j, p->sectors[j].offset, p->sectors[j].size, p->sectors[j].size>>10,
erase_state);
}
-
}
return ERROR_OK;
if ((retval = flash_erase_address_range(target, address, length)) == ERROR_OK)
{
- duration_stop_measure(&duration, &duration_text);
+ if ((retval = duration_stop_measure(&duration, &duration_text)) != ERROR_OK)
+ {
+ return retval;
+ }
command_print(cmd_ctx, "erased address 0x%8.8x length %i in %s", address, length, duration_text);
free(duration_text);
}
if ((retval = flash_driver_erase(p, first, last)) == ERROR_OK)
{
- duration_stop_measure(&duration, &duration_text);
+ if ((retval = duration_stop_measure(&duration, &duration_text)) != ERROR_OK)
+ {
+ return retval;
+ }
command_print(cmd_ctx, "erased sectors %i through %i on flash bank %i in %s", first, last, strtoul(args[0], 0, 0), duration_text);
free(duration_text);
duration_t duration;
char *duration_text;
- int retval;
+ int retval, retvaltemp;
if (argc < 1)
{
command_print(cmd_ctx, "auto erase enabled");
}
-
if (argc < 1)
{
return ERROR_COMMAND_SYNTAX_ERROR;
return retval;
}
- duration_stop_measure(&duration, &duration_text);
+ if ((retvaltemp = duration_stop_measure(&duration, &duration_text)) != ERROR_OK)
+ {
+ image_close(&image);
+ return retvaltemp;
+ }
if (retval == ERROR_OK)
{
command_print(cmd_ctx, "wrote %u byte from file %s in %s (%f kb/s)",
int handle_flash_fill_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
{
- int err = ERROR_OK;
+ int err = ERROR_OK, retval;
u32 address;
u32 pattern;
u32 count;
if(count == 0)
return ERROR_OK;
-
switch(cmd[4])
{
case 'w':
duration_start_measure(&duration);
- flash_set_dirty();
- err = flash_erase_address_range( target, address, count*wordsize );
- if (err == ERROR_OK)
+ for (wrote=0; wrote<(count*wordsize); wrote+=sizeof(chunk))
{
- for (wrote=0; wrote<(count*wordsize); wrote+=sizeof(chunk))
+ int cur_size = MIN( (count*wordsize - wrote) , 1024 );
+ flash_bank_t *bank;
+ bank = get_flash_bank_by_addr(target, address);
+ if(bank == NULL)
{
- int cur_size = MIN( (count*wordsize - wrote) , 1024 );
- if (err == ERROR_OK)
- {
- flash_bank_t *bank;
- bank = get_flash_bank_by_addr(target, address);
- if(bank == NULL)
- {
- err = ERROR_FAIL;
- break;
- }
- err = flash_driver_write(bank, chunk, address - bank->base + wrote, cur_size);
- wrote += cur_size;
- }
- if (err!=ERROR_OK)
- break;
+ return ERROR_FAIL;
}
+ err = flash_driver_write(bank, chunk, address - bank->base + wrote, cur_size);
+ if (err!=ERROR_OK)
+ return err;
+ wrote += cur_size;
}
- duration_stop_measure(&duration, &duration_text);
+ if ((retval = duration_stop_measure(&duration, &duration_text)) != ERROR_OK)
+ {
+ return retval;
+ }
if(err == ERROR_OK)
{
duration_t duration;
char *duration_text;
- int retval;
+ int retval, retvaltemp;
flash_bank_t *p;
if (argc != 3)
free(buffer);
buffer = NULL;
- duration_stop_measure(&duration, &duration_text);
- if (retval!=ERROR_OK)
+ if ((retvaltemp = duration_stop_measure(&duration, &duration_text)) != ERROR_OK)
+ {
+ fileio_close(&fileio);
+ return retvaltemp;
+ }
+ if (retval==ERROR_OK)
{
command_print(cmd_ctx, "wrote %"PRIi64" byte from file %s to flash bank %i at offset 0x%8.8x in %s (%f kb/s)",
fileio.size, args[1], strtoul(args[0], NULL, 0), offset, duration_text,
}
/* check whether it fits */
- if (addr + length > c->base + c->size)
+ if (addr + length - 1 > c->base + c->size - 1)
return ERROR_FLASH_DST_BREAKS_ALIGNMENT;
addr -= c->base;
section_first = section;
section_last = section;
padding[section] = 0;
- while ((run_address + run_size < c->base + c->size)
+ while ((run_address + run_size - 1 < c->base + c->size - 1)
&& (section_last + 1 < image->num_sections))
{
if (image->sections[section_last + 1].base_address < (run_address + run_size))
}
/* fit the run into bank constraints */
- if (run_address + run_size > c->base + c->size)
+ if (run_address + run_size - 1 > c->base + c->size - 1)
+ {
+ LOG_WARNING("writing %d bytes only - as image section is %d bytes and bank is only %d bytes", \
+ c->base + c->size - run_address, run_size, c->size);
run_size = c->base + c->size - run_address;
+ }
/* allocate buffer */
buffer = malloc(run_size);
int i;
int retval;
int fast_check = 0;
- int blank;
+ u32 blank;
if (bank->target->state != TARGET_HALTED)
{