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,
&ecosflash_flash,
&lpc288x_flash,
&ocl_flash,
+ &pic32mx_flash,
NULL,
};
{
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;
}
/* 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;
command_print(cmd_ctx, "auto erase enabled");
}
-
if (argc < 1)
{
return ERROR_COMMAND_SYNTAX_ERROR;
u32 count;
u8 chunk[1024];
u32 wrote = 0;
+ u32 cur_size = 0;
int chunk_count;
char *duration_text;
duration_t duration;
if(count == 0)
return ERROR_OK;
-
switch(cmd[4])
{
case 'w':
duration_start_measure(&duration);
- for (wrote=0; wrote<(count*wordsize); wrote+=sizeof(chunk))
+ for (wrote=0; wrote<(count*wordsize); wrote += cur_size)
{
- int cur_size = MIN( (count*wordsize - wrote) , 1024 );
+ cur_size = MIN( (count*wordsize - wrote), sizeof(chunk) );
flash_bank_t *bank;
bank = get_flash_bank_by_addr(target, address);
if(bank == NULL)
err = flash_driver_write(bank, chunk, address - bank->base + wrote, cur_size);
if (err!=ERROR_OK)
return err;
- wrote += cur_size;
}
if ((retval = duration_stop_measure(&duration, &duration_text)) != ERROR_OK)
return retval;
}
-
if(err == ERROR_OK)
{
float speed;
}
/* 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);