kinetis: use new flash interface.

This commit is contained in:
Gareth McMullin 2015-04-04 08:59:51 -07:00
parent 9e09ae2e1e
commit 1541f1c7a8
1 changed files with 30 additions and 33 deletions

View File

@ -20,10 +20,12 @@
/* This file implements KL25 target specific functions providing /* This file implements KL25 target specific functions providing
* the XML memory map and Flash memory programming. * the XML memory map and Flash memory programming.
*
* According to Freescale doc KL25P80M48SF0RM:
* KL25 Sub-family Reference Manual
*/ */
#include "general.h" #include "general.h"
#include "adiv5.h"
#include "target.h" #include "target.h"
#define SIM_SDID 0x40048024 #define SIM_SDID 0x40048024
@ -54,21 +56,23 @@
#define KL25_PAGESIZE 0x400 #define KL25_PAGESIZE 0x400
static int kl25_flash_erase(target *t, uint32_t addr, size_t len); static int kl25_flash_erase(struct target_flash *f, uint32_t addr, size_t len);
static int kl25_flash_write(target *t, uint32_t dest, static int kl25_flash_write(struct target_flash *f,
const uint8_t *src, size_t len); uint32_t dest, const void *src, size_t len);
static const char kl25_xml_memory_map[] = "<?xml version=\"1.0\"?>" static void kl25_add_flash(target *t,
/* "<!DOCTYPE memory-map " uint32_t addr, size_t length, size_t erasesize)
" PUBLIC \"+//IDN gnu.org//DTD GDB Memory Map V1.0//EN\"" {
" \"http://sourceware.org/gdb/gdb-memory-map.dtd\">"*/ struct target_flash *f = calloc(1, sizeof(*f));
"<memory-map>" f->start = addr;
" <memory type=\"flash\" start=\"0\" length=\"0x20000\">" f->length = length;
" <property name=\"blocksize\">0x400</property>" f->blocksize = erasesize;
" </memory>" f->erase = kl25_flash_erase;
" <memory type=\"ram\" start=\"0x1ffff000\" length=\"0x1000\"/>" f->write = kl25_flash_write;
" <memory type=\"ram\" start=\"0x20000000\" length=\"0x3000\"/>" f->align = 4;
"</memory-map>"; f->erased = 0xff;
target_add_flash(t, f);
}
bool kinetis_probe(target *t) bool kinetis_probe(target *t)
{ {
@ -76,9 +80,9 @@ bool kinetis_probe(target *t)
switch (sdid >> 20) { switch (sdid >> 20) {
case 0x251: case 0x251:
t->driver = "KL25"; t->driver = "KL25";
t->xml_mem_map = kl25_xml_memory_map; target_add_ram(t, 0x1ffff000, 0x1000);
t->flash_erase = kl25_flash_erase; target_add_ram(t, 0x20000000, 0x3000);
t->flash_write = kl25_flash_write; kl25_add_flash(t, 0x00000000, 0x20000, 0x400);
return true; return true;
} }
return false; return false;
@ -120,28 +124,21 @@ kl25_command(target *t, uint8_t cmd, uint32_t addr, const uint8_t data[8])
return true; return true;
} }
static int kl25_flash_erase(target *t, uint32_t addr, size_t len) static int kl25_flash_erase(struct target_flash *f, uint32_t addr, size_t len)
{ {
addr &= ~(KL25_PAGESIZE - 1);
len = (len + KL25_PAGESIZE - 1) & ~(KL25_PAGESIZE - 1);
while (len) { while (len) {
kl25_command(t, FTFA_CMD_ERASE_SECTOR, addr, NULL); kl25_command(f->t, FTFA_CMD_ERASE_SECTOR, addr, NULL);
len -= KL25_PAGESIZE; len -= KL25_PAGESIZE;
addr += KL25_PAGESIZE; addr += KL25_PAGESIZE;
} }
return 0; return 0;
} }
static int kl25_flash_write(target *t, uint32_t dest, static int kl25_flash_write(struct target_flash *f,
const uint8_t *src, size_t len) uint32_t dest, const void *src, size_t len)
{ {
/* FIXME handle misaligned start and end of sections */
if ((dest & 3) || (len & 3))
return -1;
while (len) { while (len) {
kl25_command(t, FTFA_CMD_PROGRAM_LONGWORD, dest, src); kl25_command(f->t, FTFA_CMD_PROGRAM_LONGWORD, dest, src);
len -= 4; len -= 4;
dest += 4; dest += 4;
src += 4; src += 4;