Merge pull request #302 from gsmcmullin/always_buffer_flash
Only support buffered flash writes
This commit is contained in:
commit
455e0a74d2
|
@ -239,9 +239,7 @@ static void efm32_add_flash(target *t, target_addr addr, size_t length,
|
|||
f->length = length;
|
||||
f->blocksize = page_size;
|
||||
f->erase = efm32_flash_erase;
|
||||
f->write = target_flash_write_buffered;
|
||||
f->done = target_flash_done_buffered;
|
||||
f->write_buf = efm32_flash_write;
|
||||
f->write = efm32_flash_write;
|
||||
f->buf_size = page_size;
|
||||
target_add_flash(t, f);
|
||||
}
|
||||
|
|
|
@ -94,19 +94,24 @@ static int kl_gen_flash_write(struct target_flash *f,
|
|||
target_addr dest, const void *src, size_t len);
|
||||
static int kl_gen_flash_done(struct target_flash *f);
|
||||
|
||||
static void kl_gen_add_flash(target *t,
|
||||
uint32_t addr, size_t length, size_t erasesize,
|
||||
size_t write_len)
|
||||
struct kinetis_flash {
|
||||
struct target_flash f;
|
||||
uint8_t write_len;
|
||||
};
|
||||
|
||||
static void kl_gen_add_flash(target *t, uint32_t addr, size_t length,
|
||||
size_t erasesize, size_t write_len)
|
||||
{
|
||||
struct target_flash *f = calloc(1, sizeof(*f));
|
||||
struct kinetis_flash *kf = calloc(1, sizeof(*kf));
|
||||
struct target_flash *f = &kf->f;
|
||||
f->start = addr;
|
||||
f->length = length;
|
||||
f->blocksize = erasesize;
|
||||
f->erase = kl_gen_flash_erase;
|
||||
f->write = kl_gen_flash_write;
|
||||
f->done = kl_gen_flash_done;
|
||||
f->align = write_len;
|
||||
f->erased = 0xff;
|
||||
kf->write_len = write_len;
|
||||
target_add_flash(t, f);
|
||||
}
|
||||
|
||||
|
@ -256,6 +261,8 @@ static int kl_gen_flash_erase(struct target_flash *f, target_addr addr, size_t l
|
|||
static int kl_gen_flash_write(struct target_flash *f,
|
||||
target_addr dest, const void *src, size_t len)
|
||||
{
|
||||
struct kinetis_flash *kf = (struct kinetis_flash *)f;
|
||||
|
||||
/* Ensure we don't write something horrible over the security byte */
|
||||
if (!unsafe_enabled &&
|
||||
(dest <= FLASH_SECURITY_BYTE_ADDRESS) &&
|
||||
|
@ -266,7 +273,7 @@ static int kl_gen_flash_write(struct target_flash *f,
|
|||
|
||||
/* Determine write command based on the alignment. */
|
||||
uint8_t write_cmd;
|
||||
if (f->align == K64_WRITE_LEN) {
|
||||
if (kf->write_len == K64_WRITE_LEN) {
|
||||
write_cmd = FTFE_CMD_PROGRAM_PHRASE;
|
||||
} else {
|
||||
write_cmd = FTFA_CMD_PROGRAM_LONGWORD;
|
||||
|
@ -274,9 +281,9 @@ static int kl_gen_flash_write(struct target_flash *f,
|
|||
|
||||
while (len) {
|
||||
if (kl_gen_command(f->t, write_cmd, dest, src)) {
|
||||
len -= f->align;
|
||||
dest += f->align;
|
||||
src += f->align;
|
||||
len -= kf->write_len;
|
||||
dest += kf->write_len;
|
||||
src += kf->write_len;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
|
@ -286,6 +293,7 @@ static int kl_gen_flash_write(struct target_flash *f,
|
|||
|
||||
static int kl_gen_flash_done(struct target_flash *f)
|
||||
{
|
||||
struct kinetis_flash *kf = (struct kinetis_flash *)f;
|
||||
|
||||
if (unsafe_enabled)
|
||||
return 0;
|
||||
|
@ -297,7 +305,7 @@ static int kl_gen_flash_done(struct target_flash *f)
|
|||
/* Load the security byte based on the alignment (determine 8 byte phrases
|
||||
* vs 4 byte phrases).
|
||||
*/
|
||||
if (f->align == 8) {
|
||||
if (kf->write_len == 8) {
|
||||
uint32_t vals[2];
|
||||
vals[0] = target_mem_read32(f->t, FLASH_SECURITY_BYTE_ADDRESS-4);
|
||||
vals[1] = target_mem_read32(f->t, FLASH_SECURITY_BYTE_ADDRESS);
|
||||
|
|
|
@ -65,7 +65,6 @@ static void lmi_add_flash(target *t, size_t length)
|
|||
f->blocksize = 0x400;
|
||||
f->erase = lmi_flash_erase;
|
||||
f->write = lmi_flash_write;
|
||||
f->align = 4;
|
||||
f->erased = 0xff;
|
||||
target_add_flash(t, f);
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ void lpc11xx_add_flash(target *t, uint32_t addr, size_t len, size_t erasesize)
|
|||
struct lpc_flash *lf = lpc_add_flash(t, addr, len);
|
||||
lf->f.blocksize = erasesize;
|
||||
lf->f.buf_size = IAP_PGM_CHUNKSIZE;
|
||||
lf->f.write_buf = lpc_flash_write_magic_vect;
|
||||
lf->f.write = lpc_flash_write_magic_vect;
|
||||
lf->iap_entry = IAP_ENTRYPOINT;
|
||||
lf->iap_ram = IAP_RAM_BASE;
|
||||
lf->iap_msp = IAP_RAM_BASE + MIN_RAM_SIZE - RAM_USAGE_FOR_IAP_ROUTINES;
|
||||
|
@ -122,4 +122,3 @@ lpc11xx_probe(target *t)
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ void lpc15xx_add_flash(target *t, uint32_t addr, size_t len, size_t erasesize)
|
|||
struct lpc_flash *lf = lpc_add_flash(t, addr, len);
|
||||
lf->f.blocksize = erasesize;
|
||||
lf->f.buf_size = IAP_PGM_CHUNKSIZE;
|
||||
lf->f.write_buf = lpc_flash_write_magic_vect;
|
||||
lf->f.write = lpc_flash_write_magic_vect;
|
||||
lf->iap_entry = IAP_ENTRYPOINT;
|
||||
lf->iap_ram = IAP_RAM_BASE;
|
||||
lf->iap_msp = IAP_RAM_BASE + MIN_RAM_SIZE - RAM_USAGE_FOR_IAP_ROUTINES;
|
||||
|
@ -77,4 +77,3 @@ lpc15xx_probe(target *t)
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ void lpc17xx_add_flash(target *t, uint32_t addr, size_t len, size_t erasesize, u
|
|||
lf->f.blocksize = erasesize;
|
||||
lf->base_sector = base_sector;
|
||||
lf->f.buf_size = IAP_PGM_CHUNKSIZE;
|
||||
lf->f.write_buf = lpc_flash_write_magic_vect;
|
||||
lf->f.write = lpc_flash_write_magic_vect;
|
||||
lf->iap_entry = IAP_ENTRYPOINT;
|
||||
lf->iap_ram = IAP_RAM_BASE;
|
||||
lf->iap_msp = IAP_RAM_BASE + MIN_RAM_SIZE - RAM_USAGE_FOR_IAP_ROUTINES;
|
||||
|
|
|
@ -40,9 +40,7 @@ struct lpc_flash *lpc_add_flash(target *t, target_addr addr, size_t length)
|
|||
f->start = addr;
|
||||
f->length = length;
|
||||
f->erase = lpc_flash_erase;
|
||||
f->write = target_flash_write_buffered;
|
||||
f->done = target_flash_done_buffered;
|
||||
f->write_buf = lpc_flash_write;
|
||||
f->write = lpc_flash_write;
|
||||
f->erased = 0xff;
|
||||
target_add_flash(t, f);
|
||||
return lf;
|
||||
|
@ -148,4 +146,3 @@ int lpc_flash_write_magic_vect(struct target_flash *f,
|
|||
}
|
||||
return lpc_flash_write(f, dest, src, len);
|
||||
}
|
||||
|
||||
|
|
|
@ -97,7 +97,6 @@ static void nrf51_add_flash(target *t,
|
|||
f->blocksize = erasesize;
|
||||
f->erase = nrf51_flash_erase;
|
||||
f->write = nrf51_flash_write;
|
||||
f->align = 4;
|
||||
f->erased = 0xff;
|
||||
target_add_flash(t, f);
|
||||
}
|
||||
|
|
|
@ -131,9 +131,7 @@ static void sam3_add_flash(target *t,
|
|||
f->length = length;
|
||||
f->blocksize = SAM3_PAGE_SIZE;
|
||||
f->erase = sam3_flash_erase;
|
||||
f->write = target_flash_write_buffered;
|
||||
f->done = target_flash_done_buffered;
|
||||
f->write_buf = sam3x_flash_write;
|
||||
f->write = sam3x_flash_write;
|
||||
f->buf_size = SAM3_PAGE_SIZE;
|
||||
sf->eefc_base = eefc_base;
|
||||
sf->write_cmd = EEFC_FCR_FCMD_EWP;
|
||||
|
@ -149,9 +147,7 @@ static void sam4_add_flash(target *t,
|
|||
f->length = length;
|
||||
f->blocksize = SAM4_PAGE_SIZE * 8;
|
||||
f->erase = sam4_flash_erase;
|
||||
f->write = target_flash_write_buffered;
|
||||
f->done = target_flash_done_buffered;
|
||||
f->write_buf = sam3x_flash_write;
|
||||
f->write = sam3x_flash_write;
|
||||
f->buf_size = SAM4_PAGE_SIZE;
|
||||
sf->eefc_base = eefc_base;
|
||||
sf->write_cmd = EEFC_FCR_FCMD_WP;
|
||||
|
@ -355,4 +351,3 @@ static bool sam3x_cmd_gpnvm_set(target *t, int argc, char *argv[])
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -173,9 +173,7 @@ static void sam4l_add_flash(target *t, uint32_t addr, size_t length)
|
|||
f->length = length;
|
||||
f->blocksize = SAM4L_PAGE_SIZE;
|
||||
f->erase = sam4l_flash_erase;
|
||||
f->write = target_flash_write_buffered;
|
||||
f->done = target_flash_done_buffered;
|
||||
f->write_buf = sam4l_flash_write_buf;
|
||||
f->write = sam4l_flash_write_buf;
|
||||
f->buf_size = SAM4L_PAGE_SIZE;
|
||||
f->erased = 0xff;
|
||||
/* add it into the target structures flash chain */
|
||||
|
|
|
@ -350,9 +350,7 @@ static void samd_add_flash(target *t, uint32_t addr, size_t length)
|
|||
f->length = length;
|
||||
f->blocksize = SAMD_ROW_SIZE;
|
||||
f->erase = samd_flash_erase;
|
||||
f->write = target_flash_write_buffered;
|
||||
f->done = target_flash_done_buffered;
|
||||
f->write_buf = samd_flash_write;
|
||||
f->write = samd_flash_write;
|
||||
f->buf_size = SAMD_PAGE_SIZE;
|
||||
target_add_flash(t, f);
|
||||
}
|
||||
|
@ -698,4 +696,3 @@ static bool samd_cmd_ssb(target *t)
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -109,7 +109,6 @@ static void stm32f1_add_flash(target *t,
|
|||
f->blocksize = erasesize;
|
||||
f->erase = stm32f1_flash_erase;
|
||||
f->write = stm32f1_flash_write;
|
||||
f->align = 2;
|
||||
f->erased = 0xff;
|
||||
target_add_flash(t, f);
|
||||
}
|
||||
|
|
|
@ -161,7 +161,6 @@ static void stm32f4_add_flash(target *t,
|
|||
f->blocksize = blocksize;
|
||||
f->erase = stm32f4_flash_erase;
|
||||
f->write = stm32f4_flash_write;
|
||||
f->align = 4;
|
||||
f->erased = 0xff;
|
||||
sf->base_sector = base_sector;
|
||||
sf->psize = 32;
|
||||
|
|
|
@ -237,9 +237,7 @@ static void stm32l_add_flash(target *t,
|
|||
f->length = length;
|
||||
f->blocksize = erasesize;
|
||||
f->erase = stm32lx_nvm_prog_erase;
|
||||
f->write = target_flash_write_buffered;
|
||||
f->done = target_flash_done_buffered;
|
||||
f->write_buf = stm32lx_nvm_prog_write;
|
||||
f->write = stm32lx_nvm_prog_write;
|
||||
f->buf_size = erasesize/2;
|
||||
target_add_flash(t, f);
|
||||
}
|
||||
|
@ -252,7 +250,6 @@ static void stm32l_add_eeprom(target *t, uint32_t addr, size_t length)
|
|||
f->blocksize = 4;
|
||||
f->erase = stm32lx_nvm_data_erase;
|
||||
f->write = stm32lx_nvm_data_write;
|
||||
f->align = 1;
|
||||
target_add_flash(t, f);
|
||||
}
|
||||
|
||||
|
|
|
@ -135,9 +135,7 @@ static void stm32l4_add_flash(target *t,
|
|||
f->length = length;
|
||||
f->blocksize = blocksize;
|
||||
f->erase = stm32l4_flash_erase;
|
||||
f->write = target_flash_write_buffered;
|
||||
f->done = target_flash_done_buffered;
|
||||
f->write_buf = stm32l4_flash_write;
|
||||
f->write = stm32l4_flash_write;
|
||||
f->buf_size = 2048;
|
||||
f->erased = 0xff;
|
||||
sf->bank1_start = bank1_start;
|
||||
|
|
|
@ -26,6 +26,10 @@
|
|||
|
||||
target *target_list = NULL;
|
||||
|
||||
static int target_flash_write_buffered(struct target_flash *f,
|
||||
target_addr dest, const void *src, size_t len);
|
||||
static int target_flash_done_buffered(struct target_flash *f);
|
||||
|
||||
target *target_new(void)
|
||||
{
|
||||
target *t = (void*)calloc(1, sizeof(*t));
|
||||
|
@ -138,6 +142,8 @@ void target_add_ram(target *t, target_addr start, uint32_t len)
|
|||
|
||||
void target_add_flash(target *t, struct target_flash *f)
|
||||
{
|
||||
if (f->buf_size == 0)
|
||||
f->buf_size = MIN(f->blocksize, 0x400);
|
||||
f->t = t;
|
||||
f->next = t->flash;
|
||||
t->flash = f;
|
||||
|
@ -216,15 +222,7 @@ int target_flash_write(target *t,
|
|||
struct target_flash *f = flash_for_addr(t, dest);
|
||||
size_t tmptarget = MIN(dest + len, f->start + f->length);
|
||||
size_t tmplen = tmptarget - dest;
|
||||
if (f->align > 1) {
|
||||
uint32_t offset = dest % f->align;
|
||||
uint8_t data[ALIGN(offset + tmplen, f->align)];
|
||||
memset(data, f->erased, sizeof(data));
|
||||
memcpy((uint8_t *)data + offset, src, tmplen);
|
||||
ret |= f->write(f, dest - offset, data, sizeof(data));
|
||||
} else {
|
||||
ret |= f->write(f, dest, src, tmplen);
|
||||
}
|
||||
ret |= target_flash_write_buffered(f, dest, src, tmplen);
|
||||
dest += tmplen;
|
||||
src += tmplen;
|
||||
len -= tmplen;
|
||||
|
@ -235,6 +233,9 @@ int target_flash_write(target *t,
|
|||
int target_flash_done(target *t)
|
||||
{
|
||||
for (struct target_flash *f = t->flash; f; f = f->next) {
|
||||
int tmp = target_flash_done_buffered(f);
|
||||
if (tmp)
|
||||
return tmp;
|
||||
if (f->done) {
|
||||
int tmp = f->done(f);
|
||||
if (tmp)
|
||||
|
@ -260,7 +261,7 @@ int target_flash_write_buffered(struct target_flash *f,
|
|||
if (base != f->buf_addr) {
|
||||
if (f->buf_addr != (uint32_t)-1) {
|
||||
/* Write sector to flash if valid */
|
||||
ret |= f->write_buf(f, f->buf_addr,
|
||||
ret |= f->write(f, f->buf_addr,
|
||||
f->buf, f->buf_size);
|
||||
}
|
||||
/* Setup buffer for a new sector */
|
||||
|
@ -282,7 +283,7 @@ int target_flash_done_buffered(struct target_flash *f)
|
|||
int ret = 0;
|
||||
if ((f->buf != NULL) &&(f->buf_addr != (uint32_t)-1)) {
|
||||
/* Write sector to flash if valid */
|
||||
ret = f->write_buf(f, f->buf_addr, f->buf, f->buf_size);
|
||||
ret = f->write(f, f->buf_addr, f->buf, f->buf_size);
|
||||
f->buf_addr = -1;
|
||||
free(f->buf);
|
||||
f->buf = NULL;
|
||||
|
@ -564,4 +565,3 @@ int tc_system(target *t, target_addr cmd, size_t cmdlen)
|
|||
}
|
||||
return t->tc->system(t->tc, cmd, cmdlen);
|
||||
}
|
||||
|
||||
|
|
|
@ -43,13 +43,9 @@ struct target_flash {
|
|||
flash_write_func write;
|
||||
flash_done_func done;
|
||||
target *t;
|
||||
struct target_flash *next;
|
||||
int align;
|
||||
uint8_t erased;
|
||||
|
||||
/* For buffered flash */
|
||||
size_t buf_size;
|
||||
flash_write_func write_buf;
|
||||
struct target_flash *next;
|
||||
target_addr buf_addr;
|
||||
void *buf;
|
||||
};
|
||||
|
@ -131,9 +127,6 @@ struct target_s {
|
|||
void target_add_commands(target *t, const struct command_s *cmds, const char *name);
|
||||
void target_add_ram(target *t, target_addr start, uint32_t len);
|
||||
void target_add_flash(target *t, struct target_flash *f);
|
||||
int target_flash_write_buffered(struct target_flash *f,
|
||||
target_addr dest, const void *src, size_t len);
|
||||
int target_flash_done_buffered(struct target_flash *f);
|
||||
|
||||
/* Convenience function for MMIO access */
|
||||
uint32_t target_mem_read32(target *t, uint32_t addr);
|
||||
|
@ -185,4 +178,3 @@ bool kinetis_probe(target *t);
|
|||
bool efm32_probe(target *t);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in New Issue